Repository navigation
fix(controller): answer a deployment in progress with 503 on the Agent host - #6523
Conversation
…t host While a deployment replaces or activates an Agent's version, native-host HTTP admission refused an authorized caller with the generic 403. The Agent UI's reconnect probe reads 403 as a sign-in or access problem and offered "Reconnect in browser" until the new version served. Admission now names that state agent_transition (the availability status "unavailable") and the HTTP answer is the existing 503 DEPENDENCY_UNAVAILABLE, so the UI keeps reconnecting. Stopped and unsupported Agents, a deleting Agent and a Compute owner mismatch keep agent_unavailable and 403; a changed version keeps revision_changed and 403. Authorization is decided before availability, so callers without access get the same answer in every state; the new integration case checks that for a signed-out and a read-only caller.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesReturn HTTP 503 instead of 403 to authorized Agent-host requests while the Agent version is unavailable during deployment. Example: A signed-in Agent administrator's open tab probes GET /healthz while a replacement deployment stops its predecessor.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it addresses a source-confirmed reconnect problem still present on main, and review found no actionable correctness defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe controller authenticates Agent-host requests, checks exact-Agent permissions and lifecycle state, then either refuses the request or proxies it through the private gateway. flowchart TD
A[Agent browser tab] --> B[Controller admission]
B --> C[Session and exact Agent IAM]
C --> D[Agent availability]
D -->|Unavailable during deployment| E[HTTP 503]
D -->|Available| F[Private gateway proxy]
E --> A
F --> A
Technical reviewBest possible solution: Keep deployment refusals distinct from access denials within the existing native admission owner. Do we have a high-confidence way to reproduce the issue? Current-main admission returns 403 for deployment unavailability, and the maintained browser patch interprets 403 as access denial; the author also reports a regression test failing on base and passing on head, which this read-only review did not rerun. Is this the best way to solve the issue? The focused fix changes classification at the controller that owns the refusal, reuses the existing 503 response, and preserves permission checks and stopped-Agent behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against cea7d46c6956. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 18, 2026, 8:34 PM ET / November 19, 2026, 01:34 UTC (Revision 2). |
The outsider case compared whole responses across Agent states with only the request ID removed. Injected responses also carry the Date header, which changes every second, so the comparison failed whenever a second boundary fell between the available capture and a later one. Drop it too. Correct the stopped-Agent comment: the Agent UI still offers its sign-in panel there, and the panel's link gets the generic refusal, not a console page. Give the flow page changelog a real authoring-run ID and time.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Problem
On a production-shaped test install, a signed-in user with full access to an Agent had the Agent UI open while the Agent was redeployed or upgraded. For a few seconds the UI replaced the page with "Reconnect to the Gateway. Your sign-in may have expired, or your access may have changed. Reconnect in browser". It then recovered by itself. Nothing about the sign-in had changed.
The cause is in OCC. When its WebSocket upgrade fails, the Agent UI probes
GET /healthzon the Agent host and treats 401 or 403 as a sign-in or access problem. A 503 or any other failure leaves it on "Reconnecting". While a deployment replaces or activates the version (the native availability statusunavailable: an exclusive successor replacing the workload, a predecessor stopping, or a running Agent with no active version yet),requireAvailableNativeAdminTargetthrew the same refusal as for a stopped Agent. Native-host HTTP admission mapped it toagent_unavailableand answered the generic403 FORBIDDEN.Change
unavailablestatus with a new admission reason,agent_transition.requireAvailableNativeAdminTargetis split into the lookup and arequireAvailablecheck, sonativeAdminProxyContextcan see the status between the two. The console launch, confirm and redeem routes are unchanged.interceptNativeAdminHttpanswersagent_transitionwith the existing503 DEPENDENCY_UNAVAILABLEshape thatdependency_failurealready uses.http.completedrecordsnativeAdmissionReason: agent_transition, so a deployment is not logged as a dependency failure.closeReason: agent_transitionin the close audit. The browser never sees close reasons (the socket is closed); it sees an abnormal close and runs the probe above, which now gets 503.agent_unavailableand 403. A changed version keepsrevision_changed, its 403 and its "Agent version changed" page.No new response code, body field, header, flag or setting. Nothing was deleted.
Verification
New integration case in
tests/integration/native-admin-access.test.mjs. It covers an exclusive replacement with the predecessor stopping, then an explicit stop. The authorized caller gets 200, then503 DEPENDENCY_UNAVAILABLE, then today's generic403. A signed-out caller and a signed-in caller without Agent operate get the same whole answer (status, headers and body, request ID aside) in the available, replacing and stopped states. Only the available probe reaches the upstream.apps/controller/srcfrom main (b0fe1a2196): fails at the replacing probe,403 !== 503.Existing cases stay green, unchanged: the stop lease close reason
agent_unavailable(native-admin-session-postgres.test.mjs) and the version-changed 403 (JSON and HTML) in host-only exchange (native-browser-launch-postgres.test.ts).Head
08faf218bb: the outsider comparison now also ignores theDateheader, which changes every second; it previously could fail whenever a second boundary fell between captures. At this head on a remote test VM: the new case passes; format check and ESLint on the touched files are clean;staticandchecks-baseline-2pass.postgres-authwas not rerun, because this commit changes no source or Postgres test file.CI lanes run on a remote test VM at the first head (
50ba6e3c18), all passing:static: docs length, format and lint.checks-baseline-2: typecheck,native-admin-accessandnative-admin-upgrade-reset.postgres-auth:native-admin-session-postgresandnative-browser-launch-postgres.The other lanes do not run these files. GitHub CI follows on the PR.
Format check and ESLint on the touched files: clean. A misformatted control file made the format check fail.
Not done here: a real-install check. The next production-shaped install round must open the Agent UI, redeploy the Agent (and run an upgrade), and show "Reconnecting" without the sign-in panel until the new version serves. It must also show that the end of
occ agent stopstill shows the panel, as today.Risks
authorizeAgentAccess) runs before any lifecycle check ingetAuthorizedActiveAgentRevision, so a caller without access is refused before the deployment state is read. The new 503 is therefore reachable only by a caller whose access is already established, and the test shows signed-out and unauthorized answers are identical across states.occ agent stop. For a signed-in user with access, the panel's "Reconnect in browser" link then gets the generic JSON 403 refusal, not a console page:agent_unavailablematches none of the HTML refusal pages. Only a signed-out user is sent to the console. Giving this case a proper page is a follow-up, not part of this PR.unavailablestatus. An open Agent UI then stays on "Reconnecting" instead of offering the panel; the console shows the failed deployment.