Skip to content

A route returning undefined makes POST /threads/:id/runs/wait answer 500 #714

Closed

Description

@blove

Split out of #711, which fixed the same bug class on the middleware-reject path. This instance is still live.

The bug

packages/cli/src/lib/dev/runtime-fetch-core.ts:2633 serializes a completed run with:

return Response.json(result.output, { status: 200 })

result.output is typed unknown and is literally the route's return value (await entry(input, context) in packages/cli/src/lib/runtime/execute-route-core.ts). Response.json(undefined) throws, so a route that returns nothing is caught by the outer handler and answers:

500 {"error":{"kind":"execution_error","message":"Unexpected runtime server failure"}}

The same route over POST /threads/:id/runs/stream answers 200, so the two endpoints disagree about the same run.

Reproduce

A route whose entry returns nothing:

export const workflow = async () => undefined

Then POST /threads/:id/runs/wait against it.

Why it matters

Before #373 this path was sendJson(200, undefined), which sent a 200 with an empty body. So this is a regression from the same commit that caused #711, just on the route-output path rather than the middleware path.

Not obviously a one-line fix

Unlike the middleware case, the right behavior is a real decision rather than restoring parity by reflex. A route that returns nothing could reasonably be a 200 with an empty body (the old behavior), or it could be a route authoring mistake worth surfacing as a named error. The current 500 is the worst of both: it is an unnamed, undiagnosable failure that contradicts the streaming endpoint. Whichever is chosen should apply to both endpoints.

Found by an adversarial review of #711.

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