Skip to content

agentHost: stop the Copilot runtime before deleting quick chat test homes - #342267

Merged
Alexandru Dima (alexdima) merged 2 commits into
mainfrom
alexdima/fix-quick-chat-scratch-enotempty
Oct 17, 2026
Merged

Alexandru Dima (alexdima) merged 2 commits into
mainfrom
alexdima/fix-quick-chat-scratch-enotempty

Conversation

@alexdima

@alexdima Alexandru Dima (alexdima) commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Fixes the Electron-Unit failures on many unrelated PRs since 2026-10-17 00:16 UTC (e.g. #342262, #342256, #342220, #341230, #342229, #342246, #342249).

Failure

1) CopilotAgent quick chat scratch directory does not discover workspace customizations from scratch:
   Error: ENOTEMPTY: directory not empty, rmdir '.../qc-home-XXXX/.copilot' (sometimes '.../.copilot/logs')
2..4) "after each" hook ...: Error: There are 1 undisposed disposables!
   at disposableTimeout ... at CopilotAgent._refreshModels

Failures 2–4 are a cascade into whichever suite runs next (CopilotAgentSession, claudeSessionCustomizationDiscovery, ...).

Cause

These tests create a CopilotAgent with a temp userHome. In the ones that call authenticate without a fake client, the real Copilot runtime starts with COPILOT_HOME=<tmp userHome>/.copilot and keeps writing there (.copilot/logs in the failing logs). Each finally called fs.rm(userHome) before disposeAgent(agent). The rm raced those writes and threw ENOTEMPTY, so disposeAgent never ran, and the agent's model refresh retry timer leaked into the next test's leak check.

It started with the Copilot SDK bump to 1.0.23-preview.5 (#342210, merged 00:14:57 UTC; first failing run created 00:16:48 UTC). I didn't confirm which SDK change introduced the writes. Seen 9 times in about 12 hours on Linux, macOS, and Windows.

Fix

In copilotAgent.test.ts, swap the cleanup order to dispose the agent (stopping the runtime) before removing the temp home, and remove it with maxRetries: 5. Five call sites:

  • createChat infers workspace-less from an omitted workingDirectory and uses a stable scratch dir
  • quick chat scratch directory › does not discover workspace customizations from scratch
  • quick chat scratch directory › session teardown cleans up the quick chat scratch dir
  • quick chat scratch directory › resume recreates a reaped quick chat scratch dir (uses a fake client; changed for consistency)
  • the scratchReclaimAfterPeerDisposal helper used by the scratch reclaim tests

Other tests in the file with the same order never call authenticate, so no runtime starts and they are left alone.

Validation

A temporary commit (dropped before review) ran npm run test-node -- --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --grep "quick chat scratch directory" in a 100x fail-fast loop. --grep did not narrow the run, so each attempt ran the whole copilotAgent.test.ts file.

  • Without the fix ([DO NOT MERGE] ci: flush out quick chat scratch ENOTEMPTY flake (baseline) #342269, run): failed on attempt 3/100 on Linux and attempt 2/100 on macOS with the same ENOTEMPTY + leak.
  • With the first commit (run): Linux and macOS ran the loop for 17+ minutes with no failure before the run was cancelled by the force-push that dropped the loop. Windows npm run test-node (full suite) passed.
  • The second commit (session teardown test) was added afterwards and is covered only by this PR's regular CI.

Not run locally (no node_modules in the worktree).

…omes

The quick chat scratch directory tests run a real CopilotAgent whose Copilot
runtime uses <tmp userHome>/.copilot as COPILOT_HOME. Since the Copilot SDK
bump to 1.0.23-preview.5 (#342210) the runtime writes into .copilot/logs while
the test's finally block removes the temp home, so fs.rm fails with ENOTEMPTY.
The throw also skipped disposeAgent, leaking the model refresh retry timer
into the leak checks of later, unrelated tests.

Dispose the agent first so the runtime is stopped, then remove the temp home
with retries.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

🟡 Changes recommended

Temporary workflow overrides disable normal coverage, and the diagnostic runner ignores the intended suite filter.

2 open issues
What changed in this PR

Fixes quick chat test cleanup races by stopping the Copilot runtime before deleting temporary homes.

Changes:

  • Reorders cleanup and adds removal retries in four tests.
  • Temporarily replaces Linux and macOS test coverage with repeated diagnostic runs.
File Description
src/​vs/​platform/​agentHost/​test/​node/​copilotAgent.test.ts Disposes agents before removing temporary homes, with retries.
.github/​workflows/​pr-linux-test.yml Adds a diagnostic loop and disables normal Linux test steps.
.github/​workflows/​pr-darwin-test.yml Adds a diagnostic loop and disables normal macOS test steps.

Review effort: Balanced

Comment thread .github/workflows/pr-linux-test.yml Resolved
Comment thread .github/workflows/pr-linux-test.yml Resolved
… test home

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Base: 06560909 Current: 7a1521e9

No screenshot changes.

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.

🟡 Changes recommended

One real-runtime quick-chat test retains the unsafe cleanup order, leaving the reported race possible.

1 open issue
2 resolved since last review

Review effort: Balanced

@alexdima
Alexandru Dima (alexdima) merged commit 230f18f into main Oct 17, 2026
86 of 87 checks passed
@alexdima
Alexandru Dima (alexdima) deleted the alexdima/fix-quick-chat-scratch-enotempty branch October 17, 2026 13:18
@vs-code-engineering vs-code-engineering Bot added this to the 1.143.0 milestone Oct 17, 2026
Alexandru Dima (alexdima) added a commit that referenced this pull request Oct 17, 2026
… Host tmpfs (#342277)

* agentHost: kill the Codex app-server's process tree on Linux

The Linux / Electron job of #342267 passed every Agent Host E2E suite but
failed to unmount the test tmpfs. The holder was an orphaned Codex
filesystem helper (`bwrap --die-with-parent ... --codex-run-as-fs-helper`,
PPID 1, still in its launcher's process group with its pre-exec argv) from
the Codex server-tools artifact test.

Codex spawns that helper without a parent-death signal or kill-on-drop, and
the Agent Host stopped the app-server by SIGKILLing only its PID. The
bubblewrap launcher then dies with its parent, but a sandbox child it has
just cloned waits on an eventfd that never reports the launcher's death and
only installs its own PR_SET_PDEATHSIG after that wait, so it blocks forever.

On Linux, freeze the app-server with SIGSTOP (so it can neither exit on the
stdin EOF that client.dispose() just queued nor launch another helper), then
kill its tree depth-first with killTree, which stops each helper while its
parent chain is still intact. Other platforms keep the plain SIGKILL.

Also skip fuser's "kernel" token when describing tmpfs holders, and document
the failure mode in KNOWN_ISSUES.md.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* agentHost: freeze and kill the Codex app-server tree synchronously

Addresses review feedback on the async killTree approach:

- SIGSTOP froze only the app-server. terminateProcess.sh lists a process's
  children before killing it, so a running bubblewrap launcher could still
  clone a sandbox child after that listing and strand it.
- The walk was asynchronous, so the client's two-second grace-period SIGKILL
  could kill the app-server, and with it the parent-bound launchers, before
  their children were found.
- The client was disposed (stdin closed) before the app-server was frozen.

killLinuxProcessTree now stops each process and waits, with a shared 100 ms
cap, until /proc reports it stopped (SIGSTOP is delivered asynchronously, so
a process inside clone() finishes it first) before enumerating its children.
It then kills every stopped process deepest first. The walk is synchronous,
so nothing else can interleave and an exiting Agent Host cannot cut it short
after freezing processes. CodexAgent runs it before disposing the client on
both teardown paths, and falls back to a PID-only SIGKILL elsewhere or when
/proc is unreadable.

Tests cover the stop-before-enumerate order, a child cloned while its parent
is still stopping, the stop deadline, an unreadable process table, stat
parsing, and (on Linux) a real three-level process tree.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* base: move the freezing tree kill next to killTree as freezeAndKillTree

Moves the Linux tree kill from agentHost/node/codex/linuxProcessTree.ts into
base/node/processes.ts as freezeAndKillTree, next to killTree, and documents
how the two differ: killTree signals an asynchronous snapshot of the tree on
every platform and is best-effort, while freezeAndKillTree freezes the tree
before killing it so no descendant can be created unseen or outlive its parent.

It now reads the parent and state from the labelled `PPid:` and `State:`
lines of /proc/<pid>/status rather than positional /proc/<pid>/stat fields
after the parenthesized command name. Tests move to
base/test/node/processes/processes.test.ts.

A process-group kill would avoid walking /proc, but does not reach the leaked
process: Codex's Linux sandbox launcher places bubblewrap in its own process
group (setpgid(0, 0) in linux_run_main.rs).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* agentHost: link the upstream bubblewrap issue for orphaned sandbox children

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* agentHost: return to killTree for the Codex app-server

Reverts the freezing /proc walk (freezeAndKillTree) in favour of the original
SIGSTOP + killTree approach: it adds a large Linux-only utility next to
killTree rather than improving the one the product already uses everywhere.
Keeps the link to the upstream bubblewrap issue.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test: reap orphaned Codex sandbox helpers before unmounting the Agent Host tmpfs

The orphaned Codex filesystem helper that keeps the Agent Host test tmpfs busy
is stranded mid-session, while its Agent Host server and app-server are still
running: the holder's age dates its clone several seconds before that server's
shutdown. It is reparented to PID 1 before any teardown, so killing the
app-server's process tree cannot reach it. This PR's own run on the
SIGSTOP + killTree change still hit the failure.

Drop that product change. In tmpfs.sh, when the unmount fails and every holder
is an orphaned Codex filesystem helper (parent PID 1 and
--codex-run-as-fs-helper on its command line), describe and kill each one,
report a GitHub Actions warning, and retry the unmount. Any other holder, or an
unmount that still fails, remains fatal with the existing diagnostics.

Document the mid-session mechanism, its impact (13 failed PR runs between
2026-10-07 and 2026-10-17), and the upstream issues (openai/codex#54877,
containers/bubblewrap#633).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test: cover reaping orphaned Codex sandbox helpers in the storage wrapper tests

The storage wrapper test snapshots the commands tmpfs.sh runs after a failed
unmount; it now also expects the orphaned Codex helper probe, which stops at
the first holder that is not one. Make the stub ps answer per field, and add a
test in which the only holder is an orphaned Codex filesystem helper: it is
described and killed, a warning is emitted, and the retried unmount succeeds.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants