Continue interrupted work after managed daemon restarts (#45820)

## Why

Daemon recovery reloads threads but leaves interrupted work unfinished. Resume eligible work automatically from the saved conversation, even without a connected client.

## What changed

- Attempt one new continuation turn immediately after restoration, including in Plan mode. Mark the old turn interrupted and supply recovery context without creating a user message or granting new authorization.
- Require an idle thread, matching permissions, and the same single local environment configured by the thread. Skip completed, aborted, or superseded work and snapshots without environment identity.
- Add `continue_turn_if_idle` with an atomic previous-turn check so newer tasks or standalone settings changes invalidate pending continuation.
- Preserve the output schema, service tier, and root turn ID, and emit a “Resuming interrupted work” warning when continuation starts.

## Testing

Add daemon restart coverage for continuation without a client, Plan mode, permission and environment mismatches, and legacy snapshots. Add core coverage for preserved continuation metadata, absence of user-message events, rejection of superseded continuations, and exclusion of remote execution from recovery snapshots.

GitOrigin-RevId: 2b290b75d9399fc58258bcda2e85c74e9b5b3b09
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-16 00:54:58 +00:00
1 parent 7c709f0ffd
commit f2b5b81f39
21 files changed
+641 -55

No files matched your search

+4 -5
View File
@@ -7952,12 +7952,12 @@ async fn remembered_current_cwd_stays_at_launch_across_in_app_resumes() -> Resul
let state_db =
crate::init_state_db_for_app_server_target(&config, &crate::AppServerTarget::Embedded)
.await?;
let mut app_server = crate::start_app_server_for_picker(
let mut app_server = Box::pin(crate::start_app_server_for_picker(
&config,
&crate::AppServerTarget::Embedded,
state_db.clone(),
Arc::new(EnvironmentManager::default_for_tests()),
)
))
.await?;
let (mut app, _app_event_rx, _op_rx) = make_test_app_with_channels().await;
app.config = config;
@@ -7968,9 +7968,8 @@ async fn remembered_current_cwd_stays_at_launch_across_in_app_resumes() -> Resul
let mut tui = crate::tui::test_support::make_test_tui()?;
for target_session in targets {
let control = app
.resume_target_session(&mut tui, &mut app_server, target_session)
.await?;
let control =
Box::pin(app.resume_target_session(&mut tui, &mut app_server, target_session)).await?;
assert!(matches!(control, AppRunControl::Continue));
assert!(!crate::session_resume::cwds_differ(