Skip to content

fix(ui): stale tabs restore terminals without owners - #123660

Merged
steipete merged 9 commits into
mainfrom
codex/swless-stale-client-fix
Aug 14, 2026
Merged

steipete merged 9 commits into
mainfrom
codex/swless-stale-client-fix

Conversation

@steipete

@steipete steipete commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where already-open Control UI tabs could reconnect after a same-version Gateway deployment and restore a terminal with stale JavaScript that omitted its selected agent owner. The Gateway correctly rejected that ownerless terminal.open request, leaving service-worker-less browser contexts and native WebViews with a failed terminal.

Live evidence on deployed ee6c2cb50df086e83575753313fd5131afe186b6 showed a Control UI reconnect at 2026-08-14T11:55:47.067Z, followed by an ownerless terminal.open rejection at 11:55:48.510Z.

Why This Change Was Made

Control UI clients and the Gateway now exchange a bounded, exact build ID generated from the shared immutable build manifest. A same-origin bundled UI whose identity differs stays outside connected-only state drains, disables terminal availability, and performs one guarded reload; if that reload already ran, the existing refresh card remains visible and actionable.

Legacy Gateways retain package-version fallback. Separately hosted UIs skip comparison by origin, while configured same-origin UI roots explicitly advertise that they are independently built. The Gateway still never infers a missing terminal owner.

The mocked browser transport now closes and opens the Gateway socket cohort present at each offline/online transition. Synchronous replacement sockets survive offline and recover later. Private source-Vite suites explicitly pass HMR through the existing native WebSocket seam, so connectivity tests do not reload their own harness.

Production delta: +175/-13 lines (net +162), justified by the end-to-end artifact identity, reconnect admission boundary, and lifecycle-owned pending-worker fence. Tests and test support: +519/-16 lines (net +503).

User Impact

Operators can leave Control UI tabs and native terminal views open across same-version deployments. Stale bundled documents refresh before any terminal or other connected-only work drains, configured/custom roots remain independent, and a failed automatic refresh presents a visible recovery action instead of an ownerless terminal error.

Evidence

  • Exact-head CI at ff4a6a98f0b0a5487ec09e15a7d70555a9f8d047 passed all required checks: run 31835068360.
  • Exact build/startup proof passed in build-artifacts: Control UI startup JS 11 requests / 324.8 KiB gzip (limits 18 / 325.3 KiB), CSS 1 request / 41.4 KiB (limits 1 / 45.0 KiB); CLI median max RSS was 51.1/100 MB (--help), 368.8/425 MB (plugins list), 414.5/450 MB (status), and 348.8/500 MB (gateway status). Built-artifact checks passed 1,244 tests plus the TUI PTY lane.
  • Final socket/HMR owner repair: mock/service-worker units 16/16, source-locale E2E 2/2, optional memory Chromium 17/17, UI production/test types, formatting, oxlint, and git diff --check passed.
  • Final exact-head opaque behavior commands: terminal+service-worker E2E 6/6, UI lifecycle 119/119, and protocol/Gateway/version/tooling 30/30. The opaque runner exposes aggregate test output, so clause-level source-blind attribution remains a recorded proof gap.
  • Final full branch autoreview at ff4a6a98f0b0a5487ec09e15a7d70555a9f8d047: no accepted/actionable findings (0.94 confidence); final-patch review was also clean (0.99).
  • Protocol, generated build manifest, runtime resolver, browser handshake, Gateway store, overlay, and build-info tests: 257 passed on Blacksmith Testbox (run).
  • Exact verifier patch: formatting, core/UI production types, 109 focused unit/protocol/Gateway/UI tests, and terminal Chromium 5/5 passed (run).
  • Exact behavior contract: 102 UI tests plus terminal Chromium 5/5, including configured same-origin independence, passed (run).
  • Legacy/configured admission proof: 46 unit tests plus the formerly failing Workboard/model/plugins and terminal/About browser paths, 15/15 passed (run).
  • Pending-worker and cross-platform preview proof: macOS isolated A→B 3/3 and combined terminal+service-worker 6/6; owned AWS A→B 3/3 (cbx_19e93504e0aa, run_2821fa968692).
  • Service-worker-less/native-WebView Chromium proof: client build ID is sent, one reload is guarded, the refresh card remains visible, terminal availability stays false, and zero terminal.open calls escape; 4/4 passed (run).
  • Production two-build service-worker activation and owned terminal restoration: passed (run).

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts size: M maintainer Maintainer-authored PR labels Aug 14, 2026
@steipete steipete self-assigned this Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 14, 2026, 3:57 PM ET / 19:57 UTC.

