Skip to content

fix(agent,coderd): defer plugin pack name dedupe until after per-chat pack filtering - #225

Merged
ibetitsmike merged 2 commits into
mainfrom
mike/plugin-packs-13-pack-dedupe
Nov 12, 2026
Merged

ibetitsmike merged 2 commits into
mainfrom
mike/plugin-packs-13-pack-dedupe

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Xum (AI agent) opened this on behalf of @ibetitsmike.

Fixes #214

What changed

The workspace agent no longer deduplicates skills and custom agent definitions from managed plugin packs (packs under ~/.coder/plugins, the only ones chatd filters per chat) against each other before it pushes the context snapshot. Name deduplication among those packs now runs in chatd, after filterPackResources drops rows from packs that are not enabled for the chat or not part of the pinned commit.

  • agent/agentcontext: a managed pack resource is dropped if an ordinary resource or an unmanaged pack uses the same name. The first managed row for each name stays in the normal pipeline and competes under the resource caps like any other row. Later managed duplicates are set aside and appended after the caps, only into spare capacity (at most 2*MaxResources rows, and only the bytes the snapshot has left). Ordinary resources and unmanaged packs keep first-wins in scan-root order, as before. The upstream resolve.go change is two hook lines plus the exemption in deduplicateSkills.
  • coderd/x/chatd/fork_plugin_gate.go: after per-chat and per-commit filtering, a dedupe pass keeps the first surviving managed pack row for each name (the lexically first pack directory, the same order the agent scans in). Ordinary and unmanaged-pack rows are never deduplicated here.
  • Tests cover managed, ordinary and unmanaged precedence in both scan orders, the stale agent file rename case, the spare-capacity bounds, and the chatd dedupe.

Behavior notes

  • Ordinary workspace resources and unmanaged packs now beat a managed pack with the same name in either scan order. Before, a managed pack scanned first could win and then be filtered away by chatd, which lost the resource.
  • With two same-named managed packs enabled for a chat, the chat sees the first pack's resource. Pack priority is not stored, so this order is deterministic but arbitrary.
  • A snapshot can exceed MaxResources (up to twice it) only when managed packs hold same-named duplicates. This stays within the 1000-row push limit coderd allows at the default cap.
  • During rollout, an older coderd paired with a new agent can show duplicate pack rows, because the old coderd does not run the dedupe pass. This clears once coderd is updated.

Validation

Ran in a container at this head: gofmt, go build ./agent/... ./coderd/..., go vet, and go test -count=3 ./agent/agentcontext/... passed. coderd/x/chatd with -run 'TestDedupePackResourceNames|TestFilterPackResources|Pack|AgentDefinition|AgentType|Skill|ContextResources' passed except TestAgentContextFilesAndSkillsLoadedIntoChat. That test also fails 3/3 on origin/main b62d2396fa in the same container, and it passes in fork-ci. fork-ci runs on the PR.

Author TODO

coderd/x/chatd/ARCHITECTURE.md (the fork-plugin-packs gating section, around line 1231) should say that the agent defers name dedupe for managed-pack skills and agents, and that filterPackResources deduplicates them by name after filtering. I left the document alone, per the repository rule.

… pack filtering

The workspace agent deduplicated skills and custom agents by name across
every pack on disk, so a disabled, deleted, or stale pack file could hide
the same-named resource of an enabled pack before chatd's per-chat and
per-commit filtering ran.

The agent now keeps same-named pack resources and only lets ordinary
workspace skills and agents shadow them. chatd deduplicates the pack rows
that survive filterPackResources, keeping the first in source order.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum requested this review 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-12T00:12:33.426942Z c848107 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: 5402341017

ℹ️ 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/agentcontext/resolve.go Resolved
Comment thread coderd/x/chatd/fork_plugin_gate.go Resolved
…d bound the copies

Only packs coderd installs under ~/.coder/plugins are filtered per chat, so
only their same-named skills and agents are deferred to chatd. Ordinary
resources and packs outside that root keep first-wins dedupe on the agent and
always shadow managed packs. Deferred copies are added after the resource
caps, within twice MaxResources and the remaining bytes, so they cannot
displace live rows or push past coderd's per-push limit. chatd dedupes only
managed rows, so an unmanaged row always wins.

Also give each parallel subtest of the chatd dedupe test its own context: the
parent's expired before the subtests ran and failed the pack lookups closed.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum requested this review on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: c8481075ff

ℹ️ 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 merged commit d53043d into main Nov 12, 2026
10 checks passed
@ibetitsmike
ibetitsmike deleted the mike/plugin-packs-13-pack-dedupe branch November 12, 2026 00:21
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum merged this PR on behalf of @ibetitsmike.

Merged by the pstack parity lead. The pull_request fork-ci run 43124702347 passed on head c848107, and its chat-tests job covers TestAgentContextFilesAndSkillsLoadedIntoChat. Codex receipt 6810419783 is clean on that head, and 0 of 2 threads are unresolved. Tests cover the change, including the rename case, both scan orders and the capacity bounds. The code sits behind fork-plugin-packs, which the daily server does not enable, so the final W6 pack UAT will cover it live. Main is ahead only by #222, which changes docs. Fixes #214. Adds an ARCHITECTURE.md Author TODO for Mike.

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.

bug(agent/agentcontext): disabled or earlier plugin packs on disk shadow same-named skills and agents in enabled packs

1 participant