Skip to content

feat: add agent sesison migrate endpoint - #487

Open
thesujai wants to merge 5 commits into
mainfrom
feat/agent-session-migrate
Open

feat: add agent sesison migrate endpoint#487
thesujai wants to merge 5 commits into
mainfrom
feat/agent-session-migrate

Conversation

@thesujai

@thesujaithesujai commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

add agent sesison migrate

Closes #NA

Changes

add agent sesison migrate

How was this tested?

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
Admin-gated but can bulk-write production session data; incorrect snapshots could corrupt history, though normal session runtime paths are unchanged.

Overview
Adds an ops/backfill admin API to import a single historical agent session (session row, turns, threads, context logs, capability state, and events) into Postgres in one transaction.

POST/api/v1/settings/sessions/import is mounted under the existing settings admin surface (withAdminAuth). The body is a loose Zod-validated snapshot (session + at least one turn). If session_id already exists, the handler returns 200 with imported: false; on a successful insert it returns 201 with imported: true. Standalone/SQLite deployments wire sessionSnapshotImporter as undefined and respond with 501.

Implementation is PostgresSessionSnapshotImporter, which uses ON CONFLICT DO NOTHING on the session row and rebuilds per-thread context_ids with append-only deduplication via isContextPrefix. OpenAPI docs and a changeset are included; the route is marked x-fern-ignore (not SDK-published).

Reviewed by Cursor Bugbot for commit 11510b8. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-botBot commented Aug 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 11510b8

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

This PR includes changesets to release 1 package
NameType
@truefoundry/trueforgePatch

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

Comment threadpackages/trueforge/src/db/sessionSnapshotImport.ts Outdated
Comment threadpackages/trueforge/src/db/sessionSnapshotImport.ts
Comment threadpackages/trueforge/src/db/postgres/session-store/importSessionSnapshot.ts Outdated
)
.execute();
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per-row queries inside import loops

Low Severity

The import issues a separate insert for every turn, thread, context batch, capability map, and event list. That is an N+1 write pattern inside one transaction instead of batched inserts.

Fix in CursorFix in Web

Triggered by project rule: @truefoundry/trueforge review rules

Reviewed by Cursor Bugbot for commit 0817072. Configure here.

Comment threadpackages/trueforge/src/db/postgres/session-store/importSessionSnapshot.ts Outdated

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

There are 3 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f7dc19a. Configure here.

Comment threadpackages/trueforge/src/db/postgres/sqlExpressions.ts Outdated
Comment threadpackages/trueforge/src/schemas/sessionImport.ts Outdated
Sign up for freeto 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.

1 participant

@thesujai