Repository navigation
chore: backfill tfg.source=ui metadata on existing interactive sessions - #1146
Merged
Merged
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
hary73
requested review from
chiragjn,
debajyoti-truefoundry,
heerambavi1998 and
thesujai
as code owners
October 22, 2026 13:25
🦋 Changeset detectedLatest commit: 85483e3 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>
chiragjn
approved these changes
Oct 22, 2026
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>
chiragjn
reviewed
Oct 23, 2026
…a key for index matching Co-authored-by: Cursor <cursoragent@cursor.com>
…story Co-authored-by: Cursor <cursoragent@cursor.com>
chiragjn
approved these changes
Oct 27, 2026
hary73
enabled auto-merge (squash)
October 28, 2026 05:13
hary73
disabled auto-merge
October 28, 2026 05:16
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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
20261028_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.20261028_000002_session_tfg_source_list_idx(Postgres + SQLite mirror):session (tenant_id, (created_by_subject->>'subject_id'), (metadata->>'tfg.source'), updated_at, session_id)— equality columns, then the keyset sort columns. Serves the Chat History list (created_by_me+metadata[tfg.source]=ui) in order without a sort or filtered rows. Tuned for the UI query; an index for metadata-free listing can be added later if needed.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.20261028_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
One-time, irreversible session metadata backfill must deploy with the Chat History filter change; mis-timing could hide sessions, though scope is limited to list metadata and indexing.
Overview
Adds a one-time data migration (Postgres + SQLite) that sets
metadata["tfg.source"] = "ui"on existing interactive sessions (sourceandexternal_idboth null, key not already set), merging into existing metadata and without bumpingupdated_at. Schedule-run and already-tagged sessions are skipped; the backfill migration is irreversible.Introduces
session_tfg_source_list_idxon(tenant_id, subject, tfg.source, updated_at, session_id)so Chat History-style lists (created_by_me+metadata[tfg.source]=ui) can keyset-scan in sort order. PostgreslistSessionsnow adds per-keymetadata->>'key' = valuepredicates alongside the existing@>filter (same rows) so the planner can use the new index; other metadata filters still rely on the GIN index.Ship with the release that filters Chat History on
tfg.source, or older UI sessions can disappear until this runs.Reviewed by Cursor Bugbot for commit 85483e3. Bugbot is set up for automated code reviews on this repo. Configure here.