Skip to content

feat: add sleep and reschedule endpoints for actors#4556

Merged
NathanFlurry merged 1 commit intomainfrom
04-04-feat_add_sleep_and_reschedule_endpoints_for_actors
Apr 5, 2026
Merged

feat: add sleep and reschedule endpoints for actors#4556
NathanFlurry merged 1 commit intomainfrom
04-04-feat_add_sleep_and_reschedule_endpoints_for_actors

Conversation

@MasterPtato
Copy link
Copy Markdown
Contributor

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@railway-app
Copy link
Copy Markdown

railway-app bot commented Apr 4, 2026

🚅 Deployed to the rivet-pr-4556 environment in rivet-frontend

Service Status Web Updated (UTC)
kitchen-sink ❌ Build Failed (View Logs) Web Apr 5, 2026 at 11:41 am
mcp-hub ✅ Success (View Logs) Web Apr 4, 2026 at 11:05 pm
frontend-inspector ❌ Build Failed (View Logs) Web Apr 4, 2026 at 11:05 pm
frontend-cloud ❌ Build Failed (View Logs) Web Apr 4, 2026 at 11:04 pm
website ❌ Build Failed (View Logs) Web Apr 4, 2026 at 11:04 pm
ladle ❌ Build Failed (View Logs) Web Apr 4, 2026 at 11:04 pm

@railway-app railway-app bot temporarily deployed to rivet-frontend / rivet-pr-4556 April 4, 2026 23:03 Destroyed
@claude
Copy link
Copy Markdown

claude bot commented Apr 4, 2026

PR Review: feat: add sleep and reschedule endpoints for actors

Summary

This PR adds two new HTTP API endpoints (POST /actors/{actor_id}/sleep and POST /actors/{actor_id}/reschedule), renames the internal Reallocate signal to Reschedule throughout pegboard, and introduces a new "stopping" SSE event to allow the serverless actor stream to close early when an actor stops gracefully.

The feature design is architecturally sound and follows existing patterns well, but there are a few issues that should be addressed before merging.


Issues

High: Signal rename violates protocol versioning rules

engine/packages/pegboard/src/workflows/actor2/mod.rs renames the signal name from "pegboard_actor2_reallocate" to "pegboard_actor2_reschedule". Per CLAUDE.md, published signal/protocol names must not be modified in-place — a new versioned schema must be added and the old one bridged forward. Any actors currently in a GoingAway state waiting on the old signal name will never receive the renamed signal, which is a correctness risk for rolling deployments.

Additionally, there's now a naming inconsistency: runtime.rs still uses try_reallocate, going_away, and comments like // Always immediately reallocate if going away, while the signal itself is now Reschedule. The Transition::Reallocating enum variant is also unchanged.

Medium: Missing await on stream.writeSSE for the "stopping" event

In rivetkit-typescript/packages/rivetkit/src/drivers/engine/actor-driver.ts (around line 506) and engine/sdks/typescript/test-envoy/src/index.ts (around line 201), the "stopping" SSE event write is missing await:

// Missing await — should be: await stream.writeSSE(...)
stream.writeSSE({ event: "stopping", data: "" });

Hono's SSEStreamingApi.writeSSE returns Promise<void>. Without awaiting, the event may not be flushed before the stream closes, making the feature silently non-functional in some cases. The ping loop in the same file correctly uses await stream.writeSSE(...).

Medium: No tests

The new sleep/reschedule endpoints and the "stopping" SSE flow have no test coverage. The PR checklist acknowledges this.

Medium: No documentation updates

The new endpoints are not documented. Per CLAUDE.md, API changes should be reflected in docs. If these endpoints are intended for external use, a docs page and sitemap/mod.ts update are needed.

Low: stopActor error parameter is undocumented and untested

engine/sdks/typescript/envoy-client/src/handle.ts adds an optional error?: string parameter to stopActor. It is unclear what the engine does with this field and there is no documentation or test coverage.


What Looks Good

  • Type centralization: Moving kv_get types into api-types and sharing them across api-public and api-peer is a clean improvement that reduces duplication.
  • Authorization pattern: Both reschedule.rs and sleep.rs correctly verify the actor belongs to the caller's namespace before sending signals, using pegboard::errors::Actor::NotFound to avoid leaking cross-namespace actor existence.
  • Defensive signal sending: Using .graceful_not_found() and logging a warning when the workflow is already gone is good defensive coding.
  • "stopping" SSE design: The mechanism is non-breaking since unknown SSE events were already warned-and-ignored before this change.
  • ShutdownReason type: Exporting a discriminated type instead of a boolean is a better API design.
  • Test envoy cleanup: Removing the dead /foo route is good housekeeping.

Overall

The signal rename is the most important issue to resolve — it should either follow the versioning protocol (new signal name + compat bridge) or be confirmed safe if actors with the old signal cannot survive a deployment boundary. The missing await on writeSSE is a straightforward functional bug. Tests and docs can follow in a subsequent PR if the feature is behind a flag, but both of those issues should be addressed before merge.

@NathanFlurry NathanFlurry mentioned this pull request Apr 4, 2026
11 tasks
@NathanFlurry NathanFlurry marked this pull request as ready for review April 5, 2026 10:59
Copy link
Copy Markdown
Member

NathanFlurry commented Apr 5, 2026

Merge activity

  • Apr 5, 11:11 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Apr 5, 11:41 AM UTC: Graphite rebased this pull request as part of a merge.
  • Apr 5, 11:41 AM UTC: @NathanFlurry merged this pull request with Graphite.

@NathanFlurry NathanFlurry changed the base branch from 04-03-fix_optimize_e2e_actor_path to graphite-base/4556 April 5, 2026 11:38
@NathanFlurry NathanFlurry changed the base branch from graphite-base/4556 to main April 5, 2026 11:40
@NathanFlurry NathanFlurry force-pushed the 04-04-feat_add_sleep_and_reschedule_endpoints_for_actors branch from da0b24b to b7a61fb Compare April 5, 2026 11:40
@railway-app railway-app bot temporarily deployed to rivet-frontend / rivet-pr-4556 April 5, 2026 11:40 Destroyed
@NathanFlurry NathanFlurry merged commit 3159df9 into main Apr 5, 2026
11 of 19 checks passed
@NathanFlurry NathanFlurry deleted the 04-04-feat_add_sleep_and_reschedule_endpoints_for_actors branch April 5, 2026 11:41
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.

2 participants