Skip to content

fix: wait for HTTP event stream before heartbeat - #205

Merged
JustasMonkev merged 1 commit into
mainfrom
fix/http-heartbeat-event-stream
Sep 1, 2026
Merged

JustasMonkev merged 1 commit into
mainfrom
fix/http-heartbeat-event-stream

Conversation

@JustasMonkev

@JustasMonkev JustasMonkev commented Sep 1, 2026 •

Copy link
Copy Markdown
Owner

Upstream change

Playwright MCP v0.0.80 includes microsoft/playwright#42189 and commit 43a9121961cb7dacd753133a6b5765bc00289d53. The HTTP heartbeat now waits until the client opens its event stream.

Why it matters here

This server started heartbeat on the first stateful HTTP tool call. A POST-only client cannot receive the server-initiated ping, so the server could close a healthy session after the ping timeout.

Fix

  • Wait for a successful standalone event-stream response before starting heartbeat.
  • Keep POST-only sessions alive without heartbeat.
  • Do not arm heartbeat for a rejected event-stream GET.
  • Document the behavior.

Validation

Passed:

  • npm test -- tests/mcp-http.test.ts tests/mcp-server-errors.test.ts
  • npm run lint
  • npm run build
  • npm run knip
  • git diff --check
  • mutation check: inverting the successful-stream status gate made the rejected-stream regression fail with Session not found

The full npm test run reaches 920 passing tests, 27 skipped, and 31 failures already present outside this diff: 3 recorder tests read a missing config.snapshot fixture, and 28 browser-backed screen-reader tests cannot launch because the current Playwright browser is not installed in this worktree.

Summary by CodeRabbit

  • Bug Fixes
    • HTTP sessions using POST requests remain connected without requiring an event stream.
    • Heartbeats now begin only after the optional event stream is successfully established.
    • Rejected or invalid event-stream requests no longer incorrectly activate heartbeats.
    • Heartbeat timeout and disable behavior are clarified in the documentation.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-01T13:58:49.717969Z 8d096ca PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 7be795e3-3fbd-4df3-a907-f6cb1615ba19

📥 Commits

Reviewing files that changed from the base of the PR and between b69c9fc and 8d096ca.

📒 Files selected for processing (4)
  • README.md
  • src/mcp/http.ts
  • src/mcp/server.ts
  • tests/mcp-http.test.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Changes

HTTP heartbeat readiness

Layer / File(s) Summary
Heartbeat readiness contract
src/mcp/server.ts
connect and createServer accept an optional readiness promise. Heartbeat startup waits for the promise and logs rejected readiness promises.
Session event-stream readiness
src/mcp/http.ts
Stateful sessions store the transport and a ManualPromise. The promise resolves only after a text event stream returns HTTP 200.
Heartbeat validation and documentation
tests/mcp-http.test.ts, README.md
Tests cover POST-only sessions and rejected event-stream requests. The README documents the updated heartbeat behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 8d096

The change delays HTTP heartbeat startup until a successful event stream is established while preserving POST-only session behavior. No actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant HTTPClient
  participant SessionStore
  participant MCPServer
  participant Heartbeat
  HTTPClient->>SessionStore: Create stateful session
  SessionStore->>MCPServer: connect with eventStreamReady
  HTTPClient->>SessionStore: Open text/event-stream
  SessionStore->>MCPServer: Handle event-stream request
  MCPServer-->>SessionStore: Write HTTP 200 headers
  SessionStore-->>Heartbeat: Resolve readiness
  Heartbeat-->>HTTPClient: Send server-initiated pings
Loading

Suggested reviewers: claude

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: delaying the HTTP heartbeat until the event stream is ready.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/http-heartbeat-event-stream

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JustasMonkev
JustasMonkev merged commit 2507cb8 into main Sep 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant