Repository navigation
MAINT Decompose ChatWindow conversation workflows #2652
Description
Is your feature request related to a problem? Please describe.
frontend/src/components/Chat/ChatWindow.tsx still owns the send/recovery and copy/branch orchestration, including per-conversation locks, optimistic messages, attachment/conversion state, and navigation during those operations.
Loading and stale-fetch protection are already extracted into useConversationMessages by merged #3310. Human-score/objective mutations and export are already extracted into useAttackMutations and useConversationExport by merged #3369. Those are completed steps of this issue, not workflows to extract again.
The concern is not line count by itself. Race-sensitive state is spread across React state, multiple refs, effects, and callbacks, so changing one workflow requires understanding unrelated behavior. The associated tests also have to render a large surface to verify small state transitions.
Describe the solution you'd like
Decompose the stateful workflows behind focused hooks or reducers while keeping ChatWindow as the composition and presentation boundary. Candidate boundaries include:
- message sending, optimistic state, per-conversation locking, attachments, and conversions;
- copy/new-conversation/branch-conversation/branch-attack operations;
- the remaining coordination between those operations and the already-extracted loading, mutation, export, conversation-draft/save, and converter hooks.
Reuse useConversationMessages, useAttackMutations, useConversationExport, useConversationDraft, useConversationSave, and useChatConverters. Extract the remaining orchestration, not another persistence service, converter implementation, or conversation loader.
Keep state together when it participates in the same transition. Prefer an explicit reducer for multi-step conversation mutation state over moving individual useState calls into pass-through hooks. The extracted APIs should return typed state and commands with clear ownership.
Preserve the existing ChatWindow props, rendered UX, accessibility, request payloads, optimistic-message behavior, navigation behavior, and error handling. In particular, retain the current protections against stale conversation loads, duplicate sends/exports, navigation during an in-flight send, and mutation while an operation is locked.
Describe alternatives you've considered, if relevant
Extracting only JSX sections into presentational components would shorten the file but leave the hard part, asynchronous state ownership, unchanged. Creating one large useChatWindow hook would move rather than reduce the complexity. The goal is a few cohesive workflow boundaries, not maximal file splitting.
Additional context
This was identified during the September 14, 2026 maintainability audit. Scope refreshed against main 791e12c6e5e4302e7c1211af6af8973aa6fe1f37 on October 31, 2026. #3310 and #3369 are merged partial delivery; continue this existing tracker rather than start the original decomposition again.
Coordinate remaining ChatWindow edits with dataset import #2751/#3670 and the active Chat/UI stack. Saved Scenario evidence paging is a different consumer of the existing loader and renderer, not permission to rewrite manual Chat here.
Suggested regression coverage:
- switching conversations while a fetch is in flight;
- sending independently in two conversations;
- preserving optimistic messages when the active conversation changes during send;
- duplicate-send and duplicate-export prevention;
- copy to current/new conversation and both branch paths;
- mutation locking during score, objective, and conversation updates;
- attachment and converted-piece handling;
- narrow-screen panel behavior.
Definition of done:
- each extracted hook/reducer owns one cohesive workflow and has focused tests;
ChatWindowprimarily composes workflow state and renders children;- no public API, backend contract, accessibility, or user-visible behavior changes;
- frontend unit tests, type-check, lint, and formatting pass.
Activity
PeaceMaker-best commentedon Sep 14, 2026
I'd like to take this. I will keep
ChatWindowas the composition and presentation boundary and extract cohesive, typed workflow hooks for stale-safe conversation loading/navigation, per-conversation send state and optimistic updates, copy/branch mutations, score/objective mutations, and duplicate-safe export. State that participates in the same transition will stay together rather than becoming pass-through hooks. I will preserve the existing props, request payloads, locking and navigation semantics, attachments/conversions, accessibility, and rendered behavior, with focused tests for the extracted transitions plus the existing component regression suite. I will open a separate focused PR after frontend unit tests, type-check, lint, and build pass.romanlutz commentedon Oct 14, 2026
Making this available again!
juliosuas commentedon Oct 17, 2026
Hey Roman, just woke up and wanted to keep going 🙂 Mind if I take this one? It's a bigger one but I'm ready for it. I'd use a reducer for the send/optimistic/locking state since those move together, plus separate hooks for loading (stale-safe), copy/branch, score/objective and export.
ChatWindowstays as the composition layer, no prop or UI changes. And if there's something even more complex you'd rather hand me, happy to take that instead.romanlutz commentedon Oct 18, 2026
Sure Julio César Suástegui (@juliosuas) ! You can also do it in multiple steps if you prefer
juliosuas commentedon Oct 18, 2026
Step 1 is up in #3310: it pulls the conversation loading (the stale-response handling) out into its own hook, with no behavior change. The rest comes in 3 more steps: score/objective/export, then copy/branch, and the send reducer last.
juliosuas commentedon Oct 19, 2026
Hey Roman, happy Monday 👋 Thanks for the kind words. A promise is a promise, so let's finish this one. Step 2 (score/objective/export) is next 🚀