Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(agent): show upstream retries live instead of only in the muted log (#9089)

Akarshan Biswas33c10523e7b7
diff --git a/adk/python/jan_adk/_generated.py b/adk/python/jan_adk/_generated.py
index 91fc8adca..79a4d74d2 100644
--- a/adk/python/jan_adk/_generated.py
+++ b/adk/python/jan_adk/_generated.py
@@ -44,6 +44,7 @@ EVENT_TAGS: tuple[str, ...] = (
"subagent",
"notice",
"compaction",
+ "retry",
"monitors",
"parked",
"messages_updated",
@@ -94,6 +95,7 @@ EventTag = Literal[
"subagent",
"notice",
"compaction",
+ "retry",
"monitors",
"parked",
"messages_updated",
@@ -390,6 +392,15 @@ class CompactionEvent(TypedDict):
messages: NotRequired[Union[int, None]]
type: Literal["compaction"]
+class RetryEvent(TypedDict):
+ """`item/retry`"""
+
+ attempt: int
+ max_attempts: int
+ delay_ms: int
+ reason: str
+ type: Literal["retry"]
+
class MonitorsEvent(TypedDict):
"""`item/monitors`"""
@@ -529,6 +540,7 @@ StreamEvent = Union[
SubagentEvent,
NoticeEvent,
CompactionEvent,
+ RetryEvent,
MonitorsEvent,
ParkedEvent,
MessagesUpdatedEvent,
diff --git a/packages/adk/src/generated/rpc-types.d.ts b/packages/adk/src/generated/rpc-types.d.ts
index 6959295f9..5d6184be9 100644
--- a/packages/adk/src/generated/rpc-types.d.ts
+++ b/packages/adk/src/generated/rpc-types.d.ts
@@ -39,6 +39,7 @@ export type EventTag =
| "subagent"
| "notice"
| "compaction"
+ | "retry"
| "monitors"
| "parked"
| "messages_updated"
@@ -360,6 +361,15 @@ export interface CompactionEvent {
"type": "compaction"
}
+/** The upstream request failed before anything streamed and is about to be sent again after `delay_ms`. `attempt` is the 1-based attempt that follows the wait, out of `max_attempts`; `reason` is the failure that prompted it. Sent once per retry so a consumer can say "retrying" rather than show a spinner that looks like a slow model. Display-only and never journaled; the turn continues with the next event or ends in `Error`. */
+export interface RetryEvent {
+ "attempt": number
+ "max_attempts": number
+ "delay_ms": number
+ "reason": string
+ "type": "retry"
+}
+
/** The run's active file monitors, as a whole replacing the previous set. Emitted whenever the set changes (a `monitor` start or stop, a condition matching, a monitor finishing), so a consumer keeps a live view without bookkeeping of its own. Display-only and never journaled. Not forwarded from a child: a child's monitors are its own. */
export interface MonitorsEvent {
"monitors": MonitorSnapshot[]
@@ -499,6 +509,7 @@ export type StreamEvent =
| SubagentEvent
| NoticeEvent
| CompactionEvent
+ | RetryEvent
| MonitorsEvent
| ParkedEvent
| MessagesUpdatedEvent
@@ -531,6 +542,7 @@ export interface EventByTag {
"subagent": SubagentEvent
"notice": NoticeEvent
"compaction": CompactionEvent
+ "retry": RetryEvent
"monitors": MonitorsEvent
"parked": ParkedEvent
"messages_updated": MessagesUpdatedEvent
diff --git a/packages/adk/src/generated/rpc-types.js b/packages/adk/src/generated/rpc-types.js
index 4a2944a25..ffe900522 100644
--- a/packages/adk/src/generated/rpc-types.js
+++ b/packages/adk/src/generated/rpc-types.js
@@ -21,6 +21,7 @@ export const EVENT_TAGS = Object.freeze([
"subagent",
"notice",
"compaction",
+ "retry",
"monitors",
"parked",
"messages_updated",
diff --git a/protocol/rpc-schema.json b/protocol/rpc-schema.json
index 78f6f2c79..567262298 100644
--- a/protocol/rpc-schema.json
+++ b/protocol/rpc-schema.json
@@ -838,6 +838,41 @@
"reason"
]
},
+ {
+ "description": "The upstream request failed before anything streamed and is about to be\nsent again after `delay_ms`. `attempt` is the 1-based attempt that\nfollows the wait, out of `max_attempts`; `reason` is the failure that\nprompted it. Sent once per retry so a consumer can say \"retrying\" rather\nthan show a spinner that looks like a slow model. Display-only and never\njournaled; the turn continues with the next event or ends in `Error`.",
+ "type": "object",
+ "properties": {
+ "attempt": {
+ "type": "integer",
+ "format": "uint32",
+ "minimum": 0
+ },
+ "max_attempts": {
+ "type": "integer",
+ "format": "uint32",
+ "minimum": 0
+ },
+ "delay_ms": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0
+ },
+ "reason": {
+ "type": "string"
+ },
+ "type": {
+ "type": "string",
+ "const": "retry"
+ }
+ },
+ "required": [
+ "type",
+ "attempt",
+ "max_attempts",
+ "delay_ms",
+ "reason"
+ ]
+ },
{
"description": "The run's active file monitors, as a whole replacing the previous set.\nEmitted whenever the set changes (a `monitor` start or stop, a condition\nmatching, a monitor finishing), so a consumer keeps a live view without\nbookkeeping of its own. Display-only and never journaled. Not forwarded\nfrom a child: a child's monitors are its own.",
"type": "object",
diff --git a/protocol/schema.json b/protocol/schema.json
index f4df3f009..09a38e149 100644
--- a/protocol/schema.json
+++ b/protocol/schema.json
@@ -396,6 +396,41 @@
"reason"
]
},
+ {
+ "description": "The upstream request failed before anything streamed and is about to be\nsent again after `delay_ms`. `attempt` is the 1-based attempt that\nfollows the wait, out of `max_attempts`; `reason` is the failure that\nprompted it. Sent once per retry so a consumer can say \"retrying\" rather\nthan show a spinner that looks like a slow model. Display-only and never\njournaled; the turn continues with the next event or ends in `Error`.",
+ "type": "object",
+ "properties": {
+ "attempt": {
+ "type": "integer",
+ "format": "uint32",
+ "minimum": 0
+ },
+ "max_attempts": {
+ "type": "integer",
+ "format": "uint32",
+ "minimum": 0
+ },
+ "delay_ms": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0
+ },
+ "reason": {
+ "type": "string"
+ },
+ "type": {
+ "type": "string",
+ "const": "retry"
+ }
+ },
+ "required": [
+ "type",
+ "attempt",
+ "max_attempts",
+ "delay_ms",
+ "reason"
+ ]
+ },
{
"description": "The run's active file monitors, as a whole replacing the previous set.\nEmitted whenever the set changes (a `monitor` start or stop, a condition\nmatching, a monitor finishing), so a consumer keeps a live view without\nbookkeeping of its own. Display-only and never journaled. Not forwarded\nfrom a child: a child's monitors are its own.",
"type": "object",
diff --git a/src-tauri/src/core/agent/events.rs b/src-tauri/src/core/agent/events.rs
index b494c7717..951bbc747 100644
--- a/src-tauri/src/core/agent/events.rs
+++ b/src-tauri/src/core/agent/events.rs
@@ -185,6 +185,18 @@ pub enum StreamEvent {
#[serde(default, skip_serializing_if = "Option::is_none")]
messages: Option<usize>,
},
+ /// The upstream request failed before anything streamed and is about to be
+ /// sent again after `delay_ms`. `attempt` is the 1-based attempt that
+ /// follows the wait, out of `max_attempts`; `reason` is the failure that
+ /// prompted it. Sent once per retry so a consumer can say "retrying" rather
+ /// than show a spinner that looks like a slow model. Display-only and never
+ /// journaled; the turn continues with the next event or ends in `Error`.
+ Retry {
+ attempt: u32,
+ max_attempts: u32,
+ delay_ms: u64,
+ reason: String,
+ },
/// The run's active file monitors, as a whole replacing the previous set.
/// Emitted whenever the set changes (a `monitor` start or stop, a condition
/// matching, a monitor finishing), so a consumer keeps a live view without
@@ -615,6 +627,15 @@ pub(crate) mod tests {
messages: Some(12),
},
),
+ (
+ "Retry",
+ StreamEvent::Retry {
+ attempt: 2,
+ max_attempts: 10,
+ delay_ms: 250,
+ reason: "Upstream returned HTTP 503: busy".into(),
+ },
+ ),
(
"Monitors",
StreamEvent::Monitors {
@@ -778,6 +799,7 @@ pub(crate) mod tests {
| StreamEvent::Subagent { .. }
| StreamEvent::Notice { .. }
| StreamEvent::Compaction { .. }
+ | StreamEvent::Retry { .. }
| StreamEvent::Monitors { .. }
| StreamEvent::Parked
| StreamEvent::MessagesUpdated { .. }
diff --git a/src-tauri/src/core/agent/genai_bridge.rs b/src-tauri/src/core/agent/genai_bridge.rs
index 0997b24b3..29555c5ae 100644
--- a/src-tauri/src/core/agent/genai_bridge.rs
+++ b/src-tauri/src/core/agent/genai_bridge.rs
@@ -827,6 +827,16 @@ pub(crate) async fn stream_chat_completions(
delay.as_millis(),
attempt + 2
);
+ // The TUI mutes the log, so the warning above never
+ // reaches the user; the event is what they see.
+ let _ = events.send(StreamEvent::Retry {
+ attempt: attempt + 2,
+ max_attempts: MAX_ATTEMPTS,
+ delay_ms: delay.as_millis() as u64,
+ // genai's errors span lines (Cause/Status/Body);
+ // a status row has one.
+ reason: last_err.split_whitespace().collect::<Vec<_>>().join(" "),
+ });
tokio::time::sleep(delay).await;
}
}
@@ -1603,6 +1613,52 @@ mod tests {
server.await.expect("server");
}
+ /// The TUI mutes the log facade, so a retry announced only through
+ /// `log::warn!` left the user watching a spinner for up to the whole retry
+ /// budget. Each retry has to reach the consumer as an event, before the
+ /// backoff sleep, naming the attempt about to run and why.
+ #[tokio::test]
+ async fn each_retry_is_announced_before_the_backoff() {
+ let (url, server) = serve(vec![
+ Some(status_response(503, "Service Unavailable", r#"{"error":"busy"}"#)),
+ None,
+ Some(sse_response(&[
+ r#"{"choices":[{"delta":{"content":"hi"}}]}"#,
+ r#"{"choices":[{"delta":{},"finish_reason":"stop"}]}"#,
+ ])),
+ ])
+ .await;
+
+ let (tx, mut rx) = sink();
+ run(&url, &[], &tx).await.expect("the retries carry the turn");
+
+ drop(tx);
+ let events: Vec<StreamEvent> = std::iter::from_fn(|| rx.try_recv().ok()).collect();
+ let retries: Vec<(u32, u32, u64, String)> = events
+ .iter()
+ .filter_map(|ev| match ev {
+ StreamEvent::Retry {
+ attempt,
+ max_attempts,
+ delay_ms,
+ reason,
+ } => Some((*attempt, *max_attempts, *delay_ms, reason.clone())),
+ _ => None,
+ })
+ .collect();
+ assert_eq!(retries.len(), 2, "one event per retry: {events:?}");
+ assert_eq!((retries[0].0, retries[0].1), (2, MAX_ATTEMPTS));
+ assert_eq!((retries[1].0, retries[1].1), (3, MAX_ATTEMPTS));
+ assert_eq!(retries[0].2, BASE_RETRY_DELAY.as_millis() as u64);
+ assert_eq!(retries[1].2, 2 * BASE_RETRY_DELAY.as_millis() as u64);
+ assert!(retries[0].3.contains("503"), "{}", retries[0].3);
+ assert!(!retries[0].3.contains('\n'), "a one-line reason: {}", retries[0].3);
+ let first_token = events.iter().position(|e| matches!(e, StreamEvent::Token { .. }));
+ let last_retry = events.iter().rposition(|e| matches!(e, StreamEvent::Retry { .. }));
+ assert!(first_token > last_retry, "the retries precede the answer: {events:?}");
+ server.await.expect("server");
+ }
+
/// 401 rotates to the next key rather than burning retries on a key the
/// upstream has already rejected.
#[tokio::test]
diff --git a/src-tauri/src/core/cli/mod.rs b/src-tauri/src/core/cli/mod.rs
index 8759fb441..6be466c5a 100644
--- a/src-tauri/src/core/cli/mod.rs
+++ b/src-tauri/src/core/cli/mod.rs
@@ -2932,6 +2932,14 @@ async fn print_event(ev: StreamEvent, registry: &PermissionRegistry, duplex: boo
reason,
messages,
} => eprintln!("\x1b[2m[compaction] {}\x1b[0m", describe_compaction(phase, reason, messages)),
+ StreamEvent::Retry {
+ attempt,
+ max_attempts,
+ delay_ms,
+ reason,
+ } => eprintln!(
+ "\x1b[2m[retry] {reason}; attempt {attempt}/{max_attempts} in {delay_ms}ms\x1b[0m"
+ ),
// The snapshot backs a live panel the headless printer has no room
// for; `Notice` already reports each match as it lands.
StreamEvent::Monitors { .. } => {}
@@ -2954,6 +2962,14 @@ async fn print_event(ev: StreamEvent, registry: &PermissionRegistry, duplex: boo
"\x1b[2m[subagent:{name}] [compaction] {}\x1b[0m",
describe_compaction(phase, reason, messages)
),
+ StreamEvent::Retry {
+ attempt,
+ max_attempts,
+ delay_ms,
+ reason,
+ } => eprintln!(
+ "\x1b[2m[subagent:{name}] [retry] {reason}; attempt {attempt}/{max_attempts} in {delay_ms}ms\x1b[0m"
+ ),
_ => {}
},
StreamEvent::Done { stop_reason, usage } => {
diff --git a/src-tauri/src/core/cli/run_report.rs b/src-tauri/src/core/cli/run_report.rs
index 447705b2c..13468015f 100644
--- a/src-tauri/src/core/cli/run_report.rs
+++ b/src-tauri/src/core/cli/run_report.rs
@@ -14,7 +14,7 @@
//! `step`, `tool_call_started`, `tool_call_args_delta`, `tool_call`,
//! `tool_output_delta`, `tool_result`, `subagent_start`, `subagent_queued`,
//! `subagent_end`, `subagent_plan`, `subagent`, `notice`, `compaction`,
-//! `monitors`, `parked`, `messages_updated`, `ask_request`, `ask_resolved`,
+//! `retry`, `monitors`, `parked`, `messages_updated`, `ask_request`, `ask_resolved`,
//! `todo_update`, `turn_usage`, `done`, `error`, `permission_request`,
//! `tool_request`, `tool_request_cancelled`, `tool_details`,
//! `request_provenance`. Four tags are
diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rs
index 40e5093e6..b9db2ad74 100644
--- a/src-tauri/src/core/cli/tui.rs
+++ b/src-tauri/src/core/cli/tui.rs
@@ -2163,6 +2163,11 @@ struct App {
/// or budget path), and since when. Display-only: unlike `compacting` it
/// gates nothing, because the run that compacts is the one already going.
run_compacting: Option<Instant>,
+ /// The running turn's upstream request failed before anything streamed and
+ /// the loop is waiting to resend it. Display-only, like `run_compacting`;
+ /// cleared by the next event of the parent run, since any of them means the
+ /// wait is over.
+ retrying: Option<RetryWait>,
/// A mid-run compaction finished, so the next `MessagesUpdated` carries a
/// shorter history the gauge must be re-estimated against.
pending_compaction_refresh: bool,
@@ -2739,6 +2744,7 @@ impl App {
compacting: None,
compact_started: None,
run_compacting: None,
+ retrying: None,
pending_compaction_refresh: false,
retry_after_compact: false,
overflow_retries: 0,
@@ -5367,6 +5373,13 @@ impl App {
/// Non-terminal stream events. `Done`/`Error` are handled by the loop since
/// they mutate history and the run handle.
fn apply(&mut self, ev: StreamEvent) {
+ // Whatever the parent run sends next -- a token, a tool call -- means
+ // the wait for a resend is over. A child's events say nothing about
+ // the parent's request. The terminal events never come through here;
+ // `apply_stream_event` clears it for those.
+ if !matches!(ev, StreamEvent::Retry { .. } | StreamEvent::Subagent { .. }) {
+ self.retrying = None;
+ }
match ev {
StreamEvent::Token { text } => {
self.assistant_buf.push_str(&text);
@@ -5791,6 +5804,26 @@ impl App {
self.note(&text);
}
StreamEvent::Monitors { monitors } => self.monitors = monitors,
+ // The live countdown carries every attempt; the transcript notes
+ // only the first, so a flaky link leaves one line, not ten.
+ StreamEvent::Retry {
+ attempt,
+ max_attempts,
+ delay_ms,
+ reason,
+ } => {
+ if attempt == 2 {
+ self.finalize_tool_group();
+ self.flush_assistant();
+ self.note(&format!("{reason}; retrying"));
+ }
+ self.retrying = Some(RetryWait {
+ attempt,
+ max_attempts,
+ at: Instant::now() + Duration::from_millis(delay_ms),
+ reason,
+ });
+ }
// The model is done and the loop waits on background work it
// dispatched. Nothing is generating, so present as idle (see
// `Status::Parked`) while the run stays open.
@@ -5980,6 +6013,15 @@ impl App {
StreamEvent::Notice { text } => {
self.note(&format!("{name}: {text}"));
}
+ // The live countdown belongs to the parent's request; a child's
+ // retry gets the same one-line note the parent's first retry does.
+ StreamEvent::Retry {
+ attempt: 2,
+ reason,
+ ..
+ } => {
+ self.note(&format!("{name}: {reason}; retrying"));
+ }
// A child's compaction is announced, but the spinner and gauge are
// the parent's: the child's history is not the one on screen.
StreamEvent::Compaction {
@@ -6436,6 +6478,9 @@ impl App {
}
self.status = Status::Idle;
self.run_started = None;
+ // A cancel sends no further event to clear it, so an interrupted wait
+ // would otherwise leave `[retrying]` over an idle session.
+ self.retrying = None;
// Drop any run queued but not yet spawned (still gated on model/MCP/
// snapshot readiness); otherwise the loop starts it once ready and the
// cancel is silently undone.
@@ -8077,6 +8122,30 @@ struct StartingCall {
preview_at: Option<usize>,
}
+/// The input row while a resend is pending: a countdown until it goes out,
+/// then the attempt itself, which can take as long as a connect timeout.
+fn retry_wait_label(wait: &RetryWait, now: Instant) -> String {
+ let left = wait.at.saturating_duration_since(now);
+ let when = if left.is_zero() {
+ "retrying".to_string()
+ } else {
+ format!("retrying in {}s", left.as_secs_f32().ceil() as u64)
+ };
+ format!(
+ "{when} (attempt {}/{})… {}",
+ wait.attempt, wait.max_attempts, wait.reason
+ )
+}
+
+/// A pending resend of a failed upstream request, from `StreamEvent::Retry`.
+struct RetryWait {
+ attempt: u32,
+ max_attempts: u32,
+ /// When the resend goes out, for the countdown.
+ at: Instant,
+ reason: String,
+}
+
impl StartingCall {
fn new(id: String, name: String) -> Self {
Self {
@@ -9756,6 +9825,15 @@ async fn apply_stream_event(
current: &mut Option<CurrentRun>,
) {
note_claude_alias_if_engaged(app);
+ // `Done`, `Error` and a closed stream end the run without passing through
+ // `App::apply`, so they would otherwise leave `[retrying]` over an idle
+ // session once the retries run out.
+ if matches!(
+ ev,
+ None | Some(StreamEvent::Done { .. } | StreamEvent::Error { .. })
+ ) {
+ app.retrying = None;
+ }
match ev {
Some(StreamEvent::Done { stop_reason, usage }) => {
app.on_done(stop_reason, usage);
@@ -19512,6 +19590,8 @@ fn header_spans(app: &App) -> Vec<Span<'static>> {
(kind.label().to_string(), Style::new().magenta().bold())
} else if app.run_compacting.is_some() {
("compacting".to_string(), Style::new().magenta().bold())
+ } else if app.retrying.is_some() {
+ ("retrying".to_string(), Style::new().yellow().bold())
} else if app.mcp_auth.is_some() {
// A sign-in runs while the model is otherwise idle; the badge stands in
// for `[ready]` so the pending auth is visible even off the `/mcp` screen.
@@ -20082,6 +20162,14 @@ fn input_box(app: &App) -> Paragraph<'static> {
),
]))
.block(block)
+ } else if let Some(wait) = app.retrying.as_ref().filter(|_| app.input.is_empty()) {
+ // Without this the row reads "working" through up to the whole retry
+ // budget, indistinguishable from a slow model.
+ Paragraph::new(Line::from(vec![
+ Span::styled(format!("{} ", app.spinner()), Style::new().yellow()),
+ Span::styled(retry_wait_label(wait, Instant::now()), Style::new().dim().italic()),
+ ]))
+ .block(block)
} else if app.picker.is_some() {
Paragraph::new(Line::styled("selecting…", Style::new().dim().italic())).block(block)
} else if app.status == Status::Running && app.input.is_empty() {
@@ -20363,7 +20451,8 @@ mod tests {
};
use super::{
agent_detail_lines, agent_picker_items, agents_column, background_shell_picker_items,
- cache_summary_lines, collapse_runs, open_agents_picker, trailing_repeat, SubagentPanel,
+ cache_summary_lines, collapse_runs, open_agents_picker, retry_wait_label, trailing_repeat,
+ RetryWait, SubagentPanel,
};
use crate::core::agent::events::{StreamEvent, Usage};
use crate::core::agent::r#loop::PermissionRegistry;
@@ -31920,6 +32009,113 @@ mod tests {
assert!(app.tokens_estimated);
}
+ fn retry(attempt: u32) -> StreamEvent {
+ StreamEvent::Retry {
+ attempt,
+ max_attempts: 10,
+ delay_ms: 2_000,
+ reason: "Upstream request failed: connection refused".into(),
+ }
+ }
+
+ /// A retry is visible while it waits: the header says `retrying`, the input
+ /// row counts down with the attempt and the reason, and the transcript notes
+ /// the first retry only. The next event of the run clears it.
+ #[test]
+ fn a_retry_is_shown_live_and_cleared_by_the_next_event() {
+ let mut app = test_app();
+ app.status = Status::Running;
+ app.apply(retry(2));
+ app.apply(retry(3));
+
+ let header: String = header_spans(&app).iter().map(|s| s.content.to_string()).collect();
+ assert!(header.contains("retrying"), "{header}");
+ let out = render_rows(&mut app, 120, 20).join("\n");
+ assert!(out.contains("retrying in 2s (attempt 3/10)"), "{out}");
+ assert!(out.contains("connection refused"), "{out}");
+ let notes = transcript_text(&app);
+ assert_eq!(notes.matches("retrying").count(), 1, "one note per failure: {notes}");
+
+ app.apply(StreamEvent::Token { text: "hi".into() });
+ assert!(app.retrying.is_none());
+ let header: String = header_spans(&app).iter().map(|s| s.content.to_string()).collect();
+ assert!(!header.contains("retrying"), "{header}");
+ }
+
+ /// Cancelling during the wait takes the countdown down with the run.
+ #[test]
+ fn cancelling_during_a_retry_clears_it() {
+ let mut app = test_app();
+ app.status = Status::Running;
+ app.apply(retry(2));
+ app.cancel_run();
+ assert!(app.retrying.is_none());
+ let header: String = header_spans(&app).iter().map(|s| s.content.to_string()).collect();
+ assert!(header.contains("ready"), "{header}");
+ }
+
+ /// Every way a run ends after a retry takes the countdown down: running
+ /// out of retries (`Error`), a late success (`Done`), and a stream that
+ /// closes without a terminal event. These never reach `App::apply`, so
+ /// they are driven through the loop's `apply_stream_event`.
+ #[tokio::test]
+ async fn a_run_ending_during_a_retry_clears_it() {
+ let terminals = [
+ Some(StreamEvent::Error {
+ code: "upstream".into(),
+ message: "connection refused".into(),
+ }),
+ Some(StreamEvent::Done { stop_reason: "stop".into(), usage: None }),
+ None,
+ ];
+ for end in terminals {
+ let label = format!("{end:?}");
+ let mut app = test_app();
+ app.status = Status::Running;
+ let mut current = None;
+ apply_stream_event(&mut app, Some(retry(10)), &mut current).await;
+ assert!(app.retrying.is_some(), "{label}");
+ apply_stream_event(&mut app, end, &mut current).await;
+ assert!(app.retrying.is_none(), "{label}");
+ let header: String =
+ header_spans(&app).iter().map(|s| s.content.to_string()).collect();
+ assert!(!header.contains("retrying"), "{label}: {header}");
+ }
+ }
+
+ /// The countdown turns into the attempt itself once the wait is over,
+ /// rather than sitting on "in 0s" through a connect timeout.
+ #[test]
+ fn a_retry_past_its_wait_reads_as_in_flight() {
+ let at = Instant::now();
+ let wait = RetryWait {
+ attempt: 4,
+ max_attempts: 10,
+ at,
+ reason: "boom".into(),
+ };
+ assert_eq!(retry_wait_label(&wait, at), "retrying (attempt 4/10)… boom");
+ assert_eq!(
+ retry_wait_label(&wait, at - Duration::from_millis(1_500)),
+ "retrying in 2s (attempt 4/10)… boom"
+ );
+ }
+
+ /// A child's retry is noted under its name but leaves the parent's status
+ /// alone, and a child's events do not clear a parent retry.
+ #[test]
+ fn a_subagent_retry_is_noted_without_the_parent_countdown() {
+ let mut app = test_app();
+ start_subagent(&mut app, "r1", "scout");
+ subagent_event(&mut app, "r1", "scout", retry(2));
+ assert!(app.retrying.is_none());
+ assert!(transcript_text(&app).contains("scout: Upstream request failed"));
+
+ app.apply(retry(2));
+ subagent_event(&mut app, "r1", "scout", StreamEvent::Token { text: "x".into() });
+ assert!(app.retrying.is_some(), "a child's token is not the parent's resend");
+ }
+
/// A failed compaction takes its throbber down and says so.
#[test]
fn a_failed_mid_run_compaction_clears_the_throbber() {