Skip to content

fix: show your spend and total spend in the agent listing - #1418

Open
ramantehlan wants to merge 6 commits into
mainfrom
sd/agents-spending-fix
Open

ramantehlan wants to merge 6 commits into
mainfrom
sd/agents-spending-fix

Conversation

@ramantehlan

@ramantehlan ramantehlan commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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_value keeps meaning "across every session on the agent" and becomes nullable; it is null when the caller may not see other users' sessions.
  • your_aggregate_value is new and always covers the sessions the caller created.
  • The agent library spend column renders 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.
  • Agent details Overview cards and the turn/duration statistics keep showing one number: the agent-wide one, falling back to the caller's own when it is withheld.
  • Callers under an all access scope (open source and local setups, where agents are not partitioned per user) may read totals, so both halves show real numbers there.
  • Chart data follows the same access rule as the meters, so sparklines and detail charts cover everyone's sessions wherever the totals are visible.

Individual sessions stay creator-scoped; only aggregates widen.

Testing

  • pnpm typecheck, pnpm lint:ci, pnpm format:check
  • pnpm test:trueforge, pnpm test:store:local (Postgres and SQLite contract suites), pnpm test:trueforge-ui, pnpm test:assistant-ui-runtime
  • SDKs and the OpenAPI document regenerated with pnpm openapi:write and pnpm sdk:generate

Note

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) and aggregate_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 / total with an em dash when the total is withheld, plus tooltips. Overview metric cards and statistics still show a single number via visibleMeterValue (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.

@changeset-bot

changeset-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 18b9331

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@truefoundry/trueforge Patch
@truefoundry/trueforge-assistant-ui-runtime Patch
@truefoundry/trueforge-ui Patch

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

@veria-ai

veria-ai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

Reviews

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>
@ramantehlan
ramantehlan force-pushed the sd/agents-spending-fix branch from fbf9048 to c7b5093 Compare November 17, 2026 11:20
@ramantehlan ramantehlan changed the title fix: label agent listing usage columns by viewer scope fix: show your spend and total spend in the agent listing Nov 17, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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;

@datadog-official datadog-official Bot Nov 18, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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? 👍/👎 View in Datadog  Leave us feedback  Documentation
🚩 Report as false positive. Flags the rule for review to improve detection accuracy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@datadog-official

datadog-official Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Code Quality  Code Vulnerabilities  IaC  Library Vulnerabilities  Secrets

⚠️ Warnings

🛠️ 3 Code quality issues detected

Low: typescript-code-style/assignment-name Assigment name should use camelCase View rule
packages/trueforge/src/db/sqlite/session-metrics/queries.ts:84
Low: typescript-code-style/assignment-name Assigment name should use camelCase View rule
packages/trueforge/src/db/postgres/session-metrics/queries.ts:112
Low: typescript-best-practices/boolean-prop-naming Consistent naming for boolean props View rule
packages/trueforge/src/db/sessionMetricsStore.ts:25

ℹ️ Info

No other issues found (see more)

🛡️ No new code vulnerabilities
📚 No new vulnerable libraries detected
🧱 No new Infrastructure as Code (IaC) issues
🔑 No new secrets detected

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 6c9cde0 | Docs | Give us feedback!

Comment thread .github/fern/openapi/openapi.json Resolved
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 });

@datadog-official datadog-official Bot Nov 20, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Low: Code Quality Violation

Suggested change
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? 👍/👎 View in Datadog  Leave us feedback  Documentation
🚩 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 });

@datadog-official datadog-official Bot Nov 20, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Low: Code Quality Violation

Suggested change
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? 👍/👎 View in Datadog  Leave us feedback  Documentation
🚩 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

This branch has not been deployed

No deployments
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.

3 participants