Skip to content

fix(controller): answer a deployment in progress with 503 on the Agent host - #6523

Merged
freeqaz merged 2 commits into
mainfrom
fix/native-admin-transition-503
Nov 19, 2026
Merged

freeqaz merged 2 commits into
mainfrom
fix/native-admin-transition-503

Conversation

@freeqaz

@freeqaz freeqaz commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

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 /healthz on 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 status unavailable: an exclusive successor replacing the workload, a predecessor stopping, or a running Agent with no active version yet), requireAvailableNativeAdminTarget threw the same refusal as for a stopped Agent. Native-host HTTP admission mapped it to agent_unavailable and answered the generic 403 FORBIDDEN.

Change

  • Native-host admission names the unavailable status with a new admission reason, agent_transition. requireAvailableNativeAdminTarget is split into the lookup and a requireAvailable check, so nativeAdminProxyContext can see the status between the two. The console launch, confirm and redeem routes are unchanged.
  • interceptNativeAdminHttp answers agent_transition with the existing 503 DEPENDENCY_UNAVAILABLE shape that dependency_failure already uses. http.completed records nativeAdmissionReason: agent_transition, so a deployment is not logged as a dependency failure.
  • WebSocket: refused upgrades still close without an HTTP response. A lease renewal during a deployment now records closeReason: agent_transition in 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.
  • Unchanged: stopped and unsupported Agents, a deleting Agent and a Compute owner mismatch keep agent_unavailable and 403. A changed version keeps revision_changed, its 403 and its "Agent version changed" page.
  • Docs: the native admin flow, the reference and the deploy guide's troubleshooting now say a deployment answers 503.

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, then 503 DEPENDENCY_UNAVAILABLE, then today's generic 403. 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.

    • With the fix: passes.
    • With apps/controller/src from 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 the Date header, 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; static and checks-baseline-2 pass. postgres-auth was 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-access and native-admin-upgrade-reset.
    • postgres-auth: native-admin-session-postgres and native-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 stop still shows the panel, as today.

Risks

  • Outsider oracle: authorization (authorizeAgentAccess) runs before any lifecycle check in getAuthorizedActiveAgentRevision, 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.
  • The sign-in panel still appears in these cases:
    • A stopped Agent, including at the end of 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_unavailable matches 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.
    • With host-only exchange sessions, a changed version after a redeploy. The handle is bound to the version it was opened on, so the user has to reopen the Agent. "Reconnect in browser" leads to the "Agent version changed" page.
  • A deployment that fails while the Agent should be running stays in the same unavailable status. An open Agent UI then stays on "Reconnecting" instead of offering the panel; the console shows the failed deployment.

…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.
@freeqaz
freeqaz requested a review from a team as a code owner November 19, 2026 01:07
@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Return 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.

  • Before: HTTP 403 makes the tab offer “Reconnect in browser,” suggesting sign-in or access changed.
  • After: HTTP 503 lets the tab keep reconnecting while the replacement becomes available.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch is focused and source-consistent, with meaningful integration coverage; shipped-behavior proof does not yet support a pass.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An authorized user sees a sign-in/access recovery prompt during an ordinary Agent redeployment even though their session and permissions remain valid.
Reason: The maintainer-authored direction repairs misleading recovery behavior with a small change in the existing owner; stopped-Agent recovery remains a separately acknowledged limitation.

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
Reviewed head: 08faf218bbb1900cd801e75bef6308f63980aafe

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Missing shipped-runtime evidence is an already-open Agent tab receiving 503 during redeploy or upgrade, remaining on Reconnecting, and recovering when the new version serves while explicit Stop retains its existing refusal.
Agent review details

How this fits together

The 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
Loading

Technical review

Best 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

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • kevinlin-openai: Raw commit 6ba4cce adds apps/controller/src/http/native-admin.ts:534 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6ba4cceaa1b0; files: apps/controller/src/http/native-admin.ts)
  • Kimi Yu: Raw commit 9c83629 adds apps/controller/src/http/native-admin.ts:925 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9c83629f9327; files: apps/controller/src/http/native-admin.ts)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Deployment briefly shows a misleading sign-in/access prompt in an already-open Agent tab, which recovers when the deployment serves.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-19T01:21:04.432Z sha 50ba6e3 :: needs maintainer review before merge. :: none

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.
@freeqaz

freeqaz commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@freeqaz
freeqaz merged commit 67c518f into main Nov 19, 2026
43 of 45 checks passed
@freeqaz
freeqaz deleted the fix/native-admin-transition-503 branch November 19, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant