Skip to content

Fix Codex bound thread recovery after restarts - #76936

Merged
steipete merged 1 commit into
openclaw:mainfrom
keshavbotagent:fix/codex-bound-thread-recovery
May 5, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
keshavbotagent:fix/codex-bound-thread-recovery

Conversation

@keshavbotagent

Copy link
Copy Markdown
Contributor

Summary

  • Recover stale /codex bind app-server thread references after gateway/app-server restarts.
  • If a bound turn fails with thread not found, recreate the app-server thread from the saved binding metadata and retry the turn once.
  • Add regression coverage for the missing-thread recovery path.

Notes

This is split out from #76714 so that PR stays focused on Codex OAuth/auth routing.

Tests

  • node scripts/check-changelog-attributions.mjs CHANGELOG.md
  • OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs run --config test/vitest/vitest.extensions.config.ts extensions/codex/src/conversation-binding.test.ts --maxWorkers=1
  • pnpm build

@clawsweeper

clawsweeper Bot commented May 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The PR updates the Codex plugin to recreate a missing bound app-server thread from persisted sidecar metadata, retry the inbound turn once, add a regression test, and document the fix in the changelog.

Reproducibility: yes. by source inspection, not live execution. Current main sends the stale sidecar threadId directly to turn/start and reports the thrown error, while the PR regression drives that missing-thread path into thread recreation and a single retry.

Next step before merge
No ClawSweeper repair lane is needed because this is an open implementation PR with no concrete blocking finding from this review.

Security
Cleared: Cleared: the diff stays inside Codex binding/test/changelog surfaces, preserves the selected auth profile during recovery, and does not alter dependencies, CI, publishing, or secret storage.

Review details

Best possible solution:

Land this focused Codex plugin fix after maintainer review and CI, keeping recovery local to conversation binding and preserving persisted sidecar metadata.

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

Yes by source inspection, not live execution. Current main sends the stale sidecar threadId directly to turn/start and reports the thrown error, while the PR regression drives that missing-thread path into thread recreation and a single retry.

Is this the best way to solve the issue?

Yes. Recreating the missing app-server thread once inside the Codex binding path, while preserving auth/profile and turn overrides, is the narrowest maintainable fix for this failure mode.

What I checked:

  • Current main has no stale-thread recovery: handleCodexConversationInboundClaim on current main enqueues runBoundTurn directly, so a stale app-server thread error falls into the generic failed-reply catch path. (extensions/codex/src/conversation-binding.ts:139, 978bc53e80cc)
  • Current main uses the persisted bound thread directly: runBoundTurn reads the sidecar binding and sends the saved threadId to turn/start with persisted auth/profile and turn override fields, with no recreate step on missing thread. (extensions/codex/src/conversation-binding.ts:296, 978bc53e80cc)
  • Binding sidecar stores recovery metadata: The sidecar schema persists authProfileId, model, modelProvider, approvalPolicy, sandbox, and serviceTier, which are the fields the recovery path must carry into a replacement thread. (extensions/codex/src/app-server/session-binding.ts:25, 978bc53e80cc)
  • Dependency error string checked: The managed @openai/codex 0.128.0 Linux binary contains the literal thread not found:, matching the PR's detector for stale app-server thread errors.
  • PR head retries after missing-thread errors: At the PR head, bound inbound turns call runBoundTurnWithMissingThreadRecovery, which catches only thread not found: errors, starts a replacement Codex conversation thread, and then retries runBoundTurn once. (extensions/codex/src/conversation-binding.ts:152, cf0c1ed55f21)
  • PR head preserves sidecar metadata during recreation: The replacement thread is started with the saved cwd, model/provider, auth profile, approval policy, sandbox, and service tier, and the persisted replacement binding records those same override values. (extensions/codex/src/conversation-binding.ts:437, cf0c1ed55f21)

Likely related people:

  • steipete: GitHub file history shows steipete introduced the Codex app-server protocol bridge and session binding path, then continued maintaining Codex internals and merged the related OAuth/profile routing work. (role: introduced behavior and maintainer; confidence: high; commits: 69566e43cb8b, 1c76065ccd29, 4ed6a7c6b836; files: extensions/codex/src/conversation-binding.ts, extensions/codex/src/app-server/session-binding.ts, extensions/codex/src/conversation-control.ts)
  • keshavbotagent: The same contributor authored merged Codex binding auth/profile commits in the same files before this PR, so they are tied to current-main ownership beyond simply opening this branch. (role: recent adjacent contributor; confidence: medium; commits: 05d11a431893, 71f55214ecaf, 8ea04f994a45; files: extensions/codex/src/conversation-binding.ts, extensions/codex/src/app-server/session-binding.ts)
  • vincentkoc: Recent Codex hardening commits touched the same bound-turn and control-surface area, including authorized inbound claims and stale notification handling. (role: recent adjacent maintainer; confidence: medium; commits: 346a72ddb913, ac3cd1a0ca8c; files: extensions/codex/src/conversation-binding.ts, extensions/codex/src/conversation-control.ts)

Remaining risk / open question:

  • This read-only review did not rerun the PR's validation commands; the normal PR CI/build gates should still pass before merge.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 978bc53e80cc.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 84655d1a30

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@keshavbotagent
keshavbotagent force-pushed the fix/codex-bound-thread-recovery branch from 562d040 to de93585 Compare May 3, 2026 21:17
@keshavbotagent
keshavbotagent force-pushed the fix/codex-bound-thread-recovery branch from de93585 to ef5f35b Compare May 3, 2026 21:18
@keshavbotagent
keshavbotagent force-pushed the fix/codex-bound-thread-recovery branch from ef5f35b to 01b1c6e Compare May 4, 2026 02:47
@keshavbotagent

Copy link
Copy Markdown
Contributor Author

Addressed the remaining review/security finding from the latest sweep in 01b1c6e3ed.

Changes on PR #76936:

  • preserved authProfileId during missing-thread recovery so recovered bound turns keep the selected Codex credential/profile
  • continued preserving approvalPolicy, sandbox, and serviceTier
  • extended extensions/codex/src/conversation-binding.test.ts to cover custom auth profile work, native openai-codex provider resolution, public modelProvider omission, and rewritten sidecar preservation
  • rebased onto current main

Verified:

  • git diff --check
  • node scripts/check-changelog-attributions.mjs CHANGELOG.md
  • OPENCLAW_VITEST_MAX_WORKERS=1 pnpm test extensions/codex/src/conversation-binding.test.ts --maxWorkers=1
  • pnpm build

@steipete
steipete force-pushed the fix/codex-bound-thread-recovery branch from 01b1c6e to cf0c1ed Compare May 5, 2026 02:28
@steipete
steipete merged commit a373468 into openclaw:main May 5, 2026
86 checks passed
@steipete

steipete commented May 5, 2026

Copy link
Copy Markdown
Contributor

Landed via rebase onto main.

  • Gate: changelog attribution check; git diff --check origin/main...HEAD before landing; targeted oxfmt check; OPENCLAW_VITEST_MAX_WORKERS=1 pnpm test extensions/codex/src/conversation-binding.test.ts --maxWorkers=1; pnpm build; GitHub CI exact head green.
  • Source commit: cf0c1ed
  • Landed commit: a373468

Thanks @keshavbotagent!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants