Add session metrics API and per-session totals - #484
Open
bhaveshpatel640 wants to merge 2 commits into
Open
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 |
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
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.
bhaveshpatel640
force-pushed
the
AGE-2011
branch
from
August 28, 2026 14:49
98e2416 to
109c336
Compare
bhaveshpatel640
force-pushed
the
AGE-2011
branch
from
August 28, 2026 15:02
0b1d838 to
f7d6f9d
Compare
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
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.