Skip to content

feat(flow): per-run accounting ledger for any executor - #2478

Merged
abrichr merged 21 commits into
mainfrom
claude/acp-P2-accounting-ledger
Nov 22, 2026
Merged

abrichr merged 21 commits into
mainfrom
claude/acp-P2-accounting-ledger

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

What

One value-free accounting row per run, for any executor: an OpenAdapt agent, a compiled program, another vendor's agent, or a person. A row records the outcome, a closed reason, a person's minutes, model calls and cost, field names with their checks, and the read-back tier. Values stay in a local 0600 sidecar.

  • openadapt_types.run_ledger: openadapt.run-ledger/v1 (RunLedgerRowV1) and the Cloud shape openadapt.agent-run-summary/v1 (AgentRunSummaryV1, the row without sources). Every string field is closed by a pattern or enum, and a test walks both JSON Schemas to keep it that way. Each reason belongs to exactly one bucket. VERIFIED needs an independent read-back. intervention_s is null whenever an interval is open.
  • openadapt_flow/run_ledger/outcome.py: the outcome rule. Precedence is CAUGHT_ERROR > UNKNOWN > ESCALATED > FAILED > VERIFIED. A model's or agent's own judgement only counts when no deterministic source speaks, and it never yields VERIFIED.
  • collect.py: one reader per source, reading files only. It never edits a producer.
    • On main: agent guard summary.json and guard_events.jsonl, verify-run effect-receipt.json, a compiled run's report.json and receipt.json, wrap's openadapt-agent.run/v1 records, item-approval request and answer files, task-ledger questions, and compile-agent's run1.json / agent_ledger.json.
    • Contract sources: proposed_write.json, scorecard.json, flight.json, guard_ledger_row.json and exceptions/answer-*.json.
    • A collector that finds a schema version it doesn't know makes the row UNKNOWN (schema_unrecognised).
  • store.py: $OPENADAPT_HOME/ledger/rows.jsonl, append-only. Writes are atomic under a lock. Rows are deduped on (task id, digest of the source files).
  • cli.py: the new verb openadapt-flow ledger with add, list, show [--show-values], summary, export, push.
    • export and push refuse when any sidecar value appears in the output.
    • When openadapt-privacy's scrubber is installed, they also refuse a label it would rewrite.
    • push refuses before anything else when OPENADAPT_API_KEY is not set, and goes through the hosted destination policy.
  • Docs: packages/flow/docs/RUN_LEDGER.md and docs/commands/07-proof/ledger.md. CAPABILITIES gets one row after "Signed write receipts" plus the regenerated command map. llms-full.txt is regenerated.

No producer module is touched: agent_guard, verify_run, wrap, receipt, approval_mode and agent/ledger are unchanged.

Tests

All synthetic.

  • The outcome table covers every member of TransactionOutcome, ExecuteTerminalOutcomeV1, ExecutionOutcome, GuardVerdict, and the agent RunOutcome.status values. It also covers each contract source.
  • Fixture run directories exist for each collector.
  • End to end, the real CommitGuard drives MockMed's fault server on localhost. The cases are a verified save, a save on the wrong record, the wrong record on screen (blocked), a held approval (ESCALATED, time unknown), and an approved save (VERIFIED, wait counted).
  • A refuted read-back plus an agent ledger saying it finished gives CAUGHT_ERROR.
  • An unknown schema gives UNKNOWN.
  • The export is scanned for every fixture value.
  • push with no key is refused, and the test asserts that no request was attempted.

Local results at ec6fc55 (through the CPU-slot runner): flow ledger, CLI-naming, task-view and capabilities-map tests 164 passed; openadapt-types 859 passed; mypy on run_ledger/ clean; ruff clean; the size ratchet against origin/main adds no lines to __main__.py.

Changes after the first CI run

  • Released installs. run_ledger/__init__.py and cli.py no longer import the types schema when the parser is built, so openadapt-flow --version still starts on an install whose openadapt-types predates run_ledger (the on-prem offline job). ledger itself then says to upgrade openadapt-types. A test covers this.
  • Windows. The store locks through fleet._lock.exclusive_lock (flock or msvcrt.locking) instead of fcntl, and skips fchmod where it doesn't exist (the Desktop Windows replay job).
  • Scrubber. export and push refuse when the text scrubber can't run (for example, a missing spaCy model) instead of crashing. The CLI tests use a stand-in scrubber, so they don't need the model.
  • __main__.py. The ledger registration joins the admit/check/api/deferred block, so the file's size doesn't change.

Files outside the original list, each needed by an existing test:

  • openadapt/cli_tasks.py and packages/flow/openadapt_flow/cli_tasks.py: "ledger": "inspect ledger" (test_cli_tasks.py requires every verb to have a task name; verify ledger is already the protected-write ledger).
  • packages/types/openadapt_types/vocabulary/outcomes.json: RunLedgerOutcome set aside as an accounting bucket (test_plain_outcome.py).

Integration follow-ups

One value-free openadapt.run-ledger/v1 row per run (agent, compiled
program, third-party agent or person) with the VERIFIED / ESCALATED /
CAUGHT_ERROR / FAILED / UNKNOWN outcome rule, intervention intervals,
model usage (unknown is null), field checks and read-back tier. Values
stay in a local 0600 sidecar. Collectors read the files agent guard,
verify-run, compiled runs, wrap, item approvals, the task ledger and
compile-agent already write, plus the shadow, flight, gate and exception
contract files. New verb: openadapt-flow ledger add/list/show/summary/
export/push.
Merge main. Register the ledger verb without importing the types schema,
lock the store with the shared flock/msvcrt helper, refuse an export when
the scrubber cannot run, list the verb as 'inspect ledger' in both task
tables, set RunLedgerOutcome aside in outcomes.json, and keep __main__.py
within its line budget.
Join the deferred and ledger registrations to the admit/check/api block so
__main__.py stays at its base size.
…eption files

The end-to-end run on 2026-11-21 found every join broken. The ledger now
reads what each producer really writes, from committed copies of their
synthetic artifacts:

- Readiness shadow runs (J1): a folder with a readiness run.json is read as
  one source (run.json, proposed_write.json, case.json, usage.json,
  egress.json). Never VERIFIED; a match is ESCALATED (shadow_matched); a
  mismatch or wrong record is CAUGHT_ERROR; no case.json is UNKNOWN. The
  shadow hold's guard_ledger_row.json is ignored.
- Guard rows (J3): the row's verdict is no longer a bucket source, and
  fields_differing is read as a list of names.
- A person declining is ESCALATED (person_declined), not CAUGHT_ERROR or
  unmapped_outcome, unless a refuted read-back or field diff shows an error.
- An effect receipt's REFUTED counts as a catch only when the store shows a
  write, as the guard's own verdict rule does. A halt before the save and a
  save that never landed are no longer CAUGHT_ERROR.
- P6 exception answers (J4) are read from $OPENADAPT_HOME/exceptions/<run_ref>
  (ledger add --run-ref).
- P7 fallback results and dispatcher envelopes (J5) have a reader; a refused
  gate is a decline, the nested agent attempt isn't read again.
- A failed, timed-out or errored run with no evidence nothing was sent is
  UNKNOWN (write_unconfirmed), not FAILED.
- export and push let through field names the run's guard task, verify.yaml
  or readiness reference declares (patient_id); any other name the scrubber
  rewrites still refuses.
- Real push --dry-run output is committed as
  packages/types/tests/fixtures/agent_run_summary_v1_examples.jsonl and
  validated against the JSON Schema.
- The dispatcher envelope is WrappedTask.call's result plus finish()'s
  outcome and fallback, with no replay or compile. The reader takes the
  record check from the envelope's fallback, and the fixtures are rebuilt
  with P7's own _result and finish.
- A wrap run record whose result path is agent_fallback reads like an
  agent's first run.
- A guard ledger row is never a bucket source (J3); its differing fields
  show as "differs" and summary.json decides.
- A FAILED_SCOPE readiness case, or one with no proposal, declares none of
  the proposed field names, and a guard task for another task id declares
  nothing.
- No exception folder is guessed from the run directory's name; P6's run
  reference is only given with --run-ref.
- The real-scrubber test skips when the scrubber can't run.
… egress

- The shadow fixtures are now P1's committed samples (matched, mismatched,
  extra-target) and P3's real scrubbed-mode egress.json.
- run.json EXTRA_TARGET is UNKNOWN (shadow_extra_target) and
  EGRESS_REFUSED, or egress.refused, is UNKNOWN (egress_refused). A healthy
  --egress blocked run, which also says mode "blocked", stays as compared.
- run.json's egress copy is read when there is no egress.json.
- A row with no person intervals has intervention_s null (unknown) unless
  a source shows nobody was asked: a shadow hold, a not_gated guard run, a
  flight with no gate events. The types schema allows null with no
  intervals, and 0 or null only.
- The J6 examples are regenerated, now with P1's samples.
…read P5's new row

- A row's task_id passes the scrubber check only when the run's own files
  name it: a readiness run.json or case.json, or a guard task whose task_id
  matches. Presidio reads P1's readiness-mockmed-0002 as an organisation;
  that sample now exports, and the same id given only with --task-id still
  refuses.
- A P7 record check proves no write, or confirms a save, only with
  readable: true. A VERIFIED fallback whose check isn't readable is UNKNOWN
  (reconciliation_required); a refused gate without it is UNKNOWN
  (write_unconfirmed). New fixtures carry record checks built with P7's own
  task_record_check at 3b73d09.
- The guard row fixtures carry P5's d0a1e92 keys (guard_verdict,
  verdict_reason) and mapping, plus two rows from P5's own tests. The row is
  still not a bucket source.
- The J6 examples are regenerated.
…s approvals

From the integrated run2 (2026-11-22):

- export and push screen each row: a row the scrubber or the sidecar scan
  refuses stays local and is listed with its reason, the rest still go, and
  the command exits 2. A scrubber that can't run still refuses everything.
- P7's own result.json or envelope declares its request id (or task key),
  so fallback rows no longer refuse on task_id.
- started_at and ended_at come from the wall-clock moments the run's files
  record (approval files, a shadow hold, the egress timeline, a read-back's
  issued_at, exception cards) when no source keeps the run's own start and
  end. They stay null only when no source records a moment.
- ledger add --approvals DIR reads an item-approval fallback's request and
  answer from DIR/<fallback request id>/item-approval, so the person's time
  on an approved or declined fallback is known. A result.json's record
  check names the new record's fields; the row keeps those the run's
  verify.yaml declares.
- Readiness runs that proposed nothing get shadow reasons
  (shadow_no_proposal, shadow_timed_out, shadow_agent_error), never a
  production FAILED reason.
- New fixtures are copies of run2's real artifacts; the J6 examples are
  regenerated.
P3 now writes egress/pseudonyms.json with real values in plaintext. The
ledger no longer opens anything it doesn't know: only the producer files it
has readers for, item-approval requests and answers, task-ledger jobs, wrap
run records, the egress timeline and the run's own task.json,
guard_task.json and verify.yaml. Any other file is never read, hashed into
the run digest, copied to a sidecar, exported or pushed. A file named
directly must be one of these, a run-*.json record or a dispatcher result,
and --config takes only a guard task or a verify.yaml.

A test plants a name in pseudonyms.json and in a stray file, both chmod 000,
and checks that neither is opened or appears in a row, sidecar, export or
push payload.
From run3 (2026-11-22):

- A P6 exception a person cleared (continue or done_by_person) is no
  bucket source, like an approved approval: the run's own result decides,
  so a save read back independently is VERIFIED. The person's time stays
  in human.intervals. A stopped, expired or open exception is ESCALATED.
- Shadow rows have no fields_written or fields_differing: a shadow run
  writes nothing.
- Start times: a guard run is placed by its held save (the approval's
  created_at minus the guard's t); a guard run without a card uses its
  recording's meta.json created_at; a shadow hold uses held/<n>.json
  held_at; a dispatcher envelope uses wrap's run store record
  runs/<run_id>.json.
- A guard run that ended by timeout after its last save decision is
  measured to that decision (the decline row was 60.1 s, now 5.9 s).
- A fallback envelope finds its own item-approval folder, result.json and
  the task's confirmed compiled/verify.yaml by its fallback request id, so
  the approved row has the person's time and the fields written; an answer
  bound to another request is UNKNOWN.
- P5's values_unread is a closed ESCALATED reason.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 5d0dc3d

Author declaration for this head. Claude wrote the changes on this branch. This PR adds openadapt-flow ledger, which books one row per run from the files any executor leaves (guard, shadow hold, flight, exception queue, fallback and compiled replay) into one of five buckets, and exports or pushes rows only after a scrubber check. This head adds 89d0bd9 and a merge of main to af6d543, the head run 3 tested. 89d0bd9 counts an exception a person cleared followed by an independently read-back save as VERIFIED, gives shadow rows no written fields, fills more start times, measures a guard run that timed out to its last save decision, and joins an approved fallback to its own approval and result.

Local checks on this head: no test count is recorded for 5d0dc3d. The ledger suites are test_run_ledger_cli.py, test_run_ledger_collect.py, test_run_ledger_joins.py, test_run_ledger_outcome.py and packages/types/tests/test_run_ledger.py. Run 3 ran them at af6d543 inside integration tree 128faaec3, with every unit test file the six PRs add plus test_cli_tasks.py and test_capabilities_map.py, single-process: Flow 741 passed across 29 files, Types 38, Desktop 32 and Launcher 5, with no failures. There, ledger add booked 36 runs as 36 distinct rows, ledger export --require-scrubber wrote 36 rows, and ledger push sent 36 of 36 to the Cloud dev server with no refusals.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Gemini
Reviewed-Head: 5d0dc3d

A review of the per-run accounting ledger PR. The ledger correctly reads the files left by the agent control plane pieces, maps their outcomes to the five buckets, and keeps values in a local sidecar. However, there is a privacy leak when pushing to the cloud without the scrubber, and a correctness bug where answering a question prevents a run from being VERIFIED.

BLOCKER

  1. Privacy leak on push without the scrubber: In packages/flow/openadapt_flow/run_ledger/cli.py:124, cmd_push calls _scrubber(False). This means if openadapt-privacy is not installed, push skips the scrubber check and sends the rows to the cloud anyway. Since task_id, task_type, and executor_label can contain PHI, sending them unscrubbed violates the rule "no personal or health data leaves the machine unscrubbed". push must require the scrubber or fail closed if it is missing.
  2. Correctness bug (a question asked overrides VERIFIED): In packages/flow/openadapt_flow/run_ledger/collect.py:718 and :760, collect_item_approvals and collect_task_ledger unconditionally emit question_asked (which maps to ESCALATED) whenever a question is asked, even if it was answered. Because ESCALATED outranks VERIFIED, a run where a person answered a question and the agent then successfully verified a save will be booked as ESCALATED. This contradicts the docs ("A person who helped, then a verified save, is VERIFIED").

NIT

  1. Correctness bug (unauthenticated exception clearance): In packages/flow/openadapt_flow/run_ledger/collect.py:1022, collect_exception_answer requires approver_kind == "person" to consider an exception cleared. If an unauthenticated person clears the exception (approver_kind == "unauthenticated"), it emits exception_card (ESCALATED), preventing the run from being VERIFIED. Item approvals do not check approver_kind this way.

Earlier findings at this head

  • Process blocker: P1 (box 2) is not pushed: Still open (P1 is not pushed).
  • 1. The "0 writes landed" result can be bypassed with a second tab: Fixed (the adversarial run is now EXTRA_TARGET and NOT_CHECKED).
  • 2. The contamination check cannot see prefilled form values: Still open.
  • 3. Identifiers with leading zeros compare as equal: Still open.
  • 4. Extra held writes don't affect the verdict: Still open.
  • 5. Model cost is whatever the agent reports: Fixed (the ledger uses the proxy's metered cost when available).
  • 6. Service-worker requests and other off-tab traffic are not paused: Still open.
  • 7. The commit gate uses a blocklist of ten English verbs: Still open.
  • 8. An icon-only Save button can pass the gate: Still open.
  • 9. Autosave on blur, on change or on Tab never go through a "commit click": Still open.
  • 10. The scrubber passes some text through unscrubbed: Still open.
  • 11. Bypassing the proxy produces only a warning: Fixed (the ledger marks EGRESS_REFUSED as UNKNOWN).
  • 12. The scrubber blinds the agent: Still open.
  • 13. Some crash and timeout paths record "no write" without evidence: Fixed (the ledger maps these to write_unconfirmed / UNKNOWN unless there is evidence).
  • 14. P1's scorecard.json is refused by P4's parser: Fixed (the ledger row is now the contract).
  • 15. Rows are trusted on the ingest token alone: Still open.
  • 16. There is still no VERIFIED path without a database or API: Still open.
  • 17. P6 raise_exception is cooperative: Still open.
  • 18. The fallback's default TerminalGate refuses when there is no TTY: Still open.

Verdict: REQUEST CHANGES

- ledger push refuses when openadapt-privacy's text scrubber isn't
  available or can't run, as export --require-scrubber does; rows leave the
  computer, so the label check always runs. push --dry-run, which sends
  nothing, still only warns.
- P5's guard block code values_unread (the card couldn't show the values,
  so no one was asked) is ESCALATED values_unread. The fixture is P5's own
  summary and row from its unit test at 6fa9c3a.
- RUN_LEDGER.md says why an answered question stays ESCALATED: the ledger
  never reads the answer text, so it can't tell a go-on from a stop.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: b4e63aa

Author declaration for this head. Claude wrote the changes on this branch. Since 5d0dc3d this head fixes the blocker in the Gemini review: ledger push refuses when the text scrubber is missing or can't run (a dry run still only warns). It also maps the guard block code values_unread to ESCALATED, and RUN_LEDGER.md now says why an answered question stays ESCALATED.

Local checks on this head: the flow ledger suites plus the capabilities map, 219 passed; types test_run_ledger.py, 18 passed; ruff, mypy and gitleaks clean. tests/test_cli_tasks.py has 1 failure that needs openadapt-agent, not installed locally.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Claude (independent reviewer)
Reviewed-Head: b4e63aa

I read the code in run_ledger/ (cli, store, collect, readers, outcome), openadapt_types/run_ledger.py, RUN_LEDGER.md and the new tests. I ran two probes against the head in a scratch home with a stub poster; nothing went over the network. The earlier review's first blocker (push without the scrubber) is fixed: push() now refuses when there is no scrubber and it isn't a dry run (cli.py:515), and a test covers it. Its second blocker (an answered question stays ESCALATED) wasn't changed in the code, but RUN_LEDGER.md now documents it (lines 94-98). Reporting ESCALATED where VERIFIED was possible undercounts without failing open, so I accept that.

Blockers

  1. The scrubber skips any task id the run's own files name, including one the calling agent picks, and the row then goes to Cloud. collect_fallback_result declares the envelope's request_id (readers.py:409-414), and _screen_one skips the scrubber for declared ids (cli.py:407-408). For wrap-dispatch/MCP, the caller supplies request_id (wrap/mcp.py:65). That caller is the third-party agent, not the operator, and the id can be any 128-character string. Probe: I set request_id in a copy of dispatch_envelope_verified.json to refill-jane-doe-dob-1980-02-03, ran LedgerStore.add, then called push() with a scrubber that rewrites jane-doe. The row was sent with that task id and nothing was refused. The sidecar check doesn't catch it either, because a name inside an id isn't a field value. Readiness run.json/case.json ids and guard-task ids get the same exemption (readers.py:193,271,692). An operator can still build those from the record, for example intake-<MRN>. Fix: send a salted digest of task_id to Cloud and keep the plain id only in the local row, or keep the scrubber check for task ids and refuse the rows it flags. Then update RUN_LEDGER.md lines 316-321.
  2. A row can be VERIFIED while one of its fields differs. collect_guard_ledger_row marks a field differs but emits no signal (collect.py:961-975), and _RowBody._consistent doesn't refuse VERIFIED with fields_differing > 0 (run_ledger.py:336-351). Probe: in a copy of run3_watch, I set the guard row's fields_differing to ["note"] and ran add. The result was VERIFIED readback_verified, with fields_differing: 1 and note: differs. RUN_LEDGER.md says a differing field is CAUGHT_ERROR evidence, and the ledger exists to settle sources that disagree. Fix: make a differing field from a deterministic source emit readback_refuted (or at least reconciliation_required), and have the schema refuse VERIFIED with fields_differing > 0.

Nits

  • collect_agent_guard (collect.py:387-395): with no verdict, nothing blocked and no guard_events.jsonl, the reason is a *_no_write one (FAILED) unless top-level hold_ms is non-empty. requests.save/saves_held aren't consulted. Unless the guard always fills hold_ms for a save that went through, this breaks the "no write needs evidence" rule. Use write_unconfirmed when requests.save > 0.
  • The wrap run record path (collect.py:628-634) takes verified: true on path: agent_fallback as an independent read-back without the readable: true check that fallback_reason requires for result.json. This is documented, and it relies on P7's flag already meaning that, so a test pinning it would help.
  • export runs without the scrubber by default (cli.py:466), and the scrubber label check never sees sources. The sidecar-value check does cover them, but folder names such as fallback/<task>/<id> aren't scrubbed. The export file is also written with the default umask, not 0600 (cli.py:474).
  • The sidecar check is case-sensitive and ignores values shorter than 3 characters (store.py:125, cli.py:419). _label lower-cases executor_label, so Smith doesn't match smith.
  • latest_entries keys on (task_id, run_ref) (store.py:440), so adding the same run again with a different --task-id keeps both rows, and summary and push count the run twice.
  • The real-Presidio test skips when the spaCy model is missing (test_run_ledger_joins.py:497). CAPABILITIES' "checked with the real Presidio scrubber" holds only where that model is installed.
  • collect_item_approvals docstring indentation is broken (collect.py:651-660).

…ffering field

From the independent review of #2478 at b4e63aa:

- A caller can choose a task id (a wrap-dispatch request id is the calling
  agent's), so the declared-task-id exemption is gone. When the scrubber
  would rewrite a task id, the row leaves with tid-<16 hex>: HMAC-SHA256 of
  the id under a per-install key in $OPENADAPT_HOME/ledger/task-id.key
  (0600). The same task still groups together; the local row keeps the id.
- A field that differs, from any source, makes the run CAUGHT_ERROR
  (readback_field_differs, a new closed reason) even when another source
  says VERIFIED, and the schema refuses VERIFIED with fields_differing > 0.
- A guard run with no guard_events.jsonl is a no-write failure only when
  requests.save shows zero saves; otherwise UNKNOWN (write_unconfirmed).
- A wrap record of an agent fallback counts verified: true only with a
  record_check that is readable and passed.
- ledger export always requires a working text scrubber and writes its
  file 0600.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 0a886f1

Author declaration for this head. Claude wrote the changes on this branch. Since b4e63aa this head fixes the two blockers in the independent review: a task id the scrubber would rewrite leaves as an opaque per-install HMAC id (tid-...) instead of text, with the declared-id exemption removed for every source; and any differing field makes the run CAUGHT_ERROR (readback_field_differs), with the schema refusing VERIFIED when fields differ. It also makes export always require the scrubber and write 0600, and tightens two no-write and read-back checks.

Local checks on this head: flow ledger suites plus the capabilities map, 219 passed; types test_run_ledger.py 19 passed and the whole types suite 862 passed; ruff and mypy clean. tests/test_cli_tasks.py has 1 failure that needs openadapt-agent, not installed locally.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Claude (independent reviewer)
Reviewed-Head: 0a886f1

I read the run_ledger/ code (cli, store, collect, readers, outcome), openadapt_types/run_ledger.py and RUN_LEDGER.md, with most attention on bfb59fc, the fix commit since b4e63aa. I ran the four flow ledger suites (216 passed, 1 skipped: the real-Presidio test, no spaCy model here) and the types ledger suite (19 passed), plus probes against fixtures in a scratch home with a stub poster; nothing went over the network. Both blockers from the last review are fixed. The caller-chosen request id refill-jane-doe-dob-1980-02-03 is now sent as tid-61a28ef4197f5cb1, and the run3_watch row with a differing note is now CAUGHT_ERROR readback_field_differs. The Gemini blocker on push without a scrubber is still fixed (cli.py:543).

Blockers

  1. A real P7 fallback record is never VERIFIED: the new check reads a key P7 doesn't write. collect_agent_run_record now counts verified: true on path: agent_fallback only when result.record_check is readable and passed (collect.py:619-623, 638). P7's wrap run record keeps that check at result.fallback.task_record_check, and has no result.record_check. The PR's own fixture shows this: run3_fallback/runs/drift-approved/openadapt-agent/runs/run-b480e452....json has verified: true, status VERIFIED, a person's approval, and fallback.task_record_check with readable: true, passed: true, created: 1. build_row on it now gives UNKNOWN reconciliation_required. The test that covers this rule (test_a_wrap_record_of_a_verified_fallback_needs_its_record_check, test_run_ledger_joins.py:350) removes fallback from the envelope and then adds a made-up result["record_check"], so it never sees the real shape. This fails closed, but every verified agent fallback read from its wrap record is booked UNKNOWN, and RUN_LEDGER.md:258-260 documents the key that doesn't exist. Fix: read result.fallback.task_record_check, the same object collect_fallback_result reads (readers.py:403). Assert VERIFIED on the drift-approved record, and correct the doc line.

Nits

  • A task id becomes tid-... only when the scrubber rewrites it (cli.py:424). A caller-chosen id that the scrubber misses, such as a bare record number, still goes to Cloud as text. Always sending the HMAC id would be simpler and wouldn't depend on Presidio's recall. The local row could keep the plain id.
  • Still open from the last review: the sidecar value check is case-sensitive (cli.py:429). latest_entries keys on (task_id, run_ref) (store.py:442), so re-adding a run with another --task-id counts it twice. The CAPABILITIES "real Presidio scrubber" check skips where the spaCy model is missing.
  • export still writes sources, which the label check never sees. In the fixtures these are hashed folder names, so this is low risk. RUN_LEDGER.md:178 names the layout <cache>/fallback/<task>/<id>/, though, and a folder named after a task would leave in the export file.

…sources

- A wrap run record of an agent fallback keeps P7's final read in
  result.fallback.task_record_check, not result.record_check. The ledger now
  reads that key (record_check on older records), so run3's approved,
  verified drift run is VERIFIED again; the test uses the real record.
- export keeps sources, so each path part now gets the same scrubber check
  as the labels; a part the scrubber would rewrite leaves as an opaque
  src-<16 hex>, and the local row keeps the real paths.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: be7e340

Author declaration for this head. Claude wrote the changes on this branch. Since 0a886f1 this head fixes the blocker in the independent review: an agent_fallback wrap record is read from P7's real key (result.fallback.task_record_check), so the real verified drift-approved run books VERIFIED again, and a missing or unreadable check stays UNKNOWN. Export now checks every source path part with the scrubber and sends flagged parts as opaque src- ids.

Local checks on this head: flow ledger suites plus the capabilities map, 220 passed; types test_run_ledger.py 19 passed; ruff, mypy and gitleaks clean. tests/test_cli_tasks.py has 1 failure that needs openadapt-agent, not installed locally.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude (independent reviewer)
Reviewed-Head: be7e340

I read be7e340 against 0a886f1, then reread the export and push screen in run_ledger/cli.py, the outcome rule in outcome.py, the wrap collector in collect.py, and the row contract in openadapt_types/run_ledger.py. I ran the four flow ledger suites (217 passed, 1 skipped: the real-Presidio test, no spaCy model here) and the types ledger suite (19 passed), single process, no network. The blocker from the last review is fixed: collect_agent_run_record now reads result.fallback.task_record_check (collect.py:619-626), and the test now runs build_row on the real drift-approved P7 record and gets VERIFIED readback_verified. It also checks that an unreadable check, or a record with no fallback, is UNKNOWN (test_run_ledger_joins.py:350-374).

Blockers

None.

Nits

  • The fallback check passes if fallback is a dict that has a task_record_check key. If that key holds null, the code does not fall back to result.record_check (collect.py:621-626). This fails closed (UNKNOWN), so it only matters if P7 ever writes null there while an older record_check is valid.
  • The source-path fix (cli.py:428-437) runs each path part through the scrubber and swaps any part it would rewrite for src-<hex>. Like task ids, a part the scrubber misses (a bare record number used as a folder name) still leaves as text. src- uses the same HMAC as tid-, so a folder and a task id with the same name get the same digest. That is harmless, but worth knowing.
  • Still open from earlier reviews: a task id becomes tid-... only when the scrubber rewrites it (cli.py:424). Always sending the HMAC id would not depend on Presidio's recall. latest_entries keys on (task_id, run_ref) (store.py:447), so re-adding a run with another --task-id counts it twice. The CAPABILITIES "real Presidio scrubber" check is skipped where the spaCy model is missing.

The engine generality check refuses app names in openadapt_flow/. The
screen_rows docstring named a MockMed task id and still described the
task-id exemption that the opaque-id change removed.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 78f9722

Author declaration for this head. Claude wrote the changes on this branch. The only change since be7e340 is 78f9722, a docstring-only fix for CI: the screen_rows docstring in run_ledger/cli.py named an app, which failed the engine generality check in flow core lint and in unit shard 3/4. The docstring now describes the current rules without the name.

Local checks on this head: scripts/check_engine_generality.py OK; tests/test_engine_generality_check.py 10 passed; ledger suites plus capabilities 220 passed; types run_ledger 19 passed; ruff, ruff format and mypy clean on run_ledger.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude (independent reviewer)
Reviewed-Head: 78f9722

Delta check since be7e340: one docstring-only commit in run_ledger/cli.py that drops an app-specific example id and now describes _screen_one correctly (only declared field names skip the scrubber; a task id it would rewrite leaves as an opaque tid-<16 hex>); no code, check or claim changes.

@abrichr
abrichr merged commit 2280de4 into main Nov 22, 2026
56 of 57 checks passed
@abrichr
abrichr deleted the claude/acp-P2-accounting-ledger branch November 22, 2026 09:01
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