Skip to content

fix(workspace): write the active workspace atomically - #164

Merged
chitrangpatel merged 1 commit into
mainfrom
fix/atomic-workspace-write
Nov 10, 2026
Merged

chitrangpatel merged 1 commit into
mainfrom
fix/atomic-workspace-write

Conversation

@chitrangpatel

Copy link
Copy Markdown
Contributor

Problem

All CANFAR sessions run as chimefrb and share one home on /arc, so they share ~/.config/workflow/workspace.yml. write.workspace renamed the existing file to a .bak and then wrote the new one in place. A session starting while another was in that window found the file missing or half-written, and failed with:

  • workspace … does not exist, or
  • 'NoneType' object has no attribute 'get' (run.py:153).

We hit this when several baseband-localization sessions started together, and had to stagger them by 90 s.

Change

workflow/utils/write.py::workspace now:

  • reads the new content first. A source file is copied, not moved, so the caller's file stays.
  • leaves the file untouched when the content hasn't changed, which is the usual case when every session sets the same workspace. No backup is made then.
  • backs up with a copy (not a rename) when the content changes, so workspace.yml never disappears.
  • writes to a temporary file in the same directory, then os.replaces it into place, so a reader sees either the old file or the new one, never a partial one. The temp file is removed on error.

Tests

New tests/test_write.py (6 tests), including a race test: 4 threads write while 4 threads read, and every read must parse to a workspace. 3 of the tests fail on the old code. All 6 pass with this change.

The rest of the suite needs backends, and fails the same way on main locally.

🤖 Generated with Claude Code

Runners that share a home (every CANFAR session runs as one account with its
home on /arc) rewrite ~/.config/workflow/workspace.yml at start-up. The old
write renamed the file to a backup and then rewrote it in place, so a runner
reading it at that moment found it missing ("workspace ... does not exist") or
empty (`'NoneType' object has no attribute 'get'` in `workflow run`), and the
session failed. It also left a new dated .bak on every start.

Now the workspace is written to a temporary file beside it and renamed into
place, so readers see the old or the new file; nothing is written, and no
backup made, when it hasn't changed; a backup is a copy; and a source file is
copied instead of moved away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Afrokk Afrokk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chitrangpatel
chitrangpatel merged commit 9de555b into main Nov 10, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants