Skip to content

feat: add workspace file upload agent API - #27078

Merged
ibetitsmike merged 4 commits into
mainfrom
mike/chat-workspace-upload/agent
Sep 25, 2026
Merged

ibetitsmike merged 4 commits into
mainfrom
mike/chat-workspace-upload/agent

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator

What

Adds a dedicated workspace-agent endpoint, POST /api/v0/upload-chat-file, that streams a request body into the chat's upload directory ~/.coder/chats/<chat-id>/files/<name>, plus the SDK plumbing to call it:

  • coderd/x/chatfiles: upload-name sanitization (SanitizeWorkspaceUploadName), collision suffixes (compound extensions such as .tar.gz stay intact: archive_2.tar.gz), and the shared ~/.coder/chats/<id>/files path layout.
  • agent/agentfiles: the HTTP handler. On Linux/macOS the directory chain is opened with openat(O_NOFOLLOW), so symlinked path components are rejected. The body streams into a hidden .<name>.upload-<random> temp file and is published under its final name only when complete, via linkat over the _2, _3, ... collision sequence, so existing files are never overwritten and a half-written file is never visible under its final name. Filesystems without hard links fall back to an exclusive placeholder plus renameat. Other platforms use an afero-based fallback with the same semantics. Stale temp files older than an hour are swept before each upload, and failures are logged with a structured warning.
  • codersdk/workspacesdk: AgentConn.UploadChatFile + regenerated agentconnmock.

Why

Coder Agents chat can attach images/text/PDF to prompts, but arbitrary files (zips, datasets, binaries) have nowhere to land where the agent's tools can act on them. This is the agent-side foundation; the coderd route that fronts it is stacked on top.

Design notes:

  • There is deliberately no size cap; the resource profile matches existing SSH/WebSocket proxying, and client cancellation aborts the stream (a failed write removes the temp file, so no partial files remain). Because the agent HTTP server uses fixed 20 s read/write timeouts, the handler pushes both deadlines forward on every received chunk, so a slow upload only fails after a 20 s stall. If the connection does not support deadline changes, the agent logs one warning per request.
  • This endpoint is not gated by CODER_AGENT_BLOCK_FILE_TRANSFER. That flag targets SSH-transport file tools (scp/rsync/sftp). Chat uploads are an agent API capability like write-file and edit-files, which already bypass the flag; the interaction is documented in the FAQ.

How tested

  • go test ./agent/agentfiles ./coderd/x/chatfiles ./codersdk/workspacesdk (unit + umask/symlink/collision integration tests).
  • UAT on a dogfood-style deployment (2026-09-21): uploads longer than 20 s went from 502 to 201 once the workspace agent was restarted on this build; a coderd restart alone keeps the old agent running, so the per-chunk deadline extension needs the agent rolled (older agents get the 409 "Restart the workspace" from feat: add chat workspace file upload endpoint #27079).

Part of CODAGT-211. Stack: agent API (this PR) -> coderd endpoint -> UI.

This PR was authored by Mux (AI) working on Mike's behalf.

@github-actions

github-actions Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Docs preview

Check off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here.

ibetitsmike commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

@linear-code

linear-code Bot commented Jul 7, 2026

Copy link
Copy Markdown

CODAGT-211

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: ba6b5a72b2

ℹ️ 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 force-pushed the mike/chat-workspace-upload/agent branch from ba6b5a7 to b3afdea Compare July 7, 2026 23:02
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: b3afdea823

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 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-09-21T21:13:04.193166Z c6b45ec 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: fb509f9635

ℹ️ 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 agent/agentfiles/uploadchatfile.go Resolved
Comment thread agent/agentfiles/uploadchatfile.go Resolved
@ibetitsmike
ibetitsmike force-pushed the mike/chat-workspace-upload/agent branch from fb509f9 to c6b45ec Compare September 21, 2026 21:03
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: c6b45ec4e0

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

@github-actions github-actions Bot removed the stale This issue is like stale bread. label Sep 22, 2026
Comment thread coderd/x/chatfiles/workspace.go Resolved
@jscottmiller

Copy link
Copy Markdown
Contributor

Overall LGTM. I'm adding agent comments for issues found during manual and automated review and uat. Nothing is blocking imo, but most of these should be easy to rip through with an agent. The improved heuristics around mime types is nice to have (e.g. reject say 1+mb of text but not images), but that one feels like a follow-up.

The inline comments are spread across the stack at the relevant code; each says roughly how big the fix is. Everything is non-blocking; all five PRs are approved.

The links and the inline comments were generated by Coder Agents from the panel review and UAT; the paragraph at the top was written by Scott.

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

Approved. See the summary comment on #27078 and the non-blocking inline follow-ups across the stack.

Approval posted by Coder Agents on Scott's behalf.

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

Re-approved after the fix commits. Verified the addressed threads against the code (agent atomic publish, workspace status, normalized references, logging/metric, first-message fallback title, reasoning-effort override, Vitest coverage, archive-409 navigation) and ran the affected Go and Vitest suites; the remaining notes are acceptable as is. The three open follow-up threads are resolved as agreed follow-ups.

Approval posted by Coder Agents on Scott's behalf.

@ibetitsmike
ibetitsmike merged commit 7c74fa3 into main Sep 25, 2026
55 of 58 checks passed
@ibetitsmike
ibetitsmike deleted the mike/chat-workspace-upload/agent branch September 25, 2026 07:05
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 25, 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.

2 participants