Skip to content

refactor: drop redundant session.last_turn_id in favor of last_turn_details (AGE-2584) - #1128

Merged
hary73 merged 2 commits into
mainfrom
hary/cleanup-turn-id
Oct 27, 2026
Merged

hary73 merged 2 commits into
mainfrom
hary/cleanup-turn-id

Conversation

@hary73

@hary73 hary73 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Sessions now carry last_turn_details ({ id, state: { status } }), which makes the session.last_turn_id column redundant. This PR removes it and reads the session tip from last_turn_details.id everywhere.

Linear: AGE-2584

Changes

  • SessionRecord drops last_turn_id; previous_turn_id: 'auto' resolution, cancel-turn, first-turn title derivation, and the default listSessionEvents anchor now use last_turn_details.id.
  • In-memory, Postgres, and SQLite createTurn stop writing last_turn_id; the column is removed from the DB types and the SQLite select list.
  • New migration 20261022_000001_drop_session_last_turn_id (Postgres + SQLite) drops the column; down re-adds and backfills it from last_turn_details.id.
  • Unchanged: the last_turn_id query param and page-token field on list-events (they're the listing anchor, not the column), so no API/SDK change.
  • Patch changeset for @truefoundry/trueforge-core and @truefoundry/trueforge.

Deploy note: the column is dropped in the same release that stops using it. During a rolling deploy, old pods still select last_turn_id and will fail on session reads once the migration runs. If that window matters, we can split the migration into a follow-up release.

How was this tested?

  • pnpm typecheck, pnpm format:check, ESLint on changed files
  • pnpm test:trueforge-core, pnpm test:trueforge
  • pnpm test:store:local (Postgres 17 + SQLite store contract suites, including migrations)

Checklist

  • I have read the contributing guidelines
  • pnpm build, pnpm test, pnpm typecheck, pnpm lint:ci, and pnpm format:check pass locally (typecheck, format, and the suites above were run; full build/lint left to CI)
  • Tests added/updated where it makes sense
  • No hand-edits to generated code (packages/trueforge-sdk, python/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 migration plus session-tip reads/writes across stores and APIs; rolling deploy can break old binaries that still SELECT last_turn_id after the migration runs.

Overview
Removes the redundant session.last_turn_id column and treats last_turn_details.id as the single source of truth for the session tip.

SessionRecord no longer exposes last_turn_id. previous_turn_id: 'auto', cancel-current-turn, first-turn title derivation, and the default listSessionEvents anchor now read last_turn_details?.id (or null/undefined when there is no tip). In-memory, Postgres, and SQLite createTurn only advance last_turn_details; session mappers and DB types drop the column.

Adds migration 20261022_000001_drop_session_last_turn_id for Postgres and SQLite (with down that re-adds and backfills from last_turn_details.id). Patch changeset for @truefoundry/trueforge-core and @truefoundry/trueforge.

Unchanged: listSessionEvents still accepts a last_turn_id query param and encodes it in page tokens—that name refers to the listing anchor, not the removed column, so wire/API shape is unchanged.

Deploy note: dropping the column in the same release as code that stops selecting it can break older pods during a rolling deploy if the migration runs first.

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

…etails (AGE-2584)

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8e4c4ef

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

@chiragjn chiragjn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please make sure we roll this out in next release once all writes to this field will stop completely - even from older live pods.
We do not want turn creation to break during rollout phase

@hary73
hary73 marked this pull request as ready for review October 22, 2026 11:06
@hary73

hary73 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Please make sure we roll this out in next release once all writes to this field will stop completely - even from older live pods. We do not want turn creation to break during rollout phase

Sure, will ensure this goes in the next release

@hary73
hary73 merged commit 7b325d9 into main Oct 27, 2026
17 checks passed
@hary73
hary73 deleted the hary/cleanup-turn-id branch October 27, 2026 10:35
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.

2 participants