Skip to content

fix: stop reconnect loops after Gateway access is revoked - #197299

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-access-inactive-admit-then-revoke-loop-20260919
Nov 11, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-access-inactive-admit-then-revoke-loop-20260919

Conversation

@steipete

@steipete steipete commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes repeated failed turns when a connected client's access authority ends: post-connect 4001 closes previously reconnected automatically and hid different invalidation causes behind the same inactive-account message.

User Impact

Terminal access failures now show the existing access-denial recovery screen and wait for an explicit Connect action. Recognized policy transitions permit fresh admission with a minimum 30-second delay and existing jitter/backoff. Handshake admission and live enforcement remain fail closed; revoked work never regains authority.

Why This Change Was Made

The access owner records a bounded, identity-free cause before invalidation reaches clients. GatewayOperatorAccessDeniedError, handshake details, and 4001 close reasons/logs distinguish grant revocation, profile failure, plugin retirement, and unavailable or failed policy checks. Unknown failures remain terminal. Both client adapters use the same closed cause contract, while unrelated closes and the native client's existing clean pre-hello retry retain their behavior.

This does not identify the original shared invalidation trigger. The diagnostic distinction lets subsequent observations distinguish profile publication/fencing from plugin lifetime retirement. There are no configuration, cache, or database schema changes. The documented fail-closed Gateway-ingress boundary remains intact; retry is fresh admission, never restored authority for a revoked run.

Evidence

Focused regressions fail on the original owner/client paths and pass with this change. The trusted-proxy fixture covers inactive required access, missing policy, a briefly unavailable policy callback, retained independent grants, coded revocation, profile alias retirement, and staff access. Shared-owner fixtures invalidate two synthetic people together.

  • Final owner/trusted-proxy/recovery selection: 17 tests passed, including two-user quiescence before lifecycle abort. Final extraction-contract tests: 23 passed; native/protocol/retry selection: 71 passed; browser unit/store selection: 50 passed. The earlier broader client/protocol selection also passed all 124 cases.
  • Final native compatibility replay: all 95 existing client tests and 25 native authentication tests passed, including clean pre-hello retry and post-connect access denial.
  • Chromium production-bundle E2E: all 4 scenarios passed; the latest replay took 60.14 s under concurrent build load (earlier serial proof: 20.91 s), covering handshake denial/unavailability, terminal post-connect denial, manual recovery, and the transient 30-second minimum retry interval. The terminal regression reproduces an unwanted second connection before the fix.
  • Independent Codex review found no actionable P0–P2 issues after the native call consumer and compatibility tests were included.
  • pnpm check:changed --base 3a6cc6597d1d1d32a4bef83fd3041fedf5f48e76 completed on the final head: every check passed except 57 production plus 32 full-tree dead-export signatures, reproduced identically on exact parent 3a6cc6597d1d1d32a4bef83fd3041fedf5f48e76, with zero added/removed signatures. These are main regressions, not noise; attribution is retained below. Other changed checks, including typechecks, UI boundaries, schema guards, and line allocations, passed.

Healthy-owner overhead uses the existing committed access-authority callback benchmark: 40 real plugin instances, 64 caller scopes, 1/2/4/8 checks per operation, five paired samples with separate A/A controls and timing/allocation passes. Assertion and scope-entry counts are unchanged.

Checks/op Median wall, before → after (ms/100k ops) Thread CPU (ns/op) Sampled allocation (B/op)
1 192.035 → 189.857 1897.82 → 1895.87 3943.54 → 3995.94
2 340.962 → 342.334 3399.84 → 3419.03 7239.16 → 7207.20
4 649.474 → 647.108 6479.65 → 6449.24 13663.75 → 13591.20
8 1325.619 → 1285.369 12737.79 → 12712.75 26673.71 → 26706.82

Final CPU changes range from -0.5% to +0.6%; sampled allocation from -0.5% to +1.3%. The one-check allocation increase (+52.4 B/op) is retained, as is the two-check wall p95 increase of 1.3%. Separate A/A CPU medians varied by -2.1% to +0.5%; host load ranged 16.9–26.3. This is an in-memory owner measurement, not a performance improvement claim. Production-shaped 35 GiB/thousands-session/62k-file btrfs proof remains uncovered: existing scale drivers do not exercise these auth failures against their storage. No unused synthetic ballast or production data was used. Production confirmation requires the new cause codes in subsequent 4001s after deployment.

