Repository navigation
fix(mcp): roll a stdio session over from the previous tool call's end - #389
Conversation
|
@PostHog review |
|
@lucasheriques PostHog Review is reviewing this pull request. |
posthog-ruby-sync Compliance ReportDate: 2026-11-29T16:11:06.702260+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-29T16:11:24.261727+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 |
8e85a72 to
f513b74
Compare
A new stamphog review started for this PR — the fresh verdict replaces this approval.
There was a problem hiding this comment.
Not approved — escalated to a human reviewer.
Add the stamphog label to request another review once you have addressed this.
The analytics write-path change has regression coverage but no independent assurance on the current head; the recorded review covers an older commit. Request a current-head review from Rafael Audibert, another teammate, or an agent reviewer before re-requesting.
- Author wrote 47% of the modified lines and has 11 merged PRs in these paths (familiarity MODERATE).
- Risky territory without independent assurance: Data ingestion or write paths — lib/posthog/mcp/session.rb, lib/posthog/mcp/instrumentation.rb, and lib/posthog/mcp/tracking_data.rb change how session identifiers are assigned to captured analytics events, including startup captures and tool calls after inactivity.
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| every_file_attested | ✓ | not a bot PR |
| size | ✓ | 49L, 3F substantive, 178L/6F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1d-complex (178L, 6F, cross-cutting, fix) |
| stamphog 2.9.1 | .stamphog/policy.yml @ f513b74 · reviewed head f513b74 |
There was a problem hiding this comment.
Not approved — escalated to a human reviewer.
Add the stamphog label to request another review once you have addressed this.
The analytics attribution changes enter risky territory without qualifying current-head assurance; the older review and discussion summaries do not supply it. Request a current-head review from Rafael Audibert, another teammate, or an agent reviewer before re-requesting.
- Author wrote 47% of the modified lines and has 11 merged PRs in these paths (familiarity MODERATE).
- Risky territory without independent assurance: Data ingestion or write paths — lib/posthog/mcp/session.rb, lib/posthog/mcp/instrumentation.rb, and lib/posthog/mcp/tracking_data.rb change the session identifiers attached to captured analytics events and when those identifiers rotate.
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| every_file_attested | ✓ | not a bot PR |
| size | ✓ | 49L, 3F substantive, 178L/6F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1d-complex (178L, 6F, cross-cutting, fix) |
| stamphog 2.9.1 | .stamphog/policy.yml @ f513b74 · reviewed head f513b74 |
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).
f513b74 to
f6e390c
Compare
|
@PostHog review |
|
@lucasheriques PostHog Review is reviewing this pull request. |
There was a problem hiding this comment.
Approved.
The analytics write-path changes have independent assurance from a current-head agent review. No unresolved substantive concerns or other refusal grounds were identified.
- Author wrote 43% of the modified lines and has 11 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 | ✓ | 49L, 3F substantive, 178L/6F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1d-complex (178L, 6F, cross-cutting, fix) |
| stamphog 2.9.1 | .stamphog/policy.yml @ f6e390c · reviewed head f6e390c |
|
Independent verifier on f6e390c: PASS+NOTES. Worth-it: LAND — fixes all four rule-3 gaps with a net -3 line lib change that replaces What I ran (merge base
Notes (non-blocking):
|
💡 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.