Skip to content

refactor(ui): split chat state container - #113780

Merged
steipete merged 2 commits into
mainfrom
codex/h6-chatstate
Jul 25, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/h6-chatstate

Conversation

@steipete

@steipete steipete commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The Control UI chat state container mixed route/composer restoration, metadata refresh, page construction, Gateway event reconciliation, render scheduling, and Lit controller lifecycle in one 2,091-line module. That made changes to the heavily evolving chat surface harder to review and kept the file on the max-lines baseline.

Why This Change Was Made

Split the container into focused host-contract, route, refresh, page, event, render, and controller modules while keeping chat-state.ts as the stable facade for existing callers. The refactor preserves current runtime behavior, public facade exports, and lifecycle/invariant comments. This is an AI-assisted maintainer-commissioned refactor.

Beyond the split

  • Carry chat-metadata ownership facts in one request context so compatibility refreshes and stale-response checks cannot drift between parallel nullable arguments.
  • Remove redundant initial-state assertions and duplicate host fields already guaranteed by the composite state contracts; initialize chatAvatarSource to its declared null state instead of relying on the final object cast.
  • Use the canonical ChatPageHost contract for state helpers because every caller already supplies the full host, deleting verbose partial-host signatures that did not protect a real call site.
  • Flatten assistant-avatar selection into one guard while preserving the existing authenticated, local, configured, then agent-list priority.

User Impact

No user-visible behavior change. Maintainers get purpose-specific chat state modules, all below 430 lines, and the ui/src/pages/chat/chat-state.ts max-lines baseline entry is removed.

Evidence

  • LOC: production +2066/-2091 (net -25); tests +0/-0; baseline +0/-1; total +2066/-2092 (net -26).
  • node scripts/run-vitest.mjs ui/src/pages/chat/chat-state.test.ts ui/src/pages/chat/chat-send.test.ts — 2 files, 277 tests passed.
  • node scripts/check-changed.mjs -- config/max-lines-baseline.txt ui/src/pages/chat/chat-state.ts ui/src/pages/chat/chat-state-controller.ts ui/src/pages/chat/chat-state-events.ts ui/src/pages/chat/chat-state-host.ts ui/src/pages/chat/chat-state-page.ts ui/src/pages/chat/chat-state-refresh.ts ui/src/pages/chat/chat-state-render.ts ui/src/pages/chat/chat-state-route.ts — passed on Blacksmith Testbox tbx_01kyd4a8pjsnn7x3mb56n2jctx; includes core-test/UI typechecks, formatting, max-lines ratchet, Control UI i18n, lint, and repository guards.
  • node scripts/crabbox-wrapper.mjs run --provider blacksmith-testbox --timing-json --shell -- "pnpm build" — passed on Blacksmith Testbox tbx_01kyd4temh1c9nf3msb2p990q3; Control UI bundle and performance budgets passed with no ineffective dynamic-import warning.
  • pnpm deadcode:dependencies && pnpm deadcode:exports — passed on Blacksmith Testbox tbx_01kyd5zy4r3se1aefe8efbh085 after making the same-module lightbox helper private.
  • Exact-head CI run 30168276275 — passed on 7683e6d368a42e9f7280471fb654fe0fab3b1e9f; the final rebase is patch-identical and prepare-run accepted that hosted evidence.
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted --engine codex --model gpt-5.6-sol --thinking high --stream-engine-output — clean, no accepted/actionable findings (0.98 confidence).
  • git diff --check — passed.

Bugs Found

None.

Placement Findings

None. The extracted responsibilities remain inside the Control UI chat owner boundary.

Baseline

Removed ui/src/pages/chat/chat-state.ts from config/max-lines-baseline.txt; every resulting production file is below the max-lines budget.

ClawSweeper Rank-up Moves

  • Refresh against current main: applied. The branch was rebased onto 6f1950ec1a1b1fac6744fc6779aa2c81a1b71217, the focused 277-test proof passed again, and repo-native preparation accepted the patch-identical hosted CI evidence.
  • Add a real Control UI behavior artifact: intentionally skipped with owner sign-off. This maintainer-commissioned PR is a behavior-neutral static module extraction with no changed visual output to screenshot or record. The existing focused lifecycle/queue/session tests, full Control UI production build, exact-head CI, clean autoreview, and dead-code gates exercise the moved contracts without mutating an operator's live setup.

@steipete
steipete marked this pull request as ready for review July 25, 2026 17:32
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui size: XL maintainer Maintainer-authored PR labels Jul 25, 2026
@steipete
steipete force-pushed the codex/h6-chatstate branch from 7683e6d to 20e405a Compare July 25, 2026 17:54
@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. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 25, 2026
@clawsweeper

clawsweeper Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 25, 2026, 1:58 PM ET / 17:58 UTC.

ClawSweeper review

What this changes

This PR splits OpenClaw Control UI chat state responsibilities—routing, refreshes, page setup, Gateway-event reconciliation, rendering, and lifecycle control—into focused modules while retaining chat-state.ts as the caller-facing facade.

Merge readiness

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

Keep this PR open for maintainer review. It is a broad, behavior-preserving Control UI refactor with substantial automated validation, but its protected maintainer label requires explicit human handling and the remaining CI matrix was still running in the supplied review state.

Priority: P3
Reviewed head: 20e405ad2a2db8b691eb74960b000c3f5303c7bd
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has substantial stated automated validation and a coherent refactor boundary, but the supplied context does not contain inspectable real after-fix behavior proof.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR provides strong automated test, build, static-check, and CI evidence, but no directly inspectable after-fix runtime transcript, recording, screenshot, or redacted live output for the reorganized Control UI lifecycle; add redacted real behavior evidence if maintainers require the external-PR proof gate. 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 strong automated test, build, static-check, and CI evidence, but no directly inspectable after-fix runtime transcript, recording, screenshot, or redacted live output for the reorganized Control UI lifecycle; add redacted real behavior evidence if maintainers require the external-PR proof gate. 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 4 items Protected maintainer handling: The supplied GitHub state includes the maintainer label. Repository review policy keeps protected-label PRs open for explicit maintainer handling rather than automated cleanup.
Refactor boundary: The PR retains ui/src/pages/chat/chat-state.ts as a facade and extracts controller, events, host, page, refresh, render, and route responsibilities into focused sibling modules.
Provided validation: The PR body reports focused chat tests, changed-surface checks, a production build, dead-code checks, an autoreview pass, and git diff --check; supplied GitHub checks also show many completed successes, while part of the matrix remained in progress.
Findings None None.
Security None None.

How this fits together

The Control UI chat page receives route changes and Gateway events, restores composer and session state, reconciles queued sends and streamed responses, then schedules Lit rendering. This refactor reorganizes that orchestration without changing the public chat-page facade used by existing callers.

flowchart LR
  A[Chat route and composer state] --> C[Chat state facade]
  B[Gateway session and run events] --> C
  C --> D[Route, refresh, page, and event modules]
  D --> E[Chat state host]
  E --> F[Lifecycle and render controller]
  F --> G[Control UI chat page]
  D --> H[Queue and session reconciliation]
Loading

Decision needed

Question Recommendation
Should this protected, maintainer-commissioned Control UI refactor be approved after the current-base lifecycle review and pending CI complete? Approve after final lifecycle review: Confirm route restoration, queued-send delivery, Gateway-event reconciliation, and render scheduling preserve the existing facade contract, then merge after required checks pass.

Why: The maintainer label prevents automated cleanup, and the refactor moves stateful session, queue, and rendering orchestration across several modules where maintainers must confirm the intended ownership and acceptable review scope.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR provides strong automated test, build, static-check, and CI evidence, but no directly inspectable after-fix runtime transcript, recording, screenshot, or redacted live output for the reorganized Control UI lifecycle; add redacted real behavior evidence if maintainers require the external-PR proof gate. 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) - This is a large stateful refactor across route restoration, queued-send reconciliation, session updates, and render scheduling; the remaining CI matrix and a human review of those cross-module lifecycle paths should complete before merge.
  • Resolve merge risk (P1) - The branch is reported as behind main; refresh the merge review against the current base so recently changed chat behavior is included in the final comparison.
  • Complete next step (P2) - The protected maintainer label and stateful cross-module lifecycle scope require explicit owner review rather than an automated repair lane.
Agent review details

Security

None.

PR surface

Source -25, Other -1. Total -26 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 8 2066 2091 -25
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 9 2066 2092 -26

Review metrics

None.

Stored data model

