Skip to content

fix: recover queued Codex chats and preserve startup failures - #182104

Merged
RomneyDa merged 7 commits into
mainfrom
openclaw/quiet-barnacle-2
Oct 26, 2026
Merged

RomneyDa merged 7 commits into
mainfrom
openclaw/quiet-barnacle-2

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes queued Codex chats staying at “Waiting for turn to start…” after a plugin reload, and startup failures or cancellations being replaced by terminal-accounting errors.

User Impact

A chat whose old thread already unloaded can resume without waiting for unrelated chats to release the retired Codex process. Startup errors retain their intended reply, and cancellation remains cancellation. Still-loaded threads, genuine session/writer replacements, and active ownership remain fenced; execution is not replayed. No configuration, schema, or migration changes are required.

Why This Change Was Made

Preserve the turn's already-claimed writer through rejected and aborted outcomes. For the separate Codex startup wait, recover a missed closure receipt with one metadata-only read from the exact old client: only a matching thread with notLoaded status permits handoff. Native resume still enforces its exclusive persistence writer lock. Process exit, exact closure, and cancellation retain their existing ownership and cleanup paths.

Incorporates @jjjhenriksen's follow-up #182161 at 2ebd4018179148e3b8fc8faf592050bc79d4af9d, with an additional real-native regression and updated runtime documentation.

Thanks @jjjhenriksen for the report and reproduction direction.

Work sessions

Evidence

  • Original accounting proof retained: 128 focused tests passed across six suites. Both queued-startup failure and cancellation regressions fail on original source with Terminal accounting session changed and pass with retained writer facts. Replacement-session/lifecycle/writer guards remain intact.
  • Codex verification: 202 tests pass across six lifecycle/client suites, including the imported handoff cases, configured MCP ownership, and two native-binary suites.
  • Real Codex 0.162.1 proof: start a target and sibling on the old process; complete a real target turn against a credential-free loopback provider; unload the target before installing closure tracking; retire the old client while retaining a sibling lease; resume the same target through startOrResumeThread on a second real process and complete its next turn. A loaded sibling remains fenced and completes another turn on the old process while that handoff waits; cancelling only the wait leaves the old client alive. Exactly three loopback model requests complete, with no operator credentials or OpenAI service calls.
  • Red/green: the native scenario fails against the pre-follow-up handoff implementation at its 20-second deadline; the patched native case passes in 1.1 seconds. The six-suite Codex invocation took 77.1 seconds wall time. A standalone native proof took about 15.5 seconds wall time including harness startup; CI timing for this combined head is pending.
  • Canonical extension production typecheck, targeted changed-test typecheck, type-aware lint, formatting, and git diff --check pass. Independent Auto Review of the combined patch: scoped clean at its default P0 threshold.
  • Four production files total (+44/-14 lines). No new state owner, retry loop, or compatibility layer; the additional native test covers the external shutdown/status/resume contract rather than duplicating the fake-transport cases.
Native contract inspection and verification limits

Personally inspected the pinned Codex 0.162.1 source: app-server/src/request_processors/thread_processor.rs (thread/read), thread_lifecycle.rs (shutdown and closure notification), and thread-store/src/local/live_writer.rs (resume's writer lock).

This proves the native missed-closure startup mechanism in isolation, not deployment to the affected live Gateway, the complete six-minute incident, or remote OpenAI service behavior. The prior standalone root test command's worker-compilation interruption remains non-verdict evidence; successful runs use the supported repository Vitest entrypoint. An initial package-boundary typecheck selected without its build prerequisites failed setup; the canonical extension/type-aware gates above passed. Documentation link audit reported 15,867 checked links and zero broken links, but its runner aborted after that summary, so a clean audit exit is not claimed.

Worked on by

roboclaw-bot and others added 3 commits October 24, 2026 01:24
Co-authored-by: jjjhenriksen <[email protected]>
Co-authored-by: jjjhenriksen <[email protected]>
Worked on by:
- @jjjhenriksen

Co-authored-by: jjjhenriksen <[email protected]>
OpenClaw-Publication: 14d44768-68ef-454c-9c08-e3fdf92d38de
@clawsweeper

clawsweeper Bot commented Oct 24, 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.

@roboclaw-bot
roboclaw-bot marked this pull request as ready for review October 24, 2026 02:14
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR recovers missed Codex thread closures and preserves claimed session-writer facts through queued startup failures and cancellations.

Example: Chat A unloads before closure tracking attaches, while chat B keeps the retired Codex process alive.

  • Before: Chat A remains at “Waiting for turn to start…” until the retired process exits.
  • After: A matching thread/read response with notLoaded status permits chat A to resume while chat B remains usable.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, useful repair with distinct regression coverage and no identified defect; supplied validation is strongest at the native-process and in-process ownership boundaries.
Proof confidence 🦐 gold shrimp (3/6) This collaborator-authored PR is outside the ordinary contributor proof gate; its body reports real Codex 0.162.1 continuation with sibling and cancellation controls, supported by an inspected native-process regression rather than a supplied Gateway recording or runtime trace.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Queued chats can remain waiting after reload, and startup failures or cancellation can be replaced by terminal-accounting errors.
Reason: Both repairs restore existing continuation and terminal-result contracts; the collaborator-authored direction requires no additional product decision.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses two concrete remaining failures using existing lifecycle owners, and no actionable patch defect was found.

Priority: P2
Reviewed head: b5cf2ab144909c3f419d5ebfd1be34bf516749a3

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied native-process and queued-runner regressions do not demonstrate the complete reloaded Gateway chat flow; their reported red/green results were not independently rerun.
Agent review details

How this fits together

Queued replies enter the shared agent executor, which returns terminal outcomes for accounting and delivery; the Codex plugin separately coordinates native-thread handoff between physical app-server clients.

flowchart TD
  A[Queued chat] --> B[Shared agent executor]
  B --> C[Codex thread lifecycle]
  C --> D[Old client status and closure]
  D --> E[Successor native resume]
  E --> F[Native writer lock]
  B --> G[Terminal accounting]
  G --> H[Reply delivery]
Loading

Technical review

Best possible solution:

Preserve claimed writer facts through terminal outcomes and recover missed closure information within the existing exact-client handoff owner.

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

Current-main source establishes both failure paths, and the supplied regressions report failures on the original implementation; this read-only review executed no target code.

Is this the best way to solve the issue?

The patch repairs the two existing owners directly, preserves current-writer and native persistence checks, and adds no competing state owner, retry loop, or configuration.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5a1187ca8112.

Provenance checked

  • Exact-thread handoff keeps the original intent (a09a59e: Allow an exactly closed thread to continue while unrelated sibling leases retain its old process, without abandoning native writer fencing.)
  • Physical-client ownership and cancellation keeps the original intent (f83b7ad: Consolidate session ownership and observe exact native runtime shutdown before successor continuation.)
  • Terminal accounting writer expectations keeps the original intent (38ced6e: Complete against the settled runtime writer while retaining authoritative session and operation checks.)
  • Queued execution convergence keeps the original intent (f8cc39c: Use the canonical agent execution pipeline for queued turns while keeping admission, delivery, and cleanup in the queued adapter.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: The introduced diff retains writer facts on rejected and aborted outcomes and adds one cancellable metadata-only read against the exact retired client, accepting only a matching notLoaded thread. (extensions/codex/src/app-server/thread-lifecycle-warm.ts:242, b5cf2ab14490)
  • Current main still needs both repairs: Fetched main still returns aborted outcomes without the captured writer and waits on closure receipts or physical process exit without recovering a missed receipt through thread/read. (src/auto-reply/reply/agent-runner-execution.ts:448, 5a1187ca8112)
  • Accounting retains its current-owner checks: The existing completion owner compares the retained writer against the authoritative session ID, lifecycle revision, and writer run ID while also checking the current reply operation; the PR changes the supplied expectation rather than removing these checks. (src/auto-reply/reply/agent-runner-completion.ts:60, b5cf2ab14490)
  • Distinct native and queued regressions: The native regression uses two real Codex processes and a loopback provider to cover missed closure, successful continuation, a still-loaded sibling, and cancellation; the queued regression injects startup failure while keeping queue admission, writer claims, accounting, and delivery real. (extensions/codex/src/app-server/thread-lifecycle.handoff.native.test.ts:42, b5cf2ab14490)
  • Authoritative dependency contract personally inspected: The patch directly invokes Codex thread/read and relies on its native status contract, establishing the dependency-policy signal. At the inspected revision, metadata reads combine persisted and live state; native resume acquires the exclusive writer lock before opening its recorder. (codex-rs/thread-store/src/local/live_writer.rs:46, 092d3acd6bec)
  • Credited related contribution: The body credits jjjhenriksen and incorporates fix(codex): chats wait after reloading an already-closed thread #182161, whose discussion distinguishes the missed-closure stall from terminal accounting. That follow-up commit was unavailable locally, so its body and discussion were inspected through REST rather than claiming a local commit comparison.

Likely related people:

  • Dallin Romney: Raw commit a09a59e adds extensions/codex/src/app-server/thread-lifecycle-warm.ts:205 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a09a59e317d7; files: extensions/codex/src/app-server/thread-lifecycle-warm.ts)
  • Paul Bohm: Raw commit f83b7ad adds extensions/codex/src/app-server/thread-lifecycle-warm.ts:189 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: f83b7ade15f3; files: extensions/codex/src/app-server/thread-lifecycle-warm.ts)

PR surface

Source +30, Tests +483, Docs +3. Total +516 across 12 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 4 44 14 +30
Tests 7 486 3 +483
Docs 1 7 4 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 537 21 +516

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Specific queued startup and reload conditions can stall existing Codex chats or replace their intended terminal result.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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-24T02:30:55.652Z sha 34b632c :: needs maintainer review before merge. :: none

Reviewed October 24, 2026, 12:15 AM ET / 04:15 UTC (Revision 2).

Worked on by:
- @jjjhenriksen

Co-authored-by: jjjhenriksen <[email protected]>
OpenClaw-Publication: 36083a45-82ec-4a8f-9d39-2fd02c208a58
@roboclaw-bot roboclaw-bot changed the title fix: preserve queued startup failures and cancellations fix: recover queued Codex chats and preserve startup failures Oct 24, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: codex and removed size: S labels Oct 24, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@RomneyDa
RomneyDa merged commit 1104add into main Oct 26, 2026
128 checks passed
@RomneyDa
RomneyDa deleted the openclaw/quiet-barnacle-2 branch October 26, 2026 04:17
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
…aw#182104)

* Merge selected base main

Co-authored-by: jjjhenriksen <[email protected]>

* fix: preserve queued startup failures and cancellations

Worked on by:
- @jjjhenriksen

Co-authored-by: jjjhenriksen <[email protected]>
OpenClaw-Publication: 14d44768-68ef-454c-9c08-e3fdf92d38de

* Publish openclaw/quiet-barnacle-2

Worked on by:
- @jjjhenriksen

Co-authored-by: jjjhenriksen <[email protected]>
OpenClaw-Publication: 36083a45-82ec-4a8f-9d39-2fd02c208a58

* test(codex): remove redundant mocked handoff success case

* fix(codex): keep retired-owner fence when passive thread read fails

* test(codex): initialize old native process before its successor

---------

Co-authored-by: roboclaw-bot <[email protected]>
Co-authored-by: jjjhenriksen <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 26, 2026
* Merge selected base main

Co-authored-by: jjjhenriksen <[email protected]>

* fix: preserve queued startup failures and cancellations

Worked on by:
- @jjjhenriksen

Co-authored-by: jjjhenriksen <[email protected]>
OpenClaw-Publication: 14d44768-68ef-454c-9c08-e3fdf92d38de

* Publish openclaw/quiet-barnacle-2

Worked on by:
- @jjjhenriksen

Co-authored-by: jjjhenriksen <[email protected]>
OpenClaw-Publication: 36083a45-82ec-4a8f-9d39-2fd02c208a58

* test(codex): remove redundant mocked handoff success case

* fix(codex): keep retired-owner fence when passive thread read fails

* test(codex): initialize old native process before its successor

---------

Co-authored-by: roboclaw-bot <[email protected]>
Co-authored-by: jjjhenriksen <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
(cherry picked from commit 1104add)
RomneyDa added a commit that referenced this pull request Oct 28, 2026
* Merge selected base main

Co-authored-by: jjjhenriksen <[email protected]>

* fix: preserve queued startup failures and cancellations

Worked on by:
- @jjjhenriksen

Co-authored-by: jjjhenriksen <[email protected]>
OpenClaw-Publication: 14d44768-68ef-454c-9c08-e3fdf92d38de

* Publish openclaw/quiet-barnacle-2

Worked on by:
- @jjjhenriksen

Co-authored-by: jjjhenriksen <[email protected]>
OpenClaw-Publication: 36083a45-82ec-4a8f-9d39-2fd02c208a58

* test(codex): remove redundant mocked handoff success case

* fix(codex): keep retired-owner fence when passive thread read fails

* test(codex): initialize old native process before its successor

---------

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

(cherry picked from commit 1104add)

Co-authored-by: jjjhenriksen <[email protected]>
Co-authored-by: roboclaw-bot <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 94ef20a88dce9508d06cf74a5f35c7c6e77d5777)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation extensions: codex P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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