Skip to content

cli: prevent duplicate GitHub environment supervisors - #348010

Merged
roblourens merged 2 commits into
mainfrom
roblou/agents/debug-windows-mc-authentication-issue
Nov 16, 2026
Merged

roblourens merged 2 commits into
mainfrom
roblou/agents/debug-windows-mc-authentication-issue

Conversation

@roblourens

@roblourens roblourens commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #347703.

Repeated code agent host --github-environment commands start independent background supervisors that share one persisted environment identity but advertise different encryption keys. Clients can then reject authentication because the host answering the relay does not match the keys published by the latest heartbeat.

Hold the existing cross-process file lock for the GitHub environment supervisor's lifetime, scoped to the backend server data directory. Reject duplicate starts before prompting for credentials and recheck in the supervisor to cover concurrent first starts. Separate server data directories remain independent; ordinary local agent-host startup is unchanged.

Also force Windows process-tree termination with taskkill /f /t and check its exit status. A failed Windows termination command must not remove discovery metadata and report that the host was killed. Add Windows regression cases for a background process without a console window and failed termination.

Live validation on macOS with the rebuilt CLI: concurrent initial starts admitted one supervisor; repeated starts, foreground mode, and alternate CLI/registry directories were rejected. The remaining host answered initialize once, completed encrypted authentication, and retained matching keys across a heartbeat. Three sharing/kill cycles stopped the full observed process tree. All test hosts and environments were removed. The maintainer independently confirmed on Windows that adding /f stops the shared host; the new Windows unit tests have not been run locally.

Checks passed: cd cli && cargo build --locked --bin code; cd cli && cargo test --locked --lib commands:: --no-fail-fast (61 tests); cd cli && cargo test --locked --lib util::command::tests (1 test); cd cli && cargo clippy --locked --lib --quiet; cd cli && rustfmt --check --edition 2021 src/commands/agent_host.rs. cd cli && rustfmt --check --edition 2021 src/util/command.rs reports an existing formatting difference in the unchanged Unix process-tree test.

(Written by Copilot)

Keep one sharing supervisor per server data directory so concurrent starts cannot publish competing encryption keys for the same environment. Preserve private data-directory permissions and reject duplicate starts before authentication.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 21:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review findings remain for the supervisor identity-locking change.

No open issues 🎉

What changed in this PR

This follow-up to #347703 prevents duplicate GitHub environment supervisors from sharing a persisted identity while advertising conflicting encryption keys. Ownership is scoped to the backend server data directory; ordinary local agent-host startup remains unchanged.

Changes:

  • Reject duplicate starts before credential prompts, then recheck and hold the cross-process lock throughout the supervisor’s lifetime.
  • Add tests for duplicate rejection, lock release, directory isolation, and Unix directory permissions.
  • Document the single-supervisor restriction and how to start independent environments.

No actionable findings remain. Windows live validation was not run, as noted in the PR description.

File Description
cli/​src/​commands/​agent_host.rs Adds supervisor locking, early duplicate detection, and regression tests.
cli/​CONTRIBUTING.md Documents ownership scope, restart guidance, and independent environment configuration.

Review effort: Balanced

Use taskkill /f /t for background process trees and surface termination failures before removing discovery metadata. Cover no-console termination and failed taskkill on Windows.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@roblourens
roblourens marked this pull request as ready for review November 16, 2026 05:18
@roblourens
roblourens enabled auto-merge November 16, 2026 05:18
@roblourens
roblourens added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit 01bb4f8 Nov 16, 2026
37 of 38 checks passed
@roblourens
roblourens deleted the roblou/agents/debug-windows-mc-authentication-issue branch November 16, 2026 05:46
@vs-code-engineering vs-code-engineering Bot added this to the 1.148.0 milestone Nov 16, 2026
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.

3 participants