fix: skip restart request for named sessions on self-handoff#927
Merged
julianknutsen merged 2 commits intogastownhall:mainfrom Apr 19, 2026
Merged
Conversation
gc handoff called dops.setRestartRequested (and setBeadRestartRequested) unconditionally. Named (human-attended) sessions like the mayor are started by the user — the controller cannot respawn them — so every PreCompact "gc handoff context cycle" tick killed Claude Code to the user's shell and lost any in-flight context-recovery work the mail would have set up. Before requesting a restart, look up the open session bead for the current sessionName. If it is a configured named session, return after sending the mail. Do not touch the restart flags. Headless pool sessions continue to behave exactly as before (the store lookup either misses or finds a non-named bead, and the restart path runs). TestDoHandoff_Regression744_NamedSessionSkipsRestart seeds a named session bead and asserts: mail is still created, dops.restartRequested is NOT set, bead restart_requested is NOT set, and stdout does not promise a restart. Fixes gastownhall#744. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2c57560 to
cd0aacd
Compare
Collaborator
Adopted Review SummaryI adopted this PR and pushed a maintainer fixup on top of the contributor commit while preserving contributor authorship. What changed during adoption
Review resultTriple-model review validated the core #744 fix: handoff mail is still created, but on-demand named sessions no longer request controller restart or emit a misleading drain event. A follow-up review finding about swallowed stale-cleanup errors was fixed before push. Remaining broader policy questions are not blockers for this scoped bug fix: whether Local verification
|
f021bc8 to
de82d6f
Compare
de82d6f to
84c0e19
Compare
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.
Summary
PreCompacthook runsgc handoff "context cycle", which calledsetRestartRequestedunconditionally. Named (human-attended) sessions like the mayor are started by the user, and the controller cannot respawn them — so every context compaction killed Claude Code to the user's shell.doHandoffnow looks up the open session bead for the current session and skips both the tmux and bead restart flags when the bead is a configured named session. Mail is still sent — context preservation was the whole point.Why
The fix the issue describes — "check whether the current session is a named session, if so skip the restart and return after sending the mail" — matches what I did.
isNamedSessionBead(the existing helper fromcmd/gc/named_sessions.go) returns true whenMetadata["configured_named_session"] == "true". A new local helpersessionIsNamed(store, sessionName)scans open session beads by the existinggc:sessionlabel and returns true only for a positive match, so pool sessions (which either have no bead at all or a non-named one) stay on the old restart path.Test plan
TestDoHandoff_Regression744_NamedSessionSkipsRestartincmd/gc/cmd_handoff_test.goseeds a named-session bead and asserts mail is created,dops.restartRequestedis NOT set, beadrestart_requestedis NOT set, and stdout does not promise a restart. Fails on main, passes after the fix.go test ./cmd/gc/ -run 'TestHandoff|TestDoHandoff'— the pre-existingTestHandoffSuccess/TestHandoffWithMessage/TestHandoffRemote*all continue to pass.go vet ./cmd/gc/clean.go build ./cmd/gc/clean.🤖 Generated with Claude Code