Skip to content

fix(usage): record GitHub analysis calls in the ledger - #567

Merged
Ayinkx merged 1 commit into
AyinkxLab:mainfrom
titankrypt-gif:fix/issue-366-analysis-ledger
Oct 23, 2026
Merged

Ayinkx merged 1 commit into
AyinkxLab:mainfrom
titankrypt-gif:fix/issue-366-analysis-ledger

Conversation

@titankrypt-gif

Copy link
Copy Markdown
Contributor

Summary

Records GitHub repository/issue/PR/file analysis completions in the central
usage ledger. These calls previously went through
app/services/analysis.py::_run and never produced a UsageRecord, leaving a
gap in the "every LLM call records a ledger row" requirement.

Problem

Issue #366 requires every LLM call to be recorded. Chat, project chat, project
analysis, reviews and tools were instrumented, but the GitHub analysis path
(analysis._run) called the provider directly. GitHub analysis usage was
therefore invisible to the ledger and dashboards.

Solution

  • analysis._run now records one UsageRecord after a successful completion,
    with source="analysis", the authenticated user, provider, and model.
  • Accounting is best-effort and wrapped so it can never break analysis.
  • Anonymous calls and calls outside an app context are not recorded because they
    have no owner.
  • complete() returns text only, so token counts are recorded as estimated
    zeroes rather than guessed.
  • Added tests/test_analysis_usage_ledger.py proving one row is written with
    the expected source, owner, provider and model.

Validation

  • python -m pytest tests/test_analysis_usage_ledger.py tests/test_stellar_analysis_github.py -q — PASS (22 passed)
  • python -m pytest tests/test_stellar_analysis.py tests/test_stellar_analysis_extra.py tests/test_stellar_aware_analysis.py -q — PASS (23 passed)
  • python -m ruff check app/services/analysis.py tests/test_analysis_usage_ledger.py — PASS
  • python -m black --check app/services/analysis.py tests/test_analysis_usage_ledger.py — PASS
  • Repo-wide ruff/black remain blocked by the pre-existing malformed
    app/services/invoice_export.py and tests/test_invoice_export.py files from
    feat(billing): export invoices as CSV and PDF with size bounds (#483) #535.

Risk

Adds one ledger write per successful GitHub analysis. The write is best-effort,
so a ledger failure cannot fail the analysis. Token counts for this path are
estimates (zero) until the provider surface exposes usage on complete().

Issue

Closes #366

@Ayinkx
Ayinkx merged commit cd4ea07 into AyinkxLab:main Oct 23, 2026
8 of 12 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.

Phase 10: Central usage ledger model and migration

2 participants