Repository navigation
fix(down): preserve slot on ecluse down --keep-worktree - #32
Merged
Merged
Conversation
Add a Stopped variant to SessionStatus for sessions whose services are down but whose worktree is kept on disk. The entry stays in state so its slot remains reserved. Adds find_session_mut and mark_stopped, which clears runtime and provisioning fields while keeping the identity fields (slug, slot, branch, worktree_path, mode).
Two op ids minted in the same process within the same nanosecond could collide. Append a process-local atomic counter so ids are always distinct, keeping pid and timestamp for readability.
down --keep-worktree and shutdown --keep-worktrees used to drop the session from state, so the next up allocated a new slot and every port changed. They now mark the session Stopped instead. - up auto-detects a Stopped session (by slug or from inside the kept worktree) and resumes it at the same slot, re-probing ports - down/shutdown/flush skip service teardown for Stopped sessions but still remove the worktree when it is not kept - a failed teardown restores the entry without duplicating it and keeps a pre-existing Stopped status - ls shows Stopped sessions as '<slug> (stopped)' - the shutdown summary counts sessions kept as stopped
…e error A Stopped session has no running services, so reading its env or status would report ports nothing is listening on. ensure_session_settled now rejects Stopped sessions and points to `ecluse up <slug>`.
mark_pending commits the state entry before the worktree is created, so waiting only for the entry let down --delete-worktree run before the worktree existed and fail teardown intermittently.
Integration tests for down --keep-worktree marking the session stopped and resuming at the same slot, down --delete-worktree on a stopped session, shutdown --keep-worktrees, and resuming a stopped session whose worktree was deleted by hand.
Stopped sessions keep their slot, so a plain down --keep-worktree no longer frees one. The message now names down --delete-worktree and notes that stopped sessions in ecluse ls hold slots.
Tell agents to prefer --delete-worktree when a task is done, and how to recover from SlotsExhausted when stopped sessions hold the slots.
Bring up three sessions, keep the third's worktree, fully tear down the first, then run a bare up from inside the kept worktree. It must resume at slot 3 rather than drift onto the freed slot 1. Fails on main.
hefgi
force-pushed
the
fix/stopped-slot-on-keep-worktree
branch
from
October 2, 2026 14:57
e27053c to
3c56d1e
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
ecluse down --keep-worktreeremoved the session fromstate.json. On the nextecluse upfrom inside that worktree, slot allocation ran fresh and picked the lowest available slot (e.g. slot 1 instead of slot 3), changing all ports.StoppedSessionStatus. With--keep-worktree(andshutdown --keep-worktrees) the session stays in state asstopped, runtime fields cleared, slot reserved.ecluse upfrom the kept worktree resumes at the same slot; ports are re-probed at that slot.env,status,shell, andsyncreject stopped sessions with an actionable error;ls,flush, andshutdownhandle the new status.SlotsExhausted, the--keep-worktree(s)help, SKILL.md, and README now say so and point atecluse down <slug> --delete-worktree.new_op_idis unique within a process, and a race test is de-flaked.state.jsonfiles with stopped sessions can't be read by older ecluse versions (noted in CHANGELOG).Test plan
ecluse upfrom the kept worktree resumes at slot 3 (fails on main, passes here)cargo fmt --check,cargo clippy --all-targets -- -D warnings,cargo test(unit + integration)