The first CI run found a missing extracted-wrapper dependency and a startup-size overage. The repaired candidate folds the codec into the existing connect-error contract, deleting the added module/re-export edge; all 23 extraction tests pass. Native quiescence now has an explicit cause regression. The final-head CI performance gate passes: startup gzip 91,847 → 92,051 B (+204), below the unchanged 92,137 B limit, with 3 requests before and after. Local macOS startup gzip is 92,142 B, five bytes above that limit; this is retained as a local measurement, not claimed as a local pass. The initial CI candidate was 92,292 B versus its base's 91,847 B. Exact-parent local startup is 91,905 B. CSS totals are identical on the exact parent and candidate (326,942 B gzip / 1,686,681 B raw); the comparison contract permits holding that inherited overage. No performance budget was increased.

Production LOC grows by 150 for the missing shared diagnostic contract and its owner/transport integration; tests add 257 lines, documentation 21, and test allocation configuration 2. No new access scan, cache, or authority check is introduced.

Inherited dead-export attribution on the exact parent

The 89 signatures match the exact-parent replay. Introducers were traced through the exported symbols and their owner history:

Family Introducing commit / PR
Knowledge 9b7dcdc7a66dc1bbcb0767b8109e798eb826954e / #196767
Telegram b22f35f7ed76552778bc185cc65a6177e8ad8b02 / #196991
Lease 2c4e34a72f490c710bc155319fcabf872f482b3e / #196724
Rebind 5f2f21a7ee193fdd4aa8ac42a407eefc04905255 / #196388
Model/tool/session-auth/OOM facades 625945b7ae01d5eea91aba5285da1a327b2a5f9f / #192552
Provider auth/catalog f63e5cd0f6d38f1d0438978255d9e244183864c3 / #190205
Provider failover/external profiles 964fa991c0aff81e2ae46a0c9f99ebc0ab349d1a / #132716
External auth forwarding 071f606eae77a13f6c4c161da009dd2ba31a1c10 / #139911
Modern reference 33d8f24c9926f8b291b71785c5b4dea4181a8128 / #129184
Runtime plugin forwarding a7436c8b4a93bff59d099661d2b206bb0627ac2b (direct commit)
Provider auth types cf1ae7bb6a729a7f13a28ca2ef9d6f108c00566f / #190544
Summary headings c7152f3bda8e52c24fc2fda83911e7e1c24fb0f2 / #196207
MCP helpers 80ba593b8b14bb3f5ddd6634a92805e04707b25c / #196252
Billing decoration 56617cd00086481212d29745ed71f5feb8a40b9e / #191326
Keyfile 37a3b162a0c58aaceb1634aaef726d0e178a529c / #196380

Separate main repairs #197260, #197271, and #196862 have landed. This PR does not duplicate those repairs.

Before: terminal access loss repeatedly reconnects

After: access denial is visible and automatic reconnect stops

@clawsweeper

clawsweeper Bot commented Nov 11, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime plugin: file-transfer size: L labels Nov 11, 2026
@steipete
steipete marked this pull request as ready for review November 11, 2026 17:07
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T17:46:48.001661Z 1d48cc6 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 1d48cc6bf8a37a15f098d1e699b71e59b5e76c4b
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/server/ws-connection/authenticated-request-dispatch.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server/ws-connection/connect-operator-access.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server/ws-connection/connect-session.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@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 backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 11, 2026
@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR records access-loss causes and stops terminal reconnects while pacing retries for known policy transitions.

Example: A connected visitor loses their access grant and receives WebSocket close 4001.

  • Before: The client reconnects automatically after access is revoked.
  • After: The browser shows “No access to this Gateway” and waits for Connect; plugin retirement instead permits fresh admission after at least 30 seconds.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, coherent patch with no actionable findings; supplied runtime evidence covers the visible browser result more strongly than the combined server-client flow.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; inspected production-bundle screenshots show visible denial recovery, while separate Gateway and client fixtures support cause propagation and retry behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Clients keep reconnecting after their access ends, obscuring the denial and its recovery action.
