Skip to content

Persist session metrics JSON on Postgres and SQLite - #478

Merged
heerambavi1998 merged 1 commit into
mainfrom
AGE-2008
Aug 31, 2026
Merged

Persist session metrics JSON on Postgres and SQLite#478
heerambavi1998 merged 1 commit into
mainfrom
AGE-2008

Conversation

@bhaveshpatel640

@bhaveshpatel640 bhaveshpatel640 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Persist a zero-initialized metrics JSON document on agent sessions (total_cost_in_usd, total_duration_ms, total_turns).

Linear: AGE-2008

Public Session HTTP is unchanged (metrics stay store-only).

Changes

  • Add SessionMetrics / SessionRecord.metrics; createSession writes zeros (InMemory, Postgres, SQLite).
  • Postgres: session.metrics jsonb NOT NULL default + partial index (tenant_id, agent_id, created_at) for named-agent time windows.
  • SQLite: rebuild session (ADD COLUMN cannot take DEFAULT (jsonb(...))); same keys; parse metrics via JSON_RESULT_COLUMNS.
  • Store contract asserts create-time zeros. Patch changeset for trueforge-core + trueforge.

How was this tested?

  • Store contract: expect(session.metrics).toEqual({ total_cost_in_usd: 0, total_duration_ms: 0, total_turns: 0 }) (InMemory / Postgres / SQLite via existing store suites).
  • tsc --noEmit on @truefoundry/trueforge; eslint on Postgres + SQLite session query files.

Checklist

  • I have read the contributing guidelines
  • pnpm build, pnpm test, pnpm typecheck, pnpm lint:ci, and pnpm format:check pass locally
  • Tests added/updated where it makes sense
  • No hand-edits to generated code (packages/trueforge-sdk, .github/fern/openapi/openapi.json, docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge
  • Docs / .env.example updated if configuration or behavior changed

Note

Medium Risk
Schema migrations alter the session table (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 at createSession across InMemory, Postgres, and SQLite. The public Session HTTP contract is unchanged—metrics are not exposed on the API yet.

Core: New SessionMetricsSchema, SessionRecord.metrics, and exports from trueforge-core. Store contract tests assert create-time zeros.

Postgres: session.metrics jsonb NOT NULL with a JSON default; partial index session_agent_created_at_idx on (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); metrics included in JSON_RESULT_COLUMNS for 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.

@changeset-bot

changeset-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1fe8376

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@truefoundry/trueforge-core Patch
@truefoundry/trueforge Patch

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

cursor[bot]

This comment was marked as outdated.

@bhaveshpatel640
bhaveshpatel640 force-pushed the AGE-2008 branch 2 times, most recently from 27c49cf to d245de5 Compare August 28, 2026 08:15
@heerambavi1998

Copy link
Copy Markdown
Contributor

@bhaveshpatel640 where are we actually populating the values from? or is that a separate PR?

@bhaveshpatel640

bhaveshpatel640 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Where are we actually populating the values from? or is that a separate PR?

Please check this stack PR @heerambavi1998 #479, #484

@heerambavi1998
heerambavi1998 merged commit d89b2ff into main Aug 31, 2026
9 checks passed
@heerambavi1998
heerambavi1998 deleted the AGE-2008 branch August 31, 2026 06:11
@debajyoti-truefoundry

Copy link
Copy Markdown
Contributor

Where are we actually populating the values from? or is that a separate PR?

Please check this stack PR @heerambavi1998 #479, #484

@bhaveshpatel640 , @sr07asthana will be picking up the rest of the PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants