Skip to content

feat(coderd/x/chatd): write enabled plugin packs into chat workspaces - #205

Merged
ibetitsmike merged 33 commits into
mainfrom
mike/plugin-packs-6-materialize
Nov 11, 2026
Merged

ibetitsmike merged 33 commits into
mainfrom
mike/plugin-packs-6-materialize

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

Third and last part of PR3 of plugin packs (R7.3), stacked on #204. chatd now writes the packs enabled for a chat into the chat's workspace, so the workspace agent discovers them and the gate from #204 shows them to that chat.

What changes

  • materializePluginPacks in coderd/x/chatd/fork_pack_materializer.go runs once per turn in buildTurnEnvironment, right after the first-turn context pin. One hook line in turn_environment.go and one forkPacks field on Server in chatd.go are the only upstream edits.
  • Each enabled pack goes to <home>/.coder/plugins/<name>/. <home> comes from chattool.ResolveWorkspaceHome. The pack's files are written with WriteFile, up to 16 at a time, each write bounded to 2 seconds and tried up to 3 times, then a .coder-pack-commit marker holding the pack's ID and commit. A matching marker skips the pack, so a restarted coderd, which has lost its in-memory record, does not rewrite it, while a pack reinstalled under the same name is written again.
  • Writes use their own agent connection from agentConnFn, without the chat headers, so the agent does not record them in the chat's git changes.
  • The server remembers (agent ID, pack ID) -> marker it wrote, so later turns on the same agent need no connection. A rebuilt workspace has a new agent ID and is written again.
  • Stored paths that are absolute, contain .., \ or :, are not clean, or name the marker are rejected before any file is written. The pack then gets no files and no marker and is retried on the next turn.
  • Once a pack reaches the agent, each chat with it enabled re-pins with RefreshChatContext on its turns whose context the agent's push has marked dirty, until it pins an agent snapshot received after the pack was written (so a push from before the write, or one that caught only part of it, does not count), so a pack enabled for a pinned chat reaches the model by the next turn without a manual refresh, including chats that share the workspace with the chat that wrote it.
  • filterPackResources also drops rows whose SKILL.md (or agent file) or manifest is not a file of the enabled pack's current commit, read once per pack and commit, since an update leaves removed files on disk.
  • The work is best effort and bounded by a 10 second timeout. Failures are logged; the turn continues.
  • Pack content is read as AsSystemRestricted: org members cannot read packs, and enabling a pack for a project or chat is what delivers its files to the chat's workspace. The pack name is validated again before it becomes a path.
  • enabledPackNames from feat(coderd/x/chatd): gate plugin packs by project and chat enablement #204 becomes enabledPacks, which also returns the ID and commit the materializer needs. A pack enabled in several places is written once per turn.
  • coderd/x/chatd/ARCHITECTURE.md gets a TODO for the materializer, for the human author.

Known limitations

  • Packs are written during a turn and reach the model from a later turn, after the agent's next context push. The first turn after enabling a pack does not see it. The automatic re-pin also takes in any other context drift the chat had, as a manual refresh would.
  • The re-pin record is in memory per replica, so after a coderd restart or on another replica a dirty chat with a pack enabled is re-pinned once more. On a cold replica, the first dirty turn finds the marker on disk without re-pinning, so the pack reaches the model one turn later.
  • While a chat is dirty and the agent has not pushed a snapshot since the pack was written, every turn of that chat re-pins.
  • The agent type picker lists a project pack's agents only after a turn has written the pack to that workspace.
  • In UAT, one of a few hundred concurrent WriteFile round trips to the agent sometimes stalled while the rest finished in milliseconds. The per-write timeout and retry work around it; its root cause (agent, tailnet or netstack) is unproven.
  • The 10 second bound covers the whole write. A pack near the 2,000 file limit on a slow workspace link may not finish, and is written again from the start on the next turn.
  • If a pack directory or marker is deleted inside the workspace, the cached record keeps it from being rewritten until the next build or coderd restart.
  • Files of disabled packs and files a pack update removed stay on disk. The gate hides them.
  • Packs live on the workspace's shared filesystem. The gate keeps a pack out of the prompt and context of chats that do not enable it, but such a chat can still read the pack's files with read_file or execute.
  • Not handled: two chats on one workspace that enable different packs defining the same skill or agent name (the agent keeps one before the per-chat gate, so one chat may see neither); a pack update that moves its manifest from .claude-plugin/plugin.json to plugin.json (the stale manifest stays on disk and hides the pack until removed files are cleaned up); two packs whose names differ only by case on a case-insensitive (Windows) workspace; concurrent turns writing the same pack (identical bytes, duplicate work only); a malformed admin-installed pack with a path under .coder-pack-commit/ (its marker write fails and it is retried each turn); symlinks a workspace user creates under ~/.coder/plugins/ redirect the writes, as the agent follows them.
  • Executable bits are not preserved: a pack script is written with the workspace's default file mode. Storing the git mode needs a schema change. The in-memory maps are not bounded; they grow with builds and pack updates and reset on restart.

Follow-ups

  • Remove files of disabled or removed packs from workspaces.
  • Preserve executable bits of pack files.
  • CLI and UI for installing packs and enabling them for projects and chats.

Validation

  • In a container: go build ./coderd/... ./enterprise/... and go vet ./coderd/x/chatd/.
  • Tests passed: TestMaterializePluginPacks (against Postgres through dbauthz: writes files concurrently then a marker naming the pack, retries a write that stalls and still completes the pack, skips a known agent and commit without connecting, re-pins each dirty chat with the pack, writer or not, retries a re-pin of a snapshot from before the write, then stops, skips the write for a new agent ID whose marker matches, writes no file and no marker for a pack with an unsafe path, does nothing with no enabled pack), TestPackResourcePath, TestManagedPackName, TestFilterPackResources (now also drops rows whose SKILL.md or manifest the pack's current commit removed), TestAgentRowDefinitionsGatesPackAgents, TestPinnedWorkspaceContext, TestContextResources, TestForkAgentDefinition*, and TestResolveTurnWorkspaceContext.

Adds the plugin_packs and plugin_pack_resources tables (chatdmig node),
their forkdb queries with dbauthz and dbmetrics wrappers, and
coderd/x/pluginpacks, which fetches one commit of a pack directory over
smart HTTP with a host allowlist and fixed size caps.

Packs reuse the organization skill RBAC object, so only organization
admins and auditors read or manage them.
The 64 MiB transfer cap does not bound memory, because go-git inflates
every fetched object into memory storage before the per-file limits run.
Read the pack first and reject it when its object headers, and the target
sizes of its deltas, add up to more than 256 MiB.
Organization admins can allowlist Git hosts and install, update, list and
delete plugin packs through /api/v2/chats/fork/organizations/{organization}
behind the fork-plugin-packs experiment. An install or update fetches the
pack, pins the resolved commit and stores its files. Members cannot see
packs and auditors can only read them.
…nstall-api

# Conflicts:
#	coderd/database/dbauthz/fork_forkdb.go
#	coderd/database/dbauthz/fork_forkdb_test.go
#	coderd/database/dbmetrics/fork_forkdb.go
#	coderd/database/forkdb/forkdbmock/forkdbmock.go
#	coderd/database/forkdb/models.go
#	coderd/database/forkdb/plugin_packs.sql.go
#	coderd/database/forkdb/querier.go
#	coderd/database/forkdb/queries/plugin_packs.sql
#	coderd/database/forkdb/sqlc.yaml
#	coderd/x/pluginpacks/fetch_test.go
…nablement-api

# Conflicts:
#	coderd/database/dbauthz/fork_forkdb.go
#	coderd/database/forkdb/forkdbmock/forkdbmock.go
#	coderd/database/forkdb/querier.go
#	coderd/database/forkdb/sqlc.yaml
#	coderd/fork_chat_routes.go
…s-6-materialize

# Conflicts:
#	coderd/x/chatd/fork_plugin_gate.go
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T18:38:44.538094Z acc1354 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: b31913f824

ℹ️ 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 coderd/x/chatd/turn_environment.go Resolved
…iles

Re-pin a chat on its first context-dirty turn after a pack write, drop pack
files the pack's current commit no longer has, record the pack ID in the
commit marker, and write packs over a connection without the chat headers so
the writes stay out of the chat's git changes.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @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: 4ae4535cc5

ℹ️ 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 coderd/x/chatd/ARCHITECTURE.md Resolved
Comment thread coderd/x/chatd/fork_plugin_gate.go Resolved
…k defining files

Re-pin each dirty chat with an enabled pack once after the pack reaches the
agent, not only the chat whose turn wrote it, and keep a pack row only when its
SKILL.md or agent file and its manifest are files of the pack's current commit.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @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: 804d553654

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

@codex review

Xum posted this on behalf of @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: b387467264

ℹ️ 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 coderd/x/chatd/fork_plugin_gate.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: e2f77113e0

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

@codex review

Xum posted this on behalf of @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: 48433f7956

ℹ️ 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 coderd/x/chatd/turn_environment.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: acc1354693

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

Base automatically changed from mike/plugin-packs-5-chatd-gating to main November 11, 2026 18:48
@ibetitsmike
ibetitsmike merged commit 86d8fd2 into main Nov 11, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/plugin-packs-6-materialize branch November 11, 2026 19:45
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum merged this PR on behalf of @ibetitsmike.

Merged as a squash of head 3e4b4f4856, on top of main 6862ebc651 (#204).

  • CI: fork-ci run 43085962623 passed on the exact head, which is based on current main. After feat(coderd/x/chatd): gate plugin packs by project and chat enablement #204 squash-merged, the lead merged main in as 3eff1309ed with a tree identical to the UAT'd acc1354693. The only later change is a test fix in fork_pack_materializer_internal_test.go: the subtests had shared the parent's expiring context, so each now creates its own.
  • UAT: run 1 on e2f77113e0 failed at step 3, because one concurrent agent WriteFile hung on each attempt and the pack never got its marker. That led to the 2 s per-write timeout with retry of only the stalled file. Run 2 on acc1354693 passed every step. pstack (573 files, pinned cursor/plugins 5866df5573) was written in turn 1 with one stalled write retried. The chat was re-pinned with 60 pack resources and no manual context refresh, a pack skill was read and a pack agent spawned. A chat outside the project saw nothing, chat-level enable and disable took effect at once, other members got 404, and with the experiment off the routes returned 403. Egress went only to GitHub during install, and the leak audit was clean.
  • Codex: clean receipt 6804223886 on acc1354693 (same non-test tree). 0 unresolved threads. Findings on unusual paths were replied to and resolved, and are listed under Known limitations.
  • Known limitations: the root cause of the WriteFile hang is unproven. Chats that have not enabled the pack can still read its files on the shared workspace filesystem.
  • Follow-up for the owner: the TODO this PR adds in "#### Generation goroutine" of coderd/x/chatd/ARCHITECTURE.md.

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.

1 participant