Repository navigation
feat(site/src): open open_preview results in the right panel - #32441
DanielleMaywood wants to merge 1 commit into
Conversation
5272318 to
f206137
Compare
f206137 to
de09426
Compare
|
/coder-agents-review |
|
Chat: Review posted | View chat Review history
deep-review v0.13.1 | Round 12 | Last posted: Round 12, 40 findings (12 P3, 17 P4, 11 Nit), COMMENT. Review Finding inventoryFinding inventory, PR #32441Findings
Contested and acknowledgedCRF-5 (P4, rightPanelTabs.ts:169) - getMatchingAgentOrFirst fallback never applies for preview tabs
CRF-16 (Nit, OpenPreviewTool.tsx:16) - Bare 80/2048 literals copy Go constants
CRF-15 (P4, PreviewPanel.tsx:13) - PreviewPanel vs PortPreviewPanel naming hides that both show ports
CRF-18 (Nit, rightPanelTabs.ts:74) - Tab field
|
| 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.
There was a problem hiding this comment.
This PR adds the Agents UI for open_preview results: a tool row with an Open preview button, and a right-panel tab that signs in and frames the preview in a CSP wrapper. 8 P3, 7 P4, 5 Nit.
The PR description says "see the routing PR", and no PR in the stack list is the routing PR. Name its number.
Out of scope (needs a ticket or explicit acceptance by a human):
coderd/x/chatd/chattool/openpreview.go:166: the tool returns success for a workspace the chat owner does not own. Sign-in rejects that workspace, so the model tells the user a preview is ready that cannot open.coderd/workspaceapps/preview.go:108,coderd/workspaceapps.go:146: each sign-in creates anapplication_connectAPI key with session lifetime that is never revoked, and an expired sign-in token is rejected even when the request has a valid preview session cookie. Every frame reload adds a key.agent/agentpreview/preview.go:69: file preview IDs exist only in agent memory, so preview links and tabs return 404 after an agent restart untilopen_previewruns again.coderd/previews.go:69: sign-in issues a token for a file preview slug without checking that the agent has published that ID, so the failure appears inside the frame instead of as a sign-in error.coderd/x/chatd/chattool/openpreview.go:138:checkURLPathlimits the path in bytes but its error says "characters", so a model with a long non-ASCII path cannot tell why it failed.
🤖 This review was automatically generated with Coder Agents.
| export const parseOpenPreviewResult = ( | ||
| result: unknown, | ||
| ): NewPreviewTab | undefined => { | ||
| const rec = asRecord(result); |
There was a problem hiding this comment.
P3 [CRF-1] parseOpenPreviewResult never reads kind, so the PR description's "parsed strictly by kind" does not hold. (Netero)
A result with no kind, or with kind: "port" and a file slug such as preview--0123abcd, gets an Open preview button. Check that kind is "port" or "file" and matches the slug form, or remove the claim from the description.
🤖
There was a problem hiding this comment.
Verified in 16f0f81d16: the description now says results are parsed by shape, which matches the parser.
🤖
| ); | ||
| }; | ||
|
|
||
| // Mirrors CheckURLPath in coderd/workspaceapps/previewhost/previewhost.go, |
There was a problem hiding this comment.
P3 [CRF-2] CheckURLPath in coderd/workspaceapps/previewhost/previewhost.go does not exist. The rule this code mirrors is checkURLPath in coderd/x/chatd/chattool/openpreview.go:129. (Netero)
A reader who follows this reference to keep the two checks in sync finds nothing to compare. Point the comment at checkURLPath.
🤖
There was a problem hiding this comment.
Verified fixed in 16f0f81d16: the comment and the client url_path check are gone.
🤖
| buildId: chat.build_id, | ||
| agentId: chat.agent_id, | ||
| agentName: workspaceAgent?.name, | ||
| openPreview: openPreviewEnabled ? openPreviewTab : undefined, |
There was a problem hiding this comment.
P3 [CRF-3] No test fails if the Open preview button shows with the open-preview experiment off. (Netero)
Changing this line to openPreview: openPreviewTab, left Tool.test.tsx, AgentChatPage.test.tsx and rightPanelTabs.test.ts passing (60 of 60), because every page test returns ["open-preview"] from /api/v2/experiments. Add a case to the open_preview results block that returns [] and asserts that no Open preview button renders.
🤖
There was a problem hiding this comment.
P3 [CRF-44] "offers no preview while the experiment is off" waits for API.getWorkspace to be called, not for its response to render, so it checks the gate only when the workspace render finishes first. (Komugi)
The button can only appear after the workspace renders, because previewAccess is undefined while workspace is unset. With !openPreviewEnabled || removed, the test fails with the current mock but passes when getWorkspace resolves 150 ms after the call. Before looking for buttons, wait for something rendered from the loaded workspace, or resolve a deferred getWorkspace and wait until the query succeeds.
🤖
There was a problem hiding this comment.
Declined: removing the experiment check from previewAccess fails this test with the mocks the suite uses, so it guards the gate today; you are right that it waits for the workspace request rather than its render, but the workspace mock resolves immediately in every case.
There was a problem hiding this comment.
The defense holds: with the gate removed, 42 of 42 runs (including on a single core) found the button and failed. Closed.
🤖
|
|
||
| const isPreviewSlug = (value: unknown): value is string => | ||
| typeof value === "string" && | ||
| /^preview--([0-9a-f]{8}|[1-9][0-9]{0,4})$/.test(value); |
There was a problem hiding this comment.
P4 [CRF-4] The port branch [1-9][0-9]{0,4} accepts preview--65536 through preview--99999, which appurl.ParsePreviewSlug rejects with strconv.ParseUint(target, 10, 16). (Netero)
Such a result shows a button whose sign-in returns 400. Match the server's range, or remove this copy (see the comment on the duplicated server rules).
🤖
There was a problem hiding this comment.
Verified fixed in 16f0f81d16: the parser checks only the preview-- prefix.
🤖
| return ( | ||
| openPreviewEnabled && | ||
| tab.workspaceId === workspace.id && | ||
| getMatchingAgentOrFirst(workspace, tab.agentName) !== undefined |
There was a problem hiding this comment.
P4 [CRF-5] getMatchingAgentOrFirst falls back to the first agent only for an empty name, and isUserRightPanelTab already rejects preview tabs with an empty agentName, so here and in UserTabPanel.tsx:77 the call only finds an agent by name. (Netero)
A reader has to trace back to isUserRightPanelTab to confirm that a preview tab cannot fall back to an unrelated agent. Use getWorkspaceAgents(workspace).find((agent) => agent.name === tab.agentName) at both call sites.
🤖
There was a problem hiding this comment.
Declined: behavior is the same because preview tabs always carry an agent name; cheap to revisit.
There was a problem hiding this comment.
The defense holds: both ways a preview tab gets an agent name keep it non-empty. Closed.
🤖
| } | ||
| const runes = [...value].length; | ||
| return ( | ||
| runes >= 1 && runes <= 80 && !/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u.test(value) |
There was a problem hiding this comment.
Nit [CRF-16] 80 here and 2048 on line 26 are bare copies of maxPreviewTitleLength and maxURLPathLength in coderd/x/chatd/chattool/openpreview.go. (Gon)
Declare them as named constants, each with a comment that names the Go constant it mirrors.
🤖
There was a problem hiding this comment.
Declined: the 2048 copy is gone in 16f0f81 because sign-in now checks url_path, and the title limit 80 stays inline in its only check.
There was a problem hiding this comment.
The 2048 copy is gone. The 80 remains: if maxPreviewTitleLength in coderd/x/chatd/chattool/openpreview.go is raised, results with longer titles render as a bare title with no button and no reason, and nothing on this line points to the Go constant. Adding "The limit of 80 mirrors maxPreviewTitleLength in coderd/x/chatd/chattool/openpreview.go." to the comment above isPreviewTitle is enough. (Gon)
🤖
There was a problem hiding this comment.
Declined: the title check is deliberately a client copy, since the user decides by title, and the limit only changes together with the tool, so a drift would need a Go change first.
There was a problem hiding this comment.
Still open as a Nit. The reply explains why the client keeps a copy, but not how someone who raises maxPreviewTitleLength in coderd/x/chatd/chattool/openpreview.go finds it: neither side names the other, and results with longer titles would then lose the button with no reason. One clause on the existing comment above isPreviewTitle fixes it: "The limit of 80 mirrors maxPreviewTitleLength in coderd/x/chatd/chattool/openpreview.go." (Gon)
🤖
There was a problem hiding this comment.
Declined: the title check is deliberately a client copy because the user decides by title, and the limit only changes together with the tool, so we are not adding the cross-reference here.
There was a problem hiding this comment.
Accepted. Neither side names the other, so whether that is acceptable is now the author's call. Closed. (Gon)
🤖
| }; | ||
|
|
||
| /** | ||
| * Signs the caller in to a preview. The returned URL carries a short-lived |
There was a problem hiding this comment.
Nit [CRF-17] Several new doc comments open with a sentence that restates the symbol name or the JSX, and AGENTS.md requires comments to be "substantive and concise". (Gon)
Here, keep only "The returned URL carries a short-lived sign-in token." The same applies to previews.ts:5 ("Signs in to a preview for one frame"), PreviewFrame.tsx:24 ("under a header with the preview's host and a reload button"), UserTabPanel.tsx:21 (the list of kinds repeats the exhaustive switch), rightPanelTabs.ts:78, and chatEntities.ts:240.
🤖
There was a problem hiding this comment.
Three of the six locations are unchanged: UserTabPanel.tsx:21 (the list of kinds), rightPanelTabs.ts:78 ("A preview tab before it has an ID."), and chatEntities.ts:240. (Gon)
🤖
There was a problem hiding this comment.
Declined: these are one-line docs on exported symbols, which the repository requires, and each one is accurate.
There was a problem hiding this comment.
The defense holds: AGENTS.md requires docs on exported symbols, and all three are exported. Closed.
🤖
| label: string; | ||
| workspaceId: string; | ||
| agentName: string; | ||
| slug: string; |
There was a problem hiding this comment.
Nit [CRF-18] The tab field slug renames the API's preview_slug, and in a module that also stores workspace app tabs, a bare slug reads as an app slug. (Gon)
Name it previewSlug.
🤖
There was a problem hiding this comment.
Declined: naming preference.
There was a problem hiding this comment.
Declined: slug sits on the preview tab variant only, next to kind: "preview", so TypeScript narrows it before any read and it cannot be confused with an app tab's fields; renaming it touches every preview tab test for no behavior change.
There was a problem hiding this comment.
The defense holds: every read narrows to kind: "preview" first, and workspace app tabs store appId, not slug. Closed.
🤖
| const signInQuery = useQuery( | ||
| previewSignIn({ ...preview, region_id: proxy.proxy?.id }, frameId), | ||
| ); | ||
| const signIn = signInQuery.data; |
There was a problem hiding this comment.
Nit [CRF-19] signIn holds a PreviewSignInResponse, but it reads as a function at signIn && ... and wrapperHTML(signIn, title). (Gon)
Name it signInResponse.
🤖
There was a problem hiding this comment.
Verified fixed in 16f0f81d16.
🤖
| return { user: userEvent.setup(), signIn }; | ||
| }; | ||
|
|
||
| it("opens a result's tab from its row once", async () => { |
There was a problem hiding this comment.
Nit [CRF-20] The test name "opens a result's tab from its row once" does not say that the test clicks twice. (Leorio)
For example: "clicking Open preview twice opens one tab and focuses it".
🤖
There was a problem hiding this comment.
Declined: naming preference.
There was a problem hiding this comment.
Declined: the test name says the result opens its tab once, which is the asserted behavior, and the body's two clicks are the setup; the suggested name describes the same assertion in more words.
There was a problem hiding this comment.
The defense holds: the name states the asserted behavior. Closed.
🤖
de09426 to
0fce80c
Compare
0fce80c to
9f8de93
Compare
9f8de93 to
185a913
Compare
185a913 to
c3d1145
Compare
b0e29c9 to
0d418bd
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
This head is a rebase of b1c1ead with the same PR diff. No new findings. The earlier approval still applies, so this review is a comment rather than another approval.
Neither base change alters what this UI sends or receives. RegionID moving from omitempty to omitzero affects only Go encoding: PreviewFrame omits region_id when no proxy is selected, coderd decodes that to uuid.Nil, and the generated type is still region_id?: string. previewHostingFor reading the proxy with AsSystemRestricted again returns the same row a dashboard session could already read, and an unknown proxy ID still gets the 400 that PreviewFrame shows with Reload.
The out-of-scope server items from earlier reviews (sign-in types reused by the address endpoint, the signed-out page's action and window.top target, key lifetime) are not part of this PR and still need tickets or explicit acceptance.
🤖 This review was automatically generated with Coder Agents.
ddafde3 to
fa5d6ce
Compare
|
/coder-agents-review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
This round reviews the tool call ID change: opening the same result again only focuses its tab, a different result renames and reloads it, and open_preview stays out of collapsed steps. New findings: 2 P4, 2 Nit.
CRF-6 still holds. Every path the panel traced shows the result the user clicked: a different tool call ID reloads, a tab saved before this change has no ID and reloads on its first click, and a result without an ID never takes the focus-only branch. The new tests fail when the toolCallId match, the stored ID, the Tool and MessageBlocks props, or the UNCOLLAPSIBLE_TOOLS entry is removed.
Out of scope: messageParsing.ts matches results to calls by tool call ID across the whole chat, and fantasy's OpenAI provider fills a missing ID with tool-call-<index> (providers/openai/language_model.go:423), which can repeat across steps. With such IDs an earlier row already renders a later result, and this PR's focus-only check would treat the two results as one. The out-of-scope server items from earlier reviews (sign-in types reused by the address endpoint, the signed-out page's action and window.top target, key lifetime) still need tickets or explicit acceptance.
🤖 This review was automatically generated with Coder Agents.
| // A newer result renames the tab and reloads its frame, so the tab | ||
| // shows what the agent just opened. | ||
| if ( | ||
| preview.toolCallId !== undefined && |
There was a problem hiding this comment.
P4 [CRF-69] No test covers clicking Open preview for a preview tab saved without toolCallId, which every tab persisted before this change is. (Netero)
The code handles it: undefined never equals the clicked ID, so the tab is renamed, reloaded and given the ID. But changing this condition to also focus tabs with no toolCallId leaves such a tab on its older label and frame, and AgentChatPage.test.tsx and rightPanelTabs.test.ts still pass (56 of 56). Add a case to the open_preview results block that seeds savePersistedRightPanelTabs with a preview tab with no toolCallId and an older label, clicks the matching result, and asserts the label and toolCallId change and the frame is replaced.
🤖
| SingletonRightPanelTabId[] | ||
| >(() => getPersistedVisibleSingletonTabs(agentId)); | ||
| const [pendingTabId, setPendingTabId] = useState<string | null>(null); | ||
| // Counts how often each preview tab was opened again, so its frame |
There was a problem hiding this comment.
P4 [CRF-70] This comment says the count tracks how often a tab "was opened again", but opening the same result again now returns at line 592 without changing it. (Razor)
A reader who trusts the comment expects every Open preview click to remount the frame. Say that the count changes when the tab is opened from a different open_preview result.
🤖
| ); | ||
| if (existingTab) { | ||
| // The same result only focuses its tab, keeping the frame's state. | ||
| // A newer result renames the tab and reloads its frame, so the tab |
There was a problem hiding this comment.
Nit [CRF-71] "A newer result" is narrower than the code: any result with a different toolCallId renames and reloads the tab, including an older row clicked after a newer one. (Razor)
The PR description says "newer" too. Write "a different result" in both.
🤖
| expect(newerFrame).not.toBe(firstFrame); | ||
| expect(firstFrame).not.toBeInTheDocument(); | ||
|
|
||
| // Opening the same result again only focuses it, keeping the frame, |
There was a problem hiding this comment.
Nit [CRF-72] These focus-only assertions sit at the end of "renames an open preview's tab and reloads it for a newer result", so when the focus-only branch breaks, the failure reports under a title that says the opposite. (Bisky)
Deleting the toolCallId match at AgentChatPageView.tsx:589 fails this test under the rename-and-reload title. Move lines 858 to 870 into their own test, for example "only focuses a preview's tab when the same result is opened again, also after a remount", seeded with one previewExchange.
🤖
86b336e to
8a343fa
Compare
5b9af8f to
46b5b5b
Compare
ef292da to
f72869c
Compare
24b5433 to
5394bc1
Compare
Renders open_preview results in the Agents chat with an Open preview button. The preview tab loads the preview's address in a srcdoc wrapper frame whose CSP allows only that preview's origin. When the preview's signed-out page posts coder-preview-sign-in-needed, the tab signs in through the dashboard endpoint, at most once per mount, and loads the returned URL. With the experiment off, the button is hidden and saved preview tabs are dropped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5394bc1 to
839e2ee
Compare
A preview opens only when its owner clicks, because the user decides by the title the agent chose. It opens only in the chat's right panel, because the preview host lets only the dashboard frame it.
The tab asks coderd for the address instead of building a hostname, and signs in only when the preview host asks, so the server's rules decide where a preview loads and reopening it creates no API key. Opening the same result again only focuses its tab, so the preview keeps its state; a newer result reloads it to show what the agent just opened.
Implementation details
Renders
open_previewresults in the Agents chat. For the workspace owner, the result has an Open preview button. Anyone else sees why they can't open it: only the workspace owner can, or the preview belongs to a different workspace. Nothing opens until the owner clicks.The preview tab asks coderd for the preview's address and loads it inside a
srcdocwrapper frame whose CSP allows only that preview's origin, with the sandbox the server returns. The UI never builds a preview hostname. If the preview host has no session, it tells the dashboard, which signs in once and reloads the frame, so reopening or reloading a preview does not create a new API key. Opening a newer result for the same preview renames its tab and reloads it; opening the same result again only focuses its tab, also after a page reload, so the preview keeps its state. The Open preview button stays visible when assistant steps are collapsed. Previews open only in the chat's right panel; opening a preview address directly shows an error page (#32439).Results are parsed by shape, the title rule is checked again because the user decides by title, and the server enforces the slug and
url_pathrules. With the experiment disabled, the button is hidden and saved preview tabs are hidden until it is enabled again.A manual pass in Safari 27.2 on macOS against an HTTPS deployment passed on an earlier version of this PR, before sign-in moved to on demand: file and port previews signed in and loaded inside the wrapper, every preview response carried the CSP, and the test page's fetch to the dashboard, top navigation and popup were all blocked. The on-demand sign-in was checked in Chromium and Firefox.
Stack (review bottom-up). Replaces the closed #31282 stack. Security review: coder/security-assessments#437.
🤖 Generated with Claude Code