Skip to content

fix(sandbox): keep Qwen Code discovery from starting Playwright MCP - #4140

Merged
yannickmonney merged 2 commits into
mainfrom
fix/playwright-mcp-discovery-stays-lazy
Oct 3, 2026
Merged

yannickmonney merged 2 commits into
mainfrom
fix/playwright-mcp-discovery-stays-lazy

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Follow-ups from agent #2's post-merge review of #4117 (record 5967420579), all in the lazy Playwright MCP launcher (services/sandbox-runtime/tale-playwright-mcp).

What changed

MEDIUM: Qwen Code turns no longer start the server during discovery.

  • The cause, from the pinned bundle: at the start of every turn, Qwen Code 0.23.3 (chunks/chunk-N7VWZDWW.js, discoverAndReturn → listMcpPrompts / listMcpResources) sends raw prompts/list and resources/list with params: {}, beside tools/list. It does this whenever the server does not advertise the capability, and it reads code -32601 / Method not found as an empty list.
  • The fix: the launcher now answers prompts/list, resources/list and resources/templates/list with {"code":-32601,"message":"Method not found"} while the recorded initialize capabilities lack prompts (or resources).
    • That is exactly what the pinned server's bundled SDK sends for a method it has no handler for ([email protected], lib/mcpBundleImpl.js, _onrequest).
    • The pinned server advertises {tools: {}} only (lib/mcp/sdk/server.js).
    • When a recorded capability does advertise a list, that list is still left to the server.
  • The other harnesses, from their pinned bundles:
    • Gemini CLI 0.59.0 lists prompts and resources only when they are advertised (discoverPrompts / discoverResources check getServerCapabilities()).
    • OpenCode 1.17.3 (the opencode-linux-x64 binary) gates its prompt list on getServerCapabilities()?.prompts.
    • Claude Code 2.1.283 (the claude-code-linux-x64 binary) uses an SDK whose listPrompts() / listResources() return an empty list, with nothing sent, when the capability is not advertised.
    • OpenClaw 2026.6.11 lists them only on demand.
    • Codex 0.142.5, a Rust binary, was not read.
    • Whatever a harness sends, the launcher now answers these three lists as the server would. Any other request it cannot answer still starts the server, so a gap costs the saving, never correctness.

LOW: the version-mismatch log. The started server's protocol version is now compared with the version the client was told (the manifest's answer), not the version it asked for.

  • Qwen asks for 2025-11-25, its SDKs' LATEST_PROTOCOL_VERSION, and the pinned server answers 2025-06-18.
  • Before, every lazy Qwen start therefore logged an untrue mismatch, and a real one went unlogged.

LOW: PLAYWRIGHT_MCP_* settings. Any non-empty PLAYWRIGHT_MCP_* variable starts the server at once. The manifest is keyed by the arguments only, but PLAYWRIGHT_MCP_CAPS, PLAYWRIGHT_MCP_CONFIG and the others change the server's tools.

LOW: a session-installed @playwright/mcp.

  • The manifest now records the file it was recorded from: the realpath of mcp-server-playwright as PATH finds it.
  • A turn whose PATH finds another file starts that server at once.
  • The lazy start runs the exact path the launcher checked, so PATH is not resolved a second time.

LOW: a hung start.

  • A server that does not answer the replayed initialize within START_TIMEOUT_S (120 s, the same bound the image build gives the server) is killed.
  • The launcher logs the server did not answer its start within 120 s, ending it and exits with the server (137). The client then sees the server gone instead of a tool call that waits.

INFO: the container check covers argument set [0] only.

  • container-sandbox-runtime-test.ts now runs for every argument set in /opt/tale/playwright-mcp/args.json:
    • it sends Qwen Code's three discovery lists;
    • it checks the server is still not running;
    • it requires the tool list and the three list answers to equal the image's own server's.
  • browser_navigate still runs on set [0].

Also:

  • The existing unit test "runs through its own interpreter line" now clears HTTPS_PROXY / NO_PROXY. On main it failed in any runner whose environment carries a proxy, this agent sandbox included.
  • Updated with the code: the register row in tests/manual/reference/automation.md (the Playwright MCP row, formerly :192), the launcher's docstring, services/sandbox-runtime/README.md and the Dockerfile comment.

Decisions on the remaining INFOs

  • The shebang resolves python3 from a session-writable PATH: no change. The launcher runs as the agent's own user, inside the agent's own session. A python3 the session puts first on PATH can do nothing the session cannot already do. Pinning an absolute interpreter would also tie the script to the base image's layout, while the unit tests run it with the host's python3.
  • TALE_PLAYWRIGHT_MCP_EAGER is wired nowhere: kept as the documented manual switch (README) for an operator who suspects a manifest. No platform setting sets it, by design.
  • The argument-set test checks the export, not what buildMcpServers emits: not changed here.
    • buildMcpServers and the Codex path build the args from the same constants the export lists (PLAYWRIGHT_MCP_ARGS, PLAYWRIGHT_VISION_ARGS).
    • golden-exec.test.ts pins every harness's args byte for byte.
    • If the two ever drift, the image has no manifest for the new set, so the server starts at once: the saving is lost, never correctness.
    • Parsing each dialect (JSON settings, Codex -c TOML, OpenCode command arrays) out of the golden execs is a follow-up if the reviewer wants it.

How I verified it

  • Unit tests, services/sandbox-runtime/daemon/src/tale-playwright-mcp.test.ts (bun test):
    • Against main's launcher, the new tests fail: 7 fail / 11 pass.
    • The 7 failures: the manifest's server file, Qwen's discovery (a started line), both version-log cases, PLAYWRIGHT_MCP_CAPS, a session server first on PATH, and the hung start (a 5 s timeout).
    • Against this head: 18 pass / 0 fail.
    • The Qwen test sends Qwen's discovery sequence and requires the stand-in's log to stay empty, with no started line: initialize asking for 2025-11-25, notifications/initialized, prompts/list {}, resources/list {}, tools/list {}, resources/templates/list {}.
  • Mutation checks, each turning its own test red:
    • answering the lists whatever the capabilities say fails "a list the server advertises is the server's to answer";
    • dropping deadline.start() fails the hung-start test.
    • Both mutants were restored from backup copies.
  • The real pinned server, locally, with no browser:
    • I installed @playwright/[email protected] (Playwright 1.56.0-alpha-2025-10-01, browser download skipped).
    • I recorded manifests with each launcher for both argument sets of playwright-mcp-args.json.
    • I ran the container check's script with browser_navigate removed. The script is attached to TALE-501.
    • This head: MCP_LAZY_DISCOVERY_OK 21. For both sets, the server was not running after discovery, and the tool list and the three -32601 answers equal the real server's own.
    • main's launcher: LAZY_SERVER_STARTED_EARLY 0. The MEDIUM reproduced against the real server.
  • Lint and types:
    • oxlint --type-aware on the changed .ts files: clean.
    • tsc --noEmit for @tale/sandbox-runtime-daemon: clean.
    • oxfmt ran through the pre-commit hook.
    • bun run lint:manual: ok.
  • The container check itself needs the image build; per the dispatch, CI runs it (build.yml, "Validate sandbox runtime behavior").

Closes #4126

Qwen Code 0.23.3 asks every MCP server for prompts/list and
resources/list at the start of every turn, whatever the server
advertised. The lazy Playwright MCP launcher from #4117 had no answer
for them, so the discovery itself started mcp-server-playwright on
every Qwen turn.

The launcher now answers prompts/list, resources/list and
resources/templates/list with the server's own -32601 Method not found
while the recorded capabilities lack prompts or resources, and leaves
them to the server when it advertises them.

Also from the #4117 review:
- the started server's protocol version is compared with the version
  the client was told, not the one it asked for;
- PLAYWRIGHT_MCP_* settings in the environment start the server at once;
- the manifest records the server file it was recorded from, and a
  server the session put ahead of it on PATH starts at once;
- the container check sends Qwen Code's discovery and covers every
  argument set.

Refs #4117
The lazy launcher replays the client's initialize to the server it
starts on a turn's first tool call and waited for the answer without a
bound, so a server whose start hangs stalled that tool call for as long
as the client waits. After two minutes, the same bound the image build
gives the server, the launcher now logs it, kills the server and exits
with it, and the client sees the server gone.

Refs #4117
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent review of PR #4140 at 59a565ebc58289beba76baa87e318b1b1c3f8999: accepted, with LOW test follow-ups.

Runtime (mine)

Launcher script Your 18 tests (daemon/src/tale-playwright-mcp.test.ts, bun test)
head 18/18
main 1ba77ed61's tale-playwright-mcp, with the head's tests 7 fail, including "Qwen Code's discovery is answered as the server would, still without it", the two version-log cases and "a server that never answers the replayed start is ended at the deadline"

Source, checked against the pinned bundles by one read-only reviewer (@playwright/mcp 0.0.41, Qwen Code 0.23.3, OpenClaw)

  • initialize: answered verbatim from the build-time manifest for the requested version. An unprobed version starts the server.
  • tools/list:
    • The pinned server's list depends only on config.capabilities, never on the client.
    • Arguments (the manifest key), the environment (PLAYWRIGHT_MCP_* starts the server at once) and a different server file all fall back correctly.
    • The container check compares the full JSON for both argument sets the sandbox passes: the base set, and base plus --image-responses omit.
  • prompts/list and resources/list: answered with the SDK's exact MethodNotFound, which Qwen turns into [].
  • Ordering while the server starts:
    • ping and held notifications are replayed.
    • The triggering call is sent after the replay.
    • A failed or hung start exits (for/else, or the deadline kill with exit 137), so the client is never left hanging.
  • Lifecycle:
    • The server starts at most once.
    • EOF before any tool call exits 0 with no child.
    • Signals are forwarded.
  • Security: model input only travels as JSON on stdin. The command line is the resolved server path plus the harness and proxy arguments.
  • The mismatch log now compares with the version the client was told. Claude Code and Qwen log nothing.

LOW (test gaps; the code is correct today)

  1. deadline.cancel() (tale-playwright-mcp:328) has no test. If it were removed, a healthy server would be SIGKILLed at 120 s, mid-turn.
    • Test: START_TIMEOUT_S = 1 with a normal stand-in. Answer a call, wait 1.5 s, answer another, then expect close() == 0 and empty stderr.
  2. Held notifications, and a second request sent while the server starts, are untested (:306-308,339-341,367-374).
    • Tests: a roots/list_changed before the first tool call; tools/call plus ping sent back to back during a slow initialize.
  3. The unit tests inherit PLAYWRIGHT_MCP_*/TALE_PLAYWRIGHT_MCP_EAGER from the runner's environment (baseEnv spreads process.env). A developer with one of those exported sees six false failures. Fix: strip the keys.

INFO

  • configured_in_env matches any PLAYWRIGHT_MCP_ name, including the Dockerfile's own ARG PLAYWRIGHT_MCP_VERSION. That's harmless today, and the container check would catch a future ENV.
  • The container check never compares the lazy initialize answer with the real server's.
  • A replayed initialize that errors logs "speaks None" and carries on.
  • What Codex sends at start wasn't traced.

Whole-PR CI at the exact head

  • Workflows: all six ran at attempt 1 and succeeded: Checks 37129379477, Build 37129379416, E2E 37129379467, SAST 37129379415, Security 37129379466 and Commitlint 37129379417.
  • Check runs: 53 success, 13 skipped by design and Trivy neutral.
  • Backend integration: skipped by design. Integration scope says "touches nothing the backend integration suite runs".
  • Validate images (job 111221914566) ran your container block against the built image: 93 passed.

Merge: squash with --match-head-commit through my gate, which dry-runs first.

@yannickmonney
yannickmonney merged commit 33aa991 into main Oct 3, 2026
@yannickmonney
yannickmonney deleted the fix/playwright-mcp-discovery-stays-lazy branch October 3, 2026 17:19
tale-code-bot added a commit that referenced this pull request Oct 29, 2026
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-code-bot added a commit that referenced this pull request Oct 30, 2026
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
tale-code-bot added a commit that referenced this pull request Oct 30, 2026
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
tale-code-bot added a commit that referenced this pull request Oct 30, 2026
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
tale-code-bot added a commit that referenced this pull request Oct 30, 2026
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 pushed a commit that referenced this pull request Oct 30, 2026
The independent review of #4140 left the Playwright MCP launcher with
start-time paths that no test held, unit tests that inherited the
runner's launcher settings, and four open notes.

- New tests hold that a server answering the replayed start outlives the
  start deadline, that a notification sent before the start reaches the
  server after it, and that a request sent while the server starts
  reaches it after the one that started it. Each fails on its broken
  variant: deadline.cancel() removed, the hold or its replay removed,
  lines after the start dropped, or a ping answered by the launcher.
- The tests strip PLAYWRIGHT_MCP_*, TALE_PLAYWRIGHT_MCP_* and
  PLAYWRIGHT_BROWSERS_PATH from the environment they inherit. Exported
  in a developer's shell, one of them failed up to 8 of the 45 tests.
- A started server that refuses the replayed initialize is now logged
  as refusing it, instead of as speaking "None". The turn still goes on,
  because the client was already told that the start succeeded.
- The image check now also compares the lazy initialize answer with the
  real server's (LAZY_INITIALIZE_DIFFERS).
- configured_in_env keeps matching every PLAYWRIGHT_MCP_ name, and its
  docstring now says why.
- Codex 0.160.0's start, traced from its source, is answered without
  the server, and a test holds it. The start is an initialize for
  2025-06-18, notifications/initialized, and one tools/list carrying
  _meta.progressToken.

Closes #4160
Task: TALE-68
yannickmonney pushed a commit that referenced this pull request Oct 30, 2026
The independent review of #4140 left the Playwright MCP launcher with
start-time paths that no test held, unit tests that inherited the
runner's launcher settings, and four open notes.

- New tests hold that a server answering the replayed start outlives the
  start deadline, that a notification sent before the start reaches the
  server after it, and that a request sent while the server starts
  reaches it after the one that started it. Each fails on its broken
  variant: deadline.cancel() removed, the hold or its replay removed,
  lines after the start dropped, or a ping answered by the launcher.
- The tests strip PLAYWRIGHT_MCP_*, TALE_PLAYWRIGHT_MCP_* and
  PLAYWRIGHT_BROWSERS_PATH from the environment they inherit. Exported
  in a developer's shell, one of them failed up to 8 of the 45 tests.
- A started server that refuses the replayed initialize is now logged
  as refusing it, instead of as speaking "None". The turn still goes on,
  because the client was already told that the start succeeded.
- The image check now also compares the lazy initialize answer with the
  real server's (LAZY_INITIALIZE_DIFFERS).
- configured_in_env keeps matching every PLAYWRIGHT_MCP_ name, and its
  docstring now says why.
- Codex 0.160.0's start, traced from its source, is answered without
  the server, and a test holds it. The start is an initialize for
  2025-06-18, notifications/initialized, and one tools/list carrying
  _meta.progressToken.

Closes #4160
Task: TALE-68
tale-code-bot added a commit that referenced this pull request Oct 30, 2026
The independent review of #4140 left the Playwright MCP launcher with
start-time paths that no test held, unit tests that inherited the
runner's launcher settings, and four open notes.

- New tests hold that a server answering the replayed start outlives the
  start deadline, that a notification sent before the start reaches the
  server after it, and that a request sent while the server starts
  reaches it after the one that started it. Each fails on its broken
  variant: deadline.cancel() removed, the hold or its replay removed,
  lines after the start dropped, or a ping answered by the launcher.
- The tests strip PLAYWRIGHT_MCP_*, TALE_PLAYWRIGHT_MCP_* and
  PLAYWRIGHT_BROWSERS_PATH from the environment they inherit. Exported
  in a developer's shell, one of them failed up to 8 of the 45 tests.
- A started server that refuses the replayed initialize is now logged
  as refusing it, instead of as speaking "None". The turn still goes on,
  because the client was already told that the start succeeded.
- The image check now also compares the lazy initialize answer with the
  real server's (LAZY_INITIALIZE_DIFFERS).
- configured_in_env keeps matching every PLAYWRIGHT_MCP_ name, and its
  docstring now says why.
- Codex 0.160.0's start, traced from its source, is answered without
  the server, and a test holds it. The start is an initialize for
  2025-06-18, notifications/initialized, and one tools/list carrying
  _meta.progressToken.

Closes #4160
Task: TALE-68
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 #4117 review: Qwen Code still starts the Playwright MCP server on every turn, and the version-mismatch log compares the wrong values

1 participant