Skip to content

fix: recover a completed Codex reply after a brief disconnect - #205298

Draft
freeqaz-openai wants to merge 9 commits into
mainfrom
fix/codex-disconnected-goal-replies
Draft

freeqaz-openai wants to merge 9 commits into
mainfrom
fix/codex-disconnected-goal-replies

Conversation

@freeqaz-openai

@freeqaz-openai freeqaz-openai commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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

  • On abnormal socket closure, recheck the current session, binding, runtime and turn. Read the latest parent turn at most twice within ten seconds. A proven foreground wait can acknowledge an already completed first child without a second wake.
  • When reusing a worker, distinguish the previous assignment from the accepted successor. Release an unused input reference once that exact task succeeds. Keep the separate reference for result delivery.
  • When the parent has already detached, keep the accepted worker receipt through cleanup and attempt a bounded history read on the original endpoint. Require the latest completed successor of that child, current delivery authority and an unconsumed receipt. Use the existing per-turn delivery claim. Other workers keep their receipts.
  • If the latest turn is the exact accepted successor and is in progress, observe it on the read-only connection. An idle or unloaded notification for that worker triggers a fresh read. A system error clears the running status without triggering an immediate read. After five quiet minutes, check the thread’s status without loading its turns. Each read has a ten-second deadline. A live parent that takes back the same active assignment takes precedence.

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 e56ce1d9

OpenClaw 3ae62ae0 recovered 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.

Check 3ae62ae0 e56ce1d9
Parent received the fifth answer while paused No receipt within 45 s of releasing the answer One receipt naming the exact turn
After one explicit goal Resume Skipped because the receipt was missing Two more tasks on the same worker, one goal completion

The 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 398c8db2 with #193024 at a4e8d899 and #206231 at b917e9cb. Only one included the changes from this PR at 3ae62ae0. 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.

  • Both builds completed active goals exactly once, with and without a socket drop.
  • When the parent was deliberately paused before disconnect, the worker completed both tasks in each run. Both builds reconnected. The PR delivered exactly one acknowledgment identifying the second answer's exact turn, 1.532 seconds after the scripted answer. The parent remained paused.
  • The control failed the acknowledgment check after 40.256 seconds from confirmed worker completion. Its later outcome is unknown.

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.

  • At 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.
  • At 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 82b682c6 alongside #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.ts suite 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. Candidate 3e0756c7 reopened 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.describe with includeNativeSubagents lost 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.

/goal resume Read the current goal. Wait for the existing worker and verify its result. Do not resend the task or spawn a replacement.

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_agent on the existing worker. The native server stayed up.

The available registry lacked the locked @openclaw/fs-safe version. 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.

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.
@clawsweeper

clawsweeper Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 25, 2026
@clawsweeper

clawsweeper Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 73d215ef70297b3c734bd5c6cc1fe9b2b6c7dc28, but the PR head is now afd551cc464653d960b1ab7b14db5fffc065a0af. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (1 earlier review cycle)
  • reviewed 2026-11-25T11:38:10.607Z sha 73d215e :: blocked before merge. :: none

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.
@clawsweeper clawsweeper Bot removed the rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. label Nov 26, 2026
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.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nostr Channel integration: nostr labels Nov 27, 2026
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.
@freeqaz-openai

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀

Re-review progress:

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: android App: android app: linux app: macos App: macos app: web-ui App: web-ui channel: a2a channel: mattermost Channel integration: mattermost channel: nextcloud-talk Channel integration: nextcloud-talk cli CLI command changes commands Command implementations docker Docker and sandbox tooling docs Improvements or additions to documentation extensions: clawrouter Extension: clawrouter extensions: codex extensions: github GitHub plugin: link previews and reader extensions: google extensions: ollama extensions: qwen extensions: runway extensions: tokenjuice Changes to the bundled tokenjuice extension extensions: vydra gateway Gateway runtime impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. P1 High-priority user-facing bug, regression, or broken workflow. plugin: file-transfer plugin: knowledge plugin: skill-workshop plugin: workboard scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant