Repository navigation
fix(mcp): give every manual capture a $session_id and read client conversation ids - #392
lucasheriques wants to merge 4 commits into
Conversation
…versation ids sdk-specs "Manual capture", lower-level method: a $session_id the caller passes is sent unchanged unless a client conversation id applies; without one, each call gets a fresh ses_<UUIDv7>. A client conversation id applies when the caller passes the request's `_meta` with the User-Agent or client name that recognizes its client. - PostHog::MCP::Client's capture_* methods fill a missing session with a fresh generated one (so distinct_id falls back to it, not "anonymous") and set $mcp_session_source. - capture_tool_call takes request_meta: and client_name:. The three-step manual API (list, call, result) the spec also asks for is not in this PR: it is a new public API and needs its own design. Tested: bundle exec rspec (2652 examples, 0 failures; 12 new client_spec examples failed first), rubocop clean, rake public_api:check passes with the regenerated snapshot.
…ases /simplify on the stack: base_event chooses the session and its source in one place, and the VS Code client-name case joins the parameterized recognition table. Tested: bundle exec rspec spec/posthog/mcp (280 examples, 0 failures).
…ability Pre-PR gate: sdk-specs "Optional events" says the report events never carry $mcp_parameters; the automatic path already dropped them. The keyword stays accepted, so existing callers keep working. Tested: bundle exec rspec (no failures; the new client_spec expectation failed first), rubocop clean, rake public_api:check passes.
|
@PostHog review |
|
@lucasheriques PostHog Review is reviewing this pull request. |
posthog-ruby-sync Compliance ReportDate: 2026-11-25T19:43:39.064993+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-async Compliance ReportDate: 2026-11-25T19:43:38.836333+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
|
There was a problem hiding this comment.
PostHog Review · Standard · reviewed f25d417: 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.
…its encoding PostHog Review on f25d417: ClientConversation.recognize raised ArgumentError from Regexp#match? on a User-Agent with invalid UTF-8, and the manual capture_tool_call calls it outside the sink's rescue, so the error reached the host's dispatcher. Such a value now recognizes no client. Tested: bundle exec rspec spec/posthog/mcp (283 examples, 0 failures; the new client_spec example failed without the fix).
|
@PostHog review |
|
@lucasheriques PostHog Review is reviewing this pull request. |
There was a problem hiding this comment.
Not approved — this change needs a human reviewer.
Adding the stamphog label gives the same result unless the changed files change.
stamphog can't auto-approve this pull request because the deny-list gate matched the public API surface: public_api_snapshot.txt changed, and the change adds request_meta: and client_name: to capture_tool_call. Because of that match, the tier gate also placed the PR in the never-auto-approve tier. The size gate passed, so size isn't the issue.
Please ask a human reviewer to look at it. Since public API changes always need that review, no change to the diff will alter this outcome.
- posthog[bot] reviewed the current head.
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✗ | matches: public_api in public_api_snapshot.txt |
| every_file_attested | ✓ | not a bot PR |
| size | ✓ | 39L, 2F substantive, 115L/5F incl. docs/generated/snapshots — within ceiling |
| tier | ✗ | T2-never because the deny-list matched public_api |
| stamphog 2.9.1 | .stamphog/policy.yml @ unknown · reviewed head e5b5af6 |
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 |
💡 Motivation and Context
Stacked on #391. The sdk-specs "Manual capture" requirement, for the lower-level method, says this. A
$session_idthe caller passes "is sent unchanged as the transport session unless a client conversation id or a conversation handle applies". Without one, "each call gets a freshses_<UUIDv7>". A client conversation id applies when the caller passes the request's_metawith theUser-Agentor client name that recognizes its client.PostHog::MCP::Clientsent no$session_idwhen given none, and read no client ids.What changed
capture_*sends$session_idand$mcp_session_source: the caller's session unchanged, or else a freshgeneratedone. The anonymousdistinct_idfalls back to it instead of"anonymous".capture_tool_calltakesrequest_meta:andclient_name:, and groups by a recognized client's conversation id.capture_missing_capabilityno longer sends$mcp_parameters. The keyword is still accepted.Scope
The spec's three-step manual API (list, call and result steps) is not here. It is new public API and needs its own design.
💚 How did you test it?
client_spec.rbtables cover a fresh or passed session for eachcapture_*, and client-id recognition byUser-Agent, by name, and for a key the client doesn't define. They failed first.bundle exec rspec: 0 failures.rubocopandrake public_api:checkpass with the regenerated snapshot.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code (Opus) found this gap in a spec-alignment audit of #386 and checked it against sdk-specs main. It wrote the fix test-first. The pre-PR gate ran over the whole stack: /simplify, a comment pass, and an adversarial review by Opus and Sonnet. Every verified finding is fixed here with a test.