Repository navigation
feat(site/src): show agent startup logs in start and create tools - #29550
Conversation
ecb5df7 to
8aa01a8
Compare
8aa01a8 to
a64868f
Compare
a64868f to
be8cb16
Compare
be8cb16 to
742ff0a
Compare
| const endRef = useRef<HTMLDivElement>(null); | ||
| useLayoutEffect(() => { | ||
| if (isRunning && logs && logs.length > 0) { | ||
| endRef.current?.scrollIntoView({ block: "end" }); | ||
| } | ||
| }, [isRunning, logs]); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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-reviewskill via Coder Agents.
|
/coder-agents-review |
|
Chat: Review posted | View chat Review historydeep-review v0.13.0 | Round 3 | Last posted: Round 3, 35 findings (3 P2, 9 P3, 15 P4, 8 Nit), COMMENT. Review Finding inventoryFinding inventory: PR #29550Findings
Contested and acknowledgedCRF-8 (P4, WorkspaceAgentLogSection.tsx:84) - Each expand of a completed row re-downloads the full agent log
CRF-23 (Nit, WorkspaceAgentLogSection.tsx:151) - sourceIcon={null} drops per-line log source attribution
CRF-40 (P4, WorkspaceAgentLogSection.tsx:107) - No test or story play asserts rendered agent box output
CRF-48 (P4, WorkspaceAgentLogSection.tsx:98) - ScrollArea props and notice markup copied from WorkspaceBuildLogSection
Law analysisNot run. Effective additions +614 at 742ff0a (threshold 1000). Round logRound 1Netero first pass: 1 P3, 1 P4. Mechanical floor clean (P3 and below), proceeding to full panel.
Round 2Churn 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.
Round 3Churn 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).
About deep-reviewCRF = Coder Review Finding (P0-P4, Nit, Note)
|
There was a problem hiding this comment.
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 callsscrollIntoView({ 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, andpersistBuildAgentBinding(coderd/x/chatd/chatd.go:492) publishes no watch event, so every frontend reader ofchat.agent_iddepends on the response-only repair inGET /chats/{id}.coderd/x/chatd/chattool/createworkspace.go:621: thewaitForAgentReadyresult carries noagent_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 afteruseWorkspaceWatchrefetches the chat andrepairChatAgentIDs(coderd/exp_chats.go:563) fillsagent_idin 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.
|
In reply to CRF-24 (P4, The PR title, which becomes the squash commit subject, now names start and create. In reply to CRF-27 (Note, Deferred to CODAGT-1181. It now describes the running call depending on the response-only In reply to CRF-35 (OOS, Deferred to CODAGT-1184, which covers both log boxes. In reply to CRF-36 (OOS, Deferred to CODAGT-1182, which covers both log boxes and includes the measurements. In reply to CRF-37 (OOS, Deferred to CODAGT-1183. In reply to CRF-38 (OOS, Deferred to CODAGT-1181. In reply to CRF-39 (OOS, Deferred to CODAGT-1181.
|
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.
775f380 to
83db989
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
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: whenFindChatAgentfails,create_workspaceon an existing workspace waits onagents[0]whileenrichChatAgentIDsleavesagent_idunrepaired, so the agent box shows "Waiting for workspace agent…" for the whole wait.site/src/components/Logs/LogLine.tsx:5:DEFAULT_LOG_LINE_SIDE_PADDINGis declared separately here and inLogs.tsx, so changing one misaligns theLogsHeaderpadding from the log line padding.site/src/pages/AgentsPage/components/ChatElements/tools/WorkspaceLifecycleTool.tsx:39: a start call that returnsagent_status: "not_ready"or failed startup scripts is labeled "Started", and no chat renderer readsagent_status, so the user sees success when the agent never became usable.site/src/modules/workspaces/WorkspaceBuildLogs/WorkspaceBuildLogs.tsx:44: thestickyprop is destructured and never used, soWorkspaceBuildLogSectionpassesstickyand gets no sticky stage headers.
🤖 This review was automatically generated with Coder Agents.
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.
|
In reply to AMREM-4 (P4, The reply on the re-render thread now says the cost is deferred to CODAGT-1182. Out-of-scope notes:
|
|
/coder-agents-review |
There was a problem hiding this comment.
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: 2000is 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)) { |
There was a problem hiding this comment.
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.
🤖
Closes CODAGT-166
start_workspaceandcreate_workspacewait for the workspace agent after the build finishes (waitForAgentReady). During that wait the row showed only the finished build log.WorkspaceAgentLogSectionadds an agent startup log box under the build log box in both tools. It uses the sameScrollAreasettings,LogsHeaderandLogslist 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
chat.agent_id, read throughuseChatWorkspace(). That hook replaces the per-field hooksuseChatWorkspaceIdanduseChatBuildId. Selecting the agent on the frontend was rejected because the backend marks the-coderd-chatnaming rule as unstable.buildIdwhile running, the resultbuild_idonce completed) equalslatest_build.id,latest_build.statusisrunning, 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.useAgentLogsin 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.scrollIntoViewwould otherwise pull the chat transcript to the row for each one.WorkspaceBuildLogsintoLogsHeader.Logstakes an optionalLineOutput; the agent box passesAgentLogOutput, moved out ofAgentLogLine, which renders ANSI colors and only the text after the last carriage return. WithoutLineOutput,Logsrenders the same<span>as on main. Status lines in both sections render throughLogNotice.Logsis outside the React Compiler directories; the compiled parent reuses theLogselement whilelinesis unchanged.agent_id. A running call follows the chat binding. Both are backend gaps, tracked in CODAGT-1181.agent_statusorstartup_scripts. Tracked in CODAGT-1190.