Skip to content

fix: preserve agent field during command expansion#3007

Open
dgageot wants to merge 2 commits into
docker:mainfrom
dgageot:board/40e4ac9c04cc88d6
Open

fix: preserve agent field during command expansion#3007
dgageot wants to merge 2 commits into
docker:mainfrom
dgageot:board/40e4ac9c04cc88d6

Conversation

@dgageot
Copy link
Copy Markdown
Member

@dgageot dgageot commented Jun 5, 2026

When invoking a slash command that targets a sub-agent via the agent: field, the routing was incorrectly going to the root agent instead of the named sub-agent. The root cause was in pkg/js/expand.go's ExpandCommands function, which rebuilt the types.Command struct field-by-field at config-load time and silently dropped the Agent field. When LookupCommand later tried to route the command, it saw an empty Agent and never switched agents.

This change fixes the bug by preserving the Agent field during command expansion. A follow-up refactor makes ExpandCommands copy the struct and overwrite only the expanded text fields (Description, Instruction), ensuring that future fields are preserved automatically and preventing this class of bug from recurring.

The fix includes unit tests in pkg/js/expand_agent_test.go and an end-to-end test in e2e/exec_command_agent_test.go with a recorded cassette and config fixture, verifying that the instruction reaches the specialist sub-agent directly. All validation checks pass: build, go vet, race tests, and the full test suites for js, cli, runtime, config, and e2e.

dgageot added 2 commits June 5, 2026 12:08
Preserves all command fields including future additions, avoiding bugs
like the Agent field loss that this change addresses.
@dgageot dgageot requested a review from a team as a code owner June 5, 2026 10:18
Copy link
Copy Markdown

@docker-agent docker-agent left a comment

Choose a reason for hiding this comment

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

Assessment: 🟢 APPROVE

The fix in pkg/js/expand.go is correct and well-tested. Copying the types.Command struct and overwriting only the Description and Instruction text fields reliably preserves the Agent field and prevents this class of bug from recurring with future fields.

The new unit test (TestExpandCommandsPreservesAgent) directly covers the regression, and the e2e test (TestExec_CommandTargetsAgent) validates the full routing path end-to-end. No bugs found in the added code.

@aheritier aheritier added area/agent For work that has to do with the general agent loop/agentic features of the app area/skills Skills system and custom slash commands kind/fix PR fixes a bug (maps to fix: commit prefix) labels Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent For work that has to do with the general agent loop/agentic features of the app area/skills Skills system and custom slash commands kind/fix PR fixes a bug (maps to fix: commit prefix)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants