Skip to content

fix(flow): count a P7 fallback as no-write only when nothing changed anywhere - #2528

Merged
abrichr merged 1 commit into
mainfrom
claude/acp-ledger-outside-run
Nov 22, 2026
Merged

abrichr merged 1 commit into
mainfrom
claude/acp-ledger-outside-run

Conversation

@abrichr

@abrichr abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member

P7 (#2491, wrap/fallback.py _nothing_written) treats a fallback run as a possible write in two cases: a change to another record during the run (outside_run), or a record check with no outside_run at all. Either way it reports RECONCILIATION_REQUIRED. The merged run ledger never read outside_run. It could count a declined or refused fallback as "nothing written" (ESCALATED person_declined, or FAILED policy_rejected_no_write) when P7 says a person must reconcile. It also took a fallback as VERIFIED from the record check alone.

Changes (run_ledger/readers.py, run_ledger/collect.py)

  • A P7 record check proves "no write" only when it is readable: true, its created, changed and removed counts are 0, and every outside_run count is 0. A missing outside_run proves nothing; such a run is UNKNOWN write_unconfirmed.
  • A fallback is VERIFIED only when P7's own record agrees: fallback.status is VERIFIED, and so is run_status when P7 keeps one. Otherwise the run is UNKNOWN reconciliation_required.
  • The same rule applies to the result.json, the dispatcher envelope and the wrap run-store record of the fallback.
  • RUN_LEDGER.md's fallback table is updated.

Tests

tests/test_run_ledger_joins.py, using real P7 result.json files from fixtures/run_ledger/run3_fallback:

  • Unchanged, the approved run is VERIFIED and the declined run is ESCALATED person_declined.
  • The declined run with an outside_run write, or with no outside_run, is UNKNOWN write_unconfirmed.
  • The approved run with P7 status RECONCILIATION_REQUIRED, or with run_status GATE_NOT_PROVED, is UNKNOWN reconciliation_required.
  • A wrap run-store record whose P7 status disagrees is UNKNOWN reconciliation_required.

Local checks: flow ledger suites plus the capabilities map, 226 passed; types run_ledger, 19 passed; ruff, mypy, gitleaks and the engine-generality check are clean.

…anywhere

P7 (#2491) treats a change to another record during a fallback run
(outside_run), or a record check without outside_run, as a possible write
and reports RECONCILIATION_REQUIRED. The run ledger now agrees:

- A P7 record check proves "no write" only when it is readable, its
  created/changed/removed counts are zero, and every outside_run count is
  zero. A missing outside_run proves nothing.
- A fallback is VERIFIED only when P7's own record agrees: fallback.status
  is VERIFIED, and so is run_status when kept. Otherwise it is UNKNOWN
  (reconciliation_required). The same holds for a wrap run record of the
  fallback.

Tests use run3's real result.json files, as they are and with an
outside_run write, a missing outside_run, or a disagreeing status.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 4bb1109

Author declaration for this head. Claude wrote the changes on this branch. It makes the run ledger agree with P7 (#2491): a fallback record check proves no write only when it is readable, its counts are zero and every outside_run count is zero, and a fallback is VERIFIED only when P7's own status agrees; otherwise the run is UNKNOWN.

Local checks on this head: flow ledger suites plus the capabilities map, 226 passed; types run_ledger, 19 passed; ruff, mypy, gitleaks and the engine-generality check clean.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude (independent reviewer)
Reviewed-Head: 4bb1109

I read the diff against main and compared the ledger's _nothing_written with the producer in #2491 (packages/flow/openadapt_flow/wrap/fallback.py _nothing_written, _run_agent) and with task_record_check in integrations/agents/skills.py. The ledger copy now matches the producer: a readable check, zero task counts, and an outside_run mapping with zero counts, where a missing outside_run means "something may have been written". policy_agrees only narrows when VERIFIED is booked, so it fails closed (a missing status, a run_status: null from the pre-start record, or a _crashed record all go to reconciliation_required). On an exported copy of the head, the four run-ledger test files pass (223 passed, 1 skipped). With main's readers.py and collect.py swapped back in, the five new negative tests fail, so they test the change.

Blockers

None.

Nits

  • packages/flow/openadapt_flow/run_ledger/collect.py:627: the function-level import of policy_agrees is there to avoid an import cycle (readers imports collect). A one-line comment would stop someone hoisting it later. Moving policy_agrees into collect.py next to _int and importing it from readers would also work.
  • packages/flow/tests/test_run_ledger_joins.py:1098: the outside_run tests cover GATE_REFUSED only. COST_CAP_EXCEEDED (policy_rejected_no_write) goes through the same nothing_written branch, and one case for it would pin that row of the table.
  • packages/flow/docs/RUN_LEDGER.md:228: the outside_run sentence sits in the GATE_REFUSED/COST_CAP_EXCEEDED UNKNOWN row, but it also defines "no write" for the two rows that use that phrase (person_declined, policy_rejected_no_write). A short note under the table would make that clearer.
  • Pre-feat(flow): per-run accounting ledger for any executor #2478 declines that have no outside_run now book as UNKNOWN (write_unconfirmed) instead of ESCALATED. That is the right way to fail, and the docs say so. A CHANGELOG line would tell anyone comparing older ledgers why those counts moved.

@abrichr
abrichr merged commit b2cbb73 into main Nov 22, 2026
56 of 57 checks passed
@abrichr
abrichr deleted the claude/acp-ledger-outside-run branch November 22, 2026 10:06
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