Skip to content

Compaction stores a tool-call fragment as the summary when the model answers the summarization prompt with a tool call (no validation or retry) #55508

Open

Description

@jbellis

What happened

With a model that answers the compaction (summarization) prompt by emitting a tool call instead of prose, Codex stores the raw tool-call text as the compaction summary. The next context window then starts with a "summary" like this (DeepSeek's text-form tool-call markup, stored verbatim):

<||DSML|| calls>
<||DSML|| invoke name="exec_command">
<||DSML|| parameter name="cmd" string="true">cd /workspace/.../bifrost && git status --short && git diff --stat</||DSML|| parameter>
...

In a benchmark run of 20 long agentic sessions on deepseek-flash with model_auto_compact_token_limit = 244800 (so compaction fired many times per session), 20 of 119 inline auto-compactions produced such a summary. The sessions that received them re-derived their state from git diff, treated their own earlier edits as another model's work, and in several cases compacted again within minutes or lost a decision the previous summary had carried. GPT models in the same harness (86 compactions observed) never did this; the trigger is model-specific, but Codex does nothing to catch it.

Why

codex-rs/core/src/compact.rs (run_compact_task_inner_impl, current main):

  • The compaction request is built with Prompt { input, base_instructions, cyber_access_program, ..Default::default() } (around line 318), so no tools are offered. A model that tries to call a tool anyway gets no function-call parsing on the provider side, and its tool-call tokens arrive as plain assistant text.
  • The summary is taken verbatim from the last assistant message (around lines 392-403). The post-turn path only checks !summary.trim().is_empty(); the inline auto-compaction path uses unwrap_or_default(), so an empty summary is accepted as well. There is no check that the text is a summary and no retry.

Suggested fix

Validate the compaction response before using it as the summary: reject an empty response and a response that is (or starts with) a tool-call fragment (a function_call item, or text matching a known tool-call markup such as the DeepSeek <||DSML|| tokens). On rejection, retry the compaction turn once with a stronger instruction ("reply with the summary as plain text; do not call tools"), and if that also fails, fail the compaction with a visible error rather than continuing with a corrupted handoff. A warning event when a summary is rejected would also help operators notice this.

How to reproduce

Run a long task on deepseek-flash (OpenAI-compatible endpoint) with a low model_auto_compact_token_limit so inline compaction fires often, then inspect the compacted records in the rollout: a fraction of the message payloads contain <||DSML|| tool-call markup instead of a summary.

Observed on the Codex build bundled with our harness (2026-10-19) and confirmed unchanged on main at e18a20d (2026-10-20).

Activity

  1. added
    bug
    context
    custom-model
    on Oct 20, 2026
  2. jbellis commented on Oct 20, 2026

    @jbellis
    Author

    Two related prompt-side observations from the same 20-session run. They are separate from the validation bug above, but they make compaction damage worse, and both are one-file changes.

    1. The compaction prompt does not tell the model not to call tools. prompts/templates/compact/prompt.md asks for a handoff summary but never says to reply in plain text only. A model that tends to keep working (DeepSeek Flash here) answers with a tool call instead, which is the trigger for this issue. One explicit line ("Reply with the summary as plain text only. Do not call any tools.") is a cheap first mitigation alongside the validation and retry.

    2. The summary prefix tells the resumed model that a different model did the work. prompts/templates/compact/summary_prefix.md begins: "Another language model started to solve this problem and produced a summary of its thinking process … Here is the summary produced by the other language model". The prompt itself also says "Create a handoff summary for another LLM". We read every session's rollout after the run, and this framing explains a recurring behavior after compaction: the resumed model treated its own uncommitted edits as someone else's unverified work. Specifically, it:

    • re-audited and rewrote files it had already finished and tested;
    • in one session, reverted its own completed fixes as "unrelated edits", hit the same test failures, and re-applied identical fixes about 50 minutes later;
    • in another, searched repository history for "the other model's" work, which led it to read commits it had been told not to read.

    Within a single session, the summary describes the same agent's own earlier work in the same workspace. Framing it as a continuation would match what is actually happening, for example: "This conversation continues an earlier part of the same session that ran out of context. The summary below covers your own earlier work; the workspace reflects it."

    We have not run an A/B test of the framing alone. This is what the rollouts show, not a controlled result.

  3. shusun-lu commented on Nov 6, 2026

    @shusun-lu

    We are seeing the same class of failure with Codex CLI 0.154.0 and a
    DeepSeek model behind a LiteLLM proxy using a Responses-compatible endpoint.

    During long-running agent sessions, Codex occasionally renders DeepSeek's
    text-form tool-call markup as an ordinary assistant message. We have observed
    both partial and complete tool-call envelopes. A representative occurrence
    looked like this:

    <exec_command>
    <|DSML| parameter name="cmd" string="true">...command...</|DSML| parameter>
    <|DSML| parameter name="workdir" string="true">...</|DSML| parameter>
    <|DSML| parameter name="shell" string="true">bash</|DSML| parameter>
    </|DSML| invoke>
    </|DSML| calls>
    

    In other cases only the closing parameter, invoke, and calls fragments
    were printed. In neither case was the intended tool call executed. Sending
    continue allowed the session to proceed, so the recovery path is usually
    workable, but the raw protocol markup is exposed to the user and the intended
    operation is silently lost.

    We cannot yet isolate every occurrence to automatic compaction because the TUI
    does not label the boundary. It nevertheless appears consistent with the path
    described above: the model tries to call a tool where no tool is available or
    where the custom provider does not translate its text-form tool call into a
    Responses function_call, so Codex receives the markup as assistant text.

    We also checked codex-rs/core/src/compact.rs in the rust-v0.166.0 tag. The
    inline-compaction path still obtains the last assistant message with
    unwrap_or_default(), and the post-turn path only checks that the text is
    non-empty. We did not find DSML/tool-fragment validation or a retry that asks
    the model to return a plain-text summary. This suggests that upgrading from
    0.154.0 to 0.166.0 does not yet provide a targeted fix for this report.

    The provider adapter should ideally translate these DSML envelopes into
    structured tool calls. As a defensive Codex-side check, I would also suggest
    rejecting empty summaries or summaries beginning with a known textual
    tool-call envelope, retrying once with an explicit plain-text-only instruction,
    and surfacing a visible protocol error if the retry also fails.

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

    bugcontextcustom-model

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions