Skip to content

fix(hooks): emit #2410-compliant StepResult fields in hooks receipt reports - #2496

Merged
abrichr merged 1 commit into
mainfrom
gemini/fix-hooks-receipt-main
Nov 22, 2026
Merged

abrichr merged 1 commit into
mainfrom
gemini/fix-hooks-receipt-main

Conversation

@abrichr

@abrichr abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member

Summary

Fixes main CI failure (flow core unit (shard 4/4): test_hooks_e2e.py::test_claude_code_allowed_blocked_and_uncertain and test_codex_asks_by_denying_until_a_person_approves) introduced when #2410 merged right after #2411.

receipt_record.build_statement() now validates each step via StepResult.model_validate(), requires change_ledger, and requires sha256:-prefixed effect_contract_hashes + effect_evidence + valid EffectFieldCheck dicts. hooks/engine.py was still emitting pre-#2410 step dicts, causing write_receipt_record() to fail with ReceiptRecordError: invalid_write_evidence and leave no receipt.json.

Changes

  • packages/flow/openadapt_flow/hooks/engine.py: emit change_ledger: [], step_id, intent, sha256:-prefixed effect_contract_hashes, effect_evidence when read-back settled, and a valid EffectFieldCheck dict when delta == "held".
  • packages/flow/tests/test_hooks_e2e.py: expect field_values in not_checked on the failed-readback UNCERTAIN path (matching Receipts: counterparty confirmations in record/run/v1 #2410's receipt line contract).

Verification

  • ruff check openadapt_flow/hooks/engine.py — passed
  • ruff format --check openadapt_flow/hooks/engine.py tests/test_hooks_e2e.py — passed
  • mypy openadapt_flow/hooks/engine.py — 0 issues
  • pytest -q tests/test_hooks_e2e.py — 4 passed

Generality & Durability

  1. No per-app code in the engine: Yes — no app-specific logic; emits standard StepResult / EffectFieldCheck fields for any declared system.
  2. Fix the class, not the instance: Yes — aligns the hooks receipt producer with Receipts: counterparty confirmations in record/run/v1 #2410's shared StepResult validation contract (matching the sibling fix in feat(plan, proxy): dry-run diff, idempotent apply, verified undo and receipts for agent writes to external systems #2428 for txplan).
  3. Held-out evidence: Not applicable / no new held-out application run claimed; verified by the existing synthetic test_hooks_e2e.py suite.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: a0c67d6

Unique delta versus parent e754d569 is the two-file hooks receipt fix. I reviewed that delta, not the already-merged trees on this branch.

The StepResult.model_validate failure is addressed. Hook reports now include required step_id and intent, an empty change_ledger, effect_contract_hashes with the sha256: prefix the evidence schema requires, effect_evidence when a write was sent and judged VERIFIED or REFUTED, and EffectFieldCheck objects instead of the bare "delta" string. write_receipt_record can therefore emit receipt.json again after #2410 landed on main.

The new fields are consistent with the existing hooks e2e contract, not a strength upgrade invented here. verification_tier: 1 is system-of-record, which matches verify_write (it reads the system of record against the pre-write snapshot) and the already-asserted VERIFIED line (check: confirmed, strength: read_back). effect_field_checks with matched: True is emitted only when result.checked.delta == "held" (the verifier's term for "the declared records were written with the declared values"). The failed-read-back UNCERTAIN path still has no evidence and no field checks; not_checked correctly gains field_values alongside approved_unverified and postconditions. BLOCKED still omits the sent-write effect block.

Residual, not a blocker: REFUTED evidence always sets observed_effect to "absent". That does not let a receipt line become confirmed, but it can over-state absence when the verifier refuted a present-but-wrong record. Expected and observed field values are also omitted from the new EffectFieldCheck (both are optional).

This source review traced hooks/engine.py, receipt_record._line / StepResult validation, verify_write, and the e2e assertions. I did not rerun pytest or CI.

@abrichr
abrichr merged commit 7ea502b into main Nov 22, 2026
51 of 52 checks passed
@abrichr
abrichr deleted the gemini/fix-hooks-receipt-main branch November 22, 2026 01:48
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