Skip to content

Stop a streamed reply that turns into a repetition loop (Codex CLI sends no output cap) #55279

Open

Description

@simin-yuan

What variant of Codex are you using?

CLI (codex exec), 0.163.0

What feature would you like to see?

A client-side check that ends a streamed reply once it has clearly turned into a repetition loop, instead of reading it to the model's output limit.

What happens today. The main turn request carries no output cap (ResponsesApiRequest in codex-rs has no max_output_tokens field), and I couldn't find a mid-stream repetition check. I pointed codex exec at a local Responses endpoint that streams one sentence on repeat, about 300,000 characters. Codex read all of it and printed all 300,049 characters to stdout:

export LOOP_KEY=dummy
codex exec --skip-git-repo-check \
  -c 'model_providers.loop={name="loop",base_url="http://127.0.0.1:8765/v1",wire_api="responses",env_key="LOOP_KEY"}' \
  -c model_provider=loop -m loop-model "hello" < /dev/null > out.txt
wc -c out.txt   # 300049

The endpoint and runner are here: https://github.com/simin-yuan/agent-runaway-bench

Why it matters for codex exec. Nobody is watching to press Ctrl-C. In CI or a scheduled job the loop goes into the log or the next step, and the turn runs until the model's own limit. Repeating and degenerate output has been reported here recently (#40957, where the app streamed repetitive garbage tokens into the output, and #40369), so this isn't only a synthetic case.

A possible approach. Hermes Agent does this on its chat-completions and Anthropic streams (RunawayStreamWatch, NousResearch/hermes-agent#130551): it watches the streamed text, and once a long stretch is dominated by verbatim copies of a few lines, it closes the stream and ends the turn with a clear message. It only fires on long repetition (tens of thousands of characters), so a reply where the user asked for repetition, or a table with similar rows, still comes through. Two details that came up when I wired the same check into two more of Hermes's streams (NousResearch/hermes-agent#141479): skip any drain of the remaining stream after the cut, and drop a tool call that was cut halfway, so the next request doesn't carry a call without a result.

Additional information

  • This measures the client only. I didn't test whether the hosted Responses API stops a looping generation on its side; if it does, the cost side of this is smaller, though codex exec would still print the loop up to that point.
  • Measured at openai/codex main 89461ea and the 0.163.0 npm release, Ubuntu 24.04.
  • Same test against other frameworks, for comparison: Hermes stops at about 16,000 characters; OpenAI Agents SDK 0.24.0, smolagents 1.26.0 and LangGraph 1.2.16 read the whole stream.

Activity

  1. added
    enhancementNew feature or request
    CLIIssues related to the Codex CLI
    execIssues related to the `codex exec` subcommand
    model-behaviorIssues related to behaviors exhibited by the model
    on Oct 19, 2026
  2. github-actions commented on Oct 19, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  3. simin-yuan commented on Oct 19, 2026

    @simin-yuan
    Author

    Thanks for the check. I don't think this is a duplicate of #54285. That issue is about codex exec --output-schema with minLength/maxLength constraints failing on some models. This one asks for a client-side cut when any streamed reply turns into a repetition loop, whatever the schema or model. They meet at one point: the gpt-6-sol run in #54285 produced 216,579 characters of repetitive JSON and was still streaming when that harness's ~600-second diagnostic limit stopped it. That run is the kind of output this request is about, so I'll keep this open as a separate request.

  4. simin-yuan commented on Oct 24, 2026

    @simin-yuan
    Author

    Not a duplicate of #54285, as far as I can tell. That one is about minLength/maxLength not being honoured under --output-schema. This one is a streamed reply that turns into a repetition loop and keeps going, because codex exec sends no output cap. It happens without --output-schema.

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

    CLIIssues related to the Codex CLIenhancementNew feature or requestexecIssues related to the `codex exec` subcommandmodel-behaviorIssues related to behaviors exhibited by the model

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions