Skip to content

fix(codex): recover conversations after unused native threads disappear - #167873

Closed
davelutztx wants to merge 1 commit into
openclaw:mainfrom
davelutztx:voice-codex-preflight-20261009
Closed

davelutztx wants to merge 1 commit into
openclaw:mainfrom
davelutztx:voice-codex-preflight-20261009

Conversation

@davelutztx

@davelutztx davelutztx commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Related: #158752

What Problem This Solves

Fixes Codex-backed conversations failing with thread not loaded when native cleanup removes an unused thread but its OpenClaw binding and managed client remain.

User Impact

The next authorized request can reach the existing stale-thread recovery and start a replacement thread. Loaded threads with an unowned inference route, ambiguous failures, and revoked or aborted requests still fail closed. No configuration changes or migration are required.

Why This Change Was Made

Inference preparation currently probes the recorded thread before the lifecycle owner's recovery boundary. An exact missing-thread response aborts that preparation even though the later lifecycle already knows how to recover it.

Reuse the existing typed thread/read missing-thread classifier, retaining caller admission and post-await revocation checks. Preparation does not mutate the binding or claim the absent thread; the lifecycle owner remains responsible for replacement.

This complements #158752's conversation-binding restart recovery: the separate gap here is the managed inference preflight, not its conversation attachment or RPC classifier changes.

Evidence

  • Personally checked native Codex 0.160.0 source at a956835d020762cb2b570053af06f643a11c0ecc, codex-rs/app-server/src/request_processors/thread_processor.rs (read_thread_view): metadata-only reads return the exact invalid-request error when neither persisted nor live thread exists.
  • Before the production fix, the real startOrResumeThread regression fails with thread not loaded: old-thread; the direct inference case also fails, while wrong-thread and wrong-code failures stay rejected.
  • The lifecycle regression uses the real app-server client wire, owned inference routing, and persisted binding store; it asserts one replacement start and the new persisted binding. The shared synthetic server now emits the native missing-thread error for absent threads.
  • An existing native-skill isolation test initially failed because it isolated HOME but inherited CODEX_HOME; that fixture now isolates both.
  • Focused one-worker run passed 133/133 tests across inference routing, native configuration, and lifecycle binding suites (45.37 seconds wrapper wall time). Inference routing: 43 tests, 11.31 seconds shard wall time; the new lifecycle recovery case took 54 ms. The two lifecycle files together ran 90 tests in 30.84 seconds, including existing database/runtime fixture startup; no new process boots or sleeps were added.
  • The four changed TypeScript files pass scoped tsgo and targeted Oxlint. Oxfmt, assertion-safety and line-cap ratchets, and git diff --check pass. Full-repository checks/build were not run for this narrow change.
  • Upstream CI run 37963384773 has a successful openclaw/ci-gate. The checks-node-changed job took 422 seconds (17:05:10–17:12:12 UTC); this is lane wall time, not isolated per-file test cost.
  • Fresh independent source review found no actionable issue. The canonical autoreview helper was also attempted, but its isolated Codex reviewer could not authenticate (HTTP 401); it produced reviewer_unavailable, not a clean review verdict.
  • No live Gateway changes or Android build changes in this PR. Native dependency source was inspected; an authenticated native-process end-to-end reproduction was not run for this submission.

@clawsweeper

clawsweeper Bot commented Oct 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 complete

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

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

The Codex plugin lets a confirmed missing native conversation thread reach existing recovery instead of stopping during model-request preparation.

Example: A user continues a conversation after its unused native thread disappears.

  • Before: Preparation fails with thread not loaded: old-thread before recovery runs.
  • After: The lifecycle creates new-thread and saves its binding for the conversation.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused implementation and supporting regressions are useful, but synthetic-server evidence leaves runtime confidence thin.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A Codex conversation fails to continue after native cleanup removes its unused thread.
Reason: This restores the established recovery path with a small change and no new configuration or public API.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: current main retains the recovery gap, and the companion restart PR does not supersede this useful repair. No actionable introduced defect was found.

Priority: P2
Reviewed head: 21705b87812177f70faa78566351c2772b0fa072

Before merge

  • Add real behavior proof - The changed inference owner is exercised through a real client against synthetic app-server responses, but no native-process result shows recovery and a completed request after cleanup. Add redacted terminal output, logs, or a recording of that scenario, removing credentials, private addresses, and non-public endpoints. No stored-data format or migration changes are introduced. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Findings

None.

Tests

  • Missing end-to-end proof: Show the next authorized request recovering after a real managed Codex process loses an unused thread, saving one replacement binding and completing the conversation request.
Agent review details

How this fits together

The Codex plugin prepares model routing and native conversation threads before sending requests to the Codex app-server. Its lifecycle owner restores threads or creates replacements and saves their conversation bindings.

flowchart LR
A[Authorized conversation request] --> B[Prepare model routing]
B --> C[Read recorded native thread]
C --> D{Exact missing-thread error?}
D -->|Yes| E[Existing lifecycle recovery]
D -->|No| F[Validate ownership or reject]
E --> G[Create and save replacement]
G --> H[Continue conversation]
Loading

Technical review

Best possible solution:

Keep thread replacement in the existing lifecycle owner while preserving exact missing-thread classification and current caller admission.

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

Yes at source level: a retained managed-client binding whose native thread and routing entry disappeared receives the verified thread/read error before lifecycle recovery. The reported failing base regression was not executed in this read-only review.

Is this the best way to solve the issue?

Yes: accepting only the existing typed missing-thread classification at the premature probe is a narrow repair that preserves loaded-thread ownership checks and the existing replacement owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • extensions/codex/src/app-server/inference-routing.ts: missing-route preflight keeps the original intent (fix(codex): restore workspace instructions for catalog-backed models #142276: Preserve native context while requiring live host ownership before forwarding parent-local inference.)
  • extensions/codex/src/app-server/inference-routing.ts: request admission and cancellation keeps the original intent (fix(codex): prevent stale native sessions from mutating successors #164197: Fence native writes and binding changes to the initiating session lineage and physical client.)
  • extensions/codex/src/app-server/thread-lifecycle.test-fixtures.ts: absent-thread response keeps the original intent (759e127: Support native configuration lifecycle regressions that preserve conversations while refreshing inherited policy.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current-main recovery gap: Fetched main still awaits thread/read without handling its exact missing-thread error, preventing the later lifecycle recovery from running. (extensions/codex/src/app-server/inference-routing.ts:460, b80da189bd42)
  • Exact classification and retained safeguards: The introduced catch reuses the expected-thread, method, and error-code classifier; post-await cancellation and caller checks remain, and loaded threads without owned routing remain rejected. (extensions/codex/src/app-server/inference-routing.ts:472, 21705b878121)
  • Native dependency contract inspected: The plugin pins @openai/codex 0.160.0 and issues its thread/read RPC, establishing the dependency signal. Personally inspected the sibling read_thread_view implementation: metadata-only reads return the exact missing-thread error when neither persisted nor live state exists; GitHub verified the dependency commit belongs to openai/codex. (codex-rs/app-server/src/request_processors/thread_processor.rs:2909, a956835d0207)
  • Existing recovery owner: Resume preparation already recognizes the exact missing-thread response and stages replacement; fresh-thread requests and persisted binding mutations retain current authority checks. The patch adds no competing replacement owner or stored encoding. (extensions/codex/src/app-server/thread-lifecycle-io.ts:345, 21705b878121)
  • Supporting regression evidence: The lifecycle case uses the real client with synthetic server responses and checks one replacement start plus its persisted binding. The inference matrix covers missing, wrong-thread, wrong-code, revoked, and aborted responses. The author reports base failure and 133 passing focused tests; this read-only review did not execute them. (extensions/codex/src/app-server/thread-lifecycle.native-config.test.ts:127, 21705b878121)
  • Proof and review continuity: The complete current body explicitly says no authenticated native-process reproduction was run. Current discussion adds no such result; the previous review at the identical head had no findings and requested native-process recovery proof. (21705b878121)

Likely related people:

  • Peter Steinberger: Raw commit 283d5e6 adds extensions/codex/src/app-server/inference-routing.ts:475 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 283d5e6fe371; files: extensions/codex/src/app-server/inference-routing.ts)

PR surface

Source +14, Tests +87. Total +101 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 24 10 +14
Tests 3 91 4 +87
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 115 14 +101

Review metrics

Metric Value Why it matters
Production versus regression code Production +24/-10; tests and test support +91/-4 The small production increase is justified by reusing the classifier while keeping replacement in its existing owner.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A bounded missing-thread condition prevents an existing Codex conversation from recovering on its next request.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-09T17:06:57.685Z sha 21705b8 :: needs real behavior proof before merge. :: none

Reviewed October 9, 2026, 1:22 PM ET / 17:22 UTC (Revision 2).

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Thanks @davelutztx for identifying this recovery gap. The credited replacement is merged in #189900 (e515a09), with regressions for unused missing threads and preserving recorded history. Closing this in favor of that fix.

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

Labels

extensions: codex P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants