Repository navigation
fix: show your spend and total spend in the agent listing - #1418
ramantehlan wants to merge 6 commits into
Conversation
🦋 Changeset detectedLatest commit: 18b9331 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Metrics meters now carry both the caller's own aggregate and the agent-wide one, with the agent-wide value null when the caller may not see other users' sessions. Callers under an `all` access scope may read totals, since agents are not partitioned per user there. The agent library spend column shows "yours / total" and falls back to a dash when the total is withheld; single-number surfaces keep showing the total and fall back to the caller's own. Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>
fbf9048 to
c7b5093
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c7b5093. Configure here.
Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>
Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>
| tenant_id: string; | ||
| agent_id: string; | ||
| subject_id: string; | ||
| include_total: boolean; |
There was a problem hiding this comment.
🟡 Low: Code Quality Violation
Prop name 'include_total' is not prefixed with `is` or `has` (...read more)
Enforces a consistent naming pattern for boolean props to ensure that the variable is prefixed with either is or has (or the uppercase equivalent). Any prefix symbol (_, $, etc) is allowed.
Helpful? 👍/👎
🚩 Report as false positive. Flags the rule for review to improve detection accuracy.
There was a problem hiding this comment.
Leaving this one as is. Store input fields in this repo are snake_case and unprefixed, matching the columns and wire fields they carry (create_agent_session in memoryIngestStore, enabled / is_default in sandboxEnvironmentStore). An is/has prefix here would read as a property of the caller rather than what it is, a switch asking the store to also compute the all-session aggregate.
|
Matches the `created_by_me` vocabulary the sessions and schedules list endpoints already use for "rows the caller created", end to end: wire field, store pair, runtime meter type, and the library usage stats. Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>
| ): Promise<SessionMetricsMeterResponse> { | ||
| const aggregate = await fetchSessionMetricsAggregate(db, input); | ||
| return buildSessionMetricsMeters(aggregate); | ||
| const created_by_me = await fetchSessionMetricsAggregate(db, { ...input, created_by_subject_id: input.subject_id }); |
There was a problem hiding this comment.
🟡 Low: Code Quality Violation
| const created_by_me = await fetchSessionMetricsAggregate(db, { ...input, created_by_subject_id: input.subject_id }); | |
| const createdByMe = await fetchSessionMetricsAggregate(db, { ...input, created_by_subject_id: input.subject_id }); |
Use 'camelCase' and not 'snake_case' or 'PascalCase' (...read more)
Ensure that variables and properties names use camelCase and not snake_case or PascalCase.
Helpful? 👍/👎
🚩 Report as false positive. Flags the rule for review to improve detection accuracy.
| ): Promise<SessionMetricsMeterResponse> { | ||
| const aggregate = await fetchSessionMetricsAggregate(db, input); | ||
| return buildSessionMetricsMeters(aggregate); | ||
| const created_by_me = await fetchSessionMetricsAggregate(db, { ...input, created_by_subject_id: input.subject_id }); |
There was a problem hiding this comment.
🟡 Low: Code Quality Violation
| const created_by_me = await fetchSessionMetricsAggregate(db, { ...input, created_by_subject_id: input.subject_id }); | |
| const createdByMe = await fetchSessionMetricsAggregate(db, { ...input, created_by_subject_id: input.subject_id }); |
Use 'camelCase' and not 'snake_case' or 'PascalCase' (...read more)
Ensure that variables and properties names use camelCase and not snake_case or PascalCase.
Helpful? 👍/👎
🚩 Report as false positive. Flags the rule for review to improve detection accuracy.
Signed-off-by: Raman Tehlan <ramantehlan@gmail.com> # Conflicts: # packages/trueforge-ui/src/atoms/lib/useAgentLibraryUsageStats.ts

What
A user without manage access on an agent only ever saw their own spend in the agent listing, with no way to tell that apart from the agent's real total. The metrics API now returns both numbers and the listing shows them together.
aggregate_valuekeeps meaning "across every session on the agent" and becomes nullable; it isnullwhen the caller may not see other users' sessions.your_aggregate_valueis new and always covers the sessions the caller created.yours / total, for example$1.20 / $4.50, and shows a dash for a withheld total. The header reads "Your / Total Spend" and a tooltip explains both halves.allaccess scope (open source and local setups, where agents are not partitioned per user) may read totals, so both halves show real numbers there.Individual sessions stay creator-scoped; only aggregates widen.
Testing
pnpm typecheck,pnpm lint:ci,pnpm format:checkpnpm test:trueforge,pnpm test:store:local(Postgres and SQLite contract suites),pnpm test:trueforge-ui,pnpm test:assistant-ui-runtimepnpm openapi:writeandpnpm sdk:generateNote
Medium Risk
Changes authorization for aggregate metrics and nullable API fields across backend, SDKs, and UI; incorrect scoping could leak cross-user spend or break clients that assumed non-null aggregate_value.
Overview
The session metrics meters API now returns two values per meter:
created_by_me_aggregate_value(always the caller's sessions) andaggregate_value(agent-wide, nullable when the caller cannot manage the agent and thus must not see other users' aggregates).The metrics router uses
canReadAgentAggregates(per-agent manage permission) to decide whether to compute totals; the store layer fetches both scopes and builds paired meters. OpenAPI, TypeScript/Python SDKs, and runtime types follow the new shape.In the agent library, the spend column header becomes "Your / Total Spend" and each row shows
your / totalwith an em dash when the total is withheld, plus tooltips. Overview metric cards and statistics still show a single number viavisibleMeterValue(agent-wide, falling back to yours). Chart data continues to scope to everyone only when totals are allowed.Tests and wire mocks were updated for the dual-meter contract and a new case where viewers without manage grants get null totals.
Reviewed by Cursor Bugbot for commit 6c9cde0. Bugbot is set up for automated code reviews on this repo. Configure here.