Skip to content

feat(agent): forward ai_session_id run-state key to gateway properties - #4011

Closed
sortafreel wants to merge 1 commit into
mainfrom
posthog-code/agent-ai-session-id
Closed

feat(agent): forward ai_session_id run-state key to gateway properties#4011
sortafreel wants to merge 1 commit into
mainfrom
posthog-code/agent-ai-session-id

Conversation

@sortafreel

Copy link
Copy Markdown
Contributor

Problem

Run generations reach the gateway with task-level attribution only (task_id, ai_stage, …) — there's no key grouping the generations of one logical operation. ReviewHog now stashes ai_session_id in run state (one per review turn, PostHog/posthog#75592), but the agent-server doesn't forward it.

Changes

Forward the ai_session_id run-state key into the gateway properties in configureEnvironment, next to ai_stage. Transported unreserved — $-keys are stripped at gateway header boundaries — and promoted to the native $ai_session_id by the llm-gateway at capture. Null-safe: runs without the state key emit no header, so merge order with the companion PR is free.

How did you test this?

Extended the configureEnvironment tests: both the header-record (codex) and header-lines (Claude) paths now assert the forwarded x-posthog-property-ai_session_id. Authored in a sandboxed environment — typecheck and test run via CI.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code

Products that stash ai_session_id in run state (ReviewHog stamps one per review turn) get it lifted onto their runs' $ai_generation events, grouping a logical operation's generations. Transported unreserved — $-keys are stripped at gateway header boundaries — and promoted to the native $ai_session_id by the llm-gateway at capture. Null-safe: runs without the state key emit no header.

Generated-By: PostHog Code
Task-Id: 77db6432-21d6-400a-ad79-7ce81def58cf
@trunk-io

trunk-io Bot commented Jul 30, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 8c99efa.

@sortafreel sortafreel closed this Jul 30, 2026
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