Skip to content

Audit: nothing reads the anchor record, so N working trees give N green verdicts and no union view #470

Closed

Description

@sandstream

The gap

kit audit verify answers for one working tree. On a machine running several, that produces several independent green verdicts and no way to ask the question a reviewer actually asks — what did the agents do to this repo today?

This is not a bug in the cwd work; it is a consequence of that work being correct. logAuditEvent resolves resolve(cwd ?? process.cwd(), logFile), and a git worktree is a distinct working tree, so it correctly gets its own chain.

Measured with two real worktrees of this repo on the same commit:

$ cd wt-a && kit audit verify
✓ audit chain intact  1 entries
✓ HMAC anchor verified (1 sealed entries).      exit 0

$ cd wt-b && kit audit verify
✓ audit chain intact  1 entries
✓ HMAC anchor verified (1 sealed entries).      exit 0

Two greens, neither of which is the whole story. A checker whose oracle is one working tree cannot see its siblings, which is the same failure class self-audit rule 14 exists to catch.

What does survive the model, also measured, so this issue is scoped to the part that doesn't:

  • Worktrees share the .git common dir, so installed pre-commit / pre-push / post-commit hooks fire in every one of them without reinstalling — an agent cannot create itself an ungated worktree.
  • .kit.toml is tracked, so policy cannot drift by construction, and the narrowing-only semantic means a session editing its own copy cannot self-approve.

The data to fix it already exists

~/.kit/audit-anchor.json stores the HMAC tip per log path and lives in the home dir, shared across every working tree on the machine. After appends in two worktrees it held both absolute paths. It is, in effect, an index of every audit log kit has ever sealed here.

Nothing reads it that way. kit audit anchor seals the audit log — the one in cwd — and the only reader outside audit-anchor.ts looks up a single path:

$ grep -rn "readAnchorRecord\|Object.keys(record" src/*.ts | grep -v audit-anchor
src/hints.ts:96:  return (await readAnchorRecord(logPath)) === null;

On the machine where this was measured that record already keys 15 log paths across 15 directories, none of which any command has ever enumerated. Most are short-lived temp dirs from test runs — which is exactly why a fix has to distinguish gone from stalled rather than alarming on both.

Proposed

  1. kit audit verify --all (or audit anchor --list): iterate the anchor record, verify every chain it knows about, and report paths that are missing or stalled as distinct outcomes with a meaningful exit code. The iteration is the whole feature; the data is already on disk and already 0600.
  2. Thread cwd at one call site. elevation.ts calls appendAuditEventDirect without cwd, so it lands in process.cwd()'s log. That is the same threading the cwd arc did everywhere else, and this call site was missed.

Why (2) matters more than its size suggests: KIT_ELEVATED=1 is documented as the CI escape hatch that "gets audit-logged loudly so a leaked CI env doesn't silently bypass". The warning does go to stderr and the record does get written — but it is written into one of N logs that no command reads together. "Loudly" is a claim about a reader, and the reader is the weak link.

Not proposed

A new gate or policy. The floor is fine; what is missing is a way to read what it already wrote.

Provenance

Found while researching agent session managers that give every session its own git worktree — a workflow that turns "N working trees on one machine" from an edge case into the normal case. The measurements above were taken against 6.6.3.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions