Skip to content

ui-react: split createChatStore into composed slices #1361

Closed

Description

@schlessera

Part of #1342.

Context

createChatStore is one ~1,070-line closure (packages/ui-react/src/stores/chat-state.ts:1100-2172), and the ChatState interface declares 54 actions. Every buffer mutation goes through mutateBuffer (same file:1170), which re-maps the whole message list on each call when journals is present.

Chat-send assembly is #2521; it touches the store's addUserMessage/withdrawSend callers, not its internals, so the two do not conflict.

Scope

  • Slices for messages/streaming, ask-user, approvals and attachments, composed into the same per-root store returned today.

Out of scope

  • Changing hook names, selectors or BrainUiServices types.
  • Applying journal receipts when the journal frame arrives instead of on every mutateBuffer call. It changes when a render happens, so it is a separate behavioural change after this split.

Acceptance criteria

  • No function in chat-state.ts exceeds ~200 lines; each slice has direct tests.
  • Existing ui-react unit and browser suites pass unchanged.

Verification

bun run test packages/ui-react
bun run typecheck

Contract impact

None.

2026-10-24: removed the closed #1380 blocker and the completed #910/#1328 coordination note, refreshed the range, and folded the 2026-10-22 source check (journal-receipt timing stays out of this pure split; #2521 is independent).

Activity

  1. added
    type: refactor
    area: ui-react
    priority: p2
    agent-ready
    on Oct 9, 2026
  2. added
    blocked
    on Oct 9, 2026
  3. schlessera commented on Oct 9, 2026

    @schlessera
    OwnerAuthor

    Unblocked: #1380 is closed, so scripts/sync-project.ts is removing the blocked label.

  4. removed
    blocked
    on Oct 9, 2026
  5. schlessera commented on Oct 21, 2026

    @schlessera
    OwnerAuthor

    Source check at dcf5341aa during the 2026-10-22 repository review:

    • The citation is out of date. createChatStore is now 1,073 lines, packages/ui-react/src/stores/chat-state.ts:1100-2172, in a 2,172-line file. The body says about 900 lines at :989-1892. The ChatState interface declares 54 actions (chat-state.ts:373-657).
    • The blocker has already closed. The body still says Blocked by #1380, but ui-react: stores and lib import from components #1380 is closed. The stale blocker line should be removed (the issue does not carry the blocked label).
    • New evidence for the slice boundaries. Every buffer mutation goes through mutateBuffer (chat-state.ts:1170-1184). When journals is present, it re-maps the whole message list on each call, which means O(n) work and a new messages array for every token delta. Applying journal receipts when the journal frame arrives, instead of on every mutation, falls naturally out of a transcript/stream slice. Note, though, that it changes when a render happens, so it belongs in a separate behavioural change, not inside this pure split.
    • Related. ui-react: chat sends are assembled separately on four surfaces, and a failed re-asked answer stays in the transcript #2521 covers chat-send assembly. That logic is duplicated across the composer, re-ask, handoff sheet and share intake, and the copies disagree on rollback and follow-up queueing. Moving it into a sendChatMessage service touches the store's addUserMessage/withdrawSend callers but not the store's internals, so the two do not conflict.
  6. self-assigned this
    on Nov 2, 2026
  7. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Claiming (token wi-1361-c7f2). Branch refactor/1361-chat-store-slices from epic/1342-turn-path-split (at 0c3b837); the PR targets the epic integration branch and closes this issue when the epic batch lands on main. Collision report for chat-state.ts: closure-only overlaps with open drafts (#3054, #3056 and others); no open PR changes the file. #3305 on the same epic branch touches three docs that cite chat-state.ts; citation repairs here sit in separate hunks.

  8. added this to the 0.45.0 milestone on Nov 2, 2026
  9. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Implementation is in #3360 (head 238eff785), which targets epic/1342-turn-path-split (base 0c3b83762). It covers both acceptance criteria:

    • Function size. createChatStore is now a 20-line composer over seven slices. The largest function is 181 lines.
    • Tests. Each slice has direct tests. The existing ui-react suite gives the same results as the untouched base.

    Local preflight passed and hosted proof has been requested. This issue closes when the epic batch lands on main.

  10. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Delivered to the epic integration branch epic/1342-turn-path-split as a5cd3e8ea via #3360, after ready-candidate proof passed against the exact epic base. This issue closes when the epic batch lands on main.

  11. removed their assignment
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyarea: ui-reactpriority: p2type: refactor

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions