feat(budget): env-driven defaults for review reasoner caps#17
Merged
Conversation
The review reasoner had hard-coded 300s wall-clock and $2 cost caps that
fire as `BudgetExhaustedError("Budget exhausted before meta-selectors")`
on real-world PRs (the docs say a 500-line PR takes 35–50min — 300s
never had a chance). Callers like github-buddy intentionally don't
thread budget overrides through `app.call`, so deployments had no way
to retune without a code change.
Read the defaults from env (PR_AF_NO_BUDGET, PR_AF_MAX_DURATION_SECONDS,
PR_AF_MAX_COST_USD) at module load. Hard-coded fallbacks preserve the
prior behavior for callers that don't set the env. Setting
PR_AF_NO_BUDGET=true on a deployment disables enforcement entirely
(the existing `no_budget` short-circuit in BudgetConfig).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
The
reviewreasoner had hard-codedmax_duration_seconds=300(5 min) andmax_cost_usd=2.0defaults. On the Railway test deployment, this firesBudgetExhaustedError("Budget exhausted before meta-selectors")~6 minutes into every real PR review — the docs themselves say a 500-line PR takes 35–50 min, so 300s never had a chance.Upstream callers (e.g. github-buddy) intentionally don't thread budget overrides through
app.call("pr-af.review", ...)(its CLAUDE.md explicitly forbids it), so deployments currently have no way to lift the caps without editing this repo's source.This PR makes the three budget defaults read from env at module load:
PR_AF_NO_BUDGET(bool, defaultfalse) — whentrue, disables all cost/duration enforcement.PR_AF_MAX_DURATION_SECONDS(int, default300) — wall-clock cap.PR_AF_MAX_COST_USD(float, default2.0) — global cost cap.Hard-coded fallbacks preserve current behavior for callers that don't set the env. The
BudgetConfig.no_budgetshort-circuit in_budget_or_timeout_exhaustedalready exists — this just lets a deployment flip it.How this resolves the Railway hang
A real review on the deployment now needs
PR_AF_NO_BUDGET=true(recommended) orPR_AF_MAX_DURATION_SECONDS=1800set on the pr-af service env. Combined with the underlying error-propagation fix in agentfield (separate PR), the 9+ hour "running" UI state goes away.Test plan
python3 -m py_compile src/pr_af/app.py(done locally — passes).PR_AF_NO_BUDGET=trueset in the deployment env and confirm meta-selectors complete.BudgetExhaustedErrorstill fires for callers depending on it).app.call("pr-af.review", pr_url=..., max_duration_seconds=600)still wins over the env default (kwargs always override).🤖 Generated with Claude Code