Skip to content

Codex app-server runtime loses thread context across turns (gateway starts a fresh thread each message) #41904

Description

@gmkseta

What happened?

Under the codex_app_server runtime (openai_runtime: codex_app_server), multi-turn conversations on the gateway lose the Codex thread's working context between messages.

The runtime is documented to keep "one Codex thread per Hermes session" (agent/transports/codex_app_server_session.py), but the gateway builds a fresh AIAgent per inbound message, so agent._codex_session is None at the start of every turn and ensure_started() issues a brand-new thread/start. Because a Codex thread's working context (files read, command output, plan state, long-running task state) lives inside the threadturn/start only sends the latest user message — every follow-up message hands the model an empty thread and silently loses all prior work.

Steps to reproduce

  1. Enable openai_runtime: codex_app_server.
  2. On a gateway platform (Discord/Telegram), message 1: "read file X".
  3. Message 2: "what did you just read?"

Observed: the model has no memory of message 1 (a fresh thread/start ran). Agent logs show distinct codex thread ids per message within one session.

Expected

The session resumes the same Codex thread across turns (codex app-server exposes thread/resume {threadId}, which reloads the persisted rollout from disk), preserving context until the conversation is explicitly reset (/new).

Environment

  • Codex CLI 0.133.0
  • Runtime: codex_app_server, gateway (Discord)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpointcomp/gatewayGateway runner, session dispatch, deliverysweeper:implemented-on-mainSweeper: behavior already present on current maintype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions