Skip to content

Stop brokers started by the test suite - #642

Open
principalwater wants to merge 3 commits into
openai:mainfrom
principalwater:fix/test-fixture-leak
Open

Stop brokers started by the test suite#642
principalwater wants to merge 3 commits into
openai:mainfrom
principalwater:fix/test-fixture-leak

Conversation

@principalwater

Copy link
Copy Markdown

Fixes the process leak reported in #640 (see this comment).

Problem

The broker is deliberately long-lived so it can be reused across companion invocations. Nothing in the test suite shuts it down, so every workspace a test touches leaves a broker plus its app-server child running for the lifetime of the machine — and the count grows with every run:

$ node --test tests/runtime.test.mjs
$ pgrep -f "codex-plugin-test" | wc -l
58

After a handful of full-suite runs I had 114 orphaned node processes.

Change

tests/helpers.mjs now tracks the workspaces makeTempDir hands out, and exposes cleanupTempWorkspaces(), which stops each workspace's broker through the existing terminateProcessTree and then removes the directory. tests/runtime.test.mjs registers it in an after hook, passing the repository root explicitly because some tests use it as the companion cwd.

No production code is touched — this is test teardown only.

Verification

Counting processes matching codex-plugin-test three seconds after node --test tests/runtime.test.mjs:

before after
leftover processes 58 0
tests / passing / failing 61 / 58 / 3 61 / 58 / 3

Test results are unchanged. The same 3 failures (status shows phases, hints, and the latest finished job, status preserves adversarial review kind labels, result returns the stored output for the latest finished job by default) reproduce identically on an unmodified checkout, so they are pre-existing and unrelated.

Note

While looking into this I noticed the suite does not isolate CLAUDE_PLUGIN_DATA: buildEnv only prepends to PATH, so broker state is written into the developer's real plugin data directory rather than a temp one. That is a separate concern and out of scope here, but it may be worth isolating so a test run cannot disturb a live session.

The broker is deliberately long-lived so it can be reused across
companion invocations. Nothing in the suite shuts it down, so every
workspace a test touches leaves a broker and its app-server child
running for the lifetime of the machine, and the count grows with every
run.

Track the workspaces handed out by makeTempDir, and add an `after` hook
in runtime.test.mjs that stops each workspace's broker via the existing
terminateProcessTree, then removes the temp directory. The repository
root is passed in explicitly because some tests use it as the companion
cwd.

Measured on `node --test tests/runtime.test.mjs`, counting leftover
processes matching "codex-plugin-test" three seconds after the run:
before 58, after 0. Test results are unchanged at 61 total, 58 passing;
the same 3 failures reproduce on an unmodified checkout.

Co-Authored-By: Claude Opus 5 <[email protected]>
@principalwater
principalwater requested a review from a team August 13, 2026 11:43

@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: 54da005e6e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tests/helpers.mjs Outdated
Signalling the saved PID and leaving broker.json in place means a later
run against a stable workspace, such as the repository root the after
hook passes in, can reread that PID and signal whatever process has
since inherited it. It also leaves the pid file, log and session
directory behind.

Use the existing teardownBrokerSession to stop the process and remove
those artifacts, then clearBrokerSession to drop the session file.

Verified on a clean slate: after `node --test tests/runtime.test.mjs`,
leftover processes 0 and leftover broker.json files 0. Test results
unchanged at 61 total, 58 passing.

Co-Authored-By: Claude Opus 5 <[email protected]>

@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: 325d5e7de4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tests/runtime.test.mjs Outdated
ROOT is a stable workspace, so a developer may already have a live
companion session registered for the checkout. Stopping it
unconditionally meant a filtered run of this file that never starts a
broker for ROOT would still kill that session.

Sample the ROOT broker PID before any test runs, and tear it down only
when the session afterwards is present and different, which is exactly
the case where this run created it. Temp workspaces are unaffected:
they are created by makeTempDir, so they always belong to the run.

Verified from a clean slate: full `node --test tests/runtime.test.mjs`
still leaves 0 processes and 0 broker.json files, results unchanged at
61 total, 58 passing.

Co-Authored-By: Claude Opus 5 <[email protected]>
@principalwater

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

endpoint: session.endpoint ?? null,

P3 Badge Keep fixture cleanup from unlinking shared /tmp sockets

When cleanup runs after the setup and status honor --cwd test, the saved session for targetWorkspace contains only the fixture endpoint unix:/tmp/fake-broker.sock and no real broker pid. Passing that endpoint into teardownBrokerSession makes the after hook unlink /tmp/fake-broker.sock if it happens to exist, so running the suite can break an unrelated socket on a developer or CI host. Please make that fixture endpoint live under the temp workspace or avoid endpoint teardown for sessions that were not created by a real broker.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@principalwater

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: bbf6ba9a8e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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.

1 participant