Uh oh!
There was an error while loading. Please reload this page.
Add session metrics API and per-session totals - #484
Conversation
🦋 Changeset detectedLatest commit: 5edc0f0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 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 |
8d360cc to
21f140eCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
a647804 to
4f7e36fCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
Reviewed by Cursor Bugbot for commit 98e2416. Configure here.
Uh oh!
There was an error while loading. Please reload this page.

Summary
Caller-scoped session metrics for named agents: persist rolled-up per-session totals, and expose meters / chart catalog / chart-data APIs aligned with the ServiceFoundry-style dashboard split.
Closes AGE-2011
Changes
Session.metrics(total_cost_in_usd,total_duration_ms,total_turns): zero on create;createTurnincrements turns; terminal writes fold cost + durationgetSessionMetricsMeters/getSessionMetricsChartDataon InMemory, Postgres, and SQLite (shared builders + inclusion rules)GET /api/v1/sessions/metrics/metersGET /api/v1/sessions/metrics/chartsGET /api/v1/sessions/metrics/charts-datatotal_duration_ms > 0(nottotal_turns > 0) so in-flight first turns don’t collapse min/median/p95 to 0msHow was this tested?
packages/trueforge-coresession metrics builders + fold (sessionMetrics.test.ts)storeContractSuitesession metrics cases, including all-12-meters fixture)packages/trueforge/tests/unit/apis/sessionHttp.test.tspnpm --filter @truefoundry/trueforge-core test(targeted),pnpm --filter @truefoundry/trueforge test:store:sqlite(metrics cases)Checklist
pnpm build,pnpm test,pnpm typecheck,pnpm lint:ci, andpnpm format:checkpass locallypackages/trueforge-sdk,.github/fern/openapi/openapi.json,docs/openapi.json) — metrics routes are fern-ignored; fork PRs omit SDK regen; maintainers regenerate after merge.env.exampleupdated if configuration or behavior changedNote
Medium Risk
Introduces new read APIs and a breaking Session wire shape (required
metrics), with aggregation logic that must stay consistent across SQLite, Postgres, and in-memory stores.Overview
Adds session metrics for named agents: rolled-up
metricson every Session response (cost, duration, turns) and three internal GET routes under/api/v1/sessions/metrics/*(Fern-excluded).Meters (
/metrics/meters) aggregate the authenticated caller’s sessions for a givenagent_idover an inclusivecreated_atwindow (max 30 days), returning 12 fixed meters (totals, cost/session, turn and duration stats with median/p95). Charts (/metrics/charts) expose a static catalog; chart data (/metrics/charts-data) returns zero-filled line series for one chart (sessions_over_time,sessions_cost_over_time,turns_over_time) with hourly buckets for ≤24h windows and daily UTC buckets otherwise.Shared aggregation lives in
sessionMetrics(core) and is wired throughISessionStoreinto in-memory, SQLite, and Postgres stores (SQL aggregates on the persistedsession.metricsJSON). HTTP handlers validate the window and agent existence, then scope queries withcreated_byfrom the user context. OpenAPI/docs and SDK types include the new shapes; contract and HTTP tests cover scoping and validation.Reviewed by Cursor Bugbot for commit 5edc0f0. Bugbot is set up for automated code reviews on this repo. Configure here.