Persistent data-model change detected: persistent cache schema: ui/src/pages/chat/chat-state-host.ts, persistent cache schema: ui/src/pages/chat/chat-state-page.ts, persistent cache schema: ui/src/pages/chat/chat-state-route.ts, vector/embedding metadata: ui/src/pages/chat/chat-state-refresh.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Verify cross-module chat invariants before merge (recommended)
    Review the current-base merge result and preserve existing queue-delivery, session-restoration, and terminal-render ordering behavior before approving the split.
  2. Accept the refactor risk with owner sign-off
    Merge after the remaining checks pass if the responsible Control UI owner accepts the lifecycle regression risk covered by the existing focused validation.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Rebase onto current main, run the focused chat-state and chat-send tests, and verify queue-delivery plus route/session restoration behavior against the current facade contract.

Technical review

Best possible solution:

Land only after the current-base review confirms the facade preserves all existing chat lifecycle contracts and the remaining required CI checks finish successfully.

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

Not applicable: this PR refactors existing Control UI internals rather than fixing a separately reported user-facing defect. The supplied validation names focused chat-state and chat-send tests as the relevant behavioral coverage.

Is this the best way to solve the issue?

Yes, conditionally: retaining chat-state.ts as the stable facade while extracting cohesive responsibilities is a maintainable route for reducing the oversized container, provided the current-base lifecycle review confirms the moved invariants remain intact.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 0ff2c8203330.

Labels

Label changes:

  • add P3: This is an internal maintainability refactor with no stated user-visible behavior change.
  • add merge-risk: 🚨 message-delivery: The extracted event and route modules retain queued-send flushing and delivery reconciliation, so an integration mistake could affect chat send delivery.
  • add merge-risk: 🚨 session-state: The split moves route restoration, session metadata refresh, stale-response checks, and lifecycle state across module boundaries.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add 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 strong automated test, build, static-check, and CI evidence, but no directly inspectable after-fix runtime transcript, recording, screenshot, or redacted live output for the reorganized Control UI lifecycle; add redacted real behavior evidence if maintainers require the external-PR proof gate. 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.

Label justifications:

  • P3: This is an internal maintainability refactor with no stated user-visible behavior change.
  • merge-risk: 🚨 message-delivery: The extracted event and route modules retain queued-send flushing and delivery reconciliation, so an integration mistake could affect chat send delivery.
  • merge-risk: 🚨 session-state: The split moves route restoration, session metadata refresh, stale-response checks, and lifecycle state across module boundaries.
  • 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 provides strong automated test, build, static-check, and CI evidence, but no directly inspectable after-fix runtime transcript, recording, screenshot, or redacted live output for the reorganized Control UI lifecycle; add redacted real behavior evidence if maintainers require the external-PR proof gate. 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:

  • Protected maintainer handling: The supplied GitHub state includes the maintainer label. Repository review policy keeps protected-label PRs open for explicit maintainer handling rather than automated cleanup. (20e405ad2a2d)
  • Refactor boundary: The PR retains ui/src/pages/chat/chat-state.ts as a facade and extracts controller, events, host, page, refresh, render, and route responsibilities into focused sibling modules. (ui/src/pages/chat/chat-state.ts:1, 20e405ad2a2d)
  • Provided validation: The PR body reports focused chat tests, changed-surface checks, a production build, dead-code checks, an autoreview pass, and git diff --check; supplied GitHub checks also show many completed successes, while part of the matrix remained in progress. (ui/src/pages/chat/chat-state.test.ts:1, 20e405ad2a2d)
  • History signal: The supplied PR history contains the refactor commit and a follow-up that keeps the lightbox helper private, showing the author addressed a same-change module-boundary concern before this review. (ui/src/pages/chat/chat-state-page.ts:1, 20e405ad2a2d)

Likely related people:

  • steipete: The supplied PR body identifies this as a maintainer-commissioned refactor, and both commits on the branch are authored by steipete. (role: refactor author and stated commissioned-work contact; confidence: medium; commits: b0a5cfefe889, 20e405ad2a2d; files: ui/src/pages/chat/chat-state.ts, ui/src/pages/chat/chat-state-controller.ts, ui/src/pages/chat/chat-state-events.ts)

Rank-up moves

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

  • Add a redacted real Control UI chat-flow transcript, recording, terminal output, or runtime log that demonstrates route restoration, a queued send, and Gateway-event reconciliation after the split.
  • Refresh the branch against current main and let the remaining CI matrix complete before final approval.

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 8b5337c into main Jul 25, 2026
135 of 142 checks passed
@steipete
steipete deleted the codex/h6-chatstate branch July 25, 2026 18:23
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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