Skip to content

feat: serve published HTML previews from the workspace agent - #32438

Draft
DanielleMaywood wants to merge 1 commit into
mainfrom
open-preview/agent
Draft

DanielleMaywood wants to merge 1 commit into
mainfrom
open-preview/agent

Conversation

@DanielleMaywood

@DanielleMaywood DanielleMaywood commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

The workspace agent can publish an absolute .html file, or a directory containing index.html, and serve it from its existing HTTP API (port 4) under /api/v0/previews/{id}/. Publishing resolves symlinks in the path's parent directories once, so a path under a symlinked directory such as macOS /tmp serves from its real location, which the response returns. The preview ID is the first eight hex digits of the SHA-256 of that path, so publishing a path again, even after the agent restarts, returns the same ID. A different path whose ID is already taken gets a 409. Adds AgentConn.OpenPreview to the workspace SDK, which decodes the ID as appurl.PreviewID and returns ErrPreviewsUnsupported when the agent predates the route.

Each request opens the published directory again through os.Root, so a directory that is deleted and rebuilt keeps serving without publishing it again. Below the resolved parent, no path element may be a symlink, only regular files are served, and names that start with a dot below a published directory, such as .git and .env, are refused. Publishing a directory requires index.html at its root, and there are no listings. On Windows, names containing \, : or ~ are refused, because Windows reads them as a path separator, an alternate data stream or a short name such as HIDDEN~1. Responses are no-store and nosniff.

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

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

🤖 Generated with Claude Code

@DanielleMaywood DanielleMaywood added the experimental Changes that might not necessarily be merged, until its approved to proceed with. label Nov 19, 2026
@DanielleMaywood
DanielleMaywood removed this pull request from stack #32443 November 20, 2026 11:36
@coder-agents-review

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

Copy link
Copy Markdown
Contributor

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

Review history
  • R1 (2026-11-25): 13 reviewers, 5 Nit, 12 P3, 10 P4, COMMENT. Review
  • R2 (2026-11-25), 5 Nit, 12 P3, 10 P4, COMMENT. Review
  • R3 (2026-11-25): 15 reviewers, 6 Nit, 12 P3, 20 P4, COMMENT. Review
  • R4 (2026-11-26): 9 reviewers, 6 Nit, 12 P3, 20 P4, COMMENT. Review
  • R5 (2026-11-26): 5 reviewers, 6 Nit, 13 P3, 20 P4, COMMENT. Review
  • R6 (2026-11-26): 4 reviewers, 6 Nit, 13 P3, 20 P4, COMMENT. Review
  • R7 (2026-11-26): 4 reviewers, 6 Nit, 13 P3, 21 P4, COMMENT. Review
  • R8 (2026-11-26): 4 reviewers, 6 Nit, 13 P3, 22 P4, COMMENT. Review
  • R9 (2026-11-26): 4 reviewers, 6 Nit, 13 P3, 23 P4, COMMENT. Review
  • R10 (2026-11-26): 4 reviewers, 7 Nit, 13 P3, 23 P4, COMMENT. Review

deep-review v0.13.1 | Round 10 | f2b6084..5e517bd

Last posted: Round 10, 43 findings (13 P3, 23 P4, 7 Nit), COMMENT. Review

Finding inventory

Finding inventory: PR #32438

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P3 Author fixed (d156c13, removed the deadline call and the description paragraph) agent/agentpreview/preview.go:100 PR description claims an extendWriteDeadline middleware that the diff does not add; deadline duplicated with literal 5m R1 Netero Yes
CRF-2 P4 Author fixed (d156c13) agent/agentpreview/preview.go:60 servedName("") error branch in publish is unreachable R1 Netero Yes
CRF-3 P3 Author fixed (d156c13) agent/agentpreview/preview.go:150 Published directory that is (or is replaced by) a symlink serves the target tree; file symlink rejected at publish, dir symlink accepted R1 Kurapika P3, Pariston P4 Yes
CRF-4 P3 Author fixed (d156c13) agent/agentpreview/preview.go:176 Lstat walk and root.OpenFile resolve the name separately; swap to in-root symlink serves hidden file R1 Meruem P3, Kurapika P4, Melody P4, Pariston P4 Yes
CRF-5 P3 Author fixed (d156c13) agent/agentpreview/preview.go:166 Windows junctions are not ModeSymlink, pass the walk, and os.Root follows them into dot-prefixed dirs R1 Hisoka Yes
CRF-6 P3 Author fixed (d156c13) agent/agentpreview/preview.go:133 Subdirectory request without trailing slash returns 404 instead of redirect R1 Melody, Ryosuke, Pariston, Mafuuu, Hisoka Yes
CRF-7 P3 Author fixed (d156c13) agent/agentpreview/preview.go:72 Republishing same path after file/directory change returns 409 errIDTaken until restart R1 Mafuuu P3, Hisoka P4, Meruem P4 Yes
CRF-8 P3 Author contested; panel closed R4 (2/2 accept) agent/agentpreview/preview.go:59 index.html required for directory publish but not for serving; blocks previews of report.html with assets R1 Luffy P3, Mafuuu Note Yes
CRF-9 P3 Author fixed (d156c13) agent/agentpreview/preview.go:113 Unknown preview ID (common after agent restart) gives the same 404 and log error as a missing file R1 Luffy P3, Leorio P4, Ryosuke Note Yes
CRF-10 P4 Author contested; panel closed R4 (2/2 accept) codersdk/workspacesdk/agentconn.go:119 Registration called "open" in SDK and "publish" in agent; api.open is a different operation R1 Gon P3, Luffy Nit Yes
CRF-11 Nit Author accepted R4; operator decision R7 (experimental release, no ticket) codersdk/workspacesdk/agentconn.go:1516 OpenPreviewResponse.File bool / json "file" reads as a file name; sibling uses is_dir R1 Gon P3 Yes
CRF-12 P4 Author contested; panel closed R3 (1/1 accept) coderd/workspaceapps/appurl/preview.go:22 ID length encoded twice (sum[:4] and {8}) R1 Gon P3 Yes
CRF-13 P4 Author fixed (d156c13) coderd/workspaceapps/appurl/preview.go:25 UnmarshalText doc does not state the accepted format (lowercase hex) R1 Gon P3 Yes
CRF-14 Nit Author contested; panel closed R3 (1/1 accept) coderd/workspaceapps/appurl/preview.go:18 NewPreviewID doc second sentence restates agent behavior documented on OpenPreviewRequest R1 Gon P2 Yes
CRF-15 P4 Author contested; panel closed R4 (1/1 accept) coderd/workspaceapps/appurl/preview.go:17 No comment explains why the ID is 32 bits with 409 on collision R1 Leorio Yes
CRF-16 P4 Author fixed (d156c13) agent/agentpreview/preview.go:35 preview struct does not document file=="" means directory and dir is parent for file previews R1 Gon Yes
CRF-17 Nit Author contested; panel closed R3 (1/1 accept) agent/agentpreview/preview.go:59 Variable first does not say it is the root name R1 Gon Yes
CRF-18 Nit Author fixed (d156c13) agent/agentpreview/preview.go:147 openServed doc comment gives rationale but not behavior R1 Gon, Leorio Yes
CRF-19 P4 Author contested; panel closed R3 (2/2 accept) codersdk/workspacesdk/agentconn.go:1504 OpenPreviewRequest doc says hidden paths are not served, but a published dot file is served R1 Leorio P4, Gon Nit Yes
CRF-20 P3 Author fixed (d156c13) agent/agentpreview/preview.go:65 Directory without index.html returns "index.html: statat index.html: no such file or directory" R1 Leorio Yes
CRF-21 P4 Author fixed (d156c13) agent/agentpreview/preview.go:30 errNotServed states two rules, caller cannot tell which was broken R1 Leorio Yes
CRF-22 P4 Author fixed (d156c13) agent/agentpreview/preview.go:32 errIDTaken does not name the ID or the path holding it R1 Leorio Yes
CRF-23 Nit Author fixed (d156c13) agent/agentpreview/preview.go:42 "preview path must be absolute" omits the value sent R1 Leorio Yes
CRF-24 P3 Author fixed (d156c13) agent/agentpreview/preview_test.go:172 Relative-path test row passes without the IsAbs guard R1 Bisky Yes
CRF-25 P3 Author fixed (d156c13, removed the call); consequence reopened as CRF-42 agent/agentpreview/preview.go:100 No test checks handleServe extends the write deadline R1 Bisky Yes
CRF-26 P4 Author fixed (d156c13) coderd/workspaceapps/appurl/preview_test.go:11 No golden test pins NewPreviewID output across processes R1 Bisky Yes
CRF-27 P4 Author contested; panel closed R3 (1/1 accept) coderd/workspaceapps/appurl/preview.go:20 NewPreviewID is agent path-derivation logic exported from coderd URL package R1 Ryosuke Yes
CRF-28 Note Note (body) coderd/workspaceapps/appurl/preview.go:20 Preview ID is computable from a path; later PRs must authorize by workspace and user, not ID R1 Kurapika No
CRF-29 Note Note (body) agent/agentpreview/preview.go:131 Dot-prefix is the only content filter; tfstate, secrets.yaml are served once previews reach a browser R1 Kurapika No
CRF-30 Note Note (body) coderd/workspaceapps/appurl/preview.go:20 Same path in two workspaces gets the same ID; origins or cache keys must include workspace identity R1 Mafuuu No
CRF-31 Note Note (body) codersdk/workspacesdk/agentconn_test.go:445 Outdated-agent test uses a bare ServeMux; a future /api/v0 catch-all would break the 404 mapping silently R1 Melody No
CRF-32 Note Note (body) agent/agentpreview/preview.go:87 Name extraction cuts full URL path at first /{id}/; depends on mount prefix R1 Meruem No
CRF-33 Note Note (body) agent/agentpreview/preview.go:89 appurl.PreviewID(id) conversion bypasses format validation R1 Meruem No
CRF-34 Note Note (body) agent/agentpreview/preview_windows_test.go:37 Short-name test skips on volumes without 8.3 names; CI may never run it R1 Bisky No
CRF-35 Note Dropped by orchestrator (positive observation, asks for nothing) agent/agentpreview/preview.go:153 Scope is right for the stack R1 Luffy No
CRF-36 Note Dropped by orchestrator (positive observation, asks for nothing) codersdk/workspacesdk/agentconn.go:1521 Error text and commit subject are good R1 Leorio No
CRF-37 Note Dropped by orchestrator (meta summary of CRF-13, CRF-14, CRF-19) coderd/workspaceapps/appurl/preview.go:18 Comment quality pattern R1 Gon No
CRF-38 OOS Out of scope (body) agent/debuglogs.go:24 Comment copies server 20s WriteTimeout as a literal R1 Gon No
CRF-39 P4 Author contested; panel closed R4 (1/1 accept) agent/agentpreview/preview_test.go:250 TestPreviewSwappedElement catches a removed SameFile check only 3/20 runs; deterministic test already covers it R3 Netero Yes
CRF-40 P4 Author contested; panel closed R5 (2/2 accept) agent/agentpreview/preview.go:37 Unknown-ID 404 page claims the agent restarted for any unpublished ID, and uses "agent" for two different things R3 Netero, Leorio Yes
CRF-41 P4 Author fixed (e68cd8b) agent/agentpreview/preview.go:159 redirectToDirectory ./ prefix branch for colon names has no test R3 Netero Yes
CRF-42 P3 Author accepted R4 (operator chose the 20s server timeout for the experiment; raise if users hit it) agent/agentpreview/preview.go:150 Removing SetWriteDeadline leaves previews under the 20s server WriteTimeout; large assets truncated after 200 R3 Melody, Hisoka, Meruem, Mafuuu, Ryosuke, Killua, Komugi, Knov; Netero Note, Bisky Note Yes
CRF-43 OOS Out of scope (body) agent/agentfiles/files.go:222 read-file streams whole files under the same 20s WriteTimeout with no extension R3 Melody, Killua, Hisoka, Komugi, Meruem, Knov, Ryosuke No
CRF-44 P4 Author contested; panel closed R4 (1/1 accept) agent/agentpreview/preview.go:107 Commit body says ID derived from the cleaned path and symlinks refused; code hashes the parent-resolved path R3 Leorio Yes
CRF-45 Nit Author contested; panel closed R4 (1/1 accept) agent/agentpreview/api.go:22 Hook parameter prefix needs a definition in two comments; name it for what it holds R3 Gon Yes
CRF-46 P4 Author fixed (e68cd8b, narrowed the comment) agent/agentpreview/preview.go:68 Resolved parent swapped for a symlink is refused for file previews but followed for directory previews R3 Pariston Yes
CRF-47 P4 Author accepted R4; operator decision R7 (experimental release, no ticket) agent/agentpreview/preview.go:262 FIFO that reuses the swapped file's inode passes SameFile and is served as 500 seeker can't seek R3 Bisky Yes
CRF-48 P4 Author contested; panel closed R4 (1/1 accept) agent/agentpreview/preview.go:29 No test requests a name containing : on any platform R3 Bisky Yes
CRF-49 P4 Author contested; panel closed R4 (2/2 accept) agent/agentpreview/preview_internal_test.go:72 Junction test passes a hand-built mode; nothing shows Root.Lstat reports a real junction as ModeIrregular R3 Bisky, Hisoka Yes
CRF-50 Note Note (body) agent/agentpreview/preview.go:295 ModeIrregular refusal also refuses OneDrive placeholder files on Windows (inferred from Go source) R3 Hisoka No
CRF-51 P4 Author contested; panel closed R4 (1/1 accept) agent/agentpreview/preview.go:53 preview stores the published path three ways; only a comment keeps path, dir, file consistent R3 Meruem Yes
CRF-52 Note Dropped by orchestrator (fix verification, asks for nothing) agent/agentpreview/preview.go:214 CRF-3, CRF-4, CRF-5 fixes verified R3 Kurapika No
CRF-53 Note Dropped by orchestrator (positive observation, asks for nothing) agent/agentpreview/preview.go:272 openServed per-request cost is bounded R3 Killua No
CRF-54 Note Dropped by orchestrator (positive observation, asks for nothing) agent/agentpreview/preview_test.go:250 Other scheduling-dependent paths are pinned R3 Komugi No
CRF-55 Note Dropped by orchestrator (positive observation, asks for nothing) coderd/workspaceapps/appurl/preview.go:27 PreviewID checked at SDK boundary R3 Knov No
CRF-56 Note Dropped by orchestrator (fix verification, asks for nothing) agent/agentpreview/preview.go:94 CRF-20 to CRF-23 fixes verified R3 Leorio No
CRF-57 Nit Author fixed (c6e31cc) agent/agentpreview/preview_internal_test.go:72 Junction test input and comment use ModeDir ModeIrregular; Go 1.26 reports a junction as ModeIrregular only R4 Bisky
CRF-58 P3 Author accepted R6; operator decision R7 (experimental release, no ticket) agent/agentpreview/preview.go:140 Serve refusals (symlink, permission, errChanged, not regular) all return bare 404; cause logged only at Debug R5 Chopper Yes
CRF-59 Note Dropped by orchestrator (positive observation, asks for nothing) agent/agentpreview/preview_test.go:347 Publish refusals are asserted by exact Detail R5 Chopper No
CRF-60 P4 Author contested; panel closed R8 (1/1 accept) agent/agentpreview/preview.go:69 EvalSymlinks fallback in publish has no test; missing-parent publish not pinned R7 Mafuuu Yes
CRF-61 OOS Out of scope (body) coderd/httpapi/httpapi.go:273 Agent API decodes JSON without Content-Type check and no Host check; reachable via Coder Connect, so a website can send text/plain POSTs or DNS-rebind R7 Kurapika No
CRF-62 OOS Out of scope (body) agent/agentfiles/files.go:217 read-file serves .html with extension MIME and no nosniff/CSP on the agent API origin; preview route serves HTML on the same origin R7 Kurapika No
CRF-63 P4 Author fixed (c78dfe7) agent/agentpreview/preview.go:129 Redirect guards (name != "", no trailing slash) are untested; removing either keeps the suite green R8 Bisky Yes
CRF-64 Note Dropped by orchestrator (verification, asks for nothing) agent/agentpreview/preview_internal_test.go:52 Scheduling-dependent values pinned; race runs pass R8 Komugi No
CRF-65 P4 Author fixed (5e517bd) agent/agentpreview/preview_test.go:161 New test comment says the unguarded redirect "would loop"; it goes one level deeper and 404s R9 Gon P2 Yes
CRF-66 Nit Open agent/agentpreview/preview_test.go:160 Rewritten comment's first sentence restates the test's assertions R10 Gon P2 Yes

Law analysis

R3: effective +1190 at head d156c13. Verdict: Don't split. Enforcement: Advisory. One reviewable idea (agent publish/serve); no valid vertical slice; horizontal cuts produce caller-less types or move about 35 lines.

Contested and acknowledged

CRF-8 (P3, agent/agentpreview/preview.go:59) - index.html required at publish only

  • Finding: Publishing a directory requires index.html although serving does not, so a build output with report.html and assets cannot be previewed as a directory. Proposed dropping the publish-time check and keeping the 404 at /.
  • Author defense: PR description now calls it a publish rule; the check stays because the preview panel opens a directory preview at /.
  • Panel re-raised (R3, 1/2 accept): Luffy (original agent) re-raised: the feat(coderd): add the open_preview chat tool #32440 open_preview tool has url_path (example /docs/index.html, openpreview.go:83) and tells the model to open the directory to include assets, so the panel-at-/ premise does not cover the tool's own non-root path. Mafuuu (original agent) accepted for the description-honesty part it raised.

CRF-10 (P3 -> P4, codersdk/workspacesdk/agentconn.go:119) - open vs publish naming

  • Finding: SDK says "open", agent says "publish", and api.open in agentpreview is a different operation (per-request file open).
  • Author defense: OpenPreview matches the open_preview tool; renaming touches SDK, tool and UI for no behavior change.
  • Panel re-raised (R3, narrowed): Luffy (original agent) accepted. Gon (original agent) accepted the SDK half and re-raised the api.open half at P4: rename api.open to api.openFile, a change confined to preview.go.

CRF-11 (Nit, codersdk/workspacesdk/agentconn.go:1516) - File bool / json "file"

  • Finding: file reads as a file name next to path; sibling uses is_dir.
  • Author defense: Naming preference; rename would change the tool too; cheap to revisit while the experiment is hidden.
  • Panel re-raised (R3, 0/1 accept): Gon (original agent): the field crosses the agent-to-coderd wire, and agents and coderd run different versions, so after one release a rename requires coderd to accept both keys. "Cheap to revisit" stops being true when the agent ships.

CRF-12 (P4, coderd/workspaceapps/appurl/preview.go:22) - ID length literals

  • Finding: sum[:4] and {8} encode the length twice.
  • Author defense: Literals are a few lines apart; TestNewPreviewID pins the value.
  • Panel closure (R3, 1/1): Gon (original agent) verified TestNewPreviewID pins 092f225d and every agentpreview test decodes IDs through UnmarshalText, so a mismatch fails the suite before merge.

CRF-14 (Nit, coderd/workspaceapps/appurl/preview.go:18) - NewPreviewID doc duplication

  • Finding: The restart sentence repeats the OpenPreviewRequest doc.
  • Author defense: The sentence states the property NewPreviewID exists to provide.
  • Panel closure (R3, 1/1): Gon (original agent) accepted: the sentence explains why the ID is a path hash rather than random; the duplicate has no runtime effect.

CRF-17 (Nit, agent/agentpreview/preview.go:59) - variable first

  • Finding: first does not name the root file.
  • Author defense: Set just above its only uses.
  • Panel closure (R3, 1/1): Gon (original agent) verified it is set at preview.go:87 and used only within the next 13 lines.

CRF-19 (P4, codersdk/workspacesdk/agentconn.go:1504) - hidden-path doc

  • Finding: Doc says hidden paths are not served, but a published dot file is.
  • Author defense: Description now scopes the dot rule to below a published directory; the doc's "inside a preview" already excludes the published file itself.
  • Panel closure (R3, 2/2): Leorio (original agent) accepted: publishing a dot file by name serving it is intended and "inside a preview" does not claim otherwise. Gon (original agent) accepted the "request type publishes" wording part as having no caller consequence.

CRF-27 (P4, coderd/workspaceapps/appurl/preview.go:20) - NewPreviewID location

  • Finding: Agent path-derivation rule exported from a coderd URL package.
  • Author defense: Keeps ID rules (derivation, format check) in one file.
  • Panel closure (R3, 1/1): Ryosuke (original agent) accepted: the new doc ties the ID length to the hostname label, which appurl owns, so keeping derivation, length and format in one file is a reasonable trade.

Severity adjustments (R1)

  • CRF-11 (Gon P3 -> Nit). Keep-argument: the JSON key becomes a wire contract the UI PR reads, so renaming later costs a coordinated change. Downgrade reason: the stack is unmerged so the rename is cheap now; the code works and diverges only from the is_dir naming convention, which is the Nit definition.
  • CRF-12 (Gon P3 -> P4). Keep-argument: two linked literals can drift and break decoding of every response. Downgrade reason: every agentpreview test decodes OpenPreviewResponse, whose ID runs UnmarshalText, so a mismatch fails the suite immediately.
  • CRF-13 (Gon P3 -> P4). Keep-argument: a hand-built uppercase ID fails with no documented reason. Downgrade reason: the only producer is NewPreviewID; the gap affects readers, not behavior.
  • CRF-14 (Gon P2 -> Nit). Keep-argument: the fact lives in two places, which violates one-fact-one-place and can drift. Downgrade reason: a redundant doc sentence has no runtime consequence; P2 requires a behavior consequence.
  • CRF-3 merged Pariston P4 (publish-time symlink inconsistency) into Kurapika P3 at the higher severity.
  • CRF-4 tiebreaker: P3 (Meruem) over P4 (three reviewers). Meruem and Kurapika both name the exact swap and a one-line fix; the stated "no path element may be a symlink" guarantee is false.
  • CRF-7 tiebreaker: P3 (Mafuuu) over P4 (Hisoka, Meruem). The path becomes unpublishable until restart with a false error message.
  • CRF-9 tiebreaker: P3 (Luffy) over P4 (Leorio).
  • CRF-10 tiebreaker: P3 (Gon) over Nit (Luffy). Gon shows api.open names a different operation in the same package.

CRF-8 (R4 update) - index.html publish rule

  • Author defense (R4): Requiring index.html keeps every directory preview openable at /, where the panel and the tool open it by default; concedes a report.html-only directory needs an index.html added, and the tool description asks for one.
  • Panel closure (R4, 2/2): Luffy (original agent) accepted: the cost is one file write, mostly in model-written output directories, against the guarantee that no directory preview 404s at /; the author now states the cost. Mafuuu (original agent) accepted in R3 for the description part.

CRF-10 (R4 update) - api.open name

  • Author defense (R4): api.open is unexported with one caller; its signature shows it opens a served file.
  • Panel closure (R4, 2/2): Gon (original agent) accepted: the signature at preview.go:170 shows it returns a file for a published ID, so a wrong turn costs one read. Luffy accepted in R3.

CRF-11 - file JSON key

  • Finding: file reads as a file name; it is an agent-to-coderd wire key, so renaming after release needs dual-key decoding.
  • Author accepted (R4): file is the permanent name, documented as a bool; no rename planned. No ticket. Needs a human decision.

CRF-15 (R4 update) - ID length comment

CRF-39 - racing swap test

  • Finding: TestPreviewSwappedElement detects removed SameFile checks 3/20 runs; delete it.
  • Author defense (R4): The hook test catches the mutation every run; this test checks the end-to-end property under real renames and caught the earlier prefix-Lstat leak.
  • Panel closure (R4, 1/1): Netero (original agent) accepted: about 0.7s per run, real concurrent renames without the hook; the earlier-leak claim is unverified.

CRF-40 - unpublished page text

  • Finding: Page claims a restart for any unknown ID, and "Ask the agent" means the chat right after naming the workspace agent.
  • Author defense (R4): Preview URLs come only from publishing on the agent in the hostname, so an unknown ID means a restart; hand-edited IDs need no explanation.
  • Panel re-raised (R4, 1/2 accept): Netero (original agent) accepted the restart claim (nothing removes a publication; depends on feat: serve agent previews on strict preview hosts #32439 tying URLs to that agent). Leorio (original agent) accepted the restart half and re-raised the wording half: the defense does not address "Ask the agent"; fix is "Ask the chat to open it again."

CRF-42 - 20s WriteTimeout truncation

  • Finding: Removing SetWriteDeadline truncates large assets after a 200.
  • Author accepted (R4): "the operator chose to serve previews under the agent API server's 20s write timeout for this experiment"; raise the deadline if users hit it. Recorded as the operator's decision, no ticket.

CRF-44 - commit body

CRF-45 - prefix name

  • Author defense (R4): Both comments define it; unexported test hook with one caller.
  • Panel closure (R4, 1/1): Gon (original agent) accepted: both definitions are correct and cannot mislead a caller.

CRF-47 - FIFO with reused inode

  • Finding: Passes SameFile and is served as 500; O_NONBLOCK untested.
  • Author accepted (R4): Swap needs write access; O_NONBLOCK prevents the hang; nothing is read. No ticket. Needs a human decision.

CRF-48 - colon test

  • Author defense (R4): os.Root on Windows already refuses colon names, so the row cannot catch the mutation.
  • Panel closure (R4, 1/1): Bisky (original agent) verified rootCleanPath (os/root_windows.go:73) and filepathlite isLocal (path_windows.go:31) reject colons outside a drive letter.

CRF-49 - junction test

  • Author defense (R4): Dropping the ModeIrregular case fails this test; Go documents the junction mapping.
  • Panel closure (R4, 2/2): Bisky and Hisoka (original agents) accepted: Go pins the mapping in os/os_windows_test.go:141, and the pre-1.23 mapping (winsymlink=0) yields ModeSymlink, also refused. Bisky raised CRF-57 about the test's input mode.

CRF-51 - preview path stored three ways

  • Author defense (R4): publish is the only constructor.
  • Panel closure (R4, 1/1): Meruem (original agent) verified grep -n "preview{" returns only preview.go:79.

CRF-40 (R5 update) - "Ask the agent" wording

  • Author defense (R5): The page is shown inside Coder Agents, where the user talks to the agent in the chat, and the first sentence already says workspace agent for the other one.
  • Panel closure (R5, 2/2): Leorio (original agent) accepted: in Coder Agents "the agent" is the product's name for the chat assistant, and the first sentence qualifies the other process. Netero accepted the restart half in R4.

CRF-58 - serve refusals return bare 404

  • Finding: Symlinked, unreadable, non-regular and mid-rewrite files get the same bare 404 as a missing file, and the cause is logged only at Debug, which the agent does not persist unless an error is logged.
  • Author accepted (R6): Agrees both facts; keeps every 404 inside a live preview plain by design, reserves the explanatory page for an unknown ID, notes publish already names refusals of the published path, and the Debug level comes from the shared request logger. No ticket. Needs a human decision.

CRF-60 - EvalSymlinks fallback untested

  • Finding: Linux coverage shows the fallback never runs; removing it leaves tests green.
  • Author defense (R8): The Windows test-go-pg job takes this branch; TestPreviewInvalidPublications failed there until the fallback was added and fails again when reverted.
  • Panel closure (R8, 1/1): Mafuuu (original agent) accepted: the windows-2022 test-go-pg lane tests ./agent/... (ci.yaml:750) on RAM disks from setup-ramdisk-action (ci.yaml:602-604), where EvalSymlinks fails, and test-go-pg is in the required summary (ci.yaml:1300). Windows lane not run by the reviewer.

Severity adjustments (R9)

  • CRF-65 (Gon P2 -> P4). Keep-argument: the comment states a false reason for the guard, so a maintainer who believes it could drop the guard after convincing themselves the loop cannot happen, or misjudge what the guard protects. Downgrade reason: it is a test comment; the guard is pinned by the same test, so a wrong belief cannot remove it without a failing test, and nothing at runtime changes.

Severity adjustments (R10)

  • CRF-66 (Gon P2 -> Nit). Keep-argument: the R9 fix suggestion asked to replace both lines, so the fix is incomplete, and AGENTS.md requires comments not to restate code. Downgrade reason: the R9 consequence (a false loop claim) is fixed and verified accurate by Meruem and Netero; the remaining sentence is accurate, has no runtime or maintenance consequence, and Leorio (writing) found nothing. A restating comment is a convention issue, which is the Nit definition.

Round log

Round 1

Netero (CRF-1 P3, CRF-2 P4, no P0) then full panel: ging-go, kurapika, luffy, melody, ryosuke, killua (specialists); pariston, mafuuu (core); bisky, hisoka, gon, leorio (pool); meruem (wildcard). Multi-domain size target 9-12; 13 including wildcard. ging-go and killua: no findings. 12 P3, 10 P4, 5 Nit, 7 Note (body), 1 OOS, 3 dropped. Reviewed against ab38ca7..4e4f638.

Round 2 update

BLOCKED. Churn guard: 19 addressed (author claims fixed in d156c13; unverified by panel), 8 silent: CRF-8, CRF-10, CRF-11, CRF-12, CRF-14, CRF-17, CRF-19, CRF-27. No author replies on any thread; two bare /coder-agents-review requests from the author. No reviewers, Netero or Law ran. Next panel round must verify CRF-1 and CRF-25 fixes, which removed the 5 min SetWriteDeadline from handleServe (server WriteTimeout is 20s). Law not yet run; effective additions now 1190. Reviewed against f2b6084..d156c13.

Round 3

Restructure round (file added: preview_internal_test.go; openServed rewritten). Churn guard PROCEED: 8 contested. Netero (3 P4, advisory) and Law (Don't split, advisory). Full panel: dispute check-in with original agents luffy, mafuuu, gon, leorio, ryosuke (all reused via message_agent, none needed a new agent); specialists ging-go, kurapika, melody, killua; core pariston; pool bisky, hisoka, komugi, meruem; wildcard knov. ging-go: no findings. Disputes: CRF-12, CRF-14, CRF-17, CRF-19, CRF-27 closed; CRF-8, CRF-10 (narrowed to api.open, P4), CRF-11 re-raised. CRF-15 re-raised (fix incomplete). New: CRF-42 P3 (8 reviewers converged: write deadline removal truncates large assets), 9 P4/Nit, 1 Note (body), 1 OOS, 5 dropped. Verified fixed by reviewers: CRF-1, 2, 3, 4, 5, 6, 7, 9, 13, 16, 18, 20, 21, 22, 23, 24, 26. Reviewed against f2b6084..d156c13.

Round 4

Fix round (e68cd8b changes the publish comment and one test; no files added). Churn guard PROCEED: 2 addressed, 3 acknowledged, 10 contested. Netero (previous agent reused; first reply did not write the file, second did): no new findings. Law not re-run (+7 effective since R3). Panel: dispute check-in with original agents luffy, gon, leorio (R1 agents), bisky, hisoka, meruem (R3 agents); netero (R3 agent); new pariston (CRF-46 code touched), ging-go (Go files changed), wildcard mafuuu. Closed: CRF-8, 10, 15, 39, 44, 45, 48, 49, 51. Re-raised: CRF-40 (wording only). Verified fixed: CRF-41, CRF-46. Acknowledged without ticket: CRF-11, CRF-47 (need a human decision); CRF-42 recorded as operator decision. New: CRF-57 Nit. Reviewed against f2b6084..e68cd8b.

Round 5

Fix round (c6e31cc, squashed; only preview_internal_test.go changed since R4). Churn guard PROCEED: CRF-57 addressed, CRF-40 contested. Netero (new agent): no findings, CRF-57 verified by mutation. Panel: leorio (R1 agent reused, dispute), bisky (new, CRF-57 code), gon (new, comment line changed), ging-go (new), wildcard chopper. CRF-40 closed 2/2. CRF-57 verified fixed (Netero, Bisky, Gon, Leorio). New: CRF-58 P3 (Chopper; orchestrator verified loggermw.WriteLog logs <500 at Debug and cli/agent.go runs at Info with a flight recorder that flushes Debug only when an error is logged). Reviewed against f2b6084..c6e31cc.

Round 6

Fix round with no new commits (head c6e31cc unchanged). Churn guard PROCEED: CRF-58 acknowledged (no ticket). Netero (new agent): no findings. Panel (no contested findings, no changed files): pariston, mafuuu (core), chopper (raised CRF-58), wildcard knov: no findings. No open in-scope findings. Accepted without a ticket, needing a human decision: CRF-11, CRF-47, CRF-58. CRF-42 recorded as operator decision. Reviewed against f2b6084..c6e31cc.

Round 7

No new commits (c6e31cc). Author recorded operator decisions (experimental release, no ticket) for CRF-11, CRF-47, CRF-58 (churn guard missed them; orchestrator read them in comments-full.md). Churn guard PROCEED, 0 open. Netero (new agent; output file appeared only after a delay): no findings. Panel: hisoka, kurapika, meruem, wildcard mafuuu. New: CRF-60 P4 (Mafuuu). OOS: CRF-61, CRF-62 (Kurapika, agent API origin). Reviewed against f2b6084..c6e31cc.

Round 8

No new commits (c6e31cc). Churn guard PROCEED: CRF-60 contested. Netero (new): no findings. Panel: mafuuu (R7 agent reused, dispute), bisky, komugi, wildcard meruem. CRF-60 closed 1/1. New: CRF-63 P4 (Bisky, mutation-verified). Reviewed against f2b6084..c6e31cc.

Round 9

Fix round (c78dfe7 adds 10 lines to TestPreviewDirectoryRedirect). Churn guard PROCEED: CRF-63 addressed. Netero (new): no findings, CRF-63 verified. Panel: bisky (CRF-63 raiser), ging-go, gon (comment line added), wildcard meruem. CRF-63 verified by mutation (Bisky, Gon, Meruem, Netero). New: CRF-65 (Gon P2, downgraded to P4). Reviewed against f2b6084..c78dfe7.

Round 10

Fix round (5e517bd rewrites one test comment). Churn guard PROCEED: CRF-65 addressed. Netero (new): no findings. Panel: gon (CRF-65 raiser), leorio (comment wording), ging-go, wildcard meruem. CRF-65 verified accurate (Meruem, Netero). New: CRF-66 (Gon P2, downgraded to Nit). Reviewed against f2b6084..5e517bd.

About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Komugi flake/determinism
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds an agent route that publishes an .html file or a directory and serves it under /api/v0/previews/{id}/, plus AgentConn.OpenPreview. 12 P3, 10 P4 and 5 Nit findings are inline. The P3s that change behavior are in path containment (a symlinked published directory, the Lstat-then-open gap, Windows junctions), the missing trailing-slash redirect, and republishing a path whose type changed.

The PR description says the /debug/logs write deadline "is now one extendWriteDeadline middleware that wraps both routes". The diff does not contain that middleware; see the inline comment on preview.go:100.

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

  • agent/debuglogs.go:24: the comment writes the server's 20s WriteTimeout as a literal copy of agent/agent.go:1910, so changing the server timeout leaves the comment wrong.

Notes:

  • coderd/workspaceapps/appurl/preview.go:20: a preview ID is the truncated SHA-256 of a path, so anyone who knows the path can compute the ID. #32439 and #32522 must authorize preview access by workspace and user, not by possession of the ID.
  • coderd/workspaceapps/appurl/preview.go:20: the same path in two workspaces gets the same ID. An origin, cookie scope or cache key built from the ID must also include the workspace or agent.
  • agent/agentpreview/preview.go:131: the dot-prefix rule is the only content filter, so a directory preview serves files such as terraform.tfstate or secrets.yaml. Port 4 callers can already read these through /read-file; HTML in a browser-hosted preview (#32439) can fetch them from its own origin.
  • codersdk/workspacesdk/agentconn_test.go:445: TestAgentConnOpenPreviewOnOutdatedAgent serves a bare http.ServeMux. It matches today's old-agent 404 from the agentfiles router at /api/v0, but a future catch-all route under /api/v0 would break the ErrPreviewsUnsupported mapping without a test failing.
  • agent/agentpreview/preview.go:87: the name is cut from the full r.URL.Path at the first /{id}/, which assumes no mount-prefix segment equals an ID. url.PathUnescape(chi.URLParam(r, "*")) does not depend on the prefix.
  • agent/agentpreview/preview.go:89: appurl.PreviewID(id) converts an unvalidated URL segment, so the type does not guarantee the format UnmarshalText checks. It is only a map key here.
  • agent/agentpreview/preview_windows_test.go:37: TestPreviewRejectsShortNames skips on volumes without 8.3 short names. Whether the Windows CI job runs or skips it is unverified.

🤖 This review was automatically generated with Coder Agents.

Comment thread agent/agentpreview/preview.go Outdated
defer f.Close()

// Serving a large file can outlast the agent server's 20s WriteTimeout.
if err := http.NewResponseController(rw).SetWriteDeadline(time.Now().Add(5 * time.Minute)); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 [CRF-1] The PR description says the /debug/logs write deadline is now one extendWriteDeadline middleware wrapping both routes, but the diff adds no middleware and copies the deadline call into handleServe. (Netero)

grep -rn extendWriteDeadline agent returns nothing, and agent/debuglogs.go:63 still calls SetWriteDeadline itself with debugLogsWriteTimeout. Here the same 5-minute value is a second, unnamed literal, so changing one leaves the other. Add the middleware the description describes, or remove that paragraph and give the preview deadline a named constant.

🤖

Comment thread agent/agentpreview/preview.go Outdated
}

first, err := p.servedName("")
if err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-2] The error branch after p.servedName("") in publish cannot run. (Netero)

For a file preview servedName returns p.file, nil before any check, and for a directory "" becomes index.html, which passes every check. The coverage profile shows this block with count 0. Use the known name (p.file, or index.html when it is empty) instead of the call, or drop the error check.

🤖

Comment thread agent/agentpreview/preview.go Outdated
// os.Root follows symlinks that stay inside dir, which could alias a hidden
// or unpublished file.
func openServed(dir, name string) (*os.File, error) {
root, err := os.OpenRoot(dir)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 [CRF-3] openServed calls os.OpenRoot(p.dir) without checking that p.dir is not a symlink, so a published directory replaced by a symlink serves the target's whole tree. (Kurapika, Pariston)

Reproduced: publish parent/dist, replace dist with a symlink to parent/home, and GET /{id}/project/terraform.tfstate returns 200 with that file. Publishing a path that is already a symlinked directory also returns 200, while a symlinked .html file returns 400, so the description's "no path element may be a symlink" holds only for files. agentfiles.openRootDir (agent/agentfiles/files.go:151) already refuses this by comparing r.Stat(".") with os.Lstat(root) through os.SameFile; do the same here and add the swap case to TestPreviewRebuiltDirectory.

🤖

Comment thread agent/agentpreview/preview.go Outdated

// O_NONBLOCK keeps a FIFO that replaced the file after the Lstat above
// from blocking the open.
return root.OpenFile(name, os.O_RDONLY|syscall.O_NONBLOCK, 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 [CRF-4] The Lstat walk and root.OpenFile resolve name separately, and os.Root follows in-root symlinks, so a path element swapped for a symlink between the two calls opens a file the walk would refuse. (Meruem, Kurapika, Melody, Pariston)

For example, if assets becomes a symlink to .git after the walk, /{id}/assets/config serves .git/config. The O_NONBLOCK comment already assumes the file can change after the Lstat, but only the FIFO case is handled. After OpenFile, call f.Stat() and return errNotServed unless os.SameFile(info, opened) and opened.Mode().IsRegular(); that one check covers a swapped final element, a swapped intermediate directory, and the FIFO case.

🤖

Comment thread agent/agentpreview/preview.go Outdated
if err != nil {
return nil, err
}
if info.Mode()&fs.ModeSymlink != 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 [CRF-5] On Windows, a directory junction inside the published directory passes the ModeSymlink check, and os.Root follows it into a dot-prefixed or unpublished directory. (Hisoka)

Since Go 1.23, os/types_windows.go sets ModeSymlink only for IO_REPARSE_TAG_SYMLINK; a junction gets ModeDir|ModeIrregular, while os.Root follows any name-surrogate reparse point (isLink in os/root_windows.go:425). So a junction pub -> .git lets GET /{id}/pub/config serve .git/config, and junctions need no admin rights (mklink /J; pnpm creates them under node_modules). This is from reading the Go 1.26 source and was not run on Windows. Reject fs.ModeSymlink|fs.ModeIrregular on every element, and add a Windows test that creates a junction, since TestPreviewSymlinks skips Windows.

🤖

Comment thread agent/agentpreview/preview.go Outdated

func (api *API) publish(name string) (workspacesdk.OpenPreviewResponse, error) {
if !filepath.IsAbs(name) {
return workspacesdk.OpenPreviewResponse{}, xerrors.New("preview path must be absolute")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit [CRF-23] preview path must be absolute omits the value the caller sent. (Leorio)

Use xerrors.Errorf("preview path %q must be absolute", name), like the os.Stat errors that include the path.

🤖

Comment thread agent/agentpreview/preview_test.go Outdated
handler := agentpreview.NewAPI().Routes()
for _, name := range []string{
"page.html",
filepath.Join(root, "missing.html"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 [CRF-24] The relative-path row in TestPreviewInvalidPublications passes without the filepath.IsAbs guard. (Bisky)

Every row asserts only 400, and os.Stat("page.html") also returns 400 because the package directory has no page.html. Verified: with the IsAbs block deleted, go test ./agent/agentpreview/ -count=1 passes, and a regression would resolve relative paths against the agent's working directory. Assert the error Detail per row, for example preview path must be absolute here.

🤖

Comment thread agent/agentpreview/preview.go Outdated
defer f.Close()

// Serving a large file can outlast the agent server's 20s WriteTimeout.
if err := http.NewResponseController(rw).SetWriteDeadline(time.Now().Add(5 * time.Minute)); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 [CRF-25] No test checks that handleServe extends the write deadline, so deleting the call leaves the suite green. (Bisky)

httptest.ResponseRecorder does not implement SetWriteDeadline, and the integration test serves 16 bytes well inside the 20s WriteTimeout. Verified: replacing the call with error(nil) leaves ./agent/agentpreview and TestAgentOpenPreviewIntegration passing; a regression truncates any preview that takes more than 20s to send. agent/agentfiles/uploadchatfile_test.go:423 has a deadlineRecorder; use the same kind of recorder and assert a deadline at least 5 minutes out.

🤖


"github.com/coder/coder/v2/coderd/workspaceapps/appurl"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-26] No test pins the output of NewPreviewID, so "the same ID after the agent restarts" is checked only within one process. (Bisky)

TestPreviewIDsAcrossRestarts builds two API values in one process, so a per-process salt or changed digest would still pass while every agent upgrade changes published IDs. Assert that NewPreviewID("/home/coder/page.html") equals its current value.

🤖

// NewPreviewID returns the ID of the file preview of cleanedPath: the first
// 8 hex digits of its SHA-256. Publishing a path again, even after the agent
// restarts, yields the same ID.
func NewPreviewID(cleanedPath string) PreviewID {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-27] NewPreviewID is the agent's rule for deriving an ID from a filesystem path, but it is exported from a coderd URL package. (Ryosuke)

coderd needs only PreviewID and its format check; only agent/agentpreview and tests call NewPreviewID, including in the stacked PRs. Exporting it from appurl makes the derivation rule part of the shared API. Move NewPreviewID into agentpreview and keep PreviewID and UnmarshalText in appurl.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: keeping NewPreviewID beside PreviewID and its format check keeps the ID rules in one file; cheap to move later.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted: the doc now ties the ID length to the hostname label, which appurl owns, so keeping derivation, length and format check in one file is a reasonable trade.

🤖

@DanielleMaywood
DanielleMaywood force-pushed the open-preview/agent branch 5 times, most recently from 3b0e50f to d156c13 Compare November 25, 2026 22:25
@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 2. The new commits change 19 of the 27 round 1 findings, including the symlink, swap, junction, redirect, republish and unknown-ID findings. Eight findings have no code change and no reply, so the panel did not review this round. It will review once each of these has a fix or a reply on its thread: a fix in this PR, a linked issue, or a reason it should not change.

  • P3, agent/agentpreview/preview.go:59: publishing a directory still requires index.html, but serving does not require it. The description now calls this a publish rule; the thread has no reply on whether the check should stay.
  • P3, codersdk/workspacesdk/agentconn.go:119: the SDK still calls registration "open" (OpenPreview, "Could not open preview.") while the agent calls it "publish", and api.open is a different operation.
  • P4, codersdk/workspacesdk/agentconn.go:1504: the OpenPreviewRequest doc still says hidden paths are not served, but a published dot file is served.
  • P4, coderd/workspaceapps/appurl/preview.go:22: the ID length is still written as two unrelated literals, sum[:4] and {8}.
  • P4, coderd/workspaceapps/appurl/preview.go:20: NewPreviewID is still exported from the coderd URL package although only the agent derives IDs.
  • Nit, codersdk/workspacesdk/agentconn.go:1516: File bool / json:"file" is unchanged.
  • Nit, coderd/workspaceapps/appurl/preview.go:18: the NewPreviewID doc still repeats the republish behavior documented on OpenPreviewRequest.
  • Nit, agent/agentpreview/preview.go:59: the variable first is unchanged.

🤖 This review was automatically generated with Coder Agents.

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 3 reviews d156c13. New findings: 1 P3, 9 P4 and 1 Nit. Re-raised: 1 P3, 2 P4 and 1 Nit. The P3 is that removing the write deadline from handleServe lets the agent's 20s WriteTimeout cut off large preview assets after a 200.

Verified fixed: the description mismatch, the unreachable servedName branch, the symlinked published directory, the Lstat-then-open swap, Windows junctions, the trailing-slash redirect, republishing after a file/directory change, the unknown-ID 404, the UnmarshalText, preview and openServed docs, the four error texts, the relative-path test row and the NewPreviewID golden test. Five defenses were accepted (replies on those threads); index.html, the api.open name, the file JSON key and the ID-length comment are re-raised on their threads.

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

  • agent/agentfiles/files.go:222: read-file copies whole files under the same 20s WriteTimeout with no deadline extension, so a large read over a slow link is truncated after its 200.

Notes:

  • agent/agentpreview/preview.go:295: refusing ModeIrregular also refuses OneDrive placeholder files (IO_REPARSE_TAG_CLOUD_*), so a preview of a file in a OneDrive-synced folder on a Windows workspace returns "is not a regular file". Inferred from the Go source, not run on Windows.

🤖 This review was automatically generated with Coder Agents.

}
defer f.Close()

http.ServeContent(rw, r, served, time.Time{}, f)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 [CRF-42] With the 5-minute SetWriteDeadline removed, http.ServeContent runs under the agent server's 20s WriteTimeout (agent/agent.go:1910), so any preview file that takes longer than 20s to send arrives truncated after a 200 with the full Content-Length. (Melody, Hisoka, Meruem, Mafuuu, Ryosuke, Killua, Komugi, Knov)

The round 2 change removed the call that the deadline findings asked to name and test. Reproduced by several reviewers with the real handler behind an http.Server with a short WriteTimeout and a slow reader: for example status=200 content-length=67108864 read=5442688 err=unexpected EOF. A directory preview serves JS bundles, wasm, video and report traces over tailnet and the coderd proxy, so the browser runs a partial script with no error from the agent. Restore the extension with a named constant as agent/agentfiles/bundlefiles.go:63 and agent/debuglogs.go:63 do, and test it with a recorder like deadlineRecorder in agent/agentfiles/uploadchatfile_test.go:423.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: the operator chose to serve previews under the agent API server's 20s write timeout for this experiment, since previews are mostly small HTML pages; you are right that a slow download of a large asset is cut off after a 200, and the deadline can be raised if users hit it.


// Swapping a path element for a symlink while requests run must never serve
// the symlink's target.
func TestPreviewSwappedElement(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-39] TestPreviewSwappedElement fails only 3 of 20 runs when both os.SameFile checks are removed, so a regression shows up as a flake. (Netero)

With the same mutation, TestOpenServedRefusesSwappedElement fails on every run for both the parent and the last element, because the beforeOpen hook places the swap in the window deterministically. Delete the racing test and its 10000 requests and keep the hook-based one.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: removing the SameFile checks is already caught on every run by TestOpenServedRefusesSwappedElement, while this test checks the end-to-end property under real concurrent renames without the hook, and it is what caught the earlier prefix-Lstat design leaking, so its partial detection of that mutation costs nothing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted: the test exercises real concurrent renames without the hook at about 0.7s per run.

🤖

const unpublishedPage = `<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"><title>Preview unavailable</title></head>
<body><p>This preview is no longer available because the workspace agent restarted. Ask the agent to open it again.</p></body>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-40] The unpublished-preview page says "the workspace agent restarted" for every ID missing from api.previews, and then tells the user to "Ask the agent", where "agent" now means the chat assistant. (Netero, Leorio)

TestPreviewFile requests /ffffffff/, which was never published, and gets this page; so does an ID from another workspace or a mistyped ID. State only what the agent knows, with one meaning of "agent", for example: This preview is not published on this workspace. Previews are forgotten when the workspace agent restarts. Open the file from the chat again to publish it.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: preview URLs are only produced by publishing on the agent named in the hostname, so an unknown ID in practice means that agent restarted, and a hand-edited ID is not a case the page needs to explain.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-40] The restart claim is accepted: nothing removes a publication, so an unknown ID on the agent that published it means a restart. The second sentence is still open: Ask the agent to open it again. follows a sentence that names the workspace agent, which takes no requests from a person, so the user has to guess that the chat is meant. Change it to Ask the chat to open it again. (Leorio)

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: the page is shown inside Coder Agents, where the user talks to the agent in the chat, and the first sentence already says workspace agent for the other one, so we are keeping this wording.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted: inside Coder Agents "the agent" is the chat assistant the user is talking to, and the first sentence already qualifies the workspace agent.

🤖

// the preview host's, and keeps the request's escaping of the last segment.
func redirectToDirectory(rw http.ResponseWriter, r *http.Request) {
location := path.Base(r.URL.EscapedPath()) + "/"
if strings.Contains(location, ":") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-41] The ./ prefix branch in redirectToDirectory, for a directory name containing a colon, has no test. (Netero)

The coverage profile shows preview.go:159.37,162.3 with count 0. Without the prefix a browser reads a:b/ as scheme a:, so a regression breaks relative links under that directory. Add a /a:b row expecting ./a:b/ to TestPreviewDirectoryRedirect.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e68cd8b: TestPreviewDirectoryRedirect now covers a name containing a colon and fails when the colon branch is disabled.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in e68cd8b865: removing the ./ prefix fails the new /a:b row.

🤖

}
_ = f.Close()

id := appurl.NewPreviewID(resolved)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-44] The commit body says the ID is "derived from the cleaned path" and that each request "refuses symlinks", but publish hashes the path after filepath.EvalSymlinks on its parent and follows a symlinked parent. (Leorio)

On macOS /tmp/x/index.html gets the ID of /private/tmp/x/index.html, so a reader of git log finds the opposite of the behavior. The PR description already states it correctly; bring the commit body in line, for example "an ID derived from the path after resolving symlinks in its parent directories ... refuses symlinks below it".

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: coder/coder squash-merges with the PR description as the commit message, and the description already says the ID hashes the path after resolving parent symlinks, so this commit body never lands on main.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted: git log -1 f2b60844c5 shows the squash commit body is the PR description, and this description is correct.

🤖

// symlinked directory from its real location, where a later swap for a
// symlink is still refused. A parent that cannot be resolved, as on some
// Windows volumes, is used as given, so a missing path fails at os.Stat.
parent, err := filepath.EvalSymlinks(filepath.Dir(cleaned))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-46] Replacing the resolved parent with a symlink after publishing is refused for a file preview but followed for a directory preview, although the comment says a later swap "is still refused". (Pariston)

For a file preview p.dir is the resolved parent, so openRoot checks it; for a directory preview p.dir is parent plus base, so only the base is checked and os.OpenRoot follows the swapped parent. Reproduced: publish actual/page.html and actual/site, move actual away and symlink actual -> other; the file preview returns 404, the directory preview returns 200 "other site". Open the root at the resolved parent for both kinds and walk the directory's base as the first element, or narrow the comment to the published directory itself.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e68cd8b: the publish comment now says a swapped parent is refused for file previews only.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in e68cd8b865: the comment now claims only the two cases openRoot and lstatElement refuse.

🤖

return nil, err
}
opened, err := f.Stat()
if err == nil && !os.SameFile(info, opened) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-47] A regular file replaced by a FIFO between its Lstat and its open is answered with 500 seeker can't seek when the FIFO reuses the file's inode, because os.SameFile then passes. (Bisky)

Reproduced with an internal test whose beforeOpen hook removes data.txt and calls unix.Mkfifo: same inode on 3 of 3 runs, response 500. TestPreviewRejectsFIFOs never reaches the open, so replacing syscall.O_NONBLOCK with 0 leaves the suite green. Add || !opened.Mode().IsRegular() to the check after f.Stat() and keep that test, bounded by testutil.WaitShort, under a unix build tag.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: you are right that a FIFO swapped in with a reused inode gets a 500 instead of a 404 and that no test pins O_NONBLOCK, but the swap needs someone who can already write the published directory, O_NONBLOCK keeps the open from hanging, and nothing is read from the FIFO, so we are not adding a platform-specific test file to change the status code.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed for the experimental release (operator decision, no ticket): a FIFO swapped in with a reused inode gets a 500 instead of a 404; nothing is read from it and the swap needs write access to the published directory.

// another file on Windows: a backslash is a path separator, a colon names an
// alternate data stream, and a tilde appears in short names such as HIDDEN~1
// for .hidden.
const windowsUnsafeNameChars = `\:~`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-48] No test on any platform requests a name containing :, so removing it from windowsUnsafeNameChars leaves every test green. (Bisky)

TestPreviewDirectory has Windows rows for ~ and \ but none for the alternate data stream character. Add a Windows row that writes index.html:secret and asserts 404 for /{id}/index.html:secret.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: on Windows os.Root already refuses any name containing a colon (filepathlite.IsLocal in rootCleanPath), so the proposed row would pass with or without : in windowsUnsafeNameChars and could not catch the mutation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted: rootCleanPath (os/root_windows.go:73) rejects a colon outside a drive letter through filepathlite.IsLocal, so the row could not detect the mutation.

🤖


// Go reports a Windows junction as a directory with ModeIrregular, not
// ModeSymlink, and os.Root follows it.
func TestCheckElementRefusesJunctions(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-49] TestCheckElementRefusesJunctions passes a hand-built fs.ModeDir|fs.ModeIrregular to checkElement, so nothing shows that Root.Lstat reports a real junction that way. (Bisky, Hisoka)

If a Go release changes how Lstat maps mount points, this test stays green while a junction into .git is served. Creating a junction needs no admin rights: in preview_windows_test.go, run cmd /c mklink /J <root>\assets <root>\.git, publish the root, and assert 404 for /{id}/assets/config.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: dropping the ModeIrregular case fails this test, and Go documents that junctions map to ModeIrregular in os/types_windows.go, so a real mklink /J test would guard Go rather than this code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted: Go pins the mapping in os/os_windows_test.go:141, and the pre-1.23 mapping (winsymlink=0) reports ModeSymlink, which checkElement also refuses. The test's input mode is a separate Nit on this round.

🤖

// preview is a published path. A directory preview has file == "" and dir
// set to the directory; a file preview has dir set to the file's parent.
type preview struct {
path string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-51] preview stores the published path three ways (path, dir, file), and only the struct comment keeps them consistent. (Meruem)

path always equals dir for a directory and filepath.Join(dir, file) for a file. A later preview built with only dir and file leaves existing.path empty, and every republish of that ID returns 409 "already used by ". Replace the field with a path() method derived from dir and file.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: publish is the only place a preview is built and it sets path from the same resolved value as dir and file, so the 409 described needs a second constructor that does not exist.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted: publish at preview.go:79 is the only place a preview is built.

🤖

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 4 reviews e68cd8b. Nine of the ten contested findings are closed after re-checking against the code (replies on each thread), and the colon-redirect test and the narrowed publish comment are verified. One P4 remains open, the wording half of the unpublished-page finding, and there is one new Nit on the junction test's input.

The file JSON key and the FIFO 500 were accepted on their threads without an issue; this needs a human decision: accept each gap or file an issue. The 20s write timeout is recorded as the operator's choice for the experiment.

🤖 This review was automatically generated with Coder Agents.


// Go reports a Windows junction as a directory with ModeIrregular, not
// ModeSymlink, and os.Root follows it.
func TestCheckElementRefusesJunctions(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit [CRF-57] TestCheckElementRefusesJunctions passes fs.ModeDir|fs.ModeIrregular, and its comment says Go reports a junction "as a directory with ModeIrregular", but Go 1.26 does not set ModeDir for a junction. (Bisky)

In $GOROOT/src/os/types_windows.go, mode() sets ModeDir only when !fs.isReparseTagNameSurrogate(), and IO_REPARSE_TAG_MOUNT_POINT is a name surrogate, so a junction gets only ModeIrregular. The test still fails if the ModeIrregular arm is removed, but its input describes a mode Lstat never returns. Pass fs.ModeIrregular and say "as ModeIrregular, not ModeSymlink or ModeDir" in the comment.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c6e31cc: the test input is now fs.ModeIrregular and the comment says Go reports a Windows junction as ModeIrregular.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in c6e31cc913: the test passes fs.ModeIrregular alone, and deleting the ModeIrregular case in checkElement fails it.

🤖

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 5 reviews c6e31cc. The junction test fix is verified, and the "Ask the agent" wording is accepted (reply on its thread). One new P3 is inline: serve refusals other than an unpublished ID all return a bare 404, and their cause is logged only at Debug.

The file JSON key and the FIFO 500 from round 4 still have no issue and no recorded human acceptance; this needs a human decision.

🤖 This review was automatically generated with Coder Agents.

if errors.Is(err, errUnpublished) {
rw.Header().Set("Content-Type", "text/html; charset=utf-8")
rw.WriteHeader(http.StatusNotFound)
if _, err := io.WriteString(rw, unpublishedPage); err != nil && requestLogger != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 [CRF-58] handleServe answers a symlinked, unreadable, non-regular or mid-rewrite file with the same 404 page not found as a missing one, and the cause is logged only at Debug. (Chopper)

Reproduced: a published directory with locked.css (mode 000), link.css -> real.css, no missing.css, and .env returns the identical 404 body for all four, so a user whose page loads without its stylesheet cannot tell a refused file from a missing one. loggermw.WriteLog (coderd/httpmw/loggermw/logger.go:208) logs status < 500 at Debug, and cli/agent.go runs the agent at Info with a flight recorder that writes Debug lines only after an error is logged, which a 404 never does. Keep the bare 404 for fs.ErrNotExist and errNameNotServed, and write the refusal text (errSymlink, errNotRegular, errChanged, permission denied) in the 404 body, or log those cases at Info or Warn.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: you are right that a refused file and a missing one look identical from the browser, and that the agent logs the cause only at Debug. We chose to keep every 404 inside a live preview plain and give the explanatory page only to an unknown preview ID; publishing already names the reason when the published path itself is refused, and the Debug level is the agent's shared request logger, not something this preview route sets.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed for the experimental release (operator decision, no ticket): only an unknown preview ID gets the explanatory page, and other 404s inside a live preview stay plain.

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 6 reviews c6e31cc, unchanged since round 5. The panel found nothing new, and no finding remains open in the code.

Three gaps were accepted on their threads without an issue; this needs a human decision, accepting each gap or filing an issue:

  • codersdk/workspacesdk/agentconn.go:1516: file stays the permanent JSON key of an agent-to-coderd response.
  • agent/agentpreview/preview.go:262: a FIFO that reuses a swapped file's inode is answered with 500 instead of 404.
  • agent/agentpreview/preview.go:140: refused files (symlink, unreadable, non-regular, mid-rewrite) get the same bare 404 as missing ones, and the cause is logged only at Debug, so it does not reach coder-agent.log at the default level.

The 20s write timeout on preview responses is recorded as the operator's choice for the experiment.

🤖 This review was automatically generated with Coder Agents.

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 7 reviews c6e31cc, unchanged since round 5. One new P4 is inline. The operator decisions recorded on the file key, FIFO 500 and plain-404 threads are noted; no human decision remains open from earlier rounds.

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

  • coderd/httpapi/httpapi.go:273: the agent API decodes JSON without checking Content-Type and does not check the Host header. A user on Coder Connect can reach http://<agent>.<workspace>.<owner>.coder:4/, so a page on any website could send a CORS-simple text/plain POST to /api/v0/processes or /api/v0/write-file, or use DNS rebinding to read responses. Browser reachability of port 4 over Coder Connect and Chrome Private Network Access behavior for tailnet addresses are unverified.
  • agent/agentfiles/files.go:217: read-file serves an .html file with its extension's MIME type and no nosniff or CSP, so its scripts run on the same origin as the whole agent API. The preview route in this PR serves HTML on that same origin, which adds a second URL for that capability.

🤖 This review was automatically generated with Coder Agents.

// a file preview's parent is refused. A parent that cannot be resolved, as on
// some Windows volumes, is used as given, so a missing path fails at os.Stat.
parent, err := filepath.EvalSymlinks(filepath.Dir(cleaned))
if err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-60] The filepath.EvalSymlinks fallback in publish has no test, so the behavior its comment states ("a parent that cannot be resolved ... is used as given, so a missing path fails at os.Stat") is not pinned. (Mafuuu)

The coverage profile shows block preview.go:69.16,71.3 with count 0, because no test publishes a path whose parent does not exist. If the fallback is removed or changed to return the error, every test still passes, while on the Windows volumes the comment names every publish would fail with the EvalSymlinks error. Add a TestPreviewInvalidPublications row for filepath.Join(root, "missing", "page.html") and assert that the Detail is the os.Stat error for the full path.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: the Windows test-go-pg job covers this branch. TestPreviewInvalidPublications failed there with "The system cannot find the path specified" until the fallback was added, because EvalSymlinks fails on the runner's temp volume; reverting the fallback fails it again. Linux never takes this branch, so the Linux coverage profile cannot show it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted: the required windows-2022 test-go-pg lane runs ./agent/... on RAM disks (ci.yaml:602-604, ci.yaml:750), where EvalSymlinks fails, so removing the fallback fails a required job.

🤖

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 8 reviews c6e31cc, unchanged since round 5. The EvalSymlinks fallback defense is accepted (reply on its thread). One new P4 is inline.

🤖 This review was automatically generated with Coder Agents.


f, served, err := api.open(appurl.PreviewID(id), name)
if err != nil {
if errors.Is(err, errIsDirectory) && name != "" && !strings.HasSuffix(name, "/") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-63] No test covers the name != "" and !strings.HasSuffix(name, "/") guards on the redirect, and deleting either one leaves go test ./agent/agentpreview/ -count=1 passing. (Bisky)

The guards decide between a 404 and a 301 when index.html was appended. With the suffix guard removed, a directory containing trap/index.html/x requested as /{id}/trap/ gets 301 Location: trap/, which resolves to /{id}/trap/trap/ and then 404s. Add a TestPreviewDirectoryRedirect case for that layout asserting 404 with no Location, or replace both conditions with served == name, which the same case covers.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c78dfe7: TestPreviewDirectoryRedirect now publishes, then replaces the root index.html and trap/index.html with directories, and asserts / and /trap/ get a 404 with no Location. Removing either the name != "" guard or the trailing-slash guard fails it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in c78dfe7350: removing name != "" fails the test on /, and removing the trailing-slash guard fails it on /trap/.

🤖

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 9 reviews c78dfe7. The redirect-guard test is verified: removing either guard fails it. One P4 is inline on the new test comment.

🤖 This review was automatically generated with Coder Agents.

Comment thread agent/agentpreview/preview_test.go Outdated
}

// A request that already ends in a slash, or names the root, gets no
// redirect when its index.html is a directory, which would loop.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-65] The new comment says the unguarded redirect "would loop", but without the guards the redirect points one level deeper and that request returns 404. (Gon)

redirectToDirectory builds path.Base(r.URL.EscapedPath()) + "/", and path.Base drops the trailing slash, so the Location repeats the last segment. With both guards removed: path=/trap/ code=301 location="trap/", which resolves to /{id}/trap/trap/ and returns 404. Replace both lines with // Without the guards, the redirect repeats the last segment: /{id}/trap/ goes to /{id}/trap/trap/.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5e517bd: you are right, the redirect points one level deeper and that request gets a 404. The comment now says the request gets a 404 because a redirect would point at a path that does not exist.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit [CRF-66] The second sentence is accurate now. The first sentence restates what the loop below already shows (index.html as a directory at / and /trap/, then 404 and no Location), so the comment can be just // A redirect here would point one level deeper, at a path that does not exist. (Gon)

🤖

The workspace agent publishes an absolute .html file, or a directory
containing index.html, and serves it from its HTTP API under
/api/v0/previews/{id}/ with an ID derived from the cleaned path. Each
request reopens the directory through os.Root and refuses symlinks,
dotfiles and non-regular files. AgentConn.OpenPreview exposes publishing
in the workspace SDK.

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

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 10 reviews 5e517bd. The rewritten redirect comment is accurate. One Nit remains on the same comment (reply on its thread); nothing else is open.

🤖 This review was automatically generated with Coder Agents.

This branch was previously deployed

1 inactive (outdated) deployment
main — 525e2031 Deployed Nov 20, 2026 by DanielleMaywood via cla #261387
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant