Repository navigation
fix(handoff): encrypted runs hand off their receipt card; sandbox runs refuse and say why - #2830
Conversation
… set; refuse sandbox runs and say why A strict at-rest run already gets a receipt: receipt.json is a plaintext structural file of the sealed set. The public card (receipt.card.json) is sealed with the run, and receipt_for_run read it as plaintext, so get_handoff with public=true failed on every encrypted run. It now reads through sealed_set, in memory, and writes nothing. public_reveal reads the report the same way, so an encrypted tutorial run's card opens the same fields as a plaintext one. Sandbox runs stay receipt-less: record/run/v1 has no field that marks a run as synthetic, and the key's role lives in the receiver's registry, not the signed statement. get_handoff now refuses mode=sandbox results before reading any run folder, with a message the A2A text part carries. Docs: A2A.md 'When a run has no receipt' no longer lists strict runs; HANDOFF_RECEIPTS.md and the A2A capability row updated.
…t strict runs through the bridge receipt_for_run reads receipt.json as it is again (plaintext on disk, no key needed) and uses the sealed set only for the sealed public card. New tests: no-key strict run (receipt travels, card refuses clearly), a strict sealed run through the bridge's get_handoff, and the encrypted tutorial card opening the same fields. The e2e fixture's report now has a change ledger and effect evidence, so its receipt is VERIFIED as the test expects (it said UNKNOWN: incomplete_write_coverage).
Keeps this branch's change-ledger fixture, so the e2e receipt is VERIFIED again, and combines both capability-row updates.
… feat/handoff-receipt-coverage
Independent adversarial review: REQUEST CHANGESFrom: Codex
At this head, 24 agent tests and five Flow at-rest tests passed. They covered encrypted public-card readback, refusal without the card key, and sandbox refusal over the bridge and A2A. The bridge suite used a stubbed Flow process with real sealed storage and signing. |
…m the stored mode A receipt is attached only when its signed report.json digest matches the run's own report, read through the sealed set; a receipt from another run signed by the same key is refused (receipt_run_mismatch), and an encrypted run without its at-rest key is refused (run_report_unreadable). get_handoff now requires the stored run record to be finished with an attended or production mode that matches the result. RunService results carry the record's original mode, so an interrupted or refreshed run reopened under another mode keeps its sandbox provenance.
… feat/handoff-receipt-coverage
Independent adversarial review: REQUEST CHANGESFrom: Grok I re-reviewed this exact head (R2 after Codex's REQUEST CHANGES at Codex findings at this head
What still has to change
Tests I ran at this exact head
Generality: no per-app engine code. Run-to-receipt binding and mode eligibility are generic over any sealed or plaintext run. Evidence is synthetic local fixtures only (a stubbed Flow process with real sealed storage and signing). No real outside-party or production handoff is claimed. CI at this head
|
…ipt-coverage; regenerate pages
Independent adversarial review: APPROVEFrom: Grok I re-reviewed this exact head (R3 after my REQUEST CHANGES at Previous blocker at this head
Codex findings (unchanged since
|
|
From: Grok #2866 is now on main ( My approval of this head is unchanged: #2830 (comment) |
Independent adversarial review: APPROVEFrom: Grok I re-reviewed this exact head (R4 after my APPROVE at What changed since
|
Independent adversarial review: APPROVEFrom: Grok I re-reviewed this exact head (R5 after my APPROVE at This head is a clean merge from Generality gate
Tests I ran
CI at this head
|
What was found
packages/flow/docs/A2A.md("When a run has no receipt") listed three kinds of run that hand off with no receipt. Two were checked.Strict at rest (
OPENADAPT_FLOW_AT_REST=strict): the doc was stale, but there was a real bug under it. Flow does write the receipt for an encrypted run.receipt.jsonis a plaintext structural file of the sealed set, asphi_at_rest.mdsays. However, the public card (receipt.card.json) is not on the structural list, so it is sealed with the run (receipt.card.json.enc).handoff.receipt_for_run(public=True)read it as a plain file, soget_handoffwithpublic: truefailed on every encrypted run with "no receipt.card.json in that run folder".public_revealhad the same plain read ofreport.json, so an encrypted tutorial run's card silently opened fewer fields than a plaintext one.Sandbox runs: the gap is real, and I left it closed on purpose. A
record/run/v1receipt has no field that marks a run as synthetic. Thedemorole lives in the receiver's key registry, not in the signed statement. A sandbox receipt signed with this computer's key would therefore read like proof about a real system. The only no-schema way to mark it would be to downgrade the outcome to UNKNOWN with a made-up reason code, and receivers would not read that as "synthetic". So sandbox runs stay receipt-less. Before this PR the A2A text part said something unhelpful ("no such run in the server's runs directory" or "no receipt.json in that run folder"). Nowget_handoffrefuses anymode: "sandbox"result before it reads a run folder, and says why.What changed
openadapt_flow/handoff.py:receipt_for_runstill readsreceipt.jsonas a plain file, so it needs no at-rest key. Withpublic, on a sealed run it opens the card throughsealed_set, in memory. Nothing is written.openadapt_flow/receipt_record.py:public_revealreadsreport.jsonthroughsealed_set.openadapt_flow/agent/handoff_tools.py: addsSANDBOX_NO_RECEIPT;getrefuses sandbox results before touching the run folder.A2A.md,HANDOFF_RECEIPTS.md, the A2A capability row, plus regeneratedCAPABILITIES.mdandllms-full.txt.llms-full.txtalso picked up some unrelated drift from main when regenerated.packages/agent/tests/test_handoff_e2e.py: the bridge fixture's report now haschange_ledger: []and effect evidence. Without them the receipt is correctly UNKNOWN (incomplete_write_coverage), andtest_a2a_run_carries_its_receipt...failed locally on main.Tests
New:
packages/flow/tests/test_handoff_at_rest.py(5): a real sealed strict run. The receipt is written byreceipt_after_run. The statement matches a plaintext run of the same report (salted commitments excluded), for both receipt and card.get_handoff+verify_handoffare intact and VERIFIED.verify_allpasses, and no non-structural file holds plaintext. With no at-rest key, the receipt still travels and the card refuses with a clear message. A tampered receipt is refused. An encrypted tutorial card opens the same fields as a plaintext one.packages/agent/tests/test_handoff_at_rest_bridge.py(2): a strict sealed run throughAgentBridge.dispatch("get_handoff"). The Flow process is stubbed; the sealed set and receipt hook are real.packages/agent/tests/test_handoff_sandbox.py(3): a simulated sandbox run is refused over MCP, even with a real signed receipt planted in its folder. Over A2A, the artifact has no handoff part and carries the reason as text.Before the fix, the card case and the no-key case failed.
Runs:
-k "handoff or sandbox or a2a": 38 passed, 5 skipped.tests/test_build_capabilities.py: 12 passed.OPENADAPT_TEST_DEFAULT_AT_REST=1.test_handoff_e2e.pyalready failsruff format --checkon main; I did not reformat it.Not covered
mode, so it covers both.openadapt_flow/tutorial.pyalready writes a signed receipt for synthetic tutorial runs (VERIFIED when the check passes), with no in-statement synthetic mark. That is out of scope here, but it is the same concern as the sandbox case. A backward-compatible field inrecord/run/v1would let both carry an honest receipt, and it needs a separate decision.OPENADAPT_RECEIPT=offruns are unchanged (operator choice).hypothesisor Playwright were not run in this environment.Stacked on #2828
This branch merges
feat/a2a-signed-agent-cardand targets it, so merge #2828 first; GitHub retargets this tomainafterwards. The merge keeps this branch's change-ledger fixture, sotest_handoff_e2e.pyasserts VERIFIED again (#2828 alone asserts UNKNOWN for its no-ledger fixture). Combined local run: agent handoff/A2A/sandbox/mailbox tests 56 passed; Flowtest_handoff_at_rest.py+test_handoff.py33 passed.