Skip to content

fix(codex): preserve warm sessions and approvals across conversations - #120405

Merged
steipete merged 1 commit into
mainfrom
codex/codex-multi-session-lifecycle
Aug 8, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/codex-multi-session-lifecycle

Conversation

@steipete

@steipete steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Related: #115089

What Problem This Solves

Fixes an issue where people alternating between independent Codex-backed conversations repeatedly cold-restarted native sessions and lost session-scoped file-change approvals. The previous implementation retained only one subscribed native thread per shared Codex app-server, so finishing conversation B evicted conversation A even though the upstream protocol supports many concurrent subscriptions.

Why This Change Was Made

Replace the single retained-thread slot with a physical-client-owned registry that preserves independently owned native sessions while bounding retention to 64 unprotected idle threads and 30 minutes. Protect parents with unfinished native children, transfer ownership safely through compaction and transient restricted turns, and retire only the exact native thread and physical client belonging to a reset, deletion, session end, or terminal upstream notification.

Separate immutable native-thread identity from settings Codex can update through turn/start, including same-generation model selection, approval policy, sandbox, working directory, and service tier. Preserve model-generation boundaries, synchronize authoritative session/model/workspace metadata, document the lifecycle, and explain the non-obvious ownership and approval invariants beside the code.

Follow-up: transfer retained native subscriptions explicitly when a session moves into bound-conversation ownership, and release bound subscriptions on detach.

User Impact

Separate chats keep their own native conversation, warmed resources, workspace, and session-scoped native file-change approvals while sharing the intended authenticated app-server. Switching between chats no longer discards one conversation's runtime just because another finishes, while idle/LRU eviction remains bounded and resetting one conversation does not disturb its siblings. Existing native command approval and durable exec-policy behavior are unchanged; no new production configuration, environment variable, storage schema, or dependency is introduced.

The public Codex harness documentation now explains retention limits, protected native-child parents, reset behavior, and when evicted sessions may need approval again.

Evidence

  • Exact pinned upstream Codex 0.146.1 source was inspected directly: one client can subscribe to many threads in thread_state.rs, idle unloading requires zero subscribers in thread_lifecycle.rs, incompatible resumes reconstruct idle unsubscribed sessions in thread_processor.rs, and native file-change approvals remain session-scoped in apply_patch.rs.
  • Trusted Blacksmith Testbox tbx_01kzf8m1efea13w0n2vjv59dwp: 592 passing tests across 13 focused files, covering alternating pooled sessions, exact-thread reset, incognito teardown, 64-session LRU/30-minute expiration, protected native-child parents, compaction ownership, transient restricted turns, mutable model/approval/workspace/service-tier settings, conversation-only model commands, plugin hooks, and real WebSocket approval capability negotiation. Testbox-backed Actions run.
  • Real authenticated Gateway -> bundled Codex app-server 0.146.1 -> openai/gpt-5.6-sol provider proof: four actual native file changes in A -> B -> A -> B order, two distinct stable native thread IDs, one physical app-server client, and exactly two independent acceptForSession approval decisions with observed counts 1 -> 2 -> 2 -> 2; live test passed in 199.46 seconds.
  • Sanitized live proof: [codex-session-proof] A=019fdeaf-44a2-77f3-913c-2232b47320c2 B=019fdeaf-55ea-7812-aa8e-492b2c25ae40 client=656d4cf8-5b53-44b8-aeac-14be3431ab1b approvals=2 turns=4.
  • Independent widened pre-commit review: .agents/skills/autoreview/scripts/autoreview --mode uncommitted --max-priority P1 exited successfully; TruffleHog was clean and no actionable P0/P1 findings remained.
  • The same trusted Testbox passed the full production pnpm build, all-project pnpm check:changed, complete TypeScript project graph, production/full-tree dead-export checks, all three lint shards with zero findings, and runtime import-cycle detection with zero cycles.
  • Production growth is bounded and owner-justified: +380 net production lines for multi-session lifecycle ownership, bounded eviction, native-child protection, generation-safe retirement, and mutable-turn identity; tests and documentation are counted separately.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime extensions: codex size: XL maintainer Maintainer-authored PR labels Aug 8, 2026
@steipete
steipete marked this pull request as ready for review August 8, 2026 01:05
@steipete
steipete marked this pull request as draft August 8, 2026 01:22
@steipete
steipete marked this pull request as ready for review August 8, 2026 01:22
@steipete
steipete force-pushed the codex/codex-multi-session-lifecycle branch from 0cbde66 to bea3fce Compare August 8, 2026 01:28
@steipete
steipete merged commit 5a79d19 into main Aug 8, 2026
117 checks passed
@steipete
steipete deleted the codex/codex-multi-session-lifecycle branch August 8, 2026 01:38
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

docs Improvements or additions to documentation extensions: codex gateway Gateway runtime maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant