Files
claudecodeui/server
Haileyesus b3fe1b4392 fix(codex): align session id lifecycle with async thread.start events
Codex session initialization assumed thread.id was immediately available at thread creation time. In practice, for new sessions the SDK discovers/emits the real thread id asynchronously via stream events (thread.started), matching Claude’s behavior. This early assumption caused the backend to create and publish session state before the canonical id existed.

Why this matters:
- Session identity is the join key for live streaming, abort routing, notifications, and history sync.
- Emitting session_created with a guessed/fallback id risks mismatched client state and stale references.
- Registering active sessions too early can make abort/lookup logic depend on non-canonical ids.
- Divergence from Claude’s flow created provider inconsistency and made cross-provider behavior harder to reason about.

What changed:
- Stop treating thread.id as authoritative at startup for new Codex sessions.
- Capture the real session id from thread.started (prefer event.thread_id, fallback event.id).
- Emit session_created only after the canonical id is discovered (new sessions only).
- Track active session state immediately only for resumed sessions (known sessionId), otherwise defer registration until id discovery.
- Thread the captured id through normalization, token budget updates, completion payloads, and failure notifications.
- Preserve writer/session wiring by setting ws.setSessionId once the id is known.

Result:
Codex now follows the same async session-id contract as Claude, removing a race around initial session identity and making session lifecycle handling deterministic across providers.
2026-05-05 17:04:21 +03:00
..
2026-04-21 18:26:25 +02:00