Skip to content

feat: add chat previews endpoint - #31285

Closed
DanielleMaywood wants to merge 1 commit into
feat/agents-open-preview-toolfrom
feat/agents-open-preview-catalog
Closed

DanielleMaywood wants to merge 1 commit into
feat/agents-open-preview-toolfrom
feat/agents-open-preview-catalog

Conversation

@DanielleMaywood

@DanielleMaywood DanielleMaywood commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Adds GET /api/experimental/chats/{chat}/previews, which lists the previews open_preview opened in the chat's current workspace: one entry per agent, port, and URL path, or per agent and path, ordered by first open, with the newest result supplying the title and preview ID. Results come from the chat's own user-visible tool messages, so access follows chat read permission.

Decision log
  • Derived from tool results, not a new table. Model-only and deleted messages are excluded. Error results have no workspace_id, so the workspace check skips them.
  • Chat-scoped. An earlier iteration aggregated every chat bound to the workspace, which required per-row authorization and cross-chat ordering; the UI only needs the current chat's previews.
  • An endpoint instead of client-side derivation, because the chat page loads messages 50 at a time and older previews would otherwise be missing.
  • Results from a workspace the chat is no longer bound to are skipped, since their URLs would point at the wrong workspace.
  • File previews are keyed by path, not preview ID. The agent gives a path a new ID after it restarts, so restoring it replaces the stale entry with the working ID instead of listing it twice.
  • url_path is part of the entry key, so the same port at another path is a separate entry. A url_path that IsPreviewURLPath rejects skips the row.
  • Rows are revalidated (exactly one of a 1000-65535 port or a preview ID, and a valid agent name) because clients build hostnames from them. Rows that fail are skipped instead of failing the request, and a JSONB containment check skips other messages before their parts are expanded.

Stack (proof of concept for the embedded previews RFC, review bottom-up):

  1. feat: serve published file previews from the workspace agent over tailnet #31282 Agent file previews over tailnet
  2. feat: route preview app hostnames to agent previews #31283 Preview app hostname routing
  3. feat(coderd): add open_preview chat tool #31284 open_preview chat tool
  4. feat: add chat previews endpoint #31285 Chat previews endpoint ← this PR
  5. feat(site): add a Preview tab for open_preview #31286 Preview tab UI
  6. docs(docs/coder-agents): document embedded previews #31287 Docs
  7. feat: open coder_app tabs from open_preview #31484 Open coder_app tabs

🤖 This PR was written by Coder Agents on behalf of @DanielleMaywood.

@ibetitsmike ibetitsmike left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Adversarial security review — #31285 (chat previews endpoint)

Part of the stack review; the stack-level roll-up (findings S1/S2, method, verified negatives) is on #31282. Line numbers at stack head 678b80103.

Contributes to S2 (P2, unanimous; validated) — catalog is gated on chat read, which site owners (and org admins) hold for other users' chats

GetChatOpenPreviewResults authorizes via GetChatByID (coderd/database/dbauthz/dbauthz.go:3739), consistent with GetChatMessagesByChatID — so this endpoint itself leaks nothing beyond /messages. The problem is composition: a site owner (chat read and application_connect by default) who opens a victim's chat gets this catalog and the UI (#31286) iframes preview--<id>--agent--ws--<victim> in the admin's browser (validated end-to-end: site owner → 200 here, then 200 with the victim's file body through the proxy). Org admins get 200 here (titles + absolute workspace paths) but are denied at the proxy.

Suggested defence-in-depth here: return [] (or 403) when httpmw.APIKey(r).UserID != chat.OwnerID — previews are only ever renderable by the owner anyway, so non-owners gain nothing from the catalog. The primary fix (viewer-vs-owner check before building/iframing the URL) belongs in #31286.

Unverified (single reviewer) — P3

  • Unbounded jsonb_array_elements over every tool message of the chat (coderd/database/queries/chats.sql:539): no LIMIT, no pre-filter, no index on the predicate; re-run on every refetch/invalidation. Reviewer ran EXPLAIN ANALYZE and confirmed a full expansion. Suggest a containment pre-filter (cm.content @> '[{"type":"tool-result","tool_name":"open_preview"}]') + partial GIN index, and/or a limit on rows scanned.
  • A tool-result part without a result key makes the whole endpoint 500 — (part->'result')::jsonb is NULL → rows.Scan into json.RawMessage fails (reviewer verified with a DB test). Add AND part ? 'result'.
  • No server-side re-validation of stored preview_id / port / agent_name in chatPreviewsFromResults (coderd/exp_chats_previews.go:54-66). Every reviewer agreed no poisoning path exists today (see below), but the UI interpolates these straight into a hostname (site/src/utils/portForward.ts:63; node PoC: preview_id="evil.com/#" → host preview--evil.com). Cheap hardening: appurl.IsPreviewID, port range, and agent-name regex before returning; drop rows that fail.

nit

  • On the authz race (chat deleted between ExtractChatParam and the query) the handler returns 500 with err.Error() in Detail, while the sibling handlers map to 404.
  • Org admins / chat-ACL readers receive a catalog whose every iframe the owner-only proxy will reject — the response is misleading for them (folds into the S2 fix above).

Verified negatives (no action)

  • Catalog poisoning is unreachable: user message create/edit accept only ChatInputPart (text/file); postChatToolResults takes the tool name from the pending assistant call; a dynamic tool named open_preview is dropped at turn build because it collides with the always-present built-in; MCP tool names are always <server>__<tool> and carry mcp_server_config_id; hooks emit text/notice/error parts only; edits soft-delete the suffix. The SQL's mcp_server_config_id IS NULL, is_error, provider_executed and visibility filters are correct for the shapes chatd actually writes.
  • Route sits under apiKeyMiddleware + ExtractChatParam; GetChatPreviews client path matches; dbauthz test asserts ActionRead on the chat.

@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-catalog branch from b457acc to 64a8953 Compare October 28, 2026 10:39
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-catalog branch 2 times, most recently from afa3dfb to c89ee3d Compare October 28, 2026 13:06
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-catalog branch from c89ee3d to 86b0abb Compare October 28, 2026 13:20

@DanielleMaywood DanielleMaywood left a 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.

This review was performed by ai-review, an automated review bot.

1 inline finding.

Coverage
Coverage: 8 of 16 files reviewed, 4 unsupported, 4 generated; 22 rules.
Candidates: 485 found, 480 outside changed lines, 0 already discussed, 5 evaluated.
Findings: 1 (1 sites, 0 pre-existing sites), 0 over budget, 0 failed.
Model: deepseek/deepseek-v4.1-flash; 4 questions, 4 answered, 0 abstained, 0 cached; 0 uncalibrated findings held back; 4426 input and 1210 output tokens.

Comment thread coderd/exp_chats_previews_test.go Resolved
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-catalog branch from 86b0abb to 1b757b3 Compare October 28, 2026 16:42
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-catalog branch from 1b757b3 to b6b9095 Compare October 28, 2026 16:43
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-catalog branch from b6b9095 to 532b183 Compare October 29, 2026 09:57
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-catalog branch from 532b183 to 16c47ac Compare October 29, 2026 14:07
@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

@codex review

🤖 Posted by Coder Agents on behalf of @DanielleMaywood.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T14:28:32.209932Z 369e23c Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 16c47ac1bb

ℹ️ 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".

@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-catalog branch from d80e417 to 369e23c Compare November 2, 2026 14:25
@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

@codex review

🤖 Posted by Coder Agents on behalf of @DanielleMaywood.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 369e23cbb5

ℹ️ 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".

@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-catalog branch 2 times, most recently from c1d0055 to be58ca7 Compare November 3, 2026 12:21

@DanielleMaywood DanielleMaywood left a 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.

This review was performed by ai-review, an automated review bot.

1 inline finding.

Coverage
Coverage: 8 of 16 files reviewed, 4 unsupported, 4 generated; 53 rules.
Candidates: 4480 found, 4457 outside changed lines, 2 already discussed, 21 evaluated.
Findings: 1 (1 sites, 0 pre-existing sites), 0 over budget, 0 failed.
Model: deepseek/deepseek-v4.1-flash; 21 questions, 19 answered, 2 abstained (unsure 1, truncated 1), 5 cached; 0 uncalibrated findings held back; 21712 input and 19040 output tokens.

Comment thread coderd/exp_chats_previews.go Resolved
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-catalog branch from be58ca7 to d598e1d Compare November 3, 2026 14:07
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-catalog branch 4 times, most recently from 3dab4f9 to 795455b Compare November 4, 2026 10:25
@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review

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

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-11-06 09:38 UTC by @DanielleMaywood
Spend: $46.38 / $100.00

Review history
  • R1 (2026-11-04): 13 reviewers, 2 Nit, 2 P2, 4 P3, 7 P4, COMMENT. Review
  • R2 (2026-11-05): 13 reviewers, 2 Nit, 2 P2, 8 P3, 9 P4, COMMENT. Review
  • R3 (2026-11-05): 10 reviewers, 2 Nit, 2 P2, 8 P3, 12 P4, COMMENT. Review
  • R4 (2026-11-06): 5 reviewers, 2 Nit, 2 P2, 8 P3, 12 P4, COMMENT. Review
  • R5 (2026-11-06): 5 reviewers, 2 Nit, 2 P2, 8 P3, 12 P4, APPROVE. Review

deep-review v0.13.0 | Round 5 | b6ea144..4e3a177

Last posted: Round 5, 24 findings (2 P2, 8 P3, 12 P4, 2 Nit), APPROVE. Review

Finding inventory

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P3 Author fixed (96c31cb, c975cf9); verified R3 exp_chats_previews_test.go:79 No test fails if role/type/tool_name query filters are removed R1 Netero Yes
CRF-2 P3 Author contested; panel closed R2 (2/2 accept) exp_chats_previews.go:71 Endpoint duplicates open_preview acceptance rules instead of a shared validator R1 Netero P3, Gon P3 Yes
CRF-3 P4 Author contested; panel closed R2 (1/1 accept) exp_chats_previews_test.go:74 Tool error results not covered by test R1 Netero Yes
CRF-4 P4 Author fixed (PR description); verified R2 exp_chats_previews.go:1 PR description claims an offlinedocs Makefile fix the diff does not contain R1 Netero Yes
CRF-5 Note Note (body); R2 18 CI jobs fail, logs unreadable (CI) Flake Check and Storybook CI failures unexplained R1 Netero No
CRF-6 OOS Out of scope (body) Makefile:1500 coderd/apidoc/.gen lists site/node_modules/.installed twice R1 Netero No
CRF-7 P2 Author fixed (96c31cb); verified R2 exp_chats_previews.go:88 File previews keyed by preview_id, which the agent reuses after restart R1 Pariston P2, Mafuuu P2, Hisoka P2, Meruem P2, Melody P3 Yes
CRF-8 P2 Author fixed (96c31cb); verified R2; cross-kind part contested, panel closed R2 (3/3 accept) exp_chats_previews.go:73 Exactly-one check tests validity not presence; invalid preview_id/port and cross-kind url_path/path returned R1 Gon P2, Kurapika P4, Ryosuke P4, Bisky Note Yes
CRF-9 P3 Author fixed (96c31cb); verified R2 chats.sql:556 Result read in NUL-encoded storage form without decoding R1 Knuckle P3, Hisoka P4 Yes
CRF-10 P3 Author fixed (96c31cb); verified R2 exp_chats_previews.go:50 Doc comment omits oldest-first input precondition R1 Gon P2 Yes
CRF-11 P4 Author contested; panel closed R2 (1/1 accept) exp_chats_previews.go:33 Previews listed when deployment has no app hostname R1 Ryosuke Yes
CRF-12 P4 Author contested; panel closed R2 (1/1 accept) exp_chats_previews_test.go:110 Unbound-chat assertion passes without the WorkspaceID guard R1 Bisky Yes
CRF-13 P4 Author contested; panel closed R2 (1/1 accept) codersdk/chats.go:1174 REST reference lacks exactly-one-of port/preview_id description R1 Leorio Yes
CRF-14 P3 Author fixed (c975cf9); verified R3 exp_chats_previews.go:26 Endpoint description does not state key, order, or title source R1 Leorio P4, Mafuuu P3 (R2) Yes
CRF-15 P4 Author contested; panel closed R2 (1/1 accept) codersdk/chats.go:1182 ChatPreview.Path name reads as URL path next to URLPath R1 Gon Yes
CRF-16 Nit Author contested; panel closed R2 (1/1 accept) exp_chats_previews.go:55 Key type named endpoint collides with HTTP endpoint meaning R1 Gon Yes
CRF-17 Nit Author fixed (96c31cb); verified R2 exp_chats_previews_test.go:67 Hand-written loop instead of maps.Copy R1 Ging-Go Yes
CRF-18 Note Note (body) chats.sql:563 Unindexed content @> scan detoasts every tool message per request R1 Knuckle, Killua No
CRF-19 OOS Out of scope (body); root cause fixed upstream in #31282 (cryptorand IDs) agent/agentpreview/preview.go:110 Per-process preview ID counter reuses IDs across agent restarts R1 Melody, Pariston, Mafuuu, Hisoka, Meruem No
CRF-20 OOS Out of scope (body) chats.sql:519 GetChatUserPromptsByChatID skips NUL decoding R1 Knuckle No
CRF-21 OOS Out of scope (body) chats.sql:539 GetChatMessagesWithFilePartsByChatID unindexed content scan R1 Killua No
CRF-22 OOS Out of scope (body) turn_environment.go:2669 Dynamic tool named open_preview accepted when previews disabled R1 Kurapika No
CRF-23 Note Dropped by orchestrator (no change requested; DB error branch only writes 500 like sibling handlers) exp_chats_previews_test.go:21 DB error branch uncovered R1 Ryosuke No
CRF-24 P4 Author fixed (c975cf9); verified R3 exp_chats_previews_test.go:56 No test row fails when the role = 'tool' filter is removed R2 Bisky Yes
CRF-25 P4 Author fixed (c975cf9); verified R3 exp_chats_previews_test.go:96 No test row covers the 65535 port upper bound R2 Bisky Yes
CRF-26 P3 Author contested; panel closed R3 (3/3 accept) ARCHITECTURE.md:548 New route recorded only in a hidden TODO; rendered experimental route list incomplete R2 Gon P3, Hisoka P4, Melody P4 Yes
CRF-27 P3 Author fixed (c975cf9); verified R3 chatprompt.go:1613 Exported DecodeNulInJSON doc refers to unexported helper and omits when to call it R2 Gon P2 Yes
CRF-28 P3 Author fixed (c975cf9); verified R3 chats.sql:556 open_preview tool-result part without result key makes endpoint 500 permanently for the chat R2 Hisoka P4 Yes
CRF-29 P4 Author contested; panel closed R3 (1/1 accept) exp_chats_previews.go:73 Rows dropped by revalidation leave no log line R2 Chopper Yes
CRF-30 Note Note (body) exp_chats_previews.go:96 After agent restart a file preview keeps its 404 ID until reopened R2 Pariston No
CRF-31 OOS Out of scope (body); author (human) accepted R3 without ticket ARCHITECTURE.md:1179 Base TODO stands in for open_preview in the tool list R2 Gon No
CRF-32 P4 Author fixed (6f65124, 4e3a177); verified R5 codersdk/chats.go:1175 Preview kind called "path preview", "file path", and "file preview" across the diff and base R3 Gon P4 (R3); R4: Gon P2, Leorio Nit, Mafuuu Nit, Netero Note Yes
CRF-33 P4 Author fixed (PR description); verified R4 exp_chats_previews.go:71 PR description says error results fail revalidation; the workspace check skips them R3 Leorio Yes
CRF-34 P4 Author fixed (6f65124); verified R4 exp_chats_previews_test.go:101 No row with neither port nor preview ID; the "neither" half of the exactly-one check is untested R3 Bisky Yes

Contested and acknowledged

CRF-2 (P3, exp_chats_previews.go:71) - duplicated acceptance rules

  • Finding: The endpoint repeats the open_preview acceptance rules; proposed a shared OpenPreviewResult.Valid() used by tool and endpoint.
  • Author defense: Tool and endpoint already share appurl.PreviewMinimumPort, appurl.IsPreviewID, chattool.IsPreviewURLPath; a Valid method would only move the remaining range check.
  • Panel closure (R2, 2/2): Netero and Gon, the agents that raised it. Both verified the shared helpers in 96c31cb; the remaining literal is 65535, the TCP maximum. Netero noted the defense omits the url_path-without-port rule, which is the CRF-8 cross-kind part, closed separately. Bisky noted the local 65535 bound now needs its own test (CRF-25).

CRF-3 (P4, exp_chats_previews_test.go:74) - no error result test row

  • Finding: No isError=true row, so a change to error result storage is not caught.
  • Author defense: The handler never reads error fields; an error result has no workspace_id and is skipped like the "Old workspace" row.
  • Panel closure (R2, 1/1): Netero, the agent that raised it. Error results are stored as {"error": ...} (chatprompt.go:526), decode to a zero WorkspaceID, and the unbound guard returns before comparison, so a listed error requires error storage to start writing workspace_id, agent_name, and a valid port or ID.

CRF-8 cross-kind part (P2, exp_chats_previews.go:73) - url_path on file previews, path on port previews

  • Finding: The endpoint returns url_path on file previews and path on port previews, which open_preview rejects.
  • Author defense: Copied as stored because open_preview never writes either on the other kind.
  • Panel closure (R2, 3/3): Gon, Kurapika, Ryosuke, the agents that raised it. Only a non-built-in writer (the CRF-22 dynamic tool collision, the chat creator in their own chat) can produce such a row; it must match the chat's workspace, and IsPreviewURLPath keeps the origin fixed, so the worst result is an extra entry on the same preview host. Kurapika checked that decoded NUL fails IsPreviewURLPath and AgentNameRegex.

CRF-11 (P4, exp_chats_previews.go:33) - list returned with no app hostname

  • Finding: Return an empty list when api.AppHostname == "".
  • Author defense: Removing the app hostname breaks every preview link whether or not the list returns them.
  • Panel closure (R2, 1/1): Ryosuke, the agent that raised it. Filtering the list restores no working URL, and transcript links break the same way.

CRF-12 (P4, exp_chats_previews_test.go:110) - unbound-chat assertion vacuous

  • Finding: The assertion passes with the WorkspaceID guard deleted.
  • Author defense: open_preview always writes workspace_id; the guard only skips the query.
  • Panel closure (R2, 1/1): Bisky, the agent that raised it. Every success result sets WorkspaceID (openpreview.go:135) and error results do not unmarshal to a match, so removing the guard only adds one query.

CRF-13 (P4, codersdk/chats.go:1174) - REST reference lacks exactly-one rule

  • Finding: swagger/schemas.md have no description for ChatPreview, port, preview_id.
  • Author defense: Experimental endpoint; only client is the site using generated TS types.
  • Panel closure (R2, 1/1): Leorio, the agent that raised it. The generated TS type carries the doc comment.

CRF-15 (P4, codersdk/chats.go:1182) - Path vs FilePath

  • Finding: Rename Path to FilePath.
  • Author defense: path matches the open_preview argument and OpenPreviewResult.Path.
  • Panel closure (R2, 1/1): Gon, the agent that raised it. One name across tool and API, and the TS type carries the doc comment.

CRF-16 (Nit, exp_chats_previews.go:55) - endpoint type name

  • Finding: Rename local endpoint to previewKey.
  • Author defense: Type is local to one function.
  • Panel closure (R2, 1/1): Gon, the agent that raised it. The R2 description and doc comment no longer call the key a "preview endpoint", so nothing in the diff gives the word a second meaning.

CRF-26 (P3, ARCHITECTURE.md:548) - route recorded only in a hidden TODO

  • Finding: The rendered experimental-only route list omits GET /chats/{chat}/previews; proposed adding the route and deleting the TODO, citing root AGENTS.md.
  • Author defense: AGENTS.md tells agents to leave TODOs in the chatd architecture document and the human PR author writes the updates; @DanielleMaywood accepted the TODO and will write the update.
  • Panel closure (R3, 3/3): Gon (R1 agent reused), Hisoka and Melody (R2 agents reused), the agents that raised it. AGENTS.md:75-76 at head c975cf9 forbids agents from editing the document and tells reviewers to flag added TODOs, which round 2 did; all three withdrew the proposed fix. The human owner holds the edit.

CRF-29 (P4, exp_chats_previews.go:73) - dropped rows not logged

  • Finding: Rows that fail revalidation or unmarshal are dropped silently; proposed Debug logging excluding the workspace-mismatch skip.
  • Author defense: Routine skips share the workspace check; logging only drift needs plumbing; the tool applies the same rules before writing, so a revalidation skip is a code defect for tests to catch; the human author decided not to add it.
  • Panel closure (R3, 1/1): Chopper (R2 agent reused), the agent that raised it. Chopper noted the plumbing claim is wrong (the revalidation branches run after the workspace check, so logging them needs no separation), but accepted that those branches are reachable only through a code defect and a test catches that better than an unactionable log line.

Round log

Round 1

Netero first pass: 2 P3, 1 P4, 2 Note, 1 OOS. No P0, panel proceeds.

Full panel (round 1). Specialists: ging-go (.go), knuckle (query), kurapika (endpoint, auth, values used to build hostnames), ryosuke (Go API), melody (tool result JSON crosses producer/consumer boundary), killua (per-request scan). Core: pariston, mafuuu. Pool: bisky (tests), hisoka (input handling), gon, leorio (once-per-PR floor). Wildcard: meruem (random). 13 reviewers: multi-domain security-sensitive target 9-12 plus wildcard. ging-ts and nami not selected: the only .ts change is generated typesGenerated.ts with a new type no code imports yet.

Cross-check:

  • CRF-7: five reviewers converged; Melody P3 vs four at P2, higher wins.
  • CRF-8: Kurapika and Ryosuke P4 (url_path on preview ID) are a subset of Gon's P2 presence/validity finding; combined at P2. Verified by reading lines 71-87: valid port plus invalid preview_id gives hasPort != hasPreviewID and is not skipped.
  • CRF-9: Knuckle P3 (reproduced url_path change) vs Hisoka P4, higher wins.
  • CRF-10: downgraded from Gon P2 to P3. Keep-argument: the function's correctness depends on input order the comment hides, so a future caller with unsorted input gets wrong order and titles silently. Downgrade reason: unexported, one caller in the same PR whose query defines the order; consequence is maintenance risk, not current behavior. Contradiction with Leorio's Note praising the comment's key description: posted fix adds the precondition instead of removing the key text.
  • CRF-2 merged with Gon's named-constant P3.
  • CRF-4 asks for a description change, so posted as P4 rather than Note.
  • Informational Notes with no ask (Melody chain walk, Pariston premise, Leorio comment praise, Bisky CRF-2 evidence) are not inventory rows; Bisky's evidence is cited in CRF-2 and CRF-8.
  • Kurapika's dynamic tool collision: root cause in unchanged turn_environment.go, revalidation bounds impact; OOS.
  • CI logs unreadable (gh 401 in the review environment); CRF-5 left as Note (body).

Result: 2 P2, 4 P3, 7 P4, 2 Nit, 2 Note (body), 5 OOS, 1 dropped. Reviewed against 2ce038a..8a8f704.

Round 2

Churn guard PROCEED: 8 addressed, 7 contested (plus the CRF-8 cross-kind part), 0 silent. Branch rebased onto new base c2b194d; head 96c31cb.

Inventory validation: CRF-19 (agent ID counter) root cause fixed in #31282 (cryptorand.HexString(8)); CRF-22 still holds (turn_environment.go:2580).

Fix round, not restructure: no files added, renamed, or moved; the only new exported symbol (chatprompt.DecodeNulInJSON) is the CRF-9 fix; goal unchanged; effective additions +298 vs +279.

Netero (reused R1 agent for the CRF-2/CRF-3 dispute): no new findings; accepted CRF-2 and CRF-3 defenses.

Panel (13): dispute check-in with reused R1 agents for gon, bisky, ryosuke, leorio, kurapika. New agents for raisers of round 1 open findings whose code changed: pariston, mafuuu, hisoka, meruem, melody (CRF-7), knuckle (CRF-9). ging-go: .go files changed. Wildcard: chopper (random from Chopper, Kite, Zoro, Knov, Razor).

Cross-check:

  • All contested items closed by their raisers (see Contested and acknowledged).
  • Fixes verified: CRF-4, CRF-7 (Pariston, Meruem, Melody, Hisoka), CRF-8 (Gon, Ryosuke, Kurapika), CRF-9 (Knuckle, Hisoka, Bisky mutation), CRF-10 (Gon), CRF-17 (Ging-Go). CRF-1 verified for tool_name only.
  • CRF-14 re-raised: Leorio P4 (description omits preview_id replacement, key wording) and Mafuuu P3 (ChatPreview comment says PreviewID identifies the preview; feat(site): add a Preview tab for open_preview #31286 keys selection by preview_id, so re-open loses selection). Convergent, higher wins: P3. Posted as a reply on the existing thread.
  • CRF-24: Bisky's role-filter gap contradicts Netero's CRF-1 acceptance reasoning; Bisky cites provider-executed tool results on assistant messages (message_conversion.go:188). Posted at P4 as a separate test gap.
  • CRF-26: Gon P3, Hisoka P4, Melody P4; Netero called it consistent with other TODOs in the file. Pattern inheritance rejected: AGENTS.md requires updating ARCHITECTURE.md, and the TODO has no ticket. Higher wins: P3.
  • CRF-27: downgraded from Gon P2 to P3. Keep-argument: an exported decoder whose doc does not say when to call it invites the next raw-content reader to skip it, and CRF-20 is an existing instance of that bug. Downgrade reason: no behavior in this PR is wrong; consequence is a future caller missing it.
  • CRF-28: raised from Hisoka P4 to P3. Hisoka reproduced a scan error that 500s every later request for the chat; R1 Knuckle's claim that a NULL result is skipped is empirically disproved. A human reviewer (ibetitsmike) raised the same issue. Upward case: permanent failure with no recovery path for the chat. Downward: no current writer produces it. Permanence sets P3.
  • CRF-29 (Chopper P4) kept.
  • Informational Notes (Melody, Kurapika, Knuckle, Meruem, Ging-Go verifications; Chopper test-structure Note) are not inventory rows.

Result: new 3 P3, 3 P4, 1 Note (body), 1 OOS; CRF-14 re-raised at P3. Reviewed against c2b194d..96c31cb.

Round 3

Churn guard PROCEED: 5 addressed, 2 contested, 0 silent. Head c975cf9 on base 31acf45 (rebased).

Fix round, not restructure: no files added, renamed, or moved; no exported signature changes; goal unchanged; effective additions +311 vs +298.

Netero (new agent; no contested Netero findings): no findings; verified CRF-1, CRF-24, CRF-25, CRF-28 by mutation.

Panel (10): dispute check-in with reused agents for gon (R1 agent), hisoka, melody (CRF-26), chopper (CRF-29), all R2 agents. New agents: leorio, mafuuu (CRF-14), bisky (CRF-24, CRF-25), knuckle (query changed, CRF-28), ging-go (.go changed). Wildcard: meruem (random from Meruem, Kite, Zoro, Knov, Razor). Gon and Leorio present for comment changes.

Cross-check:

  • CRF-26 and CRF-29 closed by their raisers (see Contested and acknowledged).
  • Fixes verified: CRF-14 (Leorio, Mafuuu, Melody, Netero), CRF-24 and CRF-25 (Bisky, Netero, Meruem by mutation), CRF-27 (Gon, Meruem, Netero), CRF-28 (Hisoka, Knuckle, Bisky, Meruem, Melody, Netero by mutation). Mafuuu confirmed feat(site): add a Preview tab for open_preview #31286 previewKey now keys file previews by agent and path.
  • New: CRF-32 Gon P4 (terminology; verified codersdk/chats.go:1175 says "path preview", exp_chats_previews.go:55 says "file path", openpreview.go:33 and appurl.go:151 say "file preview"). CRF-33 Leorio P4 (PR description). CRF-34 Bisky P4 (verified by mutation hasPort && hasPreviewID).
  • Ging-Go: no findings.
  • CRF-31 OOS: author reported human acceptance without a ticket.

Result: 3 P4 new; all prior findings closed or verified. Reviewed against 31acf45..c975cf9.

Round 4

Churn guard PROCEED: 3 addressed, 0 contested, 0 silent. Head 6f65124 on base 9554451 (rebased). Since round 3 the PR's own changes are comment wording, regenerated docs and types, one test row, and the PR description.

Fix round, not restructure: no files added or moved, no signature changes, goal unchanged, effective additions +312 vs +311.

Netero (new agent): no findings; verified CRF-34 by mutation; Note on line 55 wording.

Panel (5): gon (CRF-32), leorio (CRF-33), bisky (CRF-34), ging-go (.go changed). Wildcard: mafuuu (random from Mafuuu, Meruem, Kite, Zoro, Knov, Razor). New agents for all; no contested findings.

Cross-check:

  • CRF-33 verified (Leorio, Netero). CRF-34 verified by mutation (Bisky, Netero). Ging-Go: no findings.
  • CRF-32 re-raised: exp_chats_previews.go:55 still says "per agent and file path" while the key can be a directory. Gon P2, Leorio Nit, Mafuuu Nit, Netero Note. Gate: strongest case for P2 is that the doc comment duplicates the key from the @description and the two copies already drifted in the round that fixed one, so they will drift again. Kept at CRF-32's original P4 instead: the function is unexported, the key struct is five lines below, no API reader sees this comment, and the consequence is a misleading word, not wrong behavior. Gon's removal of the duplicated key text is included as the fix option.

Result: 0 new findings; CRF-32 re-raised at P4. Reviewed against 9554451..6f65124.

Round 5

Churn guard PROCEED: 1 addressed (CRF-32), 0 contested, 0 silent. Head 4e3a177 on base b6ea144 (rebased). Only change to the PR's own code since round 4: exp_chats_previews.go:55 "file path" to "path".

Fix round, not restructure. Netero (new agent): no findings. Panel (5): gon, leorio, mafuuu (CRF-32 raisers), ging-go (.go changed), wildcard meruem (random from Meruem, Chopper, Kite, Zoro, Knov, Razor). All: no findings; CRF-32 verified by grep over added lines. Gon did not re-raise the duplicated-key comment (round 4 kept it at P4 with removal optional; the two copies now agree).

Result: no new findings; no open findings. APPROVE event. Reviewed against b6ea144..4e3a177.

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 GET /api/experimental/chats/{chat}/previews, which rebuilds the chat's preview list from its stored open_preview tool results. Findings: 2 P2, 4 P3, 7 P4, 2 Nit.

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

  • agent/agentpreview/preview.go:110: preview IDs come from a per-process counter, so after an agent restart a stored ID can serve a different path than the one it was opened for. A listed file preview shows that other path or returns 404 until the model republishes it, even after this endpoint keys file previews by path.
  • coderd/x/chatd/turn_environment.go:2669: on a deployment without an app hostname, open_preview is not registered, so a chat creator can register a dynamic tool with that name. Its results pass this endpoint's SQL filters if the deployment later sets an app hostname; the revalidation limits them to the chat's own workspace.
  • coderd/database/queries/chats.sql:519: GetChatUserPromptsByChatID returns prompt text without NUL decoding, so prompt history shows U+E000 sentinel pairs for prompts that contain NUL or U+E000.
  • coderd/database/queries/chats.sql:539: GetChatMessagesWithFilePartsByChatID runs the same unindexed content @> scan over every user and assistant message, so the attachments endpoint's cost grows with chat length.
  • Makefile:1500: coderd/apidoc/.gen lists site/node_modules/.installed twice; the second entry has no effect.

Notes:

  • coderd/database/queries/chats.sql:563: no index serves the content @> filter, so each request reads every tool message in the chat. A local measurement with 2000 tool messages of about 8 KB took 100 ms. This cost is acceptable for a fetch on page load and becomes a database load problem if the UI refetches on every message event.
  • CI: Flake Check and Storybook failed on this head. The job logs were not readable from the review environment. TestChatPreviews passed 35 times locally with -shuffle=on, and the only site/ change is the generated ChatPreview type.

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/exp_chats_previews.go Resolved
Comment thread coderd/exp_chats_previews.go Resolved
Comment thread coderd/database/queries/chats.sql Resolved
Comment thread coderd/exp_chats_previews_test.go Resolved
Comment thread coderd/exp_chats_previews.go Resolved
Comment thread codersdk/chats.go Resolved
Comment thread coderd/exp_chats_previews.go Resolved
Comment thread codersdk/chats.go Resolved
Comment thread coderd/exp_chats_previews.go Resolved
Comment thread coderd/exp_chats_previews_test.go Resolved
@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 of the review of the chat previews endpoint. New findings: 3 P3, 3 P4. One round 1 finding, about the endpoint description and the ChatPreview contract, is re-raised at P3.

Verified fixed: file previews keyed by path, the presence check, NUL decoding, the tool_name filter test, the oldest-first doc comment, the PR description, and maps.Copy. The reviewers who raised the contested findings accepted the defenses for the shared validator, the error-result test row, cross-kind url_path and path, the app hostname check, the unbound-chat test, the REST field descriptions, the Path name, and the endpoint type name.

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

  • coderd/x/chatd/ARCHITECTURE.md:1179: a TODO(DanielleMaywood) HTML comment from #31284 stands in for documenting open_preview in the tool list, so the rendered tool list leaves it out.

Notes:

  • coderd/exp_chats_previews.go:96: after an agent restart, a file preview entry keeps its pre-restart preview ID, which returns 404, until the model reopens that path. Port entries behave the same way while their server is down.
  • CI: 18 jobs fail on this head, including fmt, lint, and test-js, which build nothing this diff changes. The job logs were not readable from the review environment. Locally, go build, TestChatPreviews with -race -count=10, and the chatprompt and dbauthz tests pass.

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/x/chatd/ARCHITECTURE.md Resolved
Comment thread coderd/x/chatd/chatprompt/chatprompt.go Resolved
Comment thread coderd/database/queries/chats.sql Resolved
Comment thread coderd/exp_chats_previews_test.go Resolved
Comment thread coderd/exp_chats_previews_test.go Resolved
Comment thread coderd/exp_chats_previews.go Resolved
@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

Replies to the review body. Out of scope: @DanielleMaywood has accepted the open_preview TODO at coderd/x/chatd/ARCHITECTURE.md:1179 without a ticket, because the human author writes the updates to that document. Restart note: not changing. The list records what open_preview opened and does not probe the agent, so a path preview keeps its pre-restart preview ID, and a port preview stays listed while its server is down, until the model opens it again. Reopening the path replaces the entry with the working ID.

🤖 Posted by Coder Agents on behalf of @DanielleMaywood.

@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 of the review of the chat previews endpoint. New findings: 3 P4.

Verified fixed: the endpoint description and ChatPreview contract, the DecodeNulInJSON doc comment, the part ? 'result' filter, and the role-filter and 65536-port test rows. Reviewers checked the query and test fixes by removing each guard and watching TestChatPreviews fail. The reviewers who raised the architecture document TODO and the missing log line for dropped rows accepted the defenses; AGENTS.md:75-76 assigns the architecture document update to the human author.

Notes:

  • CI was still pending when this review ran (19 passed, 6 pending).

🤖 This review was automatically generated with Coder Agents.

Comment thread codersdk/chats.go Resolved
Comment thread coderd/exp_chats_previews.go Resolved
Comment thread coderd/exp_chats_previews_test.go Resolved
@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 of the review of the chat previews endpoint. No new findings. One round 3 finding, about naming the file preview kind, is re-raised at P4 because one instance was missed.

Verified fixed: the PR description now says the workspace check skips error results, and the "Neither" row fails the test when the exactly-one check is changed to hasPort && hasPreviewID.

Notes:

  • CI was still pending when this review ran (12 passed, 13 pending).

🤖 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 5 of the review of the chat previews endpoint. No new findings, and no findings remain open.

The doc comment at coderd/exp_chats_previews.go:55 now says "per agent and path", so every added line names the kind "file and directory previews" consistently. The only change since round 4 is that line; TestChatPreviews passes at this head.

Notes:

  • CI was still pending when this review ran (2 passed, 20 pending).

🤖 This review was automatically generated with Coder Agents.

GET /api/experimental/chats/{chat}/previews lists the previews that
open_preview opened in the chat's current workspace, one per agent, port,
and URL path, or per agent and path, ordered by first open. The newest
result supplies the title and preview ID. Results come from the chat's own
user-visible tool messages, so access follows chat read permission.
@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

Superseded by the strict-mode preview stack starting at #32438.

This branch had an error being deployed

1 failed deployment
docs-preview — cf81b48a Deployed Nov 24, 2026 by DanielleMaywood via cleanup #463
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants