Repository navigation
[Server] Add a Revolt event loop example - #636
Open
chr-hertel wants to merge 2 commits into
Open
chr-hertel wants to merge 2 commits into
chr-hertel wants to merge 2 commits into
Conversation
chr-hertel
requested review from
CodeWithKyrian,
Nyholm and
soyuka
as code owners
October 27, 2026 22:03
Contributor
There was a problem hiding this comment.
🟡 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 on lines
+118
to
+119
| while ($fiber->isSuspended() && !$state->isParked()) { | ||
| $state->waitForTheRuntime(); |
|
|
||
| $response = $server->run(new StreamableHttpTransport($psrRequest, $factory, $factory, logger())); | ||
|
|
||
| return new Response($response->getStatusCode(), $response->getHeaders(), (string) $response->getBody()); |
Comment on lines
+60
to
+61
| foreach ($callbacks as $callback) { | ||
| $callback(); |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Adds
examples/server/revolt/with an Inspector test, built on top of #616 (its commit is included here).🤖 Generated with Claude Code