chore(agents): add a machine-wide Playwright browser resource budget

Playwright disables normal background throttling, so a hidden 5chan page keeps
doing P2P and rendering work after a check finishes. Agents verifying in
parallel across worktrees stacked whole browser engines on one machine.

Add scripts/pw-session.sh, a wrapper that permits one active Playwright browser
at a time and records who holds it:

- The lock is machine-wide, not per-repository, because the contended resource
  is RAM and CPU. Every worktree and checkout shares one slot.
- Acquisition is an atomic mkdir. Stale locks clear themselves: `open` reclaims
  any slot whose recorded browser is no longer `status: open` in
  `playwright-cli list --all`, so an interrupted workflow cannot strand the
  budget. When that list cannot be read the lock is left alone, so a broken CLI
  never silently disables the budget.
- `open` exits 75 when the slot is busy; `--wait[=SECONDS]` blocks instead.
- `close` always stops the browser, even when the lock was already lost, and
  never releases a slot held by a different session.
- `status` reports the holder and whether its browser is still alive.

Agent policy now runs browser engines and profiler batches sequentially, uses
Chrome/Blink during iteration and the full engine matrix only for final
verification, and never uses `close-all` or `kill-all` while other agents may
own sessions.

Covered by scripts/pw-session.test.js.
This commit is contained in:
Tommaso Casaburi
2026-08-01 19:21:01 +02:00
parent a67c66de0d
commit 1a33f7dc88
31 changed files with 835 additions and 169 deletions
+19 -12
View File
@@ -26,17 +26,25 @@ Do not start, restart, or stop the dev server yourself. If the app is unreachabl
Default to a fresh isolated `playwright-cli` browser session. If the requested verification depends on auth, cookies, extensions, open tabs, or other existing browser state and the parent agent did not specify session mode, stop and ask whether to use a fresh browser or the contributor's current browser session.
### Step 2: Navigate and Snapshot
### Step 2: Navigate and Snapshot Sequentially
Use playwright-cli to check the relevant page in all three browser engines with separate sessions:
Choose short task-specific session names. Use the shared wrapper to check the relevant page in all three browser engines one at a time:
```bash
playwright-cli -s=verify-chrome open https://5chan.localhost --browser=chrome
playwright-cli -s=verify-firefox open https://5chan.localhost --browser=firefox
playwright-cli -s=verify-webkit open https://5chan.localhost --browser=webkit
./scripts/pw-session.sh open verify-chrome https://5chan.localhost --browser=chrome
# Complete the Chrome desktop/mobile flow.
./scripts/pw-session.sh close verify-chrome
./scripts/pw-session.sh open verify-firefox https://5chan.localhost --browser=firefox
# Complete the Firefox desktop/mobile flow.
./scripts/pw-session.sh close verify-firefox
./scripts/pw-session.sh open verify-webkit https://5chan.localhost --browser=webkit
# Complete the WebKit desktop/mobile flow.
./scripts/pw-session.sh close verify-webkit
```
Navigate each engine session to the specific page/route where the change should be visible.
Navigate the current engine session to the specific page/route where the change should be visible. Always close that session in a finally-style cleanup, even when a check fails, before opening the next engine. If the wrapper exits 75 the slot is busy: retry with `./scripts/pw-session.sh open --wait <session> ...`, or report it to the parent so the check can be rescheduled. Never bypass the lock.
### Step 3: Verify the Changes
@@ -49,14 +57,12 @@ Based on what the parent agent asked you to check:
- Check mobile viewport in each engine if the change is layout-related:
```bash
playwright-cli -s=verify-chrome resize 375 812
playwright-cli -s=verify-chrome snapshot
playwright-cli -s=verify-firefox resize 375 812
playwright-cli -s=verify-firefox snapshot
playwright-cli -s=verify-webkit resize 375 812
playwright-cli -s=verify-webkit snapshot
playwright-cli -s=SESSION resize 375 812
playwright-cli -s=SESSION snapshot
```
Replace `SESSION` with the currently open engine session. Finish its mobile check before closing it and moving to the next engine.
### Step 4: Report Back
```
@@ -87,4 +93,5 @@ playwright-cli -s=verify-webkit snapshot
- If the dev server is unreachable, report the error and stop
- Never attach to a live personal browser session without explicit permission
- If current-session reuse is requested, use the supported attach path only when available; otherwise report the limitation instead of silently switching to a fresh session
- Never run multiple browser engines at once, and never use `playwright-cli close-all` or `kill-all`
- Don't modify any code — you are read-only, verification only