Skip to content

fix(mcp): roll a stdio session over from the previous tool call's end - #389

Merged
lucasheriques merged 3 commits into
mainfrom
lucas/mcp-session-rotation
Nov 29, 2026
Merged

lucasheriques merged 3 commits into
mainfrom
lucas/mcp-session-rotation

Conversation

@lucasheriques

@lucasheriques lucasheriques commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

💡 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::MCP broke this in four ways:

  • It rotated at more than 30 minutes, not 30 or more.
  • It measured from the last request of any kind, so a tools/list kept the session alive.
  • It re-resolved after the call, so a call longer than 30 minutes switched session midway.
  • It held no session before the first request.

What changed

  • The connection session is generated when the server is instrumented. A custom event captured before any request carries it.
  • Session.start_tool_call rotates 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_call stamps the end. resolve never rotates, so the record step keeps the arrival session.

💚 How did you test it?

  • spec/posthog/mcp/session_rotation_spec.rb covers 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. rubocop and rake public_api:check pass.

📝 Checklist

  • All commits are signed (see Commit signing)
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to 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.

@lucasheriques
lucasheriques added this pull request to stack #393 November 25, 2026 19:37
@lucasheriques lucasheriques self-assigned this Nov 25, 2026
@lucasheriques lucasheriques changed the title lucas/mcp session rotation fix(mcp): roll a stdio session over from the previous tool call's end Nov 25, 2026
@lucasheriques
lucasheriques marked this pull request as ready for review November 25, 2026 19:38
@lucasheriques
lucasheriques requested a review from a team as a code owner November 25, 2026 19:38
@lucasheriques

Copy link
Copy Markdown
Contributor Author

@PostHog review

@posthog

posthog Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@lucasheriques PostHog Review is reviewing this pull request.

@veria-ai

veria-ai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

posthog-ruby-sync Compliance Report

Date: 2026-11-29T16:11:06.702260+00:00
Duration: 94782ms

✅ All Tests Passed!

47/47 tests passed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 9ms
Format Validation.Event Has Uuid ✅ 7ms
Format Validation.Event Has Lib Properties ✅ 6ms
Format Validation.Distinct Id Is String ✅ 9ms
Format Validation.Token Is Present ✅ 6ms
Format Validation.Custom Properties Preserved ✅ 8ms
Format Validation.Event Has Timestamp ✅ 7ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 7ms
Retry Behavior.Retries On 503 ✅ 5386ms
Retry Behavior.Does Not Retry On 400 ✅ 2010ms
Retry Behavior.Does Not Retry On 401 ✅ 2010ms
Retry Behavior.Respects Retry After Header ✅ 8016ms
Retry Behavior.Implements Backoff ✅ 15346ms
Retry Behavior.Retries On 500 ✅ 5116ms
Retry Behavior.Retries On 502 ✅ 5116ms
Retry Behavior.Retries On 504 ✅ 5151ms
Retry Behavior.Max Retries Respected ✅ 15594ms
Deduplication.Generates Unique Uuids ✅ 18ms
Deduplication.Preserves Uuid On Retry ✅ 5139ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10367ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5158ms
Deduplication.No Duplicate Events In Batch ✅ 18ms
Deduplication.Different Events Have Different Uuids ✅ 10ms
Compression.Sends Gzip When Enabled ✅ 7ms
Batch Format.Uses Proper Batch Structure ✅ 6ms
Batch Format.Flush With No Events Sends Nothing ✅ 4ms
Batch Format.Synchronous Capture Delivers Each Event Immediately ✅ 17ms
Error Handling.Does Not Retry On 403 ✅ 2008ms
Error Handling.Does Not Retry On 413 ✅ 2008ms
Error Handling.Retries On 408 ✅ 5115ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 10ms
Request Payload.Flags Request Uses V2 Query Param ✅ 8ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 8ms
Request Payload.Flags Request Omits Authorization Header ✅ 7ms
Request Payload.Token In Flags Body Matches Init ✅ 6ms
Request Payload.Groups Round Trip ✅ 7ms
Request Payload.Groups Default To Empty Object ✅ 6ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 7ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 6ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 6ms
Request Lifecycle.No Flags Request On Init Alone ✅ 3ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 6ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 9ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 8ms
Retry Behavior.Retries Flags On 502 ✅ 108ms
Retry Behavior.Retries Flags On 504 ✅ 158ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 8ms

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

posthog-ruby-async Compliance Report

Date: 2026-11-29T16:11:24.261727+00:00
Duration: 98837ms

✅ All Tests Passed!

47/47 tests passed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 9ms
Format Validation.Event Has Uuid ✅ 106ms
Format Validation.Event Has Lib Properties ✅ 108ms
Format Validation.Distinct Id Is String ✅ 106ms
Format Validation.Token Is Present ✅ 106ms
Format Validation.Custom Properties Preserved ✅ 108ms
Format Validation.Event Has Timestamp ✅ 107ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 7ms
Retry Behavior.Retries On 503 ✅ 5310ms
Retry Behavior.Does Not Retry On 400 ✅ 2110ms
Retry Behavior.Does Not Retry On 401 ✅ 2109ms
Retry Behavior.Respects Retry After Header ✅ 8115ms
Retry Behavior.Implements Backoff ✅ 15722ms
Retry Behavior.Retries On 500 ✅ 5212ms
Retry Behavior.Retries On 502 ✅ 5213ms
Retry Behavior.Retries On 504 ✅ 5214ms
Retry Behavior.Max Retries Respected ✅ 15622ms
Deduplication.Generates Unique Uuids ✅ 111ms
Deduplication.Preserves Uuid On Retry ✅ 5212ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10310ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5215ms
Deduplication.No Duplicate Events In Batch ✅ 112ms
Deduplication.Different Events Have Different Uuids ✅ 107ms
Compression.Sends Gzip When Enabled ✅ 106ms
Batch Format.Uses Proper Batch Structure ✅ 106ms
Batch Format.Flush With No Events Sends Nothing ✅ 4ms
Batch Format.Multiple Events Batched Together ✅ 112ms
Error Handling.Does Not Retry On 403 ✅ 2109ms
Error Handling.Does Not Retry On 413 ✅ 2110ms
Error Handling.Retries On 408 ✅ 5211ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 107ms
Request Payload.Flags Request Uses V2 Query Param ✅ 107ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 107ms
Request Payload.Flags Request Omits Authorization Header ✅ 106ms
Request Payload.Token In Flags Body Matches Init ✅ 107ms
Request Payload.Groups Round Trip ✅ 106ms
Request Payload.Groups Default To Empty Object ✅ 107ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 107ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 107ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 106ms
Request Lifecycle.No Flags Request On Init Alone ✅ 3ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 106ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 109ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 106ms
Retry Behavior.Retries Flags On 502 ✅ 253ms
Retry Behavior.Retries Flags On 504 ✅ 242ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 111ms

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PostHog Review · Standard · reviewed 8e85a72: no findings.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

SDK performance: posthog-ruby

