Skip to content

Charge auto-research LLM calls to the agenda that owns them - #48

Merged
Kemalau merged 3 commits into
masterfrom
fix/auto-research-agenda-token-accounting
Oct 16, 2026
Merged

Kemalau merged 3 commits into
masterfrom
fix/auto-research-agenda-token-accounting

Conversation

@Kemalau

@Kemalau Kemalau commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes Extend agenda token accounting to the auto_research execution path #42. auto_research workers now enter agenda_scope before they spend, so execution-path LLM calls are attributed to the agenda that authorized them.
  • A scoped legacy call_llm checks the agenda cap before the provider request, writes agenda_token_ledger, and bumps token_spent. NULL, 0, and negative budgets stay accounting-only; crossing a positive cap flips the agenda to paused_budget, and raising the budget unpauses on the next check.
  • Grant-backed role calls keep the existing reservation clock: token_spent still moves when the parent grant settles, so usage is not counted twice. Each settled sub-reservation now appends a ledger row immediately, and in-flight grant usage counts toward the cap before that settlement.

Test plan

  • python -m unittest tests.test_agenda_execution_budget
  • python -m unittest tests.test_ingestion_extraction_retry.ScopedAttemptRegressionTests tests.test_ingestion_extraction_retry.RoleCheckpointRegressionTests tests.test_llm_client
  • Confirm a live execution grant writes agenda_token_ledger rows as each role call settles, and that token_spent still moves only when the parent grant settles

Made with Cursor

Execution workers spent outside any agenda scope, so those tokens never reached the agenda ledger until a whole grant settled.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cla-assistant

cla-assistant Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Kemalau

Kemalau commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator Author

I have read the CLA.md and agree to the terms.

@Kemalau
Kemalau merged commit b02c8cf into master Oct 16, 2026
2 checks passed
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.

Extend agenda token accounting to the auto_research execution path

1 participant