Skip to content

fix: stop MCP servers of plugin packs no workspace chat enables - #233

Merged
ibetitsmike merged 19 commits into
mainfrom
mike/plugin-packs-17-pack-cleanup
Nov 12, 2026
Merged

ibetitsmike merged 19 commits into
mainfrom
mike/plugin-packs-17-pack-cleanup

Conversation

@ibetitsmike

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

This stops the workspace agent from running the MCP servers of plugin packs that no chat on the workspace enables. Before this change, disabling or uninstalling a managed pack only hid its tools: the server process kept running and restarted with the agent (Codex P1 on #231, and seen live in the #231 UAT).

Agent (agent/agentcontext)

  • packMCPSources skips a pack under ~/.coder/plugins/ whose .coder-pack-commit marker is missing or empty. coderd writes the marker last, so an unmarked pack is either incomplete or disabled. Packs outside the managed root behave as before.
  • The agent already re-resolves when a marker changes, so emptying it removes the pack's sources and the MCP manager stops its servers.

coderd (coderd/x/chatd)

  • materializePluginPacks plans a cleanup (fork_pack_cleanup.go). When this server holds a pack for the agent that the current chat does not enable, it takes the union of enabled packs over the workspace's non-archived chats. Each pack no chat enables gets an empty marker through WriteFile (the agent API has no delete). The pack is then forgotten, so enabling it again rewrites it and re-pins its chats.
  • A pack whose directory name another enabled pack uses is only forgotten, because the other pack owns the directory.
  • Once per agent per server process, on a pass that connects anyway, it lists ~/.coder/plugins and empties the markers of directories no chat enables. This covers packs written before a restart.
  • It only connects when there is a pack to write or a marker to clear.

Known gaps:

  • Cleanup runs on the next turn of a chat on the workspace, not when the pack is disabled.
  • After a coderd restart, a workspace whose chats enable no pack never connects, so it is not swept. With several replicas, a pack another replica wrote stays active until this replica sweeps that agent.
  • A re-enable that races a clear can leave the pack off until the workspace is rebuilt or coderd restarts.
  • A failed enablement lookup counts as not enabled, so a database error can clear an enabled pack. The next turn of the enabling chat rewrites it.
  • Pack files stay on disk; skills and agents of disabled packs are still hidden by filterPackResources.

Validation on 1f58c8d, run in a container:

  • gofmt -l on the changed files passes.
  • go build ./agent/... ./coderd/... ./enterprise/... passes.
  • go vet ./agent/agentcontext/ ./coderd/x/chatd/ passes.
  • go test ./agent/agentcontext/ ./agent/x/agentmcp/ passes.
  • go test -run 'Plugin|Pack|PinnedWorkspaceMCP' ./coderd/x/chatd/ passes.
  • Negative controls: keeping unmarked managed packs makes TestResolverPackMCPSourcesSkipsUnmarkedManagedPacks fail, and never planning a disabled pack makes TestMaterializePluginPacks/ClearsMarkerOfPackNoWorkspaceChatEnables fail.

A managed pack that no chat on the workspace enables stayed on disk with
its commit marker, so the workspace agent kept starting its MCP servers.

The agent now skips the MCP servers of a managed pack whose marker is
missing or empty. coderd empties the marker of each pack it wrote to an
agent once no unarchived chat on the workspace enables it, forgets the
pack so enabling it again rewrites it, and on the first connection to an
agent sweeps pack directories it did not write.
# Conflicts:
#	agent/agentcontext/fork_pack_mcp.go
#	agent/agentcontext/fork_pack_mcp_internal_test.go
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 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-12T06:42:53.567418Z 1f58c8d 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.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum requested this review 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: 1f58c8d33c

ℹ️ 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_pack_cleanup.go Resolved
Comment thread coderd/x/chatd/fork_pack_cleanup.go Resolved
Comment thread coderd/x/chatd/fork_pack_cleanup.go Resolved
@ibetitsmike
ibetitsmike merged commit 6592830 into main Nov 12, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/plugin-packs-17-pack-cleanup branch November 12, 2026 06:53
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum merged this PR on behalf of @ibetitsmike.

Merged after fork-ci passed on head 1f58c8d (run 43169073964), Codex review 5870255173 on that head (the P1 flags the ARCHITECTURE.md TODO, which stays for @ibetitsmike to write; four edge-case P2s declined with replies), 0 unresolved threads, local Go validation with negative controls, and a live recheck on a 1f58c8d server and agent with the laiso/cman pack: disabling the pack stopped its MCP server and emptied its marker on the next turn, re-enabling brought the server and tools back, and uninstalling stopped the server and removed the tools. Behind fork-plugin-packs.

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