Skip to content

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

Rust

fix(ci): make UI benchmark navigation state-aware (#2318)

Seth Karten5d25a44bd22e
diff --git a/scripts/benchmarks/terminal.py b/scripts/benchmarks/terminal.py
index 8b13489bba..9529add64d 100644
--- a/scripts/benchmarks/terminal.py
+++ b/scripts/benchmarks/terminal.py
@@ -133,6 +133,19 @@ class Terminal:
raise TimeoutError("Timed out waiting for terminal display")
self.pump()
+ def until_output(self, predicate: Callable[[str], bool], seconds: float) -> None:
+ index = len(self.raw)
+ output = ""
+ deadline = time.perf_counter() + seconds
+ while True:
+ output += "".join(self.raw[index:])
+ index = len(self.raw)
+ if predicate(output):
+ return
+ if time.perf_counter() >= deadline:
+ raise TimeoutError("Timed out waiting for new terminal output")
+ self.pump()
+
def ready(self, seconds: float = 30) -> float:
deadline = time.perf_counter() + seconds
probes: list[str] = []
diff --git a/scripts/benchmarks/tests/test_terminal_readiness.py b/scripts/benchmarks/tests/test_terminal_readiness.py
index 0509782c32..eb27f9a7b3 100644
--- a/scripts/benchmarks/tests/test_terminal_readiness.py
+++ b/scripts/benchmarks/tests/test_terminal_readiness.py
@@ -139,6 +139,13 @@ class ReadinessTests(unittest.TestCase):
terminal.until(lambda display: "missing" in display.text(), 0.1)
self.assertLess(clock.now - 4.0, 0.11)
+ def test_until_output_ignores_matching_text_already_on_screen(self):
+ terminal, editor, clock = self.launch()
+ terminal.display.feed("agents view")
+ editor.schedule(clock.now + 0.03, "fresh agents view")
+ terminal.until_output(lambda output: "fresh agents view" in output, 0.1)
+ self.assertIn("fresh agents view", terminal.display.text())
+
def test_changed_absent_and_stale_labels_do_not_gate_input(self):
for label in ("agents/resume", "manage", "sessions / continue", "", "benchready"):
with self.subTest(label=label):
diff --git a/scripts/benchmarks/tests/test_ui.py b/scripts/benchmarks/tests/test_ui.py
index 7da5206100..3b93e45559 100644
--- a/scripts/benchmarks/tests/test_ui.py
+++ b/scripts/benchmarks/tests/test_ui.py
@@ -17,6 +17,8 @@ from ui import (
expand_subagents,
expected_roster_inactive,
fixture_spec,
+ move_down,
+ open_agents_view,
session_id,
session_name,
spawn_ledger_path,
@@ -168,6 +170,19 @@ class ProbeLogicTests(unittest.TestCase):
self.assertEqual(total_cpu(processes), 4.0)
self.assertEqual(total_cpu([]), 0.0)
+ def test_open_agents_view_waits_for_fresh_output_before_clearing_search(self):
+ terminal = FakeTerminal(
+ [
+ "Ctrl+N new\n> old-query",
+ "session still rendering",
+ "Ctrl+N new\n> old-query",
+ "Search sessions",
+ ]
+ )
+ open_agents_view(terminal, clear=True)
+ self.assertEqual(terminal.sent, [ui.LEFT_ARROW, ui.BACKSPACE * 24])
+ self.assertEqual(terminal.display.text(), "Search sessions")
+
def test_wait_for_roster_requires_a_settled_count(self):
frames = [
"agents 0 running, 1 idle, 5 inactive",
@@ -207,6 +222,11 @@ class ProbeLogicTests(unittest.TestCase):
with self.assertRaisesRegex(RuntimeError, "first installation"):
ui_measure(ui_request(), side, 0, results=Path("/unused"), homes=Path("/unused"), user="bench")
+ def test_move_down_sends_separate_keypresses(self):
+ terminal = FakeTerminal(["initial"])
+ move_down(terminal, 3)
+ self.assertEqual(terminal.sent, [ui.DOWN_ARROW] * 3)
+
def test_expand_subagents_requires_a_newly_expanded_row(self):
# An ancestor already shows "▾", so only a growing count proves the selected row expanded;
# the first expand keystroke is eaten and the retry lands.
@@ -270,6 +290,14 @@ class FakeTerminal:
if not self.pump():
raise TimeoutError("Timed out waiting for the expected terminal state")
+ def until_output(self, predicate, timeout: float) -> None: # type: ignore[no-untyped-def]
+ output = ""
+ while not predicate(output):
+ if not self.frames:
+ raise TimeoutError("Timed out waiting for fresh terminal output")
+ self.pump()
+ output += self.display.text()
+
def settle(self, seconds: float) -> None:
self.pump()
diff --git a/scripts/benchmarks/ui.py b/scripts/benchmarks/ui.py
index 15b88951f6..9526e50ee1 100644
--- a/scripts/benchmarks/ui.py
+++ b/scripts/benchmarks/ui.py
@@ -32,7 +32,7 @@ BASE_TIMESTAMP_MS = 946684800000 # 2000-01-01T00:00:00Z; fixed so fixtures are
TOOL_OUTPUT_LINES = 60
SEARCH_PLACEHOLDER = "Search sessions"
-AGENTS_VIEW_HINT = SEARCH_PLACEHOLDER
+AGENTS_VIEW_FOOTER = "Ctrl+N new"
ROSTER_COUNT = re.compile(r"agents\s+(\d+) running, (\d+) idle, (\d+) inactive")
READY_MARKER = "benchready"
LEFT_ARROW = "\x1b[D"
@@ -386,6 +386,14 @@ def clear_search(terminal: Terminal, *, attempts: int = 5) -> None:
raise TimeoutError("Agents-view search box did not clear")
+def open_agents_view(terminal: Terminal, *, clear: bool, timeout: float = 60) -> None:
+ """Open a freshly rendered agents view, then optionally clear its preserved search."""
+ terminal.child.send(LEFT_ARROW)
+ terminal.until_output(lambda output: AGENTS_VIEW_FOOTER in output, timeout)
+ if clear:
+ clear_search(terminal)
+
+
def type_query(terminal: Terminal, query: str, *, attempts: int = 3) -> None:
"""Type a search query and verify it echoed before filtering on it."""
for _ in range(attempts):
@@ -399,6 +407,13 @@ def type_query(terminal: Terminal, query: str, *, attempts: int = 3) -> None:
raise TimeoutError("Agents-view search query did not echo")
+def move_down(terminal: Terminal, steps: int) -> None:
+ """Move through a deterministic fixture tree without coalescing keypresses."""
+ for _ in range(steps):
+ terminal.child.send(DOWN_ARROW)
+ terminal.settle(0.08)
+
+
def expand_subagents(terminal: Terminal, *, attempts: int = 4) -> None:
"""Expand the selected row's subagent list; the toggle retries to survive eaten keystrokes."""
expanded = terminal.display.text().count("▾")
@@ -525,8 +540,7 @@ def ui_measure(request: Request, side: Side, trial: int, *, results: Path, homes
started = time.perf_counter()
cpu_start = cpu_total()
bytes_start = terminal.bytes
- terminal.child.send(LEFT_ARROW)
- terminal.until(lambda display: AGENTS_VIEW_HINT in display.text(), 60)
+ open_agents_view(terminal, clear=False)
elapsed = time.perf_counter() - started
cpu = cpu_total() - cpu_start
record(side, "agents_view", trial, elapsed) # type: ignore[arg-type]
@@ -564,8 +578,7 @@ def ui_measure(request: Request, side: Side, trial: int, *, results: Path, homes
started = time.perf_counter()
cpu_start = cpu_total()
bytes_start = terminal.bytes
- terminal.child.send(LEFT_ARROW)
- terminal.until(lambda display: AGENTS_VIEW_HINT in display.text(), 60)
+ open_agents_view(terminal, clear=True)
terminal.settle(1.0)
type_query(terminal, spec.root[:8])
terminal.until(lambda display: session_name("root", 0) in display.text(), 60)
@@ -578,33 +591,28 @@ def ui_measure(request: Request, side: Side, trial: int, *, results: Path, homes
record(side, "parent_open_cpu", trial, cpu) # type: ignore[arg-type]
note("parent_open", seconds=elapsed, cpu=cpu, pty_bytes=terminal.bytes - bytes_start)
- # Deepest subagent session: search, drill in, open at depth SUBAGENT_DEPTH
- # while its parent session is live, matching real subagent workflows.
+ # Deepest subagent session: expand the deterministic fixture tree and
+ # drill to depth SUBAGENT_DEPTH while its parent session is live.
metric = "subagent_open"
started = time.perf_counter()
cpu_start = cpu_total()
bytes_start = terminal.bytes
- terminal.child.send(LEFT_ARROW)
- terminal.until(lambda display: AGENTS_VIEW_HINT in display.text(), 60)
+ open_agents_view(terminal, clear=True)
terminal.settle(1.0)
- query = spec.subagents[-1][:8]
- type_query(terminal, query)
+ type_query(terminal, spec.root[:8])
terminal.until(lambda display: session_name("root", 0) in display.text(), 60)
clear_search(terminal)
expand_subagents(terminal)
- # The search box must be empty to expand; refilter to the chain so the
- # first fan-out sibling cannot steal the down-arrow, then drill a level
- # at a time until the deepest subagent row is selected.
- type_query(terminal, query)
- terminal.settle(0.5)
- terminal.child.send(DOWN_ARROW)
- terminal.settle(0.8)
- for _ in range(SUBAGENT_DEPTH - 1):
+ for depth in range(1, SUBAGENT_DEPTH + 1):
+ # Filtering keeps the selected parent visible and removes its
+ # unrelated siblings. Move across its summary row to the child,
+ # then clear search before the next expansion key.
+ type_query(terminal, spec.subagents[depth - 1][:8])
+ terminal.settle(0.5)
+ move_down(terminal, 2)
clear_search(terminal)
- expand_subagents(terminal)
- terminal.settle(0.8)
- terminal.child.send(DOWN_ARROW)
- terminal.settle(0.8)
+ if depth < SUBAGENT_DEPTH:
+ expand_subagents(terminal)
terminal.child.send(RIGHT_ARROW)
input_ready(terminal, tail_marker("sub", SUBAGENT_DEPTH))
elapsed = time.perf_counter() - started