Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 7700f30

Browse files
committed
feat(core): actor sleeping
1 parent 779f5ae commit 7700f30

File tree

13 files changed

+203
-69
lines changed

13 files changed

+203
-69
lines changed

packages/core/fixtures/driver-test-suite/action-timeout.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ export const shortTimeoutActor = actor({
55
onAuth: () => {},
66
state: { value: 0 },
77
options: {
8+
<<<<<<< HEAD
89
action: {
910
timeout: 50, // 50ms timeout
1011
},
12+
=======
13+
actionTimeout: 50, // 50ms timeout
14+
>>>>>>> 3fda0eea (feat(core): actor sleeping)
1115
},
1216
actions: {
1317
quickAction: async (c) => {
@@ -26,9 +30,13 @@ export const longTimeoutActor = actor({
2630
onAuth: () => {},
2731
state: { value: 0 },
2832
options: {
33+
<<<<<<< HEAD
2934
action: {
3035
timeout: 200, // 200ms timeout
3136
},
37+
=======
38+
actionTimeout: 200, // 200ms timeout
39+
>>>>>>> 3fda0eea (feat(core): actor sleeping)
3240
},
3341
actions: {
3442
delayedAction: async (c) => {
@@ -56,9 +64,13 @@ export const syncTimeoutActor = actor({
5664
onAuth: () => {},
5765
state: { value: 0 },
5866
options: {
67+
<<<<<<< HEAD
5968
action: {
6069
timeout: 50, // 50ms timeout
6170
},
71+
=======
72+
actionTimeout: 50, // 50ms timeout
73+
>>>>>>> 3fda0eea (feat(core): actor sleeping)
6274
},
6375
actions: {
6476
syncAction: (c) => {

packages/core/fixtures/driver-test-suite/conn-liveness.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ export const connLivenessActor = actor({
77
acceptingConnections: true,
88
},
99
options: {
10+
<<<<<<< HEAD
1011
lifecycle: {
1112
connectionLivenessInterval: 5_000,
1213
connectionLivenessTimeout: 2_500,
1314
},
15+
=======
16+
connectionLivenessInterval: 5_000,
17+
connectionLivenessTimeout: 2_500,
18+
>>>>>>> 3fda0eea (feat(core): actor sleeping)
1419
},
1520
onConnect: (c, conn) => {
1621
if (!c.state.acceptingConnections) {

packages/core/fixtures/driver-test-suite/error-handling.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ export const errorHandlingActor = actor({
7070
},
7171
options: {
7272
// Set a short timeout for this actor's actions
73+
<<<<<<< HEAD
7374
action: {
7475
timeout: 500, // 500ms timeout for actions
7576
},
77+
=======
78+
actionTimeout: 500, // 500ms timeout for actions
79+
>>>>>>> 3fda0eea (feat(core): actor sleeping)
7680
},
7781
});
7882

@@ -90,8 +94,12 @@ export const customTimeoutActor = actor({
9094
},
9195
},
9296
options: {
97+
<<<<<<< HEAD
9398
action: {
9499
timeout: 200, // 200ms timeout
95100
},
101+
=======
102+
actionTimeout: 200, // 200ms timeout
103+
>>>>>>> 3fda0eea (feat(core): actor sleeping)
96104
},
97105
});

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
"on-change": "^5.0.1",
168168
"p-retry": "^6.2.1",
169169
"zod": "^3.25.76",
170-
"@rivetkit/engine-runner": "https://pkg.pr.new/rivet-gg/rivet/@rivetkit/engine-runner@f1c054d"
170+
"@rivetkit/engine-runner": "https://pkg.pr.new/rivet-gg/engine/@rivetkit/engine-runner@664a377"
171171
},
172172
"devDependencies": {
173173
"@hono/node-server": "^1.18.2",

packages/core/src/actor/config.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,15 @@ export const ActorConfigSchema = z
6060
createVars: z.function().optional(),
6161
options: z
6262
.object({
63-
lifecycle: z
64-
.object({
65-
createVarsTimeout: z.number().positive().default(5000),
66-
createConnStateTimeout: z.number().positive().default(5000),
67-
onConnectTimeout: z.number().positive().default(5000),
68-
connectionLivenessTimeout: z.number().positive().default(2500),
69-
connectionLivenessInterval: z.number().positive().default(5000),
70-
})
71-
.strict()
72-
.default({}),
73-
state: z
74-
.object({
75-
saveInterval: z.number().positive().default(10_000),
76-
})
77-
.strict()
78-
.default({}),
79-
action: z
80-
.object({
81-
timeout: z.number().positive().default(60_000),
82-
})
83-
.strict()
84-
.default({}),
63+
createVarsTimeout: z.number().positive().default(5000),
64+
createConnStateTimeout: z.number().positive().default(5000),
65+
onConnectTimeout: z.number().positive().default(5000),
66+
stateSaveInterval: z.number().positive().default(10_000),
67+
actionTimeout: z.number().positive().default(60_000),
68+
connectionLivenessTimeout: z.number().positive().default(2500),
69+
connectionLivenessInterval: z.number().positive().default(5000),
70+
noSleep: z.boolean().default(false),
71+
sleepTimeout: z.number().positive().default(30_000),
8572
})
8673
.strict()
8774
.default({}),

packages/core/src/actor/connection.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,7 @@ export class Conn<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider> {
209209
* @internal
210210
*/
211211
[CONNECTION_CHECK_LIVENESS_SYMBOL]() {
212-
const readyState = this.#driver.getConnectionReadyState?.(
213-
this.#actor,
214-
this,
215-
);
212+
const readyState = this.#driver.getConnectionReadyState(this.#actor, this);
216213

217214
const isConnectionClosed =
218215
readyState === ConnectionReadyState.CLOSED ||

packages/core/src/actor/driver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export interface ActorDriver {
3939
*/
4040
getDatabase(actorId: string): Promise<unknown | undefined>;
4141

42+
sleep?(actorId: string): void;
43+
4244
shutdown?(immediate: boolean): Promise<void>;
4345
}
4446

@@ -72,7 +74,7 @@ export interface ConnDriver<ConnDriverState = unknown> {
7274
* Returns the ready state of the connection.
7375
* This is used to determine if the connection is ready to send messages, or if the connection is stale.
7476
*/
75-
getConnectionReadyState?(
77+
getConnectionReadyState(
7678
actor: AnyActorInstance,
7779
conn: AnyConn,
7880
): ConnectionReadyState | undefined;

packages/core/src/actor/generic-conn-driver.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ export interface GenericSseDriverState {
160160
encoding: Encoding;
161161
}
162162

163-
export function createGenericSseDriver(globalState: GenericConnGlobalState) {
163+
export function createGenericSseDriver(
164+
globalState: GenericConnGlobalState,
165+
): ConnDriver<GenericSseDriverState> {
164166
return {
165167
sendMessage: (
166168
_actor: AnyActorInstance,
@@ -219,8 +221,12 @@ export function createGenericSseDriver(globalState: GenericConnGlobalState) {
219221
// MARK: HTTP
220222
export type GenericHttpDriverState = Record<never, never>;
221223

222-
export function createGenericHttpDriver() {
224+
export function createGenericHttpDriver(): ConnDriver<GenericHttpDriverState> {
223225
return {
226+
getConnectionReadyState(_actor, conn) {
227+
// TODO: This might not be the correct logic
228+
return ConnectionReadyState.OPEN;
229+
},
224230
disconnect: async () => {
225231
// Noop
226232
},

0 commit comments

Comments
 (0)