Benchmarks 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
Test Measurement Before PR With PR Change Assessment
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Queue an event (32-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​; head:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​
Queue an event (32-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​; head:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​
Queue an event (4,096-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​; head:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​
Queue an event (4,096-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​; head:​ Background serialization has no public enqueue completion boundary; use completed-delivery workloads for process-wide allocation counts.​
Evaluate all 10 flags
Shard: flags-scaling
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate all 100 flags
Shard: flags-scaling
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate all 1,000 flags
Shard: flags-scaling
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate one boolean flag
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a cohort-filtered flag
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a flag (early match)
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a flag (late match)
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a flag (no match)
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a property-filtered flag
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a regex-filtered flag
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a rollout flag
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Evaluate a multivariate flag
Shard: flags-single
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​; head:​ Ruby has no cumulative allocated-byte counter here; retained ObjectSpace bytes are not allocation volume.​
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocations per operation 56.27 count/op 56.27 count/op No observed change Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Time per operation 111.18 µs/op 111.16 µs/op <0.1% less time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Idle process memory (RSS) 28.49 MiB 28.47 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 31.51 MiB 31.49 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Managed heap after settling 5.3 MiB 5.3 MiB No observed change Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 30.74 MiB 30.72 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process CPU time per operation 24.68 µs/op 24.69 µs/op <0.1% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 31.29 MiB 31.26 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocations per operation 58.65 count/op 58.65 count/op No observed change Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Time per operation 111.3 µs/op 111.21 µs/op <0.1% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Idle process memory (RSS) 33.39 MiB 33.41 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 42.47 MiB 42.52 MiB 0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Managed heap after settling 9.17 MiB 9.17 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 40.29 MiB 39.89 MiB 1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process CPU time per operation 34.94 µs/op 34.67 µs/op 0.8% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 42.3 MiB 42.33 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocations per operation 58.68 count/op 58.68 count/op No observed change Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Time per operation 1.01 ms/op 1.01 ms/op <0.1% less time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Idle process memory (RSS) 28.48 MiB 28.48 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 30.5 MiB 30.52 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Managed heap after settling 5.3 MiB 5.3 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 30.5 MiB 30.52 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process CPU time per operation 35.21 µs/op 35.54 µs/op 0.9% more time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 30.5 MiB 30.52 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocations per operation 58.68 count/op 58.68 count/op No observed change Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Time per operation 1.01 ms/op 1.01 ms/op <0.1% less time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Idle process memory (RSS) 33.34 MiB 33.33 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 41.48 MiB 41.5 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Managed heap after settling 9.17 MiB 9.17 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 40.25 MiB 40.03 MiB 0.6% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process CPU time per operation 40.67 µs/op 40.62 µs/op 0.1% less time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 41.39 MiB 41.4 MiB <0.1% more memory Not flagged
Queue an event (32-byte payload)
Shard: capture
Caller-thread CPU time per operation 11.8 µs/op 11.69 µs/op 0.9% less time Not flagged
Queue an event (32-byte payload)
Shard: capture
Time per operation 11.79 µs/op 11.69 µs/op 0.9% less time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Caller-thread CPU time per operation 11.05 µs/op 11.42 µs/op 3.3% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Time per operation 11.05 µs/op 11.42 µs/op 3.3% more time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocations per operation 343.02 count/op 343.02 count/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Time per operation 94.26 µs/op 94.36 µs/op <0.1% more time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Process CPU time per operation 94.27 µs/op 94.36 µs/op <0.1% more time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocations per operation 3,323.94 count/op 3,324 count/op <0.1% more Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Time per operation 911.97 µs/op 912.26 µs/op <0.1% more time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Process CPU time per operation 911.92 µs/op 912.24 µs/op <0.1% more time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocations per operation 33,113.56 count/op 33,113.59 count/op <0.1% more Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Time per operation 9.22 ms/op 9.24 ms/op 0.2% more time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Process CPU time per operation 9.22 ms/op 9.24 ms/op 0.2% more time Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Idle process memory (RSS) 39.11 MiB 39.07 MiB 0.1% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Observed peak process memory (RSS) 40.39 MiB 40.35 MiB 0.1% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Managed heap after settling 8 MiB 8 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Process memory after settling (RSS) 39.49 MiB 39.44 MiB 0.1% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Lifetime peak process memory (RSS) 40.07 MiB 40.08 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Idle process memory (RSS) 38.01 MiB 38.02 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Observed peak process memory (RSS) 42.39 MiB 38.77 MiB 8.5% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Managed heap after settling 9.5 MiB 9.5 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Process memory after settling (RSS) 41.03 MiB 38.77 MiB 5.5% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Lifetime peak process memory (RSS) 42.49 MiB 38.77 MiB 8.8% less memory Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocations per operation 38 count/op 38 count/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Time per operation 7.89 µs/op 7.89 µs/op <0.1% less time Not flagged
Evaluate one boolean flag
Shard: flags-single
Process CPU time per operation 7.89 µs/op 7.89 µs/op <0.1% less time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocations per operation 38 count/op 38 count/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Time per operation 10.83 µs/op 10.8 µs/op 0.3% less time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Process CPU time per operation 10.83 µs/op 10.8 µs/op 0.3% less time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocations per operation 55 count/op 55 count/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Time per operation 13.94 µs/op 13.89 µs/op 0.3% less time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Process CPU time per operation 13.94 µs/op 13.89 µs/op 0.3% less time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocations per operation 76 count/op 76 count/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Time per operation 19.62 µs/op 19.77 µs/op 0.8% more time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Process CPU time per operation 19.62 µs/op 19.77 µs/op 0.8% more time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocations per operation 67 count/op 67 count/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Time per operation 17.73 µs/op 17.75 µs/op 0.1% more time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Process CPU time per operation 17.73 µs/op 17.75 µs/op 0.1% more time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocations per operation 34 count/op 34 count/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Time per operation 8.09 µs/op 8.12 µs/op 0.4% more time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Process CPU time per operation 8.08 µs/op 8.12 µs/op 0.5% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocations per operation 99 count/op 99 count/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Time per operation 23.24 µs/op 23.34 µs/op 0.4% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Process CPU time per operation 23.23 µs/op 23.34 µs/op 0.4% more time Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocations per operation 31 count/op 31 count/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Time per operation 7.03 µs/op 7.05 µs/op 0.3% more time Not flagged
Evaluate a rollout flag
Shard: flags-single
Process CPU time per operation 7.03 µs/op 7.05 µs/op 0.3% more time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocations per operation 37 count/op 37 count/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Time per operation 8.74 µs/op 8.75 µs/op 0.2% more time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Process CPU time per operation 8.74 µs/op 8.75 µs/op 0.2% more time Not flagged

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 fbbe32c7485db4228ab1907778b2fa31d21b6964 → f6e390c66416d9bee9f8bdce0ea1814881bd787c.

Full report and diagnostics

102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in comparison.json, including per-runner environments, resource limits, measurement methods, samples and checkpoints.

stamphog[bot]

This comment was marked as outdated.

@lucasheriques
lucasheriques force-pushed the lucas/mcp-session-rotation branch from 8e85a72 to f513b74 Compare November 27, 2026 20:52
@stamphog
stamphog Bot dismissed their stale review November 27, 2026 20:52

A new stamphog review started for this PR — the fresh verdict replaces this approval.

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@stamphog stamphog Bot removed the stamphog label Nov 27, 2026
Base automatically changed from lucas/mcp-session-identity to main November 29, 2026 16:08
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).
@lucasheriques
lucasheriques force-pushed the lucas/mcp-session-rotation branch from f513b74 to f6e390c Compare November 29, 2026 16:09
@lucasheriques

Copy link
Copy Markdown
Contributor Author

@PostHog review

@posthog

posthog Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

@lucasheriques PostHog Review is reviewing this pull request.

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PostHog Review · Standard · reviewed f6e390c: no findings.

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@lucasheriques

Copy link
Copy Markdown
Contributor Author

Independent verifier on f6e390c: PASS+NOTES. Worth-it: LAND — fixes all four rule-3 gaps with a net -3 line lib change that replaces touch_connection/stale? with a call counter and end stamp, and adds no flags or special cases.

What I ran (merge base fbbe32c vs head f6e390c, Ruby 3.3.2):

  • bundle exec rspec. Base 2677 examples, 0 failures. Head 2685 examples, 0 failures (49 pending at both).
  • Head's spec/posthog/mcp/session_rotation_spec.rb against base lib: 8 examples, 5 failures (30-minute boundary, listing keeps session alive, long call splits, late first call, startup capture). All pass at head.
  • bundle exec rubocop: no offenses. rake public_api:check: passes (needs a UTF-8 locale; with LANG unset the snapshot script raises invalid byte sequence in US-ASCII at base and head alike).
  • A standalone script drove MCP::Server + PostHog::MCP.instrument over plain server.handle (stdio path) with a fake clock. Session groups per event, base -> head:
    • call@0, call@30: same session -> rotates (fixed)
    • call@0, call@29: same -> same
    • call@0, list@20, call@35: same -> rotates (listing no longer keeps it alive)
    • call@0 running to 40, call@41: base split the call (docs_searched=S0, $mcp_tool_call=S1) -> one session for both calls
    • capture before any request: $session_id nil -> the connection session
    • list@0, first call@31: rotated -> keeps the startup session
    • call@0 raises, call@31 (head only): rotates, so the ensure decrements the in-flight count on error

Notes (non-blocking):

  • The Session module doc still says the server's own session "rolls over after INACTIVITY_TIMEOUT_MINUTES of inactivity". It now means 30 minutes from the previous tool call's end, so that line could say so.
  • A tool call that never returns keeps the in-flight count above zero, so the session never rotates. That follows the spec's "previous call ended" wording.

@lucasheriques
lucasheriques merged commit 2e4a46f into main Nov 29, 2026
30 checks passed
@lucasheriques
lucasheriques deleted the lucas/mcp-session-rotation branch November 29, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant