Skip to content

Persist immutable committed tool-call arguments for structured stages - #1193

Merged
Kewton merged 2 commits into
developfrom
feature/issue-1182-persist-immutable-committed-tool-call-arguments
Dec 1, 2026
Merged

Kewton merged 2 commits into
developfrom
feature/issue-1182-persist-immutable-committed-tool-call-arguments

Conversation

@Kewton

@Kewton Kewton commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Refs #1182 (close by hand after merge; this PR targets develop).

Summary

  • When a structured-stage tool call is sealed, the committed arguments are kept beside the ledger. Each file is content-addressed, written once and never rewritten. The logic lives in the new leaf src/planner/structured_stages/argument_archive.rs.
  • Arguments that contain a registered secret are not written. Only {"arguments_sha256":…,"withheld":true} is kept, as the user decided (option A, 2026-12-01). No cleanup mechanism is added.
  • The seal is recorded only after its argument file is written (0d67ed9). A failed write therefore never leaves a sealed record without its file. This was the REJECT on the first commit.
  • The ledger schema, envelope, signature and event names are unchanged. loop_run.rs and runner.rs are untouched, and no guardrail baseline is raised.
  • docs/dev/structured-stages.md describes where the files go, what they hold, the withheld form and the no-delete rule.

Verification

  • commandmate verify run 835 on 0d67ed9: exit 0, 17 gates pass.
  • Linux clippy: 0 warnings.
  • Two-point tests:
    • A compacted session still matches the kept arguments. This test fails on the base.
    • A failed write leaves no file-less seal. This test fails on d639cd4.
  • Review: claude-5, standing in while codex was at its usage limit, gave REJECT on the first commit, then APPROVE after the fix.

🤖 Generated with Claude Code

Kewton and others added 2 commits December 1, 2026 20:55
Issue #1182: a sealed stage's arguments_sha256 is kept in ledger.json, but
the tool-call bytes it covers live only in the conversation, which compaction
under context_budget can drop. A later audit then cannot reproduce the match.

Write the exact bytes the digest covers to arguments/<arguments_sha256>.json
beside ledger.json, under the same lock, owner-only permissions, O_NOFOLLOW,
and temporary-then-rename write. The file holds serde_json::to_vec bytes of
the call's asked arguments (expected_revision removed), so sha256(file) equals
arguments_sha256. Only a sealed commit writes it; a call carrying a registered
secret value withholds the bytes and keeps only the digest and a withheld mark.
A file is written once and never removed.

判断: 提案1のみを実装し、run_trace.rs と musubi-ca-pack 側の追従は Non-goals どおり変えない。
判断: 本文の「秘密はユーザー確認中」に対し既定案(登録済み秘密検出時は bytes を書かず digest と withheld のみ)を採った。

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
Issue #1182 review (blocker): record_commit_archiving sealed in ledger.json
first and wrote the argument file second, so a failed file write left a
sealed record on disk with no file for its arguments_sha256. Resume would not
write it, and the failure sat outside apply so StageLedger::failed stayed
clear.

Decide the commit on a copy of the machine, write arguments/<digest>.json under
the same lock only when the decision is Sealed, and only then persist the
record. A failed write ends the call without recording the seal, and the ledger
keeps no state it cannot vouch for. A commit that does not seal leaves a file
nothing refers to; a later call with the same digest reuses it (write-once), so
no seal exists without its file.

Also make an existing arguments directory owner-only (0700) on write, and align
the docs with the actual order.

Tests: a_failed_argument_write_leaves_no_sealed_record (arguments turned into
a plain file between turns: the failed call is not sealed), and a unit test
that an existing directory with another mode is corrected. Each fails on the
previous order and passes now.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
@Kewton
Kewton merged commit ccee868 into develop Dec 1, 2026
9 checks passed
@Kewton
Kewton deleted the feature/issue-1182-persist-immutable-committed-tool-call-arguments branch December 1, 2026 16:15
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