Skip to content

[Server] Add Revolt and ReactPHP examples and fix session locks under an event loop - #636

Merged
chr-hertel merged 9 commits into
mainfrom
revolt-example
Nov 8, 2026
Merged

chr-hertel merged 9 commits into
mainfrom
revolt-example

Conversation

@chr-hertel

@chr-hertel chr-hertel commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #616 - adds examples/server/revolt/ and examples/server/reactphp/, both with an Inspector test, covers the fiber schedulers on the real event loops and lands what was left open on #616.

  • Both servers buffer their responses, so they answer with 501 when a response needs streaming, e.g. when a tool sends a notification
  • Requests of one session wait for its session lock on the event loop - before, the second one failed with 503 and a resumed request lost its session writes
  • A handler still running after its request was answered no longer fires events, and what it throws is logged
  • Corrects the limits in the docs: stdio runs requests one after the other, fire-and-forget gateway calls lose the message
  • New dev dependencies: amphp/amp, amphp/http-server, revolt/event-loop, react/async, react/http & react/promise

StreamableHttpTransport still blocks the loop while polling and streams via echo - documented as a limit.

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.

🟡 Changes recommended

Scheduler failures during transport-driven fiber resumes can escape protocol error handling, terminating stdio processing or HTTP streams without a final JSON-RPC error response.

3 open issues
What changed in this PR

Adds a Revolt-powered HTTP server example, building on #616’s fiber-scheduler support so request handlers can await asynchronous I/O without the SDK resuming their fibers prematurely.

Changes:

  • Adds scheduler integration across handler fibers, protocols, client communication, and transports.
  • Adds an AMPHP/Revolt example with timer-based tools and Inspector snapshot tests.
  • Documents scheduler configuration and adds unit coverage for event-loop interactions.
File Description
tests/​Unit/​Server/​Fiber/​HandlerFibersTest.php Tests fiber ownership, suspension, and exception handling.
tests/​Unit/​Server/​Fiber/​FakeEventLoop.php Provides a dependency-free test scheduler.
tests/​Unit/​Server/​Fiber/​EventLoopToolCallTest.php Tests asynchronous tool calls across protocol eras.
tests/​Interop/​Server/​Http/​snapshots/​HttpRevoltTest-tools_list.json Records example tool schemas.
tests/​Interop/​Server/​Http/​snapshots/​HttpRevoltTest-tools_call-wait.json Records the wait tool result.
tests/​Interop/​Server/​Http/​snapshots/​HttpRevoltTest-tools_call-check_services.json Records concurrent service-check results.
tests/​Interop/​Server/​Http/​snapshots/​HttpRevoltTest-resources_templates_list.json Records empty resource templates.
tests/​Interop/​Server/​Http/​snapshots/​HttpRevoltTest-resources_list.json Records empty resources.
tests/​Interop/​Server/​Http/​snapshots/​HttpRevoltTest-prompts_list.json Records empty prompts.
tests/​Interop/​Server/​Http/​HttpRevoltTest.php Runs Inspector checks against the Revolt example.
tests/​Interop/​Server/​Http/​HttpInspectorSnapshotTestCase.php Allows custom server startup commands.
src/​Server/​Transport/​StreamableHttpTransport.php Uses scheduler-aware fiber resumption for HTTP.
src/​Server/​Transport/​StdioTransport.php Uses scheduler-aware fiber resumption for stdio.
src/​Server/​Transport/​BaseTransport.php Routes failed-yield resumption through handler management.
src/​Server/​Stateless/​StatelessProtocol.php Integrates scheduling into stateless handlers.
src/​Server/​Protocol.php Integrates scheduling into handshake-era handlers.
src/​Server/​Fiber/​HandlerFiberState.php Tracks suspension, settlement, and handler errors.
src/​Server/​Fiber/​HandlerFibers.php Coordinates server-driven and runtime-driven fibers.
src/​Server/​Fiber/​FiberSettlement.php Provides settlement callbacks for schedulers.
src/​Server/​Fiber/​FiberSchedulerInterface.php Defines the runtime waiting contract.
src/​Server/​ClientGateway.php Marks client-facing suspensions for the server.
src/​Server/​Builder.php Exposes scheduler configuration to both protocols.
examples/​server/​revolt/​SlowTools.php Demonstrates asynchronous waits and concurrent checks.
examples/​server/​revolt/​server.php Hosts the example using AMPHP HTTP.
examples/​server/​revolt/​RevoltFiberScheduler.php Adapts settlement waiting to Revolt.
examples/​server/​README.md Adds example startup instructions.
docs/​run/​server-builder.md Documents scheduler configuration and limitations.
composer.json Adds development dependencies and example autoloading.
CHANGELOG.md Records scheduler support and fiber-handling changes.

Review effort: Balanced

Comment thread src/Server/Fiber/HandlerFibers.php Resolved
Comment thread examples/server/revolt/server.php Resolved
Comment thread src/Server/Fiber/FiberSettlement.php Resolved
@chr-hertel chr-hertel added the Server Issues & PRs related to the Server component label Nov 3, 2026
@chr-hertel chr-hertel added this to the 0.10.0 milestone Nov 4, 2026
@chr-hertel chr-hertel changed the title [Server] Add a Revolt event loop example [Examples] Add Revolt and ReactPHP event loop examples Nov 8, 2026
@chr-hertel chr-hertel changed the title [Examples] Add Revolt and ReactPHP event loop examples [Server] Add Revolt and ReactPHP examples and fix session locks under an event loop Nov 8, 2026

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.

🟡 Changes recommended

The abandonment check misses exceptions caught in dispatchResult(), allowing a resumed ResponseEvent listener to trigger a late ErrorEvent after the request has already been answered.

1 open issue
3 resolved since last review

Review effort: Balanced

Comment thread src/Server/Protocol.php Resolved

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 review has no active issues requiring resolution.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@chr-hertel
chr-hertel merged commit e12cead into main Nov 8, 2026
35 checks passed
@chr-hertel
chr-hertel deleted the revolt-example branch November 8, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants