Skip to content

fix(util): a key approval and the picker keep a write made at the same time (#861) - #894

Open
akleizor-hive[bot] wants to merge 5 commits into
mainfrom
hive/861-symphony
Open

akleizor-hive[bot] wants to merge 5 commits into
mainfrom
hive/861-symphony

Conversation

@akleizor-hive

@akleizor-hive akleizor-hive Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

What

Recording a key approval and the project picker's launch-time rewrites of a
profile's .claude.json (and the picker's settings-layer rewrite) are now one
locked read-modify-write: rewriteProfileJSON in util/profilejson.go holds
the profile's live lock (.locks/<name>.live) exclusively from its read to
its rename — the lock a session holds shared for its life and the mode
SeedPersonAnswers takes. No ccmorph session, launch, picker or second
approval can write the file under another's rename, and no write is lost
(#299, #861).

Design points, each checked against INTENT.md and Scope and ownership:

  • One owner. ApproveKey and both of ProjectPicker's rewrites
    (.claude.json and the settings layer) go through the one helper; the seam
    every regression test interleaves at (profileJSONRead) belongs to it.
  • An edit with nothing to change takes no lock and writes nothing — the
    common second-terminal case stays free of the lockWait.
  • A running session's files win over fresh picker rows. While a session
    holds the lock, the picker waits at most lockWait, writes nothing and
    returns PickerDone without a word; the launch proceeds with the rows the
    files already hold, and the next launch that can take the lock writes them.
    A key approval that cannot be recorded is saved (SaveApproval marker) by
    login/add and recorded by the next launch before Claude Code starts; a
    launch that finds a saved approval still waiting says so and starts nothing.
  • Not Claude Code's .claude.json.lock — another product's mechanics stay
    with its owner.

Commits

Tests

  • The approval race test (red on 2b81ffa, proven red again by mutation) plus the picker's own interleaving test: a foreign lock-honouring write at each rewrite's seam lands, and so do the picker's rows.
  • Mutation checks in scratch copies: with the lock block deleted both interleaving tests fail "was lost"; with EX downgraded to SH the four lock-proof tests fail; with the nothing-to-change pre-check deleted the no-lock test fails.
  • go vet ./..., full Go suites under umask 077 and NO_PROXY='*', the four zsh suites and 475+ Python tests.

Supersedes #345 (left open): #299 closed at its spend cap with this branch
accepted at its gate but out of landing retries; this PR replays that accepted
work onto current main and extends the same lock to the picker, per the scout
note on #861.

Closes #861

🤖 Generated with Claude Code

akleizor and others added 5 commits November 25, 2026 22:12
…write (#299, #861)

Squash of origin/hive/299-symphony at 9243c27 onto current main. The
merge commit shape would replay #299's thirteen commits again under the
gate's rebase and raise the same three conflicts that spent its landing
retries; this lands them as one. Conflicts resolved: REVIEW.md keeps
both sides, keyapproval.go keeps both imports and main's
paths.IsSymlink and keyRefusedMsg, and main's `rm` confirmation now
answers the new behaviour test. The changelog bullet moves from
v0.5.8 to Unreleased.

Co-Authored-By: Claude Code <noreply@anthropic.com>
rewriteProfileJSON holds the profile's live lock exclusively from its
read to the rename, takes no lock and writes nothing when the edit
changes nothing, and wraps ErrProfileInUse when a holder outlasts the
bounded wait. ApproveKey's whole rewrite now runs through it; the
read seam every regression test interleaves at became the helper's.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…ofile's live lock (#861)

ProjectPicker rewrites the same two files a live session writes from the
launch path. Its rewriteJSON now runs through rewriteProfileJSON, the one
locked read-modify-write ApproveKey uses, so a session's own save can no
longer be lost under a picker rename. With a session open the picker
writes nothing and the launch goes on with the rows the files already
hold; the next launch that can take the lock records them.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…nfig (#861)

The changelog entry now names both writers the lock covers — the key
approval and the picker's rows and layer — and ARCHITECTURE.md §1 says
what .locks/<name>.live is and which rewrites hold it exclusively.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…s its rewrite (#299, #861)

SeedPersonAnswers read the profile's .claude.json and edited it before
taking the live lock, then renamed that snapshot: a key approval landing
between the read and the rename was silently erased under it. The
authoritative read and edit now run through rewriteProfileJSON, the one
locked read-modify-write ApproveKey and the picker use — the unlocked
read stays only to answer the no-gaps case and to report the gaps of a
deferred seeding. A second-process ApproveKey met at the seeding's seam
finds the profile in use and lands once the seeding ends, with both
writes standing.

Co-Authored-By: Claude Code <noreply@anthropic.com>
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.

Recording a key approval rewrites the profile home's .claude.json with no lock, so a write Claude Code makes at the same time is silently lost

1 participant