Repository navigation
[AGE-2759] Add a partial session_event index for feature-signal event types - #1337
Merged
Merged
Conversation
… types Analytics feature adoption reads only sandbox.created, model.message, and thread.created events per session. Without an index it parses every event payload to check its type. IF NOT EXISTS lets large deployments pre-create the index CONCURRENTLY, since the migration's transactional build blocks event inserts while it runs.
rutvij-menavlikar
requested review from
chiragjn,
debajyoti-truefoundry,
heerambavi1998 and
thesujai
as code owners
November 11, 2026 09:57
🦋 Changeset detectedLatest commit: 5a0d90e 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>
…and thread.created model.message is no longer read by its consumer, so it is dropped from the index predicate. The remaining types are a small fraction of events.
Replace the partial index on two event types with an expression index on event->>'type', so any query filtering events by type can use it.
heerambavi1998
approved these changes
Nov 11, 2026
heerambavi1998
enabled auto-merge (squash)
November 11, 2026 12:04
truefoundry-saas
added a commit
that referenced
this pull request
Nov 11, 2026
* [AGE-2759] Add a partial session_event index for feature-signal event types (#1337) * refactor: update SERVER_URL handling in controller configuration (#1345) * refactor: update SERVER_URL handling in controller configuration * refactor: simplify comments for SERVER_URL in controller configuration
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
Per-session lookups that filter on
sandbox.created,model.message, andthread.createdevents currently have to read and parse the payload of every event in the session to check its type. This PR adds a partial index onsession_event (session_id)restricted to those three event types, so those lookups touch only the relevant rows.The migration uses
IF NOT EXISTS, so large deployments can pre-create the index withCREATE INDEX CONCURRENTLYbefore migrating. The in-migration build is transactional and blocks event inserts while it runs.Linear: AGE-2759
Changes
SESSION_EVENT_FEATURE_TYPE_IDX(session_event_feature_type_idx) topackages/trueforge/src/db/indexes.ts.20261111_000003_session_event_feature_type_idx.ts:upcreates the partial indexON session_event (session_id) WHERE event->>'type' IN ('sandbox.created', 'model.message', 'thread.created')usingIF NOT EXISTS.downdrops it withIF EXISTS.lock_timeout = '5s'(SET LOCAL) so the migration fails fast instead of queueing behind long locks.@truefoundry/trueforge.Risk / rollout
session_eventis a high-write table. For large deployments, pre-create the indexCONCURRENTLYbefore running the migration, which then becomes a no-op. Rollback is a plainDROP INDEX.How was this tested?
Checklist
pnpm build,pnpm test,pnpm typecheck,pnpm lint:ci, andpnpm format:checkpass locallypackages/trueforge-sdk,python/trueforge_sdk,.github/fern/openapi/openapi.json,docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge.env.exampleupdated if configuration or behavior changed (N/A: no config or behavior docs affected)Note
Medium Risk
Index creation on the high-write
session_eventtable can block inserts during migration unless the index is pre-builtCONCURRENTLY; rollout behavior is unchanged after the index exists.Overview
Adds a Postgres expression index on
session_eventforevent->>'type', so filters on event type can use the index instead of parsing every JSON payload on scan.Introduces
SESSION_EVENT_TYPE_IDXand migration20261111_000003_session_event_type_idx(CREATE INDEX IF NOT EXISTS/DROP INDEX IF EXISTS) withSET LOCAL lock_timeout = '5s'so migrations fail fast under lock contention. Large deployments can pre-create the index withCONCURRENTLYso the migration is a no-op. Includes a patch changeset for@truefoundry/trueforge.Reviewed by Cursor Bugbot for commit 5a0d90e. Bugbot is set up for automated code reviews on this repo. Configure here.