Skip to content

refactor(ui): centralize gateway page lifecycle - #118243

Merged
steipete merged 5 commits into
mainfrom
refactor/ui-gateway-page-controller
Aug 3, 2026
Merged

steipete merged 5 commits into
mainfrom
refactor/ui-gateway-page-controller

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Control UI pages independently owned the same gateway subscription, reconnect identity, request-generation, route-provenance, and initial-load lifecycle. The repeated implementations had already drifted in naming and made same-client reconnect/source-replacement correctness page-specific.

Why This Change Was Made

This promotes the proven Usage page binding design into GatewayPageController, composed with the existing non-Lit createGatewayConnectionLifecycle epoch primitive. Nine pages now share the controller: Usage, Nodes, Skills, Tasks, Worktrees, Channels, Cron, Agents, and Plugins.

The controller owns exact gateway source binding, separate source/client identity versus connection transitions, request capture/currentness, exact route-data provenance, reusable detach/reattach behavior, and optional focus/visibility activation. Usage keeps its TTL and interrupted-refresh policy page-local. Page-specific identity signals such as channel pairing auth and plugin icon auth remain with their owners.

The migration also replaces Tasks, Cron, Usage, and Sessions scope-observer copies with one persistent watchAgentScope, moves Nodes' repeated server-field resets onto a connection-owned state object, and removes local agent loading/error mirrors from Skills and Agents.

User Impact

No rendering or RPC behavior changes are intended. Reconnects, provider-source replacement, agent scope changes, route preloads, and stale async completions retain their existing behavior through one lifecycle vocabulary. Production code is net 144 lines smaller; tests are counted separately.

Evidence

  • OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree node scripts/run-vitest.mjs ui/src/lit/gateway-page-controller.test.ts ui/src/lib/agents/watch-agent-scope.test.ts ui/src/lib/gateway-connection-lifecycle.test.ts ui/src/pages/usage/usage-page.test.ts ui/src/pages/usage/refresh-policy.test.ts ui/src/pages/tasks/tasks-page.test.ts ui/src/pages/worktrees/worktrees-page.test.ts ui/src/pages/nodes/nodes-page.test.ts ui/src/pages/channels/channels-page.test.ts ui/src/pages/cron/cron-page.test.ts ui/src/pages/agents/agents-page.test.ts ui/src/pages/plugins/plugins-page.test.ts ui/src/pages/plugins/plugins-page.routing.test.ts ui/src/pages/sessions/sessions-page.test.ts ui/src/pages/gateway-source-replacement.test.ts — 15 files, 172 tests passed on exact head.
  • git diff --check origin/main...HEAD — passed.
  • Targeted oxlint on Nodes and Usage lifecycle surfaces — passed with warnings denied.
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted — final Codex review clean; no accepted/actionable findings.
  • Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/30770483020 — relevant checks green.
  • Production LOC: +821 / -965 = net -144. Test LOC: +416 / -192 = net +224.

@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Aug 2, 2026
@steipete
steipete marked this pull request as ready for review August 2, 2026 22:13
@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 3, 2026, 1:21 AM ET / 05:21 UTC.

ClawSweeper review

What this changes

This PR replaces nine Control UI pages’ separate Gateway subscription, reconnect, and stale-request handling with a shared GatewayPageController, while retaining page-specific loading policies.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 4 items remain

The shared controller follows the existing connection-epoch contract and the changed pages retain targeted stale-request and source-replacement coverage; no discrete patch defect was found. This PR remains necessary because current main does not contain its head, but merge should wait for inspectable after-fix browser proof of reconnect and gateway-source replacement behavior.

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

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The controller and regression coverage are coherent, but merge readiness is capped by missing real browser behavior proof for the shared availability path.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR provides focused tests and CI, but no inspectable after-fix browser recording, runtime trace, live output, or redacted logs for the reconnect/source-replacement behavior; add that proof and redact private endpoints, IPs, and credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR provides focused tests and CI, but no inspectable after-fix browser recording, runtime trace, live output, or redacted logs for the reconnect/source-replacement behavior; add that proof and redact private endpoints, IPs, and credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Current-main check: The PR head is not an ancestor of origin/main, and origin/main is not an ancestor of the PR head, so the refactor is neither already implemented on current main nor merely behind it.
Shared lifecycle owner: The controller binds the exact Gateway source, transitions the established connection lifecycle, invalidates stale work on source or connection changes, and only invokes page initialization after a connected snapshot.
Existing epoch contract: The pre-existing lifecycle primitive invalidates a scope when either the client identity or connected state changes; the new controller composes that primitive rather than introducing a parallel request-currentness rule.
Findings None None.
Security None None.

How this fits together

Control UI data pages consume an application Gateway source that can reconnect or be replaced while a page has requests in flight. The new controller converts Gateway snapshots into a shared connection epoch and then lets each page refresh, clear state, or ignore stale results using that common lifecycle boundary.

flowchart LR
  A[Application Gateway source] --> B[Gateway snapshot]
  B --> C[Gateway page controller]
  C --> D[Connection epoch and request scope]
  C --> E[Page-specific refresh policy]
  D --> F[Data requests and subscriptions]
  E --> F
  F --> G[Control UI page state]
  G --> H[Rendered dashboard page]
Loading

Decision needed

Question Recommendation
After the contributor supplies browser-level reconnect and source-replacement proof, should the Control UI lifecycle owner approve this controller as the canonical boundary for the nine migrated pages? Request browser proof, then approve: Keep the controller architecture and require a redacted recorded or diagnostic browser run showing a migrated page recover from reconnect and source replacement before final approval.

Why: The patch is a broad shared availability boundary and is protected with the maintainer label; automated source review can assess the contract and tests but cannot substitute for owner acceptance of the browser-level lifecycle behavior.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR provides focused tests and CI, but no inspectable after-fix browser recording, runtime trace, live output, or redacted logs for the reconnect/source-replacement behavior; add that proof and redact private endpoints, IPs, and credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - A lifecycle regression in the shared controller can leave any of the nine migrated dashboard pages stale, empty, or repeatedly loading after reconnect or provider-source replacement; focused tests reduce that risk, but no inspectable browser-level after-fix evidence demonstrates the real page flow.
  • Complete next step (P2) - The protected maintainer label and missing real behavior proof require owner review rather than an automated repair; no concrete code defect was found to dispatch.
Agent review details

Security

None.

PR surface

Source -144, Tests +224. Total +80 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 15 825 969 -144
Tests 6 416 192 +224
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 1241 1161 +80

Review metrics

None.

Stored data model

Persistent data-model change detected: persistent cache schema: ui/src/pages/usage/refresh-policy.test.ts, serialized state: ui/src/pages/sessions/sessions-page.ts, unknown-data-model-change: ui/src/pages/sessions/sessions-page.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Prove the shared reconnect path before merge (recommended)
    Capture redacted browser-level evidence that a migrated page reconnects and that a replacement Gateway source cannot display stale prior-source data.
  2. Accept test-only lifecycle coverage
    Merge based on the focused test and CI evidence while accepting that the shared runtime transition was not demonstrated in a browser.
  3. Pause the centralization
    Keep the PR open or split it if browser proof exposes page-specific behavior that cannot safely share this controller.

Technical review

Best possible solution:

Keep one canonical Gateway lifecycle controller, then add a redacted browser recording or runtime trace that visibly exercises a migrated page through same-client reconnect and Gateway-source replacement without stale data winning.

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

Not applicable as a defect report: this PR is a refactor. The changed reconnect and source-replacement paths are source-testable, but a high-confidence real browser reproduction/proof has not been supplied in the PR materials.

Is this the best way to solve the issue?

Yes, conditionally: centralizing the already-established connection-epoch invariant is more maintainable than preserving nine drifting copies, provided browser proof confirms the migrated pages preserve their lifecycle behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 05100271568b.

Labels

Label justifications:

  • P2: This is a broad but non-emergency Control UI lifecycle refactor whose main risk is dashboard availability after connection changes.
  • merge-risk: 🚨 availability: One controller now governs reconnect and source-replacement behavior for nine data-backed pages, so an owner-boundary regression can leave pages unavailable or stale.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR provides focused tests and CI, but no inspectable after-fix browser recording, runtime trace, live output, or redacted logs for the reconnect/source-replacement behavior; add that proof and redact private endpoints, IPs, and credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current-main check: The PR head is not an ancestor of origin/main, and origin/main is not an ancestor of the PR head, so the refactor is neither already implemented on current main nor merely behind it. (ui/src/lit/gateway-page-controller.ts:38, 538acf40a1d1)
  • Shared lifecycle owner: The controller binds the exact Gateway source, transitions the established connection lifecycle, invalidates stale work on source or connection changes, and only invokes page initialization after a connected snapshot. (ui/src/lit/gateway-page-controller.ts:58, 538acf40a1d1)
  • Existing epoch contract: The pre-existing lifecycle primitive invalidates a scope when either the client identity or connected state changes; the new controller composes that primitive rather than introducing a parallel request-currentness rule. (ui/src/lib/gateway-connection-lifecycle.ts:20, e5eff98879f8)
  • Sibling-path coverage: The branch adds controller tests for same-client reconnects, source replacement, exact route-data identity, and detach/reattach; the cross-page test suite additionally covers Usage, Skills, Sessions, Cron, Tasks, and source replacement behavior. (ui/src/lit/gateway-page-controller.test.ts:63, 538acf40a1d1)
  • Proof gate remains unmet: The PR body reports focused tests, lint, and CI, but the provided body, comments, and timeline contain no inspectable redacted browser recording, runtime trace, terminal output, or live log showing the after-fix reconnect/source-replacement behavior. The prior review also requested this proof and the current timeline still carries status: 📣 needs proof. (538acf40a1d1)

Likely related people:

  • steipete: Current-main blame attributes the existing gateway connection lifecycle primitive to Peter Steinberger, and this PR extends that same lifecycle boundary across Control UI pages. (role: introduced lifecycle primitive and recent area contributor; confidence: high; commits: e5eff98879f8, 538acf40a1d1; files: ui/src/lib/gateway-connection-lifecycle.ts, ui/src/lit/gateway-page-controller.ts, ui/src/pages/usage/usage-page.ts)

Rank-up moves

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

  • Add a redacted browser recording or runtime trace for one migrated page reconnecting with the same client.
  • Show a Gateway-source replacement while a request is in flight and verify that prior-source data cannot win.
  • Update the PR body with the evidence; if automatic review does not refresh, ask a maintainer to comment @clawsweeper re-review.

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 (3 earlier review cycles)
  • reviewed 2026-08-02T22:23:55.476Z sha 301051e :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-02T22:42:23.744Z sha 1c397d6 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-02T22:53:39.553Z sha 1c397d6 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed 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. labels Aug 2, 2026
@steipete steipete self-assigned this Aug 3, 2026
@steipete
steipete force-pushed the refactor/ui-gateway-page-controller branch from 1c397d6 to 538acf4 Compare August 3, 2026 05:16
@steipete

steipete commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready refresh on rebased head 538acf40a1d117797109d55354b2e7e5fe3018bf.

The rebase preserves both sides of the overlapping UI work:

Proof:

  • node scripts/run-vitest.mjs ui/src/pages/nodes/nodes-page.test.ts ui/src/pages/nodes/view.devices.test.ts ui/src/pages/worktrees/worktrees-page.test.ts ui/src/pages/sessions/sessions-page.test.ts ui/src/pages/sessions/sessions-page.archived.test.ts ui/src/lib/agents/watch-agent-scope.test.ts ui/src/lit/gateway-page-controller.test.ts — 7 files, 81 tests passed.
  • node scripts/watch-pr-ci.mjs 118243 538acf40a1d117797109d55354b2e7e5fe3018bf — exact-head CI green, run https://github.com/openclaw/openclaw/actions/runs/30786702465.
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main — clean, no actionable findings.
  • git diff --check origin/main...HEAD — clean.
  • Review artifacts reinitialized and validated for this exact head with recommendation READY FOR /prepare-pr and zero findings.

ClawSweeper's runtime-recording rank-up move is intentionally skipped: this is a behavior-neutral lifecycle refactor, the focused suites directly exercise disconnect/reconnect/source replacement and stale async confirmation, and the full hosted UI matrix passed. prepare-run will now verify the strict merge result against current main.

@steipete
steipete merged commit 59cd041 into main Aug 3, 2026
97 checks passed
@steipete
steipete deleted the refactor/ui-gateway-page-controller branch August 3, 2026 05:31
@steipete

steipete commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
* refactor(ui): centralize gateway page lifecycle

* fix(ui): align gateway controller state types

* fix(ui): satisfy lifecycle lint boundaries

* fix(ui): keep usage refresh reason private

* test(ui): cover usage refresh policy surface
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 merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant