Skip to content

refactor(site/src): simplify AgentChatPageView (stage 1 cleanup) - #31476

Merged
DanielleMaywood merged 3 commits into
mainfrom
refactor/agents-chat-page-view-cleanup
Oct 29, 2026
Merged

DanielleMaywood merged 3 commits into
mainfrom
refactor/agents-chat-page-view-cleanup

Conversation

@DanielleMaywood

@DanielleMaywood DanielleMaywood commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Note

This PR was generated by Coder Agents on behalf of @DanielleMaywood.

Simplify some code

LLM Slop Description

Stage 1 of the AgentChatPageView simplification, limited to changes that keep behavior the same.

  • Delete dead code: unreachable UserTabContent fallbacks, a support guard the add-tab menu already applies, the shouldShowSidebar alias, no-op classes, an unused test id, stray text nodes, agentId keys that KeyedAgentChatPage already provides, and a read-only term implied by canSubmitChatTurn.
  • Move leaf-only values into their consumers. QueuedForCapacityCallout reads entitlements and permissions itself, WorkspacePill fetches the deployment SSH config itself (the sshCommand prop is gone from four components), and ChatWorkspaceContext wraps only the timeline, its sole consumer.
  • Separate the logical steps in the tab list and the open-tab handlers with blank lines.

Behavior changes from the plan (computing tab visibility once, which fixes Desktop connecting behind a closed panel, and saving tabs on write with the built-in Terminal as a synthesized tab) are left for separate PRs with their own tests. Also not included: rebasing #30638, and moving the drag value into RightPanel. Overlaps with open #31286 and #30638.

Design review and plan

AgentChatPageView: why it looks like this, and how to simplify it

Scope: site/src/pages/AgentsPage/AgentChatPage/AgentChatPageView.tsx (1125 lines) and its container AgentChatPage.tsx (870 lines), on origin/main a512a7f (2026-10-29). Line numbers below refer to that commit. "View" = AgentChatPageView.tsx, "Page" = AgentChatPage.tsx.

Method: four read-only research lanes (git history, PR bodies, review threads), one cross-check of the 8 most load-bearing claims (7 confirmed, 1 uncertain, 0 refuted), then three parallel design passes under different constraints. Confidence is high unless marked.

1. Headline numbers

2. Root causes

  1. The View is the lowest common owner of the transcript and the right panel. feat(site): rich preview for the spawn_computer_use_agent tool #23684 moved tab selection out of SidebarTabView so a transcript tool (the inline desktop preview) could open the Desktop tab. Every feature that links the two lands here: Desktop open, Preview open, Git panel writing into the composer.
  2. Each right-panel feature arrived with its own state, persistence, support check, render case and, if tools can open it, its own context. There is no shared tab shape, so a new tab means shotgun surgery.
  3. Panels stay mounted on purpose (fix(site/src/pages/AgentsPage): preserve right panel tab state across switches #23737: unmounting lost scroll, commit drafts and VNC; feat: support multiple terminal tabs on the agents right panel #26089: hidden canvas terminals keep their pixels). So the View must tell each panel "you are shown". Each feature wrote its own flag, and the flags disagree.
  4. The Sept 2026 refactor series (refactor(site/src/pages/AgentsPage): extract AgentChatPage helpers and hooks #29032 to refactor(site/src/pages/AgentsPage): fetch workspace options in <ChatPageInput /> #29118) moved reads into the leaves but deliberately stopped at the send pipeline. refactor(site/src/pages/AgentsPage): extract AgentChatPage helpers and hooks #29032 says the send pipeline and View "stay put". refactor(site/src/pages/AgentsPage): pass Chat instead of sliced chat flags #29064 says "Handlers stay props". refactor(site): drive plan mode from mutation pending state #29117 made mutation pending state drive isInputDisabled. The View became a relay. You noted the cost on refactor(site/src/pages/AgentsPage): extract AgentChatPage helpers and hooks #29032 ("So many props getting drilled").
  5. The loading view needs neither chat nor store, so it was split off (refactor(site): separate AgentsPage and AgentDetail into container/view pairs #22812) and its layout copied.

3. Catalogue: what each part does, why, and whether the reason still holds

Verdict key: Keep, Move (to the owner named), Delete.

3.1 Prop relay (Page to View)

Concern Why it exists Still holds? Verdict
Model and reasoning selection, MCP selection, editing state, mutations, pending flags (View 113-136, 153-176) submitChatTurn and isInputDisabled read them (Page 507-520, 654-698). #29032, #29064, #29117 Yes, they must stay in the Page Keep in the Page, but stop relaying them through the View. Pass the composer as a node (your #30638)
Model setup counts (providerCount, modelCount, unsupportedProviderNames, canConfigureAgentSetup) Inferred: the Page already ran the queries Partly. ChatPageInput is the only consumer, and AgentCreateForm already derives the same values itself (AgentCreateForm.tsx 542-652) Move into ChatPageInput (optional)
sshCommand (Page 613-616) #22529 No. Its only consumer is WorkspacePill, four hops down. SSHButton already reads deploymentSSHConfig itself Move into WorkspacePill
Pagination, urlTransform, gitWatcher The Page owns the infinite query and the store hydration. The git watcher also feeds the composer's folder (#24295) Yes Keep, forwarded directly

3.2 Chat column

Concern Why Still holds? Verdict
ChatTopBar + liveChatStatus (326, 834) ChatTopBar reads its own data (#29074, #29116). Archive is gated on live status (#29065) Yes Keep
Model notices (843-856) The notice depends on the Page's resolved model (#27960) Yes Keep the derivation in the Page
Archived banner and hidden composer (857, 914) Layout decisions (#29035, #29119) Yes Keep
Read-only owner notice (788-795) #24941, #25736, #30483 No. It is a second check of the Page's isViewerNotOwner. #30483 itself lists "one viewer-permission check" as a follow-up Move into ChatPageInput, as #30638 does. Only the UX moves. Submission and mutation permission checks stay where they are
attachedWorkspace, preferredFolder (397-421) #23964 badge; #24295 prefers the git root for monorepos Yes Move to ChatPageInput and the Page, as in #30638
onImplementPlan / onSendAskUserQuestionResponse gating (894-903) #24236, #29117 isOtherUserReadOnly || is redundant in production: isInputDisabled already includes viewer-not-owner (Page 242-243, 515-520) Delete the redundant term. The Page passes undefined when a turn can't be submitted
onEditUserMessage gating (886-890) #25736 Medium-confidence bug: an archived chat you own still gets an edit handler while the composer is hidden Fix, as a product call
License and runtime hours (797-806) #27902. Inferred: keep the callout presentational No. QueuedForCapacityCallout is the only consumer, and the stories already drive it through providers (cross-check confirmed) Move into the callout
initialActiveTurnMaxMessageId + initialMessages (332-341) #28130. Must be captured when the transcript mounts Yes, but ChatPageTimeline mounts at the same moment (medium) Move into ChatPageTimeline
key={agentId} on the View (Page 787) and on ChatPageTimeline (875) No written reason No. KeyedAgentChatPage already keys the whole subtree (Page 854-867) Delete

3.3 Right-panel tab model

Concern Why Still holds? Verdict
Active tab saved per chat (351, 368-373) A chat switch remounts the page (#24631) Yes Keep
No saving for archived chats (370, 376, 382, 388) Codex review on #24631: clicking tabs in an archived chat re-created the keys that archiving had just cleared, so "unarchive starts fresh" broke Yes, but the rule is written 4 times (a 5th copy in Preview), and archive clears it in 4 call sites Keep one rule
Three persistence effects for user tabs, terminal hidden, singletons (375-391) #26089 review: functional updaters plus effect saves to avoid stale closures. #28370 added the third Partly. The split from the inline sidebarTabId save is historical only. The effects write "[]" on every mount, and they rewrite state if a chat is unarchived while open (cross-check confirmed) Consolidate into one save path. Every mutation path counts, including tool-triggered opens and closes. Keep a small effect if handler saves would need duplicate writes
validateUserRightPanelTabs (445) #26208: tabs are hidden, not deleted, when their app or port goes away Yes Keep. It is the one eligibility check for user tabs
UserTabContent fallbacks (200-265) Added for consistency, and for a bot finding No. All are unreachable, because only validated tabs get here (cross-check confirmed) Delete
Singleton support (429-443), render guards (672, 680, 689), toggle guard (763) #28370: Browser loaded its iframe on every page load, so panels now start hidden and are toggled from a dropdown. A saved choice survives a temporary loss of support Data yes. The check is written 3 times, and the dropdown already filters Keep one check
Singleton order and labels #26166 keeps terminals rightmost The order is written in 3 places and disagrees (tab bar: debug, browser, desktop; canonical list and menu: browser, desktop, debug) Keep one list
Built-in Terminal as its own concept (defaultTerminalHidden, 357, 450, 549-554, 688-704) #26089: closeable and restorable, and "no Terminal 2 without Terminal 1" Partly. It costs an extra key, an extra render path and a numbering offset. It already uses reconnectionToken = chatId (cross-check confirmed) Render it through the normal terminal path as a synthesized tab. No storage migration
Dense terminal numbering (469-494) #26089, #26208 Yes Keep. It gets simpler once the built-in Terminal is a normal terminal
getEffectiveTabId falls back to the first tab (496) #23920, #24631. Never writes back Yes Keep. It has one caller and lives in the misleadingly named ChatsSidebar/
Close picks the neighbor tab (733-760) #26089. The reason is inferred Yes Keep

3.4 Activation and tab content

Concern Why Still holds? Verdict
Tab selection lives in the View Transcript tools open tabs (#23684) Yes. This is the page's integration job Keep one authority for active and shown tabs
onOpenDesktop only when the panel can render (511-518) #28370: otherwise a tool can select a tab the list omits Yes Keep, derived from the same support check
Open handlers dedupe (567-640) #26208. Reopening a command app must not start another session (#26089) Yes Keep, next to the tab kind
Pending terminal (362, 520-537) #26089: avoid a blank frame when switching terminal canvases. Every TerminalPanel fires onReady once per mount, so the guard is required Unclear. A 100 ms fallback caps the benefit, and nobody has measured it Decide after a visual check: delete, or keep inside the terminal tab code
Per-panel visibility flags (648, 676, 685, 692-699, 709, 218-219, 238) #23920: one resolved tab drives both the highlight and the content The single source holds. The flags disagree: Summary, Debug and Terminal include "panel open"; Desktop, Browser and app tabs don't. With the panel closed and Desktop active, VNC connects and Ctrl/Cmd+0/1 are captured (medium) Compute "shown" once, in SidebarTabView
WorkspaceAppFrame.active TaskPage leftover (#26088) Uncertain. Removing it changes display:none to invisible-but-laid-out Low priority, needs a visual check
TerminalClientSessionContext (366, 809) #27677: one session per page visit, surviving tab close and reopen Yes. Only TerminalPanel consumes it Keep, or pass it as a prop
ChatWorkspaceContext (810) #24194, #29550: transcript tool renderers Yes, but unrelated to tabs Wrap only the timeline

3.5 Layout, expansion, loading

Concern Why Still holds? Verdict
Panel open state owned by the Page #22983: loading and loaded views share it, so there is no shift. #28387: narrow-viewport suppression never touches the saved preference Yes Keep
Expansion gate (345-349, 968) #28387 review. RightPanel's expanded styling ignores isOpen (cross-check confirmed) Yes Move isOpen && into RightPanel
dragVisualExpanded relay (342-349, 971) #22633: siblings react during a drag Partly. All live consumers are inside RightPanel. The exception is the chat column's hidden, which is visually redundant because the expanded panel is absolute inset-0 z-30 (medium) RightPanel passes the live value to its own children. The chat column uses committed state
--agents-chat-panel-min-width, max-lg:hidden, h-full #25894, #22744/#24161, #29602 Yes Keep, written once
shouldShowSidebar, flex-row, data-testid="agents-chat-panel", {" "} Leftovers (#22837, #22718, #29017) No Delete
Separate loading view and the handleLoadingDraftChange seed #22812, #26415 Yes, while the loading composer is a different instance Keep the seed. Share the layout
Loading top bar with a no-op toggle and stale icon (1057-1062) n/a Bug Fix
Suspense skeleton #22983, #23439 It predates the lg breakpoint, the CSS variable and narrow-viewport suppression Share the layout

4. The three alternative designs

All three agree on Section 3's Delete/Move rows. They differ on the right panel and on page composition.

Design A: Delete and colocate (no new abstractions)

  • Apply every deletion and move above. Adopt refactor(site/src/pages/AgentsPage): move chat pages to ChatComposer #30638's composer node.
  • Extract two components along existing visual seams:
    • AgentChatRightPanel (about 440 lines, 16 props): user tabs, the terminal flag, pending, expansion, content.
    • AgentChatLayout (about 35 lines): the frame shared by loading, loaded and Suspense.
  • Tool-openable singletons stay in the View with their eligibility. User tabs move into the panel.
  • Result: about 340 lines and 22 props in the View.
  • Strength: smallest conceptual change, and every PR is independently safe.
  • Weakness:
    • Tab state is split between the View and the panel, so the archived rule lives in both.
    • Singleton eligibility stays in the page, against "features own eligibility".
    • Preview still needs about 8 touch points.
    • Hiding the chat column relies on a CSS :has data-attribute coupling.

Design B: Layout shell with slots (dissolve the View)

  • Delete AgentChatPageView. One AgentChatPageShell (about 140 lines) with topBar, notices, main, composer and rightPanel slots renders every state: loading, loaded, error, not-found and Suspense.
  • AgentChatPage composes the leaves directly, so no prop passes through a non-reader.
  • ChatRightPanel owns all tab state. Tools reach it through an imperative ref.open(target).
  • Strength:
    • Removes all three layout copies and the whole relay.
    • The shell keeps one top-bar and panel instance from loading to loaded.
  • Weakness:
    • The Page stays about 750 lines and becomes the composition root.
    • The imperative handle raises lifecycle questions, such as a tool firing before the panel mounts.
    • The shell must stay light because the router imports it eagerly.
    • The largest story churn of the three (66 View stories are redistributed).

Design C: Feature-owned tabs

  • SidebarTabView computes { isActive, isShown, isExpanded } once and calls tab.render(view).
  • Each feature is a module that owns its label, eligibility, selection, persistence and transcript opener context: Debug, Browser, Desktop, workspace tabs, and later Preview.
  • A registry hook lists the features. Persistence goes through one archived-aware helper.
  • The built-in Terminal becomes a seeded tab (storage migration with a legacy read). The pending terminal is deleted.
  • Result: about 190 lines and 14 props in the View. Preview is one module plus one line.
  • Strength: matches "features own eligibility and selection, the page owns activation". Fixes visibility drift structurally.
  • Weakness:
    • It is a small framework: feature type, registry, useSingletonTab, reduceRight provider nesting, hooks returning render closures.
    • It needs a storage migration, and features would share one singleton key with read-modify-write.
    • Deleting the pending terminal is an unmeasured UX bet.

Comparison

A B C
Pass-through contracts removed Most All Most
Duplicated decisions removed Most, except split tab ownership Most All
New abstractions 2 components Shell, panel, imperative handle Feature type, registry, 2 helpers
Touch points for a Preview-like tab About 8 About 6 (all inside the panel) 2
Storage migration No No Yes
Fit with your preferences Strong on "no controllers", weak on "features own eligibility" Mixed (ref handle, Page grows) Strong on ownership, weak on "no new controllers"
Migration risk Low Medium to high Medium

5. Recommendation: A's cleanup, then decide on C's ownership principle (without its framework)

Measure progress by contracts, duplicated decisions and effects removed, not by the View's line count.

Stage 1: design-agnostic cleanup (all three designs agree). Each item is an independent PR.

  1. Delete the dead code: unreachable UserTabContent fallbacks, repeated support checks, aliases, no-op classes, unused test id, inner keys, the redundant read-only gating term.
  2. Move leaf-only values into their consumers:
    • license values into QueuedForCapacityCallout
    • sshCommand into WorkspacePill
    • the timeline anchor into ChatPageTimeline
    • ChatWorkspaceContext around the timeline only
  3. Rebase refactor(site/src/pages/AgentsPage): move chat pages to ChatComposer #30638 onto the post-refactor(site): organize agent pages into route folders #31142 paths: the composer becomes a node, ChatPageInput owns its read-only presentation and attachedWorkspace, and the Page gates the turn-action handlers. Making the timeline a node too is a separate, optional PR.
  4. RightPanel owns the expansion gate and the live drag value. This deletes the View-level relay. Needs a manual drag check.
  5. SidebarTabView computes "shown" once and hands it to each panel. This fixes the Desktop, Browser and app-tab inconsistency.
  6. One save path per persisted value, covering every mutation path, with the archived rule written once. Render the built-in Terminal through the normal terminal path (synthesized, no migration). Add the missing Vitest coverage for terminal add and numbering, close and reopen, dedupe, and the archived rule.

Stage 2: reassess. After Stage 1 the View is mostly a list of regions plus tab activation. Two choices:

  • (a) Keep the tab model in the View as the single authority, and move only content rendering into a right-panel component. This is the small, A-shaped option.
  • (b) Share one layout between the loaded, loading and Suspense states. Adopt this only if it doesn't need B's imperative handle.

Stage 3, only if Preview still hurts: apply C's principle at the smallest scale.

  • Each tab-owning feature exposes its tab, menu toggle and opener from its own module.
  • The View lists the features explicitly. No registry hook, no reduceRight, no storage migration, no shared read-modify-write keys.
  • Preview's selection, reload and archived handling move into the Preview feature. Its auto-open must not be a page-level handled-ID effect.

Not recommended for now: B's imperative ref, C's registry and seeded-terminal migration, and any new controller or provider around the whole page.

6. Decisions needed from you

  1. Pending terminal: delete it after a quick visual check (it caps at 100 ms), or keep it inside the terminal tab code?
  2. Archived chats you own: should they stop offering "Edit message"? Today the composer is hidden but edit is offered.
  3. Singleton order: unify on one list? Today the tab bar and the menu disagree.
  4. Sequencing with your stacks: land Stage 1 before or after Preview feat(site): add a Preview tab for open_preview #31286, and revive the composer stack (refactor(site/src/pages/AgentsPage): move chat pages to ChatComposer #30638) now?

7. Risks to validate during implementation

  • Tool-opened tabs while the panel is hidden or narrow-suppressed.
  • Restoring saved tabs, eligibility changes (app or port disappears, then returns), and the archived rule.
  • Read-only submission. Permission checks stay at the mutation boundaries.
  • Live drag-to-expand and drag-to-close after the relay moves into RightPanel.
  • Loading-to-loaded draft survival, and the embed route at narrow widths.

@DanielleMaywood DanielleMaywood left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was performed by ai-review, an automated review bot.

4 inline findings.

Coverage
Coverage: 13 of 13 files reviewed; 35 rules.
Candidates: 298 found, 286 outside changed lines, 0 already discussed, 12 evaluated.
Findings: 4 (7 sites, 5 pre-existing sites), 0 over budget, 0 failed.
Model: deepseek/deepseek-v4.1-flash; 6 questions, 6 answered, 0 abstained, 0 cached; 0 uncalibrated findings held back; 5015 input and 7175 output tokens.

@DanielleMaywood
DanielleMaywood force-pushed the refactor/agents-chat-page-view-cleanup branch from 3aa1e41 to a631ee3 Compare October 29, 2026 12:19
@DanielleMaywood
DanielleMaywood marked this pull request as ready for review October 29, 2026 13:03
@DanielleMaywood
DanielleMaywood requested a review from a team as a code owner October 29, 2026 13:03
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T13:05:33.449934Z a631ee3 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…eView

Remove unreachable UserTabContent fallbacks (validateUserRightPanelTabs
already drops those tabs), a support check the add-tab menu already
applies, the shouldShowSidebar alias, no-op flex-row classes, an unused
test id, stray text nodes, redundant agentId keys (KeyedAgentChatPage
already keys the subtree), and a read-only term implied by
canSubmitChatTurn.
QueuedForCapacityCallout reads entitlements and permissions itself,
WorkspacePill fetches the deployment SSH config to build its command,
and ChatWorkspaceContext wraps only the timeline, its sole consumer.
Separate the logical steps in the tab list and the open-tab handlers
with blank lines.
@DanielleMaywood
DanielleMaywood force-pushed the refactor/agents-chat-page-view-cleanup branch from a631ee3 to 08c6e70 Compare October 29, 2026 13:06
@pr-queue-manager
pr-queue-manager Bot requested a review from jakehwll October 29, 2026 13:10
@DanielleMaywood
DanielleMaywood merged commit fefcfac into main Oct 29, 2026
25 checks passed
@DanielleMaywood
DanielleMaywood deleted the refactor/agents-chat-page-view-cleanup branch October 29, 2026 13:15
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants