Skip to content

Commit 22e722f

Browse files
authored
Merge pull request #226 from FluffyAIcode/AgentMemory/strategy-budget-defer-0721
Defer oversized Strategy replans without stopping proof
2 parents 69e4b09 + a42dd8e commit 22e722f

3 files changed

Lines changed: 56 additions & 21 deletions

File tree

‎autoresearch/prefill/program.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ Normal iterations use the deterministic host candidate and do not call the
4949
Strategy model. Invoke Strategy Gemma only after three consecutive
5050
non-progressing runs, after a falsified branch, or via an explicit CLI/trigger
5151
file request.
52+
If an optional Strategy replan exceeds its lossless Prefill budget, defer the
53+
replan and continue immediately with the deterministic host candidate. Never
54+
truncate the Strategy prompt and never stop the GAN proof loop for this
55+
control-plane admission failure.
5256
An unresolved Critic verdict must isolate one strictly smaller missing lemma;
5357
the host records that lemma as a deduplicated child obligation. Completed GAN
5458
runs, transcripts, checkpoints, and ledger updates remain durable even when the

‎autoresearch/prefill/supervisor.py‎

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
)
3333

3434

35+
class StrategyPrefillBudgetExceeded(ValueError):
36+
def __init__(self, token_count: int, max_tokens: int) -> None:
37+
self.token_count = int(token_count)
38+
self.max_tokens = int(max_tokens)
39+
super().__init__(
40+
"Strategy Prefill token budget exceeded without truncation: "
41+
f"{self.token_count} > {self.max_tokens}",
42+
)
43+
44+
3545
def _json_request(url: str) -> dict:
3646
with urllib.request.urlopen(url, timeout=10) as response:
3747
return json.load(response)
@@ -659,9 +669,9 @@ def propose_candidate(
659669
enable_thinking=False,
660670
)
661671
if len(ids) > max_prefill_tokens:
662-
raise ValueError(
663-
"Strategy Prefill token budget exceeded without truncation: "
664-
f"{len(ids)} > {max_prefill_tokens}",
672+
raise StrategyPrefillBudgetExceeded(
673+
len(ids),
674+
max_prefill_tokens,
665675
)
666676
generated: list[int] = []
667677
print(
@@ -1072,25 +1082,36 @@ def run_iteration(args, iteration: int) -> dict:
10721082
f"mode=gemma trigger={trigger_reason}",
10731083
flush=True,
10741084
)
1075-
proposed = propose_candidate(
1076-
address=args.address,
1077-
tokenizer_id=args.tokenizer_id,
1078-
program=program,
1079-
current=current,
1080-
results_text=(
1081-
results_path.read_text() if results_path.exists() else ""
1082-
),
1083-
ledger=ledger_data,
1084-
max_prefill_tokens=args.strategy_max_prefill_tokens,
1085-
)
1086-
if proposed["target_obligation_id"] not in _pending_leaf_ids(
1087-
ledger_data,
1088-
):
1089-
raise ValueError(
1090-
"strategy agent targeted a non-leaf proof obligation",
1085+
try:
1086+
proposed = propose_candidate(
1087+
address=args.address,
1088+
tokenizer_id=args.tokenizer_id,
1089+
program=program,
1090+
current=current,
1091+
results_text=(
1092+
results_path.read_text()
1093+
if results_path.exists() else ""
1094+
),
1095+
ledger=ledger_data,
1096+
max_prefill_tokens=args.strategy_max_prefill_tokens,
1097+
)
1098+
if proposed["target_obligation_id"] not in _pending_leaf_ids(
1099+
ledger_data,
1100+
):
1101+
raise ValueError(
1102+
"strategy agent targeted a non-leaf proof obligation",
1103+
)
1104+
if trigger_reason == "manual-trigger-file":
1105+
trigger_file.unlink(missing_ok=True)
1106+
except StrategyPrefillBudgetExceeded as exc:
1107+
strategy_mode = "host_strategy_deferred"
1108+
proposed = build_host_candidate(current, ledger_data)
1109+
print(
1110+
"[autoresearch] phase=strategy-deferred-budget "
1111+
f"tokens={exc.token_count} max={exc.max_tokens} "
1112+
f"fallback=deterministic-host",
1113+
flush=True,
10911114
)
1092-
if trigger_reason == "manual-trigger-file":
1093-
trigger_file.unlink(missing_ok=True)
10941115
else:
10951116
strategy_mode = "host"
10961117
proposed = build_host_candidate(current, ledger_data)

‎tests/inference_engine/bench/test_autoresearch_supervisor.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
render_candidate,
1111
should_keep,
1212
StrategyPrefillHeartbeat,
13+
StrategyPrefillBudgetExceeded,
1314
strategy_trigger_reason,
1415
_extract_json,
1516
_pending_leaf_ids,
@@ -397,6 +398,13 @@ def test_strategy_is_triggered_only_by_events(tmp_path):
397398
) == "manual-trigger-file"
398399

399400

401+
def test_strategy_budget_error_preserves_exact_admission_counts():
402+
error = StrategyPrefillBudgetExceeded(11935, 8448)
403+
assert error.token_count == 11935
404+
assert error.max_tokens == 8448
405+
assert "without truncation: 11935 > 8448" in str(error)
406+
407+
400408
def test_strategy_state_keeps_complete_active_ancestry_only():
401409
ledger = {"obligations": [
402410
{
@@ -585,6 +593,8 @@ def test_supervisor_preserves_runtime_and_cache_across_iterations():
585593
assert "phase=runtime-health-check" in body
586594
assert "phase=deterministic-candidate" in body
587595
assert "mode=gemma trigger=" in body
596+
assert "except StrategyPrefillBudgetExceeded" in body
597+
assert "phase=strategy-deferred-budget" in body
588598
assert "if not gan_completed:" in body
589599
assert "phase=completed-run-preserved" in body
590600
assert "deploy_candidate" not in source

0 commit comments

Comments
 (0)