Skip to content

feat(flow): opt-in governed fallback from a compiled program to the agent on drift - #2491

Merged
abrichr merged 14 commits into
mainfrom
claude/acp-P7-gated-fallback-on-drift
Nov 22, 2026
Merged

abrichr merged 14 commits into
mainfrom
claude/acp-P7-gated-fallback-on-drift

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member

Box 4 (opt-in compiled replay): a wrapped task's compiled program can now hand a drifted run back to the agent, behind a pre-commit gate. The documented default does not change: a stopped program is held, and the agent is not rerun.

What it adds

  • openadapt_flow/wrap/fallback.py: FallbackPolicy wraps any TaskCache-shaped object (normally a SkillCache). It falls back only when all of these hold:

    • the hold is a terminal halt;
    • the halted report is HALTED / HALTED_BEFORE_EFFECT with no steps_requiring_reconciliation, and it is bound to the admitted bundle's digest;
    • the replay made exactly zero model calls;
    • the cache's own record check found no change.

    It never falls back on RECONCILIATION_REQUIRED, a lost reply (the hold stays running), RECORD_CHECK_FAILED, a receipt that is not VERIFIED, or a model call during replay.

  • The fallback is a compile-agent run 1 (right-record check, origin fence, read-back) in its own directory. It has:

    • a PreCommitGate protocol. The default TerminalGate is compile-agent's _terminal_hold; with no TTY it refuses, and the agent is not started;
    • its own required max_cost_usd (--fallback-max-cost-usd, no default) and its own request ID;
    • path="agent_fallback";
    • an in-flight marker. A crash or an unproved outcome then needs a person to reconcile before the next fallback.

    A verified fallback opens a repair candidate through SkillCache.open_repair and is never admitted. A person still demonstrates and approves the repair (complete_repair).

  • openadapt-flow wrap-dispatch (wrap/dispatch_cli.py, registered with one line in __main__.py next to cli_variants):

    • runs the admitted program first;
    • returns NO_ADMITTED_PROGRAM when no program is admitted, and runs nothing;
    • applies the policy only with --fallback agent --fallback-max-cost-usd N;
    • provides status, release and evict for the hold.

    Each run writes a result JSON with WrappedTask's per-run field names, plus outcome and fallback. In that JSON, path is program, agent_fallback or held.

  • Docs: docs/WRAP_FALLBACK.md and the command doc. The command map and llms-full are regenerated.

  • Stale docs fixed:

  • CAPABILITIES.md: one new row at the end of "When the app changes".

Required assertions, and where they are tested

Requirement Test
Falls back only for HALTED_BEFORE_EFFECT test_proved_pre_effect_drift_falls_back_behind_the_gate, test_eligibility_agrees_with_open_repair, e2e test_drift_falls_back_and_the_save_is_read_back[redesign,relink]
RECONCILIATION_REQUIRED, lost reply and RECORD_CHECK_FAILED never fall back (table) test_never_falls_back[...] (9 cases), test_a_lost_reply_never_falls_back
Gate refusal means no save (state read) test_gate_refusal_means_no_save, e2e test_gate_refusal_saves_nothing (reads MockMed's store)
Cost cap enforced test_the_cap_is_required, test_cost_cap_is_enforced, test_unknown_spend_is_refused_at_the_gate, test_an_uncappable_agent_is_not_started, test_fallback_needs_its_own_cap
A verified fallback creates a repair candidate and no admission test_verified_fallback_opens_a_repair_but_admits_nothing, e2e asserts repair.opened, still held, no server
The default policy is byte-identical to today's hold test_an_ineligible_halt_through_the_policy_is_byte_identical, test_default_dispatch_is_the_wrap_hold, e2e test_without_the_policy_the_drift_is_held

Benchmark (benchmark/wrap_fallback/; MockMed in headless Chromium, scripted agent, scripted gate, no model): 3 drift modes, 6 trials. The program halted before the save on 2 modes (redesign, relink); on rename it still verified. Of the 4 fallbacks, the 2 the gate approved were VERIFIED and read back correct, and the 2 it refused saved nothing. Wrong saves: 0. Approvals asked for: 4. Model calls: 0.

One deviation

The spec asked to import the predicate in skills.py:606-617 rather than copy it. That predicate is inline in SkillCache.open_repair, and this PR must not edit skills.py. proved_before_effect therefore imports its parts (steps_requiring_reconciliation, _STOP_FILE, lifecycle.verify_admission) and repeats the conjunction. test_eligibility_agrees_with_open_repair pins the two together on the same halts. Follow-up: extract a shared predicate in skills.py and call it from both places.

Integration follow-ups

Synthetic data only. The engine names no app.

…gent on drift

FallbackPolicy hands a wrapped task to the agent only when the compiled run
halted before any effect (proved from the hold, the bound report and the
cache's record check), behind a pre-commit gate and its own spend cap. The
default stays the hold. Adds openadapt-flow wrap-dispatch (run, status,
release, evict), docs, a MockMed drift benchmark, and fixes stale rows in
AGENT_FRAMEWORKS.md and CAPABILITIES.md.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: b779bcc

The default dispatcher holds a stopped program. On the intended fallback path, the code checks the admitted bundle digest, the report's transaction outcome and unsettled steps, requires an explicit positive cost cap, and routes saves through the compile-agent hold. The following gaps affect ordinary read failures, retries and operator recovery.

  1. Distinguish “unreadable” from “unchanged.” When either system-of-record snapshot is unavailable, task_record_check returns a failed check with zero created, changed and removed. _nothing_written tests only those counters. An unavailable post-replay read can therefore qualify a halt for fallback. An unavailable read after an unverified fallback can also clear its in-flight marker. Carry an explicit indication that both reads succeeded and compare their result before either decision. The ordinary no-change check also has passed=False because this task expects one creation. Record-check producer · No-write predicate · Eligibility · Marker cleanup
  2. Honor the final independent record check. The policy obtains a fresh written result after compiler.record. It then derives VERIFIED from the earlier run-1 snapshot and gate log. If the newer read shows a duplicate, a changed/deleted target or an unreadable store, the policy can still report success, open a repair and remove the marker. Require the final task-scoped read to confirm the expected write before performing any of those actions. Preserve both readings for reconciliation when they disagree. Fresh check and success decision · Result and cleanup
  3. Keep the initial dispatch restricted to compiled replay. The CLI checks whether a program exists, then passes the real fallback agent to ordinary SkillCache.run later. That method can enter _first_run if the program has been evicted between lookup and dispatch. That first run receives the regular compile/admission configuration and has already begun before the fallback policy examines its path. Use a compiled-only dispatch operation that can return a miss without invoking the fallback agent. Instantiate or supply that agent only after fallback eligibility is established. CLI precheck and dispatch · Policy call · Cache miss · Ordinary first run
  4. Preserve ownership and uncertainty during release. A terminal cache hold can contain a RECONCILIATION_REQUIRED reply. The release command checks the outer phase and marker only, so phase="halted" can be released without the required reconciliation acknowledgement. Release can also rename an active worker's marker while that worker can still save. On completion the worker removes the shared marker by path, including one now owned by a later dispatch. Use the persisted outcome/evidence to classify the hold, distinguish a live owner from an abandoned run, and clear markers only for their owning request. Terminal hold creation · Release · Fallback ownership · Cleanup
  5. Persist the dispatcher result with the parent request. WrappedTask.call finishes the RunStore entry before the dispatcher adds fallback. A retry can recover the stored outcome but returns fallback: null, losing the child request ID, gate decisions and repair reference. The early NO_ADMITTED_PROGRAM return also skips the request ledger, so a retry after admission can execute a request previously reported terminal. Store the final dispatch envelope for both paths. When deriving a child ID, preserve the existing parent-ID contract: appending .fallback makes a valid 128-character parent ID too long, and valid parent IDs can contain characters disallowed in child filenames. RunStore replay and completion · Terminal write · Dispatcher return paths · Child-ID constraints

These findings apply across applications. I traced the producer, consumer, gate and persistence paths and inspected the committed tests. The committed synthetic benchmark reports six MockMed trials, four fallbacks, two verified saves, two refusals with no save, and zero model calls. I did not invoke an agent or run a browser, provider, signing or release operation. At review time CI was queued and the Windows desktop replay job had failed. Benchmark · CI · Windows job

…paths

An unreadable system-of-record read no longer counts as unchanged: the
task record check carries readable, and the fallback needs it to qualify
a halt or to drop the in-flight marker. A verified fallback now needs the
final task-scoped read to confirm the save; otherwise it is
RECONCILIATION_REQUIRED with both readings kept, no repair and the marker
kept.

wrap-dispatch only replays (SkillCache.replay_only): a miss is
NO_ADMITTED_PROGRAM and never reaches a first run, and the fallback agent
is built only once a fallback may start. The stored request result is the
whole dispatch envelope, so a retry replays fallback and the miss too.
Fallback ids are derived by digest, so any valid parent id works.

The in-flight marker names its owner (nonce, pid, host). A worker clears
only its own marker; release refuses a live or unprovable owner, and a
hold whose evidence does not prove nothing was written needs
--after-reconciling.

Adds ItemApprovalGate (--fallback-gate item-approval): a person approves
each fallback save from Desktop or a paired phone through the signed
item-approval store, so the fallback can run without a terminal.
…d release rules

Adds wrap-dispatch to both FLOW_NAMES copies as run --dispatch, narrows
the CAPABILITIES row to experimental with the evidence it has, and lists
what is still open. The rerun MockMed benchmark matched the committed
results, so results.json is unchanged.
… halt

wrap-dispatch release and status now need the kept, readable record
check for the halt, as the fallback does; the default dispatch keeps it
too. A run whose own checks caught a wrong save keeps its status instead
of becoming RECONCILIATION_REQUIRED. A gate bind or run-directory failure
now leaves the marker ended rather than running. Adds dispatch-level tests
of --fallback-gate item-approval with no injected gate, and narrows the
docs: Desktop's Run it screen does not show these requests.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 3b73d09

Author declaration for this head. Claude wrote the changes on this branch. This PR adds an opt-in fallback from a compiled program to the agent when the program halts on drift before any write, with a person approving each fallback save. This round answers the Codex review of b779bcc: an unreadable record read no longer counts as unchanged, a verified fallback needs the final task-scoped read to confirm the save, wrap-dispatch only replays an admitted program, and the in-flight marker names its owner so that release refuses a live or unprovable one. It also adds --fallback-gate item-approval, so a person can approve fallback saves from Desktop or a paired phone without a terminal.

Local checks on this head: run 3 merged this head into integration tree 128faaec3 and ran 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. This PR's files are test_wrap_fallback.py, test_wrap_approval_gate.py, test_wrap_dispatch_cli.py and e2e/test_wrap_fallback_e2e.py. In run 3's compiled-run step, through dispatch_cli.run and the item-approval gate, the run without drift was VERIFIED by the program with 0 model calls; the forced drift with an approval was VERIFIED on the agent fallback with 1 signed approval and a repair opened; and the forced drift that a person declined was ESCALATED with nothing saved.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Gemini
Reviewed-Head: 3b73d09

This PR adds the opt-in fallback mechanism for wrapped tasks, allowing a drifted program to hand the task to an agent behind a pre-commit gate. It successfully addresses the five architectural gaps identified in the earlier Codex review (unreadable vs. unchanged, the final independent record check, compiled-only dispatch, marker ownership during release, and persisting the dispatcher envelope). However, there is a fail-open path in how the policy decides whether the agent wrote anything, which allows rogue writes to bypass the reconciliation safety net.

Blockers

  1. Rogue writes to other records bypass reconciliation.
    • File: packages/flow/openadapt_flow/wrap/fallback.py, lines 133-143.
    • What goes wrong: The _nothing_written function checks only the created, changed, and removed counters for the task's expected record. It ignores outside_run, which task_record_check populates when the agent modifies records outside the task's scope (e.g., a different patient's record due to hallucination or drift). If the fallback agent makes a rogue write to another record but leaves the target record untouched, _nothing_written returns True. The policy then clears the in-flight marker and fails to escalate the run to RECONCILIATION_REQUIRED, leaving the rogue write unnoticed and allowing another fallback run to start.
    • Fix: Require not check.get("outside_run") in _nothing_written.

Nits

  1. Incomplete check for unused fallback options.
    • File: packages/flow/openadapt_flow/wrap/dispatch_cli.py, lines 368-374.
    • What goes wrong: The check that raises an error when --fallback-* options are passed without --fallback agent misses --fallback-approvers-config, --fallback-approver-root, and --fallback-approval-wait-s. If a user passes these without enabling the fallback agent, they are silently ignored instead of raising an error.

Earlier findings at this head

Finding 1 (older heads):

    1. The fallback's default TerminalGate refuses when there is no TTY, so the fallback can't run as a service until P5's card is wired in: Fixed (this PR wires in ItemApprovalGate for unattended service runs).

Codex Finding (2491-codex.md):

    1. Distinguish "unreadable" from "unchanged": Fixed (added and checks the readable flag).
    1. Honor the final independent record check: Fixed (the final read must confirm the save, otherwise it falls back to RECONCILIATION_REQUIRED).
    1. Keep the initial dispatch restricted to compiled replay: Fixed (added CompiledOnly and replay_only to prevent _first_run).
    1. Preserve ownership and uncertainty during release: Fixed (release checks _hold_is_proved_clean and owner_state).
    1. Persist the dispatcher result with the parent request: Fixed (overrides finalize to include the fallback envelope and uses child_request_id).

Verdict: REQUEST CHANGES

The fallback's no-write check ignored the record check's outside_run
counts, so a write to another record during the halt or the fallback
could qualify the halt or clear the in-flight marker. Any outside_run
change, or a check without outside_run, now counts as something written.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 4bd5470

Author declaration for this head. Claude wrote the changes on this branch. Since 3b73d09 this head fixes the blocker in the Gemini review: the no-write predicate now also requires every outside_run count to be zero, and a record check without outside_run fails closed, so a write to another record keeps the in-flight marker. Fresh origin/main is merged.

Local checks on this head: wrap_fallback, dispatch and approval-gate suites, 99 passed; headless MockMed e2e plus test_wrap_integration and test_skill_cache_runtime, 62 passed; ruff clean. The wrap_fallback benchmark was not rerun after this change.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

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

I read the whole diff against main and the code it depends on: SkillCache._compiled/_skill_run, task_record_check, compile-agent's record and check_run_record, WrappedTask.call, and the item-approval store. I traced eligibility, the marker, release and the dispatch envelope. The PR's three unit suites pass at this head (99 passed, single process). I also ran one probe through dispatch_cli.run with an agent that raises. The fallback's safety decisions fail closed. One gap remains in what the stored request says happened.

Earlier blockers

  • Codex 1 (unreadable read counted as unchanged): fixed. readable is checked in _nothing_written (fallback.py:141-152).
  • Codex 2 (final read ignored): fixed. A success the final read doesn't confirm becomes RECONCILIATION_REQUIRED (fallback.py:602-611).
  • Codex 3 (a miss could start a first run): fixed. replay_only and compiled_only never reach _first_run, and the agent is built only after eligibility.
  • Codex 4 (release ignored the outcome and ownership): fixed. Release uses halt_evidence, and the marker has an owner nonce and refuses a live or unknown owner.
  • Codex 5 (envelope not stored): fixed on the normal paths. On the crash path it is still lost; see blocker 1.
  • Gemini 1 (outside_run ignored): fixed at fallback.py:149-152, with tests at test_wrap_fallback.py:807-859. On a verified run, compile-agent's whole-store check_run_record already fails on any other write made during the run.

Blockers

  1. A fallback that raises is stored as a program result with no fallback record. FallbackPolicy.run resets self.last = None (fallback.py:377). self.last is set only after compiler.record returns (fallback.py:613). If the agent run raises (fallback.py:537), WrappedTask.call stores its generic RECONCILIATION_REQUIRED envelope. That envelope has no path, and finish then labels it path: "program" and fallback: null (dispatch_cli.py:86-90, 103). My probe got exactly that, both on the first call and on the replay of request r1. The same happens when _open_repair raises something other than RepairError after a verified save. In that case result.json is never written either (fallback.py:612, 649). This is the one path where the agent may have saved. The parent request then says the program ran and holds no child request ID. That contradicts WRAP_FALLBACK.md's dispatcher table ("The fallback ran or was refused | agent_fallback") and its claim that a retry returns "fallback and all". A person reconciling from the request record is pointed at the wrong actor. To fix it, set self.last (fallback: True, request_id, parent_request_id, status: "RECONCILIATION_REQUIRED") before the marker is claimed. Alternatively, catch the exception in _run_agent and return a SkillRun(path=FALLBACK_PATH, status="RECONCILIATION_REQUIRED"), keeping the marker. In both cases, add a dispatcher-level test like test_release_after_a_crashed_fallback that asserts path == "agent_fallback" and the child ID in the stored envelope.

Nits

  • Gemini's nit is still open. --fallback-approver-root and --fallback-approvers-config are silently ignored without --fallback agent (dispatch_cli.py:368-374).
  • ItemApprovalGate puts the on-screen record identity values into step_intent (approval_gate.py:232-235). item-approval show prints that field. The guarded-save gate puts only field names there (guard.py:559). The data stays local and is also visible in the screenshot, but the plain-text copy isn't needed for the approval.
  • On a verified run, the final read checks only the task's record (fallback.py:602). A write elsewhere between run 1's after read and that final read would not be caught. Requiring outside_run to be zero there would match _nothing_written.
  • agent_factory runs before marker.claim() (fallback.py:434-458). A dispatch refused because another fallback is in flight still builds the agent and loads the model key.
  • A malformed --fallback-request-id raises an uncaught ValueError from FallbackPolicy.__init__, not a one-line refusal (fallback.py:351-357, dispatch_cli.py:588).
  • WRAP_FALLBACK.md repeats the line "In Python, wrap the task's SkillCache:" before the item-approval paragraph.
  • The benchmark README's "Gate refuses" cells say "1 approval", but no save was approved. "1 approval asked" would be accurate. The benchmark was not rerun after the outside_run change. A one-line note in results.json or the README would say which head it measured.
  • A marker owned by a process on the same hostname in another PID namespace reads as ended once that PID is gone from this namespace (fallback_marker.py:126-128). This is unlikely in practice.

The policy records the fallback (its request id, gate decisions) before
the agent starts. If anything raises, it writes result.json with
RECONCILIATION_REQUIRED and the exception's class, and the stored dispatch
envelope says agent_fallback, so a retry returns the same answer instead
of path program with fallback null. A repair-desk failure after a
confirmed save no longer turns the save into a crash.

Also: item-approval gate flags without --fallback-gate item-approval are
refused, a bad --fallback-request-id is a clean error, and the gate's
request text no longer carries the record's on-screen identity.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: c5b9f83

Author declaration for this head. Claude wrote the changes on this branch. Since 4bd5470 this head fixes the blocker in the independent review: a fallback that raises is recorded before the agent starts and stored as agent_fallback / RECONCILIATION_REQUIRED with the error class, result.json is written on any exception, and a retry replays it without running the agent. Gate flags without the gate are refused, bad request ids exit cleanly, and the record identity is no longer in the gate's request text.

Local checks on this head: wrap_fallback, dispatch and approval-gate suites, 110 passed; headless MockMed e2e, wrap integration and CLI, skill cache runtime, cli_tasks and capabilities map, 157 passed; ruff and mypy clean.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

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

I read the diff's code and docs against main, with most attention on the new commit c5b9f83. I traced eligibility, the in-flight marker, the crash path through WrappedTask.call and finish, release, and the item-approval gate, and skimmed the unit and e2e tests. The PR's three unit suites pass at this head (110 passed, single process). I also ran one probe through dispatch_cli.run with a gate that raises KeyboardInterrupt. The safety decisions fail closed. One gap remains: the crash fix covers Exception, but not an interrupt at the default terminal gate.

Earlier blockers

  • Codex 1 to 5: still fixed at this head. _nothing_written requires readable and a zero outside_run (fallback.py:143-162). The final read must confirm a verified save (fallback.py:624-630). Dispatch only replays (compiled_only.py:39-51). The marker has an owner nonce, and release refuses a live or unknown owner (fallback_marker.py:109-154, dispatch_cli.py:538-545). The envelope is stored through finalize (wrap/init.py:238).
  • Gemini 1 (outside_run ignored): still fixed (fallback.py:159-162).
  • Independent review of 4bd5470, blocker 1 (a fallback that raises was stored as a program result): fixed for Exception. self.last is set to fallback: True, RECONCILIATION_REQUIRED before the gate is bound and the agent starts (fallback.py:489-498). _crashed writes result.json and re-raises (fallback.py:507-509, 679-706). finish labels any started fallback agent_fallback (dispatch_cli.py:105-106). For BaseException, see blocker 1.

Blockers

  1. Ctrl-C at the default gate still stores the request as a program result. TerminalGate asks with input() (compile_agent/cli.py:347). A person who presses Ctrl-C at "Allow this save?", or during the agent's run, raises KeyboardInterrupt. _fallback catches it as BaseException, writes result.json and re-raises (fallback.py:507-509). WrappedTask.call catches only Exception (wrap/init.py:230), so store.finish never runs and no JSON is printed. A retry of the same request then takes the unfinished-record branch (wrap/init.py:192). run returns it through finish(..., None) (dispatch_cli.py:463) as path: program, fallback: null. My probe got that exactly: result.json said agent_fallback / RECONCILIATION_REQUIRED, the marker was ended, and the retry said {"path": "program", "status": "RECONCILIATION_REQUIRED", "fallback": null}. The same happens for SystemExit raised inside the agent. Nothing unsafe passes, because the status is RECONCILIATION_REQUIRED and the marker blocks the next fallback. But the parent request names the wrong actor on a path where the agent may have saved. That contradicts WRAP_FALLBACK.md:132-135 ("A fallback that raises after it started still answers its request ... a retry returns it") and the dispatcher table. It is the same symptom as the last blocker, reached by an ordinary keystroke at the documented default gate. To fix it, have WrappedTask.call (or DispatchTask) catch BaseException, store the finalized RECONCILIATION_REQUIRED envelope with store.finish, then re-raise anything that is not an Exception. Add a dispatcher test with a gate that raises KeyboardInterrupt and assert path == "agent_fallback" and the child ID on the retry. If you'd rather not catch interrupts there, narrow the doc to Exception and list the interrupt and killed-process cases under "Not covered yet".

Nits

  • A process killed during a fallback (SIGKILL, power loss) leaves the same unfinished record and the same path: program retry. No in-process fix exists. A sentence in "Not covered yet" would keep the retry claim exact.
  • _open_repair writes repair.json outside its try (fallback.py:723). If that write fails after cache.open_repair succeeded, the confirmed save becomes a crash (RECONCILIATION_REQUIRED, marker kept), and the repair token is lost. This fails closed, so I count it as a nit. WRAP_FALLBACK.md:136-137 says only that a failure to open the repair leaves the save VERIFIED, which is true for cache.open_repair but not for writing its file.
  • test_a_crashed_fallback_is_stored_as_a_possible_write uses Agent(raises=True), and the fake raises before it appends any row (test_wrap_fallback.py:236-237), despite its message "crashed after its save". The test checks the labels, not a crash after a real write. A variant that appends the row and then raises would cover the case the docs describe.
  • REQUEST_ID_CONFLICT comes back as path: program (dispatch_cli.py:82-90), but nothing ran.
  • In FallbackPolicy.run, an OSError from keep_halt_evidence is not caught (fallback.py:398), but CompiledOnly.run does catch it (compiled_only.py:84-87). A full disk then turns a clean halt into a generic RECONCILIATION_REQUIRED, not "not eligible". This fails closed.
  • Still open from the last review: the verified final read ignores outside_run (fallback.py:624); agent_factory runs before marker.claim() (fallback.py:439-463); WRAP_FALLBACK.md:19 still repeats "In Python, wrap the task's SkillCache:"; the benchmark README's "Gate refuses" cells say "1 approval" where no save was approved; and the benchmark has not been rerun since the outside_run and crash-path changes, with no note of which head it measured.
  • Fixed since the last review: gate options without the gate are refused, a bad --fallback-request-id exits cleanly, and the gate's step_intent no longer carries the record's identity.

Ctrl-C at the gate or a SystemExit in the agent escaped WrappedTask.call's
Exception handler, so the request stayed reserved and a retry reported a
program run. The dispatch task now carries the interrupt through that
path, stores the finished agent_fallback / RECONCILIATION_REQUIRED
envelope, then raises it again. REQUEST_ID_CONFLICT reports path held,
repair.json is written inside the repair try, and the docs list a killed
process as not covered.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 29c1b15

Author declaration for this head. Claude wrote the changes on this branch. Since c5b9f83 this head fixes the blocker in the independent review: a Ctrl-C or SystemExit at the gate or inside the agent is stored as a finished agent_fallback / RECONCILIATION_REQUIRED request before it is raised again. REQUEST_ID_CONFLICT reports path held, repair.json is written inside the try, and WRAP_FALLBACK.md lists a killed process as not covered.

Local checks on this head: fallback, dispatch and approval-gate suites, 116 passed; headless MockMed e2e, wrap integration and CLI, skill cache runtime, cli_tasks and capabilities map, 157 passed; ruff and mypy clean.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude (independent reviewer)
Reviewed-Head: 29c1b15

I checked the last review's blocker against the new commit 29c1b15 and reread the crash path through DispatchTask, WrappedTask.call, FallbackPolicy._fallback and finish. I also rechecked the earlier fixes and the open nits. The PR's three unit suites pass at this head (116 passed, single process), including the new interrupt test for Ctrl-C and SystemExit, at the gate and in the agent.

Earlier blocker

  • Ctrl-C at the gate stored as a program result: fixed. DispatchTask.run turns a KeyboardInterrupt or SystemExit into _Interrupted, an Exception. WrappedTask.call then stores RECONCILIATION_REQUIRED through finalize, which labels it agent_fallback from policy.last, and call re-raises the original interrupt after store.finish (dispatch_cli.py:349-385). The stored text holds only the exception's class name. The new test asserts path: agent_fallback, the child request ID and the error class on the retry, and that the agent is not called again (test_wrap_dispatch_cli.py:615-650). The killed-process case is now listed under "Not covered yet" (WRAP_FALLBACK.md:219-222).
  • Fixed nits from the last review: REQUEST_ID_CONFLICT now reports path: held (dispatch_cli.py:88-96). A failed repair.json write now keeps the verified save (fallback.py:715-723), and a test covers it.

Blockers
None.

Nits

  • An interrupt during the compiled replay, before any fallback starts, is now also stored as a terminal RECONCILIATION_REQUIRED with path: program. That fails closed and names the right actor. It changes behavior for a plain program run, though: a Ctrl-C used to leave the request unfinished. A line in WRAP_FALLBACK.md would say so.
  • There is a small window after marker.claim() and before self.last is set (fallback.py:463-489). An interrupt there stores path: program and leaves the marker ended. No agent has run, so this fails closed.
  • Still open from earlier reviews: the verified final read ignores outside_run (fallback.py:624). Every save in that path passed the person's gate, so this is not fail-open. WRAP_FALLBACK.md:19 still ends with "In Python, wrap the task's SkillCache:" and no code under it. The benchmark README's "Gate refuses" cells say "1 approval" where the save was refused. results.json was last changed in b779bcc and does not name the head it measured.

Registering wrap-dispatch imported openadapt_flow.wrap, whose top-level
SkillRun import pulls in the agent integrations and write_ledger, which
needs fcntl. On Windows every openadapt-flow command then failed while
building its parser (windows replay). SkillRun is now a type-checking
import. Also registers benchmark/wrap_fallback/results.json in the public
artifact inventory (flow core lint).
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 43d8dd7

Author declaration for this head. Claude wrote the changes on this branch. The only change since 29c1b15 is 43d8dd7, which fixes two CI failures this branch caused: the benchmark result file is registered in packages/flow/public-artifacts.json (release consistency, flow core lint), and wrap/init.py imports SkillRun only for type checking, so building the openadapt-flow parser no longer pulls in the POSIX-only fcntl module on Windows (windows replay). A new test builds the parser with fcntl blocked.

Local checks on this head: the flow core lint steps (release consistency, ruff, engine generality, py310 syntax, ruff format, mypy on 797 files) pass; wrap, skill cache, cli_tasks, capabilities_map and Windows attempt-ledger suites, 458 passed, 7 skipped (Windows-only tests skip on macOS).

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude (independent reviewer)
Reviewed-Head: 43d8dd7

Delta check since 29c1b15: one fix commit that registers the PR's existing benchmark/wrap_fallback/results.json in public-artifacts.json and moves the SkillRun import under TYPE_CHECKING (safe: the module has from __future__ import annotations and uses SkillRun only in annotations), plus a subprocess test that builds the parser with fcntl blocked; no check weakened, no new claim.

The standalone wrap-dispatch parser and the benchmark's parser now pass
allow_abbrev=False, and BACKEND_PARITY.md records why wrap-dispatch's
--pricing-source-url is not an app URL.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: aeb75c8

Author declaration for this head. Claude wrote the changes on this branch. Since 43d8dd7 this head merges fresh origin/main (including #2478, no conflicts) and adds aeb75c8, which fixes two CI failures: the argparse parsers in benchmark/wrap_fallback/measure.py and the standalone wrap/dispatch_cli.py main() set allow_abbrev=False, and docs/BACKEND_PARITY.md lists wrap-dispatch --pricing-source-url as the source cited for model prices, not an app URL.

Local checks on this head: the two failing tests pass; wrap, skill-cache, cli_tasks, capabilities and backend-parity suites 467 passed; ledger suites from #2478 on the merged tree 277 passed; ruff and release consistency clean.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

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

Delta check since 43d8dd7: the main merge 4244322 is identical to a clean git merge-tree result (no hand resolution, so no wrap/ code changed), and aeb75c8 only sets allow_abbrev=False on the dispatch_cli and benchmark measure.py parsers (stricter: abbreviated flags are now rejected) and adds a BACKEND_PARITY.md row saying --pricing-source-url is a pricing citation, not an app URL; no check weakened, no new claim.

@abrichr
abrichr merged commit 2d1279f into main Nov 22, 2026
58 of 59 checks passed
@abrichr
abrichr deleted the claude/acp-P7-gated-fallback-on-drift branch November 22, 2026 09:58
yunusarda-sudo pushed a commit to yunusarda-sudo/OpenAdapt that referenced this pull request Nov 22, 2026
…anywhere

P7 (OpenAdaptAI#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.
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