Skip to content

--agent <name> selection is dropped ~1s after startup (race with sign-in / MCP reload) #5124

Open

Description

@wzhmvz

Describe the bug

When starting the CLI with --agent <name>, the custom agent is selected and then silently deselected ~1 s later, before any user input. The banner shows Selected custom agent: my-agent, then MCP Servers reloaded: 1 server connected, and the agent disappears from the status bar; the session falls back to the default agent.

It looks like a race between the startup agent selection and the agent/MCP refresh after sign-in. events.jsonl of an affected session (no user input in between):

14:59:11.603 subagent.selected {"agentName":"my-agent"}
14:59:11.765 subagent.selected {"agentName":"my-agent"}
14:59:11.717 subagent.selected {"agentName":"my-agent"}   <- out of order, concurrent re-selection
14:59:12.400 subagent.deselected {}

The deselect follows Signed in to https://github.com and the MCP client re-init in the process log (Service initialized as client -> task cancelled -> Service initialized as client).

Affected version

1.0.95

Steps to reproduce the behavior

  1. Have a custom agent available (user-level ~/.copilot/agents/my-agent.md, or plugin-provided).
  2. Start interactively: copilot --agent my-agent
  3. Don't type anything; watch the banner and status bar for ~2 s.
  4. Agent is gone from the status bar; events.jsonl shows subagent.deselected.

Expected behavior

The agent passed via --agent stays selected for the whole session.

Additional context

  • Frequency (automated pty launches, no input, 15 s each): dropped 5/6 with a user-level agent (--agent my-agent), 4/6 with a plugin agent (--agent myplugin:my-agent).
  • When MCP startup failed (Failed to start MCP Servers: session not found), the agent was never dropped, which points to the MCP reload / agent-list refresh path clearing the selection.
  • Workaround: run /agent my-agent after startup.
  • macOS (Apple Silicon, arm64), zsh, launched via shell alias with --allow-all and several --deny-tool flags.

Activity

  1. added theissue type on Oct 12, 2026
  2. added
    area:agentsSub-agents, fleet, autopilot, plan mode, background agents, and custom agents
    and removed on Oct 13, 2026
  3. jonathan-vella commented on Oct 20, 2026

    @jonathan-vella

    Reproduced in the GitHub Copilot App (Windows, copilotVersion 1.0.99-2) with a plugin agent (upgrade-agent:upgrade, from microsoft/upgrade-agent-plugins 1.1.685). 9/9 sessions dropped the agent, including sessions created by the app UI and by create_session with a kickoff agent. It happens before the first user message.

    session.start -> subagent.selected -> subagent.selected -> [session.permissions_changed] -> subagent.deselected   (all within 2-5 s)
    

    After the deselect the system prompt is the generic default one and the agent's MCP tools (Upgrade/*) are never attached, so the agent's workflow cannot run. Nothing is shown to the user.

    Ruled out (controlled runs, same project and prompt) - the agent is still dropped when:

    • the plugin agent file's YAML parse warning is fixed
    • the agent's mcp-servers block is removed entirely
    • the agent's MCP server is replaced by a working stub exposing all 9 tools (so it is not an MCP startup failure)
    • the .NET 10 SDK is installed (the real server uses dnx)
    • permission mode is Manual instead of allow-all (session.permissions_changed is then absent, but the deselect still happens)
    • an unrelated extension plugin is removed

    Supports the race hypothesis in this issue: the one session that kept the agent was blocked on a pending extension permission.requested ("register hooks") during startup and never completed it until the session was aborted. Startup stalled -> no deselect. This matches "when MCP startup failed, the agent was never dropped", i.e. the post-create refresh path clears the selection.

    So the app is affected as well as the CLI. Selecting a plugin agent as the session agent at creation is currently not reliable there; the app has no equivalent of the /agent <name> workaround at startup.

    Side finding, separate from this bug: the app host's YAML parser rejects agents/upgrade.agent.md ("flow content must be indented more than the surrounding block", closing ] of a multi-line args: [...] at the same indent as args:); PyYAML and the JS yaml package accept it. I'll report that on the plugin repo.

  4. jonathan-vella commented on Oct 20, 2026

    @jonathan-vella

    Correction to my comment above: the real variable was folder trust, not the stalled permission prompt.

    config.json's trustedFolders entry for the project was written 24 s before the one session that kept the agent selected; every session that dropped the agent ran against the same folder while it was still untrusted. Re-tested after trusting the folder: the agent stayed selected across multiple sessions, its MCP tools attached, and it ran get_state / get_scenarios / get_instructions / initialize_scenario normally. So in the App, this isn't a race at all — an untrusted workspace silently falls back to the default agent instead of surfacing a trust prompt or error for the selected plugin agent. Apologies for the earlier mischaracterization.

    Separately (same trusted session): once sandboxing was also enabled for the project, initialize_scenario's write under .github/upgrades/scenarios/... failed with "Access … is denied," even though real filesystem ACLs allow the write and the sandbox policy panel shows the workspace as read/write. So the sandbox's read/write grant isn't reaching this MCP server's process. Likely intentional scoping rather than a bug, but worth documenting: a plugin MCP server that writes inside the workspace needs an explicit sandbox allowance, or sandboxing needs to be off, even though the UI says the workspace itself is writable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:agentsSub-agents, fleet, autopilot, plan mode, background agents, and custom agents

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions