Skip to content

fix: avoid duplicate errors when a desktop disconnects - #137724

Merged
steipete merged 1 commit into
mainfrom
codex/desktop-terminal-handle-cleanup
Sep 4, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/desktop-terminal-handle-cleanup

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Related: #136297 (cloud Desktop readiness and worker lifecycle repair).

Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR.

What Problem This Solves

Fixes an issue where users investigating a disconnected Desktop would see an additional, misleading noVNC state error in the browser console after the original stream failure. Both a server-initiated close and a malformed RFB message reproduce it: Tried changing state of a disconnected RFB object.

This was observed while investigating cloud CUA and WebVNC continuity. It does not explain or repair the initiating Mac stream closure.

Why This Change Was Made

DesktopClient owns one noVNC connection. Its terminal callback can synchronously cause the panel to dispose that connection again. The wrapper now retires its handle before calling the consumer, and a caller-initiated disposal is also one-shot. The existing panel, handoff, authentication, and error-reporting flows stay unchanged.

The dependency contract was inspected directly in installed noVNC 1.7.0: public disconnect enters the state machine, whose disconnected state is permanent. The terminal event is therefore the canonical point for recording retirement. Moving this guard into panel callers would duplicate the dependency policy and leave direct handle disposal unprotected.

Production: +9/-1 (net +8). The one lifecycle fact belongs in the existing dependency owner; no new abstraction or alternate cleanup path is added. Tests: +12/-1. Existing test cases are extended rather than duplicated. No dependency patch/version, configuration, persistent store, public protocol, timeout, or retry policy changes.

User Impact

The original Desktop failure and Reconnect action remain visible, while cleanup no longer adds a false state-transition error. Control takeover, credentials, and explicit source selection retain their current behavior.

Evidence

Candidate: fe2b3f5966a8d07c30ac1fd3f5a446ba3d05d016, based on main 5c353d56c2f44e50d52f8a1980957609e0ebe855.

  • Before the production repair, six owner cases failed on repeated/reentrant disposal, and both real-noVNC browser failure cases reproduced the console error.
  • After repair: 57 Desktop unit cases and 43 real-browser cases pass, including server close, malformed input, control handoff, credentials, clipboard framing, fullscreen, focused windows, and session placement changes.
  • The browser suite builds and loads the production Control UI/noVNC client. Its Gateway responses and RFB wire peer are scripted; this is not a new live cloud or cross-OS acceptance claim.
  • The complete three-file changed gate passes, including formatting, UI and core-test types, lint, i18n, dependency guards, and dead exports.
  • Independent Codex review found no actionable P0–P2 findings.

Commands:

node scripts/run-vitest.mjs ui/src/components/desktop/desktop-client.test.ts ui/src/components/desktop/desktop-panel.test.ts
node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/desktop-panel.e2e.test.ts ui/src/e2e/desktop-document-mode.e2e.test.ts ui/src/e2e/desktop-panel-fullscreen.e2e.test.ts
node scripts/check-changed.mjs -- ui/src/components/desktop/desktop-client.ts ui/src/components/desktop/desktop-client.test.ts ui/src/e2e/desktop-panel.e2e.test.ts

The before/after captures deliberately show the same original failure and Reconnect action. The console regression is independently asserted by the browser tests. Both captures contain synthetic test data only.

Before After
Before: original Desktop failure remains visible After: original Desktop failure remains visible without duplicate cleanup

Exact-head CI run 33823530266, attempt 2, passed, including the required openclaw/ci-gate, UI shards, browser shards, and real-Gateway browser suite. Attempt 1 had one cancelled core shard that never acquired a runner or executed a step; the failed-jobs-only retry acquired a runner and passed without changing code, workflows, or timeouts. The separate Mac close-provenance investigation and Windows provider-terminal wording mismatch remain open diagnostic work; neither is claimed fixed here.

Review disposition

The September 4, 01:08 UTC ClawSweeper review has no actionable code/security findings. Its four before-merge items and rank-up request all concern independent confirmation of the noVNC lifecycle premise. Confirmed directly against annotated tag v1.7.0, resolved to commit 63107bd06d9e1f6136ff21aeda8cd62cbf0d433e: core/rfb.js:864–868 rejects any transition from disconnected; line 911 stores the new state before lines 942–946 dispatch the disconnect event. The public disconnect method and complete state-machine function are byte-identical in our installed package and this upstream source. Full upstream file SHA256: c46dfefbf869eda0c6d06c5dd86c42e96fc8a77c125e91599a2cdf3841261564. The dependency links above now use that immutable commit and the precise guard line. Retain the existing owner-level retirement fact and its +8 production lines; this avoids duplicated policy in callers and protects repeated direct disposal as well as reentrant cleanup. No source change was needed after review.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui size: XS maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 00:52
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 3, 2026, 9:08 PM ET / September 4, 2026, 01:08 UTC.

ClawSweeper review

What this changes

The PR makes each Control UI desktop noVNC connection handle retire exactly once so panel cleanup cannot disconnect an already-terminated RFB connection.

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep open. The focused owner-level guard blocks the demonstrated reentrant disposal path, and current main does not contain it; the protected maintainer label also rules out automated closure. Independent confirmation of the referenced noVNC lifecycle contract remains unavailable in this sparse, DNS-isolated review environment.

Priority: P2
Reviewed head: fe2b3f5966a8d07c30ac1fd3f5a446ba3d05d016
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is narrowly scoped and source-supported, but independent noVNC contract inspection remains unavailable.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository state identifies this as a MEMBER-authored, maintainer-labeled PR, so the external-contributor proof gate does not apply; its supplied browser-harness evidence is consistent with the changed DesktopClient path but could not be independently opened because DNS is unavailable.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository state identifies this as a MEMBER-authored, maintainer-labeled PR, so the external-contributor proof gate does not apply; its supplied browser-harness evidence is consistent with the changed DesktopClient path but could not be independently opened because DNS is unavailable.
Evidence reviewed 6 items Introduced owner guard: The desktop client records retirement before invoking the consumer disconnect callback and makes returned-handle disposal one-shot.
Reentrant caller path: The panel’s disconnect callback synchronously enters its connection handoff, whose current-handle disposal calls the returned disconnect function.
Current main lacks the repair: Fetched main still forwards the RFB disconnect event before consumer cleanup and exposes raw rfb.disconnect through its handle; the PR head is not an ancestor of fetched main.
Findings None None.
Security None None.

How this fits together

The Control UI opens a WebSocket-backed noVNC desktop stream and passes a connection handle to the desktop panel. When noVNC reports termination, the panel disposes that handle while showing recovery UI, so the handle must not re-enter noVNC’s terminal state machine.

flowchart LR
  A[Desktop panel] --> B[Desktop client]
  B --> C[WebSocket stream]
  B --> D[noVNC RFB connection]
  D --> E[Terminal disconnect event]
  E --> F[Panel recovery callback]
  F --> G[Connection handle disposal]
  G --> B
Loading

Decision needed

Question Recommendation
Can a maintainer independently confirm that noVNC 1.7.0 treats its disconnect event as terminal before this lifecycle guard is accepted? Verify the noVNC contract: Confirm the linked v1.7.0 implementation or an equivalent authoritative source, then retain the owner-level guard.

Why: The code path and regression coverage are clear, but this review environment could not inspect the installed or upstream dependency source that establishes the terminal-state premise.

Before merge

  • Resolve merge risk (P1) - The one-shot guard relies on noVNC 1.7.0 terminal-disconnect semantics; direct upstream verification was blocked because this sparse checkout lacks the installed package and DNS access.
  • Resolve merge risk (P1) - Production code grows by 8 net lines for one lifecycle fact; that growth is justified only if the noVNC terminal-state contract is independently confirmed.
  • Complete next step (P2) - Provide an independently inspectable noVNC 1.7.0 lifecycle reference or source excerpt confirming that terminal disconnect is permanent.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source +8, Tests +11. Total +19 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 9 1 +8
Tests 2 12 1 +11
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 21 2 +19

Review metrics

Metric Value Why it matters
Production versus test LOC production +8 net; tests +11 net The production growth is confined to one connection-lifecycle state, while regression coverage exercises idempotent and reentrant disposal plus browser-visible diagnostics.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep retirement at the DesktopClient boundary, retain the reentrant unit and browser coverage, independently confirm the noVNC terminal-event contract, then merge once the exact-head CI gate is green.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep retirement at the DesktopClient boundary, retain the reentrant unit and browser coverage, independently confirm the noVNC terminal-event contract, then merge once the exact-head CI gate is green.

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

Yes, source-reproducible with high confidence: an RFB disconnect invokes the panel callback, which synchronously disposes the same handle through the handoff owner; current main forwards that disposal directly to noVNC.

Is this the best way to solve the issue?

Unclear pending direct dependency confirmation: the guard is at the correct lifecycle owner and avoids duplicating policy in panel callers, but the noVNC terminal-event premise could not be independently read in this environment.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3d30b3accb23.

Labels

Label changes:

  • add P2: This repairs a limited Control UI desktop-disconnect diagnostic path without evidence of data loss, security exposure, or core availability loss.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository state identifies this as a MEMBER-authored, maintainer-labeled PR, so the external-contributor proof gate does not apply; its supplied browser-harness evidence is consistent with the changed DesktopClient path but could not be independently opened because DNS is unavailable.

Label justifications:

  • P2: This repairs a limited Control UI desktop-disconnect diagnostic path without evidence of data loss, security exposure, or core availability loss.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository state identifies this as a MEMBER-authored, maintainer-labeled PR, so the external-contributor proof gate does not apply; its supplied browser-harness evidence is consistent with the changed DesktopClient path but could not be independently opened because DNS is unavailable.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Provide an independently inspectable noVNC 1.7.0 source or contract reference confirming that the disconnect event is terminal.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 7513017 into main Sep 4, 2026
301 of 303 checks passed
@steipete
steipete deleted the codex/desktop-terminal-handle-cleanup branch September 4, 2026 01:27
vincentkoc added a commit that referenced this pull request Sep 4, 2026
* origin/main:
  fix(git-hooks): keep unstaged bytes out of pre-commit formatting (#137723)
  test(gateway): drain session tool fixture cleanup (#137743)
  fix: avoid duplicate errors when a desktop disconnects (#137724)
  refactor: streamline temporary mention retention (#137714)
  fix(gateway): prevent hosted lifecycle crashes and self-waits (#137456)
  test(daemon): make managerless port fixture hermetic (#137692)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 4, 2026
steipete added a commit that referenced this pull request Sep 4, 2026
Desktop stream teardown discarded the observed WebSocket close code and the preceding owner cleanup trigger, leaving normal observer disposal indistinguishable from an unexpected transport close. Record bounded diagnostics once at the observer, broker, and node transport owners without changing forwarding or teardown behavior or logging peer payloads and credentials.

Move authenticated macOS snapshot mounts to controller-owned private Darwin temporary storage so external-volume builds use the same verified mount paths for build and cleanup. Preserve read-only source, signing, and cleanup ownership. Repair two native test synchronization boundaries: wait for an admitted reconnect before requesting its lease, and flush post-resize settings layout before sampling the prior pane.

Regression and sibling proof covers real socket closes, cancellation/backpressure, snapshot mount cleanup, signed Intel native installation, and real Linux, Windows, and macOS CUA/WebVNC flows. Successful runs do not explain the previously observed intermittent Mac close or historical-marker response; those remain named follow-ups with improved diagnostics.

Follow-up to #136297 and #137724.

Required exact-head CI passed: https://github.com/openclaw/openclaw/actions/runs/33849738091 . Native proof includes the original ordered SettingsWindowLayoutTests pair, all 2,082 app Swift Testing cases, isolated AppState cases, and 1,627 OpenClawKit cases. Both native build/test jobs passed. Separate optional shared-kit scans were still queued at landing preparation.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
Desktop stream teardown discarded the observed WebSocket close code and the preceding owner cleanup trigger, leaving normal observer disposal indistinguishable from an unexpected transport close. Record bounded diagnostics once at the observer, broker, and node transport owners without changing forwarding or teardown behavior or logging peer payloads and credentials.

Move authenticated macOS snapshot mounts to controller-owned private Darwin temporary storage so external-volume builds use the same verified mount paths for build and cleanup. Preserve read-only source, signing, and cleanup ownership. Repair two native test synchronization boundaries: wait for an admitted reconnect before requesting its lease, and flush post-resize settings layout before sampling the prior pane.

Regression and sibling proof covers real socket closes, cancellation/backpressure, snapshot mount cleanup, signed Intel native installation, and real Linux, Windows, and macOS CUA/WebVNC flows. Successful runs do not explain the previously observed intermittent Mac close or historical-marker response; those remain named follow-ups with improved diagnostics.

Follow-up to openclaw#136297 and openclaw#137724.

Required exact-head CI passed: https://github.com/openclaw/openclaw/actions/runs/33849738091 . Native proof includes the original ordered SettingsWindowLayoutTests pair, all 2,082 app Swift Testing cases, isolated AppState cases, and 1,627 OpenClawKit cases. Both native build/test jobs passed. Separate optional shared-kit scans were still queued at landing preparation.
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 maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS 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