Skip to content

Support reliable cross-provider session handoff with normalized tool history #38365

Open

Description

@haochengyuan

What variant of Codex are you using?

CLI

What feature would you like to see?

Feature request

Codex should support handing off a long-running session from one model provider
to another while preserving its working context.

Example:

  • Continue a long GPT session with a custom Responses-compatible provider when
    the GPT quota is exhausted.
  • Later hand the resulting session back to OpenAI models.
  • Preserve completed conversation history, decisions, tool results, and project
    context without requiring a manual summary.

Current behavior

  1. codex resume across providers is unreliable because the session retains its
    original provider-specific state.

  2. codex fork -p <provider> -m <model> <session-id> copies the history, but the
    destination provider may reject valid historical tool records.

  3. In my case DeepSeek returned:

    No tool output found for tool call call_mj42PDsUwFvbo5vPJM4Kunyd

  4. The corresponding custom_tool_call_output was present in the rollout file,
    but a developer message occurred between the tool call and its output.
    OpenAI accepted this history; the custom provider rejected it.

  5. Provider-specific pickers also make the source session difficult to locate,
    requiring its UUID.

Desired behavior

Before a cross-provider resume or fork, Codex should normalize the transcript
into a provider-neutral representation:

  • preserve all user and assistant messages;
  • preserve completed tool calls and outputs;
  • guarantee valid call/output pairing and ordering;
  • remove or transform provider-specific protocol items;
  • retain the source session as an unchanged rollback point;
  • clearly indicate that the destination is a new session derived from the
    original session.

Ideally:

codex handoff <session-id> --profile deepseek --model deepseek-v4-pro

Environment

  • Codex CLI 0.147.0
  • macOS
  • Source provider: OpenAI
  • Destination: custom Responses-compatible provider

Additional information

No response

Activity

  1. added
    enhancement
    on Aug 13, 2026
  2. added
    CLI
    custom-model
    session
    tool-calls
    on Aug 13, 2026
  3. CCanxue commented on Aug 14, 2026

    @CCanxue

    Related evidence: cross-provider history replay is already fragile in this family. DeepSeek stores plaintext reasoning_text/agent-message shapes that strict OpenAI endpoints reject on switch (see hermes-agent#32617, #17541), and the reverse direction fails too. A normalized, provider-neutral transcript before resume/fork matches the direction several of these issues ask for; our patch only covers task delivery, not history normalization. Family overview: https://github.com/CCanxue/codex-deepseek-subagent-fix

  4. jdcodes1 commented on Aug 18, 2026

    @jdcodes1

    Half of the normalization layer you're proposing already exists — which sharpens what's actually missing. core/src/context_manager/normalize.rs guarantees presence invariants when history is rebuilt: ensure_call_outputs_present synthesizes an output for any dangling call, remove_orphan_outputs drops outputs with no call, and there are strip passes for unsupported media (https://github.com/openai/codex/blob/1f41cc5d92/codex-rs/core/src/context_manager/normalize.rs#L21, #L148).

    What it never enforces is adjacency: your DeepSeek failure is a call/output pair separated by an interleaved developer message — valid for the OpenAI Responses API, rejected by stricter chat-completions-style validators. That's a pure reordering transform the existing pass could add. The second gap is provider-opaque items: encrypted reasoning payloads and inter-agent messages carry encrypted_content only the originating provider can use (#38656 documents a fork of this problem), and compaction markers are protocol-specific — those need dropping or flattening to text on a provider switch.

    So the feature could land incrementally: extend the existing normalize pass with adjacency + opaque-item handling, and run it on fork -p/cross-provider resume. No new transcript format needed.

  5. vshulcz commented on Aug 23, 2026

    @vshulcz

    A different framing that sidesteps the rejection problem rather than normalising around it, from having built handoff across twenty agents.

    Do not move the tool history at all. What the destination needs in order to continue is not the provider-specific record of how the work happened — it is the work: the problem being solved, the conclusions reached so far, and where it stopped. That is plain text, and no endpoint rejects plain text. The transcript on disk already holds it, so the package can be rebuilt from the source session instead of converted from the previous provider's wire format.

    The trade is explicit and worth stating: you lose replay of tool calls as tool calls, so the new session starts as a fresh conversation that happens to know what the old one concluded. What you gain is that the move works between providers sharing no schema at all — and between different agents, not only different providers behind one agent.

    The failure in the report is the general case of the alternative: a normalisation layer has to keep up with every provider's record shape, forever, and reasoning_text is only the instance that surfaced this week. Text has no such obligation.

    Ours is deja handoff --to <agent> in https://github.com/vshulcz/deja-vu, Codex included. If it is useful I can write up which parts of a session actually turned out to matter on the other side and which we stopped carrying.

  6. JunkaiWang-TheoPhy commented on Sep 17, 2026

    @JunkaiWang-TheoPhy

    Related data point, since this issue already frames the normalize layer precisely: the presence invariants you describe are enforced only when history is rebuilt. ensure_call_outputs_present has a single call site (context_manager/history.rs:798), client.rs:849 does no send-time validation, and a turn's first sampling request uses the caller-provided input (session/turn.rs:1585) instead of the normalized snapshot. I filed the location plus a runnable strict-upstream checker in #46193.

    For the cross-provider handoff angle specifically: I measured what a strict third-party upstream actually rejects, and the messages are misleading — a batch split by its own outputs (callA → outA → callB → outB) is rejected with The 'reasoning_text' in the thinking mode must be passed back to the API, while callA → callB → outA → outB returns 200 for identical content. Worth knowing before deciding what a normalized history must preserve.

  7. bluesky129 commented on Sep 18, 2026

    @bluesky129

    Adding a concrete UX/architecture requirement from a multi-provider workflow:

    A running Codex process can reasonably use one provider at a time, but the persisted session should not be permanently bound to that provider. After changing the active provider/profile, restarting Codex, and resuming the same session, the user should be able to continue the original conversation without manually copying/forking it.

    Suggested semantics:

    • Session identity/history is provider-independent.
    • Provider/model/auth are runtime execution settings, not part of the session's permanent identity.
    • On resume, explicit CLI/UI overrides > selected profile/provider > session/default fallback.
    • Before sending historical context to a new provider, normalize provider-specific tool/protocol records into a canonical internal transcript.
    • If some historical item cannot be translated safely, show a precise compatibility warning and preserve the original session unchanged.
    • No manual copy/summary should be required just to switch quota source, gateway, Azure/Bedrock/custom proxy, or OpenAI login.

    This separation of Session State from Execution Backend would make provider switching much less disruptive and align the UX with how users already expect long-running coding sessions to behave.

  8. NashCC1550 commented on Sep 18, 2026

    @NashCC1550

    Another trigger for the same adjacency gap, confirmed at the wire level: <image_resize_notice>.

    Setup: Codex Desktop 0.155.0-alpha.9 (macOS), DeepSeek V4.1 Flash (deepseek-flash) through a local Responses gateway, native Responses wire. The gateway passes the history through unchanged.

    What happens: the model issues two parallel view_image calls. The first image is larger than the limit, so Codex resizes it and records a developer message with <image_resize_notice> right after the first output, before the second one. The persisted history ends with:

    function_call          view_image   call_00_…
    function_call          view_image   call_01_…
    function_call_output                call_00_…   (input_image)
    message (developer)    <image_resize_notice> Image 1 of 1 in the preceding tool output was resized …
    function_call_output                call_01_…   (input_image)
    

    DeepSeek rejects the next request:

    400 {"error":{"message":"No tool output found for tool call call_01_….","type":"invalid_request_error"}}
    

    The thread stays wedged after this, because every later turn replays the same history.

    A/B, replaying that exact history directly to https://api.deepseek.com/v1/responses (no gateway in the path):

    Input Result
    History as persisted 400 (same message)
    Same, id / status / namespace stripped 400
    Resize notice moved after the second output 200
    Resize notice removed 200
    Synthetic two parallel image outputs, no notice in between 200

    So both outputs are present, and this is not the #44604 race. The only problem is the developer message inside the call/output group. It hits whenever a parallel batch includes an image that gets resized, and it does not need a cross-provider fork.

    Workaround applied on the gateway side: before sending to DeepSeek, move any non-assistant message that sits inside a call batch to right after the batch's last output. A batch whose outputs never all arrive is left unchanged, and the transform is idempotent. With it, the same history replays with 200. A send-boundary normalization in Codex, as discussed in #46193, would cover this case too.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIcustom-modelenhancementsessiontool-calls

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions