Repository navigation
fix(browser): fold loopback spellings into one attach admission key - #1604
Conversation
A CDP endpoint serves every loopback stack on one port, but the attach admission key was built from the endpoint origin string, so scenarios attaching through http://127.0.0.1:PORT and http://[::1]:PORT produced two lease keys, passed admission in parallel and the browser rejected the second client. Collapse literal loopback hostnames to one identity in the lease key (port and target still partition it) without touching endpoint validation. Validation: npx vitest run src/browser/PlaywrightScenarioBrowser.test.ts (9 passed; the two new loopback tests failed before the fix), npx vitest run src/browser src/domain (1745 passed, 2 failed, both failing on pristine main), npm run test:fast (3896 passed, 12 failed, 7 skipped; the failure set is identical on pristine main at 3894 passed), plus typecheck, oxlint, oxfmt and resolved module-boundary verification.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
TL;DR: With this PR, I tested the head
Two different browsersI started two Chromium browsers and put a proxy on If the two browsers shared one target id, the PR would give both one key, and one would wait for the other. I could not test that. Target ids are random, and in six pairs they always differed. The lease only gates when a connection starts. Each attach still dials its own endpoint (I read Does one port serve both stacks?The PR body says one browser serves every loopback stack on one port. For headless Chromium 154 I could not confirm that. It listened on The new testsOn main, both new tests fail for the right reason: the keys differ, and Not run
Thanks, akushonkamen, for the fix and for tests that fail on main for the right reason. Commands# trees: git archive <sha> | tar -x, then npm ci && npm run build (Node 24.18.0)
# browser, headless: chromium-browser --headless=new --remote-debugging-port=P \
# --remote-allow-origins='*' --password-store=basic --user-data-dir=<fresh dir>
# proxy: Node TCP server on [::1]:P piped to 127.0.0.1:P (or to a second browser's port)
# key: node key.mjs <tree> P Q
# 2 providers: createBrowserScenarioProvider(process.env) once per capture, Promise.all
# MCP: two capture_browser_scenario calls over stdio, Promise.all
# tests: npx vitest run src/browser/PlaywrightScenarioBrowser.test.ts
# main run: the PR's test file copied over main's
# lint/types: npm run check:fast (fresh clone, git checkout --detach 3361ad116)
# each run: env -i, fake HOME, no D-Bus, ulimit -c 0, nice -n 10Raw outputTest setup
🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
Welcome to REA, @akushonkamen! Thanks for making loopback spellings share the attach admission key and testing concurrent connections. Requests for the same target now queue together when one uses IPv4 and the other IPv6 loopback. Squash-merged. |
Summary
Fixes #1497. A single CDP browser serves every loopback stack on one port, but the attach admission lock was keyed by the endpoint origin string, so two concurrent connect-mode captures naming the same browser as
http://127.0.0.1:9222andhttp://[::1]:9222took two admissions and the browser rejected the second client.Note on issue state: #1497 was closed as resolved by b4db35f (#1513). That change keyed admission on the normalized
/json/versiondiscovery URL, which fixed trailing-slash spellings but kept the origin string as the basis, so the bracketed-IPv6 spelling still produced a second key. The regression tests below fail on currentmainfor exactly that spelling and pass with this change.Problem and expected behavior
connectscenarios withcdp_endpointhttp://127.0.0.1:9222andhttp://[::1]:9222, sametarget_id, started concurrently.browserEndpointSchemanormalizes the endpoint tourl.origin(src/domain/browserObservation.ts:36-38), andattachedScenarioLeaseKeyserialized that origin (src/browser/PlaywrightScenarioBrowser.ts:190), so the two spellings yielded two lease keys and passed admission in parallel — matching @CassieFox23's reproduction where the browser refuses the second CDP client.Change and scope
attachedScenarioLeaseKey(src/browser/PlaywrightScenarioBrowser.ts:190-201) folds a literal loopback hostname to127.0.0.1before serializing the key, using the existing domain helperisLiteralLoopbackHostname(src/domain/browserObservation.ts:42-43). The port andtarget_idremain partition keys, so distinct ports and targets still get distinct admissions. Endpoint schema validation and rejection behavior are unchanged; no cleanup semantics change beyond both spellings now sharing a single admission owner.Contract and boundary impact
PlaywrightScenarioBrowser).docs/public/product-catalog.json), package, or installation impact: none.Evidence and regression coverage
attachedScenarioLeaseKey("http://127.0.0.1:9222", "page-1")equalsattachedScenarioLeaseKey("http://[::1]:9222", "page-1"), while different targets and different ports still differ.openPlaywrightScenarioBrowserentry twice (127.0.0.1then[::1]) with a suspended first connection; asserts the second attach stays queued (does not settle within 100 ms) andconnectOverCDPwas dialed once, then verifies both dials carry the original spellings. No real browser needed.2 failed | 7 passed, red cause as in the issue:connectOverCDPcalled twice / keys unequal) — observed on6d8f95e3and re-observed on the rebased base603d04ee(which contains b4db35f). With the fix:9 passed (9).For evidence-bearing changes:
Validation performed
timeout 300 npx vitest run src/browser/PlaywrightScenarioBrowser.test.ts— 9 passed (9); on base603d04eewithout the fix: 2 failed | 7 passed.timeout 300 npx vitest run src/browser src/domain --reporter=dot— 1745 passed | 2 failed; both failures (javascriptSemanticAnalysis.member_depth,PlaywrightBrowserScenarioProvidercleanup retry) also fail on pristine603d04ee.timeout 600 npm run test:fast— 3896 passed | 12 failed | 7 skipped; pristine603d04eebaseline: 3894 passed | 12 failed | 7 skipped; the 12-item failure set is identical (JS semantic analysis / process capture / Electron / Hopper conformance, unrelated to the attach lock; +2 passed = the new tests).npm run typecheck(tsc --noEmit) — passes.npx oxlint— 0 errors (the 1 warning in the touched files is the pre-existing max-params warning onopenAttachedScenarioBrowser).npm run format:check(oxfmt) — passes.npm run verify:module-boundaries— 1409 files checked.git diff --check— clean.Compatibility, safety, and release
Review checklist
type(scope): outcome.Claim and root-cause analysis were posted on the issue before this PR; no competing PR touched the attach admission key at submission time. AI-assisted (Claude Code).