Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

agents view: shells and factory-run child lines; subagents line reads 'N subagents · M running' (#3639)

Sebastian Müller0e8236274707
diff --git a/crates/pa-cli/tests/session_stop_dock_e2e.rs b/crates/pa-cli/tests/session_stop_dock_e2e.rs
index 442ea2273c..b8cd682a06 100644
--- a/crates/pa-cli/tests/session_stop_dock_e2e.rs
+++ b/crates/pa-cli/tests/session_stop_dock_e2e.rs
@@ -50,6 +50,7 @@ fn kernel_python() -> PathBuf {
python
}
+// The spawned daemon is killed and reaped by `Supervisor::drop`, which clippy cannot see.
#[allow(clippy::zombie_processes)]
fn spawn_supervisor(dir: &Path) -> Supervisor {
let socket = dir.join("daemon.sock");
diff --git a/crates/pa-tui/src/agents_view/render.rs b/crates/pa-tui/src/agents_view/render.rs
index 022dfec315..aadc041983 100644
--- a/crates/pa-tui/src/agents_view/render.rs
+++ b/crates/pa-tui/src/agents_view/render.rs
@@ -540,7 +540,10 @@ impl AgentsViewMode {
// BOTH summary lines bill the descendant tree in the Cost column (operator directive
// 2026-09-26: an all-done tree renders no running line, so the inactive line carries
// the same aggregate; deliberate divergence from TS, which renders no cost there).
- if crate::agents_view_forest::is_summary_row_identity(&row.identity) {
+ if row
+ .identity
+ .starts_with(crate::agents_view_forest::SUMMARY_ROW_PREFIX)
+ {
let zone = layout.name_width + 2 + layout.model_width;
let title = crate::agents_view_state::truncate_text(&text, zone);
let pad = zone.saturating_sub(str_width(&title));
diff --git a/crates/pa-tui/src/agents_view_forest.rs b/crates/pa-tui/src/agents_view_forest.rs
index 7cb1b8ae1b..f8b855e566 100644
--- a/crates/pa-tui/src/agents_view_forest.rs
+++ b/crates/pa-tui/src/agents_view_forest.rs
@@ -76,11 +76,24 @@ pub enum RowKind {
/// The summary line's identity prefix (the `subagents:` prefix, so a carried selection
/// restores onto it).
pub(crate) const SUMMARY_ROW_PREFIX: &str = "subagents:";
+/// The shells activity line's identity prefix.
+pub(crate) const SHELLS_ROW_PREFIX: &str = "shells:";
+/// The factory-runs activity line's identity prefix.
+pub(crate) const FACTORY_ROW_PREFIX: &str = "factory:";
-/// Whether a row identity is one of a parent's summary lines: such identities pin selection
-/// fallbacks to summary rows, which reuse their parent's session key.
-pub(crate) fn is_summary_row_identity(identity: &str) -> bool {
- identity.starts_with(SUMMARY_ROW_PREFIX)
+/// The row kind a synthetic nested-row identity pins selection fallbacks to: these rows all
+/// reuse their parent's session key, so a session-id fallback must stay on the same kind of
+/// line instead of resolving to the parent agent row.
+pub(crate) fn pinned_row_kind(identity: &str) -> Option<RowKind> {
+ if identity.starts_with(SUMMARY_ROW_PREFIX) {
+ Some(RowKind::SubagentSummary)
+ } else if identity.starts_with(SHELLS_ROW_PREFIX) {
+ Some(RowKind::Shells)
+ } else if identity.starts_with(FACTORY_ROW_PREFIX) {
+ Some(RowKind::FactoryRuns)
+ } else {
+ None
+ }
}
impl AgentsViewRow {
diff --git a/crates/pa-tui/src/agents_view_forest/rows.rs b/crates/pa-tui/src/agents_view_forest/rows.rs
index 194d37d8cc..7ce8c5bc8f 100644
--- a/crates/pa-tui/src/agents_view_forest/rows.rs
+++ b/crates/pa-tui/src/agents_view_forest/rows.rs
@@ -385,7 +385,7 @@ fn activity_rows(parent: &BaseRow, depth: usize) -> Vec<AgentsViewRow> {
let line = |kind: RowKind, prefix: &str, title: String| AgentsViewRow {
kind,
section: parent.section,
- identity: format!("{prefix}:{}", parent.identity),
+ identity: format!("{prefix}{}", parent.identity),
parent_identity: Some(parent.identity.clone()),
summary: parent.summary.clone(),
title,
@@ -406,14 +406,14 @@ fn activity_rows(parent: &BaseRow, depth: usize) -> Vec<AgentsViewRow> {
if shells > 0 {
rows.push(line(
RowKind::Shells,
- "shells",
+ super::SHELLS_ROW_PREFIX,
format!("$ {shells} shell{}", if shells == 1 { "" } else { "s" }),
));
}
if factory_runs > 0 {
rows.push(line(
RowKind::FactoryRuns,
- "factory",
+ super::FACTORY_ROW_PREFIX,
format!(
"\u{2699} {factory_runs} factory run{}",
if factory_runs == 1 { "" } else { "s" }
diff --git a/crates/pa-tui/src/agents_view_forest/selection.rs b/crates/pa-tui/src/agents_view_forest/selection.rs
index 8a84cd60c6..d04a630c57 100644
--- a/crates/pa-tui/src/agents_view_forest/selection.rs
+++ b/crates/pa-tui/src/agents_view_forest/selection.rs
@@ -1,6 +1,6 @@
use serde_json::Value;
-use super::{is_summary_row_identity, AgentsViewRow, RowKind, SelectionKey};
+use super::{pinned_row_kind, AgentsViewRow, RowKind, SelectionKey};
/// Session ids of every ancestor of a nested row, root-most first: the chain the view
/// re-expands when the drilled-in child returns to it.
@@ -53,9 +53,8 @@ pub fn resolve_selection(
if rows.is_empty() {
return 0;
}
- let selected_summary_row = identity.is_some_and(is_summary_row_identity);
- let preserves_kind =
- |row: &AgentsViewRow| !selected_summary_row || row.kind == RowKind::SubagentSummary;
+ let pinned_kind = identity.and_then(pinned_row_kind);
+ let preserves_kind = |row: &AgentsViewRow| pinned_kind.is_none_or(|kind| row.kind == kind);
if let Some(identity) = identity {
if let Some(index) = find_selectable(rows, |row| row.identity == identity) {
// Synthetic nested rows deliberately reuse their parent's session key, so their
@@ -66,17 +65,25 @@ pub fn resolve_selection(
}
}
if let Some(active) = key.and_then(|key| key.active_session_id.as_deref()) {
- if let Some(index) = find_selectable(rows, |row| {
- preserves_kind(row)
- && row
- .summary
- .get("activeSessionId")
- .or_else(|| row.summary.get("id"))
- .and_then(Value::as_str)
- == Some(active)
- }) {
+ let matches_active = |row: &AgentsViewRow| {
+ row.summary
+ .get("activeSessionId")
+ .or_else(|| row.summary.get("id"))
+ .and_then(Value::as_str)
+ == Some(active)
+ };
+ if let Some(index) = find_selectable(rows, |row| preserves_kind(row) && matches_active(row))
+ {
return index;
}
+ // The pinned line vanished (its count dropped to zero): stay with this session by
+ // landing on its parent row rather than keeping an index that may now be another
+ // session's row.
+ if pinned_kind.is_some() {
+ if let Some(index) = find_selectable(rows, matches_active) {
+ return index;
+ }
+ }
}
if let Some(identity) = identity {
if let Some(index) = find_selectable(rows, |row| row.identity == identity) {
@@ -84,12 +91,19 @@ pub fn resolve_selection(
}
}
if let Some(session) = key.and_then(|key| key.session_id.as_deref()) {
- if let Some(index) = find_selectable(rows, |row| {
- preserves_kind(row)
- && row.summary.get("sessionId").and_then(Value::as_str) == Some(session)
- }) {
+ let matches_session = |row: &AgentsViewRow| {
+ row.summary.get("sessionId").and_then(Value::as_str) == Some(session)
+ };
+ if let Some(index) =
+ find_selectable(rows, |row| preserves_kind(row) && matches_session(row))
+ {
return index;
}
+ if pinned_kind.is_some() {
+ if let Some(index) = find_selectable(rows, matches_session) {
+ return index;
+ }
+ }
}
let bounded = current.min(rows.len() - 1);
if rows[bounded].selectable() {
diff --git a/crates/pa-tui/src/agents_view_forest/tests.rs b/crates/pa-tui/src/agents_view_forest/tests.rs
index 7c326ce1d7..b1833fb979 100644
--- a/crates/pa-tui/src/agents_view_forest/tests.rs
+++ b/crates/pa-tui/src/agents_view_forest/tests.rs
@@ -407,6 +407,47 @@ fn the_expanded_group_renders_each_agent_once() {
);
}
+/// A shells/factory activity identity pins the selection's fallbacks to the same-kind line:
+/// when the carried identity goes stale (the parent's identity flips on persist/re-attach),
+/// the session-key fallback must re-find the activity line, not the parent agent row that
+/// shares its summary.
+#[test]
+fn selection_pins_a_stale_activity_identity_to_its_kind() {
+ let roster = vec![roster_entry("p", "idle", &parent_summary("p"))];
+ let counts = activity(&[("p-live", 2, 1)]);
+ let rows = rows_with_activity(&roster, None, &[], &counts);
+ let key = SelectionKey {
+ session_id: Some("p".to_string()),
+ active_session_id: Some("p-live".to_string()),
+ };
+ let index = resolve_selection(&rows, 0, Some("shells:file:/x/OLD.jsonl"), Some(&key));
+ assert_eq!(rows[index].kind, RowKind::Shells);
+ let index = resolve_selection(&rows, 0, Some("factory:file:/x/OLD.jsonl"), Some(&key));
+ assert_eq!(rows[index].kind, RowKind::FactoryRuns);
+}
+
+/// When the pinned activity line vanished (count back to zero), the session key still wins:
+/// the selection lands on that session's own row, never on whatever row holds the old index.
+#[test]
+fn a_vanished_activity_line_falls_back_to_its_sessions_row() {
+ let roster = vec![
+ roster_entry("p", "idle", &parent_summary("p")),
+ roster_entry("q", "idle", &parent_summary("q")),
+ ];
+ let rows = rows_for(&roster, None, &[]);
+ let q_index = rows
+ .iter()
+ .position(|row| row.title == "q name")
+ .expect("the second agent row");
+ let key = SelectionKey {
+ session_id: Some("p".to_string()),
+ active_session_id: Some("p-live".to_string()),
+ };
+ let index = resolve_selection(&rows, q_index, Some("shells:file:/x/p.jsonl"), Some(&key));
+ assert_eq!(rows[index].kind, RowKind::Agent);
+ assert_eq!(rows[index].title, "p name");
+}
+
/// Summary-line identities pin the selection's fallbacks to the ONE summary row. A carried
/// legacy `subagents-inactive:` identity (the 2026-09-25 two-line scheme) resolves by its session
/// key onto the PARENT row.