-
Notifications
You must be signed in to change notification settings - Fork 24
Track equivalent classified failures across agent retries #219
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 2 commits into
tinyhumansai:main
from
senamakel:classified-failure-loops
Sep 25, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,93 @@ | ||
| //! Failure equivalence and recovery budgets independent of literal call arguments. | ||
|
|
||
| use std::collections::HashMap; | ||
| use std::sync::Mutex; | ||
|
|
||
| use super::NoProgress; | ||
|
|
||
| /// A trusted classification of one failed operation. The caller supplies stable | ||
| /// operation and scope identifiers; neither error prose nor literal query text | ||
| /// belongs in this key. | ||
| #[derive(Clone, Debug, Eq, Hash, PartialEq)] | ||
| pub struct ClassifiedFailure { | ||
| pub class: String, | ||
| pub operation: String, | ||
| pub scope: String, | ||
| } | ||
|
|
||
| impl ClassifiedFailure { | ||
| pub fn new( | ||
| class: impl Into<String>, | ||
| operation: impl Into<String>, | ||
| scope: impl Into<String>, | ||
| ) -> Self { | ||
| Self { | ||
| class: class.into(), | ||
| operation: operation.into(), | ||
| scope: scope.into(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Counts equivalent failures across intervening calls. Only an observation | ||
| /// that the same blocker changed should call [`Self::clear`]. | ||
| #[derive(Default)] | ||
| pub struct ClassifiedFailureTracker { | ||
| counts: Mutex<HashMap<ClassifiedFailure, usize>>, | ||
| } | ||
|
|
||
| impl ClassifiedFailureTracker { | ||
| /// `recovery_budget` is the number of retry calls allowed after the first | ||
| /// failure. A budget of one permits one retry and halts if that retry also | ||
| /// fails; zero stops on the first observation. | ||
| pub fn record(&self, key: &ClassifiedFailure, recovery_budget: usize) -> NoProgress { | ||
| let mut counts = self.counts.lock().unwrap(); | ||
| let attempts = counts.entry(key.clone()).or_default(); | ||
| *attempts += 1; | ||
| if *attempts > recovery_budget { | ||
|
senamakel marked this conversation as resolved.
|
||
| NoProgress::Halt(format!( | ||
| "Stopping after {} attempt(s): failure class `{}` still blocks operation `{}` on `{}`. Resolve this blocker before retrying.", | ||
| attempts, key.class, key.operation, key.scope | ||
| )) | ||
| } else { | ||
| NoProgress::Continue | ||
| } | ||
| } | ||
|
|
||
| /// Clear one blocker after an observation proves it changed or recovered. | ||
| pub fn clear(&self, key: &ClassifiedFailure) { | ||
| self.counts.lock().unwrap().remove(key); | ||
| } | ||
|
|
||
| /// Clear all groups when a new turn begins. | ||
| pub fn reset(&self) { | ||
| self.counts.lock().unwrap().clear(); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod test { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn equivalent_failures_survive_intervening_calls_and_clear_by_scope() { | ||
| let tracker = ClassifiedFailureTracker::default(); | ||
| let a = ClassifiedFailure::new("permission", "search", "account-a"); | ||
| let b = ClassifiedFailure::new("permission", "search", "account-b"); | ||
| assert_eq!(tracker.record(&a, 1), NoProgress::Continue); | ||
| assert_eq!(tracker.record(&b, 1), NoProgress::Continue); | ||
| assert!( | ||
| matches!(tracker.record(&a, 1), NoProgress::Halt(message) if message.contains("2 attempt(s)")) | ||
| ); | ||
| tracker.clear(&a); | ||
| assert_eq!(tracker.record(&a, 1), NoProgress::Continue); | ||
| assert!(matches!(tracker.record(&b, 1), NoProgress::Halt(_))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn zero_budget_stops_immediately() { | ||
| let tracker = ClassifiedFailureTracker::default(); | ||
| let key = ClassifiedFailure::new("policy", "write", "project"); | ||
| assert!(matches!(tracker.record(&key, 0), NoProgress::Halt(_))); | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.