Skip to content

fix: return 503 instead of 400 for computer-route service errors - #28

Open
Ashfaqbs wants to merge 1 commit into
CopilotKit:mainfrom
Ashfaqbs:fix/computer-routes-error-status
Open

Ashfaqbs wants to merge 1 commit into
CopilotKit:mainfrom
Ashfaqbs:fix/computer-routes-error-status

Conversation

@Ashfaqbs

@Ashfaqbs Ashfaqbs commented Oct 2, 2026

Copy link
Copy Markdown

Summary

computerRoutes()'s onError handler mapped every thrown error to HTTP 400, including domain/service-state failures that aren't the client's fault: an unconfigured computer service, an unknown Dot id, a disabled permission, or the computer supervisor being unreachable all came back as 400 Bad Request.

This is inconsistent with workspace-routes.ts's existing convention, which reserves 400 for actual validation problems (malformed JSON, Zod failures) and falls back to 503 for everything else (see its onError, and the recent #11 fix for the same class of issue). computer-routes.ts had no direct test coverage before this PR, so the gap wasn't caught.

Changes

  • src/server/computer-routes.ts: Zod validation errors and malformed-JSON (SyntaxError) still return 400; everything else (service-not-configured, Dot-not-found, permission-disabled, upstream computer-service failures, etc.) now returns 503, matching the convention workspace-routes.ts already uses.
  • tests/computer-routes.test.ts (new): covers malformed JSON (400), a Zod validation failure (400), an unconfigured service (503), and an unknown Dot id (503).

Test plan

  • npm test — 164 tests passing (160 pre-existing + 4 new), no regressions.
  • npm run lint — clean.
  • npm run typecheck — clean.
  • npm run check-format — clean on changed files.
  • npm run build — succeeds.

Assisted by Claude Code (Anthropic) during investigation and implementation; reviewed and tested by me before opening this PR.

computerRoutes()'s error handler mapped every thrown error to HTTP 400,
including domain/service-state failures that are not the client's
fault: an unconfigured computer service, an unknown Dot id, a disabled
permission, or the computer supervisor being unreachable all came back
as 400 Bad Request. That misclassifies retryable/server-side failures
as client input errors and is inconsistent with workspace-routes.ts's
existing convention, which reserves 400 for actual validation problems
(malformed JSON, Zod failures) and uses 503 for everything else.

Also added the malformed-JSON carve-out workspace-routes.ts already
has (SyntaxError from a bad request body was previously falling through
to the generic case, which is still correctly 400 here, but only by
coincidence of being the blanket default -- now it's explicit and
covered by a regression test, matching the actions route's /dots/:id/
computer/actions endpoint which is the only one that parses JSON input
beyond the route param).

Covered by a new tests/computer-routes.test.ts (computer-routes.ts had
no direct test coverage before this), exercising: malformed JSON (400),
a Zod validation failure (400), an unconfigured service (503), and an
unknown Dot id (503).
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.

1 participant