Skip to content

feat: add session metadata filter - #591

Open
sr07asthana wants to merge 6 commits into
mainfrom
sr-session-metadata-filter
Open

feat: add session metadata filter#591
sr07asthana wants to merge 6 commits into
mainfrom
sr-session-metadata-filter

Conversation

@sr07asthana

@sr07asthana sr07asthana commented Sep 4, 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

Medium Risk
Adds a new list API filter and query parsing surface, plus a Postgres GIN migration; behavior is covered by tests but affects session listing for all tenants.

Overview
List sessions now accepts optional metadata[key]=value filters (OpenAPI deepObject). Sessions must contain all specified key/value pairs (exact match; extra metadata on the session is allowed). The list handler parses Hono’s flat query keys via foldListSessionsMetadataQuery / parseListSessionsQuery, with validation caps (e.g. max 10 filter keys) and rejection of bare metadata=, nested brackets, and duplicate keys.

Session metadata keys are tightened with a regex so keys cannot include [] or whitespace—aligned with deepObject query encoding and reserved nested forms. Create-session validation tests cover invalid charset keys.

Persistence: listSessions gains an optional metadata filter on the store contract; in-memory, Postgres (metadata @> + new GIN index migration), and SQLite (json_each) all implement containment filtering. SDK/OpenAPI/Fern docs and generated client pass metadata on sessions.list(); Fern object-query-parameters is enabled for this shape.

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

@changeset-bot

changeset-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 14561cf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

* (exact string equality; extra session keys are allowed). `undefined` or `{}`
* means no metadata filter.
*/
metadata: SessionMetadata | undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Metadata filter lacks contract tests

Medium Severity

listSessions now filters on metadata, but storeContractSuite.ts only threads metadata: undefined through existing cases. Postgres uses @>, SQLite uses json_each on a JSONB blob, and in-memory uses JS equality. Shared filter invariants belong in the contract suite so those backends cannot silently diverge.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: @truefoundry/trueforge-core review rules

Reviewed by Cursor Bugbot for commit dff7976. Configure here.

.string()
.min(1)
.max(SESSION_METADATA_MAX_KEY_LENGTH)
.regex(SESSION_METADATA_KEY_PATTERN)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stricter metadata keys break reads

Medium Severity

SessionMetadataSchema now rejects keys that are not alphanumeric plus . _ : -. The same schema parses persisted session.metadata on read. Existing rows with previously valid keys (spaces, slashes, leading _) will fail get/list with no data rewrite.

Additional Locations (2)
Fix in Cursor Fix in Web

Triggered by project rule: @truefoundry/trueforge review rules

Reviewed by Cursor Bugbot for commit dff7976. Configure here.

Comment thread packages/trueforge/src/schemas/session.ts
* (exact string equality; extra session keys are allowed). `undefined` or `{}`
* means no metadata filter.
*/
metadata: SessionMetadata | undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Published packages missing changeset

Low Severity

This PR changes shipped packages @truefoundry/trueforge-core and @truefoundry/trueforge and does not add a .changeset/*.md file. Existing session-metadata.md covers the earlier metadata column, not this list filter. Run pnpm changeset for those two packages.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: TrueForge review rules

Reviewed by Cursor Bugbot for commit dff7976. Configure here.

@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.

There are 4 total unresolved issues (including 3 from previous reviews).

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 14561cf. Configure here.

start_timestamp: startTimestamp != null ? startTimestamp?.toISOString() : undefined,
end_timestamp: endTimestamp != null ? endTimestamp?.toISOString() : undefined,
agent_id: agentId,
metadata: metadata != null ? toJson(metadata) : undefined,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SDK metadata filter serializes JSON

High Severity

sessions.list JSON-stringifies metadata into a bare metadata query param. The server only accepts metadata[key]=value and rejects that form, so SDK callers who pass metadata get an error instead of filtered sessions.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 14561cf. Configure here.

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.

1 participant