ClawSweeper review

What this changes

The PR adds exact Control UI build IDs to the Gateway handshake and fences stale same-origin tabs before they restore terminal state.

Merge readiness

⚠️ Ready for maintainer review - 6 items remain

Keep open: the current head still has the two P1 compatibility blockers identified in the prior review, so it can fence release UIs permanently and cannot connect to strict older Gateways.

Priority: P1
Reviewed head: ff4a6a98f0b0a5487ec09e15a7d70555a9f8d047

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The reported real-behavior evidence is strong, but two concrete upgrade-compatibility defects still block merge.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: This maintainer-authored PR includes substantial recorded browser and deployment evidence; the external-contributor proof gate does not apply.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR includes substantial recorded browser and deployment evidence; the external-contributor proof gate does not apply.
Evidence reviewed 6 items Release identity remains timestamp-derived: The Gateway build manifest derives buildId from a fresh builtAt value unless an explicit ID is supplied.
Release workflow performs two UI builds: The npm release workflow runs pnpm build and later runs a standalone pnpm ui:build, with no shared explicit artifact ID; macOS also marks only its second build as release.
Legacy Gateway schema is strict: The PR base's client schema has no buildId property, and closedObject rejects additional properties, so a new client field is not backward-compatible by itself.
Findings 2 actionable findings [P1] Pin one release identity across both UI builds
[P1] Retry legacy Gateways without client.buildId
Security None None.

How this fits together

The Control UI connects to the Gateway and restores connected features such as terminal panels after the hello response. The new build identity is meant to stop an old browser bundle from draining connected state after a Gateway deployment.

flowchart LR
A[Open Control UI tab] --> B[Gateway connection]
B --> C[Hello build identity]
C --> D{UI artifact matches?}
D -->|yes| E[Restore connected state]
D -->|no| F[Reload and fence terminal]
F --> G[Visible refresh action]
E --> H[Owned terminal request]
Loading

Before merge

  • Pin one release identity across both UI builds (P1) - This repeats the prior P1: buildId incorporates a fresh builtAt, but the release workflow runs pnpm build and then a standalone pnpm ui:build without a shared explicit ID. The Gateway manifest and replacement UI therefore differ after deployment; the guarded reload reaches the same mismatch and leaves the client fenced. The macOS workflow also applies the release flag only to its second build.
  • Retry legacy Gateways without client.buildId (P1) - This repeats the prior P1: older Gateway schemas use a closed client object without buildId, while this plan always sends it. Such a Gateway rejects connect validation before it can return the version fallback, and handleConnectFailure never retries without the field. Detect that strict validation failure and make one bounded buildId-free reconnect attempt.
  • Resolve merge risk (P1) - Release packaging can serve a UI whose identity never equals the Gateway manifest, so the guarded reload leaves same-origin operators fenced behind the refresh card.
  • Resolve merge risk (P2) - A newer Control UI currently sends an unknown field to older strict Gateways, preventing the claimed legacy package-version fallback before hello.
  • Resolve merge risk (P1) - Production grows by 162 net lines for this bug fix; the cross-artifact contract justifies new surface, but obsolete version-only paths should be removed where the completed compatibility design permits.
  • Complete next step (P2) - The two mechanical P1 repairs are clear, but this protected maintainer PR needs its owner to update the release and protocol compatibility contract.

Findings

  • [P1] Pin one release identity across both UI builds — scripts/write-build-info.ts:108-121
  • [P1] Retry legacy Gateways without client.buildId — ui/src/api/gateway.ts:446-450
Agent review details

Security

None.

PR surface

Source +206, Tests +445, Other +14. Total +665 across 32 files.

View PR surface stats
Area Files Added Removed Net
Source 16 224 18 +206
Tests 15 456 11 +445
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 14 0 +14
Total 32 694 29 +665

Review metrics

Metric Value Why it matters
Production vs test delta production +162 net, tests/test support +459 net The added cross-artifact compatibility contract is substantial for a bug fix and needs the two missing upgrade paths resolved before it earns that added surface.

Stored data model

Persistent data-model change detected: database schema: packages/gateway-protocol/src/schema/frames.build-id.test.ts, serialized state: ui/src/e2e/terminal-embedded.e2e.test.ts, serialized state: ui/src/test-helpers/control-ui-e2e.mock-gateway.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #123660
Summary: The related merged PR only stabilizes a modal-focus E2E assertion and does not repair this PR's deployment or legacy-protocol compatibility paths.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Repair release and legacy compatibility (recommended)
    Share a single release artifact ID across each workflow's UI and Gateway outputs, then add a bounded buildId-free retry for strict legacy Gateway validation failures.

Technical review

Best possible solution:

Generate one workflow-owned artifact ID and pass it to every UI build and build-info invocation, then retry exactly once without buildId when an older strict Gateway rejects the additive client field; prove both release workflows and the old-server connection.

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

Yes: source establishes two high-confidence failure paths—two release commands derive different timestamped identities, and an older closed client schema rejects the newly unconditional buildId field.

Is this the best way to solve the issue?

No: exact artifact comparison is the right owner boundary, but the current branch lacks both a shared release identity and the required legacy-Gateway downgrade path.

Full review comments:

  • [P1] Pin one release identity across both UI builds — scripts/write-build-info.ts:108-121
    This repeats the prior P1: buildId incorporates a fresh builtAt, but the release workflow runs pnpm build and then a standalone pnpm ui:build without a shared explicit ID. The Gateway manifest and replacement UI therefore differ after deployment; the guarded reload reaches the same mismatch and leaves the client fenced. The macOS workflow also applies the release flag only to its second build.
    Confidence: 0.99
  • [P1] Retry legacy Gateways without client.buildId — ui/src/api/gateway.ts:446-450
    This repeats the prior P1: older Gateway schemas use a closed client object without buildId, while this plan always sends it. Such a Gateway rejects connect validation before it can return the version fallback, and handleConnectFailure never retries without the field. Detect that strict validation failure and make one bounded buildId-free reconnect attempt.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 36c440aa2b1e.

Labels

Label justifications:

  • P1: Same-version deployments can leave an already-open operator Control UI unable to restore its terminal, and the current release path can preserve that failure after reload.
  • merge-risk: 🚨 compatibility: The changed handshake must work with split release builds and already-shipped strict Gateway schemas.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR includes substantial recorded browser and deployment evidence; the external-contributor proof gate does not apply.

Evidence

What I checked:

  • Release identity remains timestamp-derived: The Gateway build manifest derives buildId from a fresh builtAt value unless an explicit ID is supplied. (scripts/write-build-info.ts:108, ff4a6a98f0b0)
  • Release workflow performs two UI builds: The npm release workflow runs pnpm build and later runs a standalone pnpm ui:build, with no shared explicit artifact ID; macOS also marks only its second build as release. (.github/workflows/openclaw-npm-release.yml:226, ff4a6a98f0b0)
  • Legacy Gateway schema is strict: The PR base's client schema has no buildId property, and closedObject rejects additional properties, so a new client field is not backward-compatible by itself. (packages/gateway-protocol/src/schema/frames.ts:39, 621220aea9ba)
  • Client always sends the incompatible field: The browser connection plan unconditionally includes client.buildId, while its connect-failure handler contains no one-time legacy retry that removes it. (ui/src/api/gateway.ts:449, ff4a6a98f0b0)
  • Prior blockers are unchanged: The release and browser connection paths are unchanged from the previous ClawSweeper-reviewed head, so both earlier P1 findings remain applicable. (ui/src/api/gateway.ts:449, ff4a6a98f0b0)
  • Area history: Current-main file history and shortlog identify Peter Steinberger as the dominant recent contributor across the Control UI Gateway store, browser client, and build-info surface. (ui/src/app/gateway-store.ts:105, 2bc1699a37fb)

Likely related people:

  • steipete: Current-main history shows Peter Steinberger as the dominant contributor across the affected Control UI Gateway and build-info files. (role: recent area contributor; confidence: high; commits: 2bc1699a37fb, 3c81eb49257e; files: ui/src/app/gateway-store.ts, ui/src/api/gateway.ts, scripts/write-build-info.ts)
  • Jason (Json): Recent history of the Gateway store includes the Control UI connection-state repair commit ab4761f. (role: adjacent Control UI state contributor; confidence: medium; commits: ab4761f3fc9a; files: ui/src/app/gateway-store.ts)

Rank-up moves

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

  • Pass a single explicit artifact ID through every release build and add release-workflow coverage.
  • Add an old strict-Gateway connection test proving the one-time buildId-free retry.

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.

History

Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-14T13:13:32.220Z sha 9de37ea :: found issues before merge. :: [P1] Preserve one identity across split release builds | [P1] Skip comparison for configured same-origin Control UI roots | [P1] Retry without buildId for legacy Gateways
  • reviewed 2026-08-14T13:39:19.859Z sha 47b7e0a :: needs changes before merge. :: [P1] Preserve one identity across split release builds | [P1] Retry legacy Gateways without buildId
  • reviewed 2026-08-14T14:17:18.494Z sha 20ce6e2 :: found issues before merge. :: [P1] Share one identity across split release builds | [P1] Preserve legacy Gateway connections without client buildId
  • reviewed 2026-08-14T14:55:44.240Z sha 143b41d :: needs changes before merge. :: [P1] Share one identity across split release builds | [P1] Retry legacy Gateway connections without buildId
  • reviewed 2026-08-14T15:19:22.774Z sha f47eeda1526755427592c383c0680def88ef2c96 :: found issues before merge. :: [P1] Share one identity across split release builds | [P1] Retry legacy Gateway connections without buildId
  • reviewed 2026-08-14T15:29:53.218Z sha f47eeda1526755427592c383c0680def88ef2c96 :: needs changes before merge. :: [P1] Share one identity across split release builds | [P1] Retry legacy Gateway connections without buildId
  • reviewed 2026-08-14T15:46:23.731Z sha eb51831 :: found issues before merge. :: [P1] Pin release identity across the second Control UI build | [P1] Retry a legacy Gateway without client.buildId
  • reviewed 2026-08-14T15:56:06.073Z sha 42e08b4 :: found issues before merge. :: [P1] Pin release identity across standalone UI builds | [P1] Retry legacy Gateways without client build ID

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 14, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 14, 2026
@steipete
steipete force-pushed the codex/swless-stale-client-fix branch from f47eeda to eb51831 Compare August 14, 2026 15:38
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 14, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 14, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 14, 2026
@steipete
steipete merged commit 58ab589 into main Aug 14, 2026
191 checks passed
@steipete
steipete deleted the codex/swless-stale-client-fix branch August 14, 2026 20:19
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 15, 2026
* fix(ui): fence stale same-version clients by build

* test(ui): satisfy build identity lint guards

* fix(ui): complete build identity fencing

* chore: leave release notes to release prep

* test(ui): align build identity fixtures

* fix(ui): fence reconnects on pending worker

* test(ui): stabilize cross-platform update proof

* test(ui): satisfy service worker lint

* test(ui): preserve offline socket cohorts
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 gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant