Skip to content

feat: list every chat attachment in the Summary panel - #31140

Merged
ibetitsmike merged 25 commits into
mainfrom
mike/codagt-1436-sidebar-attachments
Oct 27, 2026
Merged

ibetitsmike merged 25 commits into
mainfrom
mike/codagt-1436-sidebar-attachments

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • API: GET /api/v2/chats/{chat}/attachments returns every file part in the chat's user-visible user and assistant messages, newest first, as {message_id, part_index, role, file}, where role is user or assistant. An optional before_id limits it to older messages. Parts go through the same conversion as GET /messages, so part_index matches that endpoint. file is a ChatAttachmentFile, a file-only type, so the OpenAPI schema, the API reference, and the generated TypeScript all describe a file part. An inline file omits file_id and carries its bytes in data as a base64 string. It needs the same permission as reading the chat. A new sqlc query, GetChatMessagesWithFilePartsByChatID, backs it; there is no migration.
  • Panel: attachments from the loaded messages stay live. While older history is not loaded, the panel fetches the attachments before the oldest loaded message and lists them with the rest. It sends no request when every message is loaded or the Summary tab is hidden. Loading earlier transcript pages reuses the list it already fetched instead of sending another request, and does not blank, duplicate, or reorder it, including while the last page moves into the chat store.
  • Groups: files the agent attached are listed under "From the agent", then uploads and pasted text under "From you".
  • Cards: selecting a card previews the file. Images open in the image lightbox and show their thumbnail on the card. Text, Markdown, CSV, and JSON files open in the text preview, which opens at once with a spinner while a stored file's text loads on its first view, and reuses the text until the cache frees it, five minutes after nothing on the page reads it. An icon on the card downloads the file. Other files keep the download card. Closing a preview returns focus to its card, and an image whose thumbnail fails to load becomes a download card that takes focus, even if its preview was open.
  • Dialogs: Lightbox now passes Radix's close event to onCloseAutoFocus instead of always calling preventDefault, so a card hands it to useDialogFocusReturn().restoreFocus, which prevents the default only when it can focus a target. MermaidDiagram, the only other caller that passes the prop, now calls preventDefault itself, so its focus return is unchanged. ImageLightbox and TextPreviewDialog take the same optional prop.
  • Transcript focus: closing the preview of an attachment in the transcript (the image lightbox or the text preview) or of a tool result image returns keyboard focus to the attachment that opened it instead of the page body. Each attachment button passes itself to the opener, because a stored text file opens its preview only after its download finishes, when the click event no longer holds the button.
  • States: the header count shows once the list is complete and leaves out expired files. An empty list says "No attachments yet." While the earlier request is pending, the loaded attachments stay, with a spinner below them. If the request fails, they stay and the section shows the server's error in an alert with Retry, which stays while the retry runs or waits offline. The load-earlier button is gone.
  • Expired files: files the chat no longer has fold into a closed "N expired attachments" list that names each one and explains why files expire. A file from unloaded history counts as expired when the chat's file list no longer has it. If the cached chat record is older than those messages (a revisit after more than a page of new messages), a new file can show as expired until the chat refetch returns. A stored text file whose preview finds it deleted stays in place as "Attachment expired", keeps focus, and leaves the count.
Cards grouped by who attached them Earlier attachments in the Summary panel Expired files, listed by name
Agent files under From the agent and an upload under From you, with an image thumbnail and a download icon on each card Summary panel listing a file from a loaded message and two files from messages that are not loaded Opened 3 expired attachments list naming each expired file under an explanation of why files expire
Text file found deleted Earlier request failed Image preview
PLAN.md card in place with a warning tile and Attachment expired, and the header count down to 5 A loaded attachment still listed above an alert with the server's error and a Retry button Image lightbox open over the panel after selecting the image card

Closes CODAGT-1436.

Testing

TestGetChatAttachments checks the order and the filtering (deleted, model-only, and tool messages are left out, and part_index skips a stripped hook-context part as GET /messages does), compares every returned file with its part from GET /messages, including an inline paste's data, and covers before_id, a 400 for an invalid before_id, a 404 for another user, and the raw JSON of an inline file, which has no file_id key and a base64 data string. 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

  • mafredri's review: grouping by role, the expired list, and keeping the loaded attachments visible while the earlier request loads are in 5cf0757b1d8. The previews and the download icon that @ibetitsmike asked for in the same round are in 6ae8719d6a0.
  • Frontend review (8 reviewer roles): 4 rounds before the first UAT, 3 delta rounds on the Codex fixes, then 12 rounds on mafredri's review and the preview cards, with an FE1 to FE10 audit in rounds 2 to 10 (rounds 11 and 12 re-checked comments only), then 3 delta rounds on the download-link test in 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 shared AlertTitle always renders an h2, as in every ErrorAlert; Retry does not move focus after a successful retry removes it, which matches the other RetryButton callers and would need a focus effect; the endpoint and panel ship together because the panel is the endpoint's only consumer; a chat record without files is not read as an empty file list, because the server also omits files when 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 on main forgets the same 404 as soon as the chat closes; and AttachmentBlocks.tsx is at 719 lines (699 on main), because moving its file cards out would create an import cycle.
  • Remote dogfood UAT passed on c1af9dd7cbc and again on d11c699cd0d. The second round ran d11c699cd0d and the c1af9dd7cbc frontend against the same backend: an evicted earlier upload shows as expired on d11c699cd0d and as a download card that returns 404 on c1af9dd7cbc, and loading earlier pages sends no further attachments requests on d11c699cd0d, while c1af9dd7cbc sent one per new page boundary. One issue also reproduces on main and 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 since 66e92f09064 (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.
  • Codex review: round 1 raised 4 findings, all fixed (see the resolved threads). Round 2 found no issues on d11c699cd0d. A third run on d11c699cd0d raised 2 findings, both fixed in db0109d1120. A fourth run on 6ae8719d6a0 raised 1 finding (the download-link test read only the link's attributes), fixed in 868d42430f0. A fifth run on 868d42430f0 raised 4 findings. Three are fixed in e924d0595d9: 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 on e924d0595d9 raised 1 finding (the expired list's button did not say what expired), fixed in 661db9b52af. A seventh run on 661db9b52af raised 4 findings, all fixed: an inline file's file_id came back as null and the schema described data as integers (5fb4a047e39), and viewed text stayed cached until reload and the card's doc comment restated its code (51c5c98feb8). An eighth run on 51c5c98feb8 raised 3 findings. Two are fixed: the attachment role allowed system and tool (2ed84cd882f), and the error line hid the server's message (ce4e79593f6). The third, that Testing Library cannot find the decorative thumbnail by its img role, does not reproduce and is declined in its thread.
  • @jaaydenh's approval note, that keyboard focus was lost after closing the preview of an attachment in the transcript, is fixed in b37b9952898 and 484e010dd25; 359dd039b78, 277b89ba1e2 and 606b601c445 only 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 on 484e010dd25 with 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. On bac7cb055ce focus 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 on 277b89ba1e2; 606b601c445 changes only a comment.
  • Rebased onto main after those reviews. The added and removed lines are unchanged; only the path of AgentChatPageView.tsx changed, because main moved it into AgentChatPage/. After the eighth Codex run, main was merged in, with one conflict in coderd/chat_routes.go, where both sides added a route. On 2026-10-26 the branch was rebased onto main (aa9b0a950ad) again, with conflicts in the same route list and in the generated site/src/api/typesGenerated.ts, where both sides added a type; the added and removed lines are unchanged.

Xum, an AI agent, opened this PR for @ibetitsmike and wrote this description.

@linear-code

linear-code Bot commented Oct 21, 2026

Copy link
Copy Markdown

CODAGT-1436

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for @ibetitsmike.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 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-10-23T04:45:54.139131Z ce4e795 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread site/src/api/typesGenerated.ts Resolved
Comment thread site/src/api/queries/chats.ts Resolved
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

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

@ibetitsmike
ibetitsmike marked this pull request as ready for review October 21, 2026 23:28
@ibetitsmike
ibetitsmike requested review from a team, Emyrk and nickvigilante as code owners October 21, 2026 23:28
@pr-queue-manager
pr-queue-manager Bot requested a review from jaaydenh October 21, 2026 23:31

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread codersdk/chats.go Resolved
Comment thread docs/reference/api/chats.md Resolved
@ibetitsmike
ibetitsmike force-pushed the mike/codagt-1436-sidebar-attachments branch from d11c699 to 66e92f0 Compare October 21, 2026 23:43

@mafredri mafredri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@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 attach_file results and screenshots are parts of the child chat's messages, so they show in the child chat's Summary panel. wait_agent recordings are tool-result fields (recording_file_id, thumbnail_file_id) that chatd stores on the parent chat, so they count toward its attachment limit, which is how main behaves today. Listing them in the root panel would need the endpoint to read child chats or tool results, so it fits a follow-up.

Xum, an AI agent, wrote this reply for @ibetitsmike.

@ibetitsmike
ibetitsmike requested a review from mafredri October 22, 2026 23:14
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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.

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.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread codersdk/chats.go Resolved
Comment thread codersdk/chats.go Resolved
Comment thread site/src/api/queries/chats.ts Resolved
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread codersdk/chats.go Resolved
});
viewButton.focus();

fireEvent.error(within(viewButton).getByRole("img"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

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.

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.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: ce4e79593f

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

@jaaydenh jaaydenh 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.

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.
- 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.
@ibetitsmike
ibetitsmike force-pushed the mike/codagt-1436-sidebar-attachments branch from ce4e795 to b37b995 Compare October 26, 2026 23:55
…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.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

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.

Xum, an AI agent, wrote this reply for @ibetitsmike.

@ibetitsmike
ibetitsmike merged commit 3f055e7 into main Oct 27, 2026
53 of 56 checks passed
@ibetitsmike
ibetitsmike deleted the mike/codagt-1436-sidebar-attachments branch October 27, 2026 02:13
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants