Skip to content

refactor(ui): adopt @lit/task for async data lifecycle - #115131

Merged
steipete merged 7 commits into
mainfrom
refactor/lit-task-adoption
Jul 28, 2026
Merged

steipete merged 7 commits into
mainfrom
refactor/lit-task-adoption

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

The Control UI hand-rolls the same async data lifecycle in dozens of components: fire an RPC from updated(), stash results in @state fields, guard staleness with a monotonic generation counter compared after every await, check this.isConnected, and juggle loading/error booleans. An audit found ~85 such counters across 45 files, plus components carrying both an AbortController AND an epoch for the same race, and one page tracking a loadedKey/requestedKey/loadedClient/requestedClient quadruple that reimplements args-comparison by hand.

Why This Change Was Made

@lit/task (official Lit-team package, exact-pinned 1.0.3 like our @lit/context) replaces the entire pattern: args-keyed task function, automatic discard of stale completions, per-run AbortSignal, INITIAL/PENDING/COMPLETE/ERROR status for rendering. Task semantics were verified from the installed source, not memory (shallow arg compare via Lit notEqual, auto-run during hostUpdate, _callId stale-commit guard, abort-only-signals-pending, initialState retention — the last two handled explicitly in disconnect/reset paths).

This is wave 1 of 2: foundation plus the highest-value surfaces. Rules applied consistently: Task is for reads (mutations/streaming/pagination stay hand-rolled — mutation generations and apply epochs retained where they guard writes); debounce timers kept, feeding debounced values into args; render output byte-identical.

User Impact

No behavior change. Rapid navigation/switching races (stale responses painting over newer ones) are now handled structurally by Task instead of per-site counter discipline, and ~1,100 lines of lifecycle scaffolding are deleted alongside an equal amount of new, uniform Task declarations (net −2 non-test LOC excluding lockfile, with 14 fewer bespoke lifecycle mechanisms).

Evidence

Migrated: session-diff-panel, session-discussion-panel (7 guard sites → one Task), gateway-name-discovery + cloud-profile-discovery (bespoke token classes → stateless loaders), new-session-page, mcp-app-view (Task result owns iframe/bridge teardown via abort), usage-page (3 request IDs + 3 loading flags → 3 Tasks), plugins-page (3 generations → 3 Tasks, mutation lane untouched), sessions-page (transcript-search + checkpoint lanes only; session-list lane untouched), worktrees-page (branches race on keystroke fixed), memory-import-page + onboarding-memory-import, model-setup-page (3 AbortControllers + 3 epochs → 3 Tasks).

Validation: UI prod + test tsgo; targeted oxlint/format; 131 focused tests; targeted browser tests; full UI e2e 360/361 (one unrelated Workboard form-fill flake, passed 3/3 on isolated retry); commit-mode autoreview clean. Testbox was unavailable for the new dependency; trusted-source proof ran locally per policy. Numstat: 1449/1155 total, non-test excluding lockfile 1122/1124 (net −2).

- migrate chat diff/discussion, new-session discovery, and MCP app setup reads
- migrate usage, plugins, transcript/checkpoint, worktree, memory-import, and model-setup reads
- delete read-lane request counters, abort-controller epochs, and current-request predicates while retaining mutation epochs and keyed caches
@steipete
steipete marked this pull request as ready for review July 28, 2026 09:59
@steipete
steipete requested a review from a team as a code owner July 28, 2026 09:59
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui size: XL maintainer Maintainer-authored PR labels Jul 28, 2026
@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label Jul 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Guard

This PR changes dependency-related files. Maintainers should confirm these changes are intentional.

Changed files:

  • package.json
  • pnpm-lock.yaml
  • ui/package.json

Maintainer follow-up:

  • Review whether the dependency changes are intentional.
  • Inspect resolved package deltas when lockfiles or workspace dependency policy changes are present.
  • Treat pnpm-lock.yaml and package-lock.json diffs as dependency security-review surfaces.
  • Run pnpm deps:changes:report -- --base-ref origin/main --markdown /tmp/dependency-changes.md --json /tmp/dependency-changes.json locally for detailed release-style evidence.

@github-actions

github-actions Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Dependency graph changes noted

This PR includes dependency graph changes. The dependency guard is informational because the PR author is a repository admin or a member of @openclaw/openclaw-secops.

  • Current SHA: 9d4a327d219dc6a184ca70b4ec2e8bb290358102
  • Trusted actor: @steipete
  • Trusted role: pull request author; openclaw-secops

Security review is still recommended before merge when the dependency graph change is intentional.

@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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 28, 2026
@clawsweeper

clawsweeper Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 28, 2026, 7:12 AM ET / 11:12 UTC.

ClawSweeper review

What this changes

This PR adds exact-pinned @lit/task and replaces selected Control UI read-request counters, abort controllers, loading flags, and stale-result guards with Lit Task lifecycle management across chat, setup, usage, plugins, sessions, memory-import, MCP app, and worktree views.

Merge readiness

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

Keep open. This is a broad but plausible Control UI lifecycle refactor; the reviewed diff and focused stale-result tests do not establish a discrete patch defect, but the PR still lacks inspectable after-fix evidence from a real browser session showing that a superseded request cannot repaint an older view. The maintainer label also requires explicit maintainer handling rather than cleanup closure.

Likely related people:

  • steipete — low-confidence routing candidate; authored the current lifecycle conversion and its follow-up validation commits.

Priority: P3
Reviewed head: 9d4a327d219dc6a184ca70b4ec2e8bb290358102

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation and focused coverage are credible, but real behavior proof remains the merge gate for this broad asynchronous UI refactor.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR body reports tests, browser E2E counts, lint, types, and CI, but no inspectable after-fix browser recording, terminal/live output, artifact, or redacted runtime log demonstrates a real stale-request race resolving correctly. Add redacted proof before merge; after updating the PR body, ClawSweeper should refresh automatically, or a maintainer can comment @clawsweeper re-review. 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 body reports tests, browser E2E counts, lint, types, and CI, but no inspectable after-fix browser recording, terminal/live output, artifact, or redacted runtime log demonstrates a real stale-request race resolving correctly. Add redacted proof before merge; after updating the PR body, ClawSweeper should refresh automatically, or a maintainer can comment @clawsweeper re-review. 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 Task conversion scope: The PR head imports Task/TaskStatus and replaces per-component read lifecycle state in representative Control UI surfaces, including session diff, session discussion, plugins, usage, memory import, worktrees, new-session discovery, model setup, and MCP app setup.
Focused stale-response coverage: The branch adds a session-diff test that resolves a newer loader before an older one and asserts that the stale result does not repaint the panel; similar targeted tests were added for usage selection and gateway-source replacement paths.
Dependency integrity surface: The dependency change is narrow and exact-pinned: @lit/task is declared as version 1.0.3 in the root and UI manifests, with a matching integrity-pinned lockfile entry.
Findings None None.
Security None None.

How this fits together

The Control UI renders Gateway-backed pages and components that issue asynchronous read RPCs as connection, route, and user-selection inputs change. This PR moves selected read lanes from component-specific cancellation and stale-result logic into Lit Task, which supplies argument-keyed reruns, cancellation signals, and pending/complete/error state for rendering.

flowchart LR
  A[Gateway connection and route state] --> B[Control UI component]
  B --> C[Task arguments]
  C --> D[Async Gateway read]
  D --> E[Task lifecycle state]
  E --> F[Rendered page or panel]
  C --> G[Superseded request cancellation]
  G --> E
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body reports tests, browser E2E counts, lint, types, and CI, but no inspectable after-fix browser recording, terminal/live output, artifact, or redacted runtime log demonstrates a real stale-request race resolving correctly. Add redacted proof before merge; after updating the PR body, ClawSweeper should refresh automatically, or a maintainer can comment @clawsweeper re-review. 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) - The refactor changes asynchronous state ownership across many Control UI read paths; without an inspectable live race demonstration, reviewers cannot confirm that initial, disconnect, pending, abort, and reconnect transitions retain the intended user-visible behavior.
  • Resolve merge risk (P1) - The branch is behind current main; refresh the merge result and required checks before landing, rather than inferring that base drift alone creates a code defect.
  • Complete next step (P2) - This protected, broad PR needs contributor-supplied real-behavior evidence and ordinary maintainer review rather than an automated repair branch.
Agent review details

Security

None.

PR surface

Source +279, Tests +58, Config +2, Other +14. Total +353 across 29 files.

View PR surface stats
Area Files Added Removed Net
Source 16 1411 1132 +279
Tests 9 537 479 +58
Docs 0 0 0 0
Config 2 2 0 +2
Generated 0 0 0 0
Other 2 16 2 +14
Total 29 1966 1613 +353

Review metrics

Metric Value Why it matters
Production UI dependency 1 exact-pinned dependency added @lit/[email protected] becomes a shared Control UI runtime dependency, so its lifecycle semantics affect every migrated read lane.

Stored data model

Persistent data-model change detected: serialized state: ui/src/pages/chat/components/session-diff-panel.test.ts, serialized state: ui/src/pages/chat/components/session-diff-panel.ts, serialized state: ui/src/pages/chat/components/session-discussion-panel.open-flow.test.ts, serialized state: ui/src/pages/chat/components/session-discussion-panel.test-support.ts, serialized state: ui/src/pages/chat/components/session-discussion-panel.test.ts, serialized state: ui/src/pages/chat/components/session-discussion-panel.ts, and 9 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Add observable race proof (recommended)
    Before merge, attach redacted after-fix browser, terminal, or runtime-log evidence that an older read completion cannot overwrite the newer Control UI state.
  2. Accept the residual verification gap
    A maintainer may accept the test-backed refactor without live race evidence, explicitly owning the remaining cross-surface UI lifecycle risk.
  3. Pause the refactor
    Pause this broad conversion if maintainers prefer to land smaller Task migrations with user-visible proof per surface.

