Skip to content

Refactor budget enforcement to use exception-based control flow#19

Merged
rbharvs merged 2 commits intomainfrom
brett/fix-budget-enforcement
Jun 20, 2025
Merged

Refactor budget enforcement to use exception-based control flow#19
rbharvs merged 2 commits intomainfrom
brett/fix-budget-enforcement

Conversation

@rbharvs
Copy link
Owner

@rbharvs rbharvs commented Jun 20, 2025

Summary

  • Replace manual budget checking with BudgetExceeded exception-based control flow
  • Centralize budget logic in OutputBudget.debit() method for atomic operations
  • Remove budget parameter from StreamingRegexSearcher - budget now handled at Grepper level
  • Update Globber to debit budget by path length instead of count for more accurate resource tracking

Benefits

  • Eliminates race conditions between budget checking and debiting
  • Cleaner separation of concerns - budget enforcement centralized in one place
  • More maintainable code with less repetitive manual budget checks
  • Consistent error handling across all components using BudgetExceeded exceptions

Changes

  • Updated StreamingFileReader, Globber, and Grepper to use exception-based budget handling
  • Removed obsolete budget-related tests from StreamingRegexSearcher (budget now handled upstream)
  • Fixed all test method signatures and removed unused budget parameters
  • Updated protocol interface to reflect new budget handling architecture

Test plan

  • All existing tests pass (145/145)
  • Code quality checks pass (ruff, mypy)
  • Budget enforcement still works correctly at component boundaries
  • Exception handling properly sets truncation flags

rbharvs added 2 commits June 20, 2025 19:13
- Update test budgets to account for file path length being debited
- Fix FileWindow validation to require line_count >= 1 (not >= 0)
- Adjust budget calculations in tests to include both path and content costs
- All 145 tests now pass with proper budget enforcement
@rbharvs rbharvs force-pushed the brett/fix-budget-enforcement branch from ccce1a7 to cb64a10 Compare June 20, 2025 23:33
@rbharvs rbharvs merged commit 421c2e8 into main Jun 20, 2025
1 check passed
@rbharvs rbharvs deleted the brett/fix-budget-enforcement branch June 20, 2025 23:34
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