Skip to content

Codex can still overflow between a parallel tool batch and its continuation request #192

Description

@justrach

Symptom

A Codex turn requested six read_file calls in parallel and the immediate continuation failed with:

codex api error: Your input exceeds the context window of this model. Please adjust your input and try again.

The model was gpt-5.6-sol via the Codex provider.

Why the previous fixes do not fully cover it

Agent.runTurn() currently does request -> stepResponses/runTools -> request with no context check between the tool results being appended and the continuation request. Normal auto-compaction is in mainloop.zig after a completed turn, which is too late for this path.

OpenAI Codex comparison

The upstream openai/codex turn loop checks active context after sampling/tool execution and, when another sampling iteration is needed, runs MidTurn compaction before the continuation request (codex-rs/core/src/session/turn.rs). It also combines server usage with local estimates for newly appended items.

Proposed fix

  1. Port/retain codex: context meter reads the WS-chained total, so full-history resends blow past the window at "35% ctx" and the session wedges (no auto-compact) #174's full-history estimate and context-rejection recovery on the affected release branch.
  2. Add a pre-request context gate inside Agent.runTurn(), including between tool-loop iterations.
  3. Refresh the Responses estimate after normalizing newly appended tool outputs, so a parallel batch can trigger compaction before it is sent.
  4. Add a regression test with several parallel-sized function_call_output items crossing compactAt().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions