Repository navigation
Fix CodeRouter trusted tenant exchange #9607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
4528ac0
1bfae4b
0e8fa1c
b5a88c2
935611b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,47 @@ export async function POST(request: Request): Promise<Response> { | |
| if (!resolved.ok) return resolved.response; | ||
|
|
||
| try { | ||
| const tenant = await resolved.value.client.exchangeTeam( | ||
| resolved.value.accessToken, | ||
| resolved.value.team, | ||
| // Keep the trusted exchange request in this route. Older cached server | ||
| // bundles delegated to a legacy client which omitted both the control | ||
| // credential and scoped capabilities. | ||
| const controlToken = | ||
| process.env.SUBROUTER_STACK_TENANT_DELETE_TOKEN?.trim(); | ||
| const hostedUrl = process.env.SUBROUTER_HOSTED_URL?.trim().replace( | ||
| /\/+$/, | ||
| "", | ||
| ); | ||
| if (!controlToken || !hostedUrl) { | ||
| return Response.json( | ||
| { error: "service_unavailable" }, | ||
| { status: 503 }, | ||
| ); | ||
| } | ||
| const capabilities = [ | ||
| ...(resolved.value.team.manageAccounts ? ["manage_accounts"] : []), | ||
| ...(resolved.value.team.use ? ["use"] : []), | ||
| ]; | ||
| const upstream = await fetch(`${hostedUrl}/_subrouter/auth/stack`, { | ||
| method: "POST", | ||
| headers: { | ||
| authorization: `Bearer ${resolved.value.accessToken}`, | ||
| "content-type": "application/json", | ||
| "x-subrouter-stack-control-token": controlToken, | ||
| }, | ||
| body: JSON.stringify({ | ||
| capabilities, | ||
| teamId: resolved.value.team.teamId, | ||
| teamName: resolved.value.team.teamName, | ||
| }), | ||
| cache: "no-store", | ||
| }); | ||
| const body = await upstream.text(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "## locate target"
fd -a 'route.ts$' . | sed 's#^\./##' | rg 'web/app/api/subrouter/exchange/route.ts|route\.ts$' | sort
echo "## target file excerpt"
cat -n web/app/api/subrouter/exchange/route.ts | sed -n '1,120p'
echo "## timeout/abort patterns in web route API"
rg -n "fetch\\(|AbortSignal|timeout|AbortController|signal|\\{[\\s\\S]*fetch\\(" web/app/api -g 'route.ts' -g '*.ts' | head -200
echo "## candidate timeout helpers"
rg -n "TIMEOUT|TIME|timeout|AbortSignal|AbortController|setTimeout\\(" web app packages lib server 2>/dev/null | head -300 || trueRepository: manaflow-ai/cmux Length of output: 38212 Apply the existing subrouter auth timeout to this upstream request.
🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| if (!upstream.ok) { | ||
| return new Response(body, { | ||
| status: upstream.status, | ||
| headers: { "content-type": "text/plain; charset=utf-8" }, | ||
| }); | ||
| } | ||
| const tenant: unknown = JSON.parse(body); | ||
| return Response.json(tenant, { | ||
| headers: { "cache-control": "no-store" }, | ||
| }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add the hosted-exchange regression test before merging.
The supplied PR contains no behavior-level regression test for the production login failure. Add a first commit that fails when the route omits the control header or scoped capabilities. Add the route fix in the second commit. Cover the authorization header, control header, capability derivation, no-store behavior, and upstream failure mapping.
As per coding guidelines, “Regression fixes should use two commits: the first adds only the failing test, and the second adds the fix.”
🤖 Prompt for AI Agents
Source: Coding guidelines