feat(obs): middleware mints X-Request-Id + runtime trust-gate spec#183
Merged
operatoruplift merged 1 commit intomasterfrom Apr 27, 2026
Merged
feat(obs): middleware mints X-Request-Id + runtime trust-gate spec#183operatoruplift merged 1 commit intomasterfrom
operatoruplift merged 1 commit intomasterfrom
Conversation
The middleware was a hidden gap in the trust-gate contract. Source trust-gate (#167-#174) confirmed every route file imports withRequestMeta. But the middleware in middleware.ts intercepts every /api/* request first, and its 401 "Authentication required" response went out without an X-Request-Id header. Two changes: ## middleware.ts - Mints `req_<uuid>` if the incoming request doesn't already carry an X-Request-Id, otherwise propagates. - Attaches the ID to: - the 401 unauthorized response (status, body envelope, header) - every pass-through (forwarded as a request header so the route handler's `withRequestMeta` reads the same value) - The 401 body now also carries `requestId` and `timestamp` to match the canonical envelope shape. ## tests/e2e/request-id-runtime.spec.ts (new) - 16 probes against representative endpoints, all four response shapes (200 success, 401 middleware-block, 400/410/403 handler envelopes). - Each asserts `X-Request-Id` is present and matches `^req_[0-9a-f-]+`. - Picked endpoints to cover: public (capabilities, providers, sns.resolve, health.adapters, health.llm, waitlist, auth.login), auth-gated (whoami, dashboard.stats, receipts.public-key, subscription, x402, tools.web, tools.notes, access.check, risk). ## .github/workflows/ci.yml - request-id-runtime.spec.ts joins the hermetic spec list, so a middleware regression that drops the header fails CI before merge. Trust-gate is now enforced at BOTH layers: source (every route file imports the helper) and runtime (every response carries the header). ## Verified - pnpm exec tsc --noEmit: clean - pnpm check: 3 passed, 0 failed - pnpm exec playwright test request-id-runtime.spec.ts: 16/16 pass ## Rollback Single git revert. Three files.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the last trust-gate gap
The source-level trust-gate (#167-#174) confirmed every route file imports
withRequestMeta. But there was a hidden gap: the middleware atmiddleware.tsintercepts every/api/*request first, and its 401 "Authentication required" response went out without an X-Request-Id header.A user calling any auth-gated route without a token got a 401 with no request ID, breaking the support-debug contract.
Two changes
middleware.tsreq_<uuid>if the incoming request doesn't already carry anX-Request-Id, otherwise propagates.withRequestMetareads the same value — IDs are now stable end-to-end)requestId+timestampmatching the canonical envelope shape.tests/e2e/request-id-runtime.spec.ts(new — 16 probes)Probes representative endpoints anonymously and asserts each response carries
X-Request-Idmatching^req_[0-9a-f-]+.Covers all four response shapes:
.github/workflows/ci.ymlrequest-id-runtime.spec.tsjoins the hermetic spec list. Future middleware regressions that drop the header now fail CI before merge.Trust-gate at both layers
pnpm check::trust-gate): 44/44 routes import@/lib/apiHelpersX-Request-IdVerified
Net diff
Rollback
Single
git revert. Note: rolling back re-introduces the middleware 401 gap; investigate before reverting.