fix(maestro): three defects the review flagged and left open
ci / web (pull_request) Successful in 28s
ci / rust (pull_request) Successful in 1m58s
ci / web (push) Successful in 34s
ci / rust (push) Successful in 2m44s

SPA attach had no reconnect at all. Any dropped frame closed the socket,
`onClosed` fired, and the pane was destroyed permanently — the TUI
reconnects forever on the same endpoint. Session death also reached the UI
on two uncoordinated channels: the row from the events socket, the pane
from `ws.onclose`, with nothing reconciling them, so either could happen
without the other.

The catalog is now the authority. `shouldRetryClose` decides from session
status: Running means the link dropped, so retry with 500ms-to-10s
backoff; Dead means the PTY stream was sealed and nothing more is coming;
absent means it is gone. Application closes (4000+, a relayed daemon
rejection) and clean closes are never retried. The shell also closes any
pane whose session has left the catalog. The policy lives in reconnect.ts
so it is tested without a DOM.

kill_session checked `has()` before `kill()`, which only opened a window
for the liveness watcher to reap in between — turning a 404 into a 502.
`kill` reports the miss itself.

with_spawn_history logged and carried on when `Arc::get_mut` failed,
producing a daemon whose recent-dirs picker is permanently empty with
nothing to show for it. It panics now: that is a construction-order
mistake, at startup, in code that runs once.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit was merged in pull request #50.
This commit is contained in:
Miguel Palhas
2026-08-22 16:31:54 +01:00
co-authored by Claude Opus 5
parent 812861f883
commit f31377c34f
9 changed files with 234 additions and 58 deletions
+3 -7
View File
@@ -135,14 +135,10 @@ async fn create_session(
}
}
/// `kill` already reports a missing session as `SessionError::NotFound`, which
/// maps to 404. Checking first would only add a window in which the liveness
/// watcher reaps the session between the two awaits, turning a 404 into a 502.
async fn kill_session(State(s): State<LocalApiState>, Path(id): Path<Uuid>) -> Response {
if !s.manager.has(id).await {
return error_response(
StatusCode::NOT_FOUND,
"unknown_session",
"no such session on this daemon",
);
}
match s.manager.kill(id).await {
Ok(()) => StatusCode::NO_CONTENT.into_response(),
Err(e) => {
+11 -9
View File
@@ -145,16 +145,18 @@ impl SessionManager {
}
/// Attach a durable spawn-history log (#24). Builder, called once right
/// after construction while the `Arc<Inner>` is uniquely owned — so
/// [`Arc::get_mut`] succeeds. A no-op (logged) on the off chance the handle
/// was already cloned.
/// after construction while the `Arc<Inner>` is uniquely owned.
///
/// # Panics
///
/// If the handle has already been cloned. That is a construction-order
/// mistake, and the alternative — logging and carrying on — produces a
/// daemon whose "recent dirs" picker is permanently empty with nothing to
/// show for it.
pub fn with_spawn_history(mut self, history: SpawnHistory) -> Self {
match Arc::get_mut(&mut self.inner) {
Some(inner) => inner.spawn_history = Some(history),
None => tracing::error!(
"with_spawn_history called after the SessionManager was cloned; ignoring"
),
}
let inner = Arc::get_mut(&mut self.inner)
.expect("with_spawn_history must be called before the SessionManager is cloned");
inner.spawn_history = Some(history);
self
}
@@ -362,3 +362,37 @@ async fn wait_for_updated(
}
panic!("timed out waiting for SessionUpdated");
}
/// The kill handler used to check `has()` first, which opened a window for the
/// liveness watcher to reap the session in between — turning a 404 into a 502.
/// `kill` reports the miss itself now.
#[tokio::test]
async fn killing_an_unknown_session_is_reported_as_not_found() {
let fx = Fx::new();
let err = fx
.manager
.kill(uuid::Uuid::new_v4())
.await
.expect_err("should fail");
assert_eq!(err.to_error_info().code, "not_found");
}
/// A construction-order mistake must be loud: a silently-ignored history leaves
/// the recent-dirs picker permanently empty.
#[test]
#[should_panic(expected = "before the SessionManager is cloned")]
fn attaching_spawn_history_after_cloning_panics() {
let tmp = TempDir::new().expect("tempdir");
let fake = Arc::new(FakePanes::new());
let manager = SessionManager::new(
fake,
SidecarStore::new(tmp.path().join("sidecars")),
WorktreeManager::new(tmp.path().join("worktrees")),
tmp.path().join("fifos"),
);
let _clone = manager.clone();
let _ = manager.with_spawn_history(maestro_daemon::spawn_history::SpawnHistory::new(
tmp.path().join("history.jsonl"),
7,
));
}