Repository navigation
fix(agent): warn a new failure streak after a success - #2725
AarnavNoble wants to merge 2 commits into
Conversation
The failure-streak warning was deduplicated by its reason text, which
carries only the streak's length. When a step's first streak was warned
at three failures, a second streak after a success read the same
("the last 3 actions failed in a row") and its warning was skipped; it
came only at the fourth failure, or never if the model concluded first.
checkFailureStreak now keys the warning by where the streak began, the
way e2e-inc#1993 keys a wait, and the loop dedups on key and reason together.
A streak that keeps growing is still warned at three and at four before
the stop at five, as before; only a new streak is told apart from the
last one.
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix · Severity of issue fixed: Medium Merge Risk:
|
|
/ready |
|
Fix these and comment |
okwasniewski
left a comment
There was a problem hiding this comment.
Automated review (AI triage pass), not yet read by a maintainer.
Reviewed 3c84adff8. Root-cause fix: the streak warning was deduplicated on its reason alone, which reads the same for every streak of a given length; keying it by where the streak began matches how waits are keyed since #1993. No must-fix.
Verified:
- Bug on main: tool-loop.ts:873 skips a warn whose reason equals
noticedGuardReason, and loop-guards.ts:353 builds the reason from the length only. - Warning each streak is the intended design: the streak check was written to start over after a success (
starts over after a successtest in #231), anddocs/agent-steps.mdx:69says it warns after 3 consecutive failed actions. The once-per-reason dedup was there to stop re-warning one streak on a turn that adds no result, which still holds (same key and reason). - Mutation check: reverting
tool-loop.tsfails the new loop test (expected [ 4 ] to deeply equal [ 4, 8 ]); reverting both source files also fails the newloop-guardstest. Changeset (@e2e-dev/corepatch) is accurate; no docs change needed.
Should fix
- tool-loop.ts:873 - the PR keeps the reason in the dedup so a growing streak still gets "the last 4" warning, but no test covers that. Deduping on
String(streak.key)alone (dropping the 4 warning) passes all 5594 unit tests. Add the "boom every turn" row from the PR body as a test: notices at turns 4 and 5, stop at 6.
Nits
- tool-loop.ts:873-877 -
noticedGuardReasonnow holds akey: reasoncomposite for the streak and a bare reason for the other guards, andString(streak.key)would printundefinedif a warn ever came back without a key. A dedicated field for the last warned streak (or a key that carries the length, added tonoticedWaitslike the wait path at L845-850) would keep one field, one meaning. - loop-guards.test.ts:255-263 - the
as { key?: string }casts could betoMatchObject({ key: 'failures@0' })etc., which also pins the actual key values.
CI on this fork PR has only 2 checks reported so far (both pass); the main workflows have not run yet.
Deduping the streak warning on its key alone would drop the "last 4" notice and still pass every test. The new loop test fails every turn and expects notices before turns 4 and 5 and the stop before turn 6. The loop-guards test now pins the key values instead of casting.
|
4ed4cd5 adds the "boom every turn" case as a loop test: notices name streaks of 3 and 4 before turns 4 and 5, and the stop names 5 before turn 6. Deduping on I kept The |
What
The agent loop warns "the last 3 actions failed in a row" for every streak of failures in a step, including one that starts after a success.
Why
The loop skipped a failure-streak warning whose reason matched the last one sent, and the reason carries only the streak's length. After a first streak was warned, a new streak of three got no notice until a fourth failure, or none if the model concluded first.
How it works
checkFailureStreakreturns akeyon its warning,failures@<index of the streak's first result>(packages/core/src/agent/loop-guards.ts:358). That is howcheckLoopGuardskeys a wait since fix(agent): prevent duplicate form submissions #1993.packages/core/src/agent/tool-loop.ts:873). A new streak has a new key, so it is warned. A streak that keeps going still gets "the last 4" before the stop at five, as on main. Keying by start alone would drop that warning at four, so the reason stays in the check.tool-loop.ts:845), and their reason names the tool but not its input: threepoke {target: 'a'}calls, apeek, then threepoke {target: 'b'}calls warn only the first run. Fixing that changescheckLoopGuards, so I left it for a follow-up.Issue
Fixes #2724
Verified
Ran it locally: yes
agent-grammar-tools.test.ts"warns a streak again as it grows, then stops it":boomfails every turn, and the notices name streaks of 3, 4 and 5 before turns 4, 5 and 6. Deduping on the key alone drops the turn-5 notice and fails it.A scratch test on the fake-model harness, against a main build of
@e2e-dev/coreand this branch: a project toolboomthat throws, with a different input each turn so only the streak guard applies, run withcreateToolLoopExecutor. Notices the loop added before each turn:boom1-3,peek4,boom5-7, conclude 8boomevery turnthe failure-streak warninginpackages/e2e/tests/unit/agent-grammar-tools.test.ts:544, fails on main (expected [ 4 ] to deeply equal [ 4, 8 ]) and passes here.pnpm bench:abtable: I have no model key, and the web benchmark's committed recordings replay without entering the tool loop.Checklist
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. (docs/agent-steps.mdxalready says the loop warns after 3 consecutive failed actions; no change.).d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures.e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.Summary by CodeRabbit