-
Notifications
You must be signed in to change notification settings - Fork 137
Description
Summary
When using request-response mode (lambda), ctx.run durations are always reported as 0ms in the journal timeline, even though the side effects execute correctly and take real time. In bidi/streaming mode, durations are reported accurately.
Minimal repro
import * as restate from "@restatedev/restate-sdk";
const service = restate.service({
name: "timeout",
handlers: {
run: async (ctx: restate.Context) => {
await ctx.run("noop", () => {});
await ctx.run("2000ms", () => new Promise((resolve) => setTimeout(resolve, 2000)));
await ctx.run("3000ms", () => new Promise((resolve) => setTimeout(resolve, 3000)));
},
},
});Deploy this via a lambda endpoint (or any non-streaming request-response transport). All three runs will show 0ms duration in the timeline.
Deploy the same handler via a bidi streaming endpoint and durations are reported correctly.
Cause
In request-response mode, all journal entries are buffered and returned in a single HTTP response. The server assigns appended_at timestamps when entries arrive, so all entries in a batch get the same timestamp — making every run appear instantaneous.
In streaming mode, entries are written to the stream as they complete, so the server naturally observes time gaps between "start run" and "complete run" entries.
Note: the TypeScript SDK already measures attemptDuration on the success path (context_impl.ts:466) but discards it — propose_run_completion_success only sends the handle and result, not the timing. One fix would be to have the SDK send duration hints on success completions (as it already does for transient failures), so the server can use SDK-measured durations regardless of transport.
Related
- Inconsistent timestamps from sys_invocation_status and sys_journal following a restate shutdown. #3483 — inconsistent
appended_attimestamps (different root cause, but same mechanism) - Slack discussion: https://restatedev.slack.com/archives/C06DYBCEZB4/p1758533408558389
- Discord report: https://discord.com/channels/1128210118216007792/1482393653128331425