chore: forward session and agent details as metadata to gateway calls - #685
chore: forward session and agent details as metadata to gateway calls#685sr07asthana wants to merge 6 commits into
Conversation
…ateway calls Stamp tfg.session_id, turn_id, and agent fields onto model and MCP invoke headers when TrueFoundry mode is enabled, minting the turn id before the resolver so both paths share one metadata map. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
🦋 Changeset detectedLatest commit: 6debaf7 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 |
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 6debaf7. Configure here.
| return {}; | ||
| } | ||
| return { [X_TFY_METADATA]: JSON.stringify(metadata) }; | ||
| } |
There was a problem hiding this comment.
Non-ASCII metadata breaks gateway headers
Medium Severity
gatewayMetadataHeaders puts JSON.stringify output into x-tfy-metadata. Session metadata values may contain non-Latin-1 characters, and JSON.stringify does not escape them. Fetch/undici then rejects the header as a non-ByteString, so TrueFoundry-mode model and MCP calls fail for otherwise valid sessions.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 6debaf7. Configure here.


Summary
Closes #
Changes
How was this tested?
Checklist
pnpm build,pnpm test,pnpm typecheck,pnpm lint:ci, andpnpm format:checkpass locallypackages/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 changedNote
Low Risk
Behavior is gated on TrueFoundry mode and only adds outbound gateway headers without changing auth or session access controls.
Overview
When TrueFoundry mode is on, turn execution now attaches session, turn, and agent context to outbound model and MCP calls via a single
x-tfy-metadataheader (JSON string).Metadata is built from session
metadataplus harness keys under thetfg.*prefix (session_id,turn_id, and agent id/name for reference agents). Harness values override any caller-suppliedtfg.*keys in session metadata.The turn resolver takes the full
SessionHandleand a turn id minted beforecreateTurnso the same id appears in metadata and the persisted turn. MCP header merging useswithGatewayMetadataHeaders, which works for static and async header resolvers and skips metadata when the resolver returnsauthRequired.Unit tests cover metadata stamping and MCP header merge behavior; a patch changeset documents the release note.
Reviewed by Cursor Bugbot for commit 6debaf7. Bugbot is set up for automated code reviews on this repo. Configure here.