Uh oh!
There was an error while loading. Please reload this page.
Persist session metrics JSON on Postgres and SQLite - #478
Open
bhaveshpatel640 wants to merge 1 commit into
Open
Conversation
bhaveshpatel640
requested review from
chiragjn, debajyoti-truefoundry, heerambavi1998, sr07asthana and thesujai
as code ownersAugust 27, 2026 17:01
🦋 Changeset detectedLatest commit: d245de5 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 |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
heerambavi1998
commented
Aug 28, 2026
Contributor
@bhaveshpatel640 where are we actually populating the values from? or is that a separate PR? |
| title, | ||
| last_turn_id, | ||
| custom, | ||
| jsonb('{"total_cost_in_usd":0,"total_duration_ms":0,"total_turns":0}'), |
Contributor
There was a problem hiding this comment.
we are ok not backfilling metrics?
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 freeto 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 table rebuild) and add a new required column; behavior is additive with defaults, but deploy order and migration failure modes need the usual care.Overview
Adds store-layer
SessionMetrics(total_cost_in_usd,total_duration_ms,total_turns) onSessionRecord, initialized to zeros when a session is created across InMemory, Postgres, and SQLite. The publicSessionHTTP schema is unchanged—metrics are persistence-only for now.Postgres adds a NOT NULL
session.metricsjsonb column (DB default zeros) and a partial index on(tenant_id, agent_id, created_at)for named-agent time-window queries (e.g. futureGET /sessions/metrics). SQLite rebuildssessionto addmetricswith a jsonb default (ADD COLUMN limitation), registersmetricsfor JSON result parsing, and adds the same partial index.Store contract tests assert create-time zero metrics; patch changeset for
trueforge-coreandtrueforge.Reviewed by Cursor Bugbot for commit d245de5. Bugbot is set up for automated code reviews on this repo. Configure here.