diff --git a/autoresearch/prefill/supervisor.py b/autoresearch/prefill/supervisor.py index b6046c6..0d4fb22 100644 --- a/autoresearch/prefill/supervisor.py +++ b/autoresearch/prefill/supervisor.py @@ -569,11 +569,20 @@ def _emit(self) -> None: ).get("prefill", {}) except Exception: return - total = self._delta(current, "remote_job_tokens_total") - computed = self._delta(current, "remote_job_tokens_computed") + new_remote_jobs = self._delta(current, "remote_jobs") + if new_remote_jobs: + # These two fields are gauges for the current job, not cumulative + # counters. Subtracting the previous same-length job makes a retry + # look permanently stuck at 0/0. + total = int(current.get("remote_job_tokens_total", 0)) + computed = int(current.get("remote_job_tokens_computed", 0)) + else: + total = 0 + computed = 0 state = ( computed, total, + new_remote_jobs, self._delta(current, "remote_hits"), self._delta(current, "tokens_reused"), ) @@ -583,7 +592,7 @@ def _emit(self) -> None: percent = min(100.0, 100.0 * computed / total) print( f"[autoresearch] Strategy Prefill: {computed}/{total} tokens " - f"({percent:.1f}%) · remote_hits={state[2]} reused={state[3]}", + f"({percent:.1f}%) · remote_hits={state[3]} reused={state[4]}", flush=True, ) diff --git a/tests/inference_engine/bench/test_autoresearch_supervisor.py b/tests/inference_engine/bench/test_autoresearch_supervisor.py index 1a7df9b..6d17e0a 100644 --- a/tests/inference_engine/bench/test_autoresearch_supervisor.py +++ b/tests/inference_engine/bench/test_autoresearch_supervisor.py @@ -397,23 +397,25 @@ def test_runtime_health_check_is_read_only(monkeypatch): def test_strategy_prefill_heartbeat_reports_delta(monkeypatch, capsys): heartbeat = StrategyPrefillHeartbeat(interval_s=0.01) heartbeat._baseline = { - "remote_job_tokens_total": 100, - "remote_job_tokens_computed": 100, + "remote_jobs": 10, + "remote_job_tokens_total": 300, + "remote_job_tokens_computed": 300, "remote_hits": 2, "tokens_reused": 20, } monkeypatch.setattr( "autoresearch.prefill.supervisor._json_request", lambda _url: {"prefill": { + "remote_jobs": 11, "remote_job_tokens_total": 300, - "remote_job_tokens_computed": 228, + "remote_job_tokens_computed": 128, "remote_hits": 3, "tokens_reused": 84, }}, ) heartbeat._emit() output = capsys.readouterr().out - assert "128/200 tokens (64.0%)" in output + assert "128/300 tokens (42.7%)" in output assert "remote_hits=1 reused=64" in output