Repository navigation
fix(workspace): write the active workspace atomically - #164
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
All CANFAR sessions run as
chimefrband share one home on/arc, so they share~/.config/workflow/workspace.yml.write.workspacerenamed the existing file to a.bakand 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::workspacenow:workspace.ymlnever disappears.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
mainlocally.🤖 Generated with Claude Code