Skip to content

fix(codex): next turn stalls after Stop during session handoff - #173580

Merged
RomneyDa merged 1 commit into
openclaw:mainfrom
LLagoon3:fix/codex-preserve-startup-client-handoff
Oct 16, 2026
Merged

RomneyDa merged 1 commit into
openclaw:mainfrom
LLagoon3:fix/codex-preserve-startup-client-handoff

Conversation

@LLagoon3

@LLagoon3 LLagoon3 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Related: #167280

What Problem This Solves

Fixes: the next Codex turn can stall for minutes when Stop interrupts startup while it is waiting for a retired predecessor app-server to exit.

User Impact

User impact: a pre-write Stop now releases the interrupted attempt without retiring the healthy app-server needed by peers and the next turn. Startup deadlines, in-flight native requests, and post-thread/start handoffs keep the existing conservative retirement behavior. No migration or user action is required.

Why This Change Was Made

The predecessor-exit wait now reports the narrow case where cancellation happened before the current client wrote thread state. Startup preserves its healthy client only for that case while leaving the predecessor writer fence in place, so a successor still waits for the old process to physically exit before thread/resume.

Evidence

  • Negative control: the new Stop regression fails against the original production files because the healthy client is retired, then passes with this change.
  • Mutation check: removing the post-write exclusion makes the configured-MCP ownership regression fail.
  • Focused Docker tests: 6 files, 56 tests passed.
  • Static validation: extension production/test typechecks, targeted lint, formatting, and git diff --check passed.
  • Repository pr-simplify audit: no redundant implementation or tests were found. The three regression boundaries independently cover pre-write Stop preservation, deadline retirement, and post-thread/start cleanup.
  • Required isolated Docker lane: pnpm test:extension codex completed all 25 chunks. All 12 database-worker chunks passed; all 13 app-server chunks completed with one failure in client-catalog-preview.test.ts. The same test fails identically on the untouched base commit f1d0c07dfa7, so it is unrelated to this change. The startup/abort regressions passed in both execution variants.
  • GitHub CI: 46 checks passed with no failures or pending checks.
  • Native writer-fence behavior was checked against the pinned Codex rust-v0.161.0 source.
  • Fresh local Codex autoreview was attempted after the contribution audit, but the Codex CLI rejected authentication before producing a report. The workflow did not substitute another review engine or claim a clean automated review; the final diff was reviewed manually.

Native runtime proof

An isolated Docker proof exercised the production startCodexAttemptThread path with the shipped pinned Codex app-server binary, a local scripted provider, and no operator credentials. The binary identified itself as 0.161.0 with SHA-256 9a820c17865fa825d04db416818679a9d63bd72e50835c396f496e5684626c9c.

predecessor turn persisted
pre-write predecessor-exit wait entered
Stop settled: predecessorAlive=true replacementHealthy=true resumeSent=false
successor reused replacement: appServerStarts=2
predecessor physical exit
replacement native RPC: thread/resume
successor resumed: sameReplacementClient=true
proof complete: writerFencePreserved=true

The proof passed as one native test in 11.3 seconds. The predecessor's physical-exit event was sequence 14 and the replacement's native thread/resume was sequence 15, demonstrating that Stop preserved the healthy client without weakening the writer fence. The proof harness was temporary and was removed after the run; the committed regression remains the deterministic synthetic-transport test.

…ndoff

A Codex startup that was waiting for a retired predecessor client to exit
retired its own newly acquired client when the caller stopped it, even
though that client had not written any thread state. Peers sharing the
healthy client were stranded and the next turn had to start a new process.

The predecessor-exit wait now reports, during abort dispatch, that it was
canceled before this client wrote thread state; startup then releases its
lease without retiring the client. The old owner's writer fence is
unchanged: the next writer still waits for its physical exit. Startup
timeouts, in-flight requests, and the post-start configured-MCP handoff
keep retiring the client.

Related: openclaw#167280
@clawsweeper

clawsweeper Bot commented Oct 16, 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. 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. labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Preserves the healthy shared Codex app-server when Stop cancels a predecessor-exit wait before thread writes.

Example: Stop interrupts startup while a peer keeps the predecessor app-server alive.

  • Before: The healthy replacement is retired, and the successor starts a third app-server.
  • After: The successor reuses the replacement and sends thread/resume only after the predecessor exits.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused repair with native transport evidence, meaningful regression controls, successful exact-head checks, and no findings; proof exercises the production owner through a harness.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): The exact-head maintainer trace exercises production startCodexAttemptThread with two real Codex 0.161.0 app-server processes, isolated state, and a loopback provider; Stop preserves the replacement, the successor reuses it, and native resume follows predecessor physical exit, while the base negative control starts a third process.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Stopping a Codex startup can retire a healthy shared app-server and delay the next turn.
Reason: The change repairs the demonstrated pre-write cancellation case without changing defaults, configuration, or uncertain-write cleanup.

Merge readiness

✅ Ready for maintainer review

This PR repairs a current-main cancellation bug and has no actionable findings; the new native-runtime evidence resolves the previous proof blocker.

Priority: P1
Reviewed head: f5e9dc46d236cdb7f5f658fb0c113350cbb31adc

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Codex plugin turns session startup and cancellation into native thread lifecycle operations, managing shared-client leases and predecessor writer fencing.

flowchart TD
  A[Session turn or Stop] --> B[Attempt startup]
  B --> C[Shared client lease]
  C --> D[Thread lifecycle]
  D --> E[Predecessor physical exit]
  E --> F[Native thread resume]
  D --> B
Loading

Technical review

Best possible solution:

Merge the focused pre-write cancellation repair while retaining deadline retirement and predecessor writer fencing.

Do we have a high-confidence way to reproduce the issue?

Current-main cleanup exposes the reported retirement path, and the supplied native base-versus-head trace demonstrates its observable consequence; no target code was executed during this review.

Is this the best way to solve the issue?

The lifecycle owner reports the precise safe cancellation boundary to startup cleanup, avoiding a broad relaxation of retirement or writer-lock safeguards.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5462f7f14643.

Provenance checked

  • Abandoned-startup retirement changes intended behavior with a stated reason (5a0d9d6: History records retirement of abandoned startups; older commit contents were unavailable locally and the commit-to-PR lookup returned no associated PR.)
  • Abortable physical-owner exit wait keeps the original intent (fix(codex): release stalled startup waits on cancellation #168347: Cancellation must free the abandoned queue and binding lease while successors independently retain physical-exit fencing.)
  • Configured-MCP replacement ordering keeps the original intent (fix(codex): preserve configured MCP tools in scheduled turns #120366: Retain the predecessor until its replacement commits, preserving a single authoritative binding.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +36, Tests +179. Total +215 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 44 8 +36
Tests 2 180 1 +179
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 224 9 +215

Review metrics

Metric Value Why it matters
Production versus test changes Production +44/-8; tests +180/-1 The test growth covers client preservation, unchanged deadline retirement, and the post-write exclusion, with reported negative and mutation controls.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #167280
Summary: This PR addresses the related report's remaining pre-write healthy-client retirement case.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Unnecessary shared-client retirement disrupts subsequent Codex turns and can affect sibling sessions.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-16T00:29:15.183Z sha f5e9dc4 :: needs real behavior proof before merge. :: none

Reviewed October 15, 2026, 10:57 PM ET / October 16, 2026, 02:57 UTC (Revision 2).

@RomneyDa

Copy link
Copy Markdown
Member

Maintainer proof for exact head f5e9dc46d236cdb7f5f658fb0c113350cbb31adc (release lane, 2026.10.5).

Native runtime proof (pinned Codex 0.161.0 binary, before/after)

A temporary native test (not committed) drove the production startCodexAttemptThread path through two real codex app-server processes (pinned @openai/codex 0.161.0 darwin-arm64 binary, isolated CODEX_HOME, scripted loopback Responses provider, no operator credentials):

  1. Session binds a thread on app-server fix: add @lid format support and allowFrom wildcard handling #1 (predecessor) and persists a real turn.
  2. Another lease keeps the retired predecessor (and its native writer lock) alive.
  3. A new attempt starts app-server Login fails with 'WebSocket Error (socket hang up)' ECONNRESET #2 and enters the pre-write wait for the predecessor's exit; Stop fires.
  4. A successor attempt starts; then the peer releases the predecessor.

PR head: Stop settles with the replacement still healthy; the successor reuses it, and thread/resume is sent only after the predecessor's physical exit.

{"sequence":7,"event":"app-server-start","name":"replacement","starts":2}
{"sequence":9,"event":"prewrite-exit-wait-entered"}
{"sequence":10,"event":"stop-settled","aborted":true,"predecessorAlive":true,"replacementClosed":false}
{"sequence":12,"event":"peer-releases-predecessor"}
{"sequence":14,"event":"physical-exit","name":"predecessor"}
{"sequence":15,"event":"native-rpc","name":"replacement","method":"thread/resume"}
{"sequence":17,"event":"successor-ready","sameReplacementClient":true,"threadId":"same-thread","appServerStarts":2}
{"sequence":18,"event":"writer-fence","predecessorExitSeq":14,"resumeSeq":15}
✓ keeps the healthy app-server and preserves the writer fence 8051ms

Base f1d0c07dfa7 (same test, production files reverted): Stop tears down the healthy replacement, so the successor pays a third app-server cold start.

{"sequence":9,"event":"prewrite-exit-wait-entered"}
{"sequence":10,"event":"client-closed","name":"replacement"}
{"sequence":11,"event":"physical-exit","name":"replacement"}
{"sequence":12,"event":"stop-settled","aborted":true,"predecessorAlive":true,"replacementClosed":true}
{"sequence":13,"event":"app-server-start","name":"extra-3","starts":3}
{"sequence":20,"event":"successor-ready","sameReplacementClient":false,"threadId":"same-thread","appServerStarts":3}
× AssertionError: expected 3 to be 2

Committed regression, negative control

pnpm test extensions/codex/src/app-server/attempt-startup.test.ts -t "retired owner's exit" with production files reverted to base: the Stop regression fails (expected true to be false, healthy client stdin destroyed); the deadline regression still passes. On the PR head, attempt-startup.test.ts (17 tests) and thread-lifecycle.configured-mcp-ownership.test.ts pass.

Codex dependency check

Inspected ../codex at rust-v0.161.0 (979011409de0): codex-rs/rollout/src/writer_lock.rs WriterLockCoordinator::acquire takes an exclusive per-thread file lock that WriterLockGuard holds until the owning process releases it. The patch keeps the wait-for-physical-exit fence before thread/resume, and the native trace above confirms the ordering.

Autoreview (gpt-6.1-sol, branch vs origin/main, P1 threshold): scoped-clean, no findings.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. labels Oct 16, 2026
@RomneyDa
RomneyDa merged commit 0169c8a into openclaw:main Oct 16, 2026
140 checks passed
RomneyDa pushed a commit that referenced this pull request Oct 16, 2026
…ndoff (#173580)

Backport (partial): keeps the production change and the thread-lifecycle
regression test; main-only attempt-startup harness tests stay on main.

A Codex startup that was waiting for a retired predecessor client to exit
retired its own newly acquired client when the caller stopped it, even
though that client had not written any thread state. Peers sharing the
healthy client were stranded and the next turn had to start a new process.

The predecessor-exit wait now reports, during abort dispatch, that it was
canceled before this client wrote thread state; startup then releases its
lease without retiring the client. The old owner's writer fence is
unchanged: the next writer still waits for its physical exit. Startup
timeouts, in-flight requests, and the post-start configured-MCP handoff
keep retiring the client.

Related: #167280

Co-authored-by: LLagoon3 <[email protected]>
(cherry picked from commit 0169c8a)
@LLagoon3

Copy link
Copy Markdown
Contributor Author

Follow-up contribution-gate refresh for exact head f5e9dc46d236cdb7f5f658fb0c113350cbb31adc:

  • pr-simplify: no redundant implementation or tests found; the three regression boundaries remain distinct.
  • Isolated Docker pnpm test:extension codex: all 25 chunks completed. Database-worker 12/12 passed; the app-server lane had only the known client-catalog-preview.test.ts failure that reproduces identically on untouched base f1d0c07dfa7. The changed startup/abort regressions passed in both variants.
  • Fresh local Codex autoreview was attempted, but authentication failed before a report was produced. No alternate engine was substituted and no automated-clean claim is made.
  • No code or head change; operational Gateway remained untouched.

The PR body now records these results.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

ClawSweeper could not start a re-review for this item.
Reason: re-review requires an open issue or PR.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
…ndoff (openclaw#173580)

A Codex startup that was waiting for a retired predecessor client to exit
retired its own newly acquired client when the caller stopped it, even
though that client had not written any thread state. Peers sharing the
healthy client were stranded and the next turn had to start a new process.

The predecessor-exit wait now reports, during abort dispatch, that it was
canceled before this client wrote thread state; startup then releases its
lease without retiring the client. The old owner's writer fence is
unchanged: the next writer still waits for its physical exit. Startup
timeouts, in-flight requests, and the post-start configured-MCP handoff
keep retiring the client.

Related: openclaw#167280

Co-authored-by: LLagoon3 <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 16, 2026
…ssion handoff (#173580)"

This reverts commit b2190df.

FRV #1 for 2026.10.5 failed every Docker live Codex lane with
"thread ... already has an active writer" during session handoff, the path the
partial backport changed. #173580 is a P1 fix, not a 10.5 regression; it stays
on main and is dropped from this stable.
RomneyDa pushed a commit that referenced this pull request Oct 27, 2026
…ndoff (#173580)

A Codex startup that was waiting for a retired predecessor client to exit
retired its own newly acquired client when the caller stopped it, even
though that client had not written any thread state. Peers sharing the
healthy client were stranded and the next turn had to start a new process.

The predecessor-exit wait now reports, during abort dispatch, that it was
canceled before this client wrote thread state; startup then releases its
lease without retiring the client. The old owner's writer fence is
unchanged: the next writer still waits for its physical exit. Startup
timeouts, in-flight requests, and the post-start configured-MCP handoff
keep retiring the client.

Related: #167280

Co-authored-by: LLagoon3 <[email protected]>
(cherry picked from commit 0169c8a)

Release adaptation: 2026.10.10's predecessor-exit wait also races exact thread closure and stops its watcher; the cancellation hook now wraps that existing race.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants