Uh oh!
There was an error while loading. Please reload this page.
fix(api): collapse the internal error envelope and restore requestId - #6584
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Removes Restores Reviewed by Cursor Bugbot for commit 8423bdc. Configure here. |
Greptile SummaryThe PR unifies internal orchestration failures under the bare error envelope and restores request IDs across generated internal errors.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the previously reported authentication and parsing paths now add the active request ID to internal JSON error bodies in both builders.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/api/server/routes/internal-json-route.ts | Unifies the internal JSON error envelope and routes authentication, parsing, projected, and wrapper failures through request-ID-aware responses. |
| apps/sim/lib/api/server/routes/internal-binary-route.ts | Applies the same request-ID restoration to JSON error responses emitted by internal binary routes. |
| apps/sim/lib/api/server/routes/request-id.ts | Adds helpers to stamp object error bodies and safely rebuild existing JSON validation responses while preserving status and headers. |
| apps/sim/lib/api/server/routes/internal-json-route.test.ts | Covers the unified bare envelope and request IDs on authentication, parsing, and projected errors. |
| apps/sim/lib/api/server/routes/request-id.test.ts | Verifies request-ID injection, pass-through behavior, and preservation of response metadata. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
Request[Internal API request] --> Wrapper[withRouteHandler request scope]
Wrapper --> Auth[Authentication]
Auth -->|401| Stamp[Add requestId to JSON error]
Auth --> Parse[Contract parsing]
Parse -->|400| Rebuild[Rebuild JSON response with requestId]
Parse --> UseCase[Application use case]
UseCase -->|Projected error| Stamp
UseCase -->|Unhandled error| Callback[Wrapper error callback]
Callback --> Stamp
Stamp --> Response[Error body plus x-request-id header]
Rebuild --> Response
Reviews (2): Last reviewed commit: "fix(api): stamp requestId on internal au..." | Re-trigger Greptile
Uh oh!
There was an error while loading. Please reload this page.
The builders shipped two internal error envelopes: internalOrchestrationErrorPolicy
emitted { success: false, error } while internalPlainOrchestrationErrorPolicy
emitted { error }. That split approximated pre-builder behavior, where the shape
depended on which branch failed - guard clauses returned { error } and a route's
terminal try/catch returned { success: false, error }. A per-route policy cannot
express a per-branch rule, so the two disagreed on the same status across families.
Collapse to the bare { error } shape. It is what messageFromErrorBody reads on the
client and what most migrated routes already emitted. requestJson throws
ApiClientError for any non-2xx, so no typed client ever observes the discriminator.
success: true on success bodies is a separate contract and is untouched.
Also restore requestId to internal error bodies. withRouteHandler stamps it on the
bodies it generates, but the builder overrides dropped it, leaving it only on the
x-request-id header - invisible when a user pastes an error out of the UI. It is now
applied at the createJsonErrorResponse chokepoint and in both wrapper overrides, and
is omitted when there is no active request scope.ee17317 to
8423bdcComparewaleedlatif1
commented
Aug 12, 2026
waleedlatif1
commented
Aug 12, 2026
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 8423bdc. Configure here.
Summary
internalOrchestrationErrorPolicyemitted{ success: false, error }andinternalPlainOrchestrationErrorPolicyemitted{ error }; both now emit{ error }under the singleinternalOrchestrationErrorPolicyname.{ error }and a route's terminaltry/catchreturned{ success: false, error }. A per-route policy cannot express a per-branch rule, so the two variants disagreed on the same status across families.messageFromErrorBodyreads on the client and what most migrated routes already emitted.requestJsonthrowsApiClientErrorfor any non-2xx, so no typed client ever observes the discriminator.requestIdto internal error bodies.withRouteHandlerstamps it on the bodies it generates, but the builder overrides dropped it, leaving it only on thex-request-idheader — invisible when a user pastes an error out of the UI.createJsonErrorResponsechokepoint plus both wrapper overrides, in the JSON and binary builders. Omitted when there is no active request scope, so unit tests are unaffected unless they opt in.internalFileErrorPolicies.plainalias.success: trueon success bodies is a separate contract and is untouched —/files/[fileId]/dimensionsstill returns a{ success: false }domain result at 200.Internal routes only. No
/api/v1/**route changes shape.Type of Change
Testing
bun run type-checkclean. 3118 API tests pass (app/api+lib/api).bun run check:api-validationpasses.Added
lib/api/server/routes/request-id.test.tsand a builder test pinning the bare envelope. Verified both go red when the injection is reverted.Checklist