Repository navigation
Conversation
🦋 Changeset detectedLatest commit: fa50563 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 |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fff93ee. Configure here.
…AGE-2315) Co-authored-by: Cursor <cursoragent@cursor.com>
fff93ee to
fa50563
Compare
9815307 to
fa50563
Compare
| /** | ||
| * Id and status of the last turn; null until the first turn. Replaced whole on | ||
| * createTurn and on that turn's status changes, never patched per key. | ||
| */ |
There was a problem hiding this comment.
remove comment, not needed
| @@ -36,6 +42,11 @@ export interface SessionRecord<TCustom extends object = Record<string, never>> { | |||
| * listing anchors. Advanced only by `createTurn` (atomic link). | |||
| */ | |||
| last_turn_id: string | null; | |||
There was a problem hiding this comment.
are we not removing this?
| export const SessionLastTurnDetailsSchema = z | ||
| .object({ | ||
| id: z.string().min(1), | ||
| status: TurnStatusSchema, |
There was a problem hiding this comment.
do we need all fields in status?
| @@ -0,0 +1,88 @@ | |||
| import { sql } from 'kysely'; | |||
There was a problem hiding this comment.
we don't need tests for this migration if this has been tested manually. These tests are kinda not useful later.
| await addSessionCostAndDuration(trx, { | ||
| session_id: input.session_id, | ||
| turn_created_at: new Date(result.created_at), | ||
| turn_state: input.state, | ||
| }); | ||
| await updateLastTurnDetails(trx, input); |
There was a problem hiding this comment.
looks like these always happen together. Lets have a single store method for these

Summary
Adds a nullable
last_turn_detailsJSON column onsessionholding{ id, status }for the session's last turn, so the agent sessions page can show session status from the last turn (AGE-2315). Backend only: the publicSessionDTO and UI are unchanged in this PR.Changes
TurnStatusSchemainschemas/turn.tsis now the single source of turn status literals; eachTurnStatearm uses it (OpenAPI output unchanged).SessionLastTurnDetailsSchema({ id, status }) inschemas/session.ts;SessionRecord.last_turn_details: SessionLastTurnDetails | null.createTurnsetslast_turn_idandlast_turn_detailsin the same sessionUPDATE.updateTurnNonTerminalState,updateTurnTerminalState, and the winningfreezeAndGetTurnupdate it in the same transaction as the turn, onlyWHERE last_turn_details.id = <turn>. A turn that is no longer the last turn (e.g. a new root turn started while it was running) cannot overwrite the newer turn's document.JSON_RESULT_COLUMNS.20261018_000001_session_last_turn_details(Postgres + SQLite): add the column, backfill from the turnlast_turn_idpoints at; sessions without a matching turn stay null.The guard reads the JSON id rather than
last_turn_id, so a follow-up can droplast_turn_idafter moving its remaining readers (createTurn's row lock read, the event-listing anchor,previous_turn_id: 'auto',cancelSession).How was this tested?
last_turn_detailsblock instoreContractSuite: null before first turn, create, pause/resume/terminal, freeze (incl. repeat), and a superseded turn not touching the newer last turn. Passes on in-memory, SQLite, and Postgres (scripts/test-store-local.sh).pnpm test:trueforge-coreandpnpm test:trueforgepass; typecheck, lint, format, andcheck-migration-order.shpass.Checklist
@truefoundry/trueforgeand@truefoundry/trueforge-coreMade with Cursor
Note
Medium Risk
Touches session persistence and migrations across Postgres/SQLite with concurrent turn updates; behavior is guarded and tested but wrong writes could desync session tip status from turns.
Reviewed by Cursor Bugbot for commit fa50563. Bugbot is set up for automated code reviews on this repo. Configure here.