Skip to content

Report a Playwright driver that never starts as one line, not a traceback - #725

Merged
max-sixty merged 2 commits into
mainfrom
fix/issue-724
Sep 15, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/issue-724

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

version check --render and version export each guard the browser launch, but
not Playwright's driver — the Node process that launch talks to. When that
process ends at startup, sync_playwright()'s context entry returns
self._playwright, which the connection callback never assigned, so the command
dies on AttributeError: 'PlaywrightContextManager' object has no attribute '_playwright'. The actual reason, Connection.init: Connection closed while reading from the driver, is printed afterwards and out of order as asyncio's
Task exception was never retrieved.

The two hosts that reach it are ordinary: a glibc older than the Node bundled in
the Playwright wheel needs, and a PLAYWRIGHT_NODEJS_PATH naming a Node older
than the driver bundle needs. Neither failure names that variable, which is the
line that settles both in seconds.

Solution

playwright_driver() in render_gate/browser.py enters the context itself.
On the AttributeError it reads the connection's init task for the reason and
raises DriverNotStarted carrying it — and reading that task is also what keeps
asyncio from printing the second traceback at all. Each gate catches it beside
its existing failed-launch guard and prints one line, in its own words, with the
reason, the Node that ran, and the variable that chooses one:

✗ render check failed — Playwright's driver did not start: Connection.init: Connection closed while reading from the driver. PLAYWRIGHT_NODEJS_PATH named /bin/false.
export needs a browser, and Playwright's driver did not start (Connection.init: Connection closed while reading from the driver), so none was ever asked for. PLAYWRIGHT_NODEJS_PATH named /bin/false.

A third host names a Node it does not have. The driver never runs at all there, so the spawn fails a step earlier than the silence above, and that OSError is read as the same DriverNotStarted, carrying the missing file. Its manager is left unentered and unexited, as with left one whose __enter__ raised: Playwright's stop asserts a transport handle the failed spawn never assigned, so exiting a failed entry answers with a private of its own instead of the file that is not there.

Both exit 1, as they did. driver_node() reads the two paths Playwright itself
reads — the variable, else the wheel's bundled driver/node — from the
package's own location rather than through playwright._impl._driver, because
this runs only where the driver already failed and a moved private would put the
traceback back. The interactive export path needs no browser and is untouched.

Testing

test_a_driver_that_never_starts_is_reported_rather_than_raised drives both
commands with PLAYWRIGHT_NODEJS_PATH naming a stub that exits without
answering, and asserts the one line plus the absence of all three shapes the
reader sees today — the raised private, the asyncio block, and any traceback.
Against the pre-fix source it fails on the raw traceback; it passes here.
Its third arm names a Node that does not exist and asserts the same shape, which fails on the cleanup's own _output private without the fix. test_an_unnamed_driver_node_is_the_installed_wheels_own covers the hint's
other arm, which the subprocess cannot reach.

The browser-gate happy path could not be exercised in this CI sandbox — Chrome
does not launch here, and test_check_render_refuses_what_only_a_browser_can_see
fails identically on unmodified main — so PR CI is the first run of it. The
context manager was verified equivalent out of band: entering and exiting
playwright_driver() produces byte-identical output to entering and exiting
sync_playwright() on the same host.

Closes #724 — automated triage

…back

Both browser gates guard the launch and neither guards the step before it.
Where Playwright's driver process ends at startup, `sync_playwright()`'s
context entry raises an AttributeError naming a Playwright private and the
real reason arrives afterwards as an unretrieved asyncio task, so a host with
an old glibc or an old PLAYWRIGHT_NODEJS_PATH Node reads a leaf bug.

`playwright_driver()` enters that context, reads the connection's init task
for the reason, and raises DriverNotStarted. Each gate reports it in its own
words beside the failed-launch line, naming the Node that ran and the
variable that chooses one, and exits 1.

Closes #724

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

One finding, inline: the new context manager exits a Playwright manager whose start() failed, which turns a mistyped PLAYWRIGHT_NODEJS_PATH into an AttributeError from Playwright's own cleanup — the shape this PR exists to remove, on the variable it exists to name. I'm pushing the fix to this branch, so it needs no decision from you.

Exiting a Playwright manager whose start() failed is the one thing the with
statement never did: where the spawn fails, Playwright's stop asserts a
transport handle it never assigned, so the cleanup's own AttributeError
replaced the missing file as the reason. Leave that manager unexited, and
read a failed spawn as the same DriverNotStarted the silent driver raises,
so a PLAYWRIGHT_NODEJS_PATH naming a Node that is not there gets the one
line too.
@max-sixty
max-sixty merged commit 0309bd0 into main Sep 15, 2026
4 checks passed
@max-sixty
max-sixty deleted the fix/issue-724 branch September 15, 2026 07:19
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.

Browser gates crash with a raw traceback when Playwright's driver fails to start

2 participants