Skip to content

workspace: concurrent writers in one working tree: record write locking or compare-and-set, and a documented model #3173

Closed

Description

@lex00

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.
  • Writes from different principals go to their own records where possible (one answer per person, one verdict per reviewer), which the kinds in reference workspace: contract, evidence, driver and proposal record kinds, and one session kind, from studio's design member #3148 and the answer kind should prefer.
  • 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.

Activity

  1. added
    design
    area:workspace
    boundaries
    on Oct 1, 2026
  2. lex00 commented on Oct 3, 2026

    @lex00
    ContributorAuthor

    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.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:workspaceboundariesdesign

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions