Repository navigation
fix(mcp): roll a stdio session over from the previous tool call's end - #389
lucasheriques wants to merge 3 commits into
Conversation
The sdk-specs "Session identity" rule 3: a one-client connection's session is generated when it opens, and a new one goes to the first tool call that arrives 30 minutes or more after the previous tool call ended. Every event of a call uses the id resolved when the call arrived. - TrackingData generates the connection session at startup, so a custom event captured before any request has a $session_id. - Session.resolve never rotates. Session.rotate_if_idle runs when a tool call arrives (>= 30 minutes), and Session.end_tool_call stamps the end. Listings no longer refresh the clock, and the record step of a long call reuses the arrival session. Tested: bundle exec rspec (2629 examples, 0 failures; the new session_rotation_spec failed 4 of 6 first), rubocop clean.
…ate_if_idle /simplify on the stack: TrackingData now always starts with a session, so resolve's nil check never fires. Tested: bundle exec rspec spec/posthog/mcp (257 examples, 0 failures).
…ning call Pre-PR gate (both adversaries): the startup clock counted as a previous call's end, so a first tool call 30 minutes after startup rotated; and a call arriving while another ran could rotate and re-file the running call's events. Rotation now needs an ended previous call and no call in flight (Session.start_tool_call / end_tool_call keep the count). Tested: bundle exec rspec spec/posthog/mcp (259 examples, 0 failures; both new session_rotation_spec examples failed first).
|
@PostHog review |
|
@lucasheriques PostHog Review is reviewing this pull request. |
PR overviewNo security issues were found in this pull request. Reviews
|
posthog-ruby-sync Compliance ReportDate: 2026-11-25T19:39:25.697803+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:39:34.713404+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 |
There was a problem hiding this comment.
Approved.
The analytics write-path changes have independent assurance from a current-head agent review. The code and added regression coverage support the disclosed intent, with no outstanding substantive concerns or other blocking grounds identified.
- Author wrote 43% of the modified lines and has 8 merged PRs in these paths (familiarity MODERATE).
- 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 | ✓ | 46L, 3F substantive, 175L/6F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1d-complex (175L, 6F, cross-cutting, fix) |
| stamphog 2.9.1 | .stamphog/policy.yml @ 8e85a72 · reviewed head 8e85a72 |
💡 Motivation and Context
Stacked on #386. The sdk-specs "Session identity" rule 3 gives a one-client connection (stdio) a session when it opens. A new one goes to "the first tool call that arrives 30 minutes or more after the previous tool call on that connection ended", and "every event of a call uses the id resolved when the call arrived".
PostHog::MCPbroke this in four ways:tools/listkept the session alive.What changed
Session.start_tool_callrotates when a tool call arrives 30 or more minutes after the previous tool call ended. It needs an ended previous call and no call in flight.Session.end_tool_callstamps the end.resolvenever rotates, so the record step keeps the arrival session.💚 How did you test it?
spec/posthog/mcp/session_rotation_spec.rbcovers each boundary as a table: 29 and 30 minutes, a listing between calls, a long call, the first call after a late start, a call arriving under a running call, and a capture at startup. Each example failed first.bundle exec rspec: 0 failures.rubocopandrake public_api:checkpass.📝 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.