Repository navigation
fix(codex): recover a managed worker's final reply after a Gateway restart - #207617
freeqaz-openai wants to merge 5 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: passed. What this changesRecover a managed Codex worker’s verified final text after a Gateway restart without repeating its task. Example: Worker managed-run saves “The original child produced this answer.” while the Gateway is down.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR addresses a distinct remote-worker recovery gap that remains on main; no blocking defect was found. Reviewed head: Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe subagent restart sweeper asks the selected harness for the original worker’s result; Codex reads native history, and the session store preserves the verified answer before normal completion delivery. flowchart LR
A[Restart sweeper] --> B[Retained requester custody]
B --> C[Codex recovery hook]
C --> D[Original remote turn]
D --> E[Verified final text]
E --> F[Session transcript writer]
F --> G[Registry completion and parent delivery]
Technical reviewBest possible solution: Retain this focused recovery path through the existing harness, transcript writer, and registry completion owners. Do we have a high-confidence way to reproduce the issue? Current main confirms the failure path: a restored child without a local final is interrupted even when its remote Codex turn has completed; the PR also reports packaged crash reproductions. Is this the best way to solve the issue? The change repairs the missing remote-read boundary without replaying work, while preserving ordinary local recovery and using existing storage and completion operations. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4b79976a9ed7. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +1035, Tests +774, Docs +22, Other +3. Total +1834 across 31 files. Added test files: 2. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (6 earlier review cycles)
Reviewed November 29, 2026, 1:56 AM ET / 06:56 UTC (Revision 7). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Review the 31 changed files against the main revision used to resolve the conflict.
What Problem This Solves
When a Gateway crashes, a managed Codex worker can finish on a separate app-server. The parent can receive an interruption even when the original answer is saved there. Repeating the task could repeat an action that already succeeded.
User Impact
For a new managed child on a configured remote Codex WebSocket with server-owned authentication, the Gateway can recover the original text answer. An idle parent may still need Resume. A launch without a saved receipt cannot recover its remote answer. If the plugin is unavailable before the first claim, ordinary interruption and cleanup can still occur.
Decision before merge. If the original launch is recognized but the result cannot be verified, this change keeps the worker pending without an expiry. Deletion also waits. An operator can inspect the original worker and restore authorized access. A missing binding, unavailable plugin or unsupported native history can leave work pending indefinitely. An older Gateway can drop the recovery receipt when it rewrites the record. Settle pending workers before returning to that version.
Why This Change Was Made
The Codex adapter records a launch identifier and binds recovery to the original connection. An optional harness hook reads one matching turn. When the harness first recognizes a recovery record, the registry saves its claim before the external read. The claim prevents cleanup across another restart. It grants no authority. Missing or ambiguous history is not evidence of termination.
Only the final answer is forwarded. Labeled progress, reasoning and completed dynamic tools can precede it. Native shell commands, media, extra user messages and competing answers are outside this scope. The session store checks the original writer and commits the answer. The registry then announces completion. A second sweep can reconcile a local commit without reading the server again.
This change includes both the host and the Codex consumer. It adds no scheduler, database migration, command replay or automatic parent recovery. The separate restart notice and worker activity display have already landed.
Evidence
Worker recovery on
295cf9bbI built this PR's tree alone with cached dependencies. In an isolated run with Codex CLI 0.172.0 and scripted inference, one managed worker read a unique value from a file. I held its final response, killed the Gateway with SIGKILL, restarted it and paused the original goal. Codex stayed up.
Idle-only
gateway.suspend.preparereported busy before the crash. After the parent answered the restart notice,sessions.describeshowedhasActiveRun=falsefor both chats. The parent still showedhasActiveSubagentRun=truein bothsessions.listandsessions.describe. Idle-only preparation granted a lease withactiveCount=0.I released the lease, then the worker's response. About 61 seconds later, the original parent chat showed an acknowledgement of the exact finding. That reply used a different native thread. I verified one worker answer, confirmed delivery and zero automatic turns during the next 25 seconds. The goal stayed paused.
Before replacing the remote server or its storage, check
/subagents info <runId>in the parent chat and confirm the task, delivery and parent's reply. Empty activity counts alone cannot establish that the worker finished.When the edit survives but the worker never sends a final answer
Each of two isolated trials on the same PR head used scripted inference and one worker with
cleanup: "keep"and no descendants. It edited a file and read it back. I killed both processes before the reply, confirmed both exits, and checked the edit. After restart I paused the original goal. Recovery remained pending. The parent calledsubagentswithaction: "cancel"and the exact worker run ID. Cancellation was confirmed. The worker record was removed and the child chat survived.sessions.goal.updateto complete the same goal. A wrong goal ID was refused. The correct operation required no further inference.Both completions survived another restart with unchanged file bytes and no repeated worker action. Cancellation alone cannot confirm a remote process stopped. Neither trial recovered a missing final answer.
Why a worker can stay pending after restart
I held a Codex worker's final response after it read a unique value from a file. On the same storage, two Codex 0.172.0 app-servers reported different states for the same thread, turn and client receipt. The executing server reported
inProgress, the second reader reportedinterruptedwith no completion time, and the executing server still reportedinProgress. I released the response. The second reader then reportedcompletedwith a completion time. Codex normalizes status using the reader's local knowledge of running work. An interruption without a completion time cannot justify discarding or repeating this task.One chat goal delegated through two levels. Both callers yielded before I interrupted the innermost worker's reply.
In both successful restart trials the parent received a separate startup notice before the finding. Each trial had one file read and zero automatic goal turns. Resume used the displayed goal state and the original native parent thread. A separate cold-start diagnostic found the same timestamp-free interruption on the new server and stopped when the parent startup notice used a different thread. It did not verify further delivery.
These were private, isolated Gateway trials using scripted inference on
9143f38awith this head and #193024, #206821, #207948 and #208197. Without an outage, the same build completed the nested goal in one automatic turn. No live provider or deployed upgrade was tested.Main integration at
295cf9bbI integrated
cd7baef2to resolve two conflicts with #207713. An ordinary interrupted run keeps the new interruption status. The pending-recovery hint remains specific to a claimed worker. The guide also warns that an idle Gateway can have a remote worker still running.The four affected suites passed 35 tests with one worker. They cover
/subagents info, local reply settlement, remote reply recovery and collectors. Formatting, type-aware lint on the changed handlers, and the staged test-line check passed. The packaged trials below predate this merge.Earlier packaged trials, compatibility checks and regression results
Remote workers across handoff
In an isolated build of
67e0e445together with #193024, #206821 and #207948 atd2956248, I held a managed worker through a crash. After the restart notice, the new Gateway reported an idle parent and a running child. Idle-only suspension granted a lease with zero tracked activity.A second Gateway handoff with Codex still running recovered one answer. In a separate trial the Codex server drained an in-flight response released 3.015 seconds after SIGTERM, exited cleanly, and restarted against the same storage. The parent received one answer and stayed paused. Gateway exit to verified readiness took 16.363 seconds in that trial. Both used Codex CLI 0.172.0 and scripted inference. Neither establishes safety for a forced kill, an expired termination grace period, or loss of storage.
Current stable upgrade and crash trial on
67e0e445I created a running worker and an unrelated saved chat in one process from v2026.11.11 (
a257c0f4). A second process opened the same SQLite files with the proposed build. Packagedopenclaw doctor --fix --non-interactiveexited 0. Shared schema 40 advanced to 42, and Agent schema 42 to 45. These migrations are already on main.I also crashed and restarted the packaged Gateway while a managed Codex 0.172.0 worker was waiting on a scripted provider after a successful file read. Earlier probes counted quoted chat history and an overlapping Gateway restart notice as possible inference from the command. The final probe waited for the separate startup notice and checked the full provider request sequence.
/subagents infoidentified the exact worker and showed the pending result. After completion, the same command showed the worker without the hint. Neither query required a model reply.Pending result in chat
At
67e0e445, an authorized/subagents info <runId>explains when a running worker has a pending recovery claim. It directs the requester to check the original worker and its connection before retrying. This adds no remote lookup and keeps the existing activity report. It does not change the retention policy above.The exact-ID command test covers a run that aged out of the active list. The previous handler omitted the recovery hint and failed that test. With the change, all 19 tests in the command suite passed in 101.43 seconds with one worker. An ordinary waiting worker and a killed run with a retained claim received no hint. The test uses a seeded registry. Formatting, type-aware lint and the test-line check passed.
Integration with local recovery
Local restart recovery is now on main. For an ordinary worker the local transcript is checked first, including a final from an earlier turn on a reused session. For a worker already claimed by remote recovery, even a reply saved locally must pass the original writer check. This covers a crash between saving the answer and recording completion. Before a claim exists, two failed local reads can still produce an interruption without consulting the remote worker. Closed database admission defers settlement. Check the original worker before repeating work.
On
0bdef669, 28 tests passed across the restart, worker reply and terminal effect suites in 211.22 s with one worker. Formatting and targeted type-aware lint passed. Removing only the check for an existing recovery claim made two of four worker reply tests fail. Neither the replacement writer nor the Stop control reported the expected rejection.The checks below ran on the earlier head
718d6355or the revisions named in each trial.Pinned runtime
I ran the packaged Gateway with the lockfile’s Codex CLI 0.172.0 and a synthetic provider in network isolation. The worker read a random value. I killed the Gateway while the worker was waiting for the model. The worker saved its final answer during the outage. The native progress and final messages both had numeric timestamps and null moderation metadata. The native schema also allows missing timestamps.
No progress text reached the parent. Both goals stayed idle for at least 25 seconds. One explicit Resume finished each goal on a different native thread. A separate trial on the same CLI combined this change with the goal handoff and thread preservation changes. The answer arrived once, 6.08 s after readiness. That goal needed one Resume too, and it finished on the original thread.
Stored data
v2026.11.10 → this PR. I started with the v2026.11.10 release tag at
6ea542fd. One process created a running managed worker, its Codex binding and transcript, and an unrelated saved chat. A direct read on718d6355refused the old Agent database withgateway.maintenance_required. I repeated the test with the packagedopenclaw doctor --fix --non-interactivefirst. Doctor exited 0. The shared database advanced from version 40 to 42 and the Agent database from 42 to 45. These migrations already exist on the base revision. With the fixture’s empty configuration, Doctor cleared cached harness IDs on both chats and updated the unrelated chat’s timestamp. The worker still had its original writer ID. The updated reader then opened both sessions, preserved the prior transcript entries and bindings, and settled the older worker with one interruption notice. It made no native history request, retried no work and removed neither chat. Both phases passed. I used exact source archives, cached dependencies and synthetic data. The older launch has no recovery receipt and took the ordinary interruption path. The new launch, claim and recovered reply were exercised in the pinned runtime trials above.Recent main → this PR → recent main. Three separate processes used a second set of synthetic SQLite records. Stock at
f1bec5a5wrote a running worker, Codex bindings, and messages in two sessions. The updated reader loaded them, settled the older worker with one interruption notice, and preserved the prior entries, bindings and unrelated session. No replacement attempt or native history request occurred. Stock then read those same settled records. This covers legacy data. It does not establish that an older writer can preserve a new recovery claim or launch receipt.Regression checks