Reason: The maintainer-authored direction resolves a concrete client lifecycle gap while preserving fail-closed admission and retained-run revocation.

Merge readiness

✅ Ready for maintainer review

This PR addresses a distinct post-connect reconnect loop that remains on main; no actionable introduced defect was found.

Priority: P2
Reviewed head: 1d48cc6bf8a37a15f098d1e699b71e59b5e76c4b

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: A combined real-Gateway revocation through the browser or native client is not demonstrated; browser screenshots and E2E use a mock Gateway, with server enforcement covered separately.
Agent review details

How this fits together

Gateway access owners enforce profile and plugin grant lifetimes, then send denial details to the shared protocol client and its browser and Node adapters.

flowchart LR
  A[Profile and plugin lifetimes] --> B[Gateway access owner]
  B --> C[Handshake denial or socket close]
  C --> D[Shared error contract]
  D --> E[Browser and Node adapters]
  E --> F[Pause or paced fresh admission]
Loading

Technical review

Best possible solution:

Keep cause recording in the existing access owners and retry classification in the shared protocol contract, with every retry undergoing fresh admission.

Do we have a high-confidence way to reproduce the issue?

Main's post-connect 4001 close lacks a classified connection error, allowing automatic retry; the supplied regressions target that path, but this read-only review ran no target code.

Is this the best way to solve the issue?

The change is a focused repair using existing authorization, protocol, and adapter owners; it addresses reconnect behavior without claiming to identify the original shared invalidation trigger.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against da5333972ac1.

Provenance checked

  • Shared client lifecycle and close metadata keeps the original intent (7c9b8ba: Consolidate browser and Node protocol lifecycle while retaining transport-specific policy.)
  • Access-denial reconnect policy changes intended behavior with a stated reason (799586f: Pause access-denied handshake retries and expose explicit recovery; this PR explains its narrow transient-cause exceptions.)
  • Profile, grant, and plugin lifetime enforcement keeps the original intent (552b54b: End captured visitor authority after revocation, expiry, or identity loss while preserving independently authorized access.)
  • Plugin assertion binding keeps the original intent (c258ea6: Reuse the bound callback without caching authorization or changing live plugin-scope checks.)
  • Browser close recovery keeps the original intent (0d45e40: Detect dead links and let the transport retire sockets and recover visibly.)
  • Recovered grant checking keeps the original intent (001d2a8: Retain the original authority and assert it after other policy callbacks rather than reconstructing it repeatedly.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current main retains the missing post-connect behavior: Main sends the uncoded access-denial close, while the introduced diff teaches both adapters to classify it and coded 4001 closes; existing handshake denial handling does not cover this path. (src/gateway/server/ws-connection/connect-operator-access.ts:58, da5333972ac1)
  • Bounded diagnostic and retry contract: Seven closed causes share one existing protocol owner; only three permit retries, with a 30,000 ms floor, and uncoded deployed denials remain terminal. (packages/gateway-protocol/src/connect-error-details.ts:14, 1d48cc6bf8a3)
  • Live enforcement remains authoritative: Failure causes are recorded before abort propagation; profile checks, plugin assertions, irreversible invalidation, and request rejection remain in the existing owners. (src/gateway/operator-access-policy.ts:200, 1d48cc6bf8a3)
  • Proof inspected with its stated boundary: Both downloaded screenshots were inspected and show reconnecting before and the denial screen afterward; the author's discussion explicitly identifies the browser Gateway as mocked and separates real-server revocation coverage. (ui/src/e2e/gateway-connect-denial.e2e.test.ts:13, 1d48cc6bf8a3)
  • Previous blockers resolved: The codec now resides in the existing wrapper-inventoried error-details module, and the final-head control-ui-performance job reports success without a budget increase. (packages/gateway-protocol/src/connect-error-details.ts:14, 1d48cc6bf8a3)
  • Direction and compatibility tradeoff accepted: The maintainer-authored PR explicitly chooses manual recovery for terminal failures and paced fresh admission for known policy transitions; no additional product approval is needed. (1d48cc6bf8a3)

Likely related people:

  • Peter Steinberger: Raw commit 799586f adds packages/gateway-client/src/reconnect-policy.ts:20 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 799586fa23f9; files: packages/gateway-client/src/reconnect-policy.ts)
  • Shakker: Raw commit 552b54b adds src/gateway/operator-access-policy.ts:7 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 552b54b86c13; files: src/gateway/operator-access-policy.ts)

PR surface

Source +150, Tests +257, Docs +21, Other +2. Total +430 across 24 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 13 221 71 +150
Tests 8 261 4 +257
Docs 2 21 0 +21
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 24 505 75 +430

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: The fix improves recovery after access loss without changing ordinary authorized operation.
  • merge-risk: 🚨 compatibility: Client retry behavior and the optional plugin diagnostic contract change; the maintainer-authored direction explicitly accepts terminal pauses and narrowly permitted transient retries.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

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 (2 earlier review cycles)
  • reviewed 2026-11-11T17:26:59.886Z sha 75c9cc8 :: blocked before merge. :: [P2] Include the new protocol module in the wrapper inventory
  • reviewed 2026-11-11T17:58:40.264Z sha 1d48cc6 :: needs maintainer review before merge. :: none

Reviewed November 11, 2026, 1:06 PM ET / 18:06 UTC (Revision 3).

Keep the diagnostic codec in its existing protocol owner, preserve the received close message, and identify quiesced plugin lifetimes before lifecycle abort. Remove the extra extraction dependency and a redundant terminal-set guard. Keep access enforcement and the transient retry allowlist unchanged.
@steipete

Copy link
Copy Markdown
Contributor Author

Addressed both open items on final head 1d48cc6bf8a37a15f098d1e699b71e59b5e76c4b:

  1. Extracted wrapper dependency: removed the separate protocol module and folded the small cause contract into the existing error-details owner, lines 14–71. That file is already included in the wrapper inventory, line 2884. Both failing extraction regressions now pass; the focused tooling selection passes 23 tests. No additional inventory entry or runtime module is needed.

  2. Performance merge risk: the original startup increase was attributable to this PR and has been repaired. The final-head CI performance job passes: startup JavaScript gzip is 91,847 → 92,051 bytes (+204), below the unchanged 92,137-byte enforcement limit, with 3 requests before and after. The original candidate was 92,292 bytes. No baseline or budget was raised. CSS warnings remain inherited: final CI reports 326,931 gzip / 1,686,650 raw bytes, unchanged against its comparison base. The checker, lines 369–374 preserves this base-comparison contract. For transparency, the local macOS build measured 92,142 startup bytes (5 bytes above the fixed limit); the canonical Linux CI result above is the passing gate, not a claim that the local size check passed.

The evidence boundary is explicit: the trusted-proxy Gateway fixture, lines 510–548 exercises real Gateway grant-revocation close emission; the two-person owner fixture, lines 14–82 covers shared profile/grant/retired/quiescing-instance causes. Native and browser client regressions separately cover terminal and paced recovery. The four browser E2E cases use a mock Gateway; the screenshots are not claimed as a combined real-Gateway/browser integration test. The original shared production trigger remains unproven pending coded-close evidence after deployment.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. labels Nov 11, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 11, 2026
@steipete
steipete merged commit 7154e4e into main Nov 11, 2026
186 checks passed
@steipete
steipete deleted the steipete/perf-micro-access-inactive-admit-then-revoke-loop-20260919 branch November 11, 2026 18:15
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 12, 2026
…97299)

* fix: stop reconnect loops after Gateway access is revoked

* fix: keep access diagnostics in the shared error contract

Keep the diagnostic codec in its existing protocol owner, preserve the received close message, and identify quiesced plugin lifetimes before lifecycle abort. Remove the extra extraction dependency and a redundant terminal-set guard. Keep access enforcement and the transient retry allowlist unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. plugin: file-transfer proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed size: L 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