Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions examples/experimental-durable-streams-ai-agent/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions examples/kitchen-sink-vercel/frontend/page-data.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions examples/kitchen-sink-vercel/src/actors/lifecycle/sleep.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions examples/kitchen-sink-vercel/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions examples/kitchen-sink/frontend/page-data.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions examples/kitchen-sink/src/actors/lifecycle/sleep.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions examples/kitchen-sink/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rivetkit-rust/packages/rivetkit-core/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## Sleep state invariants

- Any mutation that changes a `can_sleep` input must call `ActorContext::reset_sleep_timer()` so the `ActorTask` sleep deadline is re-evaluated. Inputs are: `ready`/`started`, `no_sleep`, `active_http_request_count`, `sleep_keep_awake_count`, `sleep_internal_keep_awake_count`, `pending_disconnect_count`, `conns()`, and `websocket_callback_count`. Missing this call leaves the sleep timer armed against stale state and triggers the `"sleep idle deadline elapsed but actor stayed awake"` warning on the next tick.
- Any mutation that changes a `can_sleep` input must call `ActorContext::reset_sleep_timer()` so the `ActorTask` sleep deadline is re-evaluated. Inputs are: `ready`/`started`, `active_http_request_count`, `sleep_keep_awake_count`, `sleep_internal_keep_awake_count`, `pending_disconnect_count`, `conns()`, and `websocket_callback_count`. Missing this call leaves the sleep timer armed against stale state and triggers the `"sleep idle deadline elapsed but actor stayed awake"` warning on the next tick.
- Runtime-owned promises that must drain during shutdown should use `ActorContext::register_task(...)`, not public `wait_until(...)`, so metrics and runtime intent stay distinct. Registered tasks must race user work against `shutdown_deadline_token()` so shutdown cannot hang forever.
- `ctx.sleep()` and `ctx.destroy()` return `Result<()>`. They error with `ActorLifecycleError::Starting` when called before startup completes and `ActorLifecycleError::Stopping` if the requested flag has already been set this generation (atomic `swap(true, ...)`). Internal idle-timer paths log and suppress the already-requested error.
- The grace deadline path (`on_sleep_grace_deadline`) aborts the user `run` handle and cancels `shutdown_deadline_token()`. Foreign-runtime adapters running `onSleep` / `onDestroy` must observe that token via `tokio::select!` so SQLite teardown does not race user cleanup work.
Expand Down
6 changes: 0 additions & 6 deletions rivetkit-rust/packages/rivetkit-core/src/actor/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ pub struct ActorConfig {
pub on_migrate_timeout: Duration,
pub action_timeout: Duration,
pub sleep_timeout: Duration,
pub no_sleep: bool,
pub sleep_grace_period: Duration,
pub sleep_grace_period_overridden: bool,
pub connection_liveness_timeout: Duration,
Expand Down Expand Up @@ -109,7 +108,6 @@ pub struct ActorConfigInput {
pub on_migrate_timeout_ms: Option<u32>,
pub action_timeout_ms: Option<u32>,
pub sleep_timeout_ms: Option<u32>,
pub no_sleep: Option<bool>,
pub sleep_grace_period_ms: Option<u32>,
pub connection_liveness_timeout_ms: Option<u32>,
pub connection_liveness_interval_ms: Option<u32>,
Expand Down Expand Up @@ -160,9 +158,6 @@ impl ActorConfig {
if let Some(value) = config.sleep_timeout_ms {
actor_config.sleep_timeout = duration_ms(value);
}
if let Some(value) = config.no_sleep {
actor_config.no_sleep = value;
}
if let Some(value) = config.sleep_grace_period_ms {
actor_config.sleep_grace_period = duration_ms(value);
actor_config.sleep_grace_period_overridden = true;
Expand Down Expand Up @@ -224,7 +219,6 @@ impl Default for ActorConfig {
on_migrate_timeout: DEFAULT_ON_MIGRATE_TIMEOUT,
action_timeout: DEFAULT_ACTION_TIMEOUT,
sleep_timeout: DEFAULT_SLEEP_TIMEOUT,
no_sleep: false,
sleep_grace_period: DEFAULT_SLEEP_GRACE_PERIOD,
sleep_grace_period_overridden: false,
connection_liveness_timeout: DEFAULT_CONNECTION_LIVENESS_TIMEOUT,
Expand Down
5 changes: 0 additions & 5 deletions rivetkit-rust/packages/rivetkit-core/src/actor/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ pub(crate) struct SleepState {
pub(crate) enum CanSleep {
Yes,
NotReady,
NoSleep,
ActiveHttpRequests,
ActiveKeepAwake,
ActiveInternalKeepAwake,
Expand Down Expand Up @@ -223,13 +222,9 @@ impl ActorContext {
}

pub(crate) async fn can_arm_sleep_timer(&self) -> CanSleep {
let config = self.sleep_state_config();
if !self.0.sleep.lifecycle_started.load(Ordering::SeqCst) {
return CanSleep::NotReady;
}
if config.no_sleep {
return CanSleep::NoSleep;
}
if self.active_http_request_count() > 0 {
return CanSleep::ActiveHttpRequests;
}
Expand Down
1 change: 0 additions & 1 deletion rivetkit-rust/packages/rivetkit-core/tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ mod moved_tests {
assert_eq!(config.on_migrate_timeout, default.on_migrate_timeout);
assert_eq!(config.action_timeout, default.action_timeout);
assert_eq!(config.sleep_timeout, default.sleep_timeout);
assert_eq!(config.no_sleep, default.no_sleep);
assert_eq!(config.sleep_grace_period, default.sleep_grace_period);
assert_eq!(
config.sleep_grace_period_overridden,
Expand Down
2 changes: 0 additions & 2 deletions rivetkit-rust/packages/rivetkit-core/tests/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ fn build_applies_actor_config_to_owned_subsystems() {
config.create_conn_state_timeout = std::time::Duration::from_millis(123);
config.connection_liveness_timeout = std::time::Duration::from_millis(456);
config.sleep_timeout = std::time::Duration::from_millis(789);
config.no_sleep = true;

let ctx = ActorContext::build(
"configured-actor".to_owned(),
Expand Down Expand Up @@ -57,7 +56,6 @@ fn build_applies_actor_config_to_owned_subsystems() {

let sleep_config = ctx.sleep_config();
assert_eq!(sleep_config.sleep_timeout, config.sleep_timeout);
assert_eq!(sleep_config.no_sleep, config.no_sleep);
}

#[tokio::test]
Expand Down
22 changes: 5 additions & 17 deletions rivetkit-typescript/artifacts/actor-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"description": "Initial connection state value. Cannot be used with createConnState."
},
"createConnState": {
"description": "Function to create connection state. Receives context and connection params. Cannot be used with connState."
"description": "Function to create connection state. Receives context and connection params. The pending connection is not visible in c.conns until this succeeds. Cannot be used with connState."
},
"vars": {
"description": "Initial ephemeral variables value. Cannot be used with createVars."
Expand Down Expand Up @@ -45,10 +45,10 @@
"description": "Called when the actor's state changes. State changes within this hook won't trigger recursion."
},
"onBeforeConnect": {
"description": "Called before a client connects. Throw an error to reject the connection."
"description": "Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
},
"onConnect": {
"description": "Called when a client successfully connects."
"description": "Called when a client successfully connects. The connection is visible in c.conns before this runs."
},
"onDisconnect": {
"description": "Called when a client disconnects."
Expand Down Expand Up @@ -130,11 +130,7 @@
"type": "number"
},
"sleepGracePeriod": {
"description": "Max time in ms for the graceful sleep window. Covers lifecycle hooks, waitUntil, async raw WebSocket handlers, and disconnect callbacks. Default: 15000.",
"type": "number"
},
"onDestroyTimeout": {
"description": "Graceful destroy shutdown window in ms. Default: 15000",
"description": "Max time in ms for the graceful shutdown window. Covers lifecycle hooks (onSleep, onDestroy), the run handler wait, async raw WebSocket handlers, disconnect callbacks, and final state serialization. Default: 15000.",
"type": "number"
},
"stateSaveInterval": {
Expand All @@ -145,10 +141,6 @@
"description": "Timeout in ms for action handlers. Default: 60000",
"type": "number"
},
"waitUntilTimeout": {
"description": "Deprecated. Legacy timeout in ms for waitUntil when sleepGracePeriod is not set. Default: 15000",
"type": "number"
},
"connectionLivenessTimeout": {
"description": "Timeout in ms for connection liveness checks. Default: 2500",
"type": "number"
Expand All @@ -157,10 +149,6 @@
"description": "Interval in ms between connection liveness checks. Default: 5000",
"type": "number"
},
"noSleep": {
"description": "Deprecated. If true, the actor will never sleep. Use c.keepAwake(promise) to scope keep-awake to a specific operation instead. Default: false",
"type": "boolean"
},
"sleepTimeout": {
"description": "Time in ms of inactivity before the actor sleeps. Default: 30000",
"type": "number"
Expand Down Expand Up @@ -191,4 +179,4 @@
},
"additionalProperties": false,
"title": "RivetKit Actor Configuration"
}
}
1 change: 0 additions & 1 deletion rivetkit-typescript/packages/rivetkit-napi/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* tslint:disable */

Check failure on line 1 in rivetkit-typescript/packages/rivetkit-napi/index.d.ts

View workflow job for this annotation

GitHub Actions / RivetKit / Quality Check

format

Formatter would have printed the following content:
/* eslint-disable */

/* auto-generated by NAPI-RS */
Expand Down Expand Up @@ -67,7 +67,6 @@
actionTimeoutMs?: number
onRequestTimeoutMs?: number
sleepTimeoutMs?: number
noSleep?: boolean
sleepGracePeriodMs?: number
connectionLivenessTimeoutMs?: number
connectionLivenessIntervalMs?: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ pub struct JsActorConfig {
pub action_timeout_ms: Option<u32>,
pub on_request_timeout_ms: Option<u32>,
pub sleep_timeout_ms: Option<u32>,
pub no_sleep: Option<bool>,
pub sleep_grace_period_ms: Option<u32>,
pub connection_liveness_timeout_ms: Option<u32>,
pub connection_liveness_interval_ms: Option<u32>,
Expand Down Expand Up @@ -1062,7 +1061,6 @@ impl From<JsActorConfig> for ActorConfigInput {
on_migrate_timeout_ms: value.on_migrate_timeout_ms,
action_timeout_ms: value.action_timeout_ms,
sleep_timeout_ms: value.sleep_timeout_ms,
no_sleep: value.no_sleep,
sleep_grace_period_ms: value.sleep_grace_period_ms,
connection_liveness_timeout_ms: value.connection_liveness_timeout_ms,
connection_liveness_interval_ms: value.connection_liveness_interval_ms,
Expand Down
17 changes: 15 additions & 2 deletions rivetkit-typescript/packages/rivetkit-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ pub struct WasmServeConfig {
pub token: Option<String>,
pub namespace: String,
pub pool_name: String,
pub envoy_key: Option<String>,
pub engine_binary_path: Option<String>,
pub dev_serverless_url: Option<String>,
pub dev_serverless_manual: bool,
pub dev_serverless_drain_timeout: Option<u32>,
pub dev_serverless_request_timeout: Option<u32>,
pub handle_inspector_http_in_runtime: Option<bool>,
pub inspector_test_token: Option<String>,
pub serverless_base_path: Option<String>,
Expand Down Expand Up @@ -149,7 +154,12 @@ impl From<WasmServeConfig> for ServeConfig {
token: config.token,
namespace: config.namespace,
pool_name: config.pool_name,
envoy_key: config.envoy_key,
engine_binary_path: config.engine_binary_path.map(PathBuf::from),
dev_serverless_url: config.dev_serverless_url,
dev_serverless_manual: config.dev_serverless_manual,
dev_serverless_drain_timeout: config.dev_serverless_drain_timeout,
dev_serverless_request_timeout: config.dev_serverless_request_timeout,
handle_inspector_http_in_runtime: config
.handle_inspector_http_in_runtime
.unwrap_or(false),
Expand Down Expand Up @@ -193,7 +203,6 @@ pub struct WasmActorConfig {
pub action_timeout_ms: Option<u32>,
pub on_request_timeout_ms: Option<u32>,
pub sleep_timeout_ms: Option<u32>,
pub no_sleep: Option<bool>,
pub sleep_grace_period_ms: Option<u32>,
pub connection_liveness_timeout_ms: Option<u32>,
pub connection_liveness_interval_ms: Option<u32>,
Expand Down Expand Up @@ -223,7 +232,6 @@ impl From<WasmActorConfig> for ActorConfigInput {
on_migrate_timeout_ms: config.on_migrate_timeout_ms,
action_timeout_ms: config.action_timeout_ms,
sleep_timeout_ms: config.sleep_timeout_ms,
no_sleep: config.no_sleep,
sleep_grace_period_ms: config.sleep_grace_period_ms,
connection_liveness_timeout_ms: config.connection_liveness_timeout_ms,
connection_liveness_interval_ms: config.connection_liveness_interval_ms,
Expand Down Expand Up @@ -2840,7 +2848,12 @@ mod tests {
token: None,
namespace: "default".to_owned(),
pool_name: "default".to_owned(),
envoy_key: None,
engine_binary_path,
dev_serverless_url: None,
dev_serverless_manual: false,
dev_serverless_drain_timeout: None,
dev_serverless_request_timeout: None,
handle_inspector_http_in_runtime: None,
inspector_test_token: None,
serverless_base_path: None,
Expand Down
Loading
Loading