An acp session's pane outlives it after a signal: the view must close on every exit path #95

Merged
city-root merged 1 commit from worker/rexcity-fhi2k into main 2026-11-12 21:01:34 +00:00
Contributor

Fixes rexcity-fhi2k: an acp session's pane outlived its session.

Why the pane stayed

What the evidence shows, and what it does not.

  • The pane is block 01a1d101… in the gascitypacks tab, labelled reviewer. Rex's id timestamp reads 19:24:49 CET, the start of the reviewer-3 session gcg-session-595a8dd6…, whose log ends 20:03:36 ━━ adapter exited, code 0 ━━ after gc's closing the sessions on a signal.
  • ~/.rexcity/<city-key>/views/ holds no record for that session, and the pane is still in rex window ls. So the record was forgotten while the pane stayed. The reviewer-2 session that ended in the same 0.25 s (…f130061…) lost its pane normally.
  • There are two places in the code where that can happen, and both forget the record whether or not the close worked: rpp.Runtime.CloseView forgot the record first and then closed the pane, and viewPanes (the prune at the next start) closed the pane of a dead wrapper, warned if that failed, and forgot the record anyway. After a single failed Rex call, nothing held the pane's id any more.
  • It was not the city lock: no other session started within minutes of 20:03:36, and a lock timeout in CloseView fails before the record is touched. It was not the signal path either: the log shows the wrapper got its SIGTERM and the adapter exited cleanly (the same path closed the 340-odd other sessions).
  • Not proven: why Rex failed the close. The wrapper's warning (pane not closed: …) goes to its stderr, which gc passes to nobody; nothing under ~/.rexcity/<city-key>/ or ~/.gc/ holds it. I did not close the stale pane or call Rex's mutating commands against the live server (only the read-only window ls). The two wrappers closed their panes within 0.25 s of each other, so a conflict between concurrent closes is a guess, not a finding.

What changed

  • rpp.CloseView closes the pane first and forgets the record only once it is closed; on failure it returns the error and the record stays. viewPanes keeps the record of a dead wrapper's view whose pane could not be closed, warns, and the next start tries again.
  • The wrapper (internal/acpbox/box.go) starts closing its pane the moment the adapter exits (beside the drain wait, not after it), tries three times (CloseRetry, 500 ms), and runs the close from a deferred wait too, so a panic in the wrapper's own goroutine still closes it.
  • SIGQUIT is caught and ends the run like SIGTERM; before, it killed the wrapper with the pane open.
  • A close that still fails is written to the session's log (· pane not closed: …), so the next time the reason can be read.
  • README (acp box section) and a fragment .changelog/acp-pane-closes-with-session.md.

Left open: a wrapper killed with SIGKILL still leaves its pane until the next start's prune, which now retries until it works. OpenView's replacement of an old view of the same name (closeStale) still only warns if the old pane will not close.

How I checked

go vet ./..., GOOS=darwin GOARCH=arm64 go vet ./..., go test ./... with a failing rex stub first on PATH (no test reaches the live Rex), go test -race of internal/acpbox, internal/rpp, and changelog -base main (valid=true).

I undid the change each test is for, saw it fail, and restored it:

  • TestCloseViewKeepsTheRecordWhileThePaneIsOpen: old CloseView order.
  • TestAStartKeepsTheRecordOfADeadWrappersViewItCouldNotClose: viewPanes without continue.
  • TestThePaneClosesOnEveryWayTheRunEnds/a SIGQUIT: SIGQUIT out of signal.Notify (the test binary dies of it).
  • TestAPaneThatFailsToCloseIsClosedAgain and TestAPaneThatCannotBeClosedIsSaidInTheLog: one attempt only.
  • TestAPaneThatCannotBeClosedIsSaidInTheLog: no log note.
  • TestThePaneClosesAtOnceWhenTheAdapterExits: close started after the drain.

The other three cases of TestThePaneClosesOnEveryWayTheRunEnds (SIGTERM, adapter killed, adapter exits with an error) pass without my change: they guard the paths that already worked. The deferred close on a panic has no test.

TestAWordOfMegabytesOnATerminalIsKeptForAReplayInLinearTime (not mine, a 5 s bound) failed once of five -race runs under load, with 6.6 s.

Bead: rexcity-fhi2k

Fixes rexcity-fhi2k: an acp session's pane outlived its session. ## Why the pane stayed What the evidence shows, and what it does not. - The pane is block `01a1d101…` in the gascitypacks tab, labelled `reviewer`. Rex's id timestamp reads 19:24:49 CET, the start of the reviewer-3 session `gcg-session-595a8dd6…`, whose log ends `20:03:36 ━━ adapter exited, code 0 ━━` after gc's `closing the sessions on a signal`. - `~/.rexcity/<city-key>/views/` holds no record for that session, and the pane is still in `rex window ls`. So the record was forgotten while the pane stayed. The reviewer-2 session that ended in the same 0.25 s (`…f130061…`) lost its pane normally. - There are two places in the code where that can happen, and both forget the record whether or not the close worked: `rpp.Runtime.CloseView` forgot the record first and then closed the pane, and `viewPanes` (the prune at the next start) closed the pane of a dead wrapper, warned if that failed, and forgot the record anyway. After a single failed Rex call, nothing held the pane's id any more. - It was not the city lock: no other session started within minutes of 20:03:36, and a lock timeout in `CloseView` fails before the record is touched. It was not the signal path either: the log shows the wrapper got its SIGTERM and the adapter exited cleanly (the same path closed the 340-odd other sessions). - **Not proven:** why Rex failed the close. The wrapper's warning (`pane not closed: …`) goes to its stderr, which gc passes to nobody; nothing under `~/.rexcity/<city-key>/` or `~/.gc/` holds it. I did not close the stale pane or call Rex's mutating commands against the live server (only the read-only `window ls`). The two wrappers closed their panes within 0.25 s of each other, so a conflict between concurrent closes is a guess, not a finding. ## What changed - `rpp.CloseView` closes the pane first and forgets the record only once it is closed; on failure it returns the error and the record stays. `viewPanes` keeps the record of a dead wrapper's view whose pane could not be closed, warns, and the next start tries again. - The wrapper (`internal/acpbox/box.go`) starts closing its pane the moment the adapter exits (beside the drain wait, not after it), tries three times (`CloseRetry`, 500 ms), and runs the close from a deferred wait too, so a panic in the wrapper's own goroutine still closes it. - SIGQUIT is caught and ends the run like SIGTERM; before, it killed the wrapper with the pane open. - A close that still fails is written to the session's log (`· pane not closed: …`), so the next time the reason can be read. - README (acp box section) and a fragment `.changelog/acp-pane-closes-with-session.md`. Left open: a wrapper killed with SIGKILL still leaves its pane until the next start's prune, which now retries until it works. `OpenView`'s replacement of an old view of the same name (`closeStale`) still only warns if the old pane will not close. ## How I checked `go vet ./...`, `GOOS=darwin GOARCH=arm64 go vet ./...`, `go test ./...` with a failing `rex` stub first on PATH (no test reaches the live Rex), `go test -race` of `internal/acpbox`, `internal/rpp`, and `changelog -base main` (`valid=true`). I undid the change each test is for, saw it fail, and restored it: - `TestCloseViewKeepsTheRecordWhileThePaneIsOpen`: old CloseView order. - `TestAStartKeepsTheRecordOfADeadWrappersViewItCouldNotClose`: viewPanes without `continue`. - `TestThePaneClosesOnEveryWayTheRunEnds/a SIGQUIT`: SIGQUIT out of `signal.Notify` (the test binary dies of it). - `TestAPaneThatFailsToCloseIsClosedAgain` and `TestAPaneThatCannotBeClosedIsSaidInTheLog`: one attempt only. - `TestAPaneThatCannotBeClosedIsSaidInTheLog`: no log note. - `TestThePaneClosesAtOnceWhenTheAdapterExits`: close started after the drain. The other three cases of `TestThePaneClosesOnEveryWayTheRunEnds` (SIGTERM, adapter killed, adapter exits with an error) pass without my change: they guard the paths that already worked. The deferred close on a panic has no test. `TestAWordOfMegabytesOnATerminalIsKeptForAReplayInLinearTime` (not mine, a 5 s bound) failed once of five `-race` runs under load, with 6.6 s. Bead: rexcity-fhi2k
fix: an acp session's pane goes with it on every exit path (rexcity-fhi2k)
All checks were successful
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 11s
test / go (pull_request) Successful in 1m47s
4341833e3c
The runtime forgot a view's record before closing its pane (CloseView) and also when a later start could not close the pane of a dead wrapper (viewPanes), so one failed Rex call left a pane that no record named and nothing closed: the 2026-11-12 20:03:36 reviewer pane of gascitypacks has no record and is still in its tab. A record now goes only after its pane is closed. The wrapper closes the pane as soon as the adapter exits, tries three times, ends the run on SIGQUIT as on SIGTERM, and says a close that failed in the log. Checked: go vet, go test ./... with a failing rex first on PATH, changelog -base main.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
city-root-review left a comment

Review of 4341833e3c for rexcity-fhi2k. Checks of the head: success.

Verdict

pass

Findings

  • [minor] internal/acpbox/box.go:297-300: the deferred view.wait() that closes the pane on a panic in run's goroutine has no test (the description says so). A case that panics in a hook after openView and checks the fake host's closes would pin it down. Only a panic in that goroutine is covered: one in the renderer's or a relay goroutine still ends the process without running run's defers. The description's wording ("the wrapper's own goroutine") is accurate about this.
  • [minor] internal/acpbox/box.go:706-718 together with internal/rpp/view.go:148: when Rex keeps failing, the wrapper now waits through up to three CloseView tries, each of which can take the city lock wait (10 s) plus CloseTimeout (10 s), before it returns. gc may SIGKILL it first. Since the record now stays when a close fails, the next prune still closes the pane, so nothing is lost. This is a note, not a defect.
  • [minor] internal/acpbox/box.go:234-236: the comment's line break ("…or a hangup,\n// which is how\n// an ACP agent…") is left over from the edit. Style only.

