Skip to content

[Server] Add a Revolt event loop example - #636

Open
chr-hertel wants to merge 2 commits into
mainfrom
revolt-example
Open

chr-hertel wants to merge 2 commits into
mainfrom
revolt-example

Conversation

@chr-hertel

Copy link
Copy Markdown
Member

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

🤖 Generated with Claude Code

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 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

No deployments
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.

3 participants