Skip to content

v0.5.0: per-agent attribution in the record, and the concurrency fix it needed - #21

Merged
shahcolate merged 1 commit into
mainfrom
claude/surface-enhancements-yxmtdr
Jul 25, 2026
Merged

shahcolate merged 1 commit into
mainfrom
claude/surface-enhancements-yxmtdr

Conversation

@shahcolate

Copy link
Copy Markdown
Owner

Ships the next open roadmap item — per-agent / worktree attribution (a by: field) — and fixes a real bug found while building it.

The record learns who

With one human and one agent, loop was subject enough: everything in the log was the agent. Run three, in three worktrees, on one repo, and at merge time "what was it allowed to do, and what did it do?" needs a who.

$ docket record log
#7  deploy  allow change → "src/api/rates.ts" (change: source files)   ← claude-code @ hotfix-402
#9  deploy  allow read  → "test/rates.test.ts" (read: the repo)        ← cursor @ wt-perf:perf-pass

$ docket metrics --by claude-code      # one agent's posture, not the team average
Field Where it comes from
by --by <agent>, then DOCKET_BY, then a detected agent (Claude Code, Cursor, Gemini CLI, Codex, Aider, GitHub Actions), then user:<name>
branch git branch at write time (short sha when detached)
worktree the linked worktree's name, when the write came from one
session the harness's session id — the Claude Code hook supplies one

Stamping happens in appendRecord, so no writer can forget it: CLI, hook, MCP, and docket review amendments all carry it. Fields with no honest value are omitted rather than filled with a placeholder that reads like a fact, and pre-existing entries read as unattributed — never guessed at.

Two properties stated plainly in the README and spec, because attribution is easy to oversell:

  • by is self-reported. A process that can write to the record can claim any subject. Provenance, not authentication.
  • But it can't be revised. by is inside the hashed entry, so rewriting who an old entry blames breaks the chain at that entry.

The bug this surfaced

Appending is read-the-head-then-chain-to-it, and that pair wasn't atomic. Two agents writing at once both chain to entry 5, and then:

$ docket record verify        # before, after 6 parallel writers
✗ chain broken at entry 13: entry 13 has seq 7 — an entry was removed, added, or reordered

Nobody tampered with anything. A false tamper alarm in an audit trail is worse than no alarm — it teaches people to disbelieve the real one, and it fires precisely in the parallel-agent scenario this feature is for.

Appends are now serialized across processes with an exclusive lock file next to the record: stale locks (dead holder) broken after 10s, and an error rather than an unlocked write if it can't acquire one within 15s. Zero dependencies, one machine in scope — a record on a shared network filesystem is documented as outside the guarantee.

Also fixed

  • docket record log --n <not-a-number> silently printed the entire log instead of erroring — "20 lines" and "everything since March" are very different answers to the same command.
  • README claimed "this is v0.3.x" while the package was at 0.4.0.

Testing

  • 16 new tests across test/attribution.test.js and test/concurrency.test.js, including five agents × twelve writes landing simultaneously from separate processes, stale-lock recovery, lock release on a throwing write, and tamper-detection of a rewritten by.
  • The concurrency tests were verified to fail when the lock is removed — they catch the bug they guard.
  • Full suite: 139 passing. Eval unchanged: 10,582 checks, zero silent allows, zero fail-open.

Docs

README (+ README.zh.md for parity), spec/SPEC.md (attribution fields, the self-reported caveat, and a normative concurrency requirement), the docs site, and CLI help. Roadmap item checked off; version bumped to 0.5.0.


Generated by Claude Code

…it needed

The record could say what happened and under which loop, but not *who*. With
one human and one agent that was fine — everything in the log was "the agent".
Running three in three worktrees on one repo, it stops being fine: at merge
time, "what was it allowed to do, and what did it do?" needs a subject.

Every entry is now stamped with `by` (the agent), `branch`, `worktree`, and
`session` when the harness supplies one. Resolution is explicit-first — `--by`,
then DOCKET_BY, then a detected agent, then the OS user — and every field is
omitted rather than filled with a placeholder that reads like a fact. Read it
back with `docket record log --by` and `docket metrics --by`.

Two properties stated plainly, because attribution is easy to oversell: `by`
is self-reported (provenance, not authentication), and it cannot be revised —
it is inside the hashed entry, so rewriting who an old entry blames breaks the
chain there.

Fixes a real bug found while building it: appending is read-the-head-then-
chain-to-it, so parallel agents could both chain to the same entry and leave
`verify` reporting "an entry was removed, added, or reordered" on a log nobody
had touched. Six concurrent writers corrupted the chain reliably. Appends are
now serialized across processes with an exclusive lock file (stale locks broken
after 10s, an error rather than an unlocked write if it can't acquire one). A
false tamper alarm is worse than no alarm — it teaches people to disbelieve the
real one.

Also fixes `docket record log --n <not-a-number>` silently printing the entire
log instead of erroring, and a stale "this is v0.3.x" in the README.

16 new tests, including five agents writing simultaneously from separate
processes; verified they fail when the lock is removed. Eval unchanged:
10,582 checks, zero silent allows, zero fail-open.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019xDGH82gMx6NWh3xqinF9B
@shahcolate
shahcolate merged commit cc06033 into main Jul 25, 2026
3 checks passed
@shahcolate
shahcolate deleted the claude/surface-enhancements-yxmtdr branch August 5, 2026 04:52
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.

1 participant