Repository navigation
feat: list every chat attachment in the Summary panel - #31140
Conversation
|
@codex review
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c1af9dd7cb
ℹ️ 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".
|
@codex review
|
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d11c699cd0
ℹ️ 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".
d11c699 to
66e92f0
Compare
mafredri
left a comment
There was a problem hiding this comment.
Two concerns, one question, one nit.
Question: files from sub-agents (attach_file in a child chat, computer-use screenshots) and wait_agent recordings never show in the root chat's Summary panel. Recordings also count toward the root chat's attachment limit. Is that intended for this panel, or a follow-up?
+1 to the open Codex thread on codersdk/chats.go: Swagger still types file as any ChatMessagePart.
Checked: TestGetChatAttachments, the three frontend test files, a throwaway render test for the UI points below, and the cached-boundary seeding against edits (no deleted messages leak in). Didn't run it on dogfood.
🤖 This review was automatically generated with Coder Agents.
|
@mafredri On the question in your review: this PR leaves them out. The endpoint lists the file parts of the chat's own user and assistant messages. A sub-agent's
|
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6ae8719d6a
ℹ️ 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".
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 868d42430f
ℹ️ 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".
| AND visibility IN ('user', 'both') | ||
| AND role IN ('user', 'assistant') | ||
| AND content @> '[{"type": "file"}]'::jsonb | ||
| ORDER BY id DESC; |
There was a problem hiding this comment.
Bound the attachment history response
For a chat that has accumulated many attachments, this query has no LIMIT, so merely opening the Summary panel reads every historical matching message and the handler materializes all file parts into one response, including base64 Data from inline files. The attachment limit only caps files currently linked to the chat; evicted references remain in historical messages, so it does not bound this database scan, allocation, HTTP payload, or the resulting rendered list. Paginate this endpoint or enforce a defensible response-size or result cap.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changed in this PR, and I left this thread open for @ibetitsmike to decide. A cap changes what the panel can claim: the header count and the "N expired" list assume the full list, so a silent LIMIT would show a wrong count. Paging needs a cursor on the endpoint and a "load more" control in the panel, which is a product decision.
For scale: the query reads only the chat's user-visible user and assistant messages that hold a file part. Uploads and agent attachments are stored files, so their parts carry metadata, not bytes. GET /messages already returns the same parts, inline data included, in pages of up to 200 messages.
Xum, an AI agent, wrote this reply for @ibetitsmike.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e924d0595d
ℹ️ 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".
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 661db9b52a
ℹ️ 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".
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 51c5c98feb
ℹ️ 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".
| }); | ||
| viewButton.focus(); | ||
|
|
||
| fireEvent.error(within(viewButton).getByRole("img")); |
There was a problem hiding this comment.
Stop querying the decorative thumbnail as an image
In both new focus tests, MessageAttachmentCard renders this thumbnail with alt="", which gives it the presentation role rather than img; getByRole("img") therefore throws before fireEvent or the focus assertion runs, failing the unit suite. Select the decorative node without asserting an image role, such as through a dedicated test hook for this role-free element.
AGENTS.md reference: site/AGENTS.md:L16-L16
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changed, because this does not reproduce. Both focus tests pass, locally and in CI (test-js passed on e924d0595d9 and 661db9b52af, which have the same tests). This repo's @testing-library/react 14.3.1 uses @testing-library/dom 9.3.3, which takes roles from aria-query 5.1.3. That version gives an img element with an alt attribute of any value, including alt="", the img role, so getByRole("img") finds the thumbnail. If a later upgrade maps an empty alt to presentation, the query fails loudly on that line, and the test can change then.
Xum, an AI agent, wrote this reply for @ibetitsmike.
|
@codex review
|
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
jaaydenh
left a comment
There was a problem hiding this comment.
Approving with one issue for keyboard users.
When using the keyboard to tab to an attachment inline in the chat then selecting the attachment with the keyboard (enter or space), after pressing escape to close the attachment, the focus on the attachment is lost and a keyboard user would need to tab all the way from the beginning starting with the coder logo.
The focus should be remembered for keyboard users.
Add GET /api/v2/chats/{chat}/attachments, backed by a new
GetChatMessagesWithFilePartsByChatID query, so clients can list every
file part in a chat's user-visible user and assistant messages, newest
first, without paging through the transcript. An optional before_id
limits the list to messages older than a boundary.
The Summary tab's Attachments section listed only the agent files in
the messages already loaded in the chat store, so long chats showed
"No attachments in the loaded messages." and a Load earlier messages
button.
The panel now combines the loaded messages' attachments, which stay
live, with GET /api/v2/chats/{chat}/attachments for the history before
the oldest loaded message. It lists user uploads as well as agent
files, counts earlier references when marking evicted files, and shows
an error line with Retry when the earlier list fails. Chats whose
messages are all loaded, and a hidden Summary tab, make no request.
Forward the query abort signal, read the placeholder boundary without positional key holes, reuse partFileIds for eviction, test the placeholder rules, and trim redundant comments and story helpers.
…ate comment above its branch
…or failed earlier attachments
- Treat an earlier attachment as evicted when the chat record lacks its file. Messages before the loaded ones predate the record, so they do not need the newest-linked boundary, which missed evictions when the only remaining files were recordings in unloaded history. - Seed an earlier boundary's attachments from a cached list for a later boundary instead of requesting that subset again. - Generate ChatAttachment.file as ChatFilePart, the only part type the attachments endpoint returns. - Describe the ChatAttachments ordering contract in its JSDoc.
…oundary Add an ExpiredEarlierAttachment story so the Summary panel's handoff of earlier file IDs to eviction has visual coverage, and a chatAttachments case proving boundary 0 (every attachment) is never seeded from a cached partial list.
… tighten attachment docs Pass earlier attachments through partFileIds instead of repeating its file case, state the newest-first order on the attachments prop, and say why earlier file IDs need no newer remaining reference.
…ents story render Render the three stories that start from the latest messages page with one shared function, and give the expired-earlier-attachment chat fixture a name like the file's other chat variants.
The attachments endpoint only returns file parts, but `ChatAttachment.file` was a `ChatMessagePart`, so the OpenAPI schema and the generated API reference described every part type (the example response showed `"type": "text"`). `ChatAttachmentFile` carries only a file part's fields, and its single-value `type` enum makes the schema, the Go client, and the generated TypeScript agree that the part is a file. The TypeScript generator no longer needs a special case to narrow the field. The endpoint's description now sits on one source line, so the generated reference keeps the sentence on one line.
…hments and fold expired ones The Summary panel listed uploads, pasted text, and files the agent attached as identical cards, so agent output was hard to find. `MessageAttachment` now keeps the message role, and the panel groups the files under "From the agent" and "From you". Expired files rendered as nameless "Attachment expired" tiles and counted toward the header, so a long chat past its attachment limit showed a column of identical tiles. They now fold into a closed "N expired" list that names each file and explains why it expired, and the header counts only the files that still exist. While the earlier-attachments request is pending, the panel shows the attachments from loaded messages with a spinner below them instead of hiding them.
The Summary panel's attachment cards only downloaded files, while the transcript previews them. Selecting a card now previews the file, and an icon on the card downloads it. Images open in the image lightbox, and the card shows their thumbnail. Text, Markdown, CSV, and JSON files open in the text preview, which loads a stored file's text on its first view and reuses it after that. Other files keep the download card. Closing a preview returns focus to its card. `Lightbox` now passes the close event to `onCloseAutoFocus` instead of always calling `preventDefault`, so the card's focus return prevents the default only when it can focus a target. `MermaidDiagram`, the other caller that passes the prop, calls `preventDefault` itself, so its focus return is unchanged. `ImageLightbox` and `TextPreviewDialog` take the same prop. When a thumbnail fails to load, the card becomes a download card and keeps focus. When a view finds a stored text file deleted, its card stays in place as expired, keeps focus, and no longer counts toward the header. The earlier-attachments query requests nothing until the panel has a boundary, instead of reading 0 as "every attachment". The shared download link moved into its own module, so AttachmentBlocks.tsx stays near its size on main. The expired list's explanation now says that unreferenced attachments are deleted only when conversation retention is on, because the purge runs only then. `ChatAttachmentsOptions` only carries the Go client's query options, so it is left out of the generated TypeScript types. Two existing stories import the shared 1x1 PNG fixture instead of keeping their own copies.
…n the installed iOS app The Summary panel test read the download link's href and download attributes, so removing AttachmentDownloadLink's click handler, which opens the share sheet in an installed iOS app, left every test green. The test now stubs that environment with vi.stubGlobal, clicks the link, and asserts the file request and the shared file's name.
…s focused and one at a time An image card whose thumbnail failed while its preview was open swapped to a download card and closed the preview, but focus sat in the preview's portal, so it fell to the page body. The card now counts an open preview as holding focus, so the download card takes it. A stored text file opened its preview only after its text loaded, so during a slow load another file could open a second modal preview on top of it. The preview now opens at once and shows a spinner until the text arrives. A failed load still closes it, and the card shows the error. When the transcript's last page loaded, the panel dropped the earlier attachments for the render before the chat store took in that page, so the list and its count shrank for a paint. The panel now keeps the cached earlier list until the store catches up, without requesting it again.
…mmary panel's expired list The button that opens the list of files the chat no longer has read "1 expired" or "3 expired", so neither its text nor a screen reader said what had expired. It now reads "1 expired attachment" or "3 expired attachments".
GET /api/v2/chats/{chat}/attachments sent "file_id": null for an inline
file such as pasted text, because omitempty does not omit a
uuid.NullUUID, while the OpenAPI schema and the generated TypeScript
declare file_id as an optional string. ChatAttachmentFile now tags it
omitzero, so an inline file leaves it out.
The schema also described data as an array of integers, but Go sends a
[]byte as a base64 string, which the TypeScript type already declares.
The field is now documented as a base64 string, and the new field
comments reach the API reference and the TypeScript type.
chatFileText spread disabledRefetchOptions, which sets gcTime to Infinity, so the text of every file someone viewed stayed in the query cache until the page reloaded, even after no card showed it. A stored chat file can be 10 MiB. The query now sets only enabled: false and takes the default gcTime, as ProposePlanTool does for the same key, so the cache frees the text five minutes after nothing observes it. With the query disabled, the helper's other options had no effect. MessageAttachmentCard's doc comment only restated its media-type branches. It now also states what the code does not show: for a stored text file, the card loads the text only on view, and a 404 marks the card expired while that response stays cached. The Summary panel's header count leaves such a file out for the same time, as its comment now says.
GET /api/v2/chats/{chat}/attachments lists file parts from user and
assistant messages only, but ChatAttachment.role was a ChatMessageRole,
so the OpenAPI schema and the generated TypeScript also allowed system
and tool. A new ChatAttachmentRole type holds the two roles the
endpoint returns, and the schema and the TypeScript union now list
only those.
… earlier attachments fail When the request for attachments from earlier messages failed, the Summary panel showed fixed copy, "Could not load attachments from earlier messages.", and the server's error never reached the user. ChatAttachments now takes the query's error and renders it with the shared ErrorAlert, with the existing Retry button as its action. TanStack Query clears the error of a query with no data and sets it back to pending when it refetches, so a retry would swap the alert for the loading spinner. The Retry handler stores the error it retries, with the oldest loaded message that keys the query, and clears it when the retry settles. The alert and its Retry button stay on screen while the retry runs or waits offline, and any other refetch, such as a reconnect, shows the spinner. New stories cover a retry in flight, a retry paused offline, and a reconnect after a failed retry.
…s when their preview closes The transcript's image and text previews and the tool result image preview open without a Radix DialogTrigger, so closing one with Escape moved focus to the page body and a keyboard user had to tab from the top of the page to get back to the attachment. The previews now remember the button that opened them and focus it again on close, the way the Summary panel's attachment cards already do. Transcript attachments report only what they open, so the timeline remembers the focused button instead of the click event.
ce4e795 to
b37b995
Compare
…at opened a preview A text file opens its preview only after its download finishes, so reading the focused element at that point could pick up whatever the user moved to while the file loaded. Pass the clicked button to the opener instead, and cover the slow download in a test.
…he remembered dialog trigger rememberTrigger now passes the event's button to rememberTriggerButton, so one function writes the remembered trigger. The attachment preview tests use named message fixtures and the shared createDeferred helper.
…after a preview closes Radix restores focus from a setTimeout(0) when a dialog closes, so the focus tests wait for it instead of relying on timer order. The slow download test also checks that focus left the attachment before the download finishes, and the rememberTriggerButton comment fits on one line.
…ake a button The comment above rememberTriggerButton now covers the openers that run inside a click handler too: the transcript hands them a button because a stored text file opens its preview after an await, when React has cleared event.currentTarget.
|
Thanks for catching this, @jaaydenh. It is fixed in b37b995 and 484e010. After Enter or Space opens the preview of an attachment in the transcript, Escape now returns focus to that attachment, so Tab continues from there instead of from the Coder logo. This covers images, text files (including a stored file whose preview waits for its download), pasted text, the agent's attachments, and tool result images, and a keyboard-only run on dogfood confirmed each case. The composer's previews of pending attachments, the recording preview, and the Instructions page's text preview drop focus the same way, but they predate this PR, so they are left for a follow-up.
|
In long chats, the Summary panel's Attachments section only listed agent files from the messages already loaded in the transcript. It showed "No attachments in the loaded messages." and a Load earlier messages button, so finding a chat's files meant paging through its history.
What changes
GET /api/v2/chats/{chat}/attachmentsreturns every file part in the chat's user-visible user and assistant messages, newest first, as{message_id, part_index, role, file}, whereroleisuserorassistant. An optionalbefore_idlimits it to older messages. Parts go through the same conversion asGET /messages, sopart_indexmatches that endpoint.fileis aChatAttachmentFile, a file-only type, so the OpenAPI schema, the API reference, and the generated TypeScript all describe a file part. An inline file omitsfile_idand carries its bytes indataas a base64 string. It needs the same permission as reading the chat. A new sqlc query,GetChatMessagesWithFilePartsByChatID, backs it; there is no migration.Lightboxnow passes Radix's close event toonCloseAutoFocusinstead of always callingpreventDefault, so a card hands it touseDialogFocusReturn().restoreFocus, which prevents the default only when it can focus a target.MermaidDiagram, the only other caller that passes the prop, now callspreventDefaultitself, so its focus return is unchanged.ImageLightboxandTextPreviewDialogtake the same optional prop.Closes CODAGT-1436.
Testing
TestGetChatAttachmentschecks the order and the filtering (deleted, model-only, and tool messages are left out, andpart_indexskips a stripped hook-context part asGET /messagesdoes), compares every returned file with its part fromGET /messages, including an inline paste'sdata, and coversbefore_id, a 400 for an invalidbefore_id, a 404 for another user, and the raw JSON of an inline file, which has nofile_idkey and a base64datastring. The dbauthz suite asserts chat read. Vitest covers the panel's request gating and Retry, seeding an earlier boundary from a cached list, the attachment helpers (including earlier files the chat no longer lists), and the cards' previews (including a text preview that opens before its text loads), download link (including the share sheet it opens in an installed iOS app), and focus, including a thumbnail that fails to load, also with its preview open, and a text file that returns 404, and that a viewed text file's text leaves the cache once nothing shows it. Vitest also opens a transcript image, an inline text file, a stored text file whose download finishes after focus has moved on, and a tool result image with Enter, closes each with Escape, and checks that focus is back on the attachment. Stories cover the new states, including a retry in flight, a retry paused offline, and a reconnect after a failed retry. Two existing stories now import the shared 1x1 PNG fixture instead of keeping their own copies. Each new test fails when its code path is broken. No new dependencies.Review record
5cf0757b1d8. The previews and the download icon that @ibetitsmike asked for in the same round are in6ae8719d6a0.868d42430f0, 4 on the fixes for Codex's fifth run, 1 on its sixth, 7 on its seventh, and 4 on its eighth. The last of those four passed every role it ran, and so did its FE1 to FE10 audit. Every blocking and should-fix finding is fixed or declined with a reason. Declined: the alert's title is an h2 under the section's h3, because the sharedAlertTitlealways renders an h2, as in everyErrorAlert; Retry does not move focus after a successful retry removes it, which matches the otherRetryButtoncallers and would need a focus effect; the endpoint and panel ship together because the panel is the endpoint's only consumer; a chat record withoutfilesis not read as an empty file list, because the server also omitsfileswhen its best-effort metadata query fails, which would show every earlier file as expired; the header count does not subtract a deleted image or an unopened text file, because the panel learns of a deletion only from the chat record or a preview's 404; a card whose file a chat refetch reports deleted moves into the expired list, which closes its open preview, as the transcript swaps an evicted file's card for the expired tile; if the transcript's last page arrives while the earlier request is still loading, the header count briefly leaves out that page's files, because only a rerender test reading the header could hold a fix, which FE1 keeps out of Vitest; a text file found deleted counts again once the cache frees its 404, five minutes after nothing on the page reads it, because keeping that 404 until reload would need a cache entry per deleted file that is never freed, and the transcript onmainforgets the same 404 as soon as the chat closes; and AttachmentBlocks.tsx is at 719 lines (699 onmain), because moving its file cards out would create an import cycle.c1af9dd7cbcand again ond11c699cd0d. The second round rand11c699cd0dand thec1af9dd7cbcfrontend against the same backend: an evicted earlier upload shows as expired ond11c699cd0dand as a download card that returns 404 onc1af9dd7cbc, and loading earlier pages sends no further attachments requests ond11c699cd0d, whilec1af9dd7cbcsent one per new page boundary. One issue also reproduces onmainand is unchanged here: after a live attach evicts an older file, the panel and the transcript keep its download card until the page reloads. The changes since66e92f09064(mafredri's review, the preview cards, and the fixes for Codex's third to eighth runs) were checked in Storybook and Vitest, and on dogfood only through the keyboard round below, which also opened the Summary panel's image and text cards; the screenshots above are Storybook renders.d11c699cd0d. A third run ond11c699cd0draised 2 findings, both fixed indb0109d1120. A fourth run on6ae8719d6a0raised 1 finding (the download-link test read only the link's attributes), fixed in868d42430f0. A fifth run on868d42430f0raised 4 findings. Three are fixed ine924d0595d9: an open image preview lost focus when its thumbnail failed, a slow text load let a second preview open, and the earlier attachments dropped for a render when the last page loaded. The fourth (paginate or cap the endpoint) is left open for a product decision. A sixth run one924d0595d9raised 1 finding (the expired list's button did not say what expired), fixed in661db9b52af. A seventh run on661db9b52afraised 4 findings, all fixed: an inline file'sfile_idcame back asnulland the schema describeddataas integers (5fb4a047e39), and viewed text stayed cached until reload and the card's doc comment restated its code (51c5c98feb8). An eighth run on51c5c98feb8raised 3 findings. Two are fixed: the attachment role allowedsystemandtool(2ed84cd882f), and the error line hid the server's message (ce4e79593f6). The third, that Testing Library cannot find the decorative thumbnail by itsimgrole, does not reproduce and is declined in its thread.b37b9952898and484e010dd25;359dd039b78,277b89ba1e2and606b601c445only refactor the hook, tighten the tests, and reword a comment. Frontend review ran 5 rounds on the fix; the last passed, and every blocking and should-fix finding is fixed or declined. Declined: the composer's pending-attachment previews, the recording preview, and the Instructions page's text preview also drop focus when they close, but they predate this PR and are outside the transcript, so they are a follow-up; if a stored text file finishes downloading while the same message's image preview is open, closing the image returns focus to the text file, because a message row remembers one opener, so focus still stays in that message; and the fix grows ConversationTimeline.tsx from 812 to 827 lines, which was already over the 500-line guideline. Remote dogfood UAT passed on484e010dd25with real key presses: after Enter or Space opens the preview of a user's image, text file (also when its download is slowed and the user presses Tab while it loads), or pasted text, of an assistant's attachments, of one of three attachments in one message, or of a tool result image, Escape returns focus to the same attachment, so Tab continues from there. Onbac7cb055cefocus fell to the page body and the next Tab went to the Coder logo, so a keyboard user needed 130 Tabs to get back to the composer instead of 44. Summary panel cards returned focus before the fix and still do. The image, slowed text file, and Summary panel cases passed again on277b89ba1e2;606b601c445changes only a comment.mainafter those reviews. The added and removed lines are unchanged; only the path ofAgentChatPageView.tsxchanged, becausemainmoved it intoAgentChatPage/. After the eighth Codex run,mainwas merged in, with one conflict incoderd/chat_routes.go, where both sides added a route. On 2026-10-26 the branch was rebased ontomain(aa9b0a950ad) again, with conflicts in the same route list and in the generatedsite/src/api/typesGenerated.ts, where both sides added a type; the added and removed lines are unchanged.