Repository navigation
fix(guardrail): generic tool-call repetition breaker (closes #308) - #314
Merged
Merged
Conversation
Greedy-decoding small models can loop on a byte-identical tool call
(e.g. acp_status {"scope":"uncompressed","view":"ranges"} x30), a
sequence-level attractor that token penalties cannot break and that the
compress-failure breaker never counts. Add a per-session consecutive-run
fingerprint guard: sha1(toolName + key-sorted canonical JSON(args)) —
arguments only, result content ignored. At warn (default 3) append a strong
warning to the matching toolResult; at abort (default 5) block the call,
abort the turn, and notify the terminal. Any arg/tool change or real user
message resets the run. Config: acp.json { "repetitionGuard": {enabled,warn,abort} },
default on.
# Conflicts: # CHANGELOG.md
Contributor
📦 Built Extension ArtifactBranch: Option A — Install from npm PR tag (recommended)pi install npm:billion-context-pi@pr-314Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pi-pr314.tgz
pi install ./packageThis comment is automatically updated on each push. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #308 — greedy-decoding small models get stuck re-emitting a byte-identical tool call every turn (
acp_status {"scope":"uncompressed","view":"ranges"}×30, context 57K→130K). This is a sequence-level attractor: the repetition crosses turn boundaries, so token-level penalties are powerless, and none of the existing defenses catch it:compress-retry-cappedbreaker only countscompressfailures (collectCompressOutcomesinsrc/index.tsskips non-compress results) —acp_statusalways succeeds → zero count;turnKey— during the loop there's no new user message, soturnKeystays constant and every non-emergency nudge is suppressed;src/tool-guardrails.tspreviously had only the bash output cap + timeout detection, no repetition detection.Fix (owner spec item #1 — core)
A per-session consecutive-run fingerprint guard in
src/tool-guardrails.ts:sha1(toolName + canonical-JSON(args)), where the JSON serialization sorts object keys → compares arguments only; key order and result content are ignored (the visible message count inside anacp_statusresult varies 24→26→28, but identical args still match);warn(default 3): append a strong warning to the matching toolResult ("stop issuing this identical call — change arguments/approach, or stop");abort(default 5): block the call (not executed), abort the current turn, and notify the terminal;Config:
acp.json { "repetitionGuard": { "enabled": true, "warn": 3, "abort": 5 } }— default on. Resolution lives insrc/config.ts(resolveRepetitionGuard,REPETITION_GUARD_DEFAULTS);abortis clamped to be> warn.Deferred (intentionally not in this PR)
The other three suggestions from the issue are deliberately split out:
acp_status/decompress/search_contextrepeats); the extra "tokenCount no-drop" signal is weaker and adds little value now.Happy to track these as follow-up issues if you want them.
Tests
+22 tests, all green (full suite 484 pass / 0 fail across repeated runs):
canonicalStringify(key-order independence, array ordering preserved, undefined-value drop, nesting),repetitionFingerprint(stable across key order, differs on arg change / tool change);RepetitionTracker: escalation none→warn→abort, reset on a different fingerprint (args or tool name),reset();pi+ctx): warn@3 without blocking, block+abort@5 (turn aborted exactly once, still blocked after), argument-change reset, user-input-resets-but-extension-input-does-not, fully inert whenrepetitionGuard: false, custom{warn:2, abort:3}thresholds.Docs updated:
CONFIGURATION.md/CONFIGURATION.zh-CN.md(new "Tool Call Repetition Guard" section + summary tables) andCHANGELOG.md.