Repository navigation
Conversation
…e caller through a host with its own status, not 502 (swamp-club#4894) The host's router opened its upstream with Deno's WebSocket client, which reports a refused handshake only as an error event, so every refusal by a workspace or the root (a refused or expired token, an origin refusal, a misdirected request, a rate limit) reached the caller as 502 "The workspace could not be reached." The CLI could not tell a refused credential from a crashed child, and its login hint never showed. The router now reads the child's status from Deno's handshake failure text (`Invalid status code: N`), the same text the CLI and worker already read, and answers a 4xx or 5xx with that status and a body of its own. The child is asked once, so a refused credential is never sent twice. A redirect, whose Location cannot be passed on, and a child that never answered still reach the caller as 502; a timeout stays 504. The child's body and headers do not survive, which no WebSocket client could read anyway. - Router tests use a child that refuses by the credential and headers it receives (401, 403, 421, 429, 503), each asserting the caller's status, the host's own body and exactly one handshake. - The CLI sign-in test for a workspace refusing its exchanged token now sees the 401 login hint through the host instead of HTTP 502. - The 502 hint for a workspace token stays for older hosts. - A worker behind a host with a refused credential now gives up after three attempts, as it does against serve directly, instead of retrying the router's 502 as a restart. - design/surfaces/serve-workspaces.md and design/enablers/remote-execution.md describe the new behaviour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…b#4894) - The comment above refusalStatus no longer reads as if only a redirect without a Location falls to 502; every redirect does. - The router logs the upstream failure text only when there is one, so a timeout or abort no longer ends its line with an empty string. - workspaceTokenRefusalHint's JSDoc wraps at 80 columns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Adversarial Review
I read src/serve/host/workspace_router.ts (relayWebSocket, the new refusalStatus), host_reply.ts, the hint change in server_login_hint.ts, and the router and sign-in tests.
Critical / High
None.
I checked these paths and found them correct:
- Settle races.
failureis written only from theerrorlistener, and only the non-open branches read it. If the timeout settles first and anerrorarrives later, the code still takes the 504 branch. A caller or host abort leavesfailureempty, so it falls back to 502. Aclosewithout anerroralso gives 502. No path changesoutcome. - Status range.
refusalStatusonly accepts 400–599, and the\bstops a 4-or-more-digit run from being read as a 3-digit status. 101, redirects and anything unparseable still give 502. So a 1xx, 2xx or 3xx status can't reachResponse.json, which would otherwise throw a RangeError for statuses below 200. - What crosses from the child. Only the status number does. The body comes from the host (
hostReply), and the child's headers are dropped. Nothing downstream ofrouter.handle(serve_host.ts:248) branches on the status, so passing it through can't affect any host-side rate limiting or auth bookkeeping. - Asking the child once. There is still one upstream handshake per caller attempt, so a refused credential is never sent to the child twice.
Medium
None.
Low
workspace_router.ts:261: the host now passes through any 4xx/5xx a child chooses to send, including 401 or 407 with noWWW-AuthenticateorProxy-Authenticateheader. A misbehaving workspace child could therefore make the host appear to refuse the caller's credential. That is the intended behaviour, and it is low risk because the children are spawned by the host. If a tighter contract is wanted later, you could allowlist the statuses the CLI and worker actually act on (401/403/404/421/429/503) and map everything else to 502.workspace_router.ts:139-144:failureis Deno's internal error text and is logged at info level. Today it only carries the status, but if Deno ever adds URL or header detail to that text, it would land in host logs. This is theoretical.
Verdict
PASS. The status pass-through is limited to 4xx/5xx and every non-matching path keeps the old 502/504 answers.
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.
Summary
The host's router (
src/serve/host/workspace_router.ts,relayWebSocket) opens its upstream with Deno's WebSocket client, which reports a refused handshake only as an error event. Every refusal by a workspace or the root — a refused or expired token (401), an origin refusal (403), a misdirected request (421), a rate limit (429), a child shutting down (503) — reached the caller as502 "The workspace could not be reached.". The CLI could not tell a refused credential from a crashed child, and its login hint never showed.The router now reads the child's status from Deno's handshake failure text (
Invalid status code: N) — the same textsrc/cli/remote_run.tsandsrc/worker/connect.tsalready read — and answers a 4xx or 5xx with that status and a body of its own.Decisions
Retry-After, but no Deno or browser WebSocket client can read a refused handshake's body or headers, and it would put a hand-written frame codec on every relayed socket. The child's body and headers are dropped; nothing from the child but the status number crosses.Locationcannot be passed on), a child that never answered, or a close before any error still reach the caller as 502; the open timeout stays 504. If Deno ever rewords its message, the router falls back to today's 502, and the router tests against a realDeno.servechild fail on that toolchain bump.workspaceTokenRefusalHint) is kept, since an older host still answers 502.User-visible impact
MAX_PRE_ENROLL_FAILURES(3) attempts, exactly as it does against serve directly, instead of retrying the router's 502 as a serve restart for the 5-minute budget. No worker code change.Test Plan
integration/serve_host_workspace_router_test.ts: the 502 pin is replaced by a stand-in child that refuses by the credential and headers it receives (401 no/wrong bearer, 403 foreign Origin, 421 mismatched forwarded host, 429 busy withRetry-After, 503 draining). Each case asserts the caller's status through the host, the host's own JSON body, no child header, and exactly one child handshake. A good bearer is relayed after one handshake; a 301 child stays 502. Existing unreachable-502, timeout and hang-up tests kept.integration/serve_workspace_cli_sign_in_test.ts: a workspace refusing its exchanged token through the real router now yields the exact 401 login hint.--repeats=10.4a7f1d565; attestation posted.Docs:
design/surfaces/serve-workspaces.mdanddesign/enablers/remote-execution.mdupdated.🤖 Generated with Claude Code