Take subagent reports out of the main transcript, and separate turns with a rule
A row per finished background task is a screenful of dividers about work the reader was not asking after, and one of them turned out to be a whole shell command drawn as centred prose, because its words came from somewhere with no reason to keep them short. `Event::TaskNote` is gone entirely, along with the row that drew it. A subagent's closing report is recorded as that subagent's own transcript's closing text and is read in the subcard, which is where it was already going; what the parent gets a row for is a message a subagent genuinely sends it, which arrives by the peer path and has had one all along. What remains is the actual defect and the smallest thing that fixes it. The fold still refuses to grow a settled reply, so a turn boundary is always a message boundary, and where two replies then abut it puts a `TurnBreak` between them: a hairline, no words, no colour. Made by the fold rather than sent by the server, because it is not something that happened -- it is the boundary between two things that did. `joinPages` puts one in at a page seam, which the fold never gets to see. The task notification is still what closes a task in `Status::Waiting`'s bookkeeping, and the registry lookup that recognises one this translator never saw start is what makes that work for a session adopted across a restart. Verified on the emulator: three replies, three rules, and nothing about the helpers anywhere in the parent. 170 server tests, 85 JVM tests, ktfmt, clippy, rustfmt and Android lint clean. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ef1aad8776
commit
1bbb642973
13 files changed
+171
-407
No files matched your search
@@ -594,19 +594,19 @@ impl Translator {
|
||||
|
||||
/// A task reporting back, from whichever of the two lines got here first.
|
||||
///
|
||||
/// Reported once. The two shapes can both arrive for one task, and the
|
||||
/// [`Translator::tasks`] entry is what says which of them is the first --
|
||||
/// it is removed here, so a second line for the same task finds nothing
|
||||
/// and says nothing. That is also what stops a task being counted as
|
||||
/// outstanding for ever.
|
||||
/// Handled once. The two shapes can both arrive for one task, and what
|
||||
/// says which of them is the first is that it finds the task still open.
|
||||
///
|
||||
/// Three things come out of it, and the third is the one that is easy to
|
||||
/// leave out. The summary goes into the subagent's own transcript, which
|
||||
/// is the only place its closing words ever appear; the subagent is
|
||||
/// finished; and the *parent* gets an [`Event::TaskNote`], because a
|
||||
/// message arriving is something that happened to this session and the
|
||||
/// turn it wakes up and runs would otherwise begin with nothing in front
|
||||
/// of it.
|
||||
/// **Nothing about it reaches the parent's transcript**, deliberately.
|
||||
/// The summary is the subagent's own closing words and goes into the
|
||||
/// subagent's own transcript, which is the only place it belongs; a row
|
||||
/// per finished task in the session's transcript is a screen of dividers
|
||||
/// about work the reader was not asking after, and the session did not
|
||||
/// receive a message it could act on. What *does* reach the parent is a
|
||||
/// message a subagent genuinely sends it, which arrives by the peer
|
||||
/// path. The only thing produced here is the status: a session with
|
||||
/// nothing outstanding any more has stopped being
|
||||
/// [`SessionStatus::Waiting`].
|
||||
fn task_ended(
|
||||
&mut self,
|
||||
about: Option<String>,
|
||||
@@ -631,23 +631,12 @@ impl Translator {
|
||||
if !self.open_tasks.remove(&about) && !self.subagents.is_open(&about) {
|
||||
return Vec::new();
|
||||
}
|
||||
if let Some(summary) = &summary {
|
||||
self.subagents.record(
|
||||
&about,
|
||||
Event::AssistantText {
|
||||
delta: summary.clone(),
|
||||
},
|
||||
);
|
||||
if let Some(summary) = summary {
|
||||
self.subagents
|
||||
.record(&about, Event::AssistantText { delta: summary });
|
||||
}
|
||||
self.subagents.finish(&about);
|
||||
let mut events = vec![Event::TaskNote {
|
||||
title: self.subagents.title_of(&about),
|
||||
about,
|
||||
// Present by construction: `ended` says no to a line with no
|
||||
// status at all.
|
||||
status: status.unwrap_or_default().to_string(),
|
||||
summary,
|
||||
}];
|
||||
let mut events = Vec::new();
|
||||
// The last outstanding task, with the session's own turn already
|
||||
// over: it has stopped being `Waiting` and nothing else will say so.
|
||||
// Inside a turn there is nothing to announce -- the turn's own
|
||||
@@ -1473,17 +1462,9 @@ mod tests {
|
||||
r#"{"type":"system","subtype":"task_notification","task_id":"t1","tool_use_id":"toolu_bg","status":"completed","summary":"pushed as c41c36f"}"#,
|
||||
],
|
||||
),
|
||||
vec![
|
||||
Event::TaskNote {
|
||||
about: "toolu_bg".into(),
|
||||
title: Some("the Dev Updater agent".into()),
|
||||
status: "completed".into(),
|
||||
summary: Some("pushed as c41c36f".into()),
|
||||
},
|
||||
Event::Status {
|
||||
state: SessionStatus::Idle
|
||||
},
|
||||
]
|
||||
vec![Event::Status {
|
||||
state: SessionStatus::Idle
|
||||
}]
|
||||
);
|
||||
|
||||
// Reported once. The two lifecycle shapes can both arrive for one
|
||||
@@ -1539,17 +1520,9 @@ mod tests {
|
||||
r#"{"type":"system","subtype":"task_notification","task_id":"old","tool_use_id":"toolu_old","status":"completed","summary":"pushed"}"#,
|
||||
],
|
||||
),
|
||||
vec![
|
||||
Event::TaskNote {
|
||||
about: "toolu_old".into(),
|
||||
title: Some("the Dev Updater agent".into()),
|
||||
status: "completed".into(),
|
||||
summary: Some("pushed".into()),
|
||||
},
|
||||
Event::Status {
|
||||
state: SessionStatus::Idle
|
||||
},
|
||||
]
|
||||
vec![Event::Status {
|
||||
state: SessionStatus::Idle
|
||||
}]
|
||||
);
|
||||
// Once: `finish` closed it, so the second shape finds nothing.
|
||||
assert!(
|
||||
@@ -1586,10 +1559,16 @@ mod tests {
|
||||
!events.iter().any(closes_a_turn),
|
||||
"the turn has not ended: {events:?}"
|
||||
);
|
||||
// The helper's summary went where it belongs and nowhere else.
|
||||
let subagent = subagents.get("toolu_fg").expect("subagent started");
|
||||
let lines =
|
||||
crate::session::transcript::read_after(&subagent.transcript_path(), 0).expect("read");
|
||||
assert!(
|
||||
events
|
||||
.iter()
|
||||
.any(|event| matches!(event, Event::TaskNote { .. }))
|
||||
lines.iter().any(|entry| matches!(
|
||||
&entry.event,
|
||||
Event::AssistantText { delta } if delta == "done"
|
||||
)),
|
||||
"{lines:?}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user