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 11 | Last posted: Round 11, 53 findings (1 P1, 11 P3, 32 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. Round 10Churn guard PROCEED: 2 addressed (CRF-69, 70 in 9a81592), 0 contested, 0 silent. Base moved to aa2ba14 (#32522 sign-in); between bases only coderd/previews.go (proxy lookup as system-restricted), its test and codersdk RegionID omitzero changed, none called by this PR. The patch change is one ARCHITECTURE.md sentence rewritten and moved. Fix round over that file. Round 11Churn guard PROCEED: 0 open findings. Head 944be92 rebased onto cb551b7 (base change: two comments in coderd/previews.go and its test). The only patch change since R10: one sentence added to the open_preview tool description (openpreview.go:148) telling the model that Host-checking dev servers such as Vite must allow the preview's address. Fix round over that sentence. 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.
This review covers 9a81592. Since 0be9a55 the PR's own commit only rewrites and moves the single-file url_path sentence in ARCHITECTURE.md. The rest comes from the rebase onto aa2ba14, which changes the sign-in proxy lookup in coderd/previews.go; this PR does not call it. CRF-69 and CRF-70 are verified fixed, and no findings remain open.
Locally, go build ./coderd/..., go vet ./coderd/x/chatd/chattool/ and the OpenPreview, tool-policy and reserved-name tests pass. 19 CI jobs fail at this head, and their logs could not be read here.
🤖 This review was automatically generated with Coder Agents.
9a81592 to
944be92
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
This review covers 944be92. Since 9a81592 the PR's own commit adds one sentence to the open_preview tool description about dev servers that check the Host header. The rest comes from the rebase onto cb551b7, which changes only comments in coderd/previews.go and its test. The sentence's premise is correct: ServerTailnet.ReverseProxy (coderd/tailnet.go:227) uses httputil.NewSingleHostReverseProxy, which leaves req.Host as the preview hostname, and apptest.go:1088 asserts that pass-through for subdomain apps. Findings: 1 P4. go test ./coderd/x/chatd/chattool/ -run OpenPreview and go vet ./coderd/x/chatd/chattool/ pass locally.
Out of scope (needs a ticket or explicit acceptance by a human):
coderd/tailnet.go:227:httputil.NewSingleHostReverseProxysetsReverseProxy.Director, which Go 1.26 deprecates in favor ofRewrite.
🤖 This review was automatically generated with Coder Agents.
| "Add url_path to open at a path and query other than /, for example /?folder=/home/coder/project. "+ | ||
| "File previews serve the files' current contents and last until the workspace agent restarts; call this again with the same path to restore one. "+ | ||
| "Port and path previews may load only from their own address, so a page that loads scripts, styles, or fonts from a CDN or another server breaks; bundle them instead. "+ | ||
| "A dev server that checks the Host header, such as Vite, must allow the preview's address (for Vite, server.allowedHosts), or you can build the site and preview the output directory with path instead. "+ |
There was a problem hiding this comment.
P4 [CRF-72] The sentence tells the model to allow "the preview's address" in server.allowedHosts, but nothing the model receives contains that address. (Netero, Pen Botter, Chopper, Razor)
OpenPreviewResult (openpreview.go:44) holds the title, workspace ID, agent name, port, slug, path and url_path, and the wildcard suffix appears nowhere the model reads. The suffix also depends on the region the user picks when opening the preview (openpreview.go:68). So the model can only guess the hostname or set allowedHosts: true, which turns off Vite's DNS rebinding check, and a wrong guess shows the user Vite's "Blocked request" page while the model sees a successful result. Either say what to allow, for example the deployment's wildcard app domain such as .apps.example.com, which the agent can read from VSCODE_PROXY_URI (agent/agent.go:1570) for the primary, or keep only the build-and-preview-by-path advice. vite preview reads preview.allowedHosts, not server.allowedHosts, if the sentence keeps the Vite example.
🤖
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 944be92567
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| p.publishChatPubsubEvent(updatedChat, codersdk.ChatWatchEventKindStatusChange, nil) | ||
| } | ||
|
|
||
| if p.experiments.Enabled(codersdk.ExperimentOpenPreview) { |
There was a problem hiding this comment.
Add the dashboard renderer before exposing open_preview
When this experiment is enabled, successful calls are exposed to the model and persisted, but the current dashboard has no open_preview renderer or preview API caller: site/src/pages/AgentsPage/components/ChatElements/tools/Tool.tsx omits it from toolRenderers and sends unknown names to GenericToolRenderer. A repo-wide search likewise finds no chat-side consumer, so users receive a generic JSON tool row instead of the promised clickable preview card and cannot open the preview at all.
Useful? React with 👍 / 👎.
| if options.PreviewsUnavailable != nil { | ||
| return fantasy.NewTextErrorResponse(previewsUnavailableMessage(options.PreviewsUnavailable)), nil | ||
| } |
There was a problem hiding this comment.
Allow previews hosted exclusively by workspace proxies
On deployments without a primary AppHostname, this returns an error before producing a card even when a workspace proxy has a valid wildcard hostname. The existing preview endpoints deliberately resolve a requested proxy region independently in previewHostingFor, and only ErrHostPrefixCookieOff is globally fatal, so such a proxy can successfully serve the preview; passing the primary deployment's missing-host error here makes that valid region unreachable from chat.
Useful? React with 👍 / 👎.
| WorkspaceName: workspace.WorkspaceName, | ||
| Username: workspace.OwnerUsername, | ||
| } | ||
| if len(app.String()) > maxHostnameLabelLength { |
There was a problem hiding this comment.
Validate the selected region's full hostname label
For supported wildcard patterns with a first-label suffix, such as *--apps.example.com, this checks only the substituted application string and omits the static --apps bytes. Consequently, an application string at or near 63 bytes is accepted and stored, but previewhost.Hosting.URL later constructs the full first label and rejects it as over the DNS limit, so opening the resulting card always fails in that region. The validation must account for the selected region's wildcard pattern or be deferred to the region-aware address endpoint.
Useful? React with 👍 / 👎.
944be92 to
a59fe16
Compare
a59fe16 to
0343a38
Compare
a57c982 to
9075ba4
Compare
9075ba4 to
71763e3
Compare
71763e3 to
468ecee
Compare
63e66e1 to
32e41d8
Compare
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 <noreply@anthropic.com>
32e41d8 to
917c027
Compare
The tool stores what to open (workspace, agent, preview slug and path), not a URL. The dashboard resolves the address and signs in only when the user clicks, so a stored result never carries a credential and works in whichever region the user picks.
The tool refuses what sign-in would refuse, such as another user's workspace, so the agent can tell the user why before a card exists. The name
open_previewis reserved because chatd would treat a built-in call as client-run if a dynamic tool shared it. The workspace binding is read in one lock section because the tool builds hostnames from the agent and workspace names of the connection it calls.Implementation details
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