Skip to content

fix(codex): session handoff stalls when a retired writer stays loaded - #196172

Merged
RomneyDa merged 6 commits into
openclaw:mainfrom
montrellcruse:fix/codex-stdio-retired-owner-timeout
Nov 23, 2026
Merged

RomneyDa merged 6 commits into
openclaw:mainfrom
montrellcruse:fix/codex-stdio-retired-owner-timeout

Conversation

@montrellcruse

@montrellcruse montrellcruse commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Related: #167280. Follow-up to #173580.

What Problem This Solves

A Codex follow-up can spend its entire startup budget waiting for a retired stdio process that another session still uses. If the target thread's release stays unconfirmed, startup cleanup can then close a healthy replacement client shared by other sessions.

User Impact

The handoff now reports a timeout after the existing ten-second thread-unload confirmation budget (distinct from the five-second unsubscribe-request budget). A failure before a thread write leaves the replacement client available for a later attempt. The timeout tells the user to retry the message shortly or continue in a new chat if the conversation still cannot resume. Resuming on another writer still requires proof that the old process exited or the exact thread unloaded.

Why This Change Was Made

The process-exit wait already respected caller cancellation. This change uses the existing timeout helper and pre-write cancellation callback at that same wait. A shorter whole-startup deadline still controls startup cleanup. The change adds no config, transport, or new source of ownership state. Native Codex acknowledges unsubscribe separately from shutdown and emits thread/closed after teardown completes. Native teardown at 0.164.0

Evidence

CI fixture repair (3d134196a0583)

The conflict-repaired head failed checks-node-changed-extensions-bundle-3 in thread-lifecycle.native-config.test.ts: its policy-change fixture expected already-admitted work to be revoked. Main's admission change in #202513 snapshots operator policy, including through the public plugin test host. The fixture now supplies the restricted policy at admission and retains both rejection assertions: a visible model-policy error and no native thread/turn dispatch. Missing-issuer coverage remains. Production code and the ten-second handoff/seven-second closure regression are unchanged.

Focused static lint, pinned formatter/pre-commit, and diff checks passed. A local baseline test attempt could not reach tests because the shared dependency installation lacks the TypeScript ./fs export. No passing local runtime or typecheck claim for this repair; fresh fork CI is required. Prior-head CI failed in this one test shard; all other non-aggregate jobs passed or were intentionally skipped.

Shutdown budget follow-up (071f3c870422e)

The retired-owner handoff now shares the existing ten-second thread-unload confirmation constant with configuration adoption. This avoids rejecting legitimate slow shutdowns while keeping bounded failure and healthy-client preservation. Unsubscribe RPCs retain their five-second limit; shorter whole-startup deadlines still take precedence.

A new production-startup-boundary regression delivers thread/closed after seven simulated seconds while a peer keeps the old process alive. It fails with timed_out on c3ebf5981fc4 and passes with this follow-up, with no resume before closure. Startup and adoption suites: 29 tests passed, 34.52 seconds wrapper wall time (30.75 seconds Vitest). Native seven-second teardown was not independently reproduced; this delayed-closure proof uses the existing synthetic native transport. Earlier native traces below remain evidence for their explicitly named older heads, not the updated ten-second timing. Current-head CI timing is pending.

The added test protects successful slow shutdown, which the never-closes timeout controls do not cover. The separate test-line allocation grants exactly 21 net lines for this regression.

Focused lint, extension production typecheck, formatting, and diff checks passed. Local ClawSweeper reviewed c3ebf5981fc4..071f3c870422e and found no actionable correctness or security defects.

Earlier-head evidence

Recorded native stdio trace on 87ddb73527d5 (macOS arm64, Codex 0.164.0). The managed launch used thread_unload_delay_secs=0. In the existing native test fixture, two app-server processes ran on stdio with disposable state and a loopback model. The following is terminal output from the deliberately unconfirmed sibling handoff. The old process answered for the same loaded thread after rejection. The same replacement client issued zero resume requests during the wait and then completed a fresh turn on its already-resumed conversation.

HANDOFF {"reason":"timed_out","message":"The previous Codex thread did not confirm shutdown before the handoff timed out. Try sending your message again in a few seconds. If the conversation still cannot resume, start a new chat.","elapsedMs":5001,"successorResumes":0}
OLD_OWNER {"method":"thread/read","sameThread":true,"status":"idle"}
REPLACEMENT {"method":"turn/start","terminalStatus":"completed","providerRequests":4}
 Test Files  2 passed (2)
      Tests  23 passed (23)

The startup regression separately exercises caller cleanup and checks that the healthy client's input stays open. To repeat the native trace, apply the patch below to the test fixture at 87ddb73527d5 (the current head instead uses ten seconds). The provider count includes earlier fixture turns.

Repeat the historical five-second trace on `87ddb73527d5`

Save the following diff to trace.diff and run:

git apply trace.diff
pnpm test extensions/codex/src/app-server/thread-lifecycle.handoff.native.test.ts \
  -t 'resumes after an untracked' --maxWorkers=1
diff --git a/extensions/codex/src/app-server/thread-lifecycle.handoff.native.test.ts b/extensions/codex/src/app-server/thread-lifecycle.handoff.native.test.ts
index 230bfda44..128975557 100644
--- a/extensions/codex/src/app-server/thread-lifecycle.handoff.native.test.ts
+++ b/extensions/codex/src/app-server/thread-lifecycle.handoff.native.test.ts
@@ -174,6 +174,8 @@ it(
       });
       const stop = new AbortController();
       let settled = false;
+      const started = performance.now();
+      const replacementRequests = vi.spyOn(successor, "request");
       const fenced = releaseCodexBoundLiveThread({
         client: successor,
         clientId: successor.getInstanceId(),
@@ -191,11 +193,21 @@ it(
           runNativeTurn(old, sibling.thread.id, "Keep the sibling usable while handoff waits."),
         ).resolves.toMatchObject({ status: "completed" });
         expect(settled).toBe(false);
-        const cancelled = new Error("Stop only the waiting handoff");
-        stop.abort(cancelled);
-        await expect(fenced).rejects.toBe(cancelled);
+        const error = await fenced.then(() => { throw new Error("Unexpected handoff"); }, e => e);
+        const elapsed = Math.round(performance.now() - started);
+        expect(error).toMatchObject({reason: "timed_out", message: expect.stringContaining("start a new chat")});
+        const successorResumes = replacementRequests.mock.calls.filter(([method]) => method === "thread/resume").length;
+        expect(successorResumes).toBe(0);
+        console.log("HANDOFF", JSON.stringify({reason: error.reason, message: error.message, elapsedMs: elapsed, successorResumes}));
+        const ownerState = await old.request("thread/read", {threadId: sibling.thread.id, includeTurns: false});
+        expect(ownerState.thread.id).toBe(sibling.thread.id);
+        expect(ownerState.thread.status.type).not.toBe("notLoaded");
+        console.log("OLD_OWNER", JSON.stringify({method:"thread/read", sameThread: ownerState.thread.id === sibling.thread.id, status:ownerState.thread.status.type}));
+        const next = await runNativeTurn(successor, resumed.threadId, "Reply on the healthy replacement after handoff failure.");
+        expect(next).toMatchObject({status:"completed"});
+        console.log("REPLACEMENT", JSON.stringify({method:"turn/start", terminalStatus:next.status, providerRequests}));
         expect(old.getCloseError()).toBeUndefined();
-        expect(providerRequests).toBe(3);
+        expect(providerRequests).toBe(4);
       } finally {
         stop.abort();
         await Promise.allSettled([fenced]);
  • Hosted CI for a798639084d5 passed. The required CI and security gate also passed on that commit.

  • Red on 6edcaa28edb7, green on a798639084d5. With a 60-second startup budget and a live peer holding the retired process, the new test advances five seconds and then releases the peer. On the base, startup was still waiting and could resume. With the fix, it has already rejected and preserved the healthy client. The existing one-second startup-timeout control passes on both.

  • Real stdio, managed settings, macOS arm64, Codex 0.164.0. Upstream's native test uses two real app-server processes, disposable state, thread_unload_delay_secs=0, and a loopback model fixture. The ordinary resume succeeded. For the deliberately untracked, still-loaded sibling, the handoff remained pending through an extra 65-second observation on the base. With the fix, the equivalent handoff rejected about five seconds after the sibling's successful turn. This exercises unconfirmed release. An ordinary managed unsubscribe separately completed in 2–12 ms.

  • Six focused suites, 120 tests passed on c3ebf5981fc4, covering native handoff, startup, adoption, cancellation, and configured-MCP ownership. Focused typecheck, lint, formatting, diff, and test-line checks passed. Both deadline cases retain their explicit cleanup assertions. Sharing the test config responder reduces counted test lines by six versus the base and removes the need for an allocation. The production change remains +17 lines.

Repeat the 65-second observation on the base

In a disposable checkout of 6edcaa28edb7817efda38eccc4f0c7fd13ad148c, install with pnpm install --frozen-lockfile. Extend the observation in the existing native test:

python3 - <<'PY'
from pathlib import Path
p = Path("extensions/codex/src/app-server/thread-lifecycle.handoff.native.test.ts")
s = p.read_text()
point = "        expect(settled).toBe(false);"
assert s.count(point) == 1
s = s.replace("{ timeout: 30_000 }", "{ timeout: 95_000 }", 1)
p.write_text(s.replace(point, "        await new Promise((resolve) => setTimeout(resolve, 65_000));\n" + point))
PY
pnpm test extensions/codex/src/app-server/thread-lifecycle.handoff.native.test.ts \
  -t 'resumes after an untracked' --maxWorkers=1

The expect(settled).toBe(false) assertion passed after 65 seconds, then the fixture explicitly canceled the wait. On the PR branch, run the committed short regression:

pnpm test extensions/codex/src/app-server/attempt-startup.test.ts \
  -t 'bounds retired-owner handoff' --maxWorkers=1

@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-run

@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 9, 2026
@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head c3ebf5981fc449e107635221bcbc241d310419be, but the PR head is now 071f3c870422e0ef2aa63588de10a93ad63a6153. 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 (2 earlier review cycles)
  • reviewed 2026-11-09T18:37:27.534Z sha a798639 :: needs real behavior proof before merge. :: [P3] Add a recovery action to the handoff timeout
  • reviewed 2026-11-09T19:30:10.955Z sha c3ebf59 :: needs maintainer review before merge. :: none

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 9, 2026
@roboclaw-bot roboclaw-bot added the clawtributors PR from a clawtributor label Nov 10, 2026
@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 18, 2026
@RomneyDa
RomneyDa merged commit 1d409a2 into openclaw:main Nov 23, 2026
110 of 111 checks passed
tideclaw-bot pushed a commit that referenced this pull request Nov 23, 2026
…#196172)

* fix(codex): bound stalled session handoff from a retired process

* fix(codex): explain how to recover from a handoff timeout

* test(codex): reuse empty config responses in handoff fixtures

* fix(codex): allow slow thread shutdown during handoff

* test(codex): enforce model policy at admission in native config fixture

---------

Co-authored-by: Dallin Romney <[email protected]>

(cherry picked from commit 1d409a2)

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…#196172)

* fix(codex): bound stalled session handoff from a retired process

* fix(codex): explain how to recover from a handoff timeout

* test(codex): reuse empty config responses in handoff fixtures

* fix(codex): allow slow thread shutdown during handoff

* test(codex): enforce model policy at admission in native config fixture

---------

Co-authored-by: Dallin Romney <[email protected]>

(cherry picked from commit 1d409a2)

Release adaptation: As in 2026.11.8 stable ed39478, preserve the stronger existing mid-preparation policy regression; omit the upstream admission-only rewrite. The handoff implementation and its regressions apply unchanged.

Companion audit: #204249 is a separate authority refactor, not applicable. Verified sibling Codex d32063f96c2d, codex-rs/app-server/src/request_processors/thread_processor.rs:1153-1183 and rollout/src/writer_lock.rs:226-238.

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 24, 2026
…openclaw#196172)

* fix(codex): bound stalled session handoff from a retired process

* fix(codex): explain how to recover from a handoff timeout

* test(codex): reuse empty config responses in handoff fixtures

* fix(codex): allow slow thread shutdown during handoff

* test(codex): enforce model policy at admission in native config fixture

---------

Co-authored-by: Dallin Romney <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawtributors PR from a clawtributor extensions: codex P2 Normal backlog priority with limited blast radius. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants