Skip to content

fix(agent): retry a repetition cut that produced nothing - #1667

Merged
huichen merged 2 commits into
mainfrom
pr/huichen
Nov 21, 2026
Merged

huichen merged 2 commits into
mainfrom
pr/huichen

Conversation

@huichen

@huichen huichen commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

A run no longer dies when a model gateway's repetition guard cuts a turn that had produced nothing. The chat adapter keeps repetition as its own finish reason, and the run loop classifies such a cut as provider_repetition and re-sends the same turn inside the run (at most twice, under the existing automatic-retry switch) instead of ending as an unconfirmed finish_unknown stream. This was the failure mode behind three dead runs in one eight-run session.

Commits

  • fix(agent): retry a repetition cut that produced nothing

Verification

Local self-test at 588dcbb with the pinned Rust 1.99.1 toolchain and ulimit -n 8192:

  • cargo fmt --all -- --check -> clean
  • cargo check -p future-agent --all-targets -> clean
  • cargo clippy -p future-agent --all-targets -- -D warnings -> clean
  • cargo test -p future-agent --lib -> 3124 passed, 0 failed, 7 ignored

User-visible changes

A run that the model server's repetition guard cut before producing any text or tool call now retries that turn inside the same run (twice at most) and the conversation continues, instead of ending as an unconfirmed stream. A cut that produced visible text or a tool call is still never retried, and repeated cuts still end the run incomplete -- now carrying [RESPONSE_UNCONFIRMED] provider_repetition instead of finish_unknown. Revert 5f0f28d.

A gateway with its own repetition guard can stop a looping model with a
non-standard `finish_reason` (`repetition`) and no content at all. The chat
adapter mapped that to `FinishReason::Unknown`, so the run loop classified the
cut as `finish_unknown` and ended the whole run as an unconfirmed stream — the
failure mode behind three dead runs in one eight-run session.

- `FinishReason::Repetition` keeps the reason distinct, wire name
  `repetition`; every existing finish-reason mapping is unchanged.
- `run_loop` classifies the cut as `provider_repetition` and re-sends the same
  turn inside the run when the cut left no text and no tool call: at most
  twice, under the existing automatic-retry switch, without consuming a turn.
- Each retry is logged with `detected_by` and its attempt number. A cut that
  produced visible text or a tool call is never retried, and still ends the run
  with the same verdict as before.
- Regression tests cover retry-then-recover, the two-retry ceiling, and both
  no-retry cases; removing the retry makes them fail.

## User-visible changes

A run no longer dies when the model server's repetition guard cuts a turn that
had produced nothing: the same turn is retried inside the run (twice at most)
and the conversation continues. When the cuts repeat, or when the turn had
already produced text or a tool call, the run still ends `incomplete` — now
carrying `[RESPONSE_UNCONFIRMED] provider_repetition` instead of
`finish_unknown`.
@huichen
huichen enabled auto-merge (squash) November 21, 2026 13:22
@huichen
huichen merged commit ae91a17 into main Nov 21, 2026
25 checks passed
@huichen
huichen deleted the pr/huichen branch November 21, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant