Repository navigation
Keep concurrent usage collectors off one shared temp file - #6654
Merged
Merged
Conversation
Two Claude collectors running at once both wrote the cache through a temp path derived from the target, so the second replace found the file already moved away and crashed the update with a FileNotFoundError. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes concurrent Claude usage collectors racing over a shared temporary cache file.
Changes:
- Uses unique temporary files while preserving atomic replacement and permissions.
- Adds concurrency, integrity, cleanup, and permission regression coverage.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
bin/omarchy-agent-usage-claude |
Makes JSON cache writes concurrency-safe. |
test/shell.d/agent-usage-claude-scanner-test.sh |
Tests concurrent cache writes and permissions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
nick1udwig
pushed a commit
to nick1udwig/omarchy
that referenced
this pull request
Sep 9, 2026
Two Claude collectors running at once both wrote the cache through a temp path derived from the target, so the second replace found the file already moved away and crashed the update with a FileNotFoundError. Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.
Fixes #6649.
write_json()built its temp path from the target —claude-opencode-*.json.tmpforclaude-opencode-*.json. Two collectors running at once therefore wrote the same temp file,and the one that called
replace()second found it already moved away:That overlap is normal:
omarchy-agent-usage-updatebackgrounds one collector per agent whilethe panel refreshes on its own. The reporter hit it during
omarchy update, when migration1786099804primed the data files alongside a periodic refresh.cached_scan()was already serialized by anfcntl.flock, but the three otherwrite_json()call sites — the pi/omp session cache, the opencode cache, and the limits probe cache — were
not, so locking only the opencode scan would have left two identical races behind. Giving
write_json()a per-writer temp name viatempfile.mkstempcloses all of them at once andkeeps the replace atomic; the explicit
chmodpreserves the 0644 these caches had before,since
mkstempopens at 0600.The failure was transient and self-healed on the next run, but it aborted the collector, so
that run produced no Claude record and the update printed
claude collector failed.— 🤖 Claude, posting on behalf of @dhh