-
Notifications
You must be signed in to change notification settings - Fork 8
feat(harness): track successful no-progress loops #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
senamakel
merged 5 commits into
tinyhumansai:main
from
senamakel:feat/successful-repeat-progress
Jul 23, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ac18c6c
feat(harness): track successful no-progress loops
senamakel b999021
fix(harness): reset output streak after failures
senamakel 465f28a
refactor(harness): centralize no-progress types
senamakel 286c621
fix(harness): reset exempt progress streaks
senamakel 046acdb
fix(harness): defer repeat halt until tool success
senamakel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| //! Successful-repeat progress detection. | ||
| //! | ||
| //! [`NoProgressTracker`] handles failing tool calls, but deliberately resets on | ||
| //! success. That leaves a second loop shape undetected: a model can repeatedly | ||
| //! emit the same response and successfully invoke the same no-op tool call. | ||
| //! This tracker owns the provider- and product-neutral streak accounting for | ||
| //! those loops; a harness middleware remains responsible for building canonical | ||
| //! signatures and deciding which polling tools are exempt. | ||
|
|
||
| use std::hash::{Hash, Hasher}; | ||
|
|
||
| use super::types::{Streak, SuccessfulRepeat, SuccessfulRepeatTracker}; | ||
|
|
||
| /// Consecutive identical assistant-output batches required to halt. | ||
| pub const DEFAULT_REPEAT_OUTPUT_THRESHOLD: u32 = 4; | ||
| /// Consecutive identical successful tool-call batches required to halt. | ||
| pub const DEFAULT_REPEAT_CALL_THRESHOLD: u32 = 3; | ||
|
|
||
| impl Streak { | ||
| fn record(&mut self, signature: &str) -> u32 { | ||
| let mut hasher = std::collections::hash_map::DefaultHasher::new(); | ||
| signature.hash(&mut hasher); | ||
| let hash = hasher.finish(); | ||
| if self.last_hash == Some(hash) { | ||
| self.consecutive += 1; | ||
| } else { | ||
| self.last_hash = Some(hash); | ||
| self.consecutive = 1; | ||
| } | ||
| self.consecutive | ||
| } | ||
|
|
||
| fn reset(&mut self) { | ||
| *self = Self::default(); | ||
| } | ||
| } | ||
|
|
||
| impl Default for SuccessfulRepeatTracker { | ||
| fn default() -> Self { | ||
| Self::new( | ||
| DEFAULT_REPEAT_OUTPUT_THRESHOLD, | ||
| DEFAULT_REPEAT_CALL_THRESHOLD, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| impl SuccessfulRepeatTracker { | ||
| /// Builds a tracker. Thresholds are clamped to one so `0` cannot disable a | ||
| /// safety guard accidentally; callers that do not want this guard should | ||
| /// omit the tracker. | ||
| pub fn new(output_threshold: u32, call_threshold: u32) -> Self { | ||
| Self { | ||
| output_threshold: output_threshold.max(1), | ||
| call_threshold: call_threshold.max(1), | ||
| output: std::sync::Mutex::new(Streak::default()), | ||
| calls: std::sync::Mutex::new(Streak::default()), | ||
| } | ||
| } | ||
|
|
||
| /// Stages the canonical visible-output plus tool-call signature produced | ||
| /// by one assistant iteration. A threshold crossing is not reported until | ||
| /// [`record_call_batch`](Self::record_call_batch) confirms that the | ||
| /// associated batch succeeded and is not exempt. | ||
| pub fn record_output(&self, signature: &str, exempt: bool) -> SuccessfulRepeat { | ||
| let mut output = self.output.lock().unwrap(); | ||
| if exempt { | ||
| output.reset(); | ||
| return SuccessfulRepeat::Continue; | ||
| } | ||
| output.record(signature); | ||
| SuccessfulRepeat::Continue | ||
| } | ||
|
|
||
| /// Records the canonical tool-name/arguments signature after the whole | ||
| /// batch completes. Failed or exempt batches reset the successful streak. | ||
| pub fn record_call_batch( | ||
| &self, | ||
| signature: &str, | ||
| all_successful: bool, | ||
| exempt: bool, | ||
| ) -> SuccessfulRepeat { | ||
| if exempt || !all_successful { | ||
| // Output is observed before the completed batch can be classified. | ||
| // An exempt polling batch or a failure therefore resets both | ||
| // trackers so its preceding output cannot leak into the next | ||
| // progress-eligible iteration. | ||
| self.output.lock().unwrap().reset(); | ||
| self.calls.lock().unwrap().reset(); | ||
| return SuccessfulRepeat::Continue; | ||
| } | ||
| let output_consecutive = self.output.lock().unwrap().consecutive; | ||
| if output_consecutive >= self.output_threshold { | ||
| return SuccessfulRepeat::Halt(format!( | ||
| "Stopping: the last {output_consecutive} iterations produced the identical response and tool call with no change; the run is stuck repeating the same step without making progress." | ||
| )); | ||
| } | ||
| let mut calls = self.calls.lock().unwrap(); | ||
| let consecutive = calls.record(signature); | ||
| if consecutive < self.call_threshold { | ||
| return SuccessfulRepeat::Continue; | ||
| } | ||
| SuccessfulRepeat::Halt(format!( | ||
| "Stopping: the same successful tool-call batch was issued {consecutive} times in a row with identical arguments and no new information; the run is stuck repeating one action without making progress." | ||
| )) | ||
| } | ||
|
|
||
| /// Clears both streaks, for example when a paused run is resumed. | ||
| pub fn reset(&self) { | ||
| self.output.lock().unwrap().reset(); | ||
| self.calls.lock().unwrap().reset(); | ||
| } | ||
| } | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.