Skip to content

feat(ai): detect consecutive redundant reads of unchanged files in tool-call loop guard - #902

Merged
santhreal merged 7 commits into
mainfrom
fix/read-loop-token-compaction
Aug 25, 2026
Merged

feat(ai): detect consecutive redundant reads of unchanged files in tool-call loop guard#902
santhreal merged 7 commits into
mainfrom
fix/read-loop-token-compaction

Conversation

@santhreal

Copy link
Copy Markdown
Owner

Summary

  • Extends ToolCallLoopGuard in @veyyon/ai to detect consecutive redundant/subsumed read tool calls on unchanged files whose requested line ranges are already fully present in recent context.
  • Configurable via model.toolCallLoopGuard.readSubsumptionThreshold (default 2).
  • Preserves 100% prompt cache prefix without cache busting by injecting the corrective steering redirect message at the tail of history before the model's next turn.
  • Resets read tracking on any file mutation (edit, write, ast_edit, or bash) and permits legitimate overlapping scrolls (1-50 -> 40-100) and summary drill-downs without triggering the guard.

Verification

  • packages/ai/test/tool-call-loop-guard.test.ts (10/10 tests passing, mutation-gated)
  • packages/coding-agent/test/agent-session-tool-call-loop-guard.test.ts (2/2 tests passing, mutation-gated)
  • bun run check:tools & bun run check:ts clean

@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 132 files, which is 32 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 75228645-a757-405d-98d5-ae12873a7a35

📥 Commits

Reviewing files that changed from the base of the PR and between 8cdfe06 and 00f7ab5.

📒 Files selected for processing (132)
  • CHANGELOG.md
  • docs/handbook/book/404.html
  • docs/handbook/book/acknowledgements.html
  • docs/handbook/book/appendix/glossary.html
  • docs/handbook/book/architecture/compaction.html
  • docs/handbook/book/architecture/config.html
  • docs/handbook/book/architecture/mcp.html
  • docs/handbook/book/architecture/memory.html
  • docs/handbook/book/architecture/overview.html
  • docs/handbook/book/architecture/providers.html
  • docs/handbook/book/architecture/sandbox.html
  • docs/handbook/book/architecture/secrets.html
  • docs/handbook/book/architecture/session-turn.html
  • docs/handbook/book/architecture/tui.html
  • docs/handbook/book/concepts/index.html
  • docs/handbook/book/concepts/model-contract.html
  • docs/handbook/book/concepts/permission-model.html
  • docs/handbook/book/concepts/sessions-turns-threads.html
  • docs/handbook/book/context/compaction-memory.html
  • docs/handbook/book/context/context-files.html
  • docs/handbook/book/context/goal-state.html
  • docs/handbook/book/context/reads-search.html
  • docs/handbook/book/edit/edit-repair.html
  • docs/handbook/book/edit/engine.html
  • docs/handbook/book/edit/roadmap.html
  • docs/handbook/book/features/advisor.html
  • docs/handbook/book/features/branching.html
  • docs/handbook/book/features/cockpit.html
  • docs/handbook/book/features/collab.html
  • docs/handbook/book/features/connectors.html
  • docs/handbook/book/features/cpu-limit.html
  • docs/handbook/book/features/doctor.html
  • docs/handbook/book/features/exec.html
  • docs/handbook/book/features/export-import.html
  • docs/handbook/book/features/extensions-authoring.html
  • docs/handbook/book/features/extensions.html
  • docs/handbook/book/features/feature-flags.html
  • docs/handbook/book/features/hooks-authoring.html
  • docs/handbook/book/features/hooks.html
  • docs/handbook/book/features/index.html
  • docs/handbook/book/features/keybindings.html
  • docs/handbook/book/features/lsp.html
  • docs/handbook/book/features/marketplace-authoring.html
  • docs/handbook/book/features/marketplace.html
  • docs/handbook/book/features/mcp.html
  • docs/handbook/book/features/memory.html
  • docs/handbook/book/features/personalities.html
  • docs/handbook/book/features/plan-mode.html
  • docs/handbook/book/features/plugins.html
  • docs/handbook/book/features/profiles.html
  • docs/handbook/book/features/python-repl.html
  • docs/handbook/book/features/review.html
  • docs/handbook/book/features/sandbox.html
  • docs/handbook/book/features/secrets.html
  • docs/handbook/book/features/skills-authoring.html
  • docs/handbook/book/features/skills.html
  • docs/handbook/book/features/speech.html
  • docs/handbook/book/features/subagents.html
  • docs/handbook/book/features/web-search.html
  • docs/handbook/book/foundations/architecture.html
  • docs/handbook/book/foundations/thesis.html
  • docs/handbook/book/foundations/verification.html
  • docs/handbook/book/index.html
  • docs/handbook/book/introduction.html
  • docs/handbook/book/models/prompts.html
  • docs/handbook/book/models/providers.html
  • docs/handbook/book/models/system-prompt.html
  • docs/handbook/book/observability/overview.html
  • docs/handbook/book/print.html
  • docs/handbook/book/reference/approval-mode.html
  • docs/handbook/book/reference/cli.html
  • docs/handbook/book/reference/environment-complete.html
  • docs/handbook/book/reference/environment.html
  • docs/handbook/book/reference/exit-codes.html
  • docs/handbook/book/reference/file-locations.html
  • docs/handbook/book/reference/hooks.html
  • docs/handbook/book/reference/index.html
  • docs/handbook/book/reference/keybindings-config.html
  • docs/handbook/book/reference/keybindings-ref.html
  • docs/handbook/book/reference/mcp-config.html
  • docs/handbook/book/reference/models-yml.html
  • docs/handbook/book/reference/project-trust.html
  • docs/handbook/book/reference/providers.html
  • docs/handbook/book/reference/rpc.html
  • docs/handbook/book/reference/sdk.html
  • docs/handbook/book/reference/settings-reference.html
  • docs/handbook/book/reference/settings.html
  • docs/handbook/book/reference/skills.html
  • docs/handbook/book/reference/slash-commands.html
  • docs/handbook/book/reference/theme.html
  • docs/handbook/book/reference/tools.html
  • docs/handbook/book/reference/tree-command.html
  • docs/handbook/book/repair/cascade.html
  • docs/handbook/book/repair/overview.html
  • docs/handbook/book/repair/per-model.html
  • docs/handbook/book/repair/soundness.html
  • docs/handbook/book/router/role-routing.html
  • docs/handbook/book/searcher-c2a407aa.js
  • docs/handbook/book/searchindex-f272b308.js
  • docs/handbook/book/using/authentication.html
  • docs/handbook/book/using/configuration.html
  • docs/handbook/book/using/configuring-providers.html
  • docs/handbook/book/using/custom-tools.html
  • docs/handbook/book/using/editing.html
  • docs/handbook/book/using/examples.html
  • docs/handbook/book/using/extending.html
  • docs/handbook/book/using/faq.html
  • docs/handbook/book/using/getting-started.html
  • docs/handbook/book/using/install.html
  • docs/handbook/book/using/mcp-setup.html
  • docs/handbook/book/using/migration-guide.html
  • docs/handbook/book/using/models.html
  • docs/handbook/book/using/quickstart.html
  • docs/handbook/book/using/roles-and-profiles.html
  • docs/handbook/book/using/safety.html
  • docs/handbook/book/using/sessions.html
  • docs/handbook/book/using/task-guides.html
  • docs/handbook/book/using/themes.html
  • docs/handbook/book/using/troubleshooting.html
  • docs/handbook/book/why/argot.html
  • docs/handbook/book/why/index.html
  • docs/handbook/book/why/innovations.html
  • docs/handbook/book/why/performance.html
  • docs/handbook/book/why/value.html
  • docs/handbook/src/reference/settings-reference.md
  • packages/ai/CHANGELOG.md
  • packages/ai/src/utils/tool-call-loop-guard.ts
  • packages/ai/test/tool-call-loop-guard.test.ts
  • packages/coding-agent/CHANGELOG.md
  • packages/coding-agent/src/config/settings-domains/model.ts
  • packages/coding-agent/src/session/agent-session.ts
  • packages/coding-agent/test/agent-session-tool-call-loop-guard.test.ts

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…ompaction

# Conflicts:
#	docs/handbook/book/404.html
#	docs/handbook/book/acknowledgements.html
#	docs/handbook/book/appendix/glossary.html
#	docs/handbook/book/architecture/compaction.html
#	docs/handbook/book/architecture/config.html
#	docs/handbook/book/architecture/mcp.html
#	docs/handbook/book/architecture/memory.html
#	docs/handbook/book/architecture/overview.html
#	docs/handbook/book/architecture/providers.html
#	docs/handbook/book/architecture/sandbox.html
#	docs/handbook/book/architecture/secrets.html
#	docs/handbook/book/architecture/session-turn.html
#	docs/handbook/book/architecture/tui.html
#	docs/handbook/book/concepts/index.html
#	docs/handbook/book/concepts/model-contract.html
#	docs/handbook/book/concepts/permission-model.html
#	docs/handbook/book/concepts/sessions-turns-threads.html
#	docs/handbook/book/context/compaction-memory.html
#	docs/handbook/book/context/context-files.html
#	docs/handbook/book/context/goal-state.html
#	docs/handbook/book/context/reads-search.html
#	docs/handbook/book/edit/edit-repair.html
#	docs/handbook/book/edit/engine.html
#	docs/handbook/book/edit/roadmap.html
#	docs/handbook/book/features/advisor.html
#	docs/handbook/book/features/branching.html
#	docs/handbook/book/features/cockpit.html
#	docs/handbook/book/features/collab.html
#	docs/handbook/book/features/connectors.html
#	docs/handbook/book/features/cpu-limit.html
#	docs/handbook/book/features/doctor.html
#	docs/handbook/book/features/exec.html
#	docs/handbook/book/features/export-import.html
#	docs/handbook/book/features/extensions-authoring.html
#	docs/handbook/book/features/extensions.html
#	docs/handbook/book/features/feature-flags.html
#	docs/handbook/book/features/hooks-authoring.html
#	docs/handbook/book/features/hooks.html
#	docs/handbook/book/features/index.html
#	docs/handbook/book/features/keybindings.html
#	docs/handbook/book/features/lsp.html
#	docs/handbook/book/features/marketplace-authoring.html
#	docs/handbook/book/features/marketplace.html
#	docs/handbook/book/features/mcp.html
#	docs/handbook/book/features/memory.html
#	docs/handbook/book/features/personalities.html
#	docs/handbook/book/features/plan-mode.html
#	docs/handbook/book/features/plugins.html
#	docs/handbook/book/features/profiles.html
#	docs/handbook/book/features/python-repl.html
#	docs/handbook/book/features/review.html
#	docs/handbook/book/features/sandbox.html
#	docs/handbook/book/features/secrets.html
#	docs/handbook/book/features/skills-authoring.html
#	docs/handbook/book/features/skills.html
#	docs/handbook/book/features/speech.html
#	docs/handbook/book/features/subagents.html
#	docs/handbook/book/features/web-search.html
#	docs/handbook/book/foundations/architecture.html
#	docs/handbook/book/foundations/thesis.html
#	docs/handbook/book/foundations/verification.html
#	docs/handbook/book/index.html
#	docs/handbook/book/introduction.html
#	docs/handbook/book/models/prompts.html
#	docs/handbook/book/models/providers.html
#	docs/handbook/book/models/system-prompt.html
#	docs/handbook/book/observability/overview.html
#	docs/handbook/book/print.html
#	docs/handbook/book/reference/approval-mode.html
#	docs/handbook/book/reference/cli.html
#	docs/handbook/book/reference/environment-complete.html
#	docs/handbook/book/reference/environment.html
#	docs/handbook/book/reference/exit-codes.html
#	docs/handbook/book/reference/file-locations.html
#	docs/handbook/book/reference/hooks.html
#	docs/handbook/book/reference/index.html
#	docs/handbook/book/reference/keybindings-config.html
#	docs/handbook/book/reference/keybindings-ref.html
#	docs/handbook/book/reference/mcp-config.html
#	docs/handbook/book/reference/models-yml.html
#	docs/handbook/book/reference/project-trust.html
#	docs/handbook/book/reference/providers.html
#	docs/handbook/book/reference/rpc.html
#	docs/handbook/book/reference/sdk.html
#	docs/handbook/book/reference/settings-reference.html
#	docs/handbook/book/reference/settings.html
#	docs/handbook/book/reference/skills.html
#	docs/handbook/book/reference/slash-commands.html
#	docs/handbook/book/reference/theme.html
#	docs/handbook/book/reference/tools.html
#	docs/handbook/book/reference/tree-command.html
#	docs/handbook/book/repair/cascade.html
#	docs/handbook/book/repair/overview.html
#	docs/handbook/book/repair/per-model.html
#	docs/handbook/book/repair/soundness.html
#	docs/handbook/book/router/role-routing.html
#	docs/handbook/book/searcher-c2a407aa.js
#	docs/handbook/book/searchindex-858018f9.js
#	docs/handbook/book/using/authentication.html
#	docs/handbook/book/using/configuration.html
#	docs/handbook/book/using/configuring-providers.html
#	docs/handbook/book/using/custom-tools.html
#	docs/handbook/book/using/editing.html
#	docs/handbook/book/using/examples.html
#	docs/handbook/book/using/extending.html
#	docs/handbook/book/using/faq.html
#	docs/handbook/book/using/getting-started.html
#	docs/handbook/book/using/install.html
#	docs/handbook/book/using/mcp-setup.html
#	docs/handbook/book/using/migration-guide.html
#	docs/handbook/book/using/models.html
#	docs/handbook/book/using/quickstart.html
#	docs/handbook/book/using/roles-and-profiles.html
#	docs/handbook/book/using/safety.html
#	docs/handbook/book/using/sessions.html
#	docs/handbook/book/using/task-guides.html
#	docs/handbook/book/using/themes.html
#	docs/handbook/book/using/troubleshooting.html
#	docs/handbook/book/why/argot.html
#	docs/handbook/book/why/index.html
#	docs/handbook/book/why/innovations.html
#	docs/handbook/book/why/performance.html
#	docs/handbook/book/why/value.html
Adding read subsumption rewrote the threshold check from `count !== threshold`
to `count >= threshold`, so the redirect fired again on every repeat after the
first. The turn-sim suite states the contract in its name and went red on both
of its arms: one redirect, on the turn that reaches the threshold.

The subsumption branch had the same shape and no test for it, so a steer for a
redundant read repeated on every further read. Both branches fire on equality
now, and the positive subsumption test carries a fourth still-subsumed read
that must stay quiet.

Refs #902
@santhreal
santhreal merged commit 8f417c3 into main Aug 25, 2026
40 checks passed
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