Repository navigation
fix(agents): recover delegated task finals across gateway restarts - #137606
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: blocked before merge. Reviewed September 4, 2026, 5:13 AM ET / 09:13 UTC. ClawSweeper reviewWhat this changesThe PR makes delegated-task final delivery restart-safe by preserving the current requester turn and retaining its original Gateway-instance binding through durable requester-settle recovery. Merge readiness⛔ Blocked before merge - 4 items remain Keep open: the restart-safe requester-final recovery is not included in fetched current main, and no merged PR is verified to supersede it. The reviewed ownership and replay paths are coherent, with no introduced correctness finding identified; merge needs current-main integration and exact-head validation. Priority: P1 Review scores
Verification
How this fits togetherSubagent completions are stored in the durable registry and can require a final requester wake after a restart. The wake composes the recorded Gateway ownership, dispatches a consolidated requester turn when safe, and records whether delivery settled. flowchart LR
A[Subagent completion] --> B[Durable subagent registry]
B --> C[Requester-settle batch]
C --> D[Captured Gateway owner]
D --> E[Requester wake delivery]
E --> F[Transcript and visible final]
B --> G[Restart restoration]
G --> C
Before merge
Agent review detailsSecurityNone. PR surfaceSource +219, Tests +1581, Docs +7. Total +1807 across 36 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Rebase onto current main, retain only the owner-bound replay checks needed at each asynchronous boundary, and validate the resulting exact head through the restart and requester-final flow. Do we have a high-confidence way to reproduce the issue? No current-main execution was performed in this read-only review, but the affected recovery and replay paths are source-reproducible and covered by focused branch scenarios. Is this the best way to solve the issue? Yes, the captured-resolver and exact-row approach preserves Gateway-instance ownership rather than falling back to ambient routing; it still needs exact-head integration proof. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b8cdd65bdf61. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Merged via squash.
|
…penclaw#137606) * fix(agents): recover delegated task finals across gateway restarts * test(agents): model gateway activation before recovery fixtures * test(release): preserve elapsed time in fixture clocks
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers can help update the branch when needed.
What Problem This Solves
Fixes an issue where users waiting for delegated work could receive no final answer when Gateway restart overlapped a deferred completion. Finished children could lose their requester wake during drain, exhaust it against a closed Gateway, or remain attached to the old instance. Separate requester turns could also stall when distinct caller closures represented the same live Gateway.
Why This Change Was Made
The existing registry lifecycle now retains and reactivates durable wakes: admission deferral spends no attempt, restored terminal rows bind to the current instance, and exact row/batch/generation checks fence old callbacks while preserving every captured caller's authority. Interrupted built-in completion turns reuse their existing keyed user only after fresh writer/session/physical-tail validation; projection keeps one copy without suppressing later steering or follow-up writes, and an accepted dispatch is not mistaken for a recorded visible final.
User Impact
Delegated-task finals can recover through drain, restart and delayed activation without reviving old active claims. Overlapping requester turns retain their ownership. Retry budgets and completed-delivery receipts remain intact; no configuration, protocol, dependency or schema change is introduced.
Evidence
Fresh integrated proof
The frozen integration is committed as
7a437c9712e012f8d0604f684291eae211d53acc, incorporating main through0a1e564d34580935a955c434645103b3fa41a389. All 36 candidate-file hashes are unchanged by the merge commit.mixed-distinct-alphaflowThe live flow admitted two distinct requester runs, one yielding and one completing normally. Their children overlapped, alpha completed first, and one consolidated wake produced one visible final. After 65,101ms of ordinary sweep observation, both child rows were delivered with wake/requester-run state cleared. Gateway, browser and provider stopped normally, with zero cleanup errors or observed surviving descendants. This is fresh caller-context composition proof, not fresh replacement/restart proof.
Source/index, runtime, fixture, static-helper and dependency-payload checks matched before/after. Retained QA helpers came from the earlier helper checkout, with their static closure and package payloads checked against the new runtime's dependencies; this is not an unbounded dynamic-import identity claim. Browser proof used verified Developer-ID-signed Google Chrome and a fresh ephemeral context, never a saved profile. Both fresh screenshots were inspected as synthetic-only; they are not the historical media below.
Original harness failures remain recorded: an overlong task-owned Unix-socket path and a reporter-path accounting error. The short private temporary-directory correction resumed only failed/unexecuted files; the accounting correction did not rerun tests. No product guard, assertion or test deadline was weakened. These failures are not counted as passes.
Historical red/green and media
The original built baseline reproduced the missing final through a real Control UI request, child spawn/yield and natural retry deadline during restart drain. Failing-before regressions cover late/partial restoration, replaced batch members, old-finally races, caller wrappers and closure on the final admitted attempt.
Earlier candidate proof covered original inside-drain recovery and final-attempt replay across forced restart with replacement activation held by a normal plugin service. All 79 samples retained the exact attempt-three wake; recovery reused the same three durable keyed user rows/projections and recorded one visible final before releasing the old response. Those replacement results, and the three real flows previously run on the
f1e49edfb85ccintegration, remain historical, not added to the fresh totals.Original baseline failure:
The same original flow succeeds in this inspected, synthetic-only 50.20-second recording from the earlier
b122b21f051ccandidate, not the new head:f06-after.webm
Review dispositions and compatibility
ClawSweeper Rank-up move: incompatible-binding backoff/no-hot-loop coverage. The proposed immediate-loop premise is not supported. The resolver does reject mixed/unrelated bindings, but ordinary scheduler
finallycalls deadline-only retry, which returns when no future deadline exists. Immediate re-entry consumes a one-shot marker produced only by a separate persisted requester-turn settlement, either normal completion or yield—not by the exception. Individual live/unbound owner fences can also permit terminal bookkeeping despite shared dispatch incompatibility; closed fences retain the wake for later lifecycle work.The existing registry product-flow matrix passed both completion orders for distinct-live and mixed-unbound bindings through the real resolver/lifecycle, with Gateway/store I/O harnessed. After a sweep and 30 seconds of simulated time it asserts no incompatible consolidated dispatch and both wakes cleared. Deadline, expired-deadline, rearm and pre-admission-rejection scheduler tests also passed. No speculative durable-backoff policy was added. These controls do not claim exhaustive interleavings or exact warning-count coverage; the raw review remains retained.
ClawSweeper Rank-up move: exact-head CI. The fresh local gate passes and exact-head CI for
7a437c9712e012f8d0604f684291eae211d53acccompleted successfully: all 125 jobs passed or were intentionally skipped. Recovery fixtures now follow canonical empty-registry startup/activation order. The obsolete spawned-CLI clock override is removed after upstream relative-expiry fixtures; all five CLI children use real time with original arguments/assertions/deadlines. Earlier advancing-clock proof is historical only.Managed review: all 29 review passes completed; the raw incorrect verdict and two duplicate optional-call/TS2349 reports are retained. Both claims were rejected against installed compiler source, strict-null controls and the passing canonical typecheck graphs; no source workaround or nicer-verdict rerun was used. All 36 candidate files were reviewed, but the managed helper refused the upstream-only
src/gateway/server-reload-managed-secrets.tscallee. A separate full local source read does not erase that managed-context gap.Stored-shape concern: canonical readers/writers/serializers preserve the existing registry payload, transcript/event/message shapes and pending-input custody. Replay adopts the exact existing current user through the recorder with
appended: false, without rewriting it or firing a fresh-input commit notification. SQLite close/reopen tests preserve the complete pending wake and durable transcript events, then verify replacement settlement and one later user write. This proves candidate-reader reopening/byte preservation, not a separate older executable opening a candidate-produced database. No migration, schema-version, index, retention or material store-design change is introduced.Scope, LOC exception and related work
Against pinned main, production is +601/-382 (net +219); tests/support +2320/-739 (net +1581); docs +7/-0. The positive production exception implements the fresh interrupted-turn fence, whole-batch/visible-receipt handoff and per-Gateway restored capacity. It replaces function-identity batching, ID-only async ownership, process-long recovery capacity and broad next-user suppression; the announce-wake owner shrinks 52 lines. Existing resolver, recorder, physical-current-turn and runtime-projection owners are reused. The physical branch/snapshot checks and late descendant recheck protect observed cases, not hypothetical compatibility.
This does not claim authenticated external inference, production-channel delivery, byte-identical whole developer prompts, or cross-crash exactly-once delivery in the already-visible but registry-unsettled window. The Codex continuation owner and terminal-event mapping were checked directly; requester wake ownership remains in the Gateway.
Thanks to Josh Lehman (@jalehman) for the fallback-resolver sibling-settlement diagnosis in #137471. This independently developed lifecycle/replay repair includes that subset without copying a second resolver holder; the smaller contributor PR retains its history and scope. #121195's intentional-quiet product change is distinct and not adopted. #137332 (related #137344) remains the named terminal non-success/projection follow-up. Existing transcript-commit ordering from #134920 is preserved.
Final disposition of the September 4, 09:13 UTC review
The latest ClawSweeper review reports no correctness or security finding. Its exact-head validation request is satisfied by the green CI above and the recorded owner/gate/live proof.
The rebase/rank-up request is skipped after direct main-interaction review, not merely because the branch is mergeable. The complete changed-path intersection between this candidate and observed main
ed6e3aabf0ef6cd58a8ee9d9282a6dc6c06cc918is the registry entry point, its test file, and the already-upstream clock cleanup. The newer registry change synchronously replays the existing idempotent task-status projection before resume exits, explicitly excluding steer-restart. F06 leavesresumeSubagentRununchanged and binds fresh owners before calling it; task-status projection does not acknowledge the requester wake or publish a second subagent final. Root and an independent reader checked the owner, exact-task mapping, delivery policy and new restore tests. A synthetic merge is conflict-free; it is not being described as an executed merged-runtime test. Repository policy does not require rebasing for drift alone. Native landing still enforces its current-head and merge checks.The +219 production lines cannot be removed by a single pre-admission check: awaited writer/session preparation can change the exact physical transcript tail or owner before the later commit, so custody must be revalidated at that commit boundary. Existing admission, recorder and projection owners are reused; duplicate policy and old paths are removed. Data compatibility evidence and its older-executable limitation remain stated above. Effective landing delta against the inspected main is production +219, tests/support +1602, docs +7, excluding clock cleanup already landed independently.