Repository navigation
fix(cli): close the lifecycle gaps a stress run left open - #88
Merged
Merged
Conversation
- pw: --takeover and --context/--name are cuttle's leading flags in any order, so `pw --takeover --name X <verb>` takes the lease on X, not on the default instance, and no longer hands --name to the driver. - An image that predates the bundled driver: the briefing says so and names `up --recreate` instead of advertising pw/jev-browse, and pw and jev-browse fail with that hint instead of a raw OCI exec error. - up --recreate reports the image it replaced when it changes. - The lease call waits out a daemon that is still booting after a restart, and runs in / so the daemon recreating its workdir cannot fail it. - open --until ends at once when the browser goes away. - up validates --cdp-port/--vnc-port and the instance name before any docker call; a failed run removes only what it created. - status and down --purge wording; direct backend hints no longer say run `up`; the ssh standing tunnel checks the daemon it reaches is the forwarded instance.
…umes on unknown, recheck ports after discovery - open --until fails on a lost page socket instead of re-dialing: /json relaunches a crashed browser, whose blank tab would satisfy gone:. - A failed run removes the profile volume only when docker said it did not exist; an inspect that errors counts as present. - checkPorts runs after port discovery, so --recreate cannot tear down and then fail on a CDP/VNC collision. - Shared execIn and containerHost.inspectField; the driver probe has its own timeout; one wording for the stale-image hint.
This was referenced Sep 18, 2026
tenequm
added a commit
that referenced
this pull request
Sep 18, 2026
## What was broken An independent review of #88, plus two lifecycle minors from the pool-mode stress run, found: 1. **An empty instance selector ran against the default instance.** `cuttle --name "" down --purge` (an unset shell variable) fell through `containerName`'s `cmp.Or` to the default container and purged it. The same held for a set-but-empty `CUTTLE_NAME`/`CUTTLE_CONTEXT`, for the pw peel's `--name=`/`--context ""`, and for `pw --takeover=true --name x click`, where the peel ended at `--takeover=true` and handed `--name x` to the driver. 2. **`--name` on a k8s/direct context was silently ignored.** `cuttle --context <k8s> --name scraper down --purge` tore down the context's release and PVC. 3. **`open --until` reported a slow page as gone.** The isolated world is built under a 5s per-call deadline, and coder/websocket closes the socket when a call's context expires. #88 read that closed socket as `errCDPConn`. 4. **`up --recreate`/`--purge-profile` tore the container down before anything could fail.** The image pull happened inside the `docker run` after the teardown, and a new pinned host port was never checked for a running container, so an unpullable `--image` or a busy port left nothing running. 5. **A failed `docker run` was cleaned up by name.** A run that failed before creating anything (a name conflict with a concurrent `up`, a failed pull) then ran `rm -f` on the concurrent winner's container. The name-conflict string match only covered docker's wording, not podman's. 6. **Read verbs right after a restart failed in `docker exec -w`.** The driver's workdir `/data/__default__/Downloads` is created by the daemon as it boots, so `pw`/`jev` could hit `chdir ... no such file or directory` before the verb ran. #88 fixed only the lease path. 7. **The ssh identity check could stall every invocation on a context.** The remote `docker inspect` for the container hostname ran under the context's state lock with no deadline. 8. **Wording.** The foreign-tunnel error suggested other `--cdp-port/--vnc-port`, which over ssh also moves the remote port. The upgrade hint promised "the persistent profile is kept" for ephemeral containers. `down` on an `--ephemeral` container said "profile kept", but the daemon deletes that profile as it shuts down (verified live). Re-running `up --ephemeral` on an ephemeral container warned that persistence can't change. ## What changed - `--name`/`--context` are a flag type that refuses `""`. A set-but-empty `CUTTLE_NAME`/`CUTTLE_CONTEXT` is refused when it would be consulted. `--name` on a context that is not local/ssh is refused. `splitCuttleFlags` refuses an empty value and `--takeover=<anything>`. All of these fail before any docker call. - `waitUntil` re-dials the **same** page websocket after a per-call deadline, never `/json`, so it cannot pick another tab. The re-dial has its own 5s bound, so a link that accepts and then stalls reads as gone. A real socket death still ends the wait at once. - A rebuild pulls a missing image (`docker image inspect`, then `docker pull`) and, locally, probes every requested host port except the ones the running container already holds. Both happen before the teardown and before `--purge-profile` drops the volume. - `docker run` carries a per-run `cuttle.run=<random>` label. On failure, cleanup removes only `docker ps -aq --filter label=...`, and drops a volume only together with a container this run created. `isNameConflict` is gone, since the label makes it unnecessary. - Every exec (docker, ssh, k8s) runs `sh -c '(umask 077 && mkdir -p -- "$0") && cd -- "$0" && exec "$@"' <workdir> argv...`: the workdir is created if missing, argv is never interpolated, and `--filename` output lands where it did. - The remote hostname lookup is bounded at 10s, and `ExecRunner.Output` sets a 2s `WaitDelay` so an ssh ControlMaster holding the pipes cannot stretch that bound. - Local/SSH report `PersistentProfile` from `{{json .Mounts}}`. `down` says "ephemeral profile discarded" for an ephemeral container. `up` warns only when the requested persistence differs, or when it cannot be read (k8s, as before). The foreign-tunnel error now says only "stop whatever holds it". `localImage` is renamed `containerImage`. Known and not changed: an ssh rebuild cannot probe the remote host's ports before teardown (docker still fails the run there). The `up` briefing's "logins persist across down/up" line is also shown for ephemeral containers. ## Verification - `just check` is green. New tests cover each item: empty flags and env vars, and `--name` on k8s, all refused with no docker call; a page that stalls the first socket and answers on a re-dial; a re-dial that never completes (without the bound, the test hangs for the whole wait); an unpullable image and a foreign-held new port on `--recreate`/`--purge-profile`, with no teardown; label-scoped cleanup, with no `rm -f <name>` in any case, including a pull failure during a concurrent `up`; the workdir wrapper creating a missing 0700 dir and passing a metacharacter argument verbatim; the ephemeral/persistent/unknown matrix for `up --ephemeral` and `down`. - Live on throwaway `--ephemeral` containers (`rw-a`, `rw-b`, isolated XDG, a PATH `docker` shim that blocks any call not targeting `rw-*`): - Empty selectors, whether as a flag, `--name=`, an env var, or on the pw peel, as well as whitespace and unicode names, were refused with zero docker calls. - `up --recreate --image <missing>` and `up --recreate --cdp-port <held>` both failed, and the same container ID was still running. - A plain recreate, and one on new ports, succeeded. - Three concurrent `up`s: one won, the two losers issued no `rm`, and the winner survived. - After deleting `Downloads`, `docker exec -w` failed while `pw goto`/`pw screenshot --filename` succeeded. The file landed in `Downloads`, and `cuttle downloads` listed it. - `pw snapshot` right after `docker start` succeeded. - `down` printed "ephemeral profile discarded", and a marker file in the profile was indeed gone after the restart. - Everything was cleaned up. ## Release notes An empty --name/--context or CUTTLE_NAME/CUTTLE_CONTEXT is refused instead of acting on the default instance. up --recreate pulls and checks ports before removing the old container. pw works right after a restart. open --until no longer reports a slow page as gone.
tenequm
added a commit
that referenced
this pull request
Sep 21, 2026
🤖 I have created a release *beep* *boop* --- ## [0.15.0](v0.14.2...v0.15.0) (2026-09-21) ### Features * bundle playwright-cli into the image with a cuttle pw passthrough ([#67](#67)) ([28d9846](28d9846)) * **cli:** center the skill and briefing on cuttle pw, drop host driver routing ([#75](#75)) ([33eca16](33eca16)) * **cli:** colored jev-browse output ([#70](#70)) ([cf6f109](cf6f109)) * **cli:** cuttle jev-browse - autonomous browsing loop on the bundled driver ([#66](#66)) ([0496957](0496957)) * **cli:** deliver pw action snapshots as a host file, secrets masked ([#103](#103)) ([78adbbb](78adbbb)) * **cli:** make --context/--name global so pw and jev-browse reach any instance ([#74](#74)) ([9df5c33](9df5c33)) * **cli:** zero-ceremony cuttle pw - auto-attach on demand, allow open ([a7e6491](a7e6491)) * **jev:** withhold write actions and halve jev-browse run time ([#102](#102)) ([9ca9386](9ca9386)) * **serve:** mask password field values in /snapshot ([#109](#109)) ([2a352b5](2a352b5)) * **serve:** session lease - one driver at a time, with takeover ([#69](#69)) ([87724c8](87724c8)) ### Bug Fixes * **backend:** keep profile cleanup and remote argv from reaching past their own ([#92](#92)) ([f52cfd3](f52cfd3)) * **cli:** close the gaps a review of the lifecycle fixes found ([#90](#90)) ([c46aa5e](c46aa5e)) * **cli:** close the lifecycle gaps a stress run left open ([#88](#88)) ([899a535](899a535)) * **cli:** discarding the profile removes the instance's host snapshot dir ([#113](#113)) ([57cd07a](57cd07a)) * **cli:** downloads --wait accepts a finished download, logs drops D-Bus spam ([#111](#111)) ([dcc2f46](dcc2f46)) * **cli:** name the in-page dialog behind a pw click timeout ([#99](#99)) ([11beeeb](11beeeb)) * **cli:** never fall back to another instance when the selected one is stopped ([#78](#78)) ([a1df361](a1df361)) * **cli:** re-attach the driver after a restart leaves a stale session ([#77](#77)) ([bbeb0f0](bbeb0f0)) * **cli:** run --extract on every ending, not only done ([#71](#71)) ([4954195](4954195)) * **jev:** judge done on the page that landed, and end done on a none above even odds ([#108](#108)) ([a9cb5a8](a9cb5a8)) * **jev:** offer filter-apply controls the write gate withheld ([#114](#114)) ([bdf440a](bdf440a)) * **jev:** read quoted snapshot lines and keep field values out of --extract ([#89](#89)) ([09111a2](09111a2)) * **pw:** compact find output, downloads into a directory, quieter logs ([#116](#116)) ([62f2ca8](62f2ca8)) * **pw:** snapshot links a host file like an action, and the console log line names its verb ([#110](#110)) ([c902c58](c902c58)) * **serve:** dismiss a native dialog the driver leaves open ([#87](#87)) ([14f24cb](14f24cb)) * **serve:** keep the default seed's downloads across browser relaunch ([aac8e40](aac8e40)) * **serve:** keep the dialog watch alive through a signal shutdown ([#94](#94)) ([4f4f1d0](4f4f1d0)) * **serve:** pool-mode reaping, capture tab, hung tabs and launch bursts ([#86](#86)) ([3b42ea2](3b42ea2)) * **serve:** skip an idle reap whose timer a launch has since re-armed ([#93](#93)) ([c667868](c667868)) * **smoke:** never exec into a container the run was not pointed at ([#79](#79)) ([9075244](9075244)) * **viewer:** keep websocket inside proxy prefix ([#62](#62)) ([3b10ba7](3b10ba7)) ### Performance Improvements * **cli:** run a pw verb in one docker exec, lease check included ([#100](#100)) ([a9c3c90](a9c3c90)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was broken
A lifecycle stress run (after #77/#78, which fixed its blockers) left these:
pw --takeover --name X <verb>hit the wrong instance.--name/--contextwere peeled off before--takeover, so instance flags after--takeoverwent to the driver while the lease was force-released on the default instance.pwandjev-browse, and both failed with a rawOCI runtime exec failed ... executable file not found(exit 127).up --recreateswitched images silently. Without--imageit moves the container to the CLI's default image and the briefing hid it.docker restartfailed with a rawreaching the session lease: exit status 7(daemon not listening yet) orexit status 127(exec into the driver workdir while the daemon recreates it).open --untilignored a dead browser, blocking the whole--timeoutand then printing a stale URL.up --recreate"discards the profile" (it keeps it); a repeateddown --purgeclaimed "removed container";--cdp-port 0and--cdp-port X --vnc-port Xwere accepted (and the latter left an orphan volume); an invalid--namereached docker and was printed unquoted in hints; a faileddocker runalways randocker rm -f <name>, even when it failed on a name conflict with a concurrentupthat won.up, which direct refuses.What changed
splitCuttleFlagspeels--context,--nameand--takeoverin any order from the leading run; anything from the verb on is still the driver's.sh -c 'command -v playwright-cli', run in/) decides whether the briefing shows the driver block or a note naming<cuttle> up --recreate.pwrecognizes the exec's 127 "not found" and returns the same hint;jev-browseprobes before taking the lease. An exec that fails outright is not read as a missing driver. The daemon has no version endpoint and older ones never will, so the container itself is the only reliable source.up --recreatewithout--imagemoves to this CLI's image - that is the upgrade path the new hint relies on) and printnote: image changed <old> -> <new>when it changes.SSHgainsImageso this works over ssh too.leaseCallretries curl's exit 7 for up to 20s and execs in/instead of the driver's workdir. Only the lease call changed inlease.go.open --until: a websocket failure (newerrCDPConn) ends the wait at once with the last URL. It deliberately does not re-dial:/jsonrelaunches a crashed browser, and its blank tab would satisfy agone:predicate and read as a finished sign-in.checkPortsbefore any docker call; docker's container-name rule enforced inresolvefor local/ssh;checkPortsruns after port discovery, soup --recreate --cdp-port <the viewer's port>is refused before teardown; failed runs skip cleanup on a name conflict and remove the profile volume only when docker said it did not exist beforehand (an inspect that errors counts as present); wording fixes.hostname(the container's). The ssh tunnel health check compares it with the remote container'sConfig.Hostname; a mismatch respawns the forward, and a mismatch after respawn stops the supervisor and fails with the port. A daemon that reports no hostname (older image, or not up yet) passes as before. k8s is unchanged.status,openandpwon a direct context that does not answer say to start that browser yourself; its briefing sayscuttle pwneeds a container.Verification
Throwaway containers only (
lf-*, ports 9710-9712/6710-6712), config isolated viaXDG_*:pw --takeover --name lf-a press Tabwith a lease held on lf-a: lease freed on lf-a, verb ran; the default instance's lease endpoint untouched.docker restart lf-athenpw goto: main fails 3/3 (reaching the session lease: exit status 127), this branch succeeds 3/3 in about 2s.open --until title:never --timeoutwithdocker kill6s in: main waits the full timeout; this branch returns in 6s withlost the page while waiting; last at https://example.com/. Success paths (title:, aurl:reached by navigation) still resolve.pw/jev-browsefail with the OCI error; this branch shows the upgrade note andpw snapshot,pw click,jev-browse --mockall fail with the hint.up --recreate --image cuttle:lf-fixprintsimage changed ghcr.io/glim-sh/cuttle:0.14.2 -> cuttle:lf-fix, the driver block comes back, and the root endpoint'shostnamematchesdocker inspect .Config.Hostname.--cdp-port 0and--name 'lf bad'are refused before any container or volume exists; a repeateddown --purgesays the instance was already gone; four concurrentups of one instance leave the winner running (losers hit the name conflict and no longer remove it).up, this branch says start it yourself.The ssh tunnel identity check is unit-tested (
TestTunnelReachesInstance); there was no ssh host to test it on.just checkis green.Release notes
cuttle pw --takeovernow works in any order with--name/--context. Against an image older than the bundled driver, the briefing andpw/jev-browsesay to runup --recreate.up --recreatenames an image change. Verbs right after a restart wait for the daemon.