Skip to content

feat: add filter to session metadata - #577

Closed
sr07asthana wants to merge 8 commits into
mainfrom
sr-add-metadata-filter-sessions
Closed

feat: add filter to session metadata#577
sr07asthana wants to merge 8 commits into
mainfrom
sr-add-metadata-filter-sessions

Conversation

@sr07asthana

@sr07asthana sr07asthana commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #

Changes

How was this tested?

Checklist

  • I have read the contributing guidelines
  • pnpm build, pnpm test, pnpm typecheck, pnpm lint:ci, and pnpm format:check pass locally
  • Tests added/updated where it makes sense
  • No hand-edits to generated code (packages/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

Low Risk
Additive read-path filtering with validated query input and a new Postgres GIN index; no changes to auth or session mutation behavior.

Overview
Adds an optional metadata query parameter on GET /api/v1/sessions (and the SDK sessions.list request) so callers can list only sessions whose stored metadata contains every supplied key/value pair (exact string match; extra session keys are allowed). The value is a JSON object string, validated with the same rules as session metadata; invalid JSON or oversize objects return 400.

The list handler passes the parsed filter into sessionStore.listSessions, which now accepts optional metadata on ListSessionsInput. In-memory, Postgres (metadata @>), and SQLite (json_each for literal key names) all implement the same containment semantics, including keys with dots, $, or brackets.

Postgres gets a new GIN index on session.metadata via migration 20260903_000002_session_metadata_gin. OpenAPI/SDK docs are updated, and store contract plus HTTP tests cover filtering, pagination with a fixed metadata filter, and query validation.

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

@changeset-bot

changeset-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 781659c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@truefoundry/trueforge Patch
@truefoundry/trueforge-core Patch
@truefoundry/trueforge-sdk Patch
@truefoundry/trueforge-ui 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

Comment thread packages/trueforge/src/db/sqlite/session-store/queries/sessions.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 32a1d3d. Configure here.

@sr07asthana
sr07asthana force-pushed the sr-add-metadata-filter-sessions branch from 55a50ee to 08e1ff1 Compare September 3, 2026 14:04
Comment thread docs/openapi.json
{
"description": "JSON object string. Matches sessions containing all pairs. Keep constant when paging.",
"in": "query",
"name": "metadata",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

metadata.abc = ? & metadata.xyz = ?
metadata.abc = ? || metadata.xyz = ?

sr07asthana and others added 2 commits September 4, 2026 12:23
Resolve listSessions conflicts by keeping created_by_subject_id from main and the metadata filter from this branch.

Co-authored-by: Cursor <cursoragent@cursor.com>
@sr07asthana
sr07asthana marked this pull request as draft September 4, 2026 07:13
@sr07asthana sr07asthana closed this Sep 4, 2026
@sr07asthana
sr07asthana deleted the sr-add-metadata-filter-sessions branch September 4, 2026 08:00
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