Skip to content

Dashboard: let functions declare an expected duration - #65

Merged
abdullah-bl merged 2 commits into
mainfrom
feat/expected-duration
Nov 19, 2026
Merged

abdullah-bl merged 2 commits into
mainfrom
feat/expected-duration

Conversation

@abdullah-bl

Copy link
Copy Markdown
Owner

What changed

A function can now say how long a call normally takes, with expectedMs. The dashboard then lists it as slow only when its p95 is above that, instead of above the fixed default (1 s for a query or mutation, 10 s for an action, 5 s for an HTTP route).

export const answer = internalAction({
  args: { turnId: v.id("turns") },
  expectedMs: 3 * 60_000, // a full answer from the local model
  handler: async (ctx, { turnId }) => { /* ... */ },
});
  • Functions: expectedMs sits next to args on queries, mutations and actions.
  • HTTP actions: httpAction(handler, { expectedMs }), a new optional second argument (also on component HTTP actions).
  • MCP tools: tool({ expectedMs, ... }).
  • expectedMs: Infinity turns the warning off. The work-queue and workflow runners use it, because they last as long as the function they run, which has its own metrics.
  • Startup warning: the server warns when a function's expectedMs is above its time limit, since such a call is stopped before it could count as slow.

How slowness is decided

The call log now counts, per function, the runs that took longer than its threshold, and reports slow when more than 5% did. That is the same as "the p95 is above the threshold", but exact.

The first commit compared the histogram's p95 with expectedMs. That had two problems, both fixed by the second commit:

  • The histogram stopped at about 74 s, so a larger expectedMs (the documented 3-minute example) could never be passed.
  • A percentile is its bucket's top edge, which can read up to 41% high and flag a function that is within budget.

The histogram now reaches about 3.5 days, so the displayed p95 is no longer capped. The default thresholds moved from the dashboard to src/engine/calllog.ts.

For the reviewer

  • Slow counts are taken against the threshold in force when each call ran. After a deploy that changes expectedMs, the warning takes up to an hour to fully reflect the new value.
  • The >= comparison with the default thresholds became >.
  • src/dashboard/bundle.generated.ts is rebuilt.
  • The startup warning has no automated test. I saw it fire in the test run before lowering the test's value.
  • The dashboard was not checked in a browser.

Testing

bun run typecheck passes. bun test: 587 pass, 0 fail. New tests in tests/admin.test.ts cover a 10-minute call against a 3-minute expectedMs, the one-in-twenty boundary, Infinity, and validation.

🤖 Generated with Claude Code

xa-x and others added 2 commits November 19, 2026 05:43
Long-running actions (a chat turn, a work-queue job, a workflow step) were
flagged as slow on the dashboard overview even when working as intended.
Function builders now take an optional `expectedMs`; admin metrics carry it
and the overview only flags calls slower than that. Work-queue actions and
workflow action steps default to one hour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…expectedMs

The dashboard compared a histogram p95 with expectedMs. The histogram stopped
at about 74 s, so a larger expectedMs could never be passed, and a bucket's top
edge could read up to 41% high and flag a function that was within budget.

The call log now counts the runs above each function's threshold and reports
it as slow when more than 5% are. The histogram reaches about 3.5 days.

- expectedMs: Infinity turns the warning off; the work-queue and workflow
  runners use it instead of a one-hour value.
- httpAction(handler, { expectedMs }) and tool({ expectedMs }) are supported.
- The server warns at startup when expectedMs is above the time limit.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@abdullah-bl
abdullah-bl merged commit 86728ba into main Nov 19, 2026
1 check passed
@abdullah-bl
abdullah-bl deleted the feat/expected-duration branch November 19, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants