Repository navigation
feat(mcp): group Claude, Cursor and OpenAI hosted connector sessions by their conversation ids - #401
Conversation
There was a problem hiding this comment.
PostHog Review · Standard · reviewed a58f785: 1 Should fix.
New pushes to this pull request won't start an automatic review. Comment @posthog review to review new changes.
See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.
posthog-ruby-async Compliance ReportDate: 2026-11-29T16:13:09.890616+00:00 ✅ All Tests Passed!47/47 tests passed Capture Tests✅ 30/30 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
posthog-ruby-sync Compliance ReportDate: 2026-11-29T16:12:58.961640+00:00 ✅ All Tests Passed!47/47 tests passed Capture Tests✅ 30/30 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
SDK performance: posthog-rubyBenchmarks completed. No changes flagged for review. Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate. View all results
Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals. Each shard uses its own runner; compare Before PR against With PR within a row, not across shards. Compared 102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in |
|
@PostHog review |
|
@lucasheriques PostHog Review is reviewing this pull request. |
…by their conversation ids Adds three rows to ClientConversation::ROWS, in table order: - `openai/session` for any `openai-mcp/` User-Agent (after the ChatGPT row, so `openai-mcp/1.0.0 (Codex)` lands here), not handle-free - `com.anthropic/session` for `Claude-User` / `claude-code/` or client names `Anthropic/ClaudeAI` / `claude-code`, printable string, not handle-free - `gen_ai.conversation.id` for `Cursor/` or client names `Cursor` / `cursor-vscode`, printable string, not handle-free Servers listed in client directories must turn off the injected conversation_id, so these clients' sessions survive only if we read their own id. Tested: client_conversation_spec is one parameterized spec covering recognition (row 2 vs row 1 via handle_free) and a read vector per new row; client_session_spec's "sends no conversation id in any property" table gains the three clients and fails without the rows. `bundle exec rspec` 2696 examples, 0 failures; `bundle exec rubocop` clean.
…ly the selected row's A Codex client behind an openai-mcp UA matches both the hosted-connector row and the Codex row. Session selection stays first-match, but drop_client_conversation_key now strips the keys of all matching rows so a Codex sessionId never reaches callbacks or $mcp_parameters. Tested: new parameterized case 'Codex behind a hosted connector' failed before the fix and passes; bundle exec rspec spec/posthog/mcp: 290 examples, 0 failures; rubocop clean.
30827ad to
2927a47
Compare
|
@PostHog review |
|
@lucasheriques PostHog Review is reviewing this pull request. |
There was a problem hiding this comment.
Approved.
Risky analytics and identifier-redaction changes have independent assurance from a current-head review and a STRONG-familiarity author. The current code addresses overlapping-client redaction, and no substantive unresolved concerns or other refusal grounds are evident.
- Author wrote 100% of the modified lines and has 11 merged PRs in these paths (familiarity STRONG).
- PostHog Review (Standard) reviewed the current head: no findings.
- posthog[bot] reviewed the current head.
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| every_file_attested | ✓ | not a bot PR |
| size | ✓ | 24L, 2F substantive, 87L/5F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1d-complex (87L, 5F, cross-cutting, feat) |
| stamphog 2.9.1 | .stamphog/policy.yml @ 2927a47 · reviewed head 2927a47 |
💡 Motivation and Context
MCP servers listed in the ChatGPT and Claude directories have to turn off the injected
conversation_id, so their sessions survive only if the SDK reads the client's own conversation id. Claude, Cursor and OpenAI's hosted connector all send one in_meta, andPostHog::MCPignored all three.On PostHog's own MCP server (24h to 2026-11-28):
openai-mcp/1.0.0sendsopenai/sessionon 100% of calls but missed the ChatGPT-only rule; Claude.ai sendscom.anthropic/sessionon 92% of calls and Claude Code on 39%; Cursor sendsgen_ai.conversation.idon 99.8%.Extends the table #386 added.
What changed
Three rows in
ClientConversation::ROWS. Order matters, because the first row that recognizes the client wins:_metakeyopenai/sessionUser-Agent(existing)openai/sessionUser-Agentstartingopenai-mcp/, e.g.openai-mcp/1.0.0 (Codex)sessionIdvscode.conversationIdcom.anthropic/sessionUser-AgentClaude-Useror startingclaude-code/; client nameAnthropic/ClaudeAIorclaude-codegen_ai.conversation.idUser-AgentstartingCursor/; client nameCursororcursor-vscode"Printable" is row 1's rule: 1 to 128 characters of printable ASCII.
$session_idcomes from<key>:<id>as before, and the key is dropped from$mcp_parametersand from the request the callbacks receive. None of the new rows is handle-free, so a call that sends no id still gets the conversation-handle fallback.Divergence from the spec
The sdk-specs table does not have these rows yet. A parallel sdk-specs PR adds them, and this PR will follow its vectors if they differ.
💚 How did you test it?
spec/posthog/mcp/client_conversation_spec.rbis one parameterized spec: recognition for every row (includingopenai-mcp/1.0.0 (Codex)with a Codex client name landing on row 2, not row 3) and a read vector per new row. The new examples failed before the rows existed.spec/posthog/mcp/client_session_spec.rb: the "sends no conversation id in any property" table, which runs through the real Streamable HTTP transport, gains the three clients. Those three failed before the rows existed, because the ids reached$mcp_parameters.bundle exec rspec: 2699 examples, 0 failures.bundle exec rubocop: no offenses.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Written with Claude Code (poteto-mode), as one of several parallel sessions adding the same rows to the spec, the PostHog MCP server, and the JS, Python, Go and Rust SDKs. Written test-first. The pre-PR gate ran two adversarial reviewers (Opus and Sonnet) over the Parity, Completeness, Exposure and Upgrade lenses.
Claude-Useris an exactUser-Agentmatch, so a longer agent string that only starts with it is not recognized. Rows 2, 5 and 6 reuse row 1's printable-string rule instead of adding new shapes.The gate's reviewers turned up three things:
User-Agent: openai-mcp/1.0.0 (Codex)and client namecodex-mcp-clientmatches rows 2 and 3, and the session comes from row 2, the first match. That follows the specified row order, andopenai-mcp/traffic sendsopenai/sessionon every call we see. The second commit strips the_metakey of every row the client matches, not only the selected row's, so asessionIdsent this way no longer reaches$mcp_parametersor the callbacks.