Skip to content

Run durations reported as 0ms in request-response mode (Lambda) #4489

@pcholakov

Description

@pcholakov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions