You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
workspace: concurrent writers in one working tree: record write locking or compare-and-set, and a documented model #3173
area:workspacechant workspace epic (#2525)boundariesEpic: boundaries between chant, hud, studio, behold and fountaindesignDesign or research note, no deliverable yet
Part of the boundaries epic, #3166. Found by the epic audit. Related: #2731 (gap 2: the steward and the coding agent sharing a checkout).
Problem
With the repo as the database (#3158), a box's working tree is written concurrently by several principals: people through hud (answers, reviews, notes), the coding agent (app edits, proposed records), the steward (leases, ledgers, release records), and builders in worktrees. #2731 raises the steward-agent case; nothing covers several people writing records at once, or a person and an agent amending the same record. That is the database's concurrency model, and today it's whatever the last writer did.
Proposal
chant's record writes take a per-workspace write lock (or per-record compare-and-set on the record's current digest), so two records amend calls on one record never silently overwrite: the second fails with a reason and the current digest.
The read contract reports a record's last writer and digest so UIs can show a conflict instead of hiding it.
Document the model: what's serialised, what's merged, what's a conflict.
Done when
A test runs two people's amends and an agent's amend against one record concurrently; exactly one wins per digest and the others get a conflict they can retry.
Both halves of the proposal, together. Every chant write to a working tree (records new, amend, review and close, points ask and answer, box listing set, and work evidence through amend) holds a write lock, chant-write.lock in the working tree's git directory, from its first read to its last write. That serialises writes and stops records new handing out one id twice. A waiter gives up after CHANT_WRITE_LOCK_WAIT_MS (15s) with write-lock-timeout, naming the holder; a dead or expired holder is broken.
On top of the lock, records amend, review and close take --expect <digest> (the read contract's digest). A write from a stale reading is refused with record-conflict and conflict: {id, path, expected, digest, lastWrite}; the caller re-reads and retries from digest. Every write result now carries digest. Reviews and seals stay outside the digest, so a verdict between a read and an amendment is kept, not a conflict. A write without --expect still serialises and applies its fields to the current record.
The read contract's records --json gains lastWrite: {verb, by, agent, at} | null, from a journal in the git directory keyed by the file's bytes (a cache).
For hud#819's per-writer batch: chant workspace lock acquire --holder <name> [--ttl] prints a token; each chant write run with CHANT_WRITE_LOCK=<token> goes ahead while others wait, and lock release --token ends it. A tool's own files written in the batch are covered by taking the same lock.
The writer conformance suite has the concurrent case (three amends from one digest through the writer, one wins, two record-conflict, retries win). Not changed: ledger writes on chant/lifecycle, already compare-and-set on the ref. Follow-ups once the in-flight PRs land: wip restore (#3408) should take the lock, and the MCP write tools could take expect.
area:workspacechant workspace epic (#2525)boundariesEpic: boundaries between chant, hud, studio, behold and fountaindesignDesign or research note, no deliverable yet
Activity
lex00 commentedon Oct 3, 2026
Design, as built in #3412 and recorded as ws-089:
Both halves of the proposal, together. Every chant write to a working tree (records new, amend, review and close, points ask and answer, box listing set, and work evidence through amend) holds a write lock,
chant-write.lockin the working tree's git directory, from its first read to its last write. That serialises writes and stopsrecords newhanding out one id twice. A waiter gives up afterCHANT_WRITE_LOCK_WAIT_MS(15s) withwrite-lock-timeout, naming the holder; a dead or expired holder is broken.On top of the lock,
records amend,reviewandclosetake--expect <digest>(the read contract's digest). A write from a stale reading is refused withrecord-conflictandconflict: {id, path, expected, digest, lastWrite}; the caller re-reads and retries fromdigest. Every write result now carriesdigest. Reviews and seals stay outside the digest, so a verdict between a read and an amendment is kept, not a conflict. A write without--expectstill serialises and applies its fields to the current record.The read contract's
records --jsongainslastWrite: {verb, by, agent, at} | null, from a journal in the git directory keyed by the file's bytes (a cache).For hud#819's per-writer batch:
chant workspace lock acquire --holder <name> [--ttl]prints a token; each chant write run withCHANT_WRITE_LOCK=<token>goes ahead while others wait, andlock release --tokenends it. A tool's own files written in the batch are covered by taking the same lock.The writer conformance suite has the concurrent case (three amends from one digest through the writer, one wins, two
record-conflict, retries win). Not changed: ledger writes on chant/lifecycle, already compare-and-set on the ref. Follow-ups once the in-flight PRs land:wip restore(#3408) should take the lock, and the MCP write tools could takeexpect.