Add session metrics API and per-session totals - #484
Merged
Conversation
🦋 Changeset detectedLatest commit: ef62077 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 |
bhaveshpatel640
force-pushed
the
AGE-2011
branch
4 times, most recently
from
August 28, 2026 07:06
8d360cc to
21f140e
Compare
bhaveshpatel640
force-pushed
the
AGE-2011
branch
from
August 28, 2026 08:15
d00fc07 to
77f730d
Compare
bhaveshpatel640
marked this pull request as ready for review
August 28, 2026 09:16
bhaveshpatel640
requested review from
chiragjn,
debajyoti-truefoundry,
heerambavi1998,
sr07asthana and
thesujai
as code owners
August 28, 2026 09:16
bhaveshpatel640
force-pushed
the
AGE-2011
branch
2 times, most recently
from
August 28, 2026 09:30
a647804 to
4f7e36f
Compare
5 tasks
bhaveshpatel640
force-pushed
the
AGE-2011
branch
from
August 28, 2026 13:36
8d376b0 to
f3dacba
Compare
bhaveshpatel640
force-pushed
the
AGE-2011
branch
2 times, most recently
from
August 28, 2026 15:02
0b1d838 to
f7d6f9d
Compare
heerambavi1998
force-pushed
the
AGE-2011
branch
from
August 31, 2026 05:38
5edc0f0 to
d718c66
Compare
heerambavi1998
force-pushed
the
AGE-2011
branch
from
August 31, 2026 06:11
d718c66 to
c68a525
Compare
heerambavi1998
left a comment
Contributor
There was a problem hiding this comment.
We need tests specifically for the DB queries for both impl.
Surface empty/in-flight sessions in min/avg/median meters so anomalies are visible; drop the >0 filter and active_sessions denominator. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
sr07asthana
force-pushed
the
AGE-2011
branch
from
September 1, 2026 05:37
bc738de to
ef62077
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.
Reviewed by Cursor Bugbot for commit ef62077. Configure here.
Co-authored-by: Cursor <cursoragent@cursor.com>
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
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
Breaking API change requiring
metricson everySession, plus new aggregation paths over cost/duration data that must stay caller-scoped via auth.Overview
Adds caller-scoped session metrics for named agents: rolled-up
Session.metrics(cost, duration, turns) is now required on session API responses, and new authenticated/internal/metricsendpoints expose dashboard-style meters, a chart catalog, and zero-filled chart time series filtered byagent_id,created_by, and sessioncreated_at(hourly buckets ≤24h, daily otherwise; 30-day max window).Server wiring introduces
ISessionMetricsStorewith shared aggregation/chart builders and SQLite/Postgres query implementations; the SDK/OpenAPI gainclient.internal.metrics(listCharts,getChartData,getMeters) plus the new metrics types.Reviewed by Cursor Bugbot for commit 7f4e582. Bugbot is set up for automated code reviews on this repo. Configure here.