Skip to content

fix(browser): drain DevTools relay calls before session teardown - #466

Merged
ElbertePlinio merged 8 commits into
mainfrom
fix/454-relay-permits
Oct 29, 2026
Merged

ElbertePlinio merged 8 commits into
mainfrom
fix/454-relay-permits

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

Closes #454

Each DevTools relay tools/call now holds an agent permit until the upstream child answers it, so session teardown drains relay calls before it stops Chrome. While a call is unanswered, the relay checks the session about every 100 ms. When teardown closes input, the relay stops its child, releases the permits, answers each unanswered call with the session-ended error (-32051) and exits. A relay with no call unanswered stays up as before, and a later call gets the same error. A human takeover releases the permits it covers at once, so its 5 s drain still succeeds, and the running call can still finish. SECURITY.md describes the drain and the window that remains during takeover.

A call the client cancels gets no response, but the child may still run it. It keeps its permit until the relay ends, input closes or a lease appears.

The third checklist item, moving CDP to --remote-debugging-pipe, changes how Chrome starts and how the upstream child connects. It is tracked in #459.

Traceability

Requirement Verification Scenario and edge cases Result Evidence
Hold an agent permit for each forwarded tools/call until its response "holds a permit for an in-flight call and ends it when teardown closes input", "releases one permit per response for a reused id", "refuses calls with stable errors, holds no permit, and forwards nothing" In-flight call, reused id, a child request with the same id, refused calls Pass; a probe on main shows 0 permits while a call runs ~/.pickforge/investigations/454-relay/before-probe.log, r3-sol/after-1.log to after-3.log
Test a call in flight across session destroy The unit test above, and a real-Chrome journey (qa/qa-repro.mjs) with one held call and one queued call across session destroy main and this branch main: Chrome exits first, and the queued call gets ECONNREFUSED on the freed port. This branch: the child exits at 68 ms, the relay at 84 ms and Chrome at 135 ms, and both calls get -32051 ~/.pickforge/investigations/454-relay/qa/run-main.log, qa/run-branch-r4.log
Consider --remote-debugging-pipe Considered during planning Deferred to #459 #459
Takeover still drains "lets takeover drain while a call is in flight and still forwards its response", "keeps the permit of a call admitted after a lease the watcher read has ended", and a script that pauses the watcher after its lease read until takeover times out A lease during a long call; a stale lease read after takeover ended Pass; the second test and the script lose the new call's permit before c7d86e8 ~/.pickforge/investigations/454-relay/r3-sol/before.log, r3-sol/sol-lease-repro.log
No permit leaks and no lingering relay "releases every permit when the child exits with calls unanswered", "... even when the output cannot drain", "releases every permit when the relay input ends with a call unanswered", "forwards a response the child sends while teardown stops it, with no end error"; a real-Chrome journey that checks the relay 15 s after teardown Child exit, blocked output, input end, a response during the stop Pass; on this branch the relay is gone, on main it stays ~/.pickforge/investigations/454-relay/qa/later-main.log, qa/later-branch-r4.log
An idle relay behaves as before "keeps the relay when teardown closes input after the last call was answered"; packages/cli/test/devtools-real.test.ts with real Chrome; an idle real-Chrome journey Teardown with no call unanswered The relay stays and answers a later call with -32051, as on main; the real-Chrome test passes 4 of 4 and failed on 9ff9fe0 ~/.pickforge/investigations/454-relay/qa/idle-main.log, qa/idle-branch-r4.log, r2-fable/devtools-real-head.log, r3-sol/devtools-real.log
Full suite full-suite.sh build, lint, typecheck, viewer build, vitest, cargo All steps pass at c7d86e8: vitest 3541 passed, 4 skipped; cargo 353 passed ~/.pickforge/investigations/454-relay/full/
PickCheck and secret scan pickcheck check --base origin/main --fail-on new,worsened,unmatched; gitleaks on the branch commits 0 violations over 86 files; no leaks ~/.pickforge/investigations/454-relay/pickcheck-final.json, gitleaks-final.log

Review

Council of Sol and Fable. The Kimi seat did not run: its provider hit a usage limit during this batch.

Reviewer Revision Score Result
Fable 0f27fc3 8 Permits stayed held until the relay settled after the child exited. Fixed in 9ff9fe0, with the cancelled-call note, a late-response test and SECURITY.md wording.
Fable 9ff9fe0 8 Only the closed-input path released the relay input. Fixed in 073a08d.
Sol 9ff9fe0 7 A watcher that read a lease and then paused could release the permit of a call admitted after takeover ended. Fixed in c7d86e8.
Sol c7d86e8 9 No findings.
Fable c7d86e8 9 No findings.

The lead's QA also found two defects, both fixed with tests. After teardown ended its calls, the relay stayed up while its client held stdin open; fixed in 135b25b. The real-Chrome test failed when the last watcher check ran after the last answer and ended an idle relay; fixed in 5b68cb5.

Each forwarded tools/call now holds an agent permit until the child answers it, so session teardown drains relay calls before it stops Chrome. While a call is unanswered the relay watches the session. Closed input stops the child, releases the permits and answers each call with the session-ended error. A human lease releases the permits at once so the takeover drain succeeds.

Refs #454
When teardown closed input during a call, the relay stopped its child and
answered the call, but its input stayed open with nothing reading it. The
process lived on, and a later call waited for its client timeout. The
relay now releases its input, so it exits and the client sees it close.
Permits were released only after the relay's output settled. A client
that stopped reading could hold them through the whole teardown drain,
and teardown then failed. Once the child exits, no call can reach Chrome,
so the relay releases its permits then. Each close now waits for every
release already started. A new test pins that a response the child
sends while it stops is forwarded with no session-ended answer.
Only the closed-input shutdown released the relay's input. When the
child exited with a code, or a pump failed, the client's still open
input kept the relay process alive, and a later call waited for its
client timeout. The relay now releases its input on every exit, after
every path has settled the input pump.
The watcher's last check runs after the last answer. When teardown
closed input inside that window, the relay stopped its child and exited
with nothing in flight, so later calls failed with "Not connected"
instead of the session-ended error. That check now ends the relay only
while a call is unanswered.
@ElbertePlinio
ElbertePlinio merged commit 8d49d17 into main Oct 29, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/454-relay-permits branch October 29, 2026 21:50
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: drain in-flight DevTools relay calls before session teardown

1 participant