Reconcile Claude background task state
This commit is contained in:
1 parent
f0661919bb
commit
9fd21af4e8
6 files changed
+310
-24
No files matched your search
@@ -214,6 +214,7 @@ impl ClaudeDriver {
|
||||
session_dir: &Path,
|
||||
sink: EventSink,
|
||||
subagents: Arc<Subagents>,
|
||||
initial_status: SessionStatus,
|
||||
) -> Result<Self> {
|
||||
let state = Arc::new(Mutex::new(Translator::new(
|
||||
session_dir.to_path_buf(),
|
||||
@@ -261,6 +262,9 @@ impl ClaudeDriver {
|
||||
Self::start(meta, provider, transport, session_dir)?
|
||||
}
|
||||
};
|
||||
if !started_here && matches!(initial_status, SessionStatus::Idle | SessionStatus::Waiting) {
|
||||
state.lock().unwrap().mark_settled();
|
||||
}
|
||||
|
||||
// A process this driver has just started has been asked for nothing,
|
||||
// which is what idle means. Said here because nothing else will: the
|
||||
@@ -320,14 +324,22 @@ impl ClaudeDriver {
|
||||
format!("{} {}", provider.name, transport.describe()),
|
||||
));
|
||||
|
||||
Ok(Self {
|
||||
let driver = Self {
|
||||
sink,
|
||||
queue,
|
||||
to_child,
|
||||
state,
|
||||
session_dir: session_dir.to_path_buf(),
|
||||
reading,
|
||||
})
|
||||
};
|
||||
if !started_here {
|
||||
// Claude 2.1.261 sends a full background-task snapshot after a
|
||||
// repeated initialize. That repairs a completion edge missed by a
|
||||
// backend that was down while the CLI kept running; older CLIs
|
||||
// accept the request and simply send no snapshot.
|
||||
driver.send_control(json!({"subtype": "initialize"}), None);
|
||||
}
|
||||
Ok(driver)
|
||||
}
|
||||
|
||||
/// Starts a new CLI for this session, with its streams in the session
|
||||
@@ -866,8 +878,12 @@ fn translate_line(
|
||||
return true;
|
||||
};
|
||||
let opens_a_model_call = starts_a_model_call(&message);
|
||||
let parent_running = queue.lock().unwrap().running;
|
||||
let (events, new_session_id, before) = {
|
||||
let mut state = state.lock().unwrap();
|
||||
if parent_running {
|
||||
state.mark_running();
|
||||
}
|
||||
let before = state.session_id.clone();
|
||||
let events = state.translate(&message);
|
||||
let after = state.session_id.clone();
|
||||
|
||||
Reference in new issue
Block a user