Repository navigation
feat(coderd): add the open_preview chat tool - #32440
DanielleMaywood wants to merge 1 commit into
Conversation
7730f11 to
a80637d
Compare
a80637d to
e37889b
Compare
|
/coder-agents-review |
|
Chat: Review posted | View chat Review history
deep-review v0.13.1 | Round 9 | Last posted: Round 9, 52 findings (1 P1, 11 P3, 31 P4, 9 Nit), COMMENT. Review Finding inventoryFindings
Contested and acknowledgedCRF-2 (P3, turn_environment.go:1968) - getWorkspaceBinding cached-conn and mismatch branches untested
CRF-4 (Nit, ARCHITECTURE.md:1199) - only HTML TODO comments
CRF-9 (P4, openpreview.go:186) - single-file preview published before url_path rejection
CRF-14 (P4, turn_environment.go:1810) - cache hit can pair previous conn with new agent
CRF-15 (P4, turn_environment.go:2661) - workspace MCP tools named open_preview
CRF-17 (P3, turn_environment.go:1788) - workspaceBinding duplicates chattool.PreviewWorkspace
CRF-18 (P3, openpreview.go:148) - tool description opens with "Open a preview"
CRF-26 (Nit, openpreview.go:111) - 65535 literal
CRF-27 (P4, openpreview.go:26) - length constants lack source comments
CRF-31 (P4, openpreview.go:184) - port slug built by hand
CRF-19 (P4, openpreview.go:143) - OpenPreview doc omits path publishing
Round 4 panel closures
CRF-1 (P3, turn_environment.go:2661) - open_preview reservation incomplete for stored rows (R5)
CRF-30 (P4, turn_environment.go:1799) - commit message stale (R5)
CRF-39 (P4, exp_chats.go:1529) - validation-loop comment says collisions are checked at chatloop time (R5)
CRF-41 (P4, openpreview.go:179) - label check copies sign-in rule without prefix and suffix (R5)
CRF-42 (P3, openpreview.go:191) - port forwarding display-app check enforced only in the tool (R5)
CRF-45 (P4, openpreview.go:223) - no-wildcard message does not name the setting (R5)
CRF-46 (P4, openpreview.go:180) - hostname-length message lacks label and length (R5)
CRF-47 (Nit, openpreview.go:56) - PreviewWorkspace doc (R5)
CRF-48 (Nit, openpreview.go:163) - capitalized error messages (R5)
Round 5 panel dispositions
CRF-46 (P4, openpreview.go:180) - hostname-length message (R6)
CRF-57 (Nit, turn_environment_internal_test.go:906) - test field named preview (R6)
Round 6 panel dispositions
CRF-59 (Nit, openpreview_test.go:191) - PortForwardingDisabled row lacks order comment (R7)
CRF-60 (P4, turn_environment_internal_test.go:1065) - shared previewServer written from parallel subtest (R7)
CRF-61 (P4, openpreview.go:219) - previewsUnavailableMessage default branch (R7)
Round 7 panel dispositions
CRF-68 (Nit, ARCHITECTURE.md:1198) - workspace binding entry gives no reason (R9)
Round logRound 1Netero first pass: 2 P3, 1 P4, 1 Nit. No P0, panel proceeds. Law not run (effective additions 619). Round 2Churn 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 3Churn 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 4Churn 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. Round 5Churn 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. Round 6Churn 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). Round 7Churn guard PROCEED: 3 contested (CRF-59, 60, 61), 0 silent. Head a1249bd is a pure rebase of 9ec965f onto 588ce57 (range-diff 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 8Churn 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. Round 9Churn 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. About deep-reviewCRF = Coder Review Finding (P0-P4, Nit, Note)
|
There was a problem hiding this comment.
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 onlyappendDynamicToolsdrops colliding names;dynamicToolNamesFromChatandparseDynamicToolNamesstill classify a call to any colliding built-in (for exampleexecute) as dynamic, so interruption andSubmitToolResultstreat it differently from the turn that ran it.coderd/x/chatd/chattool/mcpworkspace.go:56:NewWorkspaceMCPToolsaccepts agent-reported names without theserver__toolform, 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 unchangedfor attempt := 0; attempt < 2; attempt++loops (also lines 1474 and 1627) can befor 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.ListeningPortsexists, 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] { |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
🤖
| - 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. --> |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
🤖
| AlwaysEnableDebugLogs: options.DeploymentValues.AI.Chat.DebugLoggingEnabled.Value(), | ||
| StreamSilenceTimeout: streamSilenceTimeout, | ||
| DisableCallerSuppliedTools: options.DeploymentValues.DisableChatCallerSuppliedTools.Value(), | ||
| PreviewsAvailable: api.previewHosting != nil, |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
Verified fixed in 18fa1d5: the option comment and the message now say the primary deployment.
🤖
| // trusts its results, so no other tool source may use the name. | ||
| const OpenPreviewToolName = "open_preview" | ||
|
|
||
| const maxPreviewTitleLength = 80 |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
Declined: wording nit; the URL path limit now lives in previewhost.CheckURLPath, and the title limit is local to this tool.
There was a problem hiding this comment.
Accepted.
🤖
| 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) |
There was a problem hiding this comment.
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.
🤖
| 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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Accepted: the squash commit takes the PR description, which is correct.
🤖
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
🤖
| 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) |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
Declined: a port slug constructor in appurl is a refactor with no behavior change, and sign-in parses every slug with ParsePreviewSlug.
There was a problem hiding this comment.
Accepted: both encoders produce the same form, and any drift would fail at sign-in rather than open the wrong target.
🤖
e37889b to
68eb07e
Compare
290143c to
3e10f72
Compare
f4e63e8 to
5fb9b6c
Compare
5fb9b6c to
98365a4
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
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 ofgetWorkspaceBindinghave no test.coderd/x/chatd/ARCHITECTURE.md:1199: the document gets only HTML TODO comments foropen_previewand the binding change.coderd/x/chatd/chattool/openpreview.go: a single-file preview is published on the agent before a pathname inurl_pathis rejected.coderd/x/chatd/turn_environment.go:1810: duringselectWorkspace, a cache hit can pair the previous workspace's conn with the new agent.coderd/x/chatd/turn_environment.go: workspace MCP tools namedopen_previeware not blocked.coderd/x/chatd/turn_environment.go:1788:workspaceBindingduplicateschattool.PreviewWorkspaceand 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: theOpenPreviewdoc does not say thatpathtargets are published on the agent.coderd/x/chatd/chattool/openpreview.go:65535is still a repeated literal.coderd/x/chatd/chattool/openpreview.go:maxPreviewTitleLengthhas no comment, and theTitletag still hardcodes 80.coderd/x/chatd/chattool/openpreview.go: the port slug is still built by hand instead of inappurl.
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.
|
/coder-agents-review |
There was a problem hiding this comment.
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.
|
/coder-agents-review |
There was a problem hiding this comment.
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,dynamicToolNamesFromChatandparseDynamicToolNamesFromRawparse 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 duringselectWorkspaceexists becauseloadWorkspaceAgentLockedwritesc.agentandc.cachedWorkspaceIDwithoutc.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.
| } | ||
| switch req.kind { | ||
| case previewKindPort: | ||
| if !slices.Contains(workspace.Agent.DisplayApps, database.DisplayAppPortForwardingHelper) { |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
| - 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. --> |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
Fixed in 631c66e: both TODO lines in ARCHITECTURE.md now match the code; they stay TODOs for the author to write up.
There was a problem hiding this comment.
Verified fixed in 631c66e: both TODOs match the head.
🤖
| Message: "Dynamic tool name must not be empty.", | ||
| }) | ||
| } | ||
| if dt.Name == chattool.OpenPreviewToolName { |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
Fixed in 631c66e: createChat trims dynamic tool names before the reserved-name check, and the ReservedToolName cases include a padded name.
|
|
||
| if p.experiments.Enabled(codersdk.ExperimentOpenPreview) { | ||
| tools = append(tools, chattool.OpenPreview(chattool.OpenPreviewOptions{ | ||
| PreviewsUnavailable: p.previewsUnavailable, |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
Fixed in 631c66e: TestBuildTurnEnvironmentToolPolicy has rows for PreviewsUnavailable and ChatOwnerID; removing either option fails its row.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
Fixed in 631c66e: the Port and Path rows compare the stored JSON with require.JSONEq against a literal, so renaming a tag fails them.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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".
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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).
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Accepted.
🤖
|
CRF-39 (review 6066422083, |
18fa1d5 to
631c66e
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
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, anddynamicToolNamesFromChatthen 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}}, |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Verified fixed in 9ec965f: 80 of 80 separate runs passed.
🤖
| WorkspaceName: workspace.WorkspaceName, | ||
| Username: workspace.OwnerUsername, | ||
| } | ||
| if len(app.String()) > maxHostnameLabelLength { |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Accepted.
🤖
631c66e to
9ec965f
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Accepted: a second row would fail loudly under the race detector.
🤖
| want: chattool.OpenPreviewResult{Title: "App", Port: 65535, PreviewSlug: "preview--65535"}, | ||
| }, | ||
| { | ||
| name: "PortForwardingDisabled", |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Accepted: reverting the check order fails the row today.
🤖
9ec965f to
a1249bd
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
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.
a1249bd to
9a116a6
Compare
9a116a6 to
004cc93
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
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.
|
|
||
| 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. |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Verified fixed in 0be9a55: "named exactly open_preview" matches the untrimmed lookup in appendDynamicTools.
🤖
|
|
||
| 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. |
There was a problem hiding this comment.
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.
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
🤖
|
|
||
| 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. |
There was a problem hiding this comment.
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."
🤖
There was a problem hiding this comment.
Fixed in 0be9a55: it now says sign-in and the preview host still serve preview--<port> URLs for that agent.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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."
🤖
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]>
004cc93 to
0be9a55
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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".
🤖
Adds the
open_previewchat tool. Root chats outside plan mode get it whenever theopen-previewexperiment is enabled. When previews are unavailable, because the primary deployment has no wildcard app hostname or--host-prefix-cookieis 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 apreview--<port>host.path: an.htmlfile or a directory withindex.html, published by the workspace agent and served on apreview--<id>host.An optional
url_pathopens 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_pathmust passpreviewhost.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 namedopen_previewreturns 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.gonow caches the agent with the connection and returns all three from one lock section (getWorkspaceBinding), andgetWorkspaceConngoes through it.coderd/x/chatd/ARCHITECTURE.mddocuments the binding change and adds a Workspace previews section.The dashboard shows
open_previewresults 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.
🤖 Generated with Claude Code