From 2051f17000156362205e5c7d4f3c273f7d1e0d22 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Fri, 6 Nov 2026 22:51:51 -0800 Subject: [PATCH 01/16] fix(tier3): keep the Rich progress frame at a fixed height The interactive Tier 3 progress table changed height as the plan resolved and stages arrived: the Provider and Run plan rows appeared later, every stage added a row, and long details wrapped. Rich also redrew it from its own refresh thread at 8 Hz. Redraws of a frame whose height changes can leave repeated or jumbled frames in the terminal. - Always render the Provider and Run plan rows, with a placeholder until the plan resolves. - Keep each row on one line: the title and every column end in an ellipsis instead of wrapping. - Show the most recently updated stages in a fixed number of rows, at least six and at least one per agent, padded with blank rows. The slot count never shrinks. - Create Live with auto_refresh=False, so redraws come only from progress events and heartbeats, which hold the reporter lock. - Reset the plan, rows and slot count on close even when Live never started. A redraw failure on the heartbeat thread used to end the thread with a traceback and leave the reporter active. The heartbeat loop now catches it and calls a failure callback; SafeProgressReporter registers its disable hook there, which closes the reporter and stops the live view while the run continues. Without a callback the loop stops. A disabled SafeProgressReporter no longer reports itself active, and start() is a no-op once it is disabled. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- src/skillevaluator/tier3/harbor/progress.py | 107 ++++++-- tests/test_tier3_progress.py | 265 ++++++++++++++++++++ 2 files changed, 349 insertions(+), 23 deletions(-) diff --git a/src/skillevaluator/tier3/harbor/progress.py b/src/skillevaluator/tier3/harbor/progress.py index 533b67a03..531ba23da 100644 --- a/src/skillevaluator/tier3/harbor/progress.py +++ b/src/skillevaluator/tier3/harbor/progress.py @@ -15,7 +15,7 @@ import re import sys import threading -from collections.abc import Mapping +from collections.abc import Callable, Mapping from dataclasses import dataclass from time import monotonic from typing import Literal, Protocol, TextIO, runtime_checkable @@ -51,6 +51,10 @@ # One day stays below every platform's threading.TIMEOUT_MAX, beyond which the # heartbeat thread's wait would raise OverflowError. MAX_REFRESH_INTERVAL_SECONDS = 86400.0 +# The Rich frame keeps at least this many stage rows (more when more agents +# run), padding with blank rows, so its height never changes mid-run. A frame +# that grows or shrinks between redraws leaves stale or jumbled lines behind. +_LIVE_MIN_EVENT_ROWS = 6 @dataclass(frozen=True, slots=True) @@ -180,6 +184,7 @@ def __init__( self._plan_rendered = False self._last_progress_at: float | None = None self._last_events: dict[str, tuple[str, str]] = {} + self._failure_callback: Callable[[], None] | None = None @property def is_active(self) -> bool: @@ -208,6 +213,10 @@ def set_secret_values(self, values: list[str] | tuple[str, ...] | set[str]) -> N with self._lock: self._secret_values.update(value for value in values if value) + def set_failure_callback(self, callback: Callable[[], None] | None) -> None: + """Notify a safety wrapper when the reporter's own heartbeat thread fails.""" + self._failure_callback = callback + def emit(self, event: ProgressEvent) -> None: with self._lock: detail = self._event_detail(event) @@ -315,7 +324,22 @@ def _heartbeat_loop(self) -> None: delay = max(MIN_REFRESH_INTERVAL_SECONDS, delay - (monotonic() - self._last_progress_at)) if self._stop.wait(delay): return - self.heartbeat() + try: + self.heartbeat() + except Exception: + # A redraw failure here must turn progress off through the + # safety wrapper, which stops the live display, instead of + # killing this thread and leaving a half-drawn frame behind. + logger.debug("Tier 3 progress heartbeat failed", exc_info=True) + callback = self._failure_callback + if callback is None: + self._stop.set() + return + try: + callback() + except Exception: + logger.debug("Tier 3 progress failure callback failed", exc_info=True) + return def _safe_text(self, value: object) -> str: return redact_progress_detail(value, secret_values=self._secret_values) @@ -352,6 +376,7 @@ def __init__( self._live = None self._live_plan: Tier3RunPlan | None = None self._live_events: dict[str, tuple[ProgressEvent, str | None]] = {} + self._live_event_slots = _LIVE_MIN_EVENT_ROWS def emit(self, event: ProgressEvent) -> None: with self._lock: @@ -367,6 +392,8 @@ def emit(self, event: ProgressEvent) -> None: else: self._active.pop(event.stage, None) finished_at = self._elapsed() + # Move the stage to the end so the recent-event window shows it. + self._live_events.pop(event.stage, None) self._live_events[event.stage] = (safe_event, finished_at) self._refresh_live() @@ -382,13 +409,17 @@ def close(self) -> None: super().close() finally: with self._lock: - if live is not None and live is self._live: - try: + try: + if live is not None and live is self._live: live.stop() - finally: + finally: + # Reset even when Live never started, so a failed start + # leaves no plan or rows behind for the next run. + if live is self._live: self._live = None - self._live_plan = None - self._live_events.clear() + self._live_plan = None + self._live_events.clear() + self._live_event_slots = _LIVE_MIN_EVENT_ROWS def _render_plan(self, plan: Tier3RunPlan) -> None: self._live_plan = plan @@ -397,8 +428,9 @@ def _render_plan(self, plan: Tier3RunPlan) -> None: self._live = self._live_factory( table, console=self._console, - auto_refresh=True, - refresh_per_second=8, + # Redraw only from progress events and the heartbeat, which + # hold the reporter lock, never from Rich's own refresh thread. + auto_refresh=False, transient=False, ) self._live.start(refresh=True) @@ -424,12 +456,16 @@ def _build_live_table(self): (self._safe_text(plan.skill_name), "bold"), " · ", (mode_label, MUTED), + overflow="ellipsis", + no_wrap=True, ) table = Table(title=title, box=box.ROUNDED, border_style=FAINT, expand=True, show_lines=False) - table.add_column("Stage", style="bold", no_wrap=True) - table.add_column("State", width=12, no_wrap=True) - table.add_column("Detail", ratio=1) - table.add_column("Elapsed", justify="right", no_wrap=True) + # One line per row: long values are cut with an ellipsis rather than + # wrapped, so the frame height does not depend on the text. + table.add_column("Stage", style="bold", no_wrap=True, overflow="ellipsis") + table.add_column("State", width=12, no_wrap=True, overflow="ellipsis") + table.add_column("Detail", ratio=1, no_wrap=True, overflow="ellipsis") + table.add_column("Elapsed", justify="right", no_wrap=True, overflow="ellipsis") table.add_row("Environment", Text("configured", style=TEXT), Text(self._safe_text(plan.environment)), "") model_map = dict(plan.agent_models) @@ -440,13 +476,14 @@ def _build_live_table(self): for agent in plan.agents ) table.add_row("Agents / models", Text("configured", style=TEXT), Text(agents or "none"), "") - if plan.provider: - table.add_row( - "Provider", - Text("configured", style=TEXT), - Text(self._safe_text(plan.provider)), - "", - ) + # The Provider and Run plan rows are always present, with a placeholder + # until the plan resolves, so a plan update does not add rows. + table.add_row( + "Provider", + Text("configured" if plan.provider else "pending", style=TEXT if plan.provider else MUTED), + Text(self._safe_text(plan.provider or "resolving")), + "", + ) values = ( ("Tasks", plan.task_count), ("Cases", plan.case_count), @@ -465,8 +502,12 @@ def _build_live_table(self): ), ) known = " · ".join(f"{label} {value}" for label, value in values if value is not None) - if known: - table.add_row("Run plan", Text("configured", style=TEXT), Text(known), "") + table.add_row( + "Run plan", + Text("configured" if known else "pending", style=TEXT if known else MUTED), + Text(known or "preparing"), + "", + ) state_styles = { "ready": GREEN, "complete": GREEN, @@ -475,7 +516,13 @@ def _build_live_table(self): "delegated": AMBER, "skipped": "dim", } - for stage, (event, finished_at) in self._live_events.items(): + # Show only the most recently updated stages in a fixed number of rows. + # The slot count only grows (to fit every agent), so the frame never + # shrinks either. + self._live_event_slots = max(self._live_event_slots, len(plan.agents)) + event_slots = self._live_event_slots + recent_events = list(self._live_events.items())[-event_slots:] + for stage, (event, finished_at) in recent_events: label = ( f"Agent {stage.removeprefix('agent:')}" if stage.startswith("agent:") @@ -492,6 +539,8 @@ def _build_live_table(self): Text(event.detail or ""), Text(finished_at or self._elapsed()), ) + for _ in range(event_slots - len(recent_events)): + table.add_row("", "", "", "") return table def _refresh_live(self) -> None: @@ -532,6 +581,11 @@ def __init__(self, reporter: ProgressReporter) -> None: self._reporter = reporter self._disabled = False self._started = False + # A reporter's own heartbeat thread reports failures here, so a redraw + # error there turns progress off just like one on the caller's thread. + set_failure_callback = getattr(reporter, "set_failure_callback", None) + if callable(set_failure_callback): + set_failure_callback(self._disable) @property def is_active(self) -> bool: @@ -544,8 +598,12 @@ def is_active(self) -> bool: return self._started def start(self, plan: Tier3RunPlan) -> None: + if self._disabled: + return self._started = True self._call(self._reporter.start, plan) + if self._disabled: + self._started = False def set_secret_values(self, values: list[str] | tuple[str, ...] | set[str]) -> None: self._call(self._reporter.set_secret_values, values) @@ -582,6 +640,9 @@ def _disable(self) -> None: self._reporter.close() except Exception: logger.debug("Tier 3 progress reporter cleanup failed", exc_info=True) + finally: + # A disabled reporter shows nothing, so it is no longer active. + self._started = False def safe_progress_reporter(reporter: ProgressReporter | None) -> SafeProgressReporter: diff --git a/tests/test_tier3_progress.py b/tests/test_tier3_progress.py index 435bb7949..8aa6492e0 100644 --- a/tests/test_tier3_progress.py +++ b/tests/test_tier3_progress.py @@ -272,6 +272,162 @@ def test_rich_reporter_owns_live_table_and_updates_stage_rows(monkeypatch: pytes assert reporter.is_active is False +def _rendered_live_lines(reporter: Any, *, width: int = 80) -> list[str]: + from rich.console import Console + + stream = io.StringIO() + Console(file=stream, width=width, color_system=None).print(reporter._build_live_table()) + return stream.getvalue().splitlines() + + +def test_rich_progress_frame_height_stays_fixed_as_plan_and_events_grow() -> None: + progress = _progress_module() + reporter = progress.RichProgressReporter(stream=io.StringIO(), refresh_interval=60) + reporter._live_plan = progress.Tier3RunPlan( + skill_name="demo", + environment="docker", + agents=("codex",), + agent_models=(("codex", "example/model"),), + ) + + initial_lines = _rendered_live_lines(reporter) + reporter._live_plan = progress.Tier3RunPlan( + skill_name="demo", + environment="docker", + agents=("codex",), + agent_models=(("codex", "example/model"),), + provider="example-provider", + task_count=2, + case_count=1, + attempts=1, + baseline=True, + concurrency=4, + timeout_multiplier=2, + matrix_trials=2, + total_containers=2, + ) + for index in range(10): + reporter.emit( + progress.ProgressEvent( + stage=f"stage-{index}", + state="complete", + detail=f"completed stage {index} " + "with a detail too long for one line " * 3, + ) + ) + populated_lines = _rendered_live_lines(reporter) + + assert len(populated_lines) == len(initial_lines) + assert "example-provider" in "\n".join(populated_lines) + assert "…" in "\n".join(populated_lines) + + +def test_rich_progress_title_does_not_change_frame_height_in_a_narrow_terminal() -> None: + progress = _progress_module() + reporter = progress.RichProgressReporter(stream=io.StringIO(), refresh_interval=60) + reporter._live_plan = progress.Tier3RunPlan( + skill_name="a-skill-with-a-very-long-name", + environment="docker", + agents=tuple(f"agent-{index}" for index in range(8)), + ) + + initial_height = len(_rendered_live_lines(reporter, width=20)) + reporter._live_plan = progress.Tier3RunPlan( + skill_name="a-skill-with-a-very-long-name", + environment="docker", + agents=("agent-0",), + provider="example-provider", + task_count=2, + case_count=1, + attempts=1, + baseline=True, + concurrency=4, + timeout_multiplier=2, + total_containers=2, + ) + for index in range(10): + reporter.emit( + progress.ProgressEvent( + stage=f"stage-{index}", + state="complete", + detail=f"completed stage {index}", + ) + ) + + assert len(_rendered_live_lines(reporter, width=20)) == initial_height + + +def test_rich_progress_frame_does_not_shrink_when_the_agent_set_shrinks() -> None: + progress = _progress_module() + reporter = progress.RichProgressReporter(stream=io.StringIO(), refresh_interval=60) + + reporter._live_plan = progress.Tier3RunPlan( + skill_name="demo", + environment="docker", + agents=tuple(f"agent-{index}" for index in range(8)), + ) + initial_height = len(_rendered_live_lines(reporter)) + reporter._live_plan = progress.Tier3RunPlan(skill_name="demo", environment="docker", agents=("agent-0",)) + + assert len(_rendered_live_lines(reporter)) == initial_height + + +def test_rich_progress_uses_manual_refresh_and_recent_event_window(monkeypatch: pytest.MonkeyPatch) -> None: + import rich.live + from rich.console import Console + + progress = _progress_module() + _FakeLive.instances.clear() + monkeypatch.setattr(rich.live, "Live", _FakeLive) + reporter = progress.RichProgressReporter(stream=_TTYBuffer(), refresh_interval=60) + reporter.start(_plan(progress)) + + for index in range(7): + reporter.emit( + progress.ProgressEvent( + stage=f"stage-{index}", + state="complete", + detail=f"completed stage {index}", + ) + ) + reporter.emit(progress.ProgressEvent(stage="stage-0", state="running", detail="active again")) + + live = _FakeLive.instances[0] + rendered = io.StringIO() + Console(file=rendered, width=80, color_system=None).print(live.renderables[-1]) + text = rendered.getvalue() + # Rich's own refresh thread would redraw outside the reporter lock. + assert live.kwargs["auto_refresh"] is False + assert "refresh_per_second" not in live.kwargs + # The six most recently updated stages stay visible; the oldest drops out. + assert "active again" in text + assert all(f"completed stage {index}" in text for index in range(2, 7)) + assert "completed stage 1" not in text + reporter.close() + + +def test_rich_progress_resets_state_when_live_initialization_fails() -> None: + progress = _progress_module() + reporter = progress.RichProgressReporter(stream=io.StringIO(), refresh_interval=60) + + def _fail_live_initialization(*_args, **_kwargs): + raise RuntimeError("terminal initialization failed") + + reporter._live_factory = _fail_live_initialization + plan = progress.Tier3RunPlan( + skill_name="demo", + environment="docker", + agents=tuple(f"agent-{index}" for index in range(8)), + ) + with pytest.raises(RuntimeError, match="terminal initialization failed"): + reporter.start(plan) + reporter.close() + + assert reporter._live is None + assert reporter._live_plan is None + assert reporter._live_events == {} + assert reporter._live_event_slots == progress._LIVE_MIN_EVENT_ROWS + + def test_rich_reporter_immediately_starts_one_live_box_and_keeps_stage_updates_inside_it( monkeypatch: pytest.MonkeyPatch, ) -> None: @@ -555,16 +711,125 @@ def close(self) -> None: reporter.set_secret_values(["secret"]) reporter.start(_plan(progress)) + # A disabled reporter shows nothing, so starting it must not mark it active. + assert reporter.is_active is False reporter.emit(progress.ProgressEvent(stage="configuration", state="running")) reporter.heartbeat() reporter.close() assert broken.close_calls >= 1 reporter.start(_plan(progress)) + assert reporter.is_active is False reporter.close() assert broken.start_calls == 1 +def test_safe_reporter_becomes_inactive_after_post_start_failure() -> None: + progress = _progress_module() + + class FailingReporter: + active = False + + @property + def is_active(self) -> bool: + return self.active + + def start(self, _plan) -> None: + self.active = True + + def set_secret_values(self, _values) -> None: + pass + + def emit(self, _event) -> None: + raise RuntimeError("redraw failed") + + def heartbeat(self) -> None: + pass + + def close(self) -> None: + self.active = False + + reporter = progress.safe_progress_reporter(FailingReporter()) + reporter.start(_plan(progress)) + assert reporter.is_active is True + + reporter.emit(progress.ProgressEvent(stage="configuration", state="ready")) + + assert reporter.is_active is False + reporter.close() + + +def test_safe_reporter_disables_after_heartbeat_redraw_failure() -> None: + progress = _progress_module() + heartbeat_failed = threading.Event() + failed_on: list[threading.Thread] = [] + + class FailingLive: + def __init__(self, _table, **_kwargs) -> None: + self.update_calls = 0 + self.stop_calls = 0 + + def start(self, *, refresh: bool = False) -> None: + assert refresh + + def update(self, _table, *, refresh: bool = False) -> None: + assert refresh + self.update_calls += 1 + if self.update_calls == 2: + failed_on.append(threading.current_thread()) + heartbeat_failed.set() + raise RuntimeError("heartbeat redraw failed") + + def stop(self) -> None: + self.stop_calls += 1 + + rich_reporter = progress.RichProgressReporter(stream=io.StringIO(), refresh_interval=0.05) + rich_reporter._live_factory = FailingLive + reporter = progress.safe_progress_reporter(rich_reporter) + reporter.start(_plan(progress)) + heartbeat = rich_reporter._thread + live = rich_reporter._live + assert heartbeat is not None and live is not None + reporter.emit(progress.ProgressEvent(stage="agent:codex", state="running", detail="evaluating")) + + assert heartbeat_failed.wait(timeout=10) + # The redraw sets the event before it raises, so the heartbeat thread may still + # be turning the reporter off. That thread ends right after, so wait for it. + heartbeat.join(timeout=10) + assert not heartbeat.is_alive() + assert failed_on == [heartbeat] + assert reporter.is_active is False + assert live.stop_calls == 1 + assert rich_reporter._live is None + updates_before = live.update_calls + reporter.emit(progress.ProgressEvent(stage="agent:codex", state="complete")) + assert live.update_calls == updates_before + reporter.close() + + +def test_heartbeat_failure_without_a_safety_wrapper_stops_the_thread(monkeypatch: pytest.MonkeyPatch) -> None: + progress = _progress_module() + uncaught: list[BaseException | None] = [] + monkeypatch.setattr(threading, "excepthook", lambda args: uncaught.append(args.exc_value)) + + class FailingHeartbeatReporter(progress.PlainProgressReporter): + def heartbeat(self) -> None: + raise RuntimeError("heartbeat failed") + + reporter = FailingHeartbeatReporter(stream=io.StringIO(), refresh_interval=0.05) + reporter.start(_plan(progress)) + reporter.emit(progress.ProgressEvent(stage="agent:codex", state="running")) + heartbeat = reporter._thread + assert heartbeat is not None + + heartbeat.join(timeout=10) + + assert not heartbeat.is_alive() + assert reporter.is_active is False + assert uncaught == [] + reporter.close() + + def test_safe_reporter_tracks_lifecycle_when_delegate_has_no_active_state() -> None: progress = _progress_module() reporter = progress.safe_progress_reporter(progress.NullProgressReporter()) From f7a7c8849a9d0ce1cf4e69f060e944a17aac41b3 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Fri, 6 Nov 2026 22:51:51 -0800 Subject: [PATCH 02/16] docs(tier3): describe the fixed-height Rich progress view Explain in the Tier 3 guide how the rich progress view keeps its height, which stages it shows and what happens when drawing fails, note the fixed-height table in the CLI reference, and add an Unreleased / Fixed CHANGELOG entry. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 12 ++++++++++++ docs/cli-reference.mdx | 2 +- docs/tier3-live-evaluation.mdx | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a30baa36f..5649a2259 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,6 +121,18 @@ All notable changes to SkillEvaluator are documented in this file. `Use HTTP POST to create an item.` in a here-document or an unpiped `echo` still does not warn. +- The interactive Tier 3 progress view (`--progress rich`, or `auto` in a + terminal) now keeps one height for the whole run, so redraws no longer leave + repeated or jumbled table frames. The Provider and Run plan rows show a + placeholder until the plan resolves, each row is one line that ends in an + ellipsis when its value is too long, and stages fill a fixed number of rows, + at least six and one per agent, showing the most recently updated. The view + redraws only on progress events and heartbeats, no longer also from Rich's + own refresh thread. If drawing fails on the heartbeat thread, the view now + stops and progress turns off while the run continues. Before, that thread + ended with a traceback and the view stopped updating elapsed times but stayed + active. + ## 0.8.0 - 2026-11-05 ### Added diff --git a/docs/cli-reference.mdx b/docs/cli-reference.mdx index 1bc4958a4..d3c9cd4e6 100644 --- a/docs/cli-reference.mdx +++ b/docs/cli-reference.mdx @@ -508,7 +508,7 @@ Use `skillevaluator tier3 PATH` for the complete workflow with automatic missing | `--evaluated-source-repository TEXT` | unset | Repository (`owner/name`) of the source tree being evaluated, persisted into the run's `run_config.json`. | | `--evaluated-source-revision TEXT` | unset | Immutable revision of the evaluated source: a full Git object id, or a `sha256`/`sha384`/`sha512` digest. A short prefix is refused. | | `--evaluator-container-revision TEXT` | unset | Digest-pinned evaluator image reference recorded beside the evaluated source. | -| `--progress [auto\|rich\|plain\|off]` | `auto` | Progress display for the run: `rich` live view, `plain` line output, or `off`. | +| `--progress [auto\|rich\|plain\|off]` | `auto` | Progress display for the run: `rich` live view (a fixed-height table of the run plan and recent stages), `plain` line output, or `off`. | | `--progress-interval SECONDS` | mode default | Seconds between progress heartbeats, from `0.05` to `86400`: how often the `rich` view refreshes elapsed times and how often `plain` output repeats a `still running` line for active stages. Defaults to 1 second for `rich` and 60 seconds for `plain`, including `auto` with redirected or CI output. | Without a `--model`/`--agent-model` override, agent execution uses diff --git a/docs/tier3-live-evaluation.mdx b/docs/tier3-live-evaluation.mdx index a0f74fdd5..b4a0e52ca 100644 --- a/docs/tier3-live-evaluation.mdx +++ b/docs/tier3-live-evaluation.mdx @@ -593,6 +593,14 @@ and each uses the full `--n-concurrent` budget. For example, two agents with `--n-concurrent 4` run up to eight trials at once, fewer when fewer cases remain. +In a terminal, `--progress auto` uses the `rich` view: one table of the run +plan and its stages that keeps the same height for the whole run. Each row is +one line, and a long value ends in an ellipsis instead of wrapping. The table +shows the most recently updated stages in a fixed number of rows, at least six +and at least one per agent. It redraws only when a stage changes or a heartbeat +updates elapsed times. If the terminal fails to draw it, the view stops and the +run continues. + Every `tier3 evaluate` flag, including resource overrides and Dockerfile modes, is in the [CLI Reference](cli-reference.mdx). From abcbb960801f5c9694cba40c8eb77edbb4b3184e Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Sun, 8 Nov 2026 09:34:33 +0530 Subject: [PATCH 03/16] fix(tier3): keep running stages running when the progress view stops When a redraw failed, SafeProgressReporter turned progress off through the reporter's close(), which reports every running stage as "failed - interrupted before completion" and redraws. A one-off write error on the heartbeat thread therefore left a frame saying the running agents had failed while the run went on, and progress stayed off. - PlainProgressReporter and RichProgressReporter get close_after_failure(), which stops without marking running stages failed. The Rich reporter keeps the last frame and prints one line saying the display stopped and the run continues. SafeProgressReporter._disable uses it when the reporter has it. - The heartbeat thread skips a redraw that fails with BlockingIOError or InterruptedError (a write that would block on a terminal another process made non-blocking) and draws again on the next heartbeat. - A heartbeat failure while close() is already stopping the reporter no longer calls the failure callback. - Rich progress lines are printed without Rich's number highlighting. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- src/skillevaluator/tier3/harbor/progress.py | 52 ++++++++++++-- tests/test_tier3_progress.py | 76 ++++++++++++++++++--- 2 files changed, 113 insertions(+), 15 deletions(-) diff --git a/src/skillevaluator/tier3/harbor/progress.py b/src/skillevaluator/tier3/harbor/progress.py index 531ba23da..ff0f286d8 100644 --- a/src/skillevaluator/tier3/harbor/progress.py +++ b/src/skillevaluator/tier3/harbor/progress.py @@ -267,6 +267,16 @@ def close(self) -> None: self._last_events.clear() self._last_progress_at = None + def close_after_failure(self) -> None: + """Stop after a presentation failure without marking running stages failed. + + Only the display failed. The run goes on, so a stage that is still + running has not been interrupted. + """ + with self._lock: + self._active.clear() + self.close() + def _render_plan(self, plan: Tier3RunPlan) -> None: first_plan = not self._plan_rendered self._plan_rendered = True @@ -326,11 +336,19 @@ def _heartbeat_loop(self) -> None: return try: self.heartbeat() + except (BlockingIOError, InterruptedError): + # A terminal that another process made non-blocking can refuse + # one write; the next heartbeat draws the frame again. + logger.debug("Tier 3 progress heartbeat skipped after a transient write error", exc_info=True) + continue except Exception: # A redraw failure here must turn progress off through the # safety wrapper, which stops the live display, instead of # killing this thread and leaving a half-drawn frame behind. logger.debug("Tier 3 progress heartbeat failed", exc_info=True) + if self._stop.is_set(): + # close() is already stopping this reporter. + return callback = self._failure_callback if callback is None: self._stop.set() @@ -421,6 +439,22 @@ def close(self) -> None: self._live_events.clear() self._live_event_slots = _LIVE_MIN_EVENT_ROWS + def close_after_failure(self) -> None: + """Stop the live view after a drawing failure and say that the run goes on.""" + with self._lock: + # Only the display failed: the stages still running are not + # interrupted, so close() must not report them as failed. + self._active.clear() + had_live = self._live is not None + self.close() + if had_live: + try: + # The last frame stays on screen with its stages still running, + # so explain why it no longer updates. + self._write_line("Tier 3 progress display stopped after a drawing error; the run continues.") + except Exception: + logger.debug("Tier 3 progress stop notice failed", exc_info=True) + def _render_plan(self, plan: Tier3RunPlan) -> None: self._live_plan = plan table = self._build_live_table() @@ -548,7 +582,7 @@ def _refresh_live(self) -> None: self._live.update(self._build_live_table(), refresh=True) def _write_line(self, line: str) -> None: - self._console.print(line, markup=False, soft_wrap=True) + self._console.print(line, markup=False, highlight=False, soft_wrap=True) class NullProgressReporter: @@ -636,13 +670,21 @@ def _disable(self) -> None: if self._disabled: return self._disabled = True + # A disabled reporter shows nothing, so it is no longer active. + self._started = False + # Only the display failed, so a reporter that can stop without marking + # its running stages failed does so. try: - self._reporter.close() + close_after_failure = getattr(self._reporter, "close_after_failure", None) + except Exception: + close_after_failure = None + try: + if callable(close_after_failure): + close_after_failure() + else: + self._reporter.close() except Exception: logger.debug("Tier 3 progress reporter cleanup failed", exc_info=True) - finally: - # A disabled reporter shows nothing, so it is no longer active. - self._started = False def safe_progress_reporter(reporter: ProgressReporter | None) -> SafeProgressReporter: diff --git a/tests/test_tier3_progress.py b/tests/test_tier3_progress.py index 8aa6492e0..0e308bb6b 100644 --- a/tests/test_tier3_progress.py +++ b/tests/test_tier3_progress.py @@ -272,12 +272,16 @@ def test_rich_reporter_owns_live_table_and_updates_stage_rows(monkeypatch: pytes assert reporter.is_active is False -def _rendered_live_lines(reporter: Any, *, width: int = 80) -> list[str]: +def _render(renderable: Any, *, width: int = 80) -> str: from rich.console import Console stream = io.StringIO() - Console(file=stream, width=width, color_system=None).print(reporter._build_live_table()) - return stream.getvalue().splitlines() + Console(file=stream, width=width, color_system=None).print(renderable) + return stream.getvalue() + + +def _rendered_live_lines(reporter: Any, *, width: int = 80) -> list[str]: + return _render(reporter._build_live_table(), width=width).splitlines() def test_rich_progress_frame_height_stays_fixed_as_plan_and_events_grow() -> None: @@ -373,7 +377,6 @@ def test_rich_progress_frame_does_not_shrink_when_the_agent_set_shrinks() -> Non def test_rich_progress_uses_manual_refresh_and_recent_event_window(monkeypatch: pytest.MonkeyPatch) -> None: import rich.live - from rich.console import Console progress = _progress_module() _FakeLive.instances.clear() @@ -392,9 +395,7 @@ def test_rich_progress_uses_manual_refresh_and_recent_event_window(monkeypatch: reporter.emit(progress.ProgressEvent(stage="stage-0", state="running", detail="active again")) live = _FakeLive.instances[0] - rendered = io.StringIO() - Console(file=rendered, width=80, color_system=None).print(live.renderables[-1]) - text = rendered.getvalue() + text = _render(live.renderables[-1]) # Rich's own refresh thread would redraw outside the reporter lock. assert live.kwargs["auto_refresh"] is False assert "refresh_per_second" not in live.kwargs @@ -765,15 +766,17 @@ def test_safe_reporter_disables_after_heartbeat_redraw_failure() -> None: failed_on: list[threading.Thread] = [] class FailingLive: - def __init__(self, _table, **_kwargs) -> None: + def __init__(self, table, **_kwargs) -> None: + self.renderables = [table] self.update_calls = 0 self.stop_calls = 0 def start(self, *, refresh: bool = False) -> None: assert refresh - def update(self, _table, *, refresh: bool = False) -> None: + def update(self, table, *, refresh: bool = False) -> None: assert refresh + self.renderables.append(table) self.update_calls += 1 if self.update_calls == 2: failed_on.append(threading.current_thread()) @@ -783,7 +786,8 @@ def update(self, _table, *, refresh: bool = False) -> None: def stop(self) -> None: self.stop_calls += 1 - rich_reporter = progress.RichProgressReporter(stream=io.StringIO(), refresh_interval=0.05) + output = io.StringIO() + rich_reporter = progress.RichProgressReporter(stream=output, refresh_interval=0.05) rich_reporter._live_factory = FailingLive reporter = progress.safe_progress_reporter(rich_reporter) reporter.start(_plan(progress)) @@ -801,12 +805,64 @@ def stop(self) -> None: assert reporter.is_active is False assert live.stop_calls == 1 assert rich_reporter._live is None + # Only the display failed: the agent is never drawn as failed or interrupted, + # and a line under the frozen frame says the run goes on. + frames = [_render(table, width=180) for table in live.renderables] + assert not any("failed" in frame or "interrupted" in frame for frame in frames) + assert "running" in frames[-1] + assert "Tier 3 progress display stopped after a drawing error; the run continues." in output.getvalue() updates_before = live.update_calls reporter.emit(progress.ProgressEvent(stage="agent:codex", state="complete")) assert live.update_calls == updates_before reporter.close() +def test_heartbeat_skips_a_transient_write_error_and_keeps_progress_on(monkeypatch: pytest.MonkeyPatch) -> None: + import rich.live + + progress = _progress_module() + failed_once = threading.Event() + redrawn_after_failure = threading.Event() + uncaught: list[BaseException | None] = [] + monkeypatch.setattr(threading, "excepthook", lambda args: uncaught.append(args.exc_value)) + + class FlakyLive(_FakeLive): + """Refuses one heartbeat write, as a terminal made non-blocking by a child process can.""" + + def update(self, renderable, *, refresh: bool = False) -> None: + on_heartbeat = threading.current_thread().name == "tier3-progress-heartbeat" + if on_heartbeat and not failed_once.is_set(): + failed_once.set() + raise BlockingIOError(errno.EAGAIN, "write could not complete without blocking") + super().update(renderable, refresh=refresh) + if on_heartbeat: + redrawn_after_failure.set() + + _FakeLive.instances.clear() + monkeypatch.setattr(rich.live, "Live", FlakyLive) + reporter = progress.safe_progress_reporter( + progress.RichProgressReporter(stream=_TTYBuffer(), refresh_interval=0.05) + ) + reporter.start(_plan(progress)) + reporter.emit(progress.ProgressEvent(stage="agent:codex", state="running", detail="evaluating")) + + assert failed_once.wait(timeout=10) + assert redrawn_after_failure.wait(timeout=10) + assert reporter.is_active is True + reporter.emit(progress.ProgressEvent(stage="agent:codex", state="complete", detail="agent finished")) + reporter.emit(progress.ProgressEvent(stage="run-finished", state="complete", detail="Tier 3 evaluation finished")) + live = _FakeLive.instances[0] + frame = _render(live.renderables[-1], width=180) + reporter.close() + + assert "agent finished" in frame + assert "Tier 3 evaluation finished" in frame + assert "failed" not in frame + assert "interrupted" not in frame + assert live.stop_calls == 1 + assert uncaught == [] + + def test_heartbeat_failure_without_a_safety_wrapper_stops_the_thread(monkeypatch: pytest.MonkeyPatch) -> None: progress = _progress_module() uncaught: list[BaseException | None] = [] From c8584b137f1b941cfc4e590e8e26127d917ee8af Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Sun, 8 Nov 2026 12:44:54 +0530 Subject: [PATCH 04/16] fix(tier3): stop a plan update that races a heartbeat failure SafeProgressReporter checked its disabled flag before calling the reporter, but not atomically with the heartbeat thread's _disable(). A plan update waiting on the reporter lock while a heartbeat redraw failed could pass the check after the reporter was closed, and then start a new Live on a disabled wrapper. That frame stayed on screen, with stdout and stderr redirected through it, until the run's final close(). - start() holds a wrapper lock while the reporter draws the plan, and _disable() sets its flags under the same lock. A failure reported from the heartbeat thread waits for the plan update and then stops what it drew. The reporter is closed outside the lock, because closing joins the heartbeat thread. - Registering the failure callback is now best effort. A caller-supplied reporter whose set_failure_callback raises, or whose attribute lookup raises, is wrapped as before instead of failing the evaluation. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- src/skillevaluator/tier3/harbor/progress.py | 50 ++++++++----- tests/test_tier3_progress.py | 79 +++++++++++++++++++++ 2 files changed, 113 insertions(+), 16 deletions(-) diff --git a/src/skillevaluator/tier3/harbor/progress.py b/src/skillevaluator/tier3/harbor/progress.py index ff0f286d8..b0d0acb83 100644 --- a/src/skillevaluator/tier3/harbor/progress.py +++ b/src/skillevaluator/tier3/harbor/progress.py @@ -615,11 +615,19 @@ def __init__(self, reporter: ProgressReporter) -> None: self._reporter = reporter self._disabled = False self._started = False + # start() holds this lock while the reporter draws a plan, so a failure + # reported from the reporter's heartbeat thread waits for that plan + # update and then stops what it drew, instead of letting it start a new + # live view after progress was turned off. + self._lock = threading.RLock() # A reporter's own heartbeat thread reports failures here, so a redraw # error there turns progress off just like one on the caller's thread. - set_failure_callback = getattr(reporter, "set_failure_callback", None) - if callable(set_failure_callback): - set_failure_callback(self._disable) + try: + set_failure_callback = getattr(reporter, "set_failure_callback", None) + if callable(set_failure_callback): + set_failure_callback(self._disable) + except Exception: + logger.debug("Tier 3 progress reporter failure callback registration failed", exc_info=True) @property def is_active(self) -> bool: @@ -632,12 +640,18 @@ def is_active(self) -> bool: return self._started def start(self, plan: Tier3RunPlan) -> None: - if self._disabled: - return - self._started = True - self._call(self._reporter.start, plan) - if self._disabled: - self._started = False + with self._lock: + if self._disabled: + return + self._started = True + try: + self._reporter.start(plan) + return + except Exception: + logger.debug("Tier 3 progress reporter disabled after presentation failure", exc_info=True) + # Closed outside the lock: closing joins the heartbeat thread, which + # may be waiting for the lock to report its own failure. + self._disable() def set_secret_values(self, values: list[str] | tuple[str, ...] | set[str]) -> None: self._call(self._reporter.set_secret_values, values) @@ -649,13 +663,16 @@ def heartbeat(self) -> None: self._call(self._reporter.heartbeat) def close(self) -> None: + # The lock is not held here: closing joins the heartbeat thread, which + # may be waiting for the lock to report a failure. try: self._reporter.close() except Exception: logger.debug("Tier 3 progress reporter cleanup failed", exc_info=True) finally: - self._started = False - self._disabled = False + with self._lock: + self._started = False + self._disabled = False def _call(self, callback, *args: object) -> None: if self._disabled: @@ -667,11 +684,12 @@ def _call(self, callback, *args: object) -> None: self._disable() def _disable(self) -> None: - if self._disabled: - return - self._disabled = True - # A disabled reporter shows nothing, so it is no longer active. - self._started = False + with self._lock: + if self._disabled: + return + self._disabled = True + # A disabled reporter shows nothing, so it is no longer active. + self._started = False # Only the display failed, so a reporter that can stop without marking # its running stages failed does so. try: diff --git a/tests/test_tier3_progress.py b/tests/test_tier3_progress.py index 0e308bb6b..b54b6fba1 100644 --- a/tests/test_tier3_progress.py +++ b/tests/test_tier3_progress.py @@ -863,6 +863,85 @@ def update(self, renderable, *, refresh: bool = False) -> None: assert uncaught == [] +def test_heartbeat_failure_during_a_plan_update_stops_what_the_update_drew( + monkeypatch: pytest.MonkeyPatch, +) -> None: + import rich.live + + progress = _progress_module() + _FakeLive.instances.clear() + monkeypatch.setattr(rich.live, "Live", _FakeLive) + + class RacingReporter(progress.RichProgressReporter): + report_failure: Any = None + failure_thread: threading.Thread | None = None + race = False + + def set_failure_callback(self, callback) -> None: + super().set_failure_callback(callback) + self.report_failure = callback + + def start(self, plan) -> None: + if self.race: + # The heartbeat thread reports a redraw failure while this plan + # update is in flight. + self.failure_thread = threading.Thread(target=self.report_failure) + self.failure_thread.start() + self.failure_thread.join(timeout=0.2) + super().start(plan) + + rich_reporter = RacingReporter(stream=_TTYBuffer(), refresh_interval=60) + reporter = progress.safe_progress_reporter(rich_reporter) + reporter.start(_plan(progress)) + rich_reporter.race = True + reporter.start(_plan(progress)) + failure_thread = rich_reporter.failure_thread + assert failure_thread is not None + failure_thread.join(timeout=10) + + assert not failure_thread.is_alive() + # The failure waited for the update, then stopped the frame it drew. + assert reporter.is_active is False + assert rich_reporter.is_active is False + assert [live.stop_calls for live in _FakeLive.instances] == [1] + reporter.close() + + +def test_safe_reporter_wraps_a_reporter_whose_callback_registration_fails() -> None: + progress = _progress_module() + + class RefusingReporter(progress.NullProgressReporter): + def __init__(self) -> None: + self.events: list[Any] = [] + + def set_failure_callback(self, _callback) -> None: + raise RuntimeError("failure callbacks are not supported") + + def emit(self, event) -> None: + self.events.append(event) + + class StrictProxy: + """Forwards the reporter protocol and refuses any other attribute.""" + + def __init__(self) -> None: + self.target = RefusingReporter() + + def __getattr__(self, name: str) -> Any: + if name in {"is_active", "start", "set_secret_values", "emit", "heartbeat", "close"}: + return getattr(self.target, name) + raise RuntimeError(f"unsupported attribute: {name}") + + refusing = RefusingReporter() + proxy = StrictProxy() + + for target, events in ((refusing, refusing.events), (proxy, proxy.target.events)): + reporter = progress.safe_progress_reporter(target) + reporter.start(_plan(progress)) + reporter.emit(progress.ProgressEvent(stage="configuration", state="running")) + reporter.close() + assert [event.stage for event in events] == ["configuration"] + + def test_heartbeat_failure_without_a_safety_wrapper_stops_the_thread(monkeypatch: pytest.MonkeyPatch) -> None: progress = _progress_module() uncaught: list[BaseException | None] = [] From 9d5f6dee0b81d3bd171a58b2609d354d4802d538 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Sun, 8 Nov 2026 12:45:30 +0530 Subject: [PATCH 05/16] fix(tier3): print the full run plan above the fixed Rich progress frame The fixed-height frame cuts each row with an ellipsis. At 80 columns that hid most of the Run plan row (concurrency, max agents, timeout, matrix trials, containers, the scaled agent timeout), every agent's model after the first, and the second Ctrl+C hint, which only appears in a stopping agent's detail. On main these rows wrapped and stayed visible. - The Rich reporter prints the Agents / models, Provider and Run plan lines in full above the frame whenever one of them changes. They stay in the scrollback; the frame keeps its height. - The stopping detail is now a runner constant that starts with a short hint, "Ctrl+C again skips wait", so the row cut at 80 columns still shows it with the longest built-in stage label in the frame. - close() also clears the record of printed plan lines, so the next run prints its plan again. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- src/skillevaluator/tier3/harbor/progress.py | 81 ++++++---- src/skillevaluator/tier3/harbor/runner.py | 11 +- tests/test_tier3_progress.py | 161 +++++++++++++++++++- 3 files changed, 219 insertions(+), 34 deletions(-) diff --git a/src/skillevaluator/tier3/harbor/progress.py b/src/skillevaluator/tier3/harbor/progress.py index b0d0acb83..a5742d3c4 100644 --- a/src/skillevaluator/tier3/harbor/progress.py +++ b/src/skillevaluator/tier3/harbor/progress.py @@ -395,6 +395,7 @@ def __init__( self._live_plan: Tier3RunPlan | None = None self._live_events: dict[str, tuple[ProgressEvent, str | None]] = {} self._live_event_slots = _LIVE_MIN_EVENT_ROWS + self._printed_plan_lines: dict[str, str] = {} def emit(self, event: ProgressEvent) -> None: with self._lock: @@ -438,6 +439,7 @@ def close(self) -> None: self._live_plan = None self._live_events.clear() self._live_event_slots = _LIVE_MIN_EVENT_ROWS + self._printed_plan_lines.clear() def close_after_failure(self) -> None: """Stop the live view after a drawing failure and say that the run goes on.""" @@ -457,13 +459,20 @@ def close_after_failure(self) -> None: def _render_plan(self, plan: Tier3RunPlan) -> None: self._live_plan = plan + # The frame cuts long rows to keep its height, so each plan line is + # also printed in full above it whenever that line changes. + for label, text in self._plan_lines(plan): + if self._printed_plan_lines.get(label) != text: + self._printed_plan_lines[label] = text + self._write_line(f"{label}: {text}") table = self._build_live_table() if self._live is None: self._live = self._live_factory( table, console=self._console, - # Redraw only from progress events and the heartbeat, which - # hold the reporter lock, never from Rich's own refresh thread. + # Rich never redraws on its own timer. The frame is redrawn when + # the plan or a stage changes, on each heartbeat, and when other + # output is printed above it. auto_refresh=False, transient=False, ) @@ -471,6 +480,47 @@ def _render_plan(self, plan: Tier3RunPlan) -> None: else: self._live.update(table, refresh=True) + def _plan_agents_text(self, plan: Tier3RunPlan) -> str: + model_map = dict(plan.agent_models) + return ", ".join( + f"{self._safe_text(agent)}={self._safe_text(model_map[agent])}" + if agent in model_map + else self._safe_text(agent) + for agent in plan.agents + ) + + def _plan_values_text(self, plan: Tier3RunPlan) -> str: + values = ( + ("Tasks", plan.task_count), + ("Cases", plan.case_count), + ("Attempts", plan.attempts), + ("With skill", None if plan.with_skill is None else "yes" if plan.with_skill else "no"), + ("Baseline", None if plan.baseline is None else "yes" if plan.baseline else "no"), + ("Concurrency", plan.concurrency), + ("Max agents", plan.max_agents), + ("Timeout", None if plan.timeout_multiplier is None else f"{plan.timeout_multiplier:g}x"), + ("Matrix trials", plan.matrix_trials), + ("Preflight trials", plan.preflight_trials), + ("Containers", plan.total_containers), + ( + "Max scaled top-level agent timeout", + None if plan.task_timeout_seconds is None else f"{plan.task_timeout_seconds:g}s", + ), + ) + return " · ".join(f"{label} {value}" for label, value in values if value is not None) + + def _plan_lines(self, plan: Tier3RunPlan) -> list[tuple[str, str]]: + lines = [] + agents = self._plan_agents_text(plan) + if agents: + lines.append(("Agents / models", agents)) + if plan.provider: + lines.append(("Provider", self._safe_text(plan.provider))) + known = self._plan_values_text(plan) + if known: + lines.append(("Run plan", known)) + return lines + def _build_live_table(self): from rich import box from rich.spinner import Spinner @@ -502,13 +552,7 @@ def _build_live_table(self): table.add_column("Elapsed", justify="right", no_wrap=True, overflow="ellipsis") table.add_row("Environment", Text("configured", style=TEXT), Text(self._safe_text(plan.environment)), "") - model_map = dict(plan.agent_models) - agents = ", ".join( - f"{self._safe_text(agent)}={self._safe_text(model_map[agent])}" - if agent in model_map - else self._safe_text(agent) - for agent in plan.agents - ) + agents = self._plan_agents_text(plan) table.add_row("Agents / models", Text("configured", style=TEXT), Text(agents or "none"), "") # The Provider and Run plan rows are always present, with a placeholder # until the plan resolves, so a plan update does not add rows. @@ -518,24 +562,7 @@ def _build_live_table(self): Text(self._safe_text(plan.provider or "resolving")), "", ) - values = ( - ("Tasks", plan.task_count), - ("Cases", plan.case_count), - ("Attempts", plan.attempts), - ("With skill", None if plan.with_skill is None else "yes" if plan.with_skill else "no"), - ("Baseline", None if plan.baseline is None else "yes" if plan.baseline else "no"), - ("Concurrency", plan.concurrency), - ("Max agents", plan.max_agents), - ("Timeout", None if plan.timeout_multiplier is None else f"{plan.timeout_multiplier:g}x"), - ("Matrix trials", plan.matrix_trials), - ("Preflight trials", plan.preflight_trials), - ("Containers", plan.total_containers), - ( - "Max scaled top-level agent timeout", - None if plan.task_timeout_seconds is None else f"{plan.task_timeout_seconds:g}s", - ), - ) - known = " · ".join(f"{label} {value}" for label, value in values if value is not None) + known = self._plan_values_text(plan) table.add_row( "Run plan", Text("configured" if known else "pending", style=TEXT if known else MUTED), diff --git a/src/skillevaluator/tier3/harbor/runner.py b/src/skillevaluator/tier3/harbor/runner.py index d8c081f1a..f5fd0e94b 100644 --- a/src/skillevaluator/tier3/harbor/runner.py +++ b/src/skillevaluator/tier3/harbor/runner.py @@ -796,6 +796,12 @@ def _persist_dataset_truth(run_dir: Path, *, fallback_task_ids: list[str]) -> di # waits this long for that cleanup before it kills the process group. _HARBOR_RUN_CANCEL_GRACE_SECONDS = 30.0 _HARBOR_RUN_CANCEL_POLL_SECONDS = 0.1 +# Progress detail for an agent whose Harbor jobs are stopping. The hint comes +# first and is short, so the Rich progress row, which is cut to the terminal +# width, still shows it at 80 columns. +_HARBOR_RUN_STOPPING_DETAIL = ( + f"Ctrl+C again skips wait; stopping Harbor jobs, up to {_HARBOR_RUN_CANCEL_GRACE_SECONDS:g}s of environment cleanup" +) _HARBOR_RUN_REAP_SECONDS = 5.0 @@ -6135,10 +6141,7 @@ def _join_interrupted_agents() -> None: ProgressEvent( stage=f"agent:{agent}", state="running", - detail=( - "stopping Harbor jobs; press Ctrl+C again to skip up to " - f"{_HARBOR_RUN_CANCEL_GRACE_SECONDS:g}s of environment cleanup" - ), + detail=_HARBOR_RUN_STOPPING_DETAIL, ) ) wait(running, timeout=_HARBOR_RUN_CANCEL_POLL_SECONDS) diff --git a/tests/test_tier3_progress.py b/tests/test_tier3_progress.py index b54b6fba1..4b6f119f5 100644 --- a/tests/test_tier3_progress.py +++ b/tests/test_tier3_progress.py @@ -427,6 +427,153 @@ def _fail_live_initialization(*_args, **_kwargs): assert reporter._live_plan is None assert reporter._live_events == {} assert reporter._live_event_slots == progress._LIVE_MIN_EVENT_ROWS + # A stale record of printed plan lines would hide the next run's plan. + assert reporter._printed_plan_lines == {} + + +def test_rich_progress_prints_the_full_plan_above_the_fixed_frame(monkeypatch: pytest.MonkeyPatch) -> None: + import rich.live + + progress = _progress_module() + _FakeLive.instances.clear() + monkeypatch.setattr(rich.live, "Live", _FakeLive) + monkeypatch.setenv("COLUMNS", "80") + output = _TTYBuffer() + reporter = progress.RichProgressReporter(stream=output, refresh_interval=60) + agents = ("claude-code", "codex") + options = {"attempts": 3, "baseline": True, "with_skill": True, "concurrency": 4, "max_agents": 2} + reporter.start( + progress.Tier3RunPlan( + skill_name="pdf-processing", + environment="docker", + agents=agents, + timeout_multiplier=1.5, + **options, + ) + ) + resolved = progress.Tier3RunPlan( + skill_name="pdf-processing", + environment="docker", + agents=agents, + agent_models=(("claude-code", "anthropic/claude-sonnet-4-5"), ("codex", "openai/gpt-5.1-codex")), + provider="nv_build", + task_count=3, + case_count=12, + timeout_multiplier=1.5, + matrix_trials=72, + preflight_trials=2, + total_containers=74, + task_timeout_seconds=1350, + **options, + ) + reporter.start(resolved) + # An unchanged plan update prints nothing again. + reporter.start(resolved) + + live = _FakeLive.instances[0] + frame_heights = {len(_render(renderable).splitlines()) for renderable in live.renderables} + printed = output.getvalue().splitlines() + reporter.close() + + assert printed == [ + "Agents / models: claude-code, codex", + "Run plan: Attempts 3 · With skill yes · Baseline yes · Concurrency 4 · Max agents 2 · Timeout 1.5x", + "Agents / models: claude-code=anthropic/claude-sonnet-4-5, codex=openai/gpt-5.1-codex", + "Provider: nv_build", + "Run plan: Tasks 3 · Cases 12 · Attempts 3 · With skill yes · Baseline yes · Concurrency 4 · " + "Max agents 2 · Timeout 1.5x · Matrix trials 72 · Preflight trials 2 · Containers 74 · " + "Max scaled top-level agent timeout 1350s", + ] + # The frame below keeps one height at 80 columns while the plan resolves. + assert len(frame_heights) == 1 + + +def _stopping_frame_reporter(progress: Any, output: io.StringIO, agents: tuple[str, ...], stopping_detail: str) -> Any: + """Return a Rich reporter whose stage sequence matches a run stopped by Ctrl+C.""" + reporter = progress.RichProgressReporter(stream=output, refresh_interval=60) + plan = progress.Tier3RunPlan( + skill_name="pdf-processing", + environment="docker", + agents=agents, + agent_models=tuple((agent, f"provider/{agent}-large-model") for agent in agents), + provider="nv_build", + task_count=3, + case_count=12, + attempts=3, + baseline=True, + with_skill=True, + concurrency=4, + max_agents=2, + timeout_multiplier=1.5, + matrix_trials=72, + preflight_trials=0, + total_containers=72, + task_timeout_seconds=1350, + ) + reporter.start(plan) + for stage in ( + "configuration", + "model-resolution", + "environment-preflight", + "credential-validation", + "with-skill-tasks", + "baseline-tasks", + "case-selection", + "docker-images", + ): + reporter.emit(progress.ProgressEvent(stage=stage, state="complete", detail="done")) + # The longest built-in stage label stays in the recent-stage window. + reporter.emit( + progress.ProgressEvent( + stage="agent-runtime-preflight", + state="skipped", + detail="disabled by default; enable with --agent-runtime-preflight", + ) + ) + for agent in agents: + reporter.emit(progress.ProgressEvent(stage=f"agent:{agent}", state="running", detail="with-skill + baseline")) + for agent in agents: + reporter.emit(progress.ProgressEvent(stage=f"agent:{agent}", state="running", detail=stopping_detail)) + return reporter + + +@pytest.mark.parametrize("agents", [("claude-code", "codex"), ("mini-swe-agent",)]) +def test_rich_progress_at_80_columns_shows_the_ctrl_c_hint_and_the_full_plan( + monkeypatch: pytest.MonkeyPatch, + agents: tuple[str, ...], +) -> None: + import rich.live + + from skillevaluator.tier3.harbor import runner + + progress = _progress_module() + _FakeLive.instances.clear() + monkeypatch.setattr(rich.live, "Live", _FakeLive) + monkeypatch.setenv("COLUMNS", "80") + stream = _TTYBuffer() + reporter = _stopping_frame_reporter(progress, stream, agents, runner._HARBOR_RUN_STOPPING_DETAIL) + output = stream.getvalue() + frame = _render(_FakeLive.instances[0].renderables[-1], width=80) + reporter.close() + + agent_rows = [line for line in frame.splitlines() if line.startswith("│ Agent ") and "running" in line] + assert len(agent_rows) == len(agents) + # The frame cuts each row to the terminal width; the second Ctrl+C hint + # comes first in the detail and is short, so it is still readable. + hint = runner._HARBOR_RUN_STOPPING_DETAIL.split(";")[0] + assert hint.startswith("Ctrl+C again") + assert all(hint in row for row in agent_rows) + # Every plan value is printed in full above the frame. + assert all(f"{agent}=provider/{agent}-large-model" in output for agent in agents) + for value in ( + "Concurrency 4", + "Max agents 2", + "Timeout 1.5x", + "Matrix trials 72", + "Containers 72", + "Max scaled top-level agent timeout 1350s", + ): + assert value in output def test_rich_reporter_immediately_starts_one_live_box_and_keeps_stage_updates_inside_it( @@ -451,7 +598,13 @@ def test_rich_reporter_immediately_starts_one_live_box_and_keeps_stage_updates_i Console(file=initial, force_terminal=False, width=180).print(live.renderables[0]) assert "Harbor Run Configuration" in initial.getvalue() assert "demo-skill" in initial.getvalue() - assert output.getvalue() == "" + # Only the full plan lines are printed above the box; no stage line is. + plan_lines = ( + "Agents / models: codex=gpt-5, opencode=nvidia/llama\n" + "Provider: openai\n" + "Run plan: Tasks 2 · Cases 2 · Attempts 3 · Baseline yes · Concurrency 4 · Max agents 2 · Timeout 1.5x\n" + ) + assert output.getvalue() == plan_lines reporter.emit(progress.ProgressEvent(stage="agent-runtime-preflight", state="running")) @@ -459,7 +612,7 @@ def test_rich_reporter_immediately_starts_one_live_box_and_keeps_stage_updates_i Console(file=updated, force_terminal=False, width=180).print(live.renderables[-1]) assert "Agent Runtime Preflight" in updated.getvalue() assert "running" in updated.getvalue() - assert output.getvalue() == "" + assert output.getvalue() == plan_lines reporter.close() @@ -3272,7 +3425,9 @@ def run_agent(**kwargs: Any) -> list[str]: assert reporter.interrupts == 2 events = [(event.stage, event.state, event.detail) for event in reporter.events] stopping = [detail for stage, state, detail in events if stage == "agent:codex" and state == "running"] - assert stopping[-1].startswith("stopping Harbor jobs; press Ctrl+C again") + assert stopping[-1] == runner._HARBOR_RUN_STOPPING_DETAIL + assert stopping[-1].startswith("Ctrl+C again skips wait; stopping Harbor jobs") + assert stopping[-1].endswith("up to 30s of environment cleanup") assert ("agent:codex", "failed", "interrupted before completion") in events assert events[-1] == ("run-finished", "failed", "Tier 3 evaluation interrupted") From 2209ebd22394f67b4307a3576a993ae598682712 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Sun, 8 Nov 2026 12:46:20 +0530 Subject: [PATCH 06/16] fix(tier3): list every stage in full in the final Rich progress frame Live is created with transient=False, so its last frame stays in the scrollback. That frame kept the six-row recent window, so earlier outcomes dropped out of the record (for example a failed first agent, or a degraded Docker images stage). Its details were cut with an ellipsis, and a run that failed before the plan resolved left "pending / resolving" rows behind, as if work were still in progress. - close() updates Live with a final table before stopping it. That table lists every stage without padding rows, wraps the Detail column in full, and shows unresolved Provider and Run plan rows as "- / not resolved". - After a drawing failure, Live keeps the last frame it drew instead, since drawing the final table could fail the same way. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- src/skillevaluator/tier3/harbor/progress.py | 75 ++++++++++----- tests/test_tier3_progress.py | 101 ++++++++++++++++++++ 2 files changed, 150 insertions(+), 26 deletions(-) diff --git a/src/skillevaluator/tier3/harbor/progress.py b/src/skillevaluator/tier3/harbor/progress.py index a5742d3c4..87d50f517 100644 --- a/src/skillevaluator/tier3/harbor/progress.py +++ b/src/skillevaluator/tier3/harbor/progress.py @@ -423,6 +423,9 @@ def heartbeat(self) -> None: self._refresh_live() def close(self) -> None: + self._close(final_frame=True) + + def _close(self, *, final_frame: bool) -> None: live = self._live try: super().close() @@ -430,7 +433,14 @@ def close(self) -> None: with self._lock: try: if live is not None and live is self._live: - live.stop() + try: + if final_frame: + # Once Live stops, its last frame stays in the + # scrollback and no longer needs a fixed height, + # so it lists every stage in full. + live.update(self._build_live_table(final=True), refresh=False) + finally: + live.stop() finally: # Reset even when Live never started, so a failed start # leaves no plan or rows behind for the next run. @@ -448,11 +458,13 @@ def close_after_failure(self) -> None: # interrupted, so close() must not report them as failed. self._active.clear() had_live = self._live is not None - self.close() + # Drawing the final frame could fail the same way, so Live keeps the + # last frame it drew. + self._close(final_frame=False) if had_live: try: - # The last frame stays on screen with its stages still running, - # so explain why it no longer updates. + # That frame stays on screen with its stages still running, so + # explain why it no longer updates. self._write_line("Tier 3 progress display stopped after a drawing error; the run continues.") except Exception: logger.debug("Tier 3 progress stop notice failed", exc_info=True) @@ -521,7 +533,7 @@ def _plan_lines(self, plan: Tier3RunPlan) -> list[tuple[str, str]]: lines.append(("Run plan", known)) return lines - def _build_live_table(self): + def _build_live_table(self, *, final: bool = False): from rich import box from rich.spinner import Spinner from rich.table import Table @@ -545,30 +557,39 @@ def _build_live_table(self): ) table = Table(title=title, box=box.ROUNDED, border_style=FAINT, expand=True, show_lines=False) # One line per row: long values are cut with an ellipsis rather than - # wrapped, so the frame height does not depend on the text. + # wrapped, so the frame height does not depend on the text. The final + # frame stays in the scrollback, so there the details wrap in full. table.add_column("Stage", style="bold", no_wrap=True, overflow="ellipsis") table.add_column("State", width=12, no_wrap=True, overflow="ellipsis") - table.add_column("Detail", ratio=1, no_wrap=True, overflow="ellipsis") + if final: + table.add_column("Detail", ratio=1, overflow="fold") + else: + table.add_column("Detail", ratio=1, no_wrap=True, overflow="ellipsis") table.add_column("Elapsed", justify="right", no_wrap=True, overflow="ellipsis") table.add_row("Environment", Text("configured", style=TEXT), Text(self._safe_text(plan.environment)), "") agents = self._plan_agents_text(plan) table.add_row("Agents / models", Text("configured", style=TEXT), Text(agents or "none"), "") - # The Provider and Run plan rows are always present, with a placeholder - # until the plan resolves, so a plan update does not add rows. - table.add_row( - "Provider", - Text("configured" if plan.provider else "pending", style=TEXT if plan.provider else MUTED), - Text(self._safe_text(plan.provider or "resolving")), - "", - ) + + def placeholder(waiting_detail: str) -> tuple[Text, Text]: + # The row is always present so a plan update does not add rows. A + # finished run's frame stays on screen, so there it no longer says + # the value is still on its way. + if final: + return Text("-", style=MUTED), Text("not resolved", style=MUTED) + return Text("pending", style=MUTED), Text(waiting_detail) + + if plan.provider: + provider_state, provider_detail = Text("configured", style=TEXT), Text(self._safe_text(plan.provider)) + else: + provider_state, provider_detail = placeholder("resolving") + table.add_row("Provider", provider_state, provider_detail, "") known = self._plan_values_text(plan) - table.add_row( - "Run plan", - Text("configured" if known else "pending", style=TEXT if known else MUTED), - Text(known or "preparing"), - "", - ) + if known: + plan_state, plan_detail = Text("configured", style=TEXT), Text(known) + else: + plan_state, plan_detail = placeholder("preparing") + table.add_row("Run plan", plan_state, plan_detail, "") state_styles = { "ready": GREEN, "complete": GREEN, @@ -579,11 +600,12 @@ def _build_live_table(self): } # Show only the most recently updated stages in a fixed number of rows. # The slot count only grows (to fit every agent), so the frame never - # shrinks either. + # shrinks either. The final frame lists every stage, without padding. self._live_event_slots = max(self._live_event_slots, len(plan.agents)) event_slots = self._live_event_slots - recent_events = list(self._live_events.items())[-event_slots:] - for stage, (event, finished_at) in recent_events: + events = list(self._live_events.items()) + shown_events = events if final else events[-event_slots:] + for stage, (event, finished_at) in shown_events: label = ( f"Agent {stage.removeprefix('agent:')}" if stage.startswith("agent:") @@ -600,8 +622,9 @@ def _build_live_table(self): Text(event.detail or ""), Text(finished_at or self._elapsed()), ) - for _ in range(event_slots - len(recent_events)): - table.add_row("", "", "", "") + if not final: + for _ in range(event_slots - len(shown_events)): + table.add_row("", "", "", "") return table def _refresh_live(self) -> None: diff --git a/tests/test_tier3_progress.py b/tests/test_tier3_progress.py index 4b6f119f5..926be175d 100644 --- a/tests/test_tier3_progress.py +++ b/tests/test_tier3_progress.py @@ -488,6 +488,107 @@ def test_rich_progress_prints_the_full_plan_above_the_fixed_frame(monkeypatch: p assert len(frame_heights) == 1 +def test_rich_final_frame_marks_a_plan_that_never_resolved(monkeypatch: pytest.MonkeyPatch) -> None: + import rich.live + + progress = _progress_module() + _FakeLive.instances.clear() + monkeypatch.setattr(rich.live, "Live", _FakeLive) + reporter = progress.RichProgressReporter(stream=_TTYBuffer(), refresh_interval=60) + # The CLI's first plan has no provider or counts; then configuration fails. + reporter.start(progress.Tier3RunPlan(skill_name="demo", environment="docker", agents=("codex",))) + reporter.emit( + progress.ProgressEvent( + stage="configuration", + state="failed", + detail="A public LLM provider is required for live evaluation", + ) + ) + live = _FakeLive.instances[0] + running_frame = _render(live.renderables[-1], width=180) + reporter.close() + final_frame = _render(live.renderables[-1], width=180) + + assert "resolving" in running_frame + assert "preparing" in running_frame + provider_row = next(line for line in final_frame.splitlines() if "Provider" in line) + plan_row = next(line for line in final_frame.splitlines() if "Run plan" in line) + assert "not resolved" in provider_row + assert "not resolved" in plan_row + assert not any(word in final_frame for word in ("pending", "resolving", "preparing")) + assert "A public LLM provider is required for live evaluation" in final_frame + assert live.stop_calls == 1 + + +def test_rich_final_frame_lists_every_stage(monkeypatch: pytest.MonkeyPatch) -> None: + import rich.live + + progress = _progress_module() + _FakeLive.instances.clear() + monkeypatch.setattr(rich.live, "Live", _FakeLive) + reporter = progress.RichProgressReporter(stream=_TTYBuffer(), refresh_interval=60) + reporter.start(_plan(progress)) + reporter.emit(progress.ProgressEvent(stage="docker-images", state="skipped", detail="local environment selected")) + for index in range(7): + reporter.emit( + progress.ProgressEvent( + stage=f"agent:agent-{index}", + state="complete", + detail=f"agent {index} finished", + ) + ) + reporter.emit(progress.ProgressEvent(stage="run-finished", state="complete", detail="Tier 3 evaluation finished")) + live = _FakeLive.instances[0] + running_frame = _render(live.renderables[-1], width=180) + reporter.close() + final_frame = _render(live.renderables[-1], width=180) + + assert "local environment selected" not in running_frame + assert "agent 0 finished" not in running_frame + # Once the run is over the frame stays in the scrollback, so it keeps every outcome. + assert "local environment selected" in final_frame + assert all(f"agent {index} finished" in final_frame for index in range(7)) + assert "Tier 3 evaluation finished" in final_frame + assert live.stop_calls == 1 + + +def _row_detail(frame: str, stage_label: str) -> str: + """Return a row's Detail cell, joining the lines it wraps onto.""" + detail: list[str] = [] + for line in frame.splitlines(): + cells = [cell.strip() for cell in line.split("│")[1:-1]] + if len(cells) != 4: + continue + # A wrapped row continues on lines whose Stage cell is empty. + if cells[0] == stage_label or (detail and not cells[0]): + detail.append(cells[2]) + elif detail: + break + return " ".join(part for part in detail if part) + + +def test_rich_final_frame_wraps_details_the_running_frame_cuts(monkeypatch: pytest.MonkeyPatch) -> None: + import rich.live + + progress = _progress_module() + _FakeLive.instances.clear() + monkeypatch.setattr(rich.live, "Live", _FakeLive) + reporter = progress.RichProgressReporter(stream=_TTYBuffer(), refresh_interval=60) + reporter.start(_plan(progress)) + reason = "one or more Harbor jobs failed; inspect the retained artifacts and the trial logs" + reporter.emit(progress.ProgressEvent(stage="agent:codex", state="failed", detail=reason)) + live = _FakeLive.instances[0] + running_frame = _render(live.renderables[-1]) + reporter.close() + final_frame = _render(live.renderables[-1]) + + # At 80 columns the running frame cuts the reason to keep one line per row. + assert _row_detail(running_frame, "Agent codex") != reason + assert "…" in _row_detail(running_frame, "Agent codex") + # The final frame no longer needs a fixed height, so it shows the reason in full. + assert _row_detail(final_frame, "Agent codex") == reason + + def _stopping_frame_reporter(progress: Any, output: io.StringIO, agents: tuple[str, ...], stopping_detail: str) -> Any: """Return a Rich reporter whose stage sequence matches a run stopped by Ctrl+C.""" reporter = progress.RichProgressReporter(stream=output, refresh_interval=60) From ae7964cc48f418d057a689fcacf8ac659029d505 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Sun, 8 Nov 2026 12:46:34 +0530 Subject: [PATCH 07/16] docs(tier3): describe the plan lines, final frame and drawing failures Align the CHANGELOG entry, the rich view paragraph in docs/tier3-live-evaluation.mdx and the --progress row in docs/cli-reference.mdx with the progress fixes: the full plan printed above the table, the final table listing every stage in full, the Ctrl+C hint shown first, a blocked heartbeat write skipped, and what a drawing failure leaves on screen. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 19 +++++++++++++------ docs/cli-reference.mdx | 2 +- docs/tier3-live-evaluation.mdx | 15 ++++++++++----- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5649a2259..6241f0d48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -126,12 +126,19 @@ All notable changes to SkillEvaluator are documented in this file. repeated or jumbled table frames. The Provider and Run plan rows show a placeholder until the plan resolves, each row is one line that ends in an ellipsis when its value is too long, and stages fill a fixed number of rows, - at least six and one per agent, showing the most recently updated. The view - redraws only on progress events and heartbeats, no longer also from Rich's - own refresh thread. If drawing fails on the heartbeat thread, the view now - stops and progress turns off while the run continues. Before, that thread - ended with a traceback and the view stopped updating elapsed times but stayed - active. + at least six and one per agent, showing the most recently updated. The agent + models, provider and run plan are printed in full above the table whenever + they change, and the table left on screen when the run ends lists every stage + with its full detail. A stopping agent's detail now starts with the second + Ctrl+C hint, so a cut row still shows it. The view redraws only on progress + events and heartbeats, no longer also from Rich's own refresh thread. A + heartbeat redraw whose write would block is skipped until the next + heartbeat. If drawing fails any other way, the table keeps its last frame + with running stages still shown as running, a line says that the run + continues, and no further progress is shown for that run; the final results + still print. Before, a failure on the heartbeat thread ended that thread with + a traceback and left the view active without updating elapsed times, and a + failure on the caller's thread marked the running stages as failed. ## 0.8.0 - 2026-11-05 diff --git a/docs/cli-reference.mdx b/docs/cli-reference.mdx index d3c9cd4e6..e3c5bb377 100644 --- a/docs/cli-reference.mdx +++ b/docs/cli-reference.mdx @@ -508,7 +508,7 @@ Use `skillevaluator tier3 PATH` for the complete workflow with automatic missing | `--evaluated-source-repository TEXT` | unset | Repository (`owner/name`) of the source tree being evaluated, persisted into the run's `run_config.json`. | | `--evaluated-source-revision TEXT` | unset | Immutable revision of the evaluated source: a full Git object id, or a `sha256`/`sha384`/`sha512` digest. A short prefix is refused. | | `--evaluator-container-revision TEXT` | unset | Digest-pinned evaluator image reference recorded beside the evaluated source. | -| `--progress [auto\|rich\|plain\|off]` | `auto` | Progress display for the run: `rich` live view (a fixed-height table of the run plan and recent stages), `plain` line output, or `off`. | +| `--progress [auto\|rich\|plain\|off]` | `auto` | Progress display for the run: `rich` live view (a fixed-height table of the run plan and recent stages, with the full plan printed above it), `plain` line output, or `off`. | | `--progress-interval SECONDS` | mode default | Seconds between progress heartbeats, from `0.05` to `86400`: how often the `rich` view refreshes elapsed times and how often `plain` output repeats a `still running` line for active stages. Defaults to 1 second for `rich` and 60 seconds for `plain`, including `auto` with redirected or CI output. | Without a `--model`/`--agent-model` override, agent execution uses diff --git a/docs/tier3-live-evaluation.mdx b/docs/tier3-live-evaluation.mdx index b4a0e52ca..d28edfca5 100644 --- a/docs/tier3-live-evaluation.mdx +++ b/docs/tier3-live-evaluation.mdx @@ -595,11 +595,16 @@ remain. In a terminal, `--progress auto` uses the `rich` view: one table of the run plan and its stages that keeps the same height for the whole run. Each row is -one line, and a long value ends in an ellipsis instead of wrapping. The table -shows the most recently updated stages in a fixed number of rows, at least six -and at least one per agent. It redraws only when a stage changes or a heartbeat -updates elapsed times. If the terminal fails to draw it, the view stops and the -run continues. +one line, and a long value ends in an ellipsis instead of wrapping. The agent +models, provider and run plan are also printed in full above the table +whenever they change. The table shows the most recently updated stages in a +fixed number of rows, at least six and at least one per agent. When the run +ends, the table left on screen lists every stage with its full detail. The +view redraws only when a stage changes or a heartbeat updates elapsed times. A +heartbeat redraw whose write would block is skipped until the next heartbeat. +If drawing fails any other way, the table stops updating with its stages as +they were, a line says that the run continues, and no further progress is +shown for that run; the final results still print. Every `tier3 evaluate` flag, including resource overrides and Dockerfile modes, is in the [CLI Reference](cli-reference.mdx). From 2128d8a632e1e8fc495d3efefa5747f04332a0b1 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Sun, 8 Nov 2026 20:14:42 +0530 Subject: [PATCH 08/16] fix(tier3): turn progress off when a heartbeat write would block A heartbeat redraw that failed with BlockingIOError or InterruptedError was skipped so that the next heartbeat could draw again. Rich does not drop a refused frame: it keeps it in the heartbeat thread's buffer and sends it again, from the start, before the next one. A terminal that refuses writes for a while therefore gets a backlog that grows by one frame per heartbeat, and once the backlog is larger than one write can take, it never drains while the reporter stays active. Treat these errors like any other drawing failure: call the failure callback, which stops the live view without marking running stages failed and says that the run continues. The heartbeat thread then ends, and its buffer with it. The test drives a real Rich Live on a terminal that refuses heartbeat writes once or every time, and checks that progress turns off and the heartbeat thread ends. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 16 ++-- docs/tier3-live-evaluation.mdx | 9 +- src/skillevaluator/tier3/harbor/progress.py | 8 +- tests/test_tier3_progress.py | 96 +++++++++++++-------- 4 files changed, 73 insertions(+), 56 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6241f0d48..37583bcc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -131,14 +131,14 @@ All notable changes to SkillEvaluator are documented in this file. they change, and the table left on screen when the run ends lists every stage with its full detail. A stopping agent's detail now starts with the second Ctrl+C hint, so a cut row still shows it. The view redraws only on progress - events and heartbeats, no longer also from Rich's own refresh thread. A - heartbeat redraw whose write would block is skipped until the next - heartbeat. If drawing fails any other way, the table keeps its last frame - with running stages still shown as running, a line says that the run - continues, and no further progress is shown for that run; the final results - still print. Before, a failure on the heartbeat thread ended that thread with - a traceback and left the view active without updating elapsed times, and a - failure on the caller's thread marked the running stages as failed. + events and heartbeats, no longer also from Rich's own refresh thread. If + drawing fails, including a terminal write that would block, the table keeps + its last frame with running stages still shown as running, a line says that + the run continues, and no further progress is shown for that run; the final + results still print. Before, a failure on the heartbeat thread ended that + thread with a traceback and left the view active without updating elapsed + times, and a failure on the caller's thread marked the running stages as + failed. ## 0.8.0 - 2026-11-05 diff --git a/docs/tier3-live-evaluation.mdx b/docs/tier3-live-evaluation.mdx index d28edfca5..db2547476 100644 --- a/docs/tier3-live-evaluation.mdx +++ b/docs/tier3-live-evaluation.mdx @@ -600,11 +600,10 @@ models, provider and run plan are also printed in full above the table whenever they change. The table shows the most recently updated stages in a fixed number of rows, at least six and at least one per agent. When the run ends, the table left on screen lists every stage with its full detail. The -view redraws only when a stage changes or a heartbeat updates elapsed times. A -heartbeat redraw whose write would block is skipped until the next heartbeat. -If drawing fails any other way, the table stops updating with its stages as -they were, a line says that the run continues, and no further progress is -shown for that run; the final results still print. +view redraws only when a stage changes or a heartbeat updates elapsed times. If +drawing fails, including a terminal write that would block, the table stops +updating with its stages as they were, a line says that the run continues, and +no further progress is shown for that run; the final results still print. Every `tier3 evaluate` flag, including resource overrides and Dockerfile modes, is in the [CLI Reference](cli-reference.mdx). diff --git a/src/skillevaluator/tier3/harbor/progress.py b/src/skillevaluator/tier3/harbor/progress.py index 87d50f517..b1825852e 100644 --- a/src/skillevaluator/tier3/harbor/progress.py +++ b/src/skillevaluator/tier3/harbor/progress.py @@ -336,15 +336,13 @@ def _heartbeat_loop(self) -> None: return try: self.heartbeat() - except (BlockingIOError, InterruptedError): - # A terminal that another process made non-blocking can refuse - # one write; the next heartbeat draws the frame again. - logger.debug("Tier 3 progress heartbeat skipped after a transient write error", exc_info=True) - continue except Exception: # A redraw failure here must turn progress off through the # safety wrapper, which stops the live display, instead of # killing this thread and leaving a half-drawn frame behind. + # That includes a write a non-blocking terminal refuses: Rich + # keeps the refused frame and sends it again before the next + # one, so skipping it would only grow that backlog. logger.debug("Tier 3 progress heartbeat failed", exc_info=True) if self._stop.is_set(): # close() is already stopping this reporter. diff --git a/tests/test_tier3_progress.py b/tests/test_tier3_progress.py index 926be175d..321ce7abe 100644 --- a/tests/test_tier3_progress.py +++ b/tests/test_tier3_progress.py @@ -1071,49 +1071,69 @@ def stop(self) -> None: reporter.close() -def test_heartbeat_skips_a_transient_write_error_and_keeps_progress_on(monkeypatch: pytest.MonkeyPatch) -> None: - import rich.live +@pytest.mark.parametrize("refused_writes", [1, None], ids=["refused-once", "refused-always"]) +def test_heartbeat_write_that_would_block_turns_progress_off( + monkeypatch: pytest.MonkeyPatch, + refused_writes: int | None, +) -> None: + from rich.console import Console progress = _progress_module() - failed_once = threading.Event() - redrawn_after_failure = threading.Event() + monkeypatch.setenv("TERM", "xterm-256color") uncaught: list[BaseException | None] = [] monkeypatch.setattr(threading, "excepthook", lambda args: uncaught.append(args.exc_value)) - - class FlakyLive(_FakeLive): - """Refuses one heartbeat write, as a terminal made non-blocking by a child process can.""" - - def update(self, renderable, *, refresh: bool = False) -> None: - on_heartbeat = threading.current_thread().name == "tier3-progress-heartbeat" - if on_heartbeat and not failed_once.is_set(): - failed_once.set() - raise BlockingIOError(errno.EAGAIN, "write could not complete without blocking") - super().update(renderable, refresh=refresh) - if on_heartbeat: - redrawn_after_failure.set() - - _FakeLive.instances.clear() - monkeypatch.setattr(rich.live, "Live", FlakyLive) - reporter = progress.safe_progress_reporter( - progress.RichProgressReporter(stream=_TTYBuffer(), refresh_interval=0.05) + refused = threading.Event() + heartbeat_writes: list[int] = [] + + class NonBlockingTerminal(_TTYBuffer): + """A terminal another process made non-blocking: it refuses heartbeat writes.""" + + def write(self, text: str) -> int: + if threading.current_thread().name == "tier3-progress-heartbeat": + heartbeat_writes.append(len(text)) + if refused_writes is None or len(heartbeat_writes) <= refused_writes: + refused.set() + raise BlockingIOError(errno.EAGAIN, "write could not complete without blocking", 0) + return super().write(text) + + stream = NonBlockingTerminal() + rich_reporter = progress.RichProgressReporter(stream=stream, refresh_interval=0.05) + # A real Rich Live, which keeps a refused frame in its buffer and sends it + # again with the next one. + rich_reporter._console = Console( + file=stream, + force_terminal=True, + legacy_windows=False, + width=120, + color_system=None, ) - reporter.start(_plan(progress)) - reporter.emit(progress.ProgressEvent(stage="agent:codex", state="running", detail="evaluating")) - - assert failed_once.wait(timeout=10) - assert redrawn_after_failure.wait(timeout=10) - assert reporter.is_active is True - reporter.emit(progress.ProgressEvent(stage="agent:codex", state="complete", detail="agent finished")) - reporter.emit(progress.ProgressEvent(stage="run-finished", state="complete", detail="Tier 3 evaluation finished")) - live = _FakeLive.instances[0] - frame = _render(live.renderables[-1], width=180) - reporter.close() - - assert "agent finished" in frame - assert "Tier 3 evaluation finished" in frame - assert "failed" not in frame - assert "interrupted" not in frame - assert live.stop_calls == 1 + reporter = progress.safe_progress_reporter(rich_reporter) + try: + reporter.start(_plan(progress)) + heartbeat = rich_reporter._thread + assert heartbeat is not None + reporter.emit(progress.ProgressEvent(stage="agent:codex", state="running", detail="evaluating")) + + assert refused.wait(timeout=10) + # A refused write turns progress off, so the heartbeat thread ends + # instead of resending a growing backlog of frames. + heartbeat.join(timeout=10) + assert not heartbeat.is_alive() + assert reporter.is_active is False + assert rich_reporter._live is None + reporter.emit(progress.ProgressEvent(stage="agent:codex", state="complete", detail="agent finished")) + output = stream.getvalue() + assert "agent finished" not in output + # Only the display failed, so no stage is reported as failed. + assert "failed" not in output + assert "interrupted" not in output + if refused_writes == 1: + # The terminal took the stop, so the frame left behind and the line + # under it say that the agent is still running. + assert "running" in output + assert "Tier 3 progress display stopped after a drawing error; the run continues." in output + finally: + reporter.close() assert uncaught == [] From 3d5ebf4f780166ac52db069a474e4c85abc4fd63 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Sun, 8 Nov 2026 20:18:40 +0530 Subject: [PATCH 09/16] fix(tier3): skip the interrupted marks atomically when a failed display stops close_after_failure() cleared the running stages under the reporter lock, released it, and then called close(), which takes the lock again and marks every still-running stage "failed - interrupted before completion". An agent update that took the lock in between put its stage back, and that stage was then drawn as failed in the frame Live leaves on screen. close() and close_after_failure() now share one _close(after_failure=...) path that decides under the same lock hold whether to mark the running stages. After a drawing failure nothing is marked, so a late update is drawn as running. The test runs the late update from another thread the first time the stopping thread releases the reporter lock. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- src/skillevaluator/tier3/harbor/progress.py | 63 ++++++++++----------- tests/test_tier3_progress.py | 63 +++++++++++++++++++++ 2 files changed, 94 insertions(+), 32 deletions(-) diff --git a/src/skillevaluator/tier3/harbor/progress.py b/src/skillevaluator/tier3/harbor/progress.py index b1825852e..8c7a8df25 100644 --- a/src/skillevaluator/tier3/harbor/progress.py +++ b/src/skillevaluator/tier3/harbor/progress.py @@ -244,16 +244,31 @@ def heartbeat(self) -> None: self._write_line(f"[{self._elapsed()}] still running: {stages}") def close(self) -> None: + self._close(after_failure=False) + + def close_after_failure(self) -> None: + """Stop after a presentation failure without marking running stages failed. + + Only the display failed. The run goes on, so a stage that is still + running has not been interrupted. + """ + self._close(after_failure=True) + + def _close(self, *, after_failure: bool) -> None: try: with self._lock: - for stage in tuple(self._active): - self.emit( - ProgressEvent( - stage=stage, - state="failed", - detail="interrupted before completion", + # Decided under the same lock hold that would mark the stages, + # so an update that arrives while a failed display stops is + # never reported as interrupted. + if not after_failure: + for stage in tuple(self._active): + self.emit( + ProgressEvent( + stage=stage, + state="failed", + detail="interrupted before completion", + ) ) - ) finally: self._stop.set() thread = self._thread @@ -267,16 +282,6 @@ def close(self) -> None: self._last_events.clear() self._last_progress_at = None - def close_after_failure(self) -> None: - """Stop after a presentation failure without marking running stages failed. - - Only the display failed. The run goes on, so a stage that is still - running has not been interrupted. - """ - with self._lock: - self._active.clear() - self.close() - def _render_plan(self, plan: Tier3RunPlan) -> None: first_plan = not self._plan_rendered self._plan_rendered = True @@ -420,22 +425,21 @@ def heartbeat(self) -> None: if self._active: self._refresh_live() - def close(self) -> None: - self._close(final_frame=True) - - def _close(self, *, final_frame: bool) -> None: + def _close(self, *, after_failure: bool) -> None: live = self._live try: - super().close() + super()._close(after_failure=after_failure) finally: with self._lock: try: if live is not None and live is self._live: try: - if final_frame: + if not after_failure: # Once Live stops, its last frame stays in the # scrollback and no longer needs a fixed height, - # so it lists every stage in full. + # so it lists every stage in full. After a + # drawing failure that frame could fail the same + # way, so Live keeps the last frame it drew. live.update(self._build_live_table(final=True), refresh=False) finally: live.stop() @@ -452,17 +456,12 @@ def _close(self, *, final_frame: bool) -> None: def close_after_failure(self) -> None: """Stop the live view after a drawing failure and say that the run goes on.""" with self._lock: - # Only the display failed: the stages still running are not - # interrupted, so close() must not report them as failed. - self._active.clear() had_live = self._live is not None - # Drawing the final frame could fail the same way, so Live keeps the - # last frame it drew. - self._close(final_frame=False) + super().close_after_failure() if had_live: try: - # That frame stays on screen with its stages still running, so - # explain why it no longer updates. + # The last frame Live drew stays on screen with its stages + # still running, so explain why it no longer updates. self._write_line("Tier 3 progress display stopped after a drawing error; the run continues.") except Exception: logger.debug("Tier 3 progress stop notice failed", exc_info=True) diff --git a/tests/test_tier3_progress.py b/tests/test_tier3_progress.py index 321ce7abe..33266f44a 100644 --- a/tests/test_tier3_progress.py +++ b/tests/test_tier3_progress.py @@ -1137,6 +1137,69 @@ def write(self, text: str) -> int: assert uncaught == [] +class _InterleavingLock: + """A reentrant lock that runs a hook once, when the arming thread next releases it fully.""" + + def __init__(self) -> None: + self._lock = threading.RLock() + self._depth = 0 + self._hook: tuple[threading.Thread, Any] | None = None + + def arm(self, hook: Any) -> None: + self._hook = (threading.current_thread(), hook) + + def __enter__(self) -> _InterleavingLock: + self._lock.acquire() + self._depth += 1 + return self + + def __exit__(self, *exc_info: object) -> None: + self._depth -= 1 + released = self._depth == 0 + self._lock.release() + armed = self._hook + if released and armed is not None and armed[0] is threading.current_thread(): + self._hook = None + armed[1]() + + +def test_an_update_that_races_a_drawing_failure_is_not_drawn_as_failed(monkeypatch: pytest.MonkeyPatch) -> None: + import rich.live + + progress = _progress_module() + _FakeLive.instances.clear() + monkeypatch.setattr(rich.live, "Live", _FakeLive) + rich_reporter = progress.RichProgressReporter(stream=_TTYBuffer(), refresh_interval=60) + lock = _InterleavingLock() + rich_reporter._lock = lock + reporter = progress.safe_progress_reporter(rich_reporter) + reporter.start(_plan(progress)) + reporter.emit(progress.ProgressEvent(stage="agent:codex", state="running", detail="attempt 1 of 3")) + + def late_agent_update() -> None: + # The caller's next agent update passed the wrapper's check before the + # failure turned progress off, and reaches the reporter while it stops. + update = threading.Thread( + target=rich_reporter.emit, + args=(progress.ProgressEvent(stage="agent:codex", state="running", detail="attempt 2 of 3"),), + ) + update.start() + update.join(timeout=10) + + lock.arm(late_agent_update) + # What the heartbeat thread's failure callback runs. + reporter._disable() + live = _FakeLive.instances[0] + frames = [_render(renderable, width=180) for renderable in live.renderables] + reporter.close() + + # Only the display failed: the agent is never drawn as failed, and the + # frame left on screen shows the update as still running. + assert not any("failed" in frame or "interrupted" in frame for frame in frames) + assert "attempt 2 of 3" in frames[-1] + assert live.stop_calls == 1 + + def test_heartbeat_failure_during_a_plan_update_stops_what_the_update_drew( monkeypatch: pytest.MonkeyPatch, ) -> None: From 77205326a7e525e0b2d341001f8f1a487fd2a1cc Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Mon, 9 Nov 2026 08:30:33 +0530 Subject: [PATCH 10/16] fix(tier3): leave columns to spare around the second Ctrl+C hint At 80 columns, with Agent Runtime Preflight in the stage window, the Detail cell is 24 characters wide and "Ctrl+C again skips wait" filled it with no column to spare. At 79 columns, or on a legacy Windows console, which uses one column less, the hint was already cut. The stopping detail now starts with "2nd Ctrl+C skips wait", two characters shorter, so it still shows at 78 columns. The 80-column test also renders the frame at 78 columns, so a longer hint fails before it reaches the edge. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- src/skillevaluator/tier3/harbor/runner.py | 5 +++-- tests/test_tier3_progress.py | 18 +++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/skillevaluator/tier3/harbor/runner.py b/src/skillevaluator/tier3/harbor/runner.py index f5fd0e94b..ea67d637d 100644 --- a/src/skillevaluator/tier3/harbor/runner.py +++ b/src/skillevaluator/tier3/harbor/runner.py @@ -798,9 +798,10 @@ def _persist_dataset_truth(run_dir: Path, *, fallback_task_ids: list[str]) -> di _HARBOR_RUN_CANCEL_POLL_SECONDS = 0.1 # Progress detail for an agent whose Harbor jobs are stopping. The hint comes # first and is short, so the Rich progress row, which is cut to the terminal -# width, still shows it at 80 columns. +# width, still shows it at 80 columns next to the longest built-in stage label, +# with columns to spare. _HARBOR_RUN_STOPPING_DETAIL = ( - f"Ctrl+C again skips wait; stopping Harbor jobs, up to {_HARBOR_RUN_CANCEL_GRACE_SECONDS:g}s of environment cleanup" + f"2nd Ctrl+C skips wait; stopping Harbor jobs, up to {_HARBOR_RUN_CANCEL_GRACE_SECONDS:g}s of environment cleanup" ) _HARBOR_RUN_REAP_SECONDS = 5.0 diff --git a/tests/test_tier3_progress.py b/tests/test_tier3_progress.py index 33266f44a..9aacfd4dc 100644 --- a/tests/test_tier3_progress.py +++ b/tests/test_tier3_progress.py @@ -654,16 +654,20 @@ def test_rich_progress_at_80_columns_shows_the_ctrl_c_hint_and_the_full_plan( stream = _TTYBuffer() reporter = _stopping_frame_reporter(progress, stream, agents, runner._HARBOR_RUN_STOPPING_DETAIL) output = stream.getvalue() - frame = _render(_FakeLive.instances[0].renderables[-1], width=80) + table = _FakeLive.instances[0].renderables[-1] reporter.close() - agent_rows = [line for line in frame.splitlines() if line.startswith("│ Agent ") and "running" in line] - assert len(agent_rows) == len(agents) # The frame cuts each row to the terminal width; the second Ctrl+C hint - # comes first in the detail and is short, so it is still readable. + # comes first in the detail and is short, so it is still readable. It + # still fits two columns narrower: a legacy Windows console uses one + # column less, and one is to spare. hint = runner._HARBOR_RUN_STOPPING_DETAIL.split(";")[0] - assert hint.startswith("Ctrl+C again") - assert all(hint in row for row in agent_rows) + assert "Ctrl+C" in hint + for width in (80, 78): + frame = _render(table, width=width) + agent_rows = [line for line in frame.splitlines() if line.startswith("│ Agent ") and "running" in line] + assert len(agent_rows) == len(agents) + assert all(hint in row for row in agent_rows), (width, agent_rows) # Every plan value is printed in full above the frame. assert all(f"{agent}=provider/{agent}-large-model" in output for agent in agents) for value in ( @@ -3610,7 +3614,7 @@ def run_agent(**kwargs: Any) -> list[str]: events = [(event.stage, event.state, event.detail) for event in reporter.events] stopping = [detail for stage, state, detail in events if stage == "agent:codex" and state == "running"] assert stopping[-1] == runner._HARBOR_RUN_STOPPING_DETAIL - assert stopping[-1].startswith("Ctrl+C again skips wait; stopping Harbor jobs") + assert stopping[-1].startswith("2nd Ctrl+C skips wait; stopping Harbor jobs") assert stopping[-1].endswith("up to 30s of environment cleanup") assert ("agent:codex", "failed", "interrupted before completion") in events assert events[-1] == ("run-finished", "failed", "Tier 3 evaluation interrupted") From 4bbdf71613adf71be81472f087fe11e4761c4381 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Mon, 9 Nov 2026 08:32:02 +0530 Subject: [PATCH 11/16] fix(tier3): print colon-delimited plan values above the progress frame as is The Agents / models, Provider and Run plan lines above the Rich progress frame are printed in full so that values the frame cuts stay readable. They went through console.print with markup and highlighting off but emoji replacement on, so a model ID such as "ollama:llama:3.1-8b" was printed as "ollama", a llama emoji and "3.1-8b". The table cells are Text objects and were already verbatim. Print the lines with emoji=False too. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- src/skillevaluator/tier3/harbor/progress.py | 4 ++- tests/test_tier3_progress.py | 27 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/skillevaluator/tier3/harbor/progress.py b/src/skillevaluator/tier3/harbor/progress.py index 8c7a8df25..2bc29b5bf 100644 --- a/src/skillevaluator/tier3/harbor/progress.py +++ b/src/skillevaluator/tier3/harbor/progress.py @@ -629,7 +629,9 @@ def _refresh_live(self) -> None: self._live.update(self._build_live_table(), refresh=True) def _write_line(self, line: str) -> None: - self._console.print(line, markup=False, highlight=False, soft_wrap=True) + # Printed as is: model IDs and providers can contain ":name:", which + # Rich would otherwise replace with an emoji. + self._console.print(line, markup=False, highlight=False, emoji=False, soft_wrap=True) class NullProgressReporter: diff --git a/tests/test_tier3_progress.py b/tests/test_tier3_progress.py index 9aacfd4dc..c4a34a1d9 100644 --- a/tests/test_tier3_progress.py +++ b/tests/test_tier3_progress.py @@ -488,6 +488,33 @@ def test_rich_progress_prints_the_full_plan_above_the_fixed_frame(monkeypatch: p assert len(frame_heights) == 1 +def test_rich_progress_prints_colon_delimited_plan_values_verbatim(monkeypatch: pytest.MonkeyPatch) -> None: + import rich.live + + progress = _progress_module() + _FakeLive.instances.clear() + monkeypatch.setattr(rich.live, "Live", _FakeLive) + output = _TTYBuffer() + reporter = progress.RichProgressReporter(stream=output, refresh_interval=60) + # Rich would read ":llama:" and ":rocket:" as emoji codes. + reporter.start( + progress.Tier3RunPlan( + skill_name="demo", + environment="docker", + agents=("opencode",), + agent_models=(("opencode", "ollama:llama:3.1-8b"),), + provider="custom:rocket:proxy", + ) + ) + printed = output.getvalue().splitlines() + reporter.close() + + assert printed == [ + "Agents / models: opencode=ollama:llama:3.1-8b", + "Provider: custom:rocket:proxy", + ] + + def test_rich_final_frame_marks_a_plan_that_never_resolved(monkeypatch: pytest.MonkeyPatch) -> None: import rich.live From 47d5a30c55efd299baabc685e3a10abe544fcd56 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Mon, 9 Nov 2026 08:36:34 +0530 Subject: [PATCH 12/16] fix(tier3): keep the final progress frame's rows on one line in a narrow terminal The final Rich frame, which stays in the scrollback, folded its Detail column so that each detail is shown in full. Stage, State and Elapsed do not wrap, so in a 60-column terminal they left the Detail column 4 characters wide and every detail folded into a stack of 4-character pieces: the emulated full run left a 252-line table, against 134 lines on main. Rich gives a ratio column whatever width the other columns leave and ignores its min_width, so the final frame is now drawn at render time: it wraps its details only when the width it is drawn at leaves the Detail column at least 20 columns wide, and otherwise keeps each row on one line as while running. The emulated 60-column run now leaves 35 lines; at 80 columns and wider nothing changes. The test renders the final frame at 76 columns, where the Detail column is exactly 20 wide, and at 75 and 60 columns. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 22 ++--- docs/tier3-live-evaluation.mdx | 12 +-- src/skillevaluator/tier3/harbor/progress.py | 98 ++++++++++++++++----- tests/test_tier3_progress.py | 39 ++++++++ 4 files changed, 131 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37583bcc5..ebccba9e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -128,17 +128,17 @@ All notable changes to SkillEvaluator are documented in this file. ellipsis when its value is too long, and stages fill a fixed number of rows, at least six and one per agent, showing the most recently updated. The agent models, provider and run plan are printed in full above the table whenever - they change, and the table left on screen when the run ends lists every stage - with its full detail. A stopping agent's detail now starts with the second - Ctrl+C hint, so a cut row still shows it. The view redraws only on progress - events and heartbeats, no longer also from Rich's own refresh thread. If - drawing fails, including a terminal write that would block, the table keeps - its last frame with running stages still shown as running, a line says that - the run continues, and no further progress is shown for that run; the final - results still print. Before, a failure on the heartbeat thread ended that - thread with a traceback and left the view active without updating elapsed - times, and a failure on the caller's thread marked the running stages as - failed. + they change, and the table left on screen when the run ends lists every + stage, with its full detail when the Detail column is at least 20 columns + wide. A stopping agent's detail now starts with the second Ctrl+C hint, so a + cut row still shows it. The view redraws only on progress events and + heartbeats, no longer also from Rich's own refresh thread. If drawing fails, + including a terminal write that would block, the table keeps its last frame + with running stages still shown as running, a line says that the run + continues, and no further progress is shown for that run; the final results + still print. Before, a failure on the heartbeat thread ended that thread with + a traceback and left the view active without updating elapsed times, and a + failure on the caller's thread marked the running stages as failed. ## 0.8.0 - 2026-11-05 diff --git a/docs/tier3-live-evaluation.mdx b/docs/tier3-live-evaluation.mdx index db2547476..771cf2c37 100644 --- a/docs/tier3-live-evaluation.mdx +++ b/docs/tier3-live-evaluation.mdx @@ -599,11 +599,13 @@ one line, and a long value ends in an ellipsis instead of wrapping. The agent models, provider and run plan are also printed in full above the table whenever they change. The table shows the most recently updated stages in a fixed number of rows, at least six and at least one per agent. When the run -ends, the table left on screen lists every stage with its full detail. The -view redraws only when a stage changes or a heartbeat updates elapsed times. If -drawing fails, including a terminal write that would block, the table stops -updating with its stages as they were, a line says that the run continues, and -no further progress is shown for that run; the final results still print. +ends, the table left on screen lists every stage. Its details wrap in full +when the terminal leaves the Detail column at least 20 columns; in a narrower +terminal each row stays on one line. The view redraws only when a stage +changes or a heartbeat updates elapsed times. If drawing fails, including a +terminal write that would block, the table stops updating with its stages as +they were, a line says that the run continues, and no further progress is +shown for that run; the final results still print. Every `tier3 evaluate` flag, including resource overrides and Dockerfile modes, is in the [CLI Reference](cli-reference.mdx). diff --git a/src/skillevaluator/tier3/harbor/progress.py b/src/skillevaluator/tier3/harbor/progress.py index 2bc29b5bf..99ad9ef28 100644 --- a/src/skillevaluator/tier3/harbor/progress.py +++ b/src/skillevaluator/tier3/harbor/progress.py @@ -55,6 +55,14 @@ # run), padding with blank rows, so its height never changes mid-run. A frame # that grows or shrinks between redraws leaves stale or jumbled lines behind. _LIVE_MIN_EVENT_ROWS = 6 +_LIVE_STATE_COLUMN_WIDTH = 12 +# The rounded table's five borders and one space of padding on each side of +# its four columns. +_LIVE_TABLE_CHROME_WIDTH = 5 + 4 * 2 +# The final frame wraps long details only when its Detail column is at least +# this wide. In a narrower column every detail would fold into a tall stack of +# short pieces, so there the rows stay cut on one line as while running. +_FINAL_DETAIL_MIN_WIDTH = 20 @dataclass(frozen=True, slots=True) @@ -379,6 +387,22 @@ def _write_line(self, line: str) -> None: self._stop.set() +class _FinalLiveFrame: + """The last Rich frame, which stays in the scrollback once Live stops. + + It draws ``wrapped`` when the width it is drawn at leaves the Detail column + at least ``_FINAL_DETAIL_MIN_WIDTH`` wide, and ``cut`` otherwise. + """ + + def __init__(self, *, wrapped: object, cut: object, min_width: int) -> None: + self.wrapped = wrapped + self.cut = cut + self.min_width = min_width + + def __rich_console__(self, _console, options): # rich renderable protocol + yield self.wrapped if options.max_width >= self.min_width else self.cut + + class RichProgressReporter(PlainProgressReporter): """Interactive Rich Live table selected for terminal output.""" @@ -532,6 +556,7 @@ def _plan_lines(self, plan: Tier3RunPlan) -> list[tuple[str, str]]: def _build_live_table(self, *, final: bool = False): from rich import box + from rich.cells import cell_len from rich.spinner import Spinner from rich.table import Table from rich.text import Text @@ -552,21 +577,11 @@ def _build_live_table(self, *, final: bool = False): overflow="ellipsis", no_wrap=True, ) - table = Table(title=title, box=box.ROUNDED, border_style=FAINT, expand=True, show_lines=False) - # One line per row: long values are cut with an ellipsis rather than - # wrapped, so the frame height does not depend on the text. The final - # frame stays in the scrollback, so there the details wrap in full. - table.add_column("Stage", style="bold", no_wrap=True, overflow="ellipsis") - table.add_column("State", width=12, no_wrap=True, overflow="ellipsis") - if final: - table.add_column("Detail", ratio=1, overflow="fold") - else: - table.add_column("Detail", ratio=1, no_wrap=True, overflow="ellipsis") - table.add_column("Elapsed", justify="right", no_wrap=True, overflow="ellipsis") - - table.add_row("Environment", Text("configured", style=TEXT), Text(self._safe_text(plan.environment)), "") + rows = [ + ("Environment", Text("configured", style=TEXT), Text(self._safe_text(plan.environment)), ""), + ] agents = self._plan_agents_text(plan) - table.add_row("Agents / models", Text("configured", style=TEXT), Text(agents or "none"), "") + rows.append(("Agents / models", Text("configured", style=TEXT), Text(agents or "none"), "")) def placeholder(waiting_detail: str) -> tuple[Text, Text]: # The row is always present so a plan update does not add rows. A @@ -580,13 +595,13 @@ def placeholder(waiting_detail: str) -> tuple[Text, Text]: provider_state, provider_detail = Text("configured", style=TEXT), Text(self._safe_text(plan.provider)) else: provider_state, provider_detail = placeholder("resolving") - table.add_row("Provider", provider_state, provider_detail, "") + rows.append(("Provider", provider_state, provider_detail, "")) known = self._plan_values_text(plan) if known: plan_state, plan_detail = Text("configured", style=TEXT), Text(known) else: plan_state, plan_detail = placeholder("preparing") - table.add_row("Run plan", plan_state, plan_detail, "") + rows.append(("Run plan", plan_state, plan_detail, "")) state_styles = { "ready": GREEN, "complete": GREEN, @@ -613,16 +628,51 @@ def placeholder(waiting_detail: str) -> tuple[Text, Text]: if event.state == "running" else Text(event.state, style=state_styles.get(event.state, "white")) ) - table.add_row( - Text(label), - state, - Text(event.detail or ""), - Text(finished_at or self._elapsed()), + rows.append( + ( + Text(label), + state, + Text(event.detail or ""), + Text(finished_at or self._elapsed()), + ) ) if not final: - for _ in range(event_slots - len(shown_events)): - table.add_row("", "", "", "") - return table + rows.extend(("", "", "", "") for _ in range(event_slots - len(shown_events))) + + def table(*, wrap_detail: bool) -> Table: + built = Table(title=title, box=box.ROUNDED, border_style=FAINT, expand=True, show_lines=False) + # One line per row: long values are cut with an ellipsis rather than + # wrapped, so the frame height does not depend on the text. Only the + # final frame may wrap its details. + built.add_column("Stage", style="bold", no_wrap=True, overflow="ellipsis") + built.add_column("State", width=_LIVE_STATE_COLUMN_WIDTH, no_wrap=True, overflow="ellipsis") + if wrap_detail: + built.add_column("Detail", ratio=1, overflow="fold") + else: + built.add_column("Detail", ratio=1, no_wrap=True, overflow="ellipsis") + built.add_column("Elapsed", justify="right", no_wrap=True, overflow="ellipsis") + for row in rows: + built.add_row(*row) + return built + + if not final: + return table(wrap_detail=False) + # The final frame stays in the scrollback, so its details wrap in full + # where the Detail column, which gets the width the other columns + # leave, is wide enough. + stage_width = max(cell_len(str(cell)) for cell in ["Stage", *(row[0] for row in rows)]) + elapsed_width = max(cell_len(str(cell)) for cell in ["Elapsed", *(row[3] for row in rows)]) + return _FinalLiveFrame( + wrapped=table(wrap_detail=True), + cut=table(wrap_detail=False), + min_width=( + _LIVE_TABLE_CHROME_WIDTH + + stage_width + + _LIVE_STATE_COLUMN_WIDTH + + elapsed_width + + _FINAL_DETAIL_MIN_WIDTH + ), + ) def _refresh_live(self) -> None: if self._live is not None: diff --git a/tests/test_tier3_progress.py b/tests/test_tier3_progress.py index c4a34a1d9..ae3542961 100644 --- a/tests/test_tier3_progress.py +++ b/tests/test_tier3_progress.py @@ -616,6 +616,45 @@ def test_rich_final_frame_wraps_details_the_running_frame_cuts(monkeypatch: pyte assert _row_detail(final_frame, "Agent codex") == reason +def test_rich_final_frame_keeps_rows_on_one_line_where_the_detail_column_is_narrow( + monkeypatch: pytest.MonkeyPatch, +) -> None: + import rich.live + + progress = _progress_module() + _FakeLive.instances.clear() + monkeypatch.setattr(rich.live, "Live", _FakeLive) + reporter = progress.RichProgressReporter(stream=_TTYBuffer(), refresh_interval=60) + reporter.start(_plan(progress)) + reporter.emit( + progress.ProgressEvent( + stage="agent-runtime-preflight", + state="skipped", + detail="disabled by default; enable with --agent-runtime-preflight", + ) + ) + reason = "one or more Harbor jobs failed; inspect the retained artifacts and the trial logs" + reporter.emit(progress.ProgressEvent(stage="agent:codex", state="failed", detail=reason)) + live = _FakeLive.instances[0] + reporter.close() + final = live.renderables[-1] + + # Stage (23 characters for Agent Runtime Preflight), State and Elapsed leave + # the Detail column 20 characters wide at 76 columns, so the details wrap. + wide = _render(final, width=76) + assert _row_detail(wide, "Agent codex") == reason + assert max(len(line.split("│")[3]) - 2 for line in wide.splitlines() if line.count("│") == 5) == 20 + # One column narrower, folding every detail into a tall stack of short + # pieces would leave the frame unreadable, so each row stays on one line. + for width in (75, 60): + narrow = _render(final, width=width) + rows = [line for line in narrow.splitlines() if line.count("│") == 5] + # The header, four plan rows and two stages. + assert len(rows) == 7, (width, narrow) + assert _row_detail(narrow, "Agent codex").endswith("…") + assert all(len(line) == width for line in narrow.splitlines() if line.strip()) + + def _stopping_frame_reporter(progress: Any, output: io.StringIO, agents: tuple[str, ...], stopping_detail: str) -> Any: """Return a Rich reporter whose stage sequence matches a run stopped by Ctrl+C.""" reporter = progress.RichProgressReporter(stream=output, refresh_interval=60) From b34927c2121775a70603dd89cc79e5d8c345ff84 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Mon, 9 Nov 2026 08:38:43 +0530 Subject: [PATCH 13/16] docs(changelog): move the progress view entry away from open PRs' insert points The entry sat at the end of Unreleased > Fixed, where open PRs #367 and #386 also add their entries, so each of them conflicted with this branch. It now sits in the middle of the same Fixed list, which no open PR changes. The text is unchanged. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebccba9e3..89d87f206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -97,6 +97,25 @@ All notable changes to SkillEvaluator are documented in this file. `Bedrock request failed`, like a Bedrock error that ends the judge and like the default `legacy` policy. +- The interactive Tier 3 progress view (`--progress rich`, or `auto` in a + terminal) now keeps one height for the whole run, so redraws no longer leave + repeated or jumbled table frames. The Provider and Run plan rows show a + placeholder until the plan resolves, each row is one line that ends in an + ellipsis when its value is too long, and stages fill a fixed number of rows, + at least six and one per agent, showing the most recently updated. The agent + models, provider and run plan are printed in full above the table whenever + they change, and the table left on screen when the run ends lists every + stage, with its full detail when the Detail column is at least 20 columns + wide. A stopping agent's detail now starts with the second Ctrl+C hint, so a + cut row still shows it. The view redraws only on progress events and + heartbeats, no longer also from Rich's own refresh thread. If drawing fails, + including a terminal write that would block, the table keeps its last frame + with running stages still shown as running, a line says that the run + continues, and no further progress is shown for that run; the final results + still print. Before, a failure on the heartbeat thread ended that thread with + a traceback and left the view active without updating elapsed times, and a + failure on the caller's thread marked the running stages as failed. + - `skillevaluator tier3 feedback` now writes the evaluated skill's directory (known from `--skill` or a run in the skill's `evals/results`) as its name and the home directory as `~` in the evidence it sends to the LLM, so an @@ -121,25 +140,6 @@ All notable changes to SkillEvaluator are documented in this file. `Use HTTP POST to create an item.` in a here-document or an unpiped `echo` still does not warn. -- The interactive Tier 3 progress view (`--progress rich`, or `auto` in a - terminal) now keeps one height for the whole run, so redraws no longer leave - repeated or jumbled table frames. The Provider and Run plan rows show a - placeholder until the plan resolves, each row is one line that ends in an - ellipsis when its value is too long, and stages fill a fixed number of rows, - at least six and one per agent, showing the most recently updated. The agent - models, provider and run plan are printed in full above the table whenever - they change, and the table left on screen when the run ends lists every - stage, with its full detail when the Detail column is at least 20 columns - wide. A stopping agent's detail now starts with the second Ctrl+C hint, so a - cut row still shows it. The view redraws only on progress events and - heartbeats, no longer also from Rich's own refresh thread. If drawing fails, - including a terminal write that would block, the table keeps its last frame - with running stages still shown as running, a line says that the run - continues, and no further progress is shown for that run; the final results - still print. Before, a failure on the heartbeat thread ended that thread with - a traceback and left the view active without updating elapsed times, and a - failure on the caller's thread marked the running stages as failed. - ## 0.8.0 - 2026-11-05 ### Added From baa461e495ad9be16defedeee1e599874a1f3902 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Mon, 9 Nov 2026 09:16:38 +0530 Subject: [PATCH 14/16] fix(tier3): show the cursor again when the terminal refused a failed display's stop A terminal that refuses a heartbeat redraw (a write that would block) usually refuses the stop that follows a few microseconds later on the same thread. Rich then loses the queued show-cursor control with that thread's buffer, the stop notice is skipped, and close() finds no Live to stop, so the cursor stayed hidden after the run. close_after_failure() now records when Live's stop or the notice under the last frame was refused, with the thread it ran on. The run's final close() then shows the cursor with Console.show_cursor(True) and prints "...; the run went on without it." A notice that was refused on the closing thread itself is not printed again: Rich still holds it for that thread and sends it with the cursor write. The refused-write test gains a terminal that refuses every thread's writes until the heartbeat thread has ended, a case that refuses only the notice, and the cursor and single-notice checks after close(). A new test covers the same refusals on the caller's thread. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 9 +- docs/tier3-live-evaluation.mdx | 4 +- src/skillevaluator/tier3/harbor/progress.py | 42 +++++++- tests/test_tier3_progress.py | 105 ++++++++++++++++++-- 4 files changed, 148 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89d87f206..33ab3569f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -112,9 +112,12 @@ All notable changes to SkillEvaluator are documented in this file. including a terminal write that would block, the table keeps its last frame with running stages still shown as running, a line says that the run continues, and no further progress is shown for that run; the final results - still print. Before, a failure on the heartbeat thread ended that thread with - a traceback and left the view active without updating elapsed times, and a - failure on the caller's thread marked the running stages as failed. + still print. When the terminal also refuses that line, or the write that + shows the cursor again, a line saying that the run went on is printed and + the cursor is shown when the run ends. Before, a failure on the heartbeat + thread ended that thread with a traceback and left the view active without + updating elapsed times, and a failure on the caller's thread marked the + running stages as failed. - `skillevaluator tier3 feedback` now writes the evaluated skill's directory (known from `--skill` or a run in the skill's `evals/results`) as its name diff --git a/docs/tier3-live-evaluation.mdx b/docs/tier3-live-evaluation.mdx index 771cf2c37..56bbaf1d5 100644 --- a/docs/tier3-live-evaluation.mdx +++ b/docs/tier3-live-evaluation.mdx @@ -605,7 +605,9 @@ terminal each row stays on one line. The view redraws only when a stage changes or a heartbeat updates elapsed times. If drawing fails, including a terminal write that would block, the table stops updating with its stages as they were, a line says that the run continues, and no further progress is -shown for that run; the final results still print. +shown for that run; the final results still print. When the terminal also +refuses that line, or the write that shows the cursor again, a line saying +that the run went on is printed and the cursor is shown when the run ends. Every `tier3 evaluate` flag, including resource overrides and Dockerfile modes, is in the [CLI Reference](cli-reference.mdx). diff --git a/src/skillevaluator/tier3/harbor/progress.py b/src/skillevaluator/tier3/harbor/progress.py index 99ad9ef28..ad11932cb 100644 --- a/src/skillevaluator/tier3/harbor/progress.py +++ b/src/skillevaluator/tier3/harbor/progress.py @@ -63,6 +63,9 @@ # this wide. In a narrower column every detail would fold into a tall stack of # short pieces, so there the rows stay cut on one line as while running. _FINAL_DETAIL_MIN_WIDTH = 20 +_DISPLAY_STOPPED_NOTICE = "Tier 3 progress display stopped after a drawing error; the run continues." +# Printed when the run ends instead, when the terminal refused the line above. +_DISPLAY_STOPPED_LATE_NOTICE = "Tier 3 progress display stopped after a drawing error; the run went on without it." @dataclass(frozen=True, slots=True) @@ -423,6 +426,10 @@ def __init__( self._live_events: dict[str, tuple[ProgressEvent, str | None]] = {} self._live_event_slots = _LIVE_MIN_EVENT_ROWS self._printed_plan_lines: dict[str, str] = {} + # Set when the terminal refused Live's stop, or the notice under the + # last frame, after a drawing failure: the thread that stopped Live and + # whether the notice reached Rich. close() finishes that stop. + self._unfinished_stop: tuple[threading.Thread, bool] | None = None def emit(self, event: ProgressEvent) -> None: with self._lock: @@ -476,19 +483,50 @@ def _close(self, *, after_failure: bool) -> None: self._live_events.clear() self._live_event_slots = _LIVE_MIN_EVENT_ROWS self._printed_plan_lines.clear() + if not after_failure: + unfinished, self._unfinished_stop = self._unfinished_stop, None + if unfinished is not None: + self._finish_refused_stop(*unfinished) def close_after_failure(self) -> None: """Stop the live view after a drawing failure and say that the run goes on.""" with self._lock: had_live = self._live is not None - super().close_after_failure() + try: + super().close_after_failure() + except Exception: + # A terminal that refused the redraw can refuse Live's stop too, + # and with it the write that shows the cursor again. + if had_live: + with self._lock: + self._unfinished_stop = (threading.current_thread(), False) + raise if had_live: try: # The last frame Live drew stays on screen with its stages # still running, so explain why it no longer updates. - self._write_line("Tier 3 progress display stopped after a drawing error; the run continues.") + self._write_line(_DISPLAY_STOPPED_NOTICE) except Exception: logger.debug("Tier 3 progress stop notice failed", exc_info=True) + with self._lock: + self._unfinished_stop = (threading.current_thread(), True) + + def _finish_refused_stop(self, stopped_on: threading.Thread, notice_sent: bool) -> None: + """Show the cursor and the stop notice that the terminal refused after a drawing failure. + + Runs on the thread that closes the run, once the terminal may take + writes again. Rich keeps a refused write for its thread and sends it + before that thread's next one; a thread that ended took its refused + writes with it. + """ + try: + # Live hides the cursor while it draws and shows it again when it + # stops, so a refused stop leaves it hidden after the run. + self._console.show_cursor(True) + if not notice_sent or stopped_on is not threading.current_thread(): + self._write_line(_DISPLAY_STOPPED_LATE_NOTICE) + except Exception: + logger.debug("Tier 3 progress terminal restore failed", exc_info=True) def _render_plan(self, plan: Tier3RunPlan) -> None: self._live_plan = plan diff --git a/tests/test_tier3_progress.py b/tests/test_tier3_progress.py index ae3542961..15c6c4654 100644 --- a/tests/test_tier3_progress.py +++ b/tests/test_tier3_progress.py @@ -1141,10 +1141,26 @@ def stop(self) -> None: reporter.close() -@pytest.mark.parametrize("refused_writes", [1, None], ids=["refused-once", "refused-always"]) +_STOP_NOTICE = "Tier 3 progress display stopped after a drawing error; the run continues." +_LATE_STOP_NOTICE = "Tier 3 progress display stopped after a drawing error; the run went on without it." + + +def _assert_cursor_shown_and_one_stop_notice(output: str, notice: str) -> None: + # Live hid the cursor while it drew; it is shown again after the last hide. + assert "\x1b[?25l" in output + assert output.rfind("\x1b[?25h") > output.rfind("\x1b[?25l") + assert output.count("Tier 3 progress display stopped after a drawing error") == 1 + assert notice in output + + +@pytest.mark.parametrize( + "refusal", + ["once", "always", "every-thread-for-a-while", "notice-only"], + ids=["refused-once", "refused-always", "every-thread-refused-for-a-while", "notice-refused"], +) def test_heartbeat_write_that_would_block_turns_progress_off( monkeypatch: pytest.MonkeyPatch, - refused_writes: int | None, + refusal: str, ) -> None: from rich.console import Console @@ -1154,14 +1170,24 @@ def test_heartbeat_write_that_would_block_turns_progress_off( monkeypatch.setattr(threading, "excepthook", lambda args: uncaught.append(args.exc_value)) refused = threading.Event() heartbeat_writes: list[int] = [] + # The heartbeat thread's first write is the refused redraw, its second + # Live's stop and its third the notice under the last frame. + refused_heartbeat_writes = {"once": {1}, "notice-only": {1, 3}}.get(refusal, set()) class NonBlockingTerminal(_TTYBuffer): - """A terminal another process made non-blocking: it refuses heartbeat writes.""" + """A terminal another process made non-blocking: it refuses some writes.""" + + # While set, the terminal's buffer is full and it refuses every + # thread's writes. + blocked = False def write(self, text: str) -> int: + if self.blocked: + refused.set() + raise BlockingIOError(errno.EAGAIN, "write could not complete without blocking", 0) if threading.current_thread().name == "tier3-progress-heartbeat": heartbeat_writes.append(len(text)) - if refused_writes is None or len(heartbeat_writes) <= refused_writes: + if refusal == "always" or len(heartbeat_writes) in refused_heartbeat_writes: refused.set() raise BlockingIOError(errno.EAGAIN, "write could not complete without blocking", 0) return super().write(text) @@ -1183,12 +1209,15 @@ def write(self, text: str) -> int: heartbeat = rich_reporter._thread assert heartbeat is not None reporter.emit(progress.ProgressEvent(stage="agent:codex", state="running", detail="evaluating")) + stream.blocked = refusal == "every-thread-for-a-while" assert refused.wait(timeout=10) # A refused write turns progress off, so the heartbeat thread ends # instead of resending a growing backlog of frames. heartbeat.join(timeout=10) assert not heartbeat.is_alive() + # The terminal takes writes again before the run ends. + stream.blocked = False assert reporter.is_active is False assert rich_reporter._live is None reporter.emit(progress.ProgressEvent(stage="agent:codex", state="complete", detail="agent finished")) @@ -1197,14 +1226,78 @@ def write(self, text: str) -> int: # Only the display failed, so no stage is reported as failed. assert "failed" not in output assert "interrupted" not in output - if refused_writes == 1: + if refusal == "once": # The terminal took the stop, so the frame left behind and the line # under it say that the agent is still running. assert "running" in output - assert "Tier 3 progress display stopped after a drawing error; the run continues." in output + assert _STOP_NOTICE in output finally: reporter.close() assert uncaught == [] + # A stop or notice the terminal refused on the heartbeat thread is lost + # with that thread, so closing the run shows the cursor and the notice. + _assert_cursor_shown_and_one_stop_notice( + stream.getvalue(), + _STOP_NOTICE if refusal == "once" else _LATE_STOP_NOTICE, + ) + + +@pytest.mark.parametrize( + "refused_writes", + [{1, 2}, {1, 3}], + ids=["update-and-stop-refused", "update-and-notice-refused"], +) +def test_callers_write_that_would_block_is_finished_when_progress_closes( + monkeypatch: pytest.MonkeyPatch, + refused_writes: set[int], +) -> None: + from rich.console import Console + + progress = _progress_module() + monkeypatch.setenv("TERM", "xterm-256color") + caller = threading.current_thread() + caller_writes: list[int] = [] + + class NonBlockingTerminal(_TTYBuffer): + """Refuses the caller's update, then its stop of Live or the notice under the last frame.""" + + armed = False + + def write(self, text: str) -> int: + if self.armed and threading.current_thread() is caller: + caller_writes.append(len(text)) + if len(caller_writes) in refused_writes: + raise BlockingIOError(errno.EAGAIN, "write could not complete without blocking", 0) + return super().write(text) + + stream = NonBlockingTerminal() + # No heartbeat during the test, so every write comes from this thread. + rich_reporter = progress.RichProgressReporter(stream=stream, refresh_interval=60) + rich_reporter._console = Console( + file=stream, + force_terminal=True, + legacy_windows=False, + width=120, + color_system=None, + ) + reporter = progress.safe_progress_reporter(rich_reporter) + try: + reporter.start(_plan(progress)) + reporter.emit(progress.ProgressEvent(stage="agent:codex", state="running", detail="evaluating")) + stream.armed = True + reporter.emit(progress.ProgressEvent(stage="agent:codex", state="running", detail="still evaluating")) + assert reporter.is_active is False + assert rich_reporter._live is None + stream.armed = False + finally: + reporter.close() + output = stream.getvalue() + assert "failed" not in output + assert "interrupted" not in output + # Rich sends this thread's refused writes again with its next one, so a + # refused notice is printed then, once, and a refused stop is followed by + # the late notice. + _assert_cursor_shown_and_one_stop_notice(output, _LATE_STOP_NOTICE if 2 in refused_writes else _STOP_NOTICE) class _InterleavingLock: From fb69d9d99bc936c229551b8763811f03abacaaea Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Mon, 9 Nov 2026 10:11:59 +0530 Subject: [PATCH 15/16] fix(tier3): finish a refused progress stop without replaying its frames Two gaps in how the run's close() finished a stop the terminal refused after a drawing failure: - The heartbeat thread recorded a refused stop, or a refused notice, in a second lock hold after the one that stopped Live, and wrote the notice outside the lock. A run-end close() that took the lock in between found no Live to stop and no record, so the cursor stayed hidden, and the record then reached the next run's close(), which printed the late notice in a healthy run. The stop, the notice and the record now share one lock hold, so close() either stops Live itself or finds the record. start() of a new run also drops a record left by a run that was never closed. - close() showed the cursor through the same Rich console, which first sent everything that console held for the closing thread from refused writes: the refused frame and Live's stop, each led by cursor-up and erase-line controls sized to the frame on screen when drawing failed. Lines printed since then, such as logged warnings, were erased and overwritten. close() now drops that held output first, shows the cursor and ends the frame's last line when the stop was refused, and prints the late notice whenever the notice did not reach the terminal, so a refused notice is no longer sent as the on-time "the run continues" line at the end of the run. Tests: the caller-thread refusal cases now print warnings before close() and check that close() writes no cursor-up or erase-line control and ends with the late notice. A new test closes the run from another thread while the heartbeat thread's refused stop is in progress, and another starts a reporter again without close() after a refused stop. The stop-notice check also requires the notice on a line of its own. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 9 +- docs/tier3-live-evaluation.mdx | 2 + src/skillevaluator/tier3/harbor/progress.py | 123 +++++++++++------- tests/test_tier3_progress.py | 133 +++++++++++++++++++- 4 files changed, 215 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33ab3569f..6a7d0823f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -114,10 +114,11 @@ All notable changes to SkillEvaluator are documented in this file. continues, and no further progress is shown for that run; the final results still print. When the terminal also refuses that line, or the write that shows the cursor again, a line saying that the run went on is printed and - the cursor is shown when the run ends. Before, a failure on the heartbeat - thread ended that thread with a traceback and left the view active without - updating elapsed times, and a failure on the caller's thread marked the - running stages as failed. + the cursor is shown when the run ends. Frames the terminal refused are + dropped then, so they are never drawn over output printed since. Before, a + failure on the heartbeat thread ended that thread with a traceback and left + the view active without updating elapsed times, and a failure on the + caller's thread marked the running stages as failed. - `skillevaluator tier3 feedback` now writes the evaluated skill's directory (known from `--skill` or a run in the skill's `evals/results`) as its name diff --git a/docs/tier3-live-evaluation.mdx b/docs/tier3-live-evaluation.mdx index 56bbaf1d5..28251130f 100644 --- a/docs/tier3-live-evaluation.mdx +++ b/docs/tier3-live-evaluation.mdx @@ -608,6 +608,8 @@ they were, a line says that the run continues, and no further progress is shown for that run; the final results still print. When the terminal also refuses that line, or the write that shows the cursor again, a line saying that the run went on is printed and the cursor is shown when the run ends. +Frames the terminal refused are dropped then, so they are never drawn over +output printed since. Every `tier3 evaluate` flag, including resource overrides and Dockerfile modes, is in the [CLI Reference](cli-reference.mdx). diff --git a/src/skillevaluator/tier3/harbor/progress.py b/src/skillevaluator/tier3/harbor/progress.py index ad11932cb..5afd63336 100644 --- a/src/skillevaluator/tier3/harbor/progress.py +++ b/src/skillevaluator/tier3/harbor/progress.py @@ -64,7 +64,8 @@ # short pieces, so there the rows stay cut on one line as while running. _FINAL_DETAIL_MIN_WIDTH = 20 _DISPLAY_STOPPED_NOTICE = "Tier 3 progress display stopped after a drawing error; the run continues." -# Printed when the run ends instead, when the terminal refused the line above. +# Printed when the run ends instead, when the terminal refused the line above +# or Live's stop. _DISPLAY_STOPPED_LATE_NOTICE = "Tier 3 progress display stopped after a drawing error; the run went on without it." @@ -99,6 +100,14 @@ class Tier3RunPlan: report_path: str | None = None +@dataclass(frozen=True, slots=True) +class _FailedDisplayStop: + """What reached the terminal when the live view stopped after a drawing failure.""" + + stop_refused: bool + notice_shown: bool + + @dataclass(frozen=True, slots=True) class ProgressEvent: """A structured progress transition emitted by the Tier 3 engine.""" @@ -426,10 +435,18 @@ def __init__( self._live_events: dict[str, tuple[ProgressEvent, str | None]] = {} self._live_event_slots = _LIVE_MIN_EVENT_ROWS self._printed_plan_lines: dict[str, str] = {} - # Set when the terminal refused Live's stop, or the notice under the - # last frame, after a drawing failure: the thread that stopped Live and - # whether the notice reached Rich. close() finishes that stop. - self._unfinished_stop: tuple[threading.Thread, bool] | None = None + # Set, under the same lock hold that stops Live, when a drawing failure + # stopped it. The run's close() finishes what the terminal refused. + self._failed_stop: _FailedDisplayStop | None = None + + def start_progress(self) -> None: + with self._lock: + if self._started_at is None and self._failed_stop is not None: + # The run whose display failed was never closed. Its refused + # writes and its notice do not belong to this run. + self._failed_stop = None + self._drop_refused_writes() + super().start_progress() def emit(self, event: ProgressEvent) -> None: with self._lock: @@ -464,16 +481,16 @@ def _close(self, *, after_failure: bool) -> None: with self._lock: try: if live is not None and live is self._live: - try: - if not after_failure: + if after_failure: + self._stop_live_after_failure(live) + else: + try: # Once Live stops, its last frame stays in the - # scrollback and no longer needs a fixed height, - # so it lists every stage in full. After a - # drawing failure that frame could fail the same - # way, so Live keeps the last frame it drew. + # scrollback and no longer needs a fixed + # height, so it lists every stage in full. live.update(self._build_live_table(final=True), refresh=False) - finally: - live.stop() + finally: + live.stop() finally: # Reset even when Live never started, so a failed start # leaves no plan or rows behind for the next run. @@ -484,46 +501,66 @@ def _close(self, *, after_failure: bool) -> None: self._live_event_slots = _LIVE_MIN_EVENT_ROWS self._printed_plan_lines.clear() if not after_failure: - unfinished, self._unfinished_stop = self._unfinished_stop, None - if unfinished is not None: - self._finish_refused_stop(*unfinished) + failed_stop, self._failed_stop = self._failed_stop, None + if failed_stop is not None: + self._finish_failed_stop(failed_stop) - def close_after_failure(self) -> None: - """Stop the live view after a drawing failure and say that the run goes on.""" - with self._lock: - had_live = self._live is not None + def _stop_live_after_failure(self, live) -> None: + """Stop the live view after a drawing failure and say that the run goes on. + + The full final frame could fail the same way, so Live keeps the last + frame it drew. Runs under the reporter lock and records the outcome in + the same lock hold, so the run's close() either stops Live itself or + finds the record. + """ try: - super().close_after_failure() + live.stop() except Exception: # A terminal that refused the redraw can refuse Live's stop too, # and with it the write that shows the cursor again. - if had_live: - with self._lock: - self._unfinished_stop = (threading.current_thread(), False) - raise - if had_live: - try: - # The last frame Live drew stays on screen with its stages - # still running, so explain why it no longer updates. - self._write_line(_DISPLAY_STOPPED_NOTICE) - except Exception: - logger.debug("Tier 3 progress stop notice failed", exc_info=True) - with self._lock: - self._unfinished_stop = (threading.current_thread(), True) + logger.debug("Tier 3 progress display stop failed", exc_info=True) + self._failed_stop = _FailedDisplayStop(stop_refused=True, notice_shown=False) + return + try: + # Live keeps the last frame it drew, with its stages still running, + # so explain why it no longer updates. + self._write_line(_DISPLAY_STOPPED_NOTICE) + except Exception: + logger.debug("Tier 3 progress stop notice failed", exc_info=True) + self._failed_stop = _FailedDisplayStop(stop_refused=False, notice_shown=False) + else: + self._failed_stop = _FailedDisplayStop(stop_refused=False, notice_shown=True) + + def _drop_refused_writes(self) -> None: + """Discard the output this thread's Rich console holds from refused writes. + + Rich keeps a refused write for its thread and sends it before that + thread's next one. A refused frame or stop starts by moving the cursor + up over the frame that was on screen when drawing failed, so sent any + later it would erase and overwrite whatever was printed since. A + thread that ended took its refused writes with it. + """ + try: + self._console.begin_capture() + self._console.end_capture() + except Exception: + logger.debug("Tier 3 progress refused output could not be dropped", exc_info=True) - def _finish_refused_stop(self, stopped_on: threading.Thread, notice_sent: bool) -> None: - """Show the cursor and the stop notice that the terminal refused after a drawing failure. + def _finish_failed_stop(self, failed_stop: _FailedDisplayStop) -> None: + """Show the cursor and the stop notice when the terminal refused them after a drawing failure. Runs on the thread that closes the run, once the terminal may take - writes again. Rich keeps a refused write for its thread and sends it - before that thread's next one; a thread that ended took its refused - writes with it. + writes again. """ + self._drop_refused_writes() try: - # Live hides the cursor while it draws and shows it again when it - # stops, so a refused stop leaves it hidden after the run. - self._console.show_cursor(True) - if not notice_sent or stopped_on is not threading.current_thread(): + if failed_stop.stop_refused: + # Live hides the cursor while it draws and shows it again when + # it stops, then ends the frame's last line. + self._console.show_cursor(True) + if self._console.is_terminal: + self._console.line() + if not failed_stop.notice_shown: self._write_line(_DISPLAY_STOPPED_LATE_NOTICE) except Exception: logger.debug("Tier 3 progress terminal restore failed", exc_info=True) diff --git a/tests/test_tier3_progress.py b/tests/test_tier3_progress.py index 15c6c4654..281cca827 100644 --- a/tests/test_tier3_progress.py +++ b/tests/test_tier3_progress.py @@ -1150,7 +1150,10 @@ def _assert_cursor_shown_and_one_stop_notice(output: str, notice: str) -> None: assert "\x1b[?25l" in output assert output.rfind("\x1b[?25h") > output.rfind("\x1b[?25l") assert output.count("Tier 3 progress display stopped after a drawing error") == 1 - assert notice in output + # The notice is a line of its own below the last frame, even when the + # terminal refused the stop that ends the frame's last line. + visible = output.replace("\x1b[?25h", "").replace("\x1b[?25l", "") + assert f"\n{notice}\n" in visible @pytest.mark.parametrize( @@ -1289,15 +1292,135 @@ def write(self, text: str) -> int: assert reporter.is_active is False assert rich_reporter._live is None stream.armed = False + # Once progress is off, other output (a logged warning, say) goes + # straight to the terminal below the last frame. + for number in range(1, 4): + stream.write(f"warning {number} printed after the display stopped\n") + printed_before_close = len(stream.getvalue()) finally: reporter.close() output = stream.getvalue() assert "failed" not in output assert "interrupted" not in output - # Rich sends this thread's refused writes again with its next one, so a - # refused notice is printed then, once, and a refused stop is followed by - # the late notice. - _assert_cursor_shown_and_one_stop_notice(output, _LATE_STOP_NOTICE if 2 in refused_writes else _STOP_NOTICE) + closing_output = output[printed_before_close:] + # Rich keeps this thread's refused writes and would send them with its + # next one. They move the cursor up over the frame that was on screen + # when drawing failed, so close() drops them instead of erasing the + # warnings, and prints the late notice in place of a refused one. + assert "\x1b[1A" not in closing_output + assert "\x1b[2K" not in closing_output + assert closing_output.endswith(f"{_LATE_STOP_NOTICE}\n") + if 2 in refused_writes: + assert "\x1b[?25h" in closing_output + _assert_cursor_shown_and_one_stop_notice(output, _LATE_STOP_NOTICE) + + +def test_run_end_close_during_a_refused_heartbeat_stop_shows_the_cursor(monkeypatch: pytest.MonkeyPatch) -> None: + from rich.console import Console + + progress = _progress_module() + monkeypatch.setenv("TERM", "xterm-256color") + uncaught: list[BaseException | None] = [] + monkeypatch.setattr(threading, "excepthook", lambda args: uncaught.append(args.exc_value)) + lock = _InterleavingLock() + closers: list[threading.Thread] = [] + + def close_the_run() -> None: + # The run ends while the heartbeat thread is still turning a failed + # display off: its stop was refused and it has let go of the lock. + closer = threading.Thread(target=reporter.close, name="run-end-close") + closers.append(closer) + closer.start() + closer.join(timeout=10) + + class NonBlockingTerminal(_TTYBuffer): + """Refuses every heartbeat-thread write while ``refusing`` is set.""" + + refusing = True + + def write(self, text: str) -> int: + if self.refusing and threading.current_thread().name == "tier3-progress-heartbeat": + if "\x1b[?25h" in text: + # Live's stop, which shows the cursor again. + lock.arm(close_the_run) + raise BlockingIOError(errno.EAGAIN, "write could not complete without blocking", 0) + return super().write(text) + + stream = NonBlockingTerminal() + rich_reporter = progress.RichProgressReporter(stream=stream, refresh_interval=0.05) + rich_reporter._lock = lock + rich_reporter._console = Console( + file=stream, + force_terminal=True, + legacy_windows=False, + width=120, + color_system=None, + ) + reporter = progress.safe_progress_reporter(rich_reporter) + reporter.start(_plan(progress)) + heartbeat = rich_reporter._thread + assert heartbeat is not None + reporter.emit(progress.ProgressEvent(stage="agent:codex", state="running", detail="evaluating")) + + heartbeat.join(timeout=10) + assert not heartbeat.is_alive() + assert len(closers) == 1 + assert not closers[0].is_alive() + stream.refusing = False + first_run = stream.getvalue() + _assert_cursor_shown_and_one_stop_notice(first_run, _LATE_STOP_NOTICE) + # Nothing of the failed run is left for the next one. + reporter.start(_plan(progress)) + reporter.close() + assert "display stopped" not in stream.getvalue()[len(first_run) :] + assert uncaught == [] + + +def test_a_new_run_without_close_carries_nothing_from_a_refused_stop(monkeypatch: pytest.MonkeyPatch) -> None: + from rich.console import Console + + progress = _progress_module() + monkeypatch.setenv("TERM", "xterm-256color") + + class NonBlockingTerminal(_TTYBuffer): + """Refuses every write while ``refusing`` is set.""" + + refusing = False + + def write(self, text: str) -> int: + if self.refusing: + raise BlockingIOError(errno.EAGAIN, "write could not complete without blocking", 0) + return super().write(text) + + stream = NonBlockingTerminal() + rich_reporter = progress.RichProgressReporter(stream=stream, refresh_interval=60) + rich_reporter._console = Console( + file=stream, + force_terminal=True, + legacy_windows=False, + width=120, + color_system=None, + ) + reporter = progress.safe_progress_reporter(rich_reporter) + reporter.start(_plan(progress)) + reporter.emit(progress.ProgressEvent(stage="agent:codex", state="running", detail="evaluating")) + stream.refusing = True + # The update and Live's stop are both refused. + reporter.emit(progress.ProgressEvent(stage="agent:codex", state="running", detail="still evaluating")) + assert reporter.is_active is False + stream.refusing = False + first_run = stream.getvalue() + + # The reporter is used again without the close() that ends the failed run. + rich_reporter.start(_plan(progress)) + rich_reporter.emit(progress.ProgressEvent(stage="agent:codex", state="complete", detail="agent finished")) + rich_reporter.close() + + second_run = stream.getvalue()[len(first_run) :] + assert "agent finished" in second_run + assert "still evaluating" not in second_run + assert "display stopped" not in second_run + assert second_run.rfind("\x1b[?25h") > second_run.rfind("\x1b[?25l") class _InterleavingLock: From 406de3a9a8835223d437af3a432db63643c8b891 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Mon, 9 Nov 2026 11:17:09 +0530 Subject: [PATCH 16/16] fix(tier3): show the cursor when Live's own stop of a refused first frame was refused Rich's Live.start() stops Live itself when its first frame fails, then raises. When the terminal refused that stop as well, the write that shows the cursor again stayed in the caller's Rich buffer. The stop that follows the drawing failure then had nothing left to do and raised nothing, so the record said the stop went through, and close() dropped the held write without showing the cursor. close() now also shows the cursor when the refused output it drops holds that write. No frame reached the terminal then, so it ends no line. Signed-off-by: Narendran Raghavan Co-Authored-By: Claude Opus 5.5 --- src/skillevaluator/tier3/harbor/progress.py | 18 ++++-- tests/test_tier3_progress.py | 65 +++++++++++++++++++++ 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/src/skillevaluator/tier3/harbor/progress.py b/src/skillevaluator/tier3/harbor/progress.py index 5afd63336..c6730e796 100644 --- a/src/skillevaluator/tier3/harbor/progress.py +++ b/src/skillevaluator/tier3/harbor/progress.py @@ -531,8 +531,8 @@ def _stop_live_after_failure(self, live) -> None: else: self._failed_stop = _FailedDisplayStop(stop_refused=False, notice_shown=True) - def _drop_refused_writes(self) -> None: - """Discard the output this thread's Rich console holds from refused writes. + def _drop_refused_writes(self) -> str: + """Discard the output this thread's Rich console holds from refused writes, and return it. Rich keeps a refused write for its thread and sends it before that thread's next one. A refused frame or stop starts by moving the cursor @@ -542,9 +542,10 @@ def _drop_refused_writes(self) -> None: """ try: self._console.begin_capture() - self._console.end_capture() + return self._console.end_capture() except Exception: logger.debug("Tier 3 progress refused output could not be dropped", exc_info=True) + return "" def _finish_failed_stop(self, failed_stop: _FailedDisplayStop) -> None: """Show the cursor and the stop notice when the terminal refused them after a drawing failure. @@ -552,7 +553,9 @@ def _finish_failed_stop(self, failed_stop: _FailedDisplayStop) -> None: Runs on the thread that closes the run, once the terminal may take writes again. """ - self._drop_refused_writes() + from rich.control import Control + + dropped = self._drop_refused_writes() try: if failed_stop.stop_refused: # Live hides the cursor while it draws and shows it again when @@ -560,6 +563,13 @@ def _finish_failed_stop(self, failed_stop: _FailedDisplayStop) -> None: self._console.show_cursor(True) if self._console.is_terminal: self._console.line() + elif str(Control.show_cursor(True)) in dropped: + # Live.start() stops Live itself when its first frame fails, + # so the stop above had nothing left to do. The terminal + # refused that earlier stop too, and its write that shows the + # cursor was just dropped. No frame reached the terminal, so + # there is no last line to end. + self._console.show_cursor(True) if not failed_stop.notice_shown: self._write_line(_DISPLAY_STOPPED_LATE_NOTICE) except Exception: diff --git a/tests/test_tier3_progress.py b/tests/test_tier3_progress.py index 281cca827..266d8553b 100644 --- a/tests/test_tier3_progress.py +++ b/tests/test_tier3_progress.py @@ -1423,6 +1423,71 @@ def write(self, text: str) -> int: assert second_run.rfind("\x1b[?25h") > second_run.rfind("\x1b[?25l") +@pytest.mark.parametrize("notice_refused", [True, False], ids=["notice-refused", "notice-accepted"]) +def test_refused_first_frame_and_stop_leave_the_cursor_shown( + monkeypatch: pytest.MonkeyPatch, + notice_refused: bool, +) -> None: + from rich.console import Console + from rich.live import Live + + progress = _progress_module() + monkeypatch.setenv("TERM", "xterm-256color") + + class NonBlockingTerminal(_TTYBuffer): + """Takes Live's hide-cursor write, then refuses the first frame and Live's own stop.""" + + armed = False + + def write(self, text: str) -> int: + refused = self.armed and "\x1b[?25l" not in text + if refused and (notice_refused or _STOP_NOTICE not in text): + raise BlockingIOError(errno.EAGAIN, "write could not complete without blocking", 0) + return super().write(text) + + stream = NonBlockingTerminal() + rich_reporter = progress.RichProgressReporter(stream=stream, refresh_interval=60) + rich_reporter._console = Console( + file=stream, + force_terminal=True, + legacy_windows=False, + width=120, + color_system=None, + ) + + def live_on_a_refusing_terminal(*args: Any, **kwargs: Any) -> Any: + # The plan lines above the frame are already printed. + stream.armed = True + return Live(*args, **kwargs) + + rich_reporter._live_factory = live_on_a_refusing_terminal + reporter = progress.safe_progress_reporter(rich_reporter) + try: + # Live.start() stops Live itself when its first frame fails, then + # raises. The terminal refuses that stop as well, so the cursor Live + # hid stays hidden, and Live is already stopped when progress turns off. + reporter.start(_plan(progress)) + assert reporter.is_active is False + assert rich_reporter._live is None + stream.armed = False + printed_before_close = len(stream.getvalue()) + finally: + reporter.close() + output = stream.getvalue() + _assert_cursor_shown_and_one_stop_notice(output, _LATE_STOP_NOTICE if notice_refused else _STOP_NOTICE) + # Nothing the terminal refused is sent when the run ends. + assert "\x1b[1A" not in output[printed_before_close:] + if notice_refused: + # No frame reached the terminal, so the late notice follows the plan + # lines without a blank line. + assert "Harbor Run Configuration" not in output + assert "\n\n" not in output.replace("\x1b[?25h", "").replace("\x1b[?25l", "") + else: + # The notice went out with the frame and the stop the terminal had + # refused just before, so the frame is on screen above it. + assert "Harbor Run Configuration" in output + + class _InterleavingLock: """A reentrant lock that runs a hook once, when the arming thread next releases it fully."""