Verified

  • I read the work bead, the description and the whole diff (7 files, +260/−27), and the target's REVIEW.md. There is no AGENTS.md or CLAUDE.md on main.
  • The fix matches the cause it states. rpp.CloseView used to forget the record before closePane, and viewPanes forgot the record of a dead wrapper's view even when the close failed. Both paths now keep the record until the pane is gone. closePane still treats a block that is no longer listed as closed, so a pane the user closed by hand does not leave a record behind for ever. viewPanes only looks at records of the current Rex session, as before.
  • SIGQUIT is now in signal.Notify, and watchSignals' default branch sends it to terminate, which also writes the · quit note to the log.
  • viewCloser runs the close exactly once (via sync.Once). start() begins it when the adapter exits, alongside the drain. The log note after a failed close is written only once q.done shows the renderer has ended, so it races with no other writer of the log.
  • Merging the head into origin/main (a5f35b2) is a fast-forward with no conflict, and the forge says mergeable.
  • All commands ran with the city's variables removed (proved: 0 matching) and with a failing rex stub first on PATH: go vet ./... ok; GOOS=darwin GOARCH=arm64 go vet ./... ok; go test ./... all packages ok; go test -race -count=1 ./internal/acpbox/ ./internal/rpp/ ok.
  • changelog -base main (the city's build from PATH): valid=true, exit 0. The fragment .changelog/acp-pane-closes-with-session.md has only a ### Fixed heading and its bullets, describes the effect for a city, and the change is not breaking. The README's acp box section is updated to match.
  • The work bead's investigation item is answered with evidence: the views directory has no record while the pane is still in rex window ls, and the two places that forget a record are named. Locking and the signal path are ruled out with reasons. That Rex failed the close is stated as not proven, and the new log note means the next occurrence can be diagnosed.
Review of 4341833e3cffec62f54f26b02155c4c87ba87335 for rexcity-fhi2k. Checks of the head: success. ### Verdict pass ### Findings - [minor] internal/acpbox/box.go:297-300: the deferred `view.wait()` that closes the pane on a panic in `run`'s goroutine has no test (the description says so). A case that panics in a hook after `openView` and checks the fake host's closes would pin it down. Only a panic in that goroutine is covered: one in the renderer's or a relay goroutine still ends the process without running `run`'s defers. The description's wording ("the wrapper's own goroutine") is accurate about this. - [minor] internal/acpbox/box.go:706-718 together with internal/rpp/view.go:148: when Rex keeps failing, the wrapper now waits through up to three `CloseView` tries, each of which can take the city lock wait (10 s) plus `CloseTimeout` (10 s), before it returns. gc may SIGKILL it first. Since the record now stays when a close fails, the next prune still closes the pane, so nothing is lost. This is a note, not a defect. - [minor] internal/acpbox/box.go:234-236: the comment's line break ("…or a hangup,\n// which is how\n// an ACP agent…") is left over from the edit. Style only. ### Verified - I read the work bead, the description and the whole diff (7 files, +260/−27), and the target's REVIEW.md. There is no AGENTS.md or CLAUDE.md on main. - The fix matches the cause it states. `rpp.CloseView` used to forget the record before `closePane`, and `viewPanes` forgot the record of a dead wrapper's view even when the close failed. Both paths now keep the record until the pane is gone. `closePane` still treats a block that is no longer listed as closed, so a pane the user closed by hand does not leave a record behind for ever. `viewPanes` only looks at records of the current Rex session, as before. - SIGQUIT is now in `signal.Notify`, and `watchSignals`' default branch sends it to `terminate`, which also writes the `· quit` note to the log. - `viewCloser` runs the close exactly once (via `sync.Once`). `start()` begins it when the adapter exits, alongside the drain. The log note after a failed close is written only once `q.done` shows the renderer has ended, so it races with no other writer of the log. - Merging the head into origin/main (a5f35b2) is a fast-forward with no conflict, and the forge says mergeable. - All commands ran with the city's variables removed (proved: 0 matching) and with a failing `rex` stub first on PATH: `go vet ./...` ok; `GOOS=darwin GOARCH=arm64 go vet ./...` ok; `go test ./...` all packages ok; `go test -race -count=1 ./internal/acpbox/ ./internal/rpp/` ok. - `changelog -base main` (the city's build from PATH): `valid=true`, exit 0. The fragment `.changelog/acp-pane-closes-with-session.md` has only a `### Fixed` heading and its bullets, describes the effect for a city, and the change is not breaking. The README's acp box section is updated to match. - The work bead's investigation item is answered with evidence: the views directory has no record while the pane is still in `rex window ls`, and the two places that forget a record are named. Locking and the signal path are ruled out with reasons. That Rex failed the close is stated as not proven, and the new log note means the next occurrence can be diagnosed.
Commenting is not possible because the repository is archived.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
mikluko/rexcity!95
No description provided.