Technical review

Best possible solution:

Keep Task limited to read lanes, preserve the existing mutation and streaming guards, and add redacted browser or terminal-backed proof that deliberately resolves an older Gateway request after a newer selection while the UI continues to display only the newer state.

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

Not applicable as a reported bug: this PR is a preventive internal refactor. The branch includes source-level race tests, but no inspectable real browser run has been supplied to reproduce the before/after behavior in a live setup.

Is this the best way to solve the issue?

Yes in principle: a shared, argument-keyed Task abstraction is a more maintainable way to protect read lanes from stale completions than repeating counters and abort bookkeeping. The remaining requirement is proof that the chosen lifecycle semantics preserve visible behavior across a real rapid-switching flow.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 64991433137f.

Labels

Label justifications:

  • P3: This is an internal UI lifecycle refactor with no demonstrated user-facing regression or urgent production failure.
  • merge-risk: 🚨 other: A broad conversion of asynchronous UI lifecycle handling can change initial, pending, abort, and reconnect behavior across several pages even when individual tests pass.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish 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 body reports tests, browser E2E counts, lint, types, and CI, but no inspectable after-fix browser recording, terminal/live output, artifact, or redacted runtime log demonstrates a real stale-request race resolving correctly. Add redacted proof before merge; after updating the PR body, ClawSweeper should refresh automatically, or a maintainer can comment @clawsweeper re-review. 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:

  • Task conversion scope: The PR head imports Task/TaskStatus and replaces per-component read lifecycle state in representative Control UI surfaces, including session diff, session discussion, plugins, usage, memory import, worktrees, new-session discovery, model setup, and MCP app setup. (ui/src/pages/usage/usage-page.ts:1, 9d4a327d219d)
  • Focused stale-response coverage: The branch adds a session-diff test that resolves a newer loader before an older one and asserts that the stale result does not repaint the panel; similar targeted tests were added for usage selection and gateway-source replacement paths. (ui/src/pages/chat/components/session-diff-panel.test.ts:34, 9d4a327d219d)
  • Dependency integrity surface: The dependency change is narrow and exact-pinned: @lit/task is declared as version 1.0.3 in the root and UI manifests, with a matching integrity-pinned lockfile entry. (pnpm-lock.yaml:3620, 9d4a327d219d)
  • Prior proof gate remains unmet: The prior completed ClawSweeper review explicitly found no inspectable after-fix recording, terminal/live output, artifact, or redacted runtime log; the current PR body reports tests and E2E counts but supplies no inspectable real-behavior artifact. (ab20fef2b4fd)
  • Current PR state: The branch remains open, is cleanly mergeable but behind main, and carries the repository maintainer label; its central refactor is therefore neither implemented on current main nor eligible for automated cleanup closure. (9d4a327d219d)

Likely related people:

  • steipete: Authored all seven commits in the current branch, including the read-lifecycle conversion, the usage refresh follow-up, and the focused test adjustments. (role: current implementation author and recent area contributor; confidence: medium; commits: 40fc3793b088, 42e9fe43eb09, 9d4a327d219d; files: ui/src/pages/usage/usage-page.ts, ui/src/pages/plugins/plugins-page.ts, ui/src/pages/chat/components/session-discussion-panel.ts)

Rank-up moves

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

  • Attach redacted live evidence that a superseded Gateway read cannot repaint an older Control UI state.
  • Refresh the branch against current main and let required checks validate the resulting merge head.

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-07-28T10:16:58.118Z sha ae1840e :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-28T10:44:24.708Z sha 42e9fe4 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-28T10:53:43.819Z sha ab20fef :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. label Jul 28, 2026
@steipete
steipete merged commit 053384f into main Jul 28, 2026
232 of 236 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete
steipete deleted the refactor/lit-task-adoption branch July 28, 2026 12:37
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 29, 2026
* refactor(ui): adopt @lit/task for async data lifecycle

- migrate chat diff/discussion, new-session discovery, and MCP app setup reads
- migrate usage, plugins, transcript/checkpoint, worktree, memory-import, and model-setup reads
- delete read-lane request counters, abort-controller epochs, and current-request predicates while retaining mutation epochs and keyed caches

* chore(ui): drop dead plugin search helper (knip)

* chore(deps): allowlist @lit/task as root UI-workspace dependency in knip

* fix(ui): preserve usage refresh lifecycle

* test(ui): source workboard fixture copy from en locale (raw-copy gate)

* test(ui): read workboard fixture copy via t() (typed locale access)

* style: format test-support imports
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 dependencies-changed PR changes dependency-related files maintainer Maintainer-authored PR merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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