Skip to content

fix(review): meter issue planner AI usage#1403

Open
JSONbored wants to merge 1 commit into
mainfrom
codex/fix-unmetered-ai-calls-in-planner
Open

fix(review): meter issue planner AI usage#1403
JSONbored wants to merge 1 commit into
mainfrom
codex/fix-unmetered-ai-calls-in-planner

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • Prevent unmetered Workers-AI spend from the @gittensory plan command by enforcing the repo/global AI budget and avoiding bursty actor-driven consumption.
  • Ensure planner actions are recorded in the shared AI usage accounting so the existing daily neuron budget gating works across features.
  • Reduce risk of cross-tenant resource exhaustion by adding a short per-actor/per-repo cooldown to avoid repeated planner-trigger spam.

Description

  • Enforce budget and record usage in the planner by adding neuron estimation and pre-checks in generateIssuePlan using estimateNeurons, sumAiEstimatedNeuronsSince, and a new recordPlannerUsage wrapper that writes ai_usage_events rows (statuses: ok, no_output, quota_exceeded).
  • Add a per-actor/per-repo cooldown for @gittensory plan in maybeProcessPlanCommand with ISSUE_PLAN_COOLDOWN_MS and the helper isPlanCommandCoolingDown which checks recent audit_events to avoid repeated AI spend.
  • Wire accounting/cooldown into src/review/planner.ts and src/queue/processors.ts, and update tests in test/unit/planner.test.ts and test/unit/queue.test.ts to cover budget and cooldown behavior.

Testing

  • Ran npx vitest run test/unit/planner.test.ts and all planner unit tests passed (12/12).
  • Ran targeted queue tests for the planner with npx vitest run test/unit/queue.test.ts -t "planner" and the planner-related queue tests passed (planner cases succeeded; unrelated long-running queue tests were skipped in the targeted run).
  • Ran npm run typecheck (tsc --noEmit) and typechecking succeeded.
  • Started npm run test:coverage (full coverage) but the coverage run did not complete within the interactive run window; targeted unit tests above demonstrate the new budget/cooldown behavior passed.

Codex Task

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 26, 2026
@superagent-security

Copy link
Copy Markdown

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.34%. Comparing base (6138b9e) to head (5541fc5).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1403   +/-   ##
=======================================
  Coverage   95.33%   95.34%           
=======================================
  Files         192      192           
  Lines       20750    20770   +20     
  Branches     7500     7507    +7     
=======================================
+ Hits        19783    19803   +20     
  Misses        383      383           
  Partials      584      584           
Files with missing lines Coverage Δ
src/queue/processors.ts 87.68% <100.00%> (+0.07%) ⬆️
src/review/planner.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark codex size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant