Skip to content

test(sandbox): cover the Playwright MCP launcher's start-time paths - #5119

Closed
tale-code-bot wants to merge 6 commits into
mainfrom
test/playwright-mcp-launcher-start-paths
Closed

tale-code-bot wants to merge 6 commits into
mainfrom
test/playwright-mcp-launcher-start-paths

Conversation

@tale-code-bot

Copy link
Copy Markdown
Collaborator

Summary

Closes #4160 (task TALE-68).

The independent review of #4140 (record) left three LOW findings and four INFO notes on the Playwright MCP launcher (services/sandbox-runtime/tale-playwright-mcp). The LOW findings are start-time paths no test covered and runner environment leaking into the unit tests. This PR:

  • adds a test for each LOW path. Each new test fails on its broken variant and passes on the launcher at this head;
  • strips the launcher's settings from the environment the tests inherit;
  • settles the four INFO notes. INFO 2 and INFO 3 are fixed in code. INFO 4 is traced and held by a test. INFO 1 stays as it is, recorded as a decision.

The issue's line references are from 33aa991fe. Since then #4367 added the managed headless shell. On main (0da08205) the paths sit at:

  • :375-377: a notification is held;
  • :397: deadline.cancel();
  • :408-410: the held lines are replayed;
  • :435-462: run().

LOW findings

Finding Test Fails when
1. deadline.cancel() has no test a server that answers the replayed start outlives the deadline. With START_TIMEOUT_S = 1: answer a call, wait 1.5 s, answer another. Expects close() == 0 and empty stderr. deadline.cancel() is removed. The healthy server is SIGKILLed at 1 s, the launcher logs did not answer its start within 1 s and exits 137, and the second call is never answered.
2. Held notifications a notification sent before the server starts reaches it after the replayed start. A notifications/roots/list_changed is sent before the first tool call and does not start the server. The server then sees the replayed initialize, notifications/initialized, the notification and the tools/call, in that order. Either the hold (self.held.append) or the replay (for line in self.held) is removed.
2. A second request while the server starts a request sent while the server starts reaches it after the one that started it. A tools/call and a ping are sent back to back while the stand-in takes 0.5 s to answer the replayed initialize. Both reach the server, in order, and the server answers each exactly once. Lines after the start are dropped, or the launcher answers a ping itself once the server runs.
3. Runner environment leaks into the tests The tests take one runnerEnv: process.env without PLAYWRIGHT_MCP_*, TALE_PLAYWRIGHT_MCP_* and PLAYWRIGHT_BROWSERS_PATH. It replaces the three ...process.env spreads. On main, the suite fails 8/45 with TALE_PLAYWRIGHT_MCP_EAGER=1 exported, 8/45 with PLAYWRIGHT_MCP_CAPS=vision and 2/45 with PLAYWRIGHT_BROWSERS_PATH=/home/dev/.cache/ms-playwright. At this head it passes 50/50 under each of them and under all of them together.

PLAYWRIGHT_BROWSERS_PATH is not in the issue's list. #4367, which came after the review, made the managed-shell check read it, and Playwright users commonly export it; the worker this ran on exports it too.

The stand-in's STAND_IN_HANG becomes STAND_IN_INIT_DELAY (in seconds), so the hang test and the slow-start test share one knob. Both deadline tests share the one-second loader.

INFO notes

  1. configured_in_env matches any PLAYWRIGHT_MCP_ name. Decision: keep it, and its docstring now says why.

    • A name the server ignores costs only the lazy start.
    • An allowlist of the names 0.0.41 reads would miss a name a later server adds, and the launcher would then answer from a stale manifest.
    • PLAYWRIGHT_MCP_VERSION is an ARG of the playwright-build stage (Dockerfile:328), so it never reaches a turn's environment, and no ENV sets a PLAYWRIGHT_MCP_ name.
    • A future ENV would fail the image check with LAZY_SERVER_STARTED_EARLY.
  2. The image check never compared initialize. Fixed. container-sandbox-runtime-test.ts now compares the lazy initialize result with the real server's for every argument set, and fails with LAZY_INITIALIZE_DIFFERS when they differ.

  3. A replayed initialize that errors logged "speaks None" and carried on. Fixed: the launcher now logs the server refused its start: <the server's error>. It still carries on, and that is the decision:

    • the client was already told the start succeeded;
    • each later request still gets the server's own answer;
    • ending the server would turn one refused message into the loss of every browser tool for the turn.
  4. What Codex sends at start was not traced. Traced from source at openai/codex rust-v0.160.0, the image's CODEX_VERSION. Its MCP client is rmcp 3.2.0 (codex-rs/Cargo.toml:446). With the default config it sends three messages:

    1. initialize for 2025-06-18, with experimental: {"codex/auth-change": {}} and elicitation (codex-rs/codex-mcp/src/rmcp_client.rs:1105-1128);
    2. notifications/initialized;
    3. one tools/list whose params carry only _meta: {"progressToken": 0} (rmcp crates/rmcp/src/service.rs:880-893).

    In the default protocol mode it does not follow nextCursor (rmcp_client.rs:675-678). It sends nothing else before a tool call; resources/* goes out only when the model asks for it. The launcher answers all three without the server. The new test Codex's start is answered as the server would, still without it holds that, and it fails on a launcher that reads any tools/list params as a page request. This is a source trace only: the Codex binary was not run.

services/platform/tests/manual/reference/automation.md (the launcher's row) now names the new coverage, the refusal log and the initialize comparison.

Checklist

  • bun run check: not run in full here, because it covers the whole monorepo; CI's Checks run it at this head. Run here on the touched workspaces:
    • the whole daemon suite (bun test): 635 pass, 10 skip, 4 fail at this head. The same 4 fail on main's own sources (0da08205) in this worker. Three build the exec shim with a C compiler, which this worker lacks. The fourth expects a /healthz without the memory and egress fields that this worker's cgroup and environment add. None of the four touches the launcher;
    • the daemon's lint (oxlint, type-aware) and typecheck: both exit 0;
    • oxfmt --check and oxlint on the changed files: clean;
    • bun run lint:manual: ok;
    • the conflict-marker check: run by the commit hook.
    • Not run: the platform workspace's typecheck. In that workspace the change is a string literal (the node script) and a comment.
  • bun run lint:sast: not run locally. Its script downloads the Opengrep binary outside any lock file, and the commit hook skipped it as uncached. The SAST workflow runs it on this PR.
  • Translations: N/A, no user-visible string.
  • Docs: N/A, no user-visible change. The new log line is the launcher's stderr.
  • README.md / README.de.md / README.fr.md: N/A. services/sandbox-runtime/README.md doesn't describe the logs and needs no change.

Test plan

In services/sandbox-runtime/daemon:

  • bun test src/tale-playwright-mcp.test.ts passes 50/50.
  • With TALE_PLAYWRIGHT_MCP_EAGER=1, PLAYWRIGHT_MCP_CAPS=vision or PLAYWRIGHT_BROWSERS_PATH=/elsewhere exported, the suite still passes 50/50. The same exports on main fail 8, 8 and 2 tests.
  • Each mutant was applied to the launcher, the whole suite was run, and the launcher was restored. Results at 263e099e674e3f54df119a649990003327a01aef:
Mutant Result
deadline.cancel() removed 49/50; only outlives the deadline fails
self.held.append(line) removed 49/50; only a notification sent before the server starts… fails
the held-line replay removed 49/50; same test fails
lines after the start dropped 43/50; a request sent while the server starts… fails, along with 6 tests that also pass messages through
the launcher answering a ping itself once the server runs 49/50; only a request sent while the server starts… fails
the refusal branch removed 49/50; only a started server refusing the replayed start… fails. Its stderr reads the server speaks None, the client was told 2025-06-18.
any tools/list params read as a page request 49/50; only Codex's start… fails
  • Image check, outside Docker. The new initialize comparison was run outside Docker: the node script from container-sandbox-runtime-test.ts, with the suite's stand-in as mcp-server-playwright and this launcher as tale-playwright-mcp.
    • With the recorded manifests it prints MCP_LAZY_OK.
    • With a manifest whose recorded initialize claims server version 0.0.40 against the server's 0.0.41, it fails with LAZY_INITIALIZE_DIFFERS.
    • The check as it is on main passes over that drift.
  • Not run here: the container check against the real image, because this worker has no Docker daemon. Build's Validate images job runs it against the image built from this PR.

The launcher tests spread process.env into every launcher they spawn. A
developer who exported TALE_PLAYWRIGHT_MCP_EAGER=1 or a PLAYWRIGHT_MCP_*
setting saw 8 of the 45 tests fail. One with a PLAYWRIGHT_BROWSERS_PATH of
their own, which the managed-shell check reads, saw 2 fail. Every spawn now
starts from the runner's environment less those settings.

Refs #4160
The #4140 review found three start-time paths of the launcher that no test
held. Each new test fails on its broken variant and passes on the launcher
as it is:

- A server that answers the replayed start outlives the deadline. With
  deadline.cancel() removed, it is SIGKILLed at the deadline and the
  launcher exits 137 mid-turn.
- A notification sent before the server starts reaches it after the
  replayed start. The test fails when the launcher stops holding the
  notification or stops replaying it.
- A request sent while the server starts reaches it after the request that
  started it. The test fails when lines after the start are dropped, or
  when the launcher answers a ping itself instead of the server.

The stand-in's STAND_IN_HANG becomes STAND_IN_INIT_DELAY (seconds), so the
hang and the slow start share one knob. The one-second-deadline loader is
shared by both deadline tests.

Refs #4160
When the started server answered the replayed initialize with an error,
the launcher logged "the server speaks None, the client was told <v>". It
now logs the refusal and the server's error. The turn still goes on: the
client was already told the start succeeded. Each request still gets the
server's own answer. Ending the server would turn one refused message into
the loss of every browser tool for the turn.

The test's stand-in refuses initialize under STAND_IN_INIT_REFUSED. On the
launcher before this change the test fails with the "speaks None" line.

Refs #4160
The #4140 review noted that configured_in_env matches any PLAYWRIGHT_MCP_
name, the Dockerfile's own build ARG PLAYWRIGHT_MCP_VERSION included. That
is the intended trade, now stated where the match is made. A name the
server ignores costs only the lazy start. A list of the names this server
reads would miss one a later server adds, and answer from a stale
manifest.

Refs #4160
The image's container check compared the launcher's tool list and its
prompt and resource list answers with the real server's, for every
argument set. It never compared the initialize answer, as the #4140 review
noted. It now compares that answer too, so a recorded start that drifts
from the server it names fails the check with LAZY_INITIALIZE_DIFFERS.

Refs #4160
The #4140 review noted that nobody had traced what Codex sends at the start
of a turn. Traced from source at rust-v0.160.0, the image's pin, whose MCP
client is rmcp 3.2.0, it sends:

1. initialize for 2025-06-18, with experimental and elicitation
   capabilities;
2. notifications/initialized;
3. one tools/list whose params carry only _meta.progressToken.

Nothing else is sent before a tool call. The launcher answers all three
without the server. The new test holds that, and it fails on a launcher
that reads any tools/list params as a page request.

Refs #4160

@tale-review-bot tale-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Requesting changes at 263e099e674e3f54df119a649990003327a01aef. Nothing in the code needs to change: a runner time limit cut off a required check.

  • The code holds. The review found nothing.
    • bun test src/tale-playwright-mcp.test.ts passes 50/50, and still passes with the runner's Playwright settings exported.
    • Each new test fails on its broken variant: deadline.cancel() removed, the hold removed, the refusal log reverted.
    • The base sources fail 8 of 45 with TALE_PLAYWRIGHT_MCP_EAGER=1 exported.
  • Failed: CI ready (SAST) (SAST run 40962786204). Its Opengrep job 123759594494 ran 22:21:55–22:37:13Z and was cancelled at its 15-minute limit, in "Verify scanner reporting and blocking behavior". This PR doesn't touch the scanner. Opengrep hits that limit across the repository under the current runner load.
  • The other runs on this head merge into 0da082051:
    • Checks 40962786301 passed every job it ran; its gate is still queued.
    • Security, Commitlint and CLI are green.
    • E2E and Build are still pending.

To make it right: run this PR's checks again at the same head (draft→ready), preferably once the Actions queue is shorter.

@yannickmonney

Copy link
Copy Markdown
Contributor

The autonomous cycle now lands each task through the merge train instead of its own pull request (.agents/repo.md on train), so this pull request closes. The branch test/playwright-mcp-launcher-start-paths stays and the task goes on with it: the Reviewer reviews the branch's head on the task and squashes accepted work onto train.

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.

Follow-ups from the #4140 review: untested start-deadline cancel, held notifications and runner env leakage in the Playwright MCP launcher tests

3 participants