Skip to content

fix(takeover): close session input before teardown - #316

Merged
ElbertePlinio merged 6 commits into
mainfrom
fix/213-session-input-gate
Oct 9, 2026
Merged

ElbertePlinio merged 6 commits into
mainfrom
fix/213-session-input-gate

Conversation

@ElbertePlinio

@ElbertePlinio ElbertePlinio commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Teardown now closes agent input before it releases a display, so a delayed input call for a torn-down session can no longer reach a display that a new session reused.

How it works:

  • An irreversible .<id>.input-closed marker sits next to the takeover identity marker. Retention and pruning leave it in place, and it reserves the id.
  • Permits and human leases use create-then-check. The caller pre-checks the marker and the record, publishes the permit or lease atomically (temp file plus hard link), then re-checks the marker and the record and rolls back on failure. Teardown creates the marker first, then drains permits. Any permit that passed its re-check was published before the marker, so the drain always sees it and waits. No lock is involved, so this works across Node versions, Bun, and network namespaces.
  • Refusals surface as AgentPermitUnavailableError, so evidence records them as not-attempted.
  • Explicit destroy drains for up to 305 s, the longest permitted input action plus margin, and honors cancellation. A timeout keeps every resource, names the pending permits, and leaves the session for a reaper retry. The reaper and startup rollback use a 5 s budget, and the reaper caps its session lock wait at 5 s.
  • The drain happens once, inside the typed desktop and browser teardown, under the session VNC lock, and teardown re-reads resource ownership after it. Desktop and browser startup rollback close and drain first. Combined desktop+android sessions drain before any retention.
  • The reaper revives an interrupted teardown (a running or starting record with the marker) and pending retries. Completed rollback error records stay in place for inspection. A clean destroy retains logs without a failure snapshot; an error record keeps its snapshot.

This replaces the #213 part of #305. An earlier revision of this PR used an abstract Unix socket lock. Review and CI showed it fails between Node 20 and Node 22+ and across network namespaces, so it was removed.

Closes #213

Requirement Verified by Scenario Result Evidence
Refuse coordination for an id without a live record Automated tests, QA Delayed input stalled before publication, teardown runs, input resumes (with and without prune); unknown and non-running ids; late click and late lease after destroy Action never runs; late click and late lease refused qa-213/r3/run.log J3
Teardown drains in-flight input before releasing the display Automated tests, QA Permit held 4 s while session destroy runs; new click during drain Destroy finished after 4.1 s; Xvfb alive during the hold; new click not-attempted qa-213/r3/run.log J2
Permits never visible half-written Automated test Lease drain runs between temp write and link No sweep, no untracked action CI
Startup ownership is never lost Automated tests (real Xvfb) Startup publishes Xvfb during teardown drain; stale record write Destroy stops the published Xvfb CI
Drain timeout and cancellation keep resources and allow retry Automated tests Permit never released; CLI interrupted after closure; MCP cancel Resources kept, reaper recovers via marker CI
Reaper does not block or over-reap Automated tests Reaper during a live explicit destroy; completed rollback error record Returns within 5 s; error record kept CI
Marker survives prune Automated tests, QA session prune --all-stopped Logs pruned, marker and identity kept, input still refused qa-213/r3/run.log J4
Cross-runtime behavior Automated tests Core tests under Node 20.19.0 and Bun 1.3.12 Pass CI
Legacy storage and retained directories stay readable Automated tests Status, lease reads, retained logs, failure snapshots Readable CI

Checks: lint, typecheck, build, GSK_RENDERER=cairo PICKFORGE_REQUIRE_BROWSER=1 bun run test:coverage (3,073 passed, 6 skipped, thresholds unchanged), PickCheck clean. One earlier full run hit a load flake in an unchanged browser abort test, filed as #318. xterm is not installed on this host, so its live tests did not run.

Reviews: Astra and Fable at xhigh, four repair rounds, all findings resolved. Follow-ups: #317 (marker growth), #318 (browser abort test flake).

QA used an isolated PICKFORGE_HOME and product-created desktop sessions. Evidence lives outside the repo in the batch 5 artifacts folder (qa-213).

@ElbertePlinio
ElbertePlinio merged commit 1dbca54 into main Oct 9, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/213-session-input-gate branch October 9, 2026 17:07
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.

takeover: late input callers can rebuild coordination for a torn-down session

1 participant