Skip to content

Typescript module - can't enforce server-only calls of scheduled reducer #3490

@hankportney

Description

@hankportney

Playing with new typescript modules, the below code repeatedly errors when ticking, indicating the check for identity recommended by the C# docs (notably - this wasn't in the TS docs, but seems like a missing entire example?) isn't working.

Using v1.16.1 with latest CLI, seeing the issue locally (haven't tried deploying).

Reducer:

spacetimedb.reducer("GameTick", { arg: GameSchedule.rowType }, (ctx) => {
	// THIS HERE is throwing errors for my server-side calls.  I tried a non-strict equality check as well, no dice.
	if (ctx.sender !== ctx.identity) {
		throw new errors.SenderError(
			"Tick reducer can only be called by the server"
		);
	}
});

Table:

const GameSchedule = table(
	{ name: "gameSchedule", scheduled: "GameTick", public: false },
	{
		id: t.u64().primaryKey().unique(),
		scheduledAt: t.scheduleAt()
	}
);

Init:

const initGame = (ctx: ReducerCtx) => {
	ctx.db.gameSchedule.insert({
		id: 0n,
		scheduledAt: ScheduleAt.interval(8333n)
	});
};

spacetimedb.init((ctx) => {
	initGame(ctx);
});

and finally, the error:
[1] 2025-10-25T21:16:05.000666Z ERROR: GameTick: Tick reducer can only be called by the server [0] 2025-10-25T21:16:05.023926Z INFO crates/core/src/host/wasm_common/module_host_actor.rs:478: reducer returned e rror: Tick reducer can only be called by the server

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions