Skip to content

feat(coderd): add the open_preview chat tool - #32440

Draft
DanielleMaywood wants to merge 1 commit into
open-preview/sign-infrom
open-preview/tool
Draft

DanielleMaywood wants to merge 1 commit into
open-preview/sign-infrom
open-preview/tool

Conversation

@DanielleMaywood

@DanielleMaywood DanielleMaywood commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Adds the open_preview chat tool. Root chats outside plan mode get it whenever the open-preview experiment is enabled. When previews are unavailable, because the primary deployment has no wildcard app hostname or --host-prefix-cookie is off, the tool says so, so the agent can tell the user why. It takes a title and exactly one target:

  • port: a server already running in the workspace, 9 to 65535, served on a preview--<port> host.
  • path: an .html file or a directory with index.html, published by the workspace agent and served on a preview--<id> host.

An optional url_path opens the target at a path and query. A single-file preview accepts only a query. Titles reject control, format, and line and paragraph separator characters. The result stores the preview slug, which says whether it is a port or a path. url_path must pass previewhost.CheckURLPath, the check sign-in uses. Port previews require the agent to show the port forwarding display app. The tool refuses a workspace the chat owner does not own, since only the workspace owner can sign in to its previews. It also refuses a preview hostname label over 63 characters. Both checks run before the tool calls the agent, and sign-in checks the label again with the region's wildcard prefix and suffix. Creating a chat with a dynamic tool named open_preview returns 400, and turns still drop that name from any chat that already stores it, so no other tool can pose as it.

The tool needs the workspace's connection, agent and workspace ID to agree, because it builds hostnames from the agent and workspace names. So coderd/x/chatd/turn_environment.go now caches the agent with the connection and returns all three from one lock section (getWorkspaceBinding), and getWorkspaceConn goes through it. coderd/x/chatd/ARCHITECTURE.md documents the binding change and adds a Workspace previews section.

The dashboard shows open_preview results as preview cards only with #32441, so this PR and #32441 merge together. On its own, a result shows as plain tool output.

Opening existing coder_apps from the tool is left to a follow-up (security review finding F2).

Stack (review bottom-up). Replaces the closed #31282 stack. Security review: coder/security-assessments#437.

  1. feat: serve published HTML previews from the workspace agent #32438 Agent file previews
  2. feat: serve agent previews on strict preview hosts #32439 Strict preview hosting and experiment
  3. feat: sign previews in from the dashboard with a host-bound token #32522 Preview sign-in
  4. feat(coderd): add the open_preview chat tool #32440 open_preview chat tool, this PR
  5. feat(site/src): open open_preview results in the right panel #32441 Agents UI
  6. docs: document open_preview previews #32442 Docs

🤖 Generated with Claude Code

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review

coder-agents-review Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-11-26 13:57 UTC by @DanielleMaywood
Spend: $87.37 / $100.00

Review history
  • R1 (2026-11-25): 13 reviewers, 3 Nit, 10 P3, 14 P4, COMMENT. Review
  • R2 (2026-11-25), 3 Nit, 10 P3, 14 P4, COMMENT. Review
  • R3 (2026-11-25), 3 Nit, 10 P3, 14 P4, COMMENT. Review
  • R4 (2026-11-25): 14 reviewers, 5 Nit, 12 P3, 21 P4, COMMENT. Review
  • R5 (2026-11-26): 12 reviewers, 6 Nit, 1 P1, 11 P3, 23 P4, REQUEST_CHANGES. Review
  • R6 (2026-11-26): 8 reviewers, 7 Nit, 1 P1, 11 P3, 25 P4, COMMENT. Review
  • R7 (2026-11-26): 4 reviewers, 7 Nit, 1 P1, 11 P3, 25 P4, APPROVE. Review
  • R8 (2026-11-26): 4 reviewers, 9 Nit, 1 P1, 11 P3, 29 P4, COMMENT. Review
  • R9 (2026-11-26): 4 reviewers, 9 Nit, 1 P1, 11 P3, 31 P4, COMMENT. Review

deep-review v0.13.1 | Round 9 | 4f68cc0..0be9a55

Last posted: Round 9, 52 findings (1 P1, 11 P3, 31 P4, 9 Nit), COMMENT. Review

Finding inventory

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P3 Author contested; panel closed R5 (4/4 accept) turn_environment.go:2661 open_preview reservation only in appendDynamicTools; other dynamic_tools readers still classify the name as dynamic R1 Netero Yes
CRF-2 P3 Author contested; panel closed R4 (1/1 accept) turn_environment.go:1968 Cached-conn-during-dial and workspace-mismatch branches of getWorkspaceBinding untested R1 Netero Yes
CRF-3 P4 Author fixed (18fa1d5) openpreview.go:167 GetPreviewWorkspace error path untested R1 Netero Yes
CRF-4 Nit Author contested; panel closed R4 (1/1 accept) ARCHITECTURE.md:1199 ARCHITECTURE.md gets only HTML TODO comments for open_preview R1 Netero Yes
CRF-5 P3 Author fixed (18fa1d5) coderd.go:965 PreviewsAvailable reflects only the primary; proxy-only wildcard deployments always refused with a false message R1 Kurapika, Pariston, Mafuuu, Kite, Ryosuke, Leorio, Gon Yes
CRF-6 P3 Author fixed (18fa1d5) turn_environment.go:1981 Tool succeeds on shared workspaces that sign-in always refuses (owner check) and publishes on another user's agent R1 Kurapika, Hisoka, Mafuuu Yes
CRF-7 P3 Author fixed (18fa1d5) openpreview.go:199 Tool succeeds for hostname labels over 63 chars that sign-in refuses R1 Hisoka, Ryosuke, Leorio, Mafuuu Yes
CRF-8 P3 Author fixed (18fa1d5) openpreview.go:130 checkURLPath accepts invalid escapes and reserved sign-in query params that break sign-in R1 Kurapika P3, Hisoka P4 Yes
CRF-9 P4 Author accepted R3 (only the agent knows file vs directory; extra publication serves the chosen file until restart) openpreview.go:186 Single-file preview published on the agent before url_path is rejected R1 Melody, Mafuuu, Bisky (Note) Yes
CRF-10 P3 Author fixed (18fa1d5) chatd_internal_test.go:1447 Cleared-during-dial test passes with the new agent caching lines deleted R1 Bisky Yes
CRF-11 P4 Author fixed (18fa1d5) openpreview_test.go:121 Title guard Cc/Zl/Zp categories untested R1 Bisky Yes
CRF-12 P4 Author fixed (18fa1d5) openpreview_test.go:136 Upper port bound 65535 untested R1 Bisky Yes
CRF-13 P4 Author fixed (18fa1d5) turn_environment.go:2581 Tool registered without previews available, contradicting the PR description R1 Bisky (Note), Mafuuu Yes
CRF-14 P4 Author accepted R3 (stale conn from main ensureWorkspaceAgent; rare 404 accepted for the experiment) turn_environment.go:1810 Cache-hit binding can pair previous workspace conn with new agent during selectWorkspace window R1 Hisoka Yes
CRF-15 P4 Author contested; panel closed R4 (1/1 accept) turn_environment.go:2661 Workspace MCP tools named open_preview are not reserved against R1 Kite Yes
CRF-16 P3 Author fixed (18fa1d5) openpreview.go:33 Persisted kind "file" also covers directory previews R1 Gon Yes
CRF-17 P3 Author contested; panel closed R4 (3/3 accept) turn_environment.go:1788 workspaceBinding duplicates chattool.PreviewWorkspace with a copy function R1 Gon P3, Luffy P4, Ryosuke P4 Yes
CRF-18 P3 Author contested; panel closed R4 (1/1 accept) openpreview.go:148 Tool description says it opens the panel, then says the user opens it R1 Gon Yes
CRF-19 P4 Author contested; panel closed R4 (1/1 accept) openpreview.go:143 OpenPreview doc omits that path targets are published on the agent R1 Gon P3 Yes
CRF-20 P4 Author fixed (631c66e) openpreview.go:22 Reserved-name rationale written three times and overstates what the reservation protects R1 Gon P2 (x3: openpreview.go:22, turn_environment.go:2659, dynamictool_internal_test.go:120), Pariston Note Yes
CRF-21 Nit Dropped by orchestrator (Go doc form; second sentence is substantive) openpreview.go:36 OpenPreviewResult doc first sentence restates name R1 Gon P2 No
CRF-22 Nit Dropped by orchestrator (example shows the query form, which the prose does not) openpreview.go:47 URLPath doc example repeats path and query R1 Gon P2 No
CRF-23 Nit Dropped by orchestrator (comment is rewritten by the CRF-5 fix either way) openpreview.go:61 PreviewsAvailable option comment repeats what false means R1 Gon P2 No
CRF-24 Nit Author fixed (18fa1d5) openpreview.go:128 checkURLPath doc hardcodes 2048 instead of naming the constant R1 Gon P2 Yes
CRF-25 Nit Dropped by orchestrator (comment explains why that test input exists) openpreview_test.go:119 Test comment repeats production comment R1 Gon P2 No
CRF-26 Nit Author contested; panel closed R4 (1/1 accept) openpreview.go:111 65535 literal repeated; lower bound uses a named constant R1 Gon P4 Yes
CRF-27 P4 Author contested; panel closed R4 (1/1 accept) openpreview.go:26 Length constants have no source comment; Title tag hardcodes 80 R1 Gon Yes
CRF-28 P4 Author fixed (18fa1d5) openpreview.go:138 url_path error says characters but counts bytes and names no failed rule R1 Leorio, Gon Yes
CRF-29 P4 Author fixed (18fa1d5) openpreview.go:181 Port forwarding error gives the model no next step R1 Leorio Yes
CRF-30 P4 Author contested; panel closed R5 (2/2 accept) turn_environment.go:1799 PR description and commit omit the getWorkspaceBinding behavior change R1 Leorio, Kite (Note) Yes
CRF-31 P4 Author contested; panel closed R4 (1/1 accept) openpreview.go:184 Port slug formatted by hand in chattool instead of in appurl R1 Ryosuke Yes
CRF-32 Note Note (body) openpreview.go:185 Port preview succeeds without checking that anything listens R1 Luffy No
CRF-33 OOS Out of scope (body) turn_environment.go:1804 for attempt loop could use range 2 (unchanged line) R1 Ging-Go No
CRF-34 OOS Out of scope (body) mcpworkspace.go:56 NewWorkspaceMCPTools trusts agent-reported names without server__tool form R1 Kite No
CRF-35 OOS Out of scope (body) previews.go:107 "Invalid preview address." gives no next step R1 Leorio No
CRF-36 OOS Out of scope (body) exp_chats.go:1527 Built-in name collisions handled only in appendDynamicTools; other readers misclassify R1 Netero No
CRF-37 P3 Author fixed (631c66e) ARCHITECTURE.md:1199 open_preview TODO describes round-1 code (kind field, wildcard-only gate, drop rationale) R4 Netero Yes
CRF-38 P4 Author fixed (631c66e) exp_chats.go:1538 Reserved-name check compares untrimmed name; dynamicToolNamesFromChat trims R4 Netero Yes
CRF-39 P4 Author contested; panel closed R5 (1/1 accept) exp_chats.go:1529 Validation-loop comment says built-in collisions are checked at chatloop time R4 Netero Yes
CRF-40 P4 Dropped by orchestrator (merged into CRF-41, same fix) openpreview.go:167 Label check uses hand-written 00000000 preview ID R4 Netero No
CRF-41 P4 Author contested; panel closed R5 (3/3 accept) openpreview.go:179 Label check copies sign-in's rule without the wildcard prefix and suffix, with its own constant and placeholder ID R4 Ryosuke, Gon, Netero Yes
CRF-42 P4 Author fixed (9ec965f) openpreview.go:191 Port forwarding display-app check refuses port previews that sign-in and the preview host serve R4 Pariston, Mafuuu Yes
CRF-43 P4 Author fixed (631c66e) turn_environment.go:2590 No test covers passing PreviewsUnavailable and ChatOwnerID into the registered tool R4 Bisky Yes
CRF-44 P4 Author fixed (631c66e) openpreview_test.go:286 Tests decode into OpenPreviewResult, so persisted JSON keys are not pinned R4 Bisky Yes
CRF-45 P4 Author contested; panel closed R5 (1/1 accept) openpreview.go:223 No-wildcard message does not name --wildcard-access-url R4 Leorio Yes
CRF-46 P4 Author contested; panel closed R6 (1/1 accept) openpreview.go:180 Hostname-length message gives no label, length, or who must rename R4 Leorio Yes
CRF-47 Nit Author contested; panel closed R5 (1/1 accept) openpreview.go:56 PreviewWorkspace doc says only "the workspace agent" R4 Gon Yes
CRF-48 Nit Author contested; panel closed R5 (1/1 accept) openpreview.go:163 Two tool error messages capitalized with final period, unlike the package R4 Gon Yes
CRF-49 Nit Dropped by orchestrator (second sentence states the behavior the field enables; no consequence) chatd.go:1255 Config.PreviewsUnavailable doc second sentence redundant R4 Gon P2 No
CRF-50 Nit Dropped by orchestrator (one-line test field comment; no consequence) openpreview_test.go:50 workspaceErr comment restates field R4 Gon P2 No
CRF-51 Note Note (body) turn_environment.go:1939 A single cached binding replaced whole would make the CRF-14 mismatch impossible R4 Meruem No
CRF-52 OOS Out of scope (body) openpreview.go:162 Users a chat is shared with see preview cards that 404 at sign-in (UI PR) R4 Melody No
CRF-53 OOS Out of scope (body) chatd.go:2144 Three parsers of dynamic_tools disagree on trimming R4 Meruem, Melody No
CRF-54 P1 Author fixed (9ec965f) turn_environment_internal_test.go:931 RootPreview row fails about 1 in 10 runs: random seeded names sometimes fit in 63 chars, the mock rejects OpenPreview, and the parent-t controller can panic other rows R5 Bisky, Chopper Yes
CRF-55 P4 Dropped by orchestrator (merged into CRF-54, same fix) turn_environment_internal_test.go:931 RootPreview proves ChatOwnerID wiring only through check order R5 Chopper No
CRF-56 P4 Author fixed (9ec965f) openpreview.go:179 Length refusal runs before the port forwarding refusal, so a rename can be followed by a refusal anyway R5 Chopper Yes
CRF-57 Nit Author contested; panel closed R6 (1/1 accept) turn_environment_internal_test.go:906 Test field preview holds an expected response substring R5 Gon Yes
CRF-58 OOS Out of scope (body) exp_chats.go:1544 Duplicate-name check compares untrimmed names; dynamicToolNamesFromChat merges them R5 Netero No
CRF-59 Nit Author contested; panel closed R7 (1/1 accept) openpreview_test.go:191 PortForwardingDisabled row has no comment saying it pins the check order R6 Gon Yes
CRF-60 P4 Author contested; panel closed R7 (1/1 accept) turn_environment_internal_test.go:1065 RootPreview writes shared previewServer.agentConnFn from a parallel subtest R6 Bisky Yes
CRF-61 P4 Author contested; panel closed R7 (1/1 accept) openpreview.go:219 previewsUnavailableMessage maps every non-cookie reason to "no wildcard hostname" R6 Zoro Yes
CRF-62 P4 Author fixed (0be9a55) ARCHITECTURE.md:1241 "Turns drop such a dynamic tool" is false for a stored padded name; other readers still classify it as dynamic R8 Razor, Leorio Yes
CRF-63 P4 Author fixed (0be9a55); fix sentence too broad, see CRF-69 ARCHITECTURE.md:1237 "Refuses three kinds of call" omits the single-file url_path refusal that runs after publishing R8 Razor, Pen Botter Yes
CRF-64 P4 Author fixed (PR description, R9) ARCHITECTURE.md:1239 Doc and tool description describe preview cards that only #32441 adds R8 Pen Botter; Razor, Chopper (Note) Yes
CRF-65 P4 Dropped by orchestrator (merged into CRF-64, same cause) openpreview.go:148 Tool description tells the model the user clicks a card that does not exist at this head R8 Pen Botter No
CRF-66 P4 Author fixed (PR description, R9) PR description Description says ARCHITECTURE.md only gets TODO comments; it becomes the squash commit R8 Leorio Yes
CRF-67 Nit Author fixed (0be9a55) ARCHITECTURE.md:1237 "Port URLs still work on that agent" does not say which URLs R8 Leorio Yes
CRF-68 Nit Author contested; panel closed R9 (1/1 accept) ARCHITECTURE.md:1198 Workspace binding entry gives no reason the three values come from one lock section R8 Leorio (Note) Yes
CRF-69 P4 Open (R9) ARCHITECTURE.md:1237 "A single-file path with a url_path other than / is also refused" is false for a query-only url_path such as /?page=2 R9 Netero, Leorio, Razor, Pen Botter Yes
CRF-70 P4 Open (R9) ARCHITECTURE.md:1237 Inserted single-file sentence makes "that agent" and "there" refer to the file-publishing agent instead of the hidden port forwarding one R9 Pen Botter Yes

Contested and acknowledged

CRF-2 (P3, turn_environment.go:1968) - getWorkspaceBinding cached-conn and mismatch branches untested

  • Finding: Netero reported zero coverage for the branch that returns a conn another caller cached during the dial (1968) and the workspace-mismatch branch (1930), and asked for tests of both.
  • Author defense (R3, PRRC_kwDOGkVX1s8AAAABGD8n_w): Out of scope: both branches exist untested on main in getWorkspaceConn; the cached agent and workspace ID this PR returns are covered by the second call in TestTurnWorkspaceContextGetPreviewWorkspaceAgentClearedDuringDial.
  • Status: contested, pending dispute check-in by Netero.

CRF-4 (Nit, ARCHITECTURE.md:1199) - only HTML TODO comments

  • Finding: Netero asked for the TODO text to be written as prose in the chatd tool list.
  • Author defense (R3, PRRC_kwDOGkVX1s8AAAABGD8pRw): repository rules reserve prose changes in coderd/x/chatd/ARCHITECTURE.md for the human PR author, so agents leave only TODO comments.
  • Evidence: AGENTS.md:76 at 18fa1d5: "when a change affects the documented architecture, do not edit the architecture document yourself. Leave TODO items in the affected sections; the human PR author writes the actual updates."
  • Status: contested, pending dispute check-in by Netero.

CRF-9 (P4, openpreview.go:186) - single-file preview published before url_path rejection

  • Finding: the agent publishes a single file before the tool rejects a pathname in url_path, leaving an extra publication.
  • Author accepted (R3, PRRC_kwDOGkVX1s8AAAABGD8qbA): only the agent knows whether a path is a file until it publishes; the error sends the model to the directory; the extra publication serves only the chosen file until the agent restarts.

CRF-14 (P4, turn_environment.go:1810) - cache hit can pair previous conn with new agent

  • Finding: between setCurrentChat and clearCachedWorkspaceState, ensureWorkspaceAgent can set the new agent while the old conn stays cached, so a file preview is published on the old agent and the result points at the new one.
  • Author accepted (R3, PRRC_kwDOGkVX1s8AAAABGD8rdQ): the stale conn comes from main's ensureWorkspaceAgent and affects every tool; here it can only make a rare file preview 404 until opened again, accepted for the experiment.

CRF-15 (P4, turn_environment.go:2661) - workspace MCP tools named open_preview

  • Finding: Kite reported that a workspace MCP tool named open_preview joins turns without the built-in tool; proposed one reservation after all tool sources combine.
  • Author defense (R3, PRRC_kwDOGkVX1s8AAAABGD8skg): only a modified agent can report an unprefixed name, which already lets it claim any absent built-in on main; sign-in still checks owner, agent and slug of any rendered result.
  • Status: contested, pending dispute check-in by Kite.

CRF-17 (P3, turn_environment.go:1788) - workspaceBinding duplicates chattool.PreviewWorkspace

  • Finding: two identical three-field types plus a copy function must be kept in sync; proposed one shared type.
  • Author defense (R3, PRRC_kwDOGkVX1s8AAAABGD8tyA): merging the two small structs is a refactor with no behavior change; cheap to revisit.
  • Status: contested, pending dispute check-in by Gon, Luffy, Ryosuke.

CRF-18 (P3, openpreview.go:148) - tool description opens with "Open a preview"

  • Finding: the first sentence tells the model the tool opens the panel; the last says the user opens it.
  • Author defense (R3, PRRC_kwDOGkVX1s8AAAABGD8ung): wording nit; the last sentence tells the model the user opens the preview with a click.
  • Status: contested, pending dispute check-in by Gon.

CRF-26 (Nit, openpreview.go:111) - 65535 literal

  • Finding: use math.MaxUint16 instead of repeated 65535.
  • Author defense (R3, PRRC_kwDOGkVX1s8AAAABGD8wvw): 65535 is the well-known port maximum and reads more plainly in model-facing text.
  • Status: contested, pending dispute check-in by Gon.

CRF-27 (P4, openpreview.go:26) - length constants lack source comments

  • Finding: maxPreviewTitleLength and maxURLPathLength have no source comment; Title tag hardcodes 80.
  • Author defense (R3, PRRC_kwDOGkVX1s8AAAABGD8xtw): wording nit; the URL path limit now lives in previewhost.CheckURLPath, and the title limit is local to this tool.
  • Status: contested, pending dispute check-in by Gon.

CRF-31 (P4, openpreview.go:184) - port slug built by hand

  • Finding: the persisted port slug encoder should live in appurl next to ParsePreviewSlug.
  • Author defense (R3, PRRC_kwDOGkVX1s8AAAABGD8zEg): a constructor is a refactor with no behavior change, and sign-in parses every slug with ParsePreviewSlug.
  • Status: contested, pending dispute check-in by Ryosuke.

CRF-19 (P4, openpreview.go:143) - OpenPreview doc omits path publishing

  • Finding: the OpenPreview Go doc says the tool opens a preview in the right panel, but the result is clicked by the user and path targets are published on the agent until it restarts.
  • Author defense (R4, PRRC_kwDOGkVX1s8AAAABGEFELQ): the doc covers what a Go caller needs to construct the tool; the publish side effect is documented in the model-facing tool description ("last until the workspace agent restarts", openpreview.go:146) and in workspacesdk.OpenPreviewResponse (agentconn.go:1510).
  • Status: contested, pending dispute check-in by Gon.

Round 4 panel closures

  • CRF-2 (R4, 1/1): Netero, the agent that raised it, accepted: since 18fa1d5 every write of c.conn sets c.agent and c.cachedWorkspaceID in the lock section that line 1968 reads, so the pairing holds by construction; the only exception is CRF-14 (accepted).
  • CRF-4 (R4, 1/1): Netero, original agent, accepted: AGENTS.md:76 forbids agent prose in the architecture document. Stale TODO content filed separately as CRF-37.
  • CRF-15 (R4, 1/1): Kite, original agent, accepted: resolvePreview reloads the workspace, checks the experiment and the owner, so a forged result reaches nothing the owner cannot open; the modified-agent precondition already allows claiming any absent built-in on main.
  • CRF-17 (R4, 3/3): Gon, Luffy and Ryosuke, original agents, accepted: PreviewWorkspace now has six fields and getPreviewWorkspace loads the workspace row, so it is no longer a field copy.
  • CRF-18 (R4, 1/1): Gon, original agent, accepted: the description's last sentence corrects the first, and the user sees the card beside the message.
  • CRF-19 (R4, 1/1): Gon, original agent, accepted: the only caller is appendRootChatTools, and the side effect is documented in the tool description and workspacesdk.OpenPreviewResponse.
  • CRF-26 (R4, 1/1): Gon, original agent, accepted: 65535 is the standard TCP port maximum and the model-facing text spells it out anyway.
  • CRF-27 (R4, 1/1): Gon, original agent, accepted: the URL limit moved to previewhost; the title limit and its tag are in one file.
  • CRF-31 (R4, 1/1): Ryosuke, original agent, accepted: both encoders produce the same form today, and drift would fail loudly at sign-in rather than open a wrong target.

CRF-1 (P3, turn_environment.go:2661) - open_preview reservation incomplete for stored rows (R5)

  • Finding: Netero raised that the reservation is applied only in appendDynamicTools; after the 400 fix, Ryosuke, Melody and Meruem re-raised that chats storing the name before the 400 still reach five readers, and proposed dropping the name inside the shared parsing.
  • Author defense (R5, PRRC_kwDOGkVX1s8AAAABGH7IUQ): the shared parsers classify any built-in name the same way on main, so fixing them is the separate pre-existing collision issue; this PR blocks new chats with a 400 and keeps the turn-time drop only for chats stored before it.
  • Status: contested, pending dispute check-in by Netero, Ryosuke, Melody, Meruem.

CRF-30 (P4, turn_environment.go:1799) - commit message stale (R5)

  • Finding: Leorio raised that the commit message omits the getWorkspaceBinding change and, in R4, that it describes round 1 behavior.
  • Author defense (R5, PRRC_kwDOGkVX1s8AAAABGH7LdA): coder/coder squash-merges with the PR description as the commit message, and the description is correct, so the stale commit body never lands on main.
  • Status: contested, pending dispute check-in by Leorio, Kite.

CRF-39 (P4, exp_chats.go:1529) - validation-loop comment says collisions are checked at chatloop time (R5)

  • Finding: Netero raised that the comment says built-in collisions are checked at chatloop time while the loop now rejects one built-in name.
  • Author defense (R5, IC_kwDOGkVX1s8AAAABrGXgCQ): the comment misses the reserved check, but collisions with every other built-in name are still caught at chatloop time, and the reserved check documents itself on OpenPreviewToolName.
  • Status: contested, pending dispute check-in by Netero.

CRF-41 (P4, openpreview.go:179) - label check copies sign-in rule without prefix and suffix (R5)

  • Finding: Ryosuke, Gon and Netero raised that the tool copies the 63-char rule with its own constant and placeholder ID and omits the wildcard prefix and suffix, so prefixed patterns refuse labels the tool accepted.
  • Author defense (R5, PRRC_kwDOGkVX1s8AAAABGH7NSQ): the region, and with it the prefix and suffix, is chosen when the user opens the preview, so the tool checks only the region-independent label; concedes a *--apps pattern can refuse a label the tool accepted, and sign-in reports it.
  • Status: contested, pending dispute check-in by Ryosuke, Gon, Netero.

CRF-42 (P3, openpreview.go:191) - port forwarding display-app check enforced only in the tool (R5)

  • Finding: Pariston and Mafuuu raised that sign-in and the preview host no longer check DisplayAppPortForwardingHelper, so the tool blocks previews that would open and gives a false reason.
  • Author defense (R5, PRRC_kwDOGkVX1s8AAAABGH7J1A): deliberate; a template that hides the display app tells the agent not to surface ports, so the tool declines and suggests a path preview, while the server stays consistent with plain port URLs, which never enforced the flag.
  • Status: contested, pending dispute check-in by Pariston, Mafuuu.

CRF-45 (P4, openpreview.go:223) - no-wildcard message does not name the setting (R5)

  • Finding: Leorio raised that the message does not name --wildcard-access-url.
  • Author defense (R5, PRRC_kwDOGkVX1s8AAAABGH7O2w): the model relays it, and the docs page that quotes it links the setting; keeping it for the experiment.
  • Status: contested, pending dispute check-in by Leorio.

CRF-46 (P4, openpreview.go:180) - hostname-length message lacks label and length (R5)

  • Finding: Leorio raised that the message gives no label, length, or who must rename.
  • Author defense (R5, PRRC_kwDOGkVX1s8AAAABGH7Qkw): the model relays it to the user, who can rename; sign-in gives the exact label and length if it is still too long.
  • Status: contested, pending dispute check-in by Leorio.

CRF-47 (Nit, openpreview.go:56) - PreviewWorkspace doc (R5)

  • Finding: Gon raised that the doc says only "the workspace agent" though the struct now holds workspace and owner fields.
  • Author defense (R5, PRRC_kwDOGkVX1s8AAAABGH7SwQ): every field identifies or reaches the agent a preview opens on.
  • Status: contested, pending dispute check-in by Gon.

CRF-48 (Nit, openpreview.go:163) - capitalized error messages (R5)

  • Finding: Gon raised that two tool errors start uppercase and end with a period unlike the package.
  • Author defense (R5, PRRC_kwDOGkVX1s8AAAABGH7UzQ): the casing does not change what the model or user does.
  • Status: contested, pending dispute check-in by Gon.

Round 5 panel dispositions

  • CRF-1 (R5, 4/4): Netero, Ryosuke, Melody, Meruem (all original agents) accepted: only rows stored before this PR can reach the state; the trimmed 400 blocks new rows; the client that can answer is the chat owner's; sign-in re-checks owner, agent and slug. Parser disagreement is the out-of-scope CRF-36/CRF-53 class.
  • CRF-30 (R5, 2/2): Leorio and Kite (original agents) accepted: git log origin/main shows squash merges whose body is the PR description, which is correct.
  • CRF-39 (R5, 1/1): Netero accepted: the comment's claim about other built-in names is still true and the reserved constant documents itself.
  • CRF-41 (R5, 3/3): Ryosuke, Gon, Netero accepted: the region is chosen at click, so a primary-based check could wrongly refuse; 63 is the fixed DNS limit; the placeholder matches previewIDFormat.
  • CRF-42 (R5, re-raised): Pariston and Mafuuu (original agents) accepted the gate as a product rule but re-raised the error text at P4: it says the agent does not allow port forwarding, which is false; the flag hides port UI.
  • CRF-45 (R5, 1/1): Leorio accepted: one lookup on an experiment-gated tool; the docs link in docs: document open_preview previews #32442 is unverified.
  • CRF-46 (R5, re-raised): Leorio re-raised: the defense's fallback (sign-in's error names the label) never runs on this path, because the tool refuses before a result exists; the username is part of the label and is never mentioned.
  • CRF-47, CRF-48 (R5, 1/1 each): Gon accepted.

CRF-46 (P4, openpreview.go:180) - hostname-length message (R6)

  • Finding: Leorio re-raised in R5 that the refusal gives no label or length, that sign-in's fallback never runs on this path, and that the username is part of the label but never mentioned.
  • Author defense (R6, PRRC_kwDOGkVX1s8AAAABGJBHpA): concedes the earlier reply was wrong about sign-in; keeps the short message because the model relays it, and shortening the workspace or agent name fixes the label in every case except a username near the 32-character limit.
  • Status: contested, pending dispute check-in by Leorio.

CRF-57 (Nit, turn_environment_internal_test.go:906) - test field named preview (R6)

  • Finding: Gon raised that the field holds an expected response substring, not a preview, and its doc names neither use.
  • Author defense (R6, PRRC_kwDOGkVX1s8AAAABGJBFpQ): the field's comment already says it holds part of open_preview's answer to the path call, which is what the row checks.
  • Status: contested, pending dispute check-in by Gon.

Round 6 panel dispositions

  • CRF-46 (R6, 1/1): Leorio (original agent) accepted: NameValid caps the three names at 32 characters and the fixed part of a file label is 23, so with any username a short enough workspace or agent name brings the label under 63; the advice is imprecise but never wrong.
  • CRF-57 (R6, 1/1): Gon (original agent) accepted: the field doc states the use accurately, and the field is local to one test.

CRF-59 (Nit, openpreview_test.go:191) - PortForwardingDisabled row lacks order comment (R7)

  • Finding: Gon raised that the row pairs port 65000 with longWorkspaceName to pin the check order but says nothing, so a simplification could remove the only order test.
  • Author defense (R7, PRRC_kwDOGkVX1s8AAAABGKA4YQ): reverting the check order fails the row, and a change that drops longWorkspaceName is visible in review.
  • Status: contested, pending dispute check-in by Gon.

CRF-60 (P4, turn_environment_internal_test.go:1065) - shared previewServer written from parallel subtest (R7)

  • Finding: Bisky raised that RootPreview writes previewServer.agentConnFn after t.Parallel(), so a second row on previewServer would race and mix mocks.
  • Author defense (R7, PRRC_kwDOGkVX1s8AAAABGKA2wA): concedes the race for a second row; 50/50 race-enabled runs pass; only one row needs the preview experiment.
  • Status: contested, pending dispute check-in by Bisky.

CRF-61 (P4, openpreview.go:219) - previewsUnavailableMessage default branch (R7)

  • Finding: Zoro raised that every non-cookie reason is reported as no wildcard hostname, correct only while coderd.go sets exactly two reasons.
  • Author defense (R7, PRRC_kwDOGkVX1s8AAAABGKA01A): concedes the assumption; coderd sets exactly two reasons today, each message is worded for its reader, and a third reason would need its own message.
  • Status: contested, pending dispute check-in by Zoro.

Round 7 panel dispositions

  • CRF-59 (R7, 1/1): Gon (original agent) accepted: reverting the order fails the row today, and dropping longWorkspaceName shows in review; worst case is the CRF-56 P4 behavior.
  • CRF-60 (R7, 1/1): Bisky (original agent) accepted: a future second row would race on the first run under test-go-race, so the failure is loud.
  • CRF-61 (R7, 1/1): Zoro (original agent) accepted: today only two reasons exist and every message is true; a new reason needs new per-reader advice that the err.Error() fallback would not give.

CRF-68 (Nit, ARCHITECTURE.md:1198) - workspace binding entry gives no reason (R9)

  • Finding: Leorio asked for a clause saying why the conn, agent and workspace ID must come from one lock section, so a later change does not split them.
  • Author defense (R9, PRRC_kwDOGkVX1s8AAAABGLM3Sg): the sentence states what is cached and returned together, which is what a later change must keep; a stated reason would also have to say what the lock section does not guarantee (a stale conn after an agent switch, accepted CRF-14).
  • Status: closed R9. Leorio (original agent) accepted: the sentence states the invariant a change must keep, the reason is in the PR description that becomes the squash commit body, and a stated reason would have to carry the CRF-14 exception.

Round log

Round 1

Netero first pass: 2 P3, 1 P4, 1 Nit. No P0, panel proceeds. Law not run (effective additions 619).
Full panel (round 1). Go only, security-sensitive input handling and trusted tool results, so multi-domain target 9-12. Specialists: ging-go, kurapika, takumi, ryosuke, melody, luffy. Core: pariston, mafuuu. Pool: bisky, gon, leorio, hisoka. Wildcard (shuf from distilled set): kite. 13 panel reviewers.
Cross-check: proxy availability converged across 7 reviewers. Owner, label length, url_path and region findings share one cause (tool does not run the checks postPreviewSignIn runs). Gon P2 comment findings downgraded to Nit/P4 (no behavior consequence); 4 dropped with reasons. Gon's three reserved-name comment copies merged with Pariston's accuracy note into CRF-20. Totals posted: 10 P3, 14 P4, 3 Nit; 1 Note and 4 out-of-scope in body. Reviewed against 24b45ed..e37889b.

Round 2

Churn guard BLOCKED. PR rebased onto 3cbebe3; compared with range-diff. 16 findings addressed in 18fa1d5 (CRF-1, 3, 5, 6, 7, 8, 10, 11, 12, 13, 16, 20, 24, 28, 29, 30); residuals: CRF-13 and CRF-30 commit message unchanged, CRF-20 copy at dynamictool_internal_test.go:120 still says the dashboard trusts results. 11 silent with no author reply: CRF-2, 4, 9, 14, 15, 17, 18, 19, 26, 27, 31. No reviewers spawned. CI Flake Check failed at head; log not readable (gh 401). Reviewed against 3cbebe3..18fa1d5.

Round 3

Churn guard BLOCKED. Head unchanged (18fa1d5). Author replied on all 11 open threads: 8 contested (CRF-2, 4, 15, 17, 18, 26, 27, 31), 2 accepted (CRF-9, 14), 1 silent (CRF-19, bare "Declined: wording nit."; second round without a substantive response, so a thread reply was posted). CRF-4 defense verified against AGENTS.md:76. No reviewers spawned. Reviewed against 3cbebe3..18fa1d5.

Round 4

Churn guard PROCEED: 9 contested (CRF-2, 4, 15, 17, 18, 19, 26, 27, 31), 0 silent. Head unchanged 18fa1d5. Restructure round (since R1 panel: exp_chats.go and exp_chats_test.go added to the diff; exported Config.PreviewsAvailable bool replaced by PreviewsUnavailable error; exported OpenPreviewKind removed). Full panel. Inventory validation: dropped CRF-21, 22, 25 re-checked; their comments are unchanged at 18fa1d5 and the drop reasons still hold. CRF-23's comment was rewritten by the CRF-5 fix. No reopen.
Panel (14): ging-go, kurapika, takumi, ryosuke, melody, luffy, pariston, mafuuu, bisky, gon, leorio, hisoka; kite (contested CRF-15, outside size target); wildcard meruem (shuf). Netero, Kite, Gon, Luffy, Ryosuke reused their R1 agents via message_agent. All 9 contested findings closed. Re-raised: CRF-1 (stored names reach five readers; Ryosuke, Melody, Meruem), CRF-20 (test comment copy; Netero), CRF-30 (commit message; Leorio). New on CRF-7 thread: CRF-41 (Ryosuke, Gon, Netero CRF-40 merged). Ryosuke's re-raise of CRF-5 dropped: round 1 offered the primary-only alternative and the author took it; Kite and Pariston verified the message is now true. Leorio's Note that sign-in still checks port forwarding was disproved by grep (no DisplayAppPortForwardingHelper reader in coderd/previews.go or coderd/workspaceapps); CRF-42 stands. Gon P2 comment findings dropped (CRF-49, 50). Totals posted: 2 P3, 7 P4, 2 Nit new; 3 re-raises. Reviewed against 3cbebe3..18fa1d5.

Round 5

Churn guard PROCEED: 5 addressed in 631c66e (CRF-20, 37, 38, 43, 44), 9 contested (CRF-1, 30, 39, 41, 42, 45, 46, 47, 48), 0 silent. Rebased onto 5421940. Fix round: since the R4 panel only 6 PR files changed (+57 -26, mostly tests), no file added, no exported signature change, effective additions 802 to 833. CI: 20 jobs failed including changes, lint-actions, test-js and Storybook; logs unreadable (gh 401). Locally at 631c66e: go build ./coderd/... ./codersdk/... passes, go vet on chatd and chattool passes, go test ./coderd/x/chatd/chattool -run OpenPreview passes.
Panel (12): ryosuke, melody, meruem, leorio, kite, pariston, mafuuu, gon (contested personas, previous agents via message_agent); kurapika, ging-go, bisky (specialists for changed files), wildcard chopper (shuf). Netero reused its agent, no new findings. CRF-54 P1 reproduced by orchestrator: 6/60 runs of TestBuildTurnEnvironmentToolPolicy fail with an unexpected MockAgentConn.OpenPreview call (Bisky 16/150). Likely related to the failing Flake Check, unverified. Event REQUEST_CHANGES. Reviewed against 5421940..631c66e.

Round 6

Churn guard PROCEED: 3 addressed in 9ec965f (CRF-42, 54, 56), 2 contested (CRF-46, 57). Rebased onto 99d01d9. Fix round: since the R5 panel only openpreview.go, openpreview_test.go and turn_environment_internal_test.go changed (+24 -18); no file added, no exported signature change. Orchestrator check at 9ec965f: 0/80 separate-process runs of TestBuildTurnEnvironmentToolPolicy failed (RootPreview runs; was 6/60 at 631c66e); go vet on chatd and chattool passes; chattool OpenPreview tests pass. CI: 18 jobs failed; logs unreadable (gh 401).
Panel (7): gon, leorio (contested personas, previous agents); bisky, chopper, pariston, mafuuu (fix verification for CRF-42, 54, 56); ging-go (Go files); wildcard zoro (shuf). Netero (new agent R6): no findings, CRF-42, 54, 56 verified. Both contested findings closed. New: CRF-59 Nit, CRF-60 P4, CRF-61 P4. No P0-P3 open. Reviewed against 99d01d9..9ec965f.

Round 7

Churn guard PROCEED: 3 contested (CRF-59, 60, 61), 0 silent. Head a1249bd is a pure rebase of 9ec965f onto 588ce57 (range-diff =); the base change since 99d01d9 touches only comments in coderd/previews.go. Fix round, no specialist triggers (no PR file changed).

Panel: gon, bisky, zoro (contested personas, previous agents) and wildcard kite (shuf); Netero (new agent): no findings, local build, vet and targeted tests pass at a1249bd. All 3 contested findings closed. No open findings remain; event APPROVE (downgraded to COMMENT by the CLI). Reviewed against 588ce57..a1249bd.

Round 8

Churn guard PROCEED: 0 open findings. Head 004cc93 rebased onto 9aae1d9 (base changes: comments in previews.go and previewhost.go, tests). The only patch change since R7: ARCHITECTURE.md TODO(DanielleMaywood) comments replaced by prose (workspace binding sentence, open_preview tool list entry, new "Workspace previews" section). Fix round over that file.
Panel: pen-botter (documentation specialist), leorio, razor, wildcard chopper (shuf); Netero (new agent): no findings. pen-botter's first turn started before its prompt file was written (prompt mtime 13:30:11, after the worktree at 13:29) and reported it missing; re-dispatched with message_agent and it completed. Razor reproduced the padded-name gap with a scratch test of appendDynamicTools. Padded legacy rows are a subset of the CRF-1 accepted residual; CRF-62 is filed against the doc's claim, with the code fix as an alternative. Totals posted: 4 P4, 2 Nit. Reviewed against 9aae1d9..004cc93.

Round 9

Churn guard PROCEED: 5 addressed (CRF-62, 63, 67 in 0be9a55; CRF-64, 66 in the PR description), 1 contested (CRF-68). Rebased onto 4f68cc0; the base change since 9aae1d9 reads workspace proxies with the caller's authorization in previewHostingFor (sign-in code this PR does not call) plus tests. The patch change is three sentences in ARCHITECTURE.md. Fix round. The churn guard reported its output before the file existed (read failed at once; file mtime 13:59:00); re-read succeeded.
Panel: leorio (contested persona, previous agent), razor and pen-botter (fix verification for CRF-62, 63, 67 and documentation specialist), wildcard knov (shuf); Netero (new agent). CRF-68 closed (Leorio accepted). CRF-62 and CRF-67 verified fixed by Netero, Leorio and Razor. Four reviewers independently found the CRF-63 fix sentence refuses every non-/ url_path while openpreview.go:206 and TestOpenPreview/FileWithQuery accept /?page=2 (orchestrator read the check and the doc line): CRF-69. Pen Botter: the inserted sentence moved the antecedent of "that agent" (CRF-70, orchestrator confirmed against line 1237). Pen Botter's Note on CRF-64 (correct only if #32440 and #32441 merge together, as the PR description now says) and Knov's Note (resolvePreview is the security boundary; 100% statement coverage of the tool) go in the body. Out of scope: "resolveProjectMemory check it" grammar at ARCHITECTURE.md:1230 is a base context line (blame 9f41c06). Totals posted: 2 P4. Reviewed against 4f68cc0..0be9a55.

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 the open_preview chat tool and makes getWorkspaceConn return the cached agent and workspace ID with the conn. Findings: 10 P3, 14 P4, 3 Nit.

Four of the P3 findings have one cause: the tool returns success without running the checks postPreviewSignIn runs at click time (workspace owner, region hosting, hostname label length, URL path parsing). The model then tells the user the preview is ready, and the click fails. One check function over workspace, agent, slug, region and URL path, called by both the tool and postPreviewSignIn, would fix all four and keep the rules in one place.

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

  • coderd/exp_chats.go:1527: the comment says built-in name collisions are checked at chatloop time, but only appendDynamicTools drops colliding names; dynamicToolNamesFromChat and parseDynamicToolNames still classify a call to any colliding built-in (for example execute) as dynamic, so interruption and SubmitToolResults treat it differently from the turn that ran it.
  • coderd/x/chatd/chattool/mcpworkspace.go:56: NewWorkspaceMCPTools accepts agent-reported names without the server__tool form, so a modified agent can claim any built-in name in turns where that built-in is absent.
  • coderd/previews.go:107: "Invalid preview address." with a DNS label detail does not tell the user that a shorter workspace, agent or user name would fix it.
  • coderd/x/chatd/turn_environment.go:1804: the unchanged for attempt := 0; attempt < 2; attempt++ loops (also lines 1474 and 1627) can be for attempt := range 2.

Notes:

  • coderd/x/chatd/chattool/openpreview.go:185: a port preview returns success without checking that anything listens on the port; AgentConn.ListeningPorts exists, but its results are platform dependent, so the current description (the tool does not start or wait for the server) is a reasonable choice.

🤖 This review was automatically generated with Coder Agents.

}
// The dashboard trusts open_preview results, so the name stays reserved
// in turns without the built-in tool too.
if dynamicToolNames[chattool.OpenPreviewToolName] {

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.

P3 [CRF-1] The open_preview reservation is applied only in appendDynamicTools, so the stored dynamic_tools column still declares the name and every other reader treats calls to it as client-run. (Netero)

parseDynamicToolNames (chatd.go:2144) and dynamicToolNamesFromChat (tasks.go:706) feed stream_loop.go:289, hook_server.go:136, tasks.go:830 and memory.go:116, and unansweredToolCalls (generation.go:385) puts any call whose name is in that map into the dynamic list. If a built-in open_preview call is interrupted in a chat that declared a dynamic open_preview, tasks.go:830 writes no interrupted result, and the call becomes one that SubmitToolResults accepts a client result for, which is the forged-result path the reservation is meant to block (inferred from the code, not reproduced). Reject the name with a 400 in the dynamic tool validation loop in coderd/exp_chats.go:1531, next to the empty and duplicate name checks, so the column never contains it.

🤖

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.

The 400 in createChat covers new chats only. For a chat that already stores a dynamic tool named open_preview, only appendDynamicTools drops the name. dynamicToolNamesFromChat (used by tasks.go:830, hook_server.go:136, memory.go:116, turn_trace.go:327), parseDynamicToolNames in stream_loop.go:289, and parseDynamicToolNamesFromRaw (chatstate/synthetics.go:86, used by CompleteRequiresAction) still return it. An interrupted built-in call in such a chat gets no cancellation result and becomes a call a client can answer. Drop the reserved name inside the shared parsing so every reader gets the same names, and delete the separate drop in appendDynamicTools.

🤖

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.

Declined: the shared parsers classify any built-in name the same way on main, so fixing them is the separate pre-existing collision issue; this PR blocks new chats from storing the name with a 400 and keeps the turn-time drop only for chats stored before it.

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.

Accepted: only chats stored before this PR can reach this state, the trimmed 400 blocks new ones, and the parser disagreement affects every built-in name on main.

🤖

return workspaceBinding{conn: agentConn, agent: agent, workspaceID: chatSnapshot.WorkspaceID.UUID}, nil
}
currentConn = c.conn
binding = workspaceBinding{conn: c.conn, agent: c.agent, workspaceID: c.cachedWorkspaceID.UUID}

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.

P3 [CRF-2] The branch where another caller cached a conn during this dial has no test, and neither does the workspace-mismatch branch at line 1930 whose locking this PR changed. (Netero)

A coverage run of go test ./coderd/x/chatd/ -run 'TurnWorkspaceContext|WorkspaceConn|Concurrent' reports count 0 for blocks 1930-1932, 1935-1936, 1968-1971 and 1974-1975. Line 1968 is where the binding is read from the cached state, which is what open_preview relies on for the agent name and display apps. Add a case where agentConnFn stores a conn on the context before returning and assert that the returned conn and agent are the cached pair, and a case where the chat's workspace changes during the dial.

🤖

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.

Out of scope: this also happens on main, where both branches exist in getWorkspaceConn without tests; the cached agent and workspace ID this PR returns are covered by the second call in TestTurnWorkspaceContextGetPreviewWorkspaceAgentClearedDuringDial.

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.

Accepted: every write of c.conn now sets the agent and workspace ID in the same lock section that line 1968 reads.

🤖

}

workspace, err := options.GetPreviewWorkspace(ctx)
if err != nil {

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-3] The GetPreviewWorkspace error path has no test. (Netero)

Coverage for TestOpenPreview reports block 167-169 at count 0, the only uncovered block in the file. Add a case whose GetPreviewWorkspace returns an error and assert that the error text reaches the model as a tool error.

🤖

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.

Verified fixed in 18fa1d5.

🤖

Comment thread coderd/x/chatd/ARCHITECTURE.md Outdated
- subagents (`spawn_agent`, `wait_agent`, `message_agent`, `interrupt_agent`, `list_agents`, `list_subagent_models`)
- file links
- workspace binding
<!-- TODO(DanielleMaywood): add `open_preview` to this tool list: root chats outside plan mode get it when the `open-preview` experiment is enabled, and it reports that previews are unavailable without a wildcard app hostname; it takes a title (no control, format, or line and paragraph separator characters), exactly one of port or path, and an optional url_path; the workspace agent publishes a path under an ID hashed from it, and the result stores a `kind`, the preview slug (`preview--<port>` for ports), and the path. Dynamic tools named `open_preview` are dropped in every chat, because the dashboard trusts its results. -->

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.

Nit [CRF-4] ARCHITECTURE.md gets two HTML TODO comments instead of an entry for open_preview and the binding change. (Netero)

Root AGENTS.md requires chatd changes that affect the architecture to update this document, and HTML comments do not render, so a reader sees no open_preview in the tool list. Write the TODO text into the list as prose.

🤖

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.

Not a bug: repository rules reserve prose changes in coderd/x/chatd/ARCHITECTURE.md for the human PR author, so agent-written changes may only leave TODO comments there.

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.

Accepted: AGENTS.md:76 keeps agents to TODO items. The TODO text itself is out of date; that is a separate thread on line 1199.

🤖

Comment thread coderd/coderd.go Outdated
AlwaysEnableDebugLogs: options.DeploymentValues.AI.Chat.DebugLoggingEnabled.Value(),
StreamSilenceTimeout: streamSilenceTimeout,
DisableCallerSuppliedTools: options.DeploymentValues.DisableChatCallerSuppliedTools.Value(),
PreviewsAvailable: api.previewHosting != nil,

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.

P3 [CRF-5] PreviewsAvailable is true only when the primary has a wildcard app hostname, but postPreviewSignIn also hosts previews through workspace proxies. (Kurapika, Pariston, Mafuuu, Kite, Ryosuke, Leorio, Gon)

previewHostingFor (coderd/previews.go:151-174) returns strict hosting for a proxy with a WildcardHostname without reading api.previewHosting. On a deployment where only a proxy has a wildcard hostname, every call returns "previews need a wildcard app hostname, which this deployment does not have", which is false, and when the primary has one but the user's region does not, the tool succeeds and the click fails with "This region does not serve previews." Replace the boolean with the same region check postPreviewSignIn runs, or keep the primary-only rule and say "primary" in the Config.PreviewsAvailable comment and the error text, naming CODER_WILDCARD_ACCESS_URL as the setting.

🤖

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.

Verified fixed in 18fa1d5: the option comment and the message now say the primary deployment.

🤖

Comment thread coderd/x/chatd/chattool/openpreview.go Outdated
// trusts its results, so no other tool source may use the name.
const OpenPreviewToolName = "open_preview"

const maxPreviewTitleLength = 80

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-27] maxPreviewTitleLength = 80 and maxURLPathLength = 2048 have no comment, and the Title description tag hardcodes "At most 80 characters". (Gon)

If the constant changes, the description the model reads is wrong, and a reader cannot tell whether either value comes from a UI, browser or proxy limit. Add a one-line comment to each constant with its source, and note the tag next to maxPreviewTitleLength.

🤖

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.

Declined: wording nit; the URL path limit now lives in previewhost.CheckURLPath, and the title limit is local to this tool.

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.

Accepted.

🤖

Comment thread coderd/x/chatd/chattool/openpreview.go Outdated
strings.HasPrefix(p, "//") ||
strings.ContainsAny(p, `\#`) ||
strings.ContainsFunc(p, unicode.IsControl) {
return xerrors.Errorf("url_path must start with a single /, contain only a path and query, have no backslashes, fragments or control characters, and be at most %d characters", maxURLPathLength)

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-28] The url_path error says "at most 2048 characters" but len(p) counts bytes, and it lists every rule without naming the one that failed. (Leorio, Gon)

A url_path of 1100 é runes is 2200 bytes and is rejected with a message the model can check and find false; the title check counts runes, so the two messages use "characters" for different units. Say "bytes", or return one message per failed condition.

🤖

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.

Verified fixed in 18fa1d5.

🤖

Comment thread coderd/x/chatd/chattool/openpreview.go Outdated
switch req.kind {
case OpenPreviewKindPort:
if !slices.Contains(workspace.Agent.DisplayApps, database.DisplayAppPortForwardingHelper) {
return fantasy.NewTextErrorResponse("the workspace agent does not allow port forwarding, so ports cannot be previewed"), nil

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-29] The port forwarding error names the cause but gives the model no next step. (Leorio)

The model cannot tell that a path preview still works or who can change the setting. Write, for example: "this workspace's template hides port forwarding (coder_agent display_apps.port_forwarding_helper), so ports cannot be previewed; preview an .html file or directory with path instead, or tell the user a template administrator can enable port forwarding".

🤖

return binding.conn, err
}

func (c *turnWorkspaceContext) getWorkspaceBinding(ctx context.Context) (workspaceBinding, error) {

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-30] The PR description and commit message do not mention that getWorkspaceConn now caches the agent with the conn, which changes behavior for every workspace tool. (Leorio, Kite)

A switched agent is no longer cached when another caller cached a conn during the dial, and the only explanation is an HTML TODO in ARCHITECTURE.md. Add a sentence to the description and commit body saying what changed and that open_preview needs the agent name and display apps to match the conn.

🤖

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.

The PR description now explains the change, but the commit message of 18fa1d5 still does not. It also says root chats get the tool "when the open-preview experiment is on and the server hosts previews" and that dynamic tools named open_preview are dropped. Line 2588 registers the tool whenever the experiment is on, and createChat now returns 400 for the name. Rewrite the commit body to match the head and add one sentence about getWorkspaceBinding.

🤖

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.

Declined: coder/coder squash-merges with the PR description as the commit message, and you note the description is already correct, so the stale commit body never lands on main and is not worth rewriting the stack history for.

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.

Accepted: the squash commit takes the PR description, which is correct.

🤖

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-66] The PR description, which becomes the squash commit body, still says "coderd/x/chatd/ARCHITECTURE.md only gets TODO comments", but 004cc93 replaces them with prose. (Leorio)

A reader of git log on main would conclude the architecture document was not updated. Replace it with, for example, "coderd/x/chatd/ARCHITECTURE.md documents the binding change and adds a Workspace previews section." In the same paragraph, "control, format and direction characters" omits the line and paragraph separators the code rejects (openpreview.go:109); use the document's wording.

🤖

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.

Fixed in the PR description: it now says ARCHITECTURE.md documents the binding change and adds a Workspace previews section, and that titles reject control, format, and line and paragraph separator characters.

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.

CRF-66 verified: the PR description now says the document gets the binding change and a Workspace previews section, and uses the document's character wording.

🤖

Comment thread coderd/x/chatd/chattool/openpreview.go Outdated
return fantasy.NewTextErrorResponse("the workspace agent does not allow port forwarding, so ports cannot be previewed"), nil
}
result.Port = req.port
result.PreviewSlug = appurl.PreviewSlugPrefix + strconv.Itoa(req.port)

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-31] The port slug is built by hand here, while appurl builds file slugs (PreviewID.Slug()) and parses both forms (ParsePreviewSlug). (Ryosuke)

The stored preview_slug is a persisted contract, so its encoder belongs next to its parser. Add a port slug constructor in appurl and call it here.

🤖

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.

Declined: a port slug constructor in appurl is a refactor with no behavior change, and sign-in parses every slug with ParsePreviewSlug.

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.

Accepted: both encoders produce the same form, and any drift would fail at sign-in rather than open the wrong target.

🤖

@DanielleMaywood
DanielleMaywood force-pushed the open-preview/tool branch 2 times, most recently from 290143c to 3e10f72 Compare November 25, 2026 15:28
@DanielleMaywood
DanielleMaywood force-pushed the open-preview/tool branch 2 times, most recently from f4e63e8 to 5fb9b6c Compare November 25, 2026 16:25
@DanielleMaywood

Copy link
Copy Markdown
Collaborator 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.

Re-review of 18fa1d5. The new commit addresses 16 of the 27 open findings, including the owner, hostname label, url_path and region checks, the reserved dynamic tool name, and the persisted kind field. Three of them still have a small part left: the commit message still says the tool is added only when the server hosts previews and does not mention the getWorkspaceBinding change, and the test comment at coderd/x/chatd/dynamictool_internal_test.go:120 still says the dashboard trusts the results.

The 11 findings below have neither a code change nor a reply. For each one, fix it in this PR, link a GitHub issue, or reply on its thread with why it should not change. The panel will run again after that, so this round adds no new findings.

  • coderd/x/chatd/turn_environment.go:1968: the cached-conn-during-dial and workspace-mismatch branches of getWorkspaceBinding have no test.
  • coderd/x/chatd/ARCHITECTURE.md:1199: the document gets only HTML TODO comments for open_preview and the binding change.
  • coderd/x/chatd/chattool/openpreview.go: a single-file preview is published on the agent before a pathname in url_path is rejected.
  • coderd/x/chatd/turn_environment.go:1810: during selectWorkspace, a cache hit can pair the previous workspace's conn with the new agent.
  • coderd/x/chatd/turn_environment.go: workspace MCP tools named open_preview are not blocked.
  • coderd/x/chatd/turn_environment.go:1788: workspaceBinding duplicates chattool.PreviewWorkspace and needs a copy function.
  • coderd/x/chatd/chattool/openpreview.go: the tool description says the tool opens the panel, then says the user opens it.
  • coderd/x/chatd/chattool/openpreview.go: the OpenPreview doc does not say that path targets are published on the agent.
  • coderd/x/chatd/chattool/openpreview.go: 65535 is still a repeated literal.
  • coderd/x/chatd/chattool/openpreview.go: maxPreviewTitleLength has no comment, and the Title tag still hardcodes 80.
  • coderd/x/chatd/chattool/openpreview.go: the port slug is still built by hand instead of in appurl.

The Flake Check job (139552355140) failed on this head. Check whether it failed in one of the tests this PR adds.

🤖 This review was automatically generated with Coder Agents.

@DanielleMaywood

Copy link
Copy Markdown
Collaborator 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.

Re-review of 18fa1d5, which is unchanged since the last review. Every open thread now has a reply. Two findings are recorded as accepted: the single-file publication made before a url_path pathname is rejected, and the stale conn during selectWorkspace. Eight are contested, and the reviewers who raised them will judge those replies in the next panel round. The reply on the ARCHITECTURE.md TODO comments matches AGENTS.md:76.

One finding still has no reply that addresses its consequence: the OpenPreview doc comment at coderd/x/chatd/chattool/openpreview.go:135 does not say that a path target is published on the agent and stays published until the agent restarts. "Declined: wording nit." gives the severity but no reason. Change the comment, or reply with why a reader of OpenPreview does not need to know about that side effect. The panel review, including verification of the 16 fixes in 18fa1d5, runs after that reply.

The Flake Check job (139552355140) still fails on this head.

🤖 This review was automatically generated with Coder Agents.

@DanielleMaywood

Copy link
Copy Markdown
Collaborator 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 review covers 18fa1d5, which adds the open_preview chat tool. Findings: 2 P3, 7 P4 and 2 Nit are new, and 3 earlier findings are raised again.

The reviewers checked 11 of the fixes from 18fa1d5 against the code and found them correct; those threads are resolved below. All 9 contested replies were accepted by the reviewers who raised those findings. Three fixes are incomplete. The reserved name is still classified as a dynamic tool for chats that already store it. One test comment still says the dashboard trusts the results. The commit message still describes round 1 behavior.

The new P3 about the port forwarding check comes from the rebase. Before the rebase, the tool's check matched a check in sign-in. Sign-in at the new base no longer reads DisplayAppPortForwardingHelper, so the tool is now the only place that enforces it.

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

  • coderd/x/chatd/chattool/openpreview.go:162: the tool checks the chat owner, but sign-in checks the user who clicks, so other users who can view a shared chat see preview cards that return 404 (the UI in #32441 has to handle this or hide the card).
  • coderd/x/chatd/chatd.go:2144: parseDynamicToolNames, dynamicToolNamesFromChat and parseDynamicToolNamesFromRaw parse the same column three ways, and only one trims names, so readers disagree for any name with surrounding whitespace.

Notes:

  • coderd/x/chatd/turn_environment.go:1939: the accepted stale conn during selectWorkspace exists because loadWorkspaceAgentLocked writes c.agent and c.cachedWorkspaceID without c.conn; one cached binding field replaced as a whole would make a mismatched conn and agent impossible to construct.

The Flake Check job (139552355140) still fails on this head.


coderd/exp_chats.go:1529

P4 [CRF-39] The comment above this loop says built-in name collisions are checked at chatloop time, but the loop now rejects one built-in name itself. (Netero)

Say that reserved names are rejected here, and that other collisions are resolved when the turn is built.

🤖

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/x/chatd/chattool/openpreview.go Outdated
}
switch req.kind {
case previewKindPort:
if !slices.Contains(workspace.Agent.DisplayApps, database.DisplayAppPortForwardingHelper) {

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.

P3 [CRF-42] The tool refuses port previews when the agent hides the port forwarding display app, but at the new base neither sign-in nor the preview host checks that flag, so the tool blocks previews that would open and gives a false reason. (Pariston, Mafuuu)

Outside the provisioner and database code, the only readers of DisplayAppPortForwardingHelper are this check and agentapi/subagent.go; resolvePreview in coderd/previews.go does not read it. coderd/workspaceapps/db_test.go:871 says the display app hides only the dashboard's ports UI. On a template with display_apps { port_forwarding_helper = false }, the model tells the user an administrator must enable port forwarding, a setting that does not control previews. Delete the check and its PortForwardingDisabled test, or, if the security review requires it, enforce it in resolvePreview and keep this check as the early error.

🤖

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.

Declined: keeping the check in the tool is deliberate, because a template that hides the port forwarding display app is telling the agent not to surface ports, so the tool declines and suggests a path preview, while the server stays consistent with plain port URLs, which never enforced the flag.

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.

The gate is accepted as a product rule. The error text is not: it says the agent "does not allow port forwarding" and that an administrator can "enable port forwarding", but port forwarding still works through port URLs and coder port-forward on such an agent, and the flag only hides the ports UI. Say what the check reads, for example: "this agent's template hides the port forwarding display app (display_apps.port_forwarding_helper), so open_preview does not open ports here; preview the built files with path instead, or tell the user a template administrator can show port forwarding for this agent", and update the wantError in the PortForwardingDisabled case.

🤖

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.

Fixed in 9ec965f: the message now says the template hides the port forwarding app, so open_preview does not open ports there, instead of claiming port forwarding is disallowed.

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.

Verified fixed in 9ec965f.

🤖

Comment thread coderd/x/chatd/ARCHITECTURE.md Outdated
- subagents (`spawn_agent`, `wait_agent`, `message_agent`, `interrupt_agent`, `list_agents`, `list_subagent_models`)
- file links
- workspace binding
<!-- TODO(DanielleMaywood): add `open_preview` to this tool list: root chats outside plan mode get it when the `open-preview` experiment is enabled, and it reports that previews are unavailable without a wildcard app hostname; it takes a title (no control, format, or line and paragraph separator characters), exactly one of port or path, and an optional url_path; the workspace agent publishes a path under an ID hashed from it, and the result stores a `kind`, the preview slug (`preview--<port>` for ports), and the path. Dynamic tools named `open_preview` are dropped in every chat, because the dashboard trusts its results. -->

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.

P3 [CRF-37] The open_preview TODO describes the round 1 code, and AGENTS.md:76 makes these TODOs the only notes the human author writes the architecture entry from. (Netero)

It says the result stores a kind, which 18fa1d5 removed. It says previews are unavailable only without a wildcard hostname, but previewsUnavailableMessage also refuses when --host-prefix-cookie is off. It says dynamic tools named open_preview are dropped because the dashboard trusts the results, but createChat now returns 400 and the rationale in openpreview.go:23-26 changed. It also leaves out the owner and label checks. The TODO on line 1200 says a caller never pairs a conn with a switched agent, which the accepted selectWorkspace window contradicts. Rewrite both TODOs to match the head.

🤖

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.

Fixed in 631c66e: both TODO lines in ARCHITECTURE.md now match the code; they stay TODOs for the author to write up.

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.

Verified fixed in 631c66e: both TODOs match the head.

🤖

Comment thread coderd/exp_chats.go Outdated
Message: "Dynamic tool name must not be empty.",
})
}
if dt.Name == chattool.OpenPreviewToolName {

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-38] The reserved-name check compares the untrimmed name, but dynamicToolNamesFromChat (coderd/x/chatd/tasks.go:716) trims it, so a chat created with " open_preview" passes this check. (Netero)

Interruption (tasks.go:830), SubmitToolResults (hook_server.go:136) and memory (memory.go:116) then treat a built-in open_preview call as client-run. The drop in appendDynamicTools uses parseDynamicToolNames, which does not trim, so it misses the name too. Compare strings.TrimSpace(dt.Name) here; dropping the name in the shared parsing, as raised on the reserved-name thread, also closes this.

🤖

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.

Fixed in 631c66e: createChat trims dynamic tool names before the reserved-name check, and the ReservedToolName cases include a padded name.

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.

Verified fixed in 631c66e.

🤖


if p.experiments.Enabled(codersdk.ExperimentOpenPreview) {
tools = append(tools, chattool.OpenPreview(chattool.OpenPreviewOptions{
PreviewsUnavailable: p.previewsUnavailable,

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-43] No test covers the two lines that pass PreviewsUnavailable and ChatOwnerID into the registered tool, and the owner and availability fixes depend on them. (Bisky)

With lines 2590 and 2591 deleted, go test ./coderd/x/chatd/ -run 'TestBuildTurnEnvironmentToolPolicy|TestAppendDynamicTools' passes. Without line 2591, every call fails with "belongs to another user". In the Root row, build the turn on a server with previewsUnavailable set, run open_preview from env.Tools with {"title":"App","port":3000}, and assert the unavailable message; that call returns before it dials the workspace.

🤖

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.

Fixed in 631c66e: TestBuildTurnEnvironmentToolPolicy has rows for PreviewsUnavailable and ChatOwnerID; removing either option fails its row.

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.

Verified in 631c66e: deleting either option fails its row. That check is only reliable once the flaky RootPreview row on line 931 is fixed.

🤖

// The preview slug says whether a result is a port or a path.
var fields map[string]any
require.NoError(t, json.Unmarshal([]byte(response.Content), &fields))
require.NotContains(t, fields, "kind")

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-44] The test decodes results back into OpenPreviewResult, so no test pins the JSON keys the struct doc says must stay stable. (Bisky)

With the tags renamed to json:"slug,omitempty" and json:"agent", TestOpenPreview still passes, and preview cards in already-stored messages would lose the keys the dashboard reads. Compare response.Content with require.JSONEq against a literal for one port row and one path row, and drop the kind check, which the literal covers.

🤖

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.

Fixed in 631c66e: the Port and Path rows compare the stored JSON with require.JSONEq against a literal, so renaming a tag fails them.

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.

Verified fixed in 631c66e: renaming a tag fails the JSONEq rows.

🤖

if errors.Is(err, previewhost.ErrHostPrefixCookieOff) {
return "previews require --host-prefix-cookie; tell the user an administrator can enable it"
}
return "previews need a wildcard app hostname on the primary deployment; tell the user an administrator can set one"

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-45] The no-wildcard message tells the administrator to set "a wildcard app hostname", which is not the name of a setting, while the message on line 221 names its flag. (Leorio)

Write: "previews need a wildcard access URL (--wildcard-access-url) on the primary Coder server, which is not set; tell the user an administrator can set it".

🤖

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.

Declined: the message is for the model to relay, and the docs page that quotes it links the wildcard access URL setting, so we are keeping this wording for the experiment.

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.

Accepted.

🤖

Username: workspace.OwnerUsername,
}
if len(app.String()) > maxHostnameLabelLength {
return fantasy.NewTextErrorResponse("The preview address would be longer than DNS allows. Use a shorter workspace or agent name."), nil

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-46] The hostname length message does not say that the user must rename something, or which name is long. (Leorio)

The model cannot rename a workspace or agent, and the label also contains the owner's username, so "use a shorter workspace or agent name" can be the wrong advice. Return the label and its length, for example: fmt.Sprintf("the preview hostname label %q is %d characters, over the DNS limit of %d; tell the user to rename the workspace or agent to shorten it", label, len(label), maxHostnameLabelLength).

🤖

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.

Declined: the model relays this to the user, who can rename the workspace or agent, and if the hostname is still too long, sign-in's error gives the exact label and its length, so the short message is enough here.

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.

The fallback does not apply here. Sign-in's error with the exact label and length (previewhost.go:186) runs only when the user clicks a result, and when the label is over 63 characters line 179 refuses the call, so no result exists and sign-in never runs. After a rename the tool returns the same sentence. The label also includes the owner's username, which the message never mentions, so a user with a long username can rename the workspace and agent and still be refused without learning why. Return the label and its length, as sign-in does.

🤖

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.

Declined: you are right that sign-in never sees a label the tool refuses, so our earlier reply was wrong about that. We are still keeping the short message: the model relays it, and shortening the workspace or agent name fixes the label in every case except a username near the 32-character limit.

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.

Accepted: with every name capped at 32 characters, a shorter workspace or agent name always brings the label under 63.

🤖

URLPath string `json:"url_path,omitempty"`
}

// PreviewWorkspace is the workspace agent a preview opens on.

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.

Nit [CRF-47] The PreviewWorkspace doc says "the workspace agent", but the struct now also holds the workspace name, owner ID and owner username. (Gon)

Write: // PreviewWorkspace is the workspace, owner and agent a preview opens on.

🤖

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.

Declined: every field identifies or reaches the agent a preview opens on, including the workspace and owner names that form its hostname, so the one-line doc still describes the type accurately.

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.

Accepted.

🤖

return fantasy.NewTextErrorResponse(err.Error()), nil
}
if workspace.OwnerID != options.ChatOwnerID {
return fantasy.NewTextErrorResponse("Previews open only for the workspace owner, and this chat's workspace belongs to another user."), nil

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.

Nit [CRF-48] This message and the one on line 180 are the only chattool tool errors that start with a capital letter and end with a period. (Gon)

The other messages in this function (lines 192, 201, 207) and in the package start lowercase and have no final period. Write these two the same way.

🤖

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.

Declined: these two messages are the model-facing sentences chosen in an earlier round for the hostname length and missing app cases, and their casing differs from the other errors without changing what the model or the user does with them.

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.

Accepted.

🤖

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

CRF-39 (review 6066422083, exp_chats.go:1529): Declined: the comment's list misses the reserved open_preview check, but its point that collisions with every other built-in name are caught at chatloop time is still true, and the reserved check documents itself on OpenPreviewToolName.

@DanielleMaywood

Copy link
Copy Markdown
Collaborator 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 review covers 631c66e. Findings: 1 P1, 1 P4 and 1 Nit are new, and 2 earlier findings are raised again at P4.

The P1 is the new RootPreview row in TestBuildTurnEnvironmentToolPolicy. It fails in about one run in ten, reproduced 6 times in 60 local runs. This may be what the Flake Check job reports; its log could not be read here. The rest of the CI failures (20 jobs, including changes, lint-actions and test-js) were not reproduced: go build ./coderd/... ./codersdk/..., go vet on both chatd packages and the OpenPreview tests pass locally at this head.

The five fixes in 631c66e check out. Seven contested findings are closed, and the reviewers who raised them accepted the replies, including the reply on the validation-loop comment at coderd/exp_chats.go:1529. Two replies were not accepted:

  • The port forwarding check: the reviewers accept the gate as a product rule. The error text still says port forwarding is not allowed, which is false.
  • The hostname length message: the sign-in fallback the reply relies on never runs, because the tool refuses before there is a card to click.

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

  • coderd/exp_chats.go:1544: the duplicate-name check compares untrimmed names, so "a" and " a" both pass, and dynamicToolNamesFromChat then merges them into one name.

🤖 This review was automatically generated with Coder Agents.

dontWant: []string{"open_preview"},
},
// The seeded names are too long for a preview address, which the tool checks after the workspace owner.
{name: "RootPreview", server: previewServer, preview: "longer than DNS allows", prompt: []string{advisorGuidance, acpSubagentPromptBlock}, want: []string{chatadvisor.ToolName}},

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.

P1 [CRF-54] The RootPreview row fails in about one run in ten, because its hostname label is built from random names that are sometimes short enough to pass the 63-character check. (Bisky, Chopper)

The user, workspace and agent names come from testutil.GetRandomName. When they total 40 characters or fewer, the label passes, OpenPreview calls Conn.OpenPreview, and the mock fails with Unexpected call to *agentconnmock.MockAgentConn.OpenPreview(... {/site}); this happened in 6 of 60 runs of TestBuildTurnEnvironmentToolPolicy here and in 16 of 150 for Bisky. The gomock controller is built from the parent t inside agentConnFn, so in some runs its Fatalf runs on the subtest goroutine and panics the binary, failing PlanRoot, PlanChild and RootWithoutExperiment as well. Seed short fixed names, expect OpenPreview on the mock, assert a successful result, and build the controller from the subtest's t; that also stops the row from proving the ChatOwnerID wiring only through the order of the owner and length checks.

🤖

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.

Fixed in 9ec965f: TestBuildTurnEnvironmentToolPolicy now uses fixed short names, builds the mock from the subtest and expects OpenPreview, so RootPreview asserts a successful result; green at -count=100 and -race -count=10, and removing ChatOwnerID still fails it.

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.

Verified fixed in 9ec965f: 80 of 80 separate runs passed.

🤖

WorkspaceName: workspace.WorkspaceName,
Username: workspace.OwnerUsername,
}
if len(app.String()) > maxHostnameLabelLength {

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-56] For a port target, the hostname length refusal runs before the port forwarding refusal, so a user can rename the workspace or agent and then be refused anyway. (Chopper)

On an agent without port_forwarding_helper and with a long workspace name, the first call returns "Use a shorter workspace or agent name.", and after the rename the next call returns the port forwarding refusal at line 192. The display app check needs only workspace.Agent, so move the previewKindPort check above the slug and length check at line 167.

🤖

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.

Fixed in 9ec965f: the port forwarding display-app check now runs right after the owner check, and the PortForwardingDisabled row uses port 65000 with the long workspace name.

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.

Verified fixed in 9ec965f: swapping the checks back fails PortForwardingDisabled.

🤖

replaceMCP bool
server *Server
// preview is part of open_preview's answer for a directory.
preview string

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.

Nit [CRF-57] The test case field preview does not hold a preview; it holds a substring the open_preview response must contain, and its doc names neither use. (Gon)

Rename it to wantPreviewResponse, next to want and dontWant, with a doc such as // wantPreviewResponse is a substring of open_preview's response to a path call; empty skips the call.

🤖

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.

Declined: the field's comment already says it holds part of open_preview's answer to the path call, which is what the row checks, so we are keeping the name.

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.

Accepted.

🤖

@DanielleMaywood

Copy link
Copy Markdown
Collaborator 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 review covers 9ec965f. Findings: 2 P4 and 1 Nit are new. No P0 to P3 finding is open.

The flaky RootPreview row is fixed: 80 separate runs of TestBuildTurnEnvironmentToolPolicy passed here (6 of 60 failed at 631c66e), and Bisky's 40 race-enabled runs passed. The port forwarding message and the check-order fix also hold, and both contested replies (the hostname length message and the test field name) were accepted by the reviewers who raised them. This dismisses the previous request for changes.

18 CI jobs still fail at this head, including ones this Go-only diff does not touch (changes, lint-actions, test-js). Their logs could not be read here. go build ./coderd/..., go vet on both chatd packages and the OpenPreview and tool-policy tests pass locally.

🤖 This review was automatically generated with Coder Agents.


// previewsUnavailableMessage tells the model why the primary deployment
// serves no previews, and what the user can do about it.
func previewsUnavailableMessage(err error) string {

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-61] previewsUnavailableMessage treats every error other than previewhost.ErrHostPrefixCookieOff as "no wildcard app hostname", which is right only while coderd.go:739-746 sets exactly two reasons. (Zoro)

A third reason added there would reach the model as a false wildcard message, and the cookie wording already exists in three places (previewhost.go:70, coderd/previews.go:115, here). Add previewhost.ErrNoWildcardHostname next to ErrHostPrefixCookieOff, return it from coderd.go:746, and have the default branch return err.Error() so an unknown reason is reported as it is.

🤖

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.

Declined: you are right that the default branch assumes the only other reason is a missing wildcard hostname. coderd sets exactly those two reasons today, and each message is worded for its reader, and a third reason would need its own message.

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.

Accepted: both current reasons get a true message, and a new reason would need its own wording anyway.

🤖

if tt.server != nil {
turnServer = tt.server
}
if turnServer == previewServer {

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-60] The RootPreview mock is installed by writing the shared previewServer.agentConnFn from inside a t.Parallel() subtest, so the test is correct only while exactly one row uses previewServer. (Bisky)

A second row with server: previewServer would race on that field with the first row's buildTurnEnvironment, and one row's once-only OpenPreview expectation would fail while the other's goes unmet. It holds today (40 race-enabled runs passed). Create the preview server inside the row, or give the row an agentConn field the loop applies to a per-row server, so no subtest writes shared state.

🤖

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.

Declined: you are right that a second row on previewServer would race on that field, and that it holds today (we also saw 50 of 50 race-enabled runs pass). Only one row needs the preview experiment, so we are leaving the setup as it is rather than restructuring for a row that does not exist.

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.

Accepted: a second row would fail loudly under the race detector.

🤖

want: chattool.OpenPreviewResult{Title: "App", Port: 65535, PreviewSlug: "preview--65535"},
},
{
name: "PortForwardingDisabled",

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.

Nit [CRF-59] The PortForwardingDisabled row now pairs port 65000 with longWorkspaceName to pin the check order, but nothing says so. (Gon)

Someone who simplifies the row back to the default workspace name removes the only test of that order, and the test still passes. Add a comment such as // The label is also too long: the port forwarding refusal must come first.

🤖

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.

Declined: you are right that the row does not say why it uses the long workspace name. Reverting the check order fails it, and a change that drops longWorkspaceName from the row is visible in review, so we are not adding a comment for it.

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.

Accepted: reverting the check order fails the row today.

🤖

@DanielleMaywood

Copy link
Copy Markdown
Collaborator 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 review covers a1249bd, a rebase of 9ec965f with an identical patch; the base change touches only two comments in coderd/previews.go. No new findings, and no open findings remain: the reviewers who raised the three remaining findings (the PortForwardingDisabled order comment, the shared previewServer write, and the previewsUnavailableMessage default branch) accepted the replies.

The request for changes from the earlier review was for the flaky RootPreview row, which is fixed. It could not be dismissed from this account, so it needs a dismissal by someone with write access.

19 CI jobs still fail at this head, including changes, which only detects changed paths. Their logs could not be read here. go build ./coderd/..., go vet on both chatd packages and the OpenPreview, tool-policy and reserved-name tests pass locally.

🤖 This review was automatically generated with Coder Agents.

@DanielleMaywood

Copy link
Copy Markdown
Collaborator 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 review covers 004cc93. The only change to the PR's own commit is the new ARCHITECTURE.md prose that replaces the TODO comments; the rest comes from the rebase. Findings: 4 P4 and 2 Nit, all about that prose and the PR text. The Go code is unchanged since the last review.

The new prose matches the code except for the points below. 18 CI jobs still fail at this head, and their logs could not be read here. go build ./coderd/..., go vet on both chatd packages and the OpenPreview, tool-policy and reserved-name tests pass locally.

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/x/chatd/ARCHITECTURE.md Outdated

For a `path`, the workspace agent publishes the path under an ID hashed from it. The publication lasts until the agent restarts. Each result stores the title, workspace ID, agent name, port, preview slug, path, and URL path. For a port, the slug is `preview--<port>`. The dashboard renders `open_preview` results as preview cards, and the user clicks a card to open the preview.

The name `open_preview` is reserved, because chatd would treat a built-in `open_preview` call as a call the client runs if a dynamic tool shared the name. Creating a chat with a dynamic tool whose name, with surrounding whitespace trimmed, is `open_preview` fails with a 400 error. Turns drop such a dynamic tool if a chat stored one earlier.

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] "Turns drop such a dynamic tool if a chat stored one earlier" is false for a stored name with surrounding whitespace, and it reads as if stored rows are fully handled. (Razor, Leorio)

appendDynamicTools looks up the untrimmed key from parseDynamicToolNames (chatd.go:2154), so a stored " open_preview" is kept: a scratch test on [{"name":" open_preview"}] returned names=map[ open_preview:true] and one tool named " open_preview". For the same chat dynamicToolNamesFromChat trims to open_preview, so tasks.go:830, hook_server.go:136 and memory.go:116 still classify built-in calls as client-run, which is the accepted residual for older chats. Either describe that residual in this sentence, or drop every key whose strings.TrimSpace equals OpenPreviewToolName in appendDynamicTools and add a padded row to TestAppendDynamicToolsReservesOpenPreview.

🤖

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.

Fixed in 0be9a55: the sentence now says turns drop a stored dynamic tool named exactly open_preview. A padded name stored before this stack is the residual we accepted for older chats, so we documented the exact behavior rather than widening the drop.

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.

Verified fixed in 0be9a55: "named exactly open_preview" matches the untrimmed lookup in appendDynamicTools.

🤖

Comment thread coderd/x/chatd/ARCHITECTURE.md Outdated

When the `open-preview` experiment is enabled, root chats outside plan mode get `open_preview`. `open_preview` reports that previews are unavailable when the primary deployment has no wildcard app hostname or when `--host-prefix-cookie` is off.

A call takes a `title`, exactly one of `port` or `path`, and an optional `url_path`. The title cannot contain control, format, or line and paragraph separator characters. `open_preview` refuses three kinds of call: a workspace owned by a user other than the chat's owner, a preview hostname label over 63 characters, and a port when the agent's template hides the port forwarding display app. Port URLs still work on that agent. `open_preview` does not open ports there and suggests previewing static files by `path` instead.

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-63] "open_preview refuses three kinds of call" leaves out the single-file url_path refusal at openpreview.go:206, which is also the only refusal that runs after a side effect. (Razor, Pen Botter)

A single-file path with a url_path pathname other than / is refused after Conn.OpenPreview has already published the file. A reader of this section would take url_path as unrestricted and every refusal as happening before anything is published. Add that refusal and say it runs after publishing, or drop the count.

🤖

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.

Fixed in 0be9a55: the section no longer counts the refusals and adds that a single-file path with a url_path other than / is also refused, after the agent has published the file.

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.

The refusal is now listed and says it runs after publishing. The new sentence is broader than the check; that is CRF-69.

🤖


A call takes a `title`, exactly one of `port` or `path`, and an optional `url_path`. The title cannot contain control, format, or line and paragraph separator characters. `open_preview` refuses three kinds of call: a workspace owned by a user other than the chat's owner, a preview hostname label over 63 characters, and a port when the agent's template hides the port forwarding display app. Port URLs still work on that agent. `open_preview` does not open ports there and suggests previewing static files by `path` instead.

For a `path`, the workspace agent publishes the path under an ID hashed from it. The publication lasts until the agent restarts. Each result stores the title, workspace ID, agent name, port, preview slug, path, and URL path. For a port, the slug is `preview--<port>`. The dashboard renders `open_preview` results as preview cards, and the user clicks a card to open the preview.

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-64] "The dashboard renders open_preview results as preview cards" is true only with #32441, and the tool description makes the same assumption. (Pen Botter, Razor, Chopper)

At this head site/src has no open_preview renderer, so results show through GenericToolRenderer as JSON with nothing to click, while the tool description (openpreview.go:148) tells the model the user opens the preview with a click. open-preview is not in ExperimentsSafe, so only an explicit opt-in sees this. State in the PR description that #32440 and #32441 must merge together, or move this sentence to #32441.

🤖

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.

Fixed in the PR description: it now says the dashboard shows open_preview results as preview cards only with #32441, so this PR and #32441 merge together, and that on its own a result shows as plain tool output.

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.

Verified: the PR description now says #32440 and #32441 merge together.

🤖

Comment thread coderd/x/chatd/ARCHITECTURE.md Outdated

When the `open-preview` experiment is enabled, root chats outside plan mode get `open_preview`. `open_preview` reports that previews are unavailable when the primary deployment has no wildcard app hostname or when `--host-prefix-cookie` is off.

A call takes a `title`, exactly one of `port` or `path`, and an optional `url_path`. The title cannot contain control, format, or line and paragraph separator characters. `open_preview` refuses three kinds of call: a workspace owned by a user other than the chat's owner, a preview hostname label over 63 characters, and a port when the agent's template hides the port forwarding display app. Port URLs still work on that agent. `open_preview` does not open ports there and suggests previewing static files by `path` instead.

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.

Nit [CRF-67] "Port URLs still work on that agent" does not say which URLs; the only ones this section has mentioned are the ones open_preview just refused. (Leorio)

Write, for example: "Sign-in and the preview host still serve preview--<port> URLs for that agent; only open_preview refuses to open them, and it suggests previewing static files by path instead."

🤖

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.

Fixed in 0be9a55: it now says sign-in and the preview host still serve preview--<port> URLs for that agent.

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.

Verified fixed in 0be9a55: the sentence now names the preview--<port> URLs.

🤖

- subagents (`spawn_agent`, `wait_agent`, `message_agent`, `interrupt_agent`, `list_agents`, `list_subagent_models`)
- file links
- workspace binding
- workspace binding. `getWorkspaceConn` caches the agent row together with the connection. `getWorkspaceBinding` returns the connection, the agent row, and the workspace ID from one lock section.

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.

Nit [CRF-68] The workspace binding entry says what getWorkspaceBinding returns but not why the three values must come from one lock section. (Leorio)

Without the reason, nothing in the document stops a later change from reading the conn and the agent separately again. Add a clause such as "so a tool that builds hostnames from the agent and workspace names, such as open_preview, gets names that belong to the connection it calls."

🤖

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.

Declined: the sentence states what is cached and returned together, which is what a later change must keep. A stated reason would have to stay exact about what the lock section does not guarantee (a conn can still be stale after an agent switch, the accepted TOOL-CRF-14 limitation), so we keep the statement of fact.

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.

Accepted: the sentence states what a later change must keep together, and a reason would also have to carry the CRF-14 exception.

🤖

Root chats outside plan mode get the open_preview tool when the
open-preview experiment is on and the server hosts previews. It opens a
running port, or an .html file or directory the agent publishes, and
dynamic tools named open_preview are dropped so nothing else can pose as
it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@DanielleMaywood

Copy link
Copy Markdown
Collaborator 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 review covers 0be9a55. Since 004cc93 the PR's own commit changes only three sentences in ARCHITECTURE.md; the rest comes from the rebase onto 4f68cc0, whose previewHostingFor change this PR does not call. CRF-62, CRF-64, CRF-66 and CRF-67 are verified fixed, and the CRF-68 defense is accepted. Findings: 2 P4, both on the sentence added for CRF-63. go test ./coderd/x/chatd/chattool/ -run TestOpenPreview passes locally.

Note: the preview-card sentence (CRF-64) is correct only if #32440 and #32441 merge together, as the PR description now says. If they merge separately, it and the tool description at openpreview.go:148 describe a card the dashboard does not render.

🤖 This review was automatically generated with Coder Agents.


When the `open-preview` experiment is enabled, root chats outside plan mode get `open_preview`. `open_preview` reports that previews are unavailable when the primary deployment has no wildcard app hostname or when `--host-prefix-cookie` is off.

A call takes a `title`, exactly one of `port` or `path`, and an optional `url_path`. The title cannot contain control, format, or line and paragraph separator characters. `open_preview` refuses these calls: a workspace owned by a user other than the chat's owner, a preview hostname label over 63 characters, and a port when the agent's template hides the port forwarding display app. A single-file `path` with a `url_path` other than `/` is also refused, after the agent has published the file. Sign-in and the preview host still serve `preview--<port>` URLs for that agent. `open_preview` does not open ports there and suggests previewing static files by `path` instead.

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-69] "A single-file path with a url_path other than / is also refused" is false for a query-only url_path such as /?page=2, which the tool accepts. (Netero, Leorio, Razor, Pen Botter)

The check at openpreview.go:206 cuts the query off first and refuses only when the remaining pathname is neither empty nor /. TestOpenPreview/FileWithQuery (openpreview_test.go:83) sends url_path /?page=2 for a file and expects success, and it passes at this head. A reader of this section would conclude that a file preview takes no url_path at all, which contradicts the tool description (openpreview.go:143) and the PR description. For example: "A single-file path whose url_path has a path other than / is also refused, after the agent has published the file. A query such as /?page=2 is allowed."

🤖


When the `open-preview` experiment is enabled, root chats outside plan mode get `open_preview`. `open_preview` reports that previews are unavailable when the primary deployment has no wildcard app hostname or when `--host-prefix-cookie` is off.

A call takes a `title`, exactly one of `port` or `path`, and an optional `url_path`. The title cannot contain control, format, or line and paragraph separator characters. `open_preview` refuses these calls: a workspace owned by a user other than the chat's owner, a preview hostname label over 63 characters, and a port when the agent's template hides the port forwarding display app. A single-file `path` with a `url_path` other than `/` is also refused, after the agent has published the file. Sign-in and the preview host still serve `preview--<port>` URLs for that agent. `open_preview` does not open ports there and suggests previewing static files by `path` instead.

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-70] The new single-file sentence sits between the port forwarding refusal and the two sentences that explain it, so "for that agent" and "does not open ports there" now follow a sentence about the agent that published a file. (Pen Botter)

In 004cc93 "that agent" directly followed "a port when the agent's template hides the port forwarding display app". Move the single-file sentence after "suggests previewing static files by path instead", or name the agent: "for an agent whose template hides the port forwarding display app".

🤖

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

experimental Changes that might not necessarily be merged, until its approved to proceed with.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant