Skip to content

fix(agent): warn a new failure streak after a success - #2725

Open
AarnavNoble wants to merge 2 commits into
e2e-inc:mainfrom
AarnavNoble:bugfix/tool-loop-warn-each-failure-streak
Open

AarnavNoble wants to merge 2 commits into
e2e-inc:mainfrom
AarnavNoble:bugfix/tool-loop-warn-each-failure-streak

Conversation

@AarnavNoble

@AarnavNoble AarnavNoble commented Dec 6, 2026 •

Copy link
Copy Markdown

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

  1. checkFailureStreak returns a key on its warning, failures@<index of the streak's first result> (packages/core/src/agent/loop-guards.ts:358). That is how checkLoopGuards keys a wait since fix(agent): prevent duplicate form submissions #1993.
  2. The loop dedups the streak warning on key and reason together (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.
  3. Not changed: the keyless repeat and cycle warnings are deduplicated the same way (tool-loop.ts:845), and their reason names the tool but not its input: three poke {target: 'a'} calls, a peek, then three poke {target: 'b'} calls warn only the first run. Fixing that changes checkLoopGuards, 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": boom fails 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/core and this branch: a project tool boom that throws, with a different input each turn so only the streak guard applies, run with createToolLoopExecutor. Notices the loop added before each turn:

script main this PR
boom 1-3, peek 4, boom 5-7, conclude 8 turn 4: last 3 turn 4: last 3, turn 8: last 3
boom every turn turn 4: last 3, turn 5: last 4, turn 6: stop at 5 turn 4: last 3, turn 5: last 4, turn 6: stop at 5
  • The new test, the failure-streak warning in packages/e2e/tests/unit/agent-grammar-tools.test.ts:544, fails on main (expected [ 4 ] to deeply equal [ 4, 8 ]) and passes here.
  • No pnpm bench:ab table: I have no model key, and the web benchmark's committed recordings replay without entering the tool loop.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it. (docs/agent-steps.mdx already says the loop warns after 3 consecutive failed actions; no change.)
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

View guided diff

Summary by CodeRabbit

  • Bug Fixes
    • Failure-streak warnings now appear when a run of failed actions reaches three, and again as that streak grows—even when the warning reason stays the same.
    • A successful action resets the streak, allowing a later run of three consecutive failures to trigger its own warning.
    • The loop guard’s final prompt continues to reflect the current failure-streak length.

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.
@github-actions github-actions Bot added the size:S Up to 29 changed lines, not counting tests, fixtures, translated docs, or the lockfile label Dec 6, 2026
@coderabbitai

coderabbitai Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Failure-streak warning identity

Layer / File(s) Summary
Key failure-streak warnings
packages/core/src/agent/loop-guards.ts, packages/core/src/agent/tool-loop.ts
Failure-streak warnings include the index where the streak begins. The tool loop compares and stores the streak key with its reason. The warning threshold and stop behavior remain unchanged.
Test repeated streak warnings
packages/e2e/tests/unit/agent-grammar-tools.test.ts, packages/e2e/tests/unit/loop-guards.test.ts, .changeset/failure-streak-warns-again.md
Tests verify that a continuing streak keeps its key, a new streak after success gets a different key, and warnings appear at turns 4 and 8. The changeset declares a patch for @e2e-dev/core.

Suggested reviewers: kdy1

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 4ed4c

The agent loop now warns on each new streak of three failed actions, including one that follows a success. The change is small and tested, and no merge-blocking risk was identified.

Security architecture risk: Minimal · up to 4ed4c

A new streak of failures can warn even if an earlier streak produced the same message. The warning thresholds and stop behavior are unchanged.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e11291e1-e64b-42ed-86e3-3079a1f9b061
Commits

Reviewing files that changed from the base of the PR and between 3c84adf and 4ed4cd5.

Files selected for processing: 2

  • packages/e2e/tests/unit/agent-grammar-tools.test.ts
  • packages/e2e/tests/unit/loop-guards.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

View guided diff | Re-trigger cubic

@AarnavNoble

Copy link
Copy Markdown
Author

/ready

@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

/ready did not add the Ready for Human Review label yet:

  • 9 workflow run(s) waiting for a maintainer to approve them, so CI has not run on the latest commit

Fix these and comment /ready again. How the label works.

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 success test in #231), and docs/agent-steps.mdx:69 says 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.ts fails the new loop test (expected [ 4 ] to deeply equal [ 4, 8 ]); reverting both source files also fails the new loop-guards test. Changeset (@e2e-dev/core patch) is accurate; no docs change needed.

Should fix

  1. 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

  1. tool-loop.ts:873-877 - noticedGuardReason now holds a key: reason composite for the streak and a bare reason for the other guards, and String(streak.key) would print undefined if a warn ever came back without a key. A dedicated field for the last warned streak (or a key that carries the length, added to noticedWaits like the wait path at L845-850) would keep one field, one meaning.
  2. loop-guards.test.ts:255-263 - the as { key?: string } casts could be toMatchObject({ 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.
@AarnavNoble

Copy link
Copy Markdown
Author

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 String(streak.key) alone drops the turn-5 notice and fails it. The loop-guards test now uses toMatchObject with the real keys (failures@0, failures@4) instead of casts.

I kept noticedGuardReason as the one field, so the streak and the other guards dedupe against each other as they do on main; checkFailureStreak always sets key on a warn. Happy to split it into its own field if a maintainer prefers.

The electron-windows (integration) failure is a launch timeout in dialogs > dismisses a dialog nothing answers; the Electron integration jobs fail on main too, and this PR does not touch the engine.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

View guided diff | Re-trigger cubic

@okwasniewski okwasniewski added the Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. label Dec 6, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. size:S Up to 29 changed lines, not counting tests, fixtures, translated docs, or the lockfile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

agent loop skips the failure-streak warning for a second streak of three

2 participants