Persist session metrics JSON on Postgres and SQLite - #478
Merged
Conversation
bhaveshpatel640
requested review from
chiragjn,
debajyoti-truefoundry,
heerambavi1998,
sr07asthana and
thesujai
as code owners
August 27, 2026 17:01
🦋 Changeset detectedLatest commit: 1fe8376 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-2008
branch
from
August 27, 2026 17:04
47d7397 to
637cdc7
Compare
bhaveshpatel640
force-pushed
the
AGE-2008
branch
2 times, most recently
from
August 28, 2026 08:15
27c49cf to
d245de5
Compare
Contributor
|
@bhaveshpatel640 where are we actually populating the values from? or is that a separate PR? |
Contributor
Author
Please check this stack PR @heerambavi1998 #479, #484 |
heerambavi1998
force-pushed
the
AGE-2008
branch
from
August 31, 2026 05:38
d245de5 to
1fe8376
Compare
heerambavi1998
approved these changes
Aug 31, 2026
Contributor
@bhaveshpatel640 , @sr07asthana will be picking up the rest of the PRs. |
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
Persist a zero-initialized
metricsJSON document on agent sessions (total_cost_in_usd,total_duration_ms,total_turns).Linear: AGE-2008
Public
SessionHTTP is unchanged (metrics stay store-only).Changes
SessionMetrics/SessionRecord.metrics;createSessionwrites zeros (InMemory, Postgres, SQLite).session.metrics jsonb NOT NULLdefault + partial index(tenant_id, agent_id, created_at)for named-agent time windows.session(ADD COLUMN cannot takeDEFAULT (jsonb(...))); same keys; parsemetricsviaJSON_RESULT_COLUMNS.trueforge-core+trueforge.How was this tested?
expect(session.metrics).toEqual({ total_cost_in_usd: 0, total_duration_ms: 0, total_turns: 0 })(InMemory / Postgres / SQLite via existing store suites).tsc --noEmiton@truefoundry/trueforge; eslint on Postgres + SQLite session query files.Checklist
pnpm build,pnpm test,pnpm typecheck,pnpm lint:ci, andpnpm format:checkpass locallypackages/trueforge-sdk,.github/fern/openapi/openapi.json,docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge.env.exampleupdated if configuration or behavior changedNote
Medium Risk
Schema migrations alter the
sessiontable (SQLite full rebuild); low runtime behavior change today but migration failure or lock timeout could affect deploys.Overview
Adds store-level
SessionMetrics(total_cost_in_usd,total_duration_ms,total_turns) on agent sessions, initialized to zero atcreateSessionacross InMemory, Postgres, and SQLite. The publicSessionHTTP contract is unchanged—metrics are not exposed on the API yet.Core: New
SessionMetricsSchema,SessionRecord.metrics, and exports fromtrueforge-core. Store contract tests assert create-time zeros.Postgres:
session.metricsjsonb NOT NULLwith a JSON default; partial indexsession_agent_created_at_idxon(tenant_id, agent_id, created_at)for future named-agent time-window queries (e.g.GET /sessions/metrics).SQLite: Table rebuild (expression defaults on JSON columns);
metricsincluded inJSON_RESULT_COLUMNSfor read parsing; same index as Postgres.No turn-completion logic updates these fields in this PR—only persistence and schema wiring.
Reviewed by Cursor Bugbot for commit 1fe8376. Bugbot is set up for automated code reviews on this repo. Configure here.