Skip to content

chore: forward session and agent details as metadata to gateway calls - #685

Open
sr07asthana wants to merge 6 commits into
mainfrom
sr-AGE-2106
Open

chore: forward session and agent details as metadata to gateway calls#685
sr07asthana wants to merge 6 commits into
mainfrom
sr-AGE-2106

Conversation

@sr07asthana

@sr07asthana sr07asthana commented Sep 10, 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
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-metadata header (JSON string).

Metadata is built from session metadata plus harness keys under the tfg.* prefix (session_id, turn_id, and agent id/name for reference agents). Harness values override any caller-supplied tfg.* keys in session metadata.

The turn resolver takes the full SessionHandle and a turn id minted before createTurn so the same id appears in metadata and the persisted turn. MCP header merging uses withGatewayMetadataHeaders, which works for static and async header resolvers and skips metadata when the resolver returns authRequired.

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.

sr07asthana and others added 4 commits September 10, 2026 19:22
…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-bot

changeset-bot Bot commented Sep 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6debaf7

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

This PR includes changesets to release 1 package
Name Type
@truefoundry/trueforge 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

@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 6debaf7. Configure here.

return {};
}
return { [X_TFY_METADATA]: JSON.stringify(metadata) };
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6debaf7. 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