Repository navigation
feat(usage): instrument project chat/analysis, add source breakdown and currency display - #505
Merged
Ayinkx merged 2 commits intoOct 17, 2026
Conversation
…cy display Add the central UsageRecord ledger and reversible migration, instrument project chat (streamed and non-streamed) and project analysis with project/workspace scope and an estimated flag, expose a per-user breakdown by source API, and format every cost figure in a configurable currency with an explicit estimate label. Refs AyinkxLab#429, AyinkxLab#432, AyinkxLab#451, AyinkxLab#441. Adds the ledger foundation required by the Phase 10 instrumentation issues.
|
@olaams-tech Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Keeps the PostgreSQL chat coverage gate above 85% by exercising the new ledger breakdown endpoint and the SSE reply branch of the messages API.
Contributor
Author
|
CI note: the |
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
Fixes #429
Fixes #432
Fixes #451
Fixes #441
This PR implements the Phase 10 usage-ledger work for these four issues:
UsageRecordledger model plus a reversible Alembic migration (usage_records), including scoped foreign keys and query indexes.app/services/usage_ledger.pywith count normalisation, cost estimation, scope filtering, summaries, and source aggregation. Unknown historical sources are grouped safely underunknown.source="project_chat", carrying user, workspace and project scope and the estimated flag.source="analysis", carrying user, workspace and project scope and the estimated flag.GET /api/usage/breakdown(optionally filtered byworkspace_idorproject_id, always owner-scoped), returning counts/totals per source, overall totals, known sources, and unknown sources.CURRENCY_CODE,CURRENCY_SYMBOLandCURRENCY_DECIMAL_PLACESconfiguration (default USD) with shared Python/JS formatting. Every cost figure now shows the currency code and is explicitly labelled as an estimate.Notes
The ledger foundation is a prerequisite for the instrumentation issues; it is included here because
/api/usage/breakdownand the project instrumentation need a central store. It is implemented to the schema described in #366.Verification
python -m ruff check .— passedpython -m black --check .— passed (268 files unchanged)pytest— all tests pass except two pre-existing failures on cleanorigin/main:tests/test_notifications.py::TestBudgetAlertDeduplicationimports the missingapp.services.budget_alertsmodule. Confirmed the same failure on an untouchedorigin/mainworktree.tests/js/currency.test.jsand runs in CI with the JS toolchain.