fix(client): Fix sessiongs getting in a bad state when creation is aborted - #958
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughActivation now aborts pending sessions on Ctrl-C, while the daemon records sessions per connection and reaps unfinalized sessions when connections close. Finalized Active sessions are preserved, with coverage for selective teardown cleanup. ChangesSession cleanup lifecycle
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant Daemon
participant Connection
participant SessionStore
Client->>Daemon: CreateSession
Daemon->>Connection: record_created_session(session_id)
Client->>Daemon: Upload and finalize
Daemon->>SessionStore: Mark session Active
Client->>Connection: Disconnect or press Ctrl-C
Connection->>Daemon: take_created_sessions()
Daemon->>SessionStore: Re-read session status
Daemon->>SessionStore: Delete unfinalized session
Possibly related issues
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/minimald/src/rpc.rs (1)
172-213: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy liftTrack
CreateSessionbefore draining on disconnect.handle_ssh_rpcdispatches RPCs viadrop(spawn(...)), so a disconnect can race betweenmngr.create_session(...)andconn.record_created_session(id).await. Ifsession_fut.awaitreaches teardown first,take_created_sessions()can miss that id and leave the new session unreaped. A per-connection join/counter that teardown waits on would close the gap.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/minimald/src/rpc.rs` around lines 172 - 213, Update the CreateSession handling around serve_create_session and the handle_ssh_rpc dispatch so session creation is tracked before it can race with disconnect teardown. Add or reuse per-connection in-flight RPC coordination, ensure teardown waits for the CreateSession operation to finish before calling take_created_sessions(), and only then record the created session ID so newly created sessions cannot be missed or left unreaped.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@crates/minimald/src/rpc.rs`:
- Around line 172-213: Update the CreateSession handling around
serve_create_session and the handle_ssh_rpc dispatch so session creation is
tracked before it can race with disconnect teardown. Add or reuse per-connection
in-flight RPC coordination, ensure teardown waits for the CreateSession
operation to finish before calling take_created_sessions(), and only then record
the created session ID so newly created sessions cannot be missed or left
unreaped.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cba8ae9a-bed7-40d9-9997-f2b7f4201ee5
📒 Files selected for processing (4)
crates/minimal/src/lib.rscrates/minimald/src/connection.rscrates/minimald/src/rpc.rscrates/minimald/src/server.rs
fa8527f to
703d1ca
Compare
Problem
Aborting min activate during composition/permission gating — e.g. pressing Ctrl-C at a Package … wants to patch … prompt — left a session wedged on the daemon. It couldn't be re-activated (name already taken), couldn't be attached to ("awaiting its contribution verdict"), and only got cleaned up on a daemon restart. The session name was effectively occupied forever.
Root cause
At the gating prompt, dialoguer → console re-raises SIGINT to the process on Ctrl-C (console unix_term.rs → libc::raise(SIGINT)). min installed no SIGINT handler, so the default disposition killed the process mid-prompt — before the existing abort-cleanup (drive_pending_to_active → send_abort) could run. The daemon was left holding the session in Pending/Draft indefinitely.
(The in-menu "Abort activation" option was fine — it returns through the code and cleans up. It's specifically the raw Ctrl-C / any unclean client exit that orphaned the session.)
Changes
Client-side interrupt handling (crates/minimal/src/lib.rs)
Daemon-side reaping (crates/minimald/src/{connection,rpc,server}.rs) — the robust backstop
Testing
Recovery for already-stuck sessions
Existing daemons without this fix can free a wedged name with min destroy (DestroySession has no Pending guard), or by restarting the daemon.
Summary by CodeRabbit