refactor(chat): extract runtime state owners - #1096
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 7:01 PM ET / 23:01 UTC. ClawSweeper reviewWhat this changesThe PR splits the tray chat provider’s queue, reset, history, lifecycle, metadata, mapping, and projection responsibilities into focused state owners while retaining the existing provider interface. Merge readinessKeep open. Current main still has the monolithic chat provider, while this cleanly mergeable branch performs the requested runtime ownership extraction with current-head UI proof and passing checks; it needs final maintainer review for compatibility-sensitive state behavior. Priority: P1 Review scores
Verification
How this fits togetherThe tray chat provider receives gateway chat, lifecycle, and history events, then projects state into the native chat UI. The new owners coordinate sends, resets, history reloads, and terminal events before snapshots reach rendering. flowchart LR
Gateway[Gateway chat events] --> Provider[Chat provider facade]
Provider --> Runtime[Conversation state and reset rules]
Runtime --> Queue[Queue and lifecycle state]
Runtime --> History[History loader]
Queue --> Snapshot[Chat snapshot projection]
History --> Snapshot
Snapshot --> UI[Native chat UI]
Before merge
Agent review detailsSecurityNone. Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the provider facade stable and land the focused state owners only after a maintainer accepts the reset, reconnect, history, queue, and terminal-event compatibility risk. Do we have a high-confidence way to reproduce the issue? Not applicable. This PR refactors established chat runtime behavior rather than reporting a separate user bug. Is this the best way to solve the issue? Yes. The focused state owners retain the provider facade and add characterization coverage for the critical ownership and generation invariants. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d67ef5140d13. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (23 earlier review cycles; latest 8 shown)
|
|
Added exact-head real gateway proof to the PR body: authenticated @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
4301c4f to
67d8a8b
Compare
|
Updated exact-head proof and review closeout for @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
67d8a8b to
61ed054
Compare
61ed054 to
0e34872
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use exact submitted echoes to open buffered post-reset lifecycles after queue reconciliation, and fence deferred abort work to the active runtime generation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Track generation-scoped local submissions before send completion, select the correct buffered lifecycle on exact echo, and accept only same-run skewed terminal frames above the correlated floor. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep run-scoped clock-skew floors limited to run-identifiable non-user frames so delayed pre-reset user messages cannot reappear after an exact echo opens the gate. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Rebased conflict resolution and validation statusThe five #1096 commits are rebased cleanly onto current
After explicit creator approval, the remote branch was updated with force-with-lease pinned to old head Validation
The exact-head CI rerun also passed the repository hygiene lane, setup-connect E2E, network-recovery E2E, revocation-recovery E2E, x64 and ARM64 builds, CodeQL, and Copilot setup. The tray virtualization test Real behavior proofThe earlier fixture screenshots remain withdrawn. The replacement proof below is from the production app at exact PR head An isolated tray profile copied only the local gateway registry and gateway identity, with notifications, telemetry, and node mode disabled. The app launched with: .\run-app-local.ps1 -NoBuild -DataDir <isolated-proof-profile> -AllowNonMainThe live proof then verified:
|
59096c3 to
8fa4702
Compare


Summary
OpenClawChatDataProviderfrom 7,249 to about 1,700 lines while retaining the same publicIChatDataProviderfacade for bridge IO, telemetry, events, and composition.ChatConversationStateand split queue, reset, history, presentation, lifecycle, approval, metadata, persistence, mapping, and projection into focused owners.Ownership transfer
ChatConversationStateChatQueueState+ChatSendQueuePolicyChatResetStateChatHistoryState+ChatHistoryLoaderChatPresentationStateChatLifecycleStateChatApprovalStateChatMetadataStore+ChatStatePersistenceNo substate owns a second runtime lock or duplicate reset/history generation. Source guards prevent runtime collections or
_gatefrom returning to the provider.Reset isolation and clock skew
chat.sendcan complete, then removed by the matching failure/stale/deferred path.Validation
Exact D1 head
59096c38182f07e22bb8980951a9c80828f0c01fon currentmainaac07abb1fbdaf2d75aa269397f094256188e1b5:./build.ps1: passedgit diff --check, source-owner guards, conflict markers, UTF-8, and final-newline checks: cleanReal behavior proof
A fresh disposable real-gateway fixture validated exact head
59096c38:0, and no active turn.app.chat.resetimmediately beforeapp.chat.sendand observed reset completion.ConnectingtoReady; post-reconnect history remained deduplicated.Redacted package:
d1-user-floor-proof-59096c38-20260806-144358Manifest SHA-256:
a2af2a8f886ba46c3e1185647d9c157e5d488573322d7e7bb4512096e0971fbfReview
Architecture
Adds authoritative/closed ledger rows and behavioral/source guards for the transaction root, queue/reset/history/presentation/lifecycle/approval substates, history loader, metadata/persistence owners, mapping/projection/formatting owners, and provider residue.