Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions autoresearch/prefill/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
Expand All @@ -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,
)

Expand Down
10 changes: 6 additions & 4 deletions tests/inference_engine/bench/test_autoresearch_supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Loading