List a session's background tasks above its subagents
The count beside the status said how much work was going and never what,
so "3 bg tasks" was a number with no way to find out what it was about.
Drivers now report the tasks themselves rather than a size:
`Driver::background_tasks` returns `Vec<BackgroundTask>` -- id, the
provider's own description, and a kind -- served by
`GET /sessions/{id}/background`. It is runtime state, never persisted,
and `null` is "nobody has said", which is what a session with no process
answers and what the panel says in words rather than drawing as an empty
list. `description` is optional because Codex names a background terminal
by a process id, and a number drawn as a name is worse than admitting
there is none.
Claude's `background_tasks_changed` entries turn out to be objects
carrying `task_id`, `task_type` and `description`, so each is read rather
than counted -- and an `ambient` one is now dropped from the list and the
count alike, on the CLI's own instruction: a live-update watcher is not
activity, and counting one left a session reading `waiting` with nothing
to wait for.
The phone draws them in the right-hand panel above the subagents,
collapsed to "2 bg tasks running" and pushing the subagents down when
opened. Both lists are items of one lazy column, so neither can run off
the panel, and the section is refetched whenever the live count moves --
a card for work that has finished is exactly the stale measurement the
count exists not to be.
Verified against the real Claude CLI (2.1.261): a backgrounded `sleep 120`
came back as `{"id":"br16327wr","description":"Sleep for 120 seconds",
"kind":"command"}`, and on the emulator against the echo rig the section
appeared, expanded, and dropped a card as its task finished.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c8bfc958ad
commit
942edd6b31
17 files changed
+620
-115
No files matched your search
+19
-14
@@ -75,7 +75,8 @@ use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
use super::driver::{
|
||||
AttachmentRef, Driver, Event, EventSink, QuestionOption, SessionStatus, Unqueued, patch_start,
|
||||
AttachmentRef, BackgroundTask, BackgroundTaskKind, Driver, Event, EventSink, QuestionOption,
|
||||
SessionStatus, Unqueued, patch_start,
|
||||
};
|
||||
use super::subagent::Subagents;
|
||||
|
||||
@@ -124,9 +125,9 @@ pub struct EchoDriver {
|
||||
/// says it recovered, and a clear leaves it unmeasured. What is real is
|
||||
/// which way the numbers move.
|
||||
context: Arc<AtomicU64>,
|
||||
/// Live background commands, for the same count a real provider reports.
|
||||
/// Live background commands, for the same list a real provider reports.
|
||||
/// This is the deterministic UI/session-lifecycle rig for that state.
|
||||
background_tasks: Arc<Mutex<usize>>,
|
||||
background_tasks: Arc<Mutex<Vec<BackgroundTask>>>,
|
||||
/// This session's subagents -- see `SUBAGENTS.md`. `/subagent` is the
|
||||
/// test rig for the same registry the claude driver routes real Task
|
||||
/// calls into.
|
||||
@@ -505,9 +506,13 @@ impl EchoDriver {
|
||||
});
|
||||
let background_tasks = Arc::clone(&self.background_tasks);
|
||||
{
|
||||
let mut count = background_tasks.lock().unwrap();
|
||||
*count += 1;
|
||||
self.emit(Event::BackgroundTasks { count: *count });
|
||||
let mut tasks = background_tasks.lock().unwrap();
|
||||
tasks.push(BackgroundTask {
|
||||
id: id.clone(),
|
||||
description: Some(command.clone()),
|
||||
kind: BackgroundTaskKind::Command,
|
||||
});
|
||||
self.emit(Event::BackgroundTasks { count: tasks.len() });
|
||||
}
|
||||
for word in "Started it; I'll pick this up when it lands.".split_inclusive(' ') {
|
||||
self.emit(Event::AssistantText {
|
||||
@@ -523,9 +528,9 @@ impl EchoDriver {
|
||||
tokio::spawn(async move {
|
||||
tokio::time::sleep(Duration::from_secs(seconds)).await;
|
||||
{
|
||||
let mut count = background_tasks.lock().unwrap();
|
||||
*count -= 1;
|
||||
let _ = sink.send(Event::BackgroundTasks { count: *count });
|
||||
let mut tasks = background_tasks.lock().unwrap();
|
||||
tasks.retain(|task| task.id != id);
|
||||
let _ = sink.send(Event::BackgroundTasks { count: tasks.len() });
|
||||
}
|
||||
let _ = sink.send(Event::ToolUpdate {
|
||||
id,
|
||||
@@ -541,9 +546,9 @@ impl EchoDriver {
|
||||
tokio::time::sleep(DELTA_DELAY).await;
|
||||
}
|
||||
{
|
||||
let count = background_tasks.lock().unwrap();
|
||||
let tasks = background_tasks.lock().unwrap();
|
||||
let _ = sink.send(Event::Status {
|
||||
state: if *count == 0 {
|
||||
state: if tasks.is_empty() {
|
||||
SessionStatus::Idle
|
||||
} else {
|
||||
SessionStatus::Waiting
|
||||
@@ -911,7 +916,7 @@ impl EchoDriver {
|
||||
sink,
|
||||
pending_questions: Mutex::new(Vec::new()),
|
||||
context: Arc::new(AtomicU64::new(0)),
|
||||
background_tasks: Arc::new(Mutex::new(0)),
|
||||
background_tasks: Arc::new(Mutex::new(Vec::new())),
|
||||
busy: Arc::new(AtomicBool::new(false)),
|
||||
queued: Arc::new(Mutex::new(Vec::new())),
|
||||
session_dir,
|
||||
@@ -1222,8 +1227,8 @@ fn finish_turn(sink: &EventSink, queued: &Mutex<Vec<Held>>, busy: &AtomicBool) {
|
||||
}
|
||||
|
||||
impl Driver for EchoDriver {
|
||||
fn background_tasks(&self) -> Option<usize> {
|
||||
Some(*self.background_tasks.lock().unwrap())
|
||||
fn background_tasks(&self) -> Option<Vec<BackgroundTask>> {
|
||||
Some(self.background_tasks.lock().unwrap().clone())
|
||||
}
|
||||
|
||||
fn between_turns(&self) -> bool {
|
||||
|
||||
Reference in new issue
Block a user