Repository navigation
fix: recover a completed Codex reply after a brief disconnect - #205298
Draft
freeqaz-openai wants to merge 9 commits into
Draft
freeqaz-openai wants to merge 9 commits into
freeqaz-openai wants to merge 9 commits into
Conversation
Read the accepted turn from the original endpoint without resending it. When a restored parent already received the only result of a newly spawned child, keep that receipt so a finished goal stays finished.
Contributor
|
🦞👀 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. |
Contributor
|
Codex review: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
Let the original monitor reconcile a completed foreground wait before it wakes the parent. Restore the sole proven prior assignment and its receipts before sending new input to a cold worker. A delayed first receipt must not acknowledge the second result.
A submitted turn can be accepted from history before the native start event arrives. Retire its unmatched input reference only on verified success for that exact turn. Keep result delivery and other assignments protected.
Preserve main's specific refusal when a resumed worker is no longer tracked but its own metadata names another parent. An unbound root still fails the original scope check. Only send_input reports an accepted submission ID. The ownership regression failed on a text-only conflict resolution. Keep that test unchanged and recheck input scope and inventory.
Keep the last settled turn ID for up to 256 direct workers on a monitor. When an older page exists, accept the latest successful turn as a predecessor only if it matches that worker and parent. This lets a later accepted task survive a disconnect after the previous parent registration has been pruned. A fresh client with ambiguous history still cannot infer an assignment.
Contributor
Author
|
@clawsweeper re-review |
Contributor
|
🦞👀 Re-review progress:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem this solves
After a Codex WebSocket disconnect, chat can report a failure even though the native parent saved its answer. A worker result can also wake the parent twice, or disappear when the same worker finishes another task. If the parent is idle, the Gateway can declare shutdown safe before it has delivered the result.
User impact
The Codex plugin recovers completed replies after brief connection loss. It leaves a paused goal paused, respects Stop, and never resubmits work or executes tools from history. If an acknowledged follow-up on the same worker is still running, the plugin watches for its result. Failed or ambiguous work can still require explicit recovery.
How it works
Use verified TLS or a trusted isolated endpoint. A bearer token alone cannot authenticate the server. The changes stay inside the Codex plugin.
Current revision and merge dependency
Keep this draft open for runtime review. A second observer can confirm a worker result while the first is still preparing delivery. The shared receipt guard addresses that separate race. Require it and runtime maintainer review before marking this draft ready.
At
e408375f, the Codex adapter tracks disconnected reads and reports whether the parent is still waiting. The shared completion owner controls delivery, retry and retirement. The merge retains the previous draft’s history.Evidence
Current worker loop
The resolved draft passed 241 focused cases across 12 files before lint cleanup. The final tree passed 88 affected cases across five files. All 28 changed files passed formatting and type-aware lint.
A separate network-isolated Linux test combined the draft with #193024, #206231, #206529 and the shipped runtime patches on
5e245aa0. The real Gateway and Codex CLI used synthetic inference and older cached build dependencies. The same worker completed seven turns. One reply arrived during a disconnect. The parent used each new answer once, honored Pause, and completed the goal after an explicit Resume. These are selected results from the combined build. They do not qualify a release image or prove that this draft alone completes the loop.{"ok":true,"status":"complete","overlaps":5,"workerTurns":7,"observed":{"active":false,"status":"complete","pendingInputs":0,"continuations":13,"announcements":6,"completions":1},"freshAnswers":6,"distinctReceipts":6,"resumed":true,"disconnect":{"connectionsBefore":1,"droppedSockets":2,"completedWhileOffline":true,"connectionsAfter":3}}Repeated worker tasks at
e56ce1d9OpenClaw
3ae62ae0recovered one follow-up but missed a later one after parent registration was pruned. Codex’s latest-turn summary included a cursor to older history. The fix retains IDs for up to 256 settled direct worker assignments in the same monitor and requires an exact match with the newest validated successful turn before inferring a predecessor from paged history.I ran a real Gateway and Codex 0.164.0 with scripted answers on Linux. Both builds included the two proposals and upstream pin listed below. Only the worker input preparation code differed. I paused the parent on the fourth reuse and cut its loopback connection. The test held every new connection until a separate history read confirmed the worker’s fifth task had finished.
3ae62ae0e56ce1d9The successful run recorded seven worker turns, six distinct follow-up receipts and zero pending inputs. The earlier build’s later outcome is unknown.
The test-only change failed three cases before the fix. The three affected suites passed 88/88 in 172.75 seconds with the fix and cached compiler output. A different latest turn still failed to qualify. Lint and formatting passed. A fresh monitor or an evicted record cannot infer a predecessor from multiple turns.
Worker acknowledgment after reconnect
Both builds used upstream main
398c8db2with #193024 ata4e8d899and #206231 atb917e9cb. Only one included the changes from this PR at3ae62ae0. The test used a real Gateway and Codex 0.164.0 over loopback WSS, cached older dependencies, and scripted inference.The same worker handled two successive tasks, with its second answer held until the foreground turn settled.
On the first conflict resolution, 225 of 226 tests passed. The existing regression from #206114 caught a generic error when a resumed worker belonged to another parent. I corrected the refusal and kept the test unchanged. All 68 tests in the three affected suites passed in 248 seconds, including compilation. Type-aware lint and formatting passed.
Earlier packaged comparisons
I ran a real Gateway and Codex CLI with synthetic inference. One goal used the same worker twice. I dropped the socket during the first wait, paused the parent after the second submission, and dropped the socket again after the worker finished but before the Gateway received the notification.
96b29225, after 60.536 s the parent had no result and the Gateway reported ready to stop. A separate read found the exact completed turn and answer.42682e51, shutdown stayed blocked while the worker ran, after it finished, and during a deliberately held history read. One announcement arrived 1.393 s after the second disconnect. Explicit Resume read the original goal and completed it. After returning to the original Gateway, the same session and threads retained both answers.The packaged comparisons used CLI 0.164.0 and the production changes on OpenClaw
82b682c6alongside #193024. Earlier trials on CLI 0.164.0 and 0.169.0 exercised the original foreground recovery. The remote configuration change in #201621 was omitted from this trial.Earlier tests covered changed certificates, wrong turns, Stop, concurrent registration, queued siblings and stale authority. Removing the cleanup fixes left an extra receipt for the completed task and produced an unhandled abort.
Disconnect before the worker finishes
I paused the parent, disconnected while the worker was still running and held the response for over eleven seconds. At
42682e51, the Gateway reported ready to stop and the parent missed the result.At
3e0756c7, the worker was the only shutdown blocker after 11.406 s. The Gateway still refused to stop during the result read. The parent received one announcement 2.313 s after the worker replied and stayed paused until Resume. With an active goal, the next automatic turn waited on the same worker. It finished without another input or announcement. An intermediate build without the handoff attempted a redundant announcement. In both cases the worker ran exactly two tasks.Lint, formatting and the commit hook passed. The updated
native-subagent-submission-store.test.tssuite passed 39/39 in 230.89 s with one worker, including compilation. Six additional cases took 10.459 s total. They cover both orders of a status change during the read, an inconclusive reread, authority revoked while waiting, an unrelated parent releasing its guards and re-registration on a live connection.Stored worker records across an upgrade and return
Three separate Vitest processes using local dependencies ran the old, proposed and old binding-store code against the same SQLite database. The PR merge base (
81d69df5) wrote two synthetic V1 child receipts and an assignment with a recorded result. Candidate3e0756c7reopened the database and recovered both receipts and the assignment exactly. It rejected an incorrect submission ID without modifying the row, then consumed only the matching receipt and assignment. On return, the original code reopened the same parent binding with only the sibling receipt remaining. No schema migration was needed.The probe reused the fixture in
native-subagent-submission-store.test.ts. Each process passed one assertion-based test and reported its final state.{"phase":"seed","assignments":1,"submissions":2,"binding":true} {"phase":"candidate","assignments":0,"submissions":1,"binding":true} {"phase":"return","assignments":0,"submissions":1,"binding":true}Worker visibility during recovery
At
3e0756c7,sessions.describewithincludeNativeSubagentslost the running worker after a disconnect, even as the plugin watched for its result. The session now shows the worker from that same watcher while its pending assignment, session and delivery authority remain valid. A live parent takes priority. This adds no Codex RPC or permission.With the plugin changes from
afd551cc, the same worker was visible 11.421 s after the disconnect. Shutdown still reported busy. The parent received one result and the running row disappeared. One explicit Resume completed the paused goal. Switching back preserved both results.The binding-store suite now registers the recovery scenarios in a separate file. Three cases failed on the prior implementation. All 43 cases passed with the fix, including status changes during a read, an unrelated turn and five simulated minutes without a notification. The final suite took 244.58 s on one worker including compilation, with zero skips. The split keeps the same cases and order.
Limits
Detached observation requires a saved, acknowledged follow-up under the same authority. A lost recovery connection, changed binding, read timeout or inconclusive history can still leave the result pending. These trials used local maintenance restarts. They do not establish zero downtime or recovery across a cluster outage.
The worker view relies on status changes from the recovery connection between reads. An empty worker list can mean observation was lost. If observation fails, a ready-to-stop status alone cannot prove that the worker finished. Reconcile the original task before shutdown or resubmission. If the goal is paused and you intend to resume it, the following command worked in the same conversation on the original Gateway.
Resume starts a parent turn. Check for activity, unresolved effects and the reason for the pause first. In the unmodified Gateway trial, the scripted parent used
wait_agenton the existing worker. The native server stayed up.The available registry lacked the locked
@openclaw/fs-safeversion. Local typechecking with the existing dependencies reported the same 48 diagnostics before and after the change. Exact-lockfile CI and maintainer review remain outstanding. Independent source reviews were completed. The standalone review helper could not start on this host.