Skip to content

[Server] Send a stdio call's notifications before its response - #601

Merged
chr-hertel merged 1 commit into
mainfrom
fix-stdio-notification-order
Oct 14, 2026
Merged

chr-hertel merged 1 commit into
mainfrom
fix-stdio-notification-order

Conversation

@chr-hertel

Copy link
Copy Markdown
Member

Fixes the flaky NotificationTest::testLoggingReachesTheClient ("handshake era") in CI lately - turned out to be an actual bug, not the test.

On stdio, when a handler's last notification and its return land in the same resume, handleFiberTermination() wrote the response before flushOutgoingMessages() wrote the queued notification. Our client only caught it when both lines arrived in the same read.

  • Flush the outgoing queue before writing the final result
  • Regression test in StdioSuspendedFibersTest - fails deterministically without the fix
  • Streamable HTTP isn't affected, the SSE loop flushes before every resume

Copilot AI 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.

🟢 Approval recommended

The focused ordering fix includes a regression test, with no unresolved review findings.

0 open findings

What changed in this PR

Fixes stdio message ordering so queued handler notifications reach clients before the final response.

Changes:

  • Flush outgoing messages before sending a completed call’s result.
  • Add a regression test for notification-before-response ordering.
  • Document the fix in the changelog.
File Description
tests/​Unit/​Server/​Transport/​StdioSuspendedFibersTest.php Tests notification and response ordering.
src/​Server/​Transport/​StdioTransport.php Flushes queued messages before the final response.
CHANGELOG.md Documents the stdio ordering fix.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

When a handshake-era handler's last notification and its return happened
in the same resume, the response was written before the queued
notification. A client returning on the response could miss it, which made
NotificationTest::testLoggingReachesTheClient flaky in CI.
@chr-hertel
chr-hertel force-pushed the fix-stdio-notification-order branch from de355d8 to 411cd1d Compare October 14, 2026 23:18
@chr-hertel
chr-hertel merged commit d869b8f into main Oct 14, 2026
30 checks passed
@chr-hertel chr-hertel added bug Something isn't working Server Issues & PRs related to the Server component labels Oct 14, 2026
@chr-hertel
chr-hertel deleted the fix-stdio-notification-order branch October 14, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants