Skip to content

feat(site/src): show agent startup logs in start and create tools - #29550

Merged
mafredri merged 5 commits into
mainfrom
mathias/agent-startup-logs
Sep 25, 2026
Merged

mafredri merged 5 commits into
mainfrom
mathias/agent-startup-logs

Conversation

@mafredri

@mafredri mafredri commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Closes CODAGT-166

start_workspace and create_workspace wait for the workspace agent after the build finishes (waitForAgentReady). During that wait the row showed only the finished build log.

WorkspaceAgentLogSection adds an agent startup log box under the build log box in both tools. It uses the same ScrollArea settings, LogsHeader and Logs list as the build log box, so rows, header, sizing and scrolling match. Stop is excluded because the backend does not wait for an agent after a stop build.

Design
  • Agent identity: chat.agent_id, read through useChatWorkspace(). That hook replaces the per-field hooks useChatWorkspaceId and useChatBuildId. Selecting the agent on the frontend was rejected because the backend marks the -coderd-chat naming rule as unstable.
  • The box renders only when the call's build (the chat buildId while running, the result build_id once completed) equals latest_build.id, latest_build.status is running, and the agent is in that build. The agent lookup (getWorkspaceAgent, which the workspace watch also uses) searches only the latest build, so without this check an older call would show a later build's agent.
  • Logs stream through useAgentLogs in both states. The stream replays from the start, so the box keeps its lines when the call completes. Each expand reconnects and replays the log (capped at 1 MiB), as the workspace page does.
  • Scrolling matches the build log box: the box scrolls to each new batch while the call runs, and after completion only for the first batch, normally the replay. Agents can keep writing lines after the call completes; scrollIntoView would otherwise pull the chat transcript to the row for each one.
  • While the call runs and no log has arrived, including before the chat's agent is in the latest build, the row shows "Waiting for workspace agent startup to complete…". Startup scripts may write no logs. A completed call with no logs shows nothing; the stream cannot tell an empty log from one not received yet.
  • Shared log components: the build stage header moved from WorkspaceBuildLogs into LogsHeader. Logs takes an optional LineOutput; the agent box passes AgentLogOutput, moved out of AgentLogLine, which renders ANSI colors and only the text after the last carriage return. Without LineOutput, Logs renders the same <span> as on main. Status lines in both sections render through LogNotice.
  • Each streamed batch re-renders every row of the box, as the build log box does on main. Logs is outside the React Compiler directories; the compiled parent reuses the Logs element while lines is unchanged.
  • Gaps shared with the build log box are tracked for both boxes: transcript scrolling (CODAGT-1184), truncation notice (CODAGT-1185), render cost (CODAGT-1182). Stream recovery after a socket error is tracked in CODAGT-1183.
  • A completed call whose build is no longer the latest shows no agent logs because the result has no agent_id. A running call follows the chat binding. Both are backend gaps, tracked in CODAGT-1181.
  • A row still reads "Started" or "Created" when the agent did not become ready or its startup scripts failed, because no renderer reads agent_status or startup_scripts. Tracked in CODAGT-1190.

🤖 This PR was created with the help of Coder Agents, and will be reviewed by a human. 🏂🏻

@mafredri
mafredri added this pull request to stack #29552 September 18, 2026 11:13
@mafredri
mafredri force-pushed the mathias/agent-startup-logs branch 2 times, most recently from ecb5df7 to 8aa01a8 Compare September 18, 2026 12:24
@linear-code

linear-code Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

@mafredri
mafredri force-pushed the mathias/agent-startup-logs branch from 8aa01a8 to a64868f Compare September 24, 2026 12:42
@mafredri
mafredri marked this pull request as ready for review September 24, 2026 12:45
@mafredri
mafredri force-pushed the mathias/agent-startup-logs branch from a64868f to be8cb16 Compare September 24, 2026 12:52
Base automatically changed from mathias/stop-workspace-tool to main September 24, 2026 13:14
@mafredri
mafredri force-pushed the mathias/agent-startup-logs branch from be8cb16 to 742ff0a Compare September 24, 2026 13:14
Comment on lines +90 to +95
const endRef = useRef<HTMLDivElement>(null);
useLayoutEffect(() => {
if (isRunning && logs && logs.length > 0) {
endRef.current?.scrollIntoView({ block: "end" });
}
}, [isRunning, logs]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Question to the agent: is this definitely the absolutely best way to do this? I recall this approach being a little buggy from experience. Not asking for a change here, this is the done approach. Just wanting to know if we can improve things

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 [CRF-3] scrollIntoView({ block: "end" }) scrolls the chat transcript as well as the log box, so a user who scrolled up is pulled back to this row on every streamed agent log batch. (Nami, Kite, Mafuuu)

Element.scrollIntoView scrolls every scrollable ancestor, and the transcript viewport (ChatMessageScroller.tsx:118, overflow-y-auto) is one, so this call overrides the scroller's release of follow-bottom when the user scrolls away. The effect runs on each logs change for the whole agent wait, which can last the agent connect timeout plus the startup script timeout. This is inferred from the DOM API contract and not reproduced in a browser. Scroll only the log viewport instead, as MessageBlocks.tsx:96 does for the thinking preview: set scrollTop = scrollHeight on the ScrollArea viewport element.

🤖

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No. scrollIntoView scrolls every scrollable ancestor, so each log batch also scrolls the chat transcript (CRF-3 above). In a Storybook browser test, an outer scroll container moved from scrollTop 0 to 1844 when the first batch arrived. The build log box does the same (WorkspaceBuildLogs.tsx:66). This PR keeps the agent box identical to the build log box, and CODAGT-1184 tracks fixing both boxes together so that streaming scrolls only the log box.

🤖 Posted using /amend-review skill via Coder Agents.

@mafredri

Copy link
Copy Markdown
Member Author

/coder-agents-review

@coder-agents-review

coder-agents-review Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-09-25 18:33 UTC by @mafredri

Review history
  • R2 (2026-09-25): 13 reviewers, 8 Nit, 3 P2, 8 P3, 14 P4, COMMENT. Review
  • R3 (2026-09-25): 9 reviewers, 8 Nit, 3 P2, 9 P3, 15 P4, COMMENT. Review

deep-review v0.13.0 | Round 3 | b3e073b..3f94e6c

Last posted: Round 3, 35 findings (3 P2, 9 P3, 15 P4, 8 Nit), COMMENT. Review

Finding inventory

Finding inventory: PR #29550

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P3 Author fixed (962d1d5) WorkspaceAgentLogSection.tsx:41 No test distinguishes result build_id from chat buildId for completed calls R1 Netero Yes
CRF-2 P4 Author fixed (962d1d5, branch removed) WorkspaceAgentLogSection.tsx:98 Refetch-failed-with-cached-data state has no story or test R1 Netero Yes
CRF-3 P2 Deferred (CODAGT-1184) WorkspaceAgentLogSection.tsx:93 scrollIntoView scrolls the chat transcript on every streamed agent log batch R1 Nami P2, Kite P2, Mafuuu P3 Yes
CRF-4 P2 Deferred (CODAGT-1182) WorkspaceAgentLogSection.tsx:150 Every streamed batch re-renders every log line with no virtualization R1 Killua P2, Kite P3 Yes
CRF-5 P3 Author fixed (962d1d5) WorkspaceAgentLogSection.tsx:87 On completion the log box collapses to a loading notice and returns scrolled to the top R1 Nami P3, Kite P3, Mafuuu P4 Yes
CRF-6 P3 Deferred (CODAGT-1185) WorkspaceAgentLogSection.tsx:121 logs_overflowed is dropped, so a truncated log renders as complete R1 Kite Yes
CRF-7 P3 Author fixed (962d1d5) WorkspaceAgentLogSection.tsx:80 Completed state adds a second data source where the after:0 stream would serve both states R1 Luffy Yes
CRF-8 P4 Author contested; panel closed R2 (1/1 accept) WorkspaceAgentLogSection.tsx:84 Each expand of a completed row re-downloads the full agent log R1 Nami Yes
CRF-9 P3 Deferred (CODAGT-1181) WorkspaceAgentLogSection.tsx:43 Completed row drops agent logs with no notice once the workspace stops or rebuilds R1 Luffy Yes
CRF-10 P4 Deferred (CODAGT-1181) WorkspaceAgentLogSection.tsx:41 No-build calls stream the existing agent's old log while running, then remove it on completion R1 Melody Yes
CRF-11 P3 Author fixed (962d1d5) WorkspaceAgentLogSection.tsx:42 Comment above buildIsCurrent names a hazard the check does not handle and omits the one it does R1 Gon P2, Leorio P3, Mafuuu Nit Yes
CRF-12 P3 Author fixed (962d1d5) WorkspaceAgentLogSection.tsx:43 buildIsCurrent name omits the latest_build.status === running condition R1 Gon Yes
CRF-13 P4 Author fixed (962d1d5) WorkspaceAgentLogSection.tsx:41 relevantBuildId does not say which build it holds R1 Gon Yes
CRF-14 P4 Author fixed (83db989, LogsHeader) WorkspaceAgentLogSection.tsx:141 12px header padding duplicates the WorkspaceBuildLogs header literal R1 Gon Yes
CRF-15 P4 Author fixed (962d1d5, branch removed) WorkspaceAgentLogSection.tsx:101 Fetch error notice discards the API error and gives no retry path R1 Leorio Yes
CRF-16 P4 Author fixed (962d1d5) WorkspaceAgentLogSection.tsx:25 Component doc omits the conditions under which it renders nothing R1 Leorio Yes
CRF-17 P4 Author fixed (962d1d5) CreateWorkspaceTool.tsx:85 No test covers create_workspace passing result build_id for a completed call R1 Bisky Yes
CRF-18 P4 Author fixed (962d1d5) WorkspaceAgentLogSection.tsx:114 No story renders the "Waiting for agent logs…" state R1 Bisky Yes
CRF-19 Nit Author fixed (962d1d5) WorkspaceAgentLogSection.tsx:79 streamedLogs diverges from streamingLogs in the sibling section R1 Gon Yes
CRF-20 Nit Author fixed (962d1d5, hook removed) ChatWorkspaceContext.tsx:26 useChatAgentId doc is one 110-column line; siblings wrap R1 Gon Yes
CRF-21 Nit Author fixed (962d1d5) WorkspaceAgentLogSection.test.tsx:83 currentBuild holds a build ID R1 Gon Yes
CRF-22 Nit Author fixed (962d1d5) Tool.test.tsx:20 agentLogs table flag shares a name with the query factory and differs from streams R1 Gon Yes
CRF-23 Nit Author contested; panel closed R2 (1/1 accept) WorkspaceAgentLogSection.tsx:151 sourceIcon={null} drops per-line log source attribution R1 Kite Yes
CRF-24 P4 Process note (body); author fixed (PR title) commit subject Commit subject names only the start tool; the diff also changes create R1 Leorio No
CRF-25 P1 Dropped by orchestrator (disproved: GET /chats/{id} repairs agent_id, exp_chats.go:1630; watch refetch useWorkspaceWatch.ts:47-55) WorkspaceAgentLogSection.tsx:53 chat.agent_id is null during a tool-started build so the stream never starts R1 Pariston No
CRF-26 P3 Dropped by orchestrator (disproved: AgentChatPage.tsx:134-147 polls while binding unresolved regardless of chat status) WorkspaceAgentLogSection.tsx:54 Completed row shows no agent logs until reload after a hidden-tab start R1 Melody No
CRF-27 Note Note (body); deferred (CODAGT-1181) AgentChatPageView.tsx:845 Running-state stream depends on response-only repair and the watch refetch; no test covers the chain R1 Luffy, Kite No
CRF-28 Note Dropped by orchestrator (confirmation, no action) WorkspaceAgentLogSection.tsx:49 Replaced, failed, and stale-agent rows open no socket for the wrong agent R1 Nami No
CRF-29 Note Dropped by orchestrator (confirmation, no action) WorkspaceLifecycleTool.tsx:57 Feature addresses the agent-wait gap and excludes stop correctly R1 Luffy No
CRF-30 Note Dropped by orchestrator (confirmation, no action) WorkspaceAgentLogSection.tsx:88 agent_id and build_id wire chains agree R1 Melody No
CRF-31 Note Dropped by orchestrator (confirmation, no action) WorkspaceAgentLogSection.test.tsx:84 Gating tests fail under mutation R1 Bisky No
CRF-32 Note Dropped by orchestrator (process record, no action) WorkspaceAgentLogSection.tsx Comment audit coverage record R1 Gon No
CRF-33 Note Dropped by orchestrator (confirmation, no action) WorkspaceLifecycleTool.tsx:56 Stop-exclusion comment is accurate R1 Leorio No
CRF-34 Note Dropped by orchestrator (praise, no action) PR Single logical change with negative test rows R1 Kite No
CRF-35 OOS Out of scope (body); tracked (CODAGT-1184) WorkspaceBuildLogs.tsx:66 Build log scrollIntoView also pulls the transcript during the build phase R1 Nami, Mafuuu, Kite No
CRF-36 OOS Out of scope (body); tracked (CODAGT-1182) WorkspaceBuildLogSection.tsx:74 Build logs in chat render non-virtualized up to the 1 MiB cap R1 Killua, Kite No
CRF-37 OOS Out of scope (body); tracked (CODAGT-1183) useAgentLogs.ts:59-65 Socket error closes without reconnect and toasts the agent UUID R1 Mafuuu, Kite No
CRF-38 OOS Out of scope (body); tracked (CODAGT-1181) startworkspace.go:225 Tools select the chat agent but never persist or publish it; persistBuildAgentBinding publishes no event R1 Pariston, Melody No
CRF-39 OOS Out of scope (body); tracked (CODAGT-1181) createworkspace.go:621 waitForAgentReady result carries no agent_id, so older calls cannot show their agent logs R1 Luffy No
CRF-40 P4 Author contested; panel closed R3 (1/1 accept) WorkspaceAgentLogSection.tsx:107 No test or story play asserts rendered agent box output; removing LineOutput or either waiting notice passes R2 Netero Yes
CRF-41 P2 Author fixed (d9cd92a) WorkspaceAgentLogSection.tsx:79 With the stream open after completion, scrollIntoView pulls the transcript to an expanded completed row on every later batch R2 Kite P3 Yes
CRF-42 P3 Author fixed (3f94e6c; not_ready row label tracked in CODAGT-1190) WorkspaceAgentLogSection.tsx:85 "Waiting for agent logs…" shows while the agent has not connected, and the box vanishes on not_ready R2 Leorio Yes
CRF-43 P4 Author fixed (3f94e6c) AgentLogLine.tsx:14 Exported AgentLogOutput doc omits that text before the last carriage return is dropped R2 Leorio P4, Gon P2 Yes
CRF-44 Nit Author fixed (3f94e6c) WorkspaceAgentLogSection.tsx:44 Comment's second clause restates the condition below it R2 Gon P2 Yes
CRF-45 P2 Dropped by orchestrator (accurate doc; the example names a real caller and restricts nothing) Logs.tsx:14 LogsHeader doc example "such as a build stage" R2 Gon No
CRF-46 P4 Author fixed (3f94e6c) WorkspaceAgentLogSection.tsx:70 AgentStartupLogs isRunning prop reads as the agent's state R2 Gon Yes
CRF-47 Nit Author fixed (3f94e6c) Tool.stories.tsx:2548 Agent story names do not match what they render (StartWorkspaceAgentStarting uses a ready agent) R2 Gon, Razor Yes
CRF-48 P4 Author fixed notice half (3f94e6c); ScrollArea half contested; panel closed R3 (1/1 accept) WorkspaceAgentLogSection.tsx:98 ScrollArea props and notice markup copied literally from WorkspaceBuildLogSection R2 Razor Yes
CRF-49 P4 Author fixed (3f94e6c) WorkspaceAgentLogSection.tsx:54 Agent lookup reimplements getWorkspaceAgent that the watch bailout uses R2 Razor Yes
CRF-50 Nit Author fixed (3f94e6c) Logs.tsx:22 first-of-type:pt-4 never applies because the inline padding overrides it R2 Razor P4 Yes
CRF-51 Note Dropped by orchestrator (confirmation, no action) WorkspaceAgentLogSection.tsx:74 CRF-5 fix addresses the root cause R2 Nami No
CRF-52 Note Dropped by orchestrator (confirmation, no action) WorkspaceAgentLogSection.tsx:43 Declared pairings and removed exports agree R2 Melody No
CRF-53 Note Dropped by orchestrator (confirmation, no action) WorkspaceAgentLogSection.tsx:74 CRF-7 fix removes the second data source R2 Luffy No
CRF-54 Note Dropped by orchestrator (confirmation, no action) Tool.test.tsx:20 CRF-17 and CRF-18 fixes verified by mutation R2 Bisky No
CRF-55 Note Dropped by orchestrator (process record, no action) WorkspaceAgentLogSection.tsx Comment-quality pattern across the PR R2 Gon No
CRF-56 Note Dropped by orchestrator (confirmation, no action) ChatWorkspaceContext.tsx:12 useChatWorkspace doc states the stale-binding precondition R2 Leorio No
CRF-57 Note Dropped by orchestrator (praise, no action) PR Agent box reuses Logs and LogsHeader R2 Kite No
CRF-58 OOS Out of scope (body); tracked (CODAGT-1181) createworkspace.go:461 On agent selection failure create_workspace waits on agents[0], which the frontend cannot identify R2 Melody No
CRF-59 OOS Out of scope (body); accepted by PR owner (exists on main) LogLine.tsx:5 DEFAULT_LOG_LINE_SIDE_PADDING declared separately in LogLine.tsx and Logs.tsx R2 Gon No
CRF-60 OOS Out of scope (body); tracked (CODAGT-1190) WorkspaceLifecycleTool.tsx:39 not_ready or failed startup scripts still label the row "Started"; no renderer reads agent_status R2 Leorio No
CRF-61 OOS Out of scope (body); accepted by PR owner (exists on main) WorkspaceBuildLogs.tsx:44 sticky prop is destructured and never used R2 Razor No
CRF-62 P4 Open WorkspaceAgentLogSection.tsx:80 No test covers scrolling on every batch while running; scroll-once mutation passes R3 Netero Yes
CRF-63 P3 Open WorkspaceAgentLogSection.tsx:80 Scroll gate keys on first non-empty batch, so an empty replay or a no-log running row scrolls the transcript on the first later line R3 Meruem P3, Kite P4 Yes
CRF-64 Note Dropped by orchestrator (confirmation, no action) WorkspaceAgentLogSection.tsx:77 CRF-41 fix correct for rows that received logs while running R3 Kite No
CRF-65 Note Dropped by orchestrator (confirmation, no action) WorkspaceAgentLogSection.tsx:117 Unified waiting notice is accurate in every state that renders it R3 Leorio No
CRF-66 Note Dropped by orchestrator (confirmation, no action) WorkspaceAgentLogSection.tsx:45 Agent box covers each visible state without overlapping the build box R3 Nami No
CRF-67 Note Dropped by orchestrator (confirmation, no action) WorkspaceAgentLogSection.test.tsx:178 CRF-41 scroll tests fail when the guard is removed R3 Bisky No
CRF-68 OOS Out of scope (body) WorkspaceBuildLogSection.tsx:50 refetchInterval 2000 literal repeated as "2s" in the comment at line 41 R3 Gon No

Contested and acknowledged

CRF-8 (P4, WorkspaceAgentLogSection.tsx:84) - Each expand of a completed row re-downloads the full agent log

  • Finding: Nami (R1) found that staleTime: 0 with refetchOnMount: true re-fetched the full agent log on every expand of a completed row, and proposed applying staleTime: 0 only while lifecycle_state is created or starting.
  • Author defense (R2): The REST query is gone; each expand now reconnects the socket and replays the log. Agent logs can grow after the call completes (a not_ready timeout leaves startup scripts running), so a cache needs a staleness rule, and a lifecycle-dependent staleTime adds a state. AgentRow also streams on every expand. The replay is capped at 1 MiB.
  • Panel closure (R2, 1/1): Nami, the agent that raised it (round 1 agent reused through message_agent), accepted: only rows whose build is latest_build render the box, completed rows mount collapsed so a page load opens no sockets, a cached REST snapshot would need a staleness rule because logs grow after a not_ready result, and AgentRow streams on every expand the same way.

CRF-23 (Nit, WorkspaceAgentLogSection.tsx:151) - sourceIcon={null} drops per-line log source attribution

  • Finding: Kite (R1) found that the chat box drops the per-line source icon AgentLogs shows, so interleaved lines from several scripts cannot be tied to their script, and asked to pass the icon or state in a comment why the chat view omits it.
  • Author defense (R2): The agent box matches the build log box, which shows no source icons. The box now renders through the shared Logs, which has no source icon slot.
  • Panel closure (R2, 1/1): Kite, the agent that raised it (round 1 agent reused through message_agent), conceded: the box header names the agent, AgentRow on the workspace page shows source icons for debugging a failing script, and Logs has no source slot that the build box would also need. Kite noted the "matches the build box" argument alone was weak because build logs have one source and agent logs several.

CRF-40 (P4, WorkspaceAgentLogSection.tsx:107) - No test or story play asserts rendered agent box output

  • Finding: Netero (R2) reproduced that removing LineOutput={AgentLogOutput} or either waiting notice still passes every unit test and story, because the unit tests assert only socket calls and the agent stories have no play function. Proposed play assertions for the rendered ANSI/carriage-return line and the notice text.
  • Author defense (R3): FE1 in .claude/docs/FRONTEND_PATTERNS.md limits a story's play function to state setup and rules out asserting what the DOM renders, because Pixel screenshots each story. StartWorkspaceAgentLogsStreaming renders the ANSI and carriage-return lines, and StartWorkspaceAgentNotInLatestBuild and StartWorkspaceAgentNoLogs render the waiting notice, so those mutations change screenshots. AgentLogLine.test.tsx tests ANSI rendering, escaping, and carriage-return handling through AgentLogOutput.
  • Panel closure (R3, 1/1): Netero, the agent that raised it (round 2 agent reused through message_agent), accepted: FE1 (.claude/docs/FRONTEND_PATTERNS.md) forbids assertions in play functions and rendered-DOM assertions in Vitest, the reported mutations change the Pixel screenshots of StartWorkspaceAgentLogsStreaming, StartWorkspaceAgentNotInLatestBuild, and StartWorkspaceAgentNoLogs, and the proposed fix contradicted FE1.

CRF-48 (P4, WorkspaceAgentLogSection.tsx:98) - ScrollArea props and notice markup copied from WorkspaceBuildLogSection

  • Finding: Razor (R2) found the agent box copies the build box's five ScrollArea props and its notice markup literally, so a height or border change to one box does not reach the other. Proposed extracting a shared ScrollArea wrapper and notice component.
  • Author defense (R3): The notice half is fixed: LogNotice renders the five status lines in WorkspaceBuildLogSection and the agent waiting message. The ScrollArea props stay inline because they are the tool-row convention: Tool.tsx:882 and ReadFileTool.tsx:24 pass the same five props. A shared box for only these two sections would make them differ from the other tool boxes, and one component for all tool output boxes is outside this PR.
  • Panel closure (R3, 1/1): Razor, the agent that raised it (round 2 agent reused through message_agent), accepted: 12 files under ChatElements/tools/ render a ScrollArea with the same props (Tool.tsx:881-887, ReadFileTool.tsx:23-29), so a wrapper shared only by the build and agent boxes would make those two differ from the rest without removing the copying; one component for all tool boxes changes code the diff does not touch. The notice half is fixed by LogNotice.

Law analysis

Not run. Effective additions +614 at 742ff0a (threshold 1000).

Round log

Round 1

Netero first pass: 1 P3, 1 P4. Mechanical floor clean (P3 and below), proceeding to full panel.
Round type: round 1, full panel.
Panel: ging-ts, ging-react, nami, killua, melody, luffy (domain specialists triggered by .ts/.tsx, frontend UI, streamed log rendering and shared query cache options, websocket stream to query fetch handoff, new user-facing feature), pariston, mafuuu (core), bisky (tests changed), gon, leorio (once-per-PR floor), kite (wildcard). Size exceeds the focused target of 6-8 because six domain specialists (ging-ts, ging-react, nami, killua, melody, luffy) triggered.
Cross-check:

  • CRF-3 convergent (Nami P2, Kite P2, Mafuuu P3), set P2. Posted as a reply on the human reviewer's thread asking whether the scrollIntoView approach is best.
  • CRF-4 convergent (Killua P2 with jsdom measurement, Kite P3), set P2. Posted at Kite's line 150 (lines.map); Killua reported 147.
  • CRF-5 convergent (Nami P3, Kite P3, Mafuuu P4), set P3. CRF-7 (stream for both states) is an alternative fix for CRF-5 and removes the CRF-2 branch.
  • CRF-11 convergent (Gon P2, Leorio P3, Mafuuu Nit). Keep-argument for P2: the comment is the only explanation beside the check and names a hazard handled by findWorkspaceAgent, so a maintainer may delete the check and render a later build's agent under an older call. Downgrade reason: Netero's mutation run shows removing the build-id check fails two table rows, so that deletion cannot land silently. Set P3.
  • CRF-25 dropped. Keep-argument: the stream depends on a response-only repair and a refetch trigger in modules the PR does not change, and the tests feed a (current build, bound agent) pair the DB never holds during a tool-started build. Drop reason: the frontend reads the repaired GET response (exp_chats.go:1630, tested at exp_chats_internal_test.go:251), and useWorkspaceWatch.ts:47-55 refetches the chat when the latest build is running and the bound agent is absent; Luffy, Melody, and Kite traced the same chain. The untested dependency is kept as CRF-27 Note (body).
  • CRF-26 dropped. Keep-argument: the binding-repair poll does not run in a hidden tab and the watch latch fires once per key, so a failed repair GET leaves the row empty until the tab is visible. Drop reason: the claimed consequence (no refetch until reload) does not occur because AgentChatPage.tsx:134-147 polls every 30 s while the binding is unresolved, independent of chat status.
  • CRF-24 has no file line; carried in the review body as a process observation.
    Totals: 2 P2, 7 P3, 9 P4, 5 Nit posted; 1 process note and 1 Note in body; 5 out of scope; 9 dropped. Reviewed against 646270a..742ff0a.

Round 2

Churn guard: PROCEED. 16 addressed (962d1d5, 83db989), 5 deferred with tickets (CRF-3 CODAGT-1184, CRF-4 CODAGT-1182, CRF-6 CODAGT-1185, CRF-9 and CRF-10 CODAGT-1181), 2 contested (CRF-8, CRF-23), 0 silent. The author's reply on the CRF-4 thread describes a memoized AgentLogRow that 83db989 removed; the PR description defers the render cost to CODAGT-1182.
Inventory validation: CRF-25 and CRF-26 drop reasons still hold (section still keys on chat.agent_id and the repair chain is unchanged). CRF-3 deferral premise (agent box matches the build box, forced scroll bounded to the call) no longer holds after 962d1d5; raised as new finding CRF-41 rather than reopening CRF-3, since the new problem is introduced by the CRF-5/CRF-7 fix.
Round type: restructure (PR now changes Logs.tsx, AgentLogLine.tsx, WorkspaceBuildLogs.tsx, WorkspaceBuildLogSection.tsx; exported hooks replaced by useChatWorkspace; Logs gains LineOutput; section rewritten; title changed). Full panel.
Netero: post-panel advisory, 1 P4 (CRF-40).
Panel: ging-ts, ging-react, nami, killua, melody, luffy (domain specialists), pariston, mafuuu (core), bisky (tests changed), gon, leorio (restructure round floor), kite (dispute check-in for CRF-23, not counted toward size), razor (wildcard). Size exceeds the focused target because six domain specialists triggered. Nami and Kite ran on their round 1 agents via message_agent; all others were new agents titled <persona> PR29550 R2.
Dispute check-in: CRF-8 closed 1/1 (Nami accepts). CRF-23 closed 1/1 (Kite concedes).
Cross-check:

  • CRF-41 (Kite P3) set P2. Keep-argument for P2: CRF-3 was P2 for a forced transcript scroll bounded to the agent wait; the same scroll now has no time bound for any expanded completed row whose build is current, triggered by cron coder_script runs (agentscripts.go:151 through GetScriptLogger) and by startup scripts still running after not_ready, and the deferral's basis (matches the build box) fails because the build box stops scrolling at completion. Kite rated P3 on the grounds that it is inferred and requires output after completion; the skill's inventory-validation rule reopens a broken deferral at its original severity, so P2.
  • CRF-43 convergent (Leorio P4, Gon P2), set P4. Keep-argument for P2: AgentLogOutput is now exported through the shared Logs, so a caller using it for other output loses text before a carriage return with only the body to warn them. Downgrade reason: one consumer, the name scopes it to agent log output, and the behavior moved verbatim from AgentLogLine; the consequence is a doc gap, and Leorio, who gave the concrete input/output example, rated P4.
  • CRF-44 (Gon P2) set Nit. Keep-argument: the second clause duplicates the condition on the next lines, so the rule is read twice and can drift. Downgrade reason: the comment is accurate and carries the one fact the code does not show (lookup scope); Mafuuu, Leorio, and Razor each verified it true.
  • CRF-45 (Gon P2) dropped. Keep-argument: a doc example that fits one of two callers can mislead on when to use LogsHeader. Drop reason: the doc states the contract ("Section header above a Logs list") and the example correctly names one real caller without restricting use.
  • CRF-50 (Razor P4) set Nit. Keep-argument: the shared component now advertises a first-header top padding that never renders, so a maintainer tuning spacing edits a class with no effect. Downgrade reason: rendered padding is unchanged from main (moved verbatim); the class is dead style, not a behavior change.
  • CRF-47 convergent (Gon Nit, Razor Nit), one comment.
    Totals: 1 P2, 1 P3, 5 P4, 3 Nit posted; 4 out of scope; 1 dropped finding; 7 dropped confirmations. Reviewed against b3e073b..83db989.

Round 3

Churn guard: PROCEED. 9 addressed (d9cd92a, 3f94e6c), 5 deferred with tickets unchanged, CRF-40 contested, CRF-48 ScrollArea half contested (churn guard counted CRF-48 as addressed; the author's reply contests the ScrollArea half, so it went to dispute check-in), 0 silent. OOS replies: CRF-58 added to CODAGT-1181, CRF-60 tracked in CODAGT-1190, CRF-59 and CRF-61 accepted by the PR owner (exist on main).
Inventory validation: CRF-3 deferral premise holds again at 3f94e6c (agent box scrolls on each batch while running and once after completion, as the build box does). Dropped items unchanged.
Round type: fix round. LogNotice.tsx is a new file, but it exists only to fix CRF-48; every change since 83db989 traces to a round 2 finding, the title and goal are unchanged, and effective additions grew by 57.
Netero: round 2 agent reused through message_agent (CRF-40 dispute). CRF-40 closed 1/1. New P4 CRF-62.
Panel: razor (dispute check-in for CRF-48, round 2 agent reused), kite (CRF-41), leorio (CRF-42, CRF-43; doc comments changed), gon (CRF-43, 44, 46, 47; comments changed), ging-ts, ging-react, nami (specialists for the changed .tsx files), bisky (tests added for CRF-41), meruem (wildcard). All but razor were new agents titled <persona> PR29550 R3.
Dispute check-in: CRF-40 closed 1/1 (Netero accepts; its fix contradicted FE1). CRF-48 closed 1/1 (Razor accepts; 12 tool files share the ScrollArea props).
Cross-check:

  • CRF-63 convergent (Meruem P3 completed-mount empty replay, Kite P4 running-mount with no logs), set P3. One mechanism (gate keyed on the first non-empty batch) and one fix. The author reported that the PR owner accepted "an empty replay followed by a late line still scrolls once" without stating the basis; the PR description states that the stream cannot tell an empty log from one not received yet, which Meruem disproved (server sends the replay as one message even when empty, workspaceagents.go:509; useAgentLogs.ts:45 drops it). Posted as a reply on the CRF-41 thread so the human sees the new fact where the acceptance was recorded.
  • CRF-62 (Netero P4), posted inline.
    Totals: 1 P3, 1 P4 posted; 1 out of scope; 4 dropped confirmations. Reviewed against b3e073b..3f94e6c.
About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Komugi flake/determinism
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR adds WorkspaceAgentLogSection under the build log in start_workspace and create_workspace rows, keyed on chat.agent_id. Findings: 2 P2, 7 P3, 9 P4, 5 Nit.

The commit subject and PR title name only the start tool, but the diff also adds the section to create_workspace; feat(site/src/pages/AgentsPage): show agent logs in start/create tools covers both.

Out of scope (needs a ticket or explicit acceptance by a human):

  • site/src/modules/workspaces/WorkspaceBuildLogs/WorkspaceBuildLogs.tsx:66: the build log calls scrollIntoView({ block: "end" }) on every streamed line, so the chat transcript is also pulled to the tool row during the build phase.
  • site/src/pages/AgentsPage/components/ChatElements/tools/WorkspaceBuildLogSection.tsx:74: build logs in the chat render every line without virtualization, up to the 1 MiB provisioner log cap.
  • site/src/modules/resources/useAgentLogs.ts:59-65: a socket error closes the socket without reconnecting and shows a toast naming the agent by UUID, so the chat row stops updating for the rest of the agent wait and the toast names nothing the user can see.
  • coderd/x/chatd/chattool/startworkspace.go:225: the start and create tools select the chat agent but never persist or publish it, and persistBuildAgentBinding (coderd/x/chatd/chatd.go:492) publishes no watch event, so every frontend reader of chat.agent_id depends on the response-only repair in GET /chats/{id}.
  • coderd/x/chatd/chattool/createworkspace.go:621: the waitForAgentReady result carries no agent_id, so a completed call cannot show its agent logs after its build is replaced.

Notes:

  • While a tool runs, the database holds agent_id = NULL (publishBuildBinding, coderd/x/chatd/chattool/chattool.go:126). The section finds the agent only after useWorkspaceWatch refetches the chat and repairChatAgentIDs (coderd/exp_chats.go:563) fills agent_id in the response. No test covers that chain, so a change to either one would leave the running state on "Waiting for workspace agent…" with no failing test.

🤖 This review was automatically generated with Coder Agents.

@mafredri mafredri changed the title feat(site/src/pages/AgentsPage): show agent startup logs in start tool feat(site/src/pages/AgentsPage): show agent startup logs in start and create tools Sep 24, 2026
@mafredri

Copy link
Copy Markdown
Member Author

In reply to CRF-24 (P4, site/src/pages/AgentsPage/components/ChatElements/tools/CreateWorkspaceTool.tsx:85): #29550 (review)

The PR title, which becomes the squash commit subject, now names start and create.


In reply to CRF-27 (Note, site/src/pages/AgentsPage/AgentChatPageView.tsx:845): #29550 (review)

Deferred to CODAGT-1181. It now describes the running call depending on the response-only agent_id repair and asks the call to expose its agent.


In reply to CRF-35 (OOS, site/src/modules/workspaces/WorkspaceBuildLogs/WorkspaceBuildLogs.tsx:66): #29550 (review)

Deferred to CODAGT-1184, which covers both log boxes.


In reply to CRF-36 (OOS, site/src/pages/AgentsPage/components/ChatElements/tools/WorkspaceBuildLogSection.tsx:74): #29550 (review)

Deferred to CODAGT-1182, which covers both log boxes and includes the measurements.


In reply to CRF-37 (OOS, site/src/modules/resources/useAgentLogs.ts:59): #29550 (review)

Deferred to CODAGT-1183.


In reply to CRF-38 (OOS, coderd/x/chatd/chattool/startworkspace.go:225): #29550 (review)

Deferred to CODAGT-1181.


In reply to CRF-39 (OOS, coderd/x/chatd/chattool/createworkspace.go:621): #29550 (review)

Deferred to CODAGT-1181.

🤖 Posted using /amend-review skill via Coder Agents.

@mafredri
mafredri requested a review from a team as a code owner September 25, 2026 13:54
@mafredri mafredri changed the title feat(site/src/pages/AgentsPage): show agent startup logs in start and create tools feat(site/src): show agent startup logs in start and create tools Sep 25, 2026
start_workspace and create_workspace wait for the agent after the
build finishes. The row showed only the finished build log during
that time.

Add WorkspaceAgentLogSection under the build log. It streams agent
logs while the tool runs and fetches them once it completes. The
agent is chat.agent_id, shown only when it is in the workspace's
current running build and that build is the one the call refers to.
Stop is excluded: the backend does not wait for an agent after a
stop build.
The running state streamed agent logs and the completed state fetched
them over REST. On completion the stream cleared its lines, and the box
collapsed to a loading notice until the fetch resolved. The stream
replays the log from the start, so it now serves both states, and the
REST query, its cache override, and its error branches are removed.

Log rows are memoized. Re-rendering every row took 312 ms per 50-line
batch at 5,000 lines in a Storybook dev build; memoized rows took 32 ms.

useChatWorkspace replaces three hooks that each read one field of the
same context value.
The agent box rendered rows with AgentLogLine, whose min-h-5 gives
20px rows to match AGENT_LOG_LINE_HEIGHT in the workspace page's
virtualized list. Build log rows are 16px. The agent box also lacked
the build box's horizontal scroll for long lines and the border under
its header, because that markup was copied instead of shared.

The agent box now renders through Logs and LogsHeader, which is
extracted from WorkspaceBuildLogs. Logs takes an optional LineOutput;
the agent box passes AgentLogOutput, split out of AgentLogLine, to
keep ANSI colors and carriage-return handling. Without LineOutput,
Logs renders the same span as before.

Each streamed batch re-renders every agent row, as the build box does
on main, because Logs is outside the React Compiler's directories.
CODAGT-1182 tracks that cost for both boxes.
@mafredri
mafredri force-pushed the mathias/agent-startup-logs branch from 775f380 to 83db989 Compare September 25, 2026 14:43
@mafredri

Copy link
Copy Markdown
Member Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This round reviews the rework that streams agent logs in both states and draws the box with the shared Logs and LogsHeader. New findings: 1 P2, 1 P3, 5 P4, 3 Nit.

16 round 1 findings are fixed in 962d1d5 and 83db989, and 5 are deferred with tickets (CODAGT-1181, CODAGT-1182, CODAGT-1184, CODAGT-1185). The defenses on the re-download-on-expand and source-icon threads are accepted.

The reply on the re-render thread describes a memoized AgentLogRow that 83db989 removed; update it to say the cost is deferred to CODAGT-1182, as the PR description does.

Out of scope (needs a ticket or explicit acceptance by a human):

  • coderd/x/chatd/chattool/createworkspace.go:461: when FindChatAgent fails, create_workspace on an existing workspace waits on agents[0] while enrichChatAgentIDs leaves agent_id unrepaired, so the agent box shows "Waiting for workspace agent…" for the whole wait.
  • site/src/components/Logs/LogLine.tsx:5: DEFAULT_LOG_LINE_SIDE_PADDING is declared separately here and in Logs.tsx, so changing one misaligns the LogsHeader padding from the log line padding.
  • site/src/pages/AgentsPage/components/ChatElements/tools/WorkspaceLifecycleTool.tsx:39: a start call that returns agent_status: "not_ready" or failed startup scripts is labeled "Started", and no chat renderer reads agent_status, so the user sees success when the agent never became usable.
  • site/src/modules/workspaces/WorkspaceBuildLogs/WorkspaceBuildLogs.tsx:44: the sticky prop is destructured and never used, so WorkspaceBuildLogSection passes sticky and gets no sticky stage headers.

🤖 This review was automatically generated with Coder Agents.

Comment thread site/src/components/Logs/Logs.tsx Resolved
The agent log stream stays open after the call completes, and agents
keep writing lines after that, for example from cron scripts or from
startup scripts that outlive the tool's wait. Each batch ran
scrollIntoView, which also scrolls the chat transcript, so a completed
row pulled the transcript back to itself whenever a line arrived.

The build log box scrolls while its call runs and once when a
completed row loads its logs. The agent box now does the same: it
scrolls on every batch while the call runs, and after completion only
for the replay, which the server sends as one message on connect.
The agent box showed "Waiting for workspace agent…" while the chat's
agent was not in the latest build and "Waiting for agent logs…" after.
In both states the tool waits for the agent to connect and its startup
scripts to finish, and scripts may write no logs, so both now say
"Waiting for workspace agent startup to complete…".

The build and agent log sections repeated the same status line markup;
both now render LogNotice.

The agent lookup calls getWorkspaceAgent, the helper the workspace
watch uses to decide whether its cached workspace changed. The rest
renames the isRunning prop to isCallRunning, moves the carriage-return
behavior into the AgentLogOutput doc, drops a first-of-type:pt-4 class
that the header's inline padding always overrode, and renames two
stories to describe what they render.
@mafredri

Copy link
Copy Markdown
Member Author

In reply to AMREM-4 (P4, site/src/pages/AgentsPage/components/ChatElements/tools/WorkspaceAgentLogSection.tsx:107): #29550 (review)

The reply on the re-render thread now says the cost is deferred to CODAGT-1182. Out-of-scope notes:

  1. create_workspace waiting on the first agent when FindChatAgent fails, with no agent ID repaired: added to CODAGT-1181 as a case.
  2. DEFAULT_LOG_LINE_SIDE_PADDING declared in both LogLine.tsx and Logs.tsx: exists on main; left unchanged, accepted by the PR owner.
  3. Rows labeled "Started" or "Created" when agent_status is not_ready or startup scripts failed: CODAGT-1190.
  4. Unused sticky prop in WorkspaceBuildLogs: exists on main; left unchanged, accepted by the PR owner.

🤖 Posted using /amend-review skill via Coder Agents.

@mafredri

Copy link
Copy Markdown
Member Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Round 3 review of the agent startup log box under the start and create workspace tool rows: 1 P3, 1 P4.

The round 2 findings are resolved: fixes in d9cd92a and 3f94e6c, and accepted defenses for the missing rendered-output assertions and the copied ScrollArea props. The five deferred round 1 findings keep their tickets.

Out of scope (needs a ticket or explicit acceptance by a human):

  • site/src/pages/AgentsPage/components/ChatElements/tools/WorkspaceBuildLogSection.tsx:50: refetchInterval: 2000 is restated as "2s" in the comment at line 41, so a change to the interval leaves the comment wrong.

🤖 This review was automatically generated with Coder Agents.

useLayoutEffect(() => {
// After the call completes, scroll only for the first batch: scrollIntoView
// also moves the chat transcript.
if (logs.length > 0 && (isCallRunning || !hasScrolledRef.current)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P4 [CRF-62] No test checks that a running row scrolls on every batch, so changing the condition to scroll only for the first batch passes every test. (Netero)

With (isCallRunning || !hasScrolledRef.current) replaced by !hasScrolledRef.current, pnpm exec vitest run on WorkspaceAgentLogSection.test.tsx, Tool.test.tsx and AgentLogLine.test.tsx gives Tests 18 passed (18). The test "keeps streaming agent logs after the call completes without scrolling to new lines" publishes one batch while the call runs, so it passes whether a running row follows each new batch or only the first. Publish a second batch before the rerender to completed and expect scrollIntoView to have been called twice.

🤖

@mafredri
mafredri merged commit 6f0c447 into main Sep 25, 2026
31 checks passed
@mafredri
mafredri deleted the mathias/agent-startup-logs branch September 25, 2026 18:58
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 25, 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.

3 participants