Repository navigation
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
🦋 Changeset detectedLatest commit: ee970ea The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Reviewed by Cursor Bugbot for commit 805ab35. Configure here.
Co-authored-by: Cursor <cursoragent@cursor.com>
| tenant_id, | ||
| (created_by_subject->>'subject_id'), | ||
| (metadata->>'tfg.source'), | ||
| updated_at, |
There was a problem hiding this comment.
- why do we have updated at? when listing sessions do we use updated_at or created_at
- Also it should be before
(metadata->>'tfg.source'), I expect people to query by time range always with optionally metadata filtering
There was a problem hiding this comment.
why do we have updated at? when listing sessions do we use updated_at or created_at
Yes, when listing we order by updated_at DESC
Also it should be before (metadata->>'tfg.source'), I expect people to query by time range always with optionally metadata filtering
the start / end params in the list API filter on created_at, not updated_at - so moving it up won't help for time range queries. We already have an index for supporting these queries session_list_idx (tenant_id, created_at, session_id)
But even if we don't supported range queries on updated_at, it makes sense to move updated_at above in the case where a user would just want to see their recent sessions. The current index performs better on the chat view for users which have a lot of scheduled sessions, but moving updated_at above will create a more generic index.
…a key for index matching Co-authored-by: Cursor <cursoragent@cursor.com>

Summary
Chat History is moving to listing only sessions stamped with
metadata["tfg.source"] = "ui"(#1118). Sessions created before that stamp would vanish from history, so this adds a one-time data migration that stamps every existing interactive session.Related: AGE-2528
Changes
20261022_000001_session_tfg_source_backfill(Postgres + SQLite mirror) that setstfg.source = uion sessions where:source IS NULL(not a schedule run), andexternal_id IS NULL(schedule runs are the only sessions with an external id; this also excludes schedule runs created before thesourcecolumn existed), andis_create_agent) is preserved;updated_atis not touched, so list ordering is unchanged.20261022_000002_session_tfg_source_list_idx(Postgres + SQLite mirror):session (tenant_id, (created_by_subject->>'subject_id'), updated_at, session_id, (metadata->>'tfg.source')). Serves a caller's newest-first listing (keyset onupdated_at, session_id) without a sort, with or without thetfg.sourcefilter; the filter is checked on index entries without visiting the table.listSessionsnow addsmetadata->>key = valueper metadata filter pair next to the existingmetadata @> …. Values are strings, so results are unchanged; it lets the planner use per-key expression indexes, which@>alone cannot. Other keys still usesession_metadata_gin. The key is inlined as a literal (sql.lit; keys are validated to[A-Za-z0-9._:-]) because expression indexes only match a literal key, not a bound parameter under generic plans.down(backfill) is irreversible, matching the other data backfills: backfilled rows are indistinguishable from UI-stamped ones.Rollout note
This must ship in the same release as (or after) #1118, which switches the stamp/filter key to
tfg.source. Sessions created between this migration running and the UI starting to stamp would otherwise be hidden from Chat History.How was this tested?
Manually, end to end on Postgres 17:
main(no backfill) and created: an inline New Chat session, a builder session (is_create_agent: true), a named Try-agent session, an SDK-style session with custom metadata (foo: bar), a session already carryingtfg.source: other, a session withexternal_idbut nosource(pre-sourceschedule run), and two schedule sessions via Run now.20261022_000001_session_tfg_source_backfillran.tfg.source: ui, keeping their existing keys.tfg.source: otherwas left as is.external_id-only session were left untouched.updated_atunchanged on every row.GET /sessions?created_by_me=true&metadata[tfg.source]=ui(the Chat History query) returns exactly the four interactive sessions; the unfiltered list still returns all sessions.Index check (Postgres 17, 200k seeded sessions, 50 users, ~1/3 tagged
ui):PostgresSessionStore.listSessions(captured viaauto_explain) usesIndex Scan Backward using session_tfg_source_list_idx, no sort, ~0.2 ms per page; pages are disjoint and allui.session_metadata_gin.Note
Medium Risk
Irreversible bulk UPDATE on
sessionmust deploy in step with the Chat History filter change; mis-timed rollout could hide sessions from history.Overview
Prepares for Chat History filtering on
metadata["tfg.source"] = "ui"by backfilling that key on legacy interactive sessions and speeding up the filtered list query on Postgres.A one-time migration (Postgres + SQLite) merges
tfg.source: uiintosession.metadatafor rows with nosource, noexternal_id, and no existingtfg.source, without changingupdated_ator overwriting other metadata. The backfilldownis intentionally irreversible.A new composite index
session_tfg_source_list_idx(mirrored on SQLite for schema parity) supports per-user session lists in keyset order with optionaltfg.sourcefiltering. PostgreslistSessionsnow adds redundantmetadata->>'key' = valuepredicates alongsidemetadata @>so the planner can use expression indexes like the new one while other metadata keys still hitsession_metadata_gin.Reviewed by Cursor Bugbot for commit ee970ea. Bugbot is set up for automated code reviews on this repo. Configure here.