Repository navigation
perf(sandbox): start the Playwright MCP server only when a turn uses it - #4117
Merged
Merged
Conversation
Every managed agent turn lists the Playwright MCP server among its tools, so every turn started it: a Node process that loads Playwright as it starts, about 100 MB of memory and a third of a second of CPU, held for the whole turn, although most turns never open a browser. tale-playwright-mcp, now a small Python proxy (about 20 MB, first answer in about 50 ms), answers the start of a turn itself — initialize, tools/list and ping — from manifests the image build records from the real server for the argument sets the platform passes (playwright-mcp-args.json, held equal to exec-builder's sets by its test). The answer to initialize is the server's own for every protocol version MCP has named, its latest for one it does not speak, so a later start negotiates the same version. On the turn's first other request it starts the server, replays the client's initialize under an id of its own, and passes every message through both ways. Unknown arguments or protocol versions, and TALE_PLAYWRIGHT_MCP_EAGER=1, start the server at once, as before. The proxy flags it adds to the server are unchanged.
…ool call Under the session container contract, the launcher with the platform's first argument set answers initialize and tools/list while no mcp-server-playwright process runs, its tool list equals the server's own, and a browser_navigate reaches the server it starts then.
The daemon's suite tests the wrappers beside it (tale-*-run, tale-playwright-mcp, tale-connectors-mcp, the hooks, entrypoint.sh), but its cache key held only the daemon workspace, so a change to a wrapper alone could replay a stale pass. Its test task now hashes them.
A ledger row for the launcher: the start answered from the build's manifests, the server started and the start replayed on the first other request, pass-through both ways, the eager fallbacks, and where each is automated.
Contributor
Author
|
Post-merge independent review of #4117 at MEDIUM: Qwen Code turns still start the real Playwright MCP server on every turn. For Qwen, the PR saves nothing and adds the proxy on top.
LOW
INFO
Verified correct:
Next owner: the manager, for a follow-up issue on the Qwen MEDIUM and the log fix. |
yannickmonney
added a commit
that referenced
this pull request
Oct 3, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Every managed agent turn — every harness — lists the Playwright MCP server among its tools, so every turn started it: a Node process that loads Playwright as it starts. Measured (Node,
require('playwright-core')): about 105 MB RSS and ~0.3 s of CPU, held for the whole turn. Most turns never open a browser. Earlier measurements put a whole Claude turn at +184 MiB, so this one idle server was a large share of what an agent session costs — and admission is by memory.What changes
tale-playwright-mcpanswers the start of a turn itself. It is now a small Python proxy (~20 MB, first answer in ~50 ms;python3 -Es, so a session's own Python packages cannot shadow its modules). It answersinitialize,tools/listandpingfrom manifests the image build records from the real server, and starts the server only on the turn's first other request — a tool call. It then replays the client'sinitialize(andnotifications/initialized, and any notification that came before) under an id of its own, and passes every message through both ways, server requests such asroots/listand the client's answers included.initializefor every protocol version MCP has named — the server's latest for one it does not speak — so the later start negotiates the same version (the launcher logs a mismatch). The server only advertisestoolsand already defers its own setup to the first tool call, so nothing else happens at start that the proxy skips.TALE_PLAYWRIGHT_MCP_EAGER=1start the server at once, exactly as before. The proxy flags (--proxy-server/--proxy-bypassfromHTTPS_PROXY/NO_PROXY) andPLAYWRIGHT_DISABLE_FORCED_CHROMIUM_PROXIED_LOOPBACKare unchanged.services/sandbox-runtime/playwright-mcp-args.json;exec-builder.tsexports its sets and its test holds the two equal (a new set without a record would start the server every turn again). The platform's test task hashes the JSON.turbo.jsonnow hashesservices/sandbox-runtime/tale-*,entrypoint.shand the args file.Verification
tale-playwright-mcp.test.ts(a stand-in server on PATH that logs what reaches it): the build's manifest (answers per protocol version), the start answered without the server (known and not-spoken versions), the start replayed on the first tool call with the client's params and only the client's answers reaching the client, aroots/listround trip, an unknown version and the eager switch starting the server at once, the server's exit status, the proxy flags, and the interpreter line.mcp-server-playwrightprocess afterinitializeandtools/list, the same tool list as the server's own, and abrowser_navigatethrough the server started on that call. (Docker on the authoring machine is down for want of disk, so CI's image build is where this runs first.)Follows #4097, #4098, #4099 and #4116.