|
32 | 32 | ) |
33 | 33 |
|
34 | 34 |
|
| 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 | + |
35 | 45 | def _json_request(url: str) -> dict: |
36 | 46 | with urllib.request.urlopen(url, timeout=10) as response: |
37 | 47 | return json.load(response) |
@@ -659,9 +669,9 @@ def propose_candidate( |
659 | 669 | enable_thinking=False, |
660 | 670 | ) |
661 | 671 | 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, |
665 | 675 | ) |
666 | 676 | generated: list[int] = [] |
667 | 677 | print( |
@@ -1072,25 +1082,36 @@ def run_iteration(args, iteration: int) -> dict: |
1072 | 1082 | f"mode=gemma trigger={trigger_reason}", |
1073 | 1083 | flush=True, |
1074 | 1084 | ) |
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, |
1091 | 1114 | ) |
1092 | | - if trigger_reason == "manual-trigger-file": |
1093 | | - trigger_file.unlink(missing_ok=True) |
1094 | 1115 | else: |
1095 | 1116 | strategy_mode = "host" |
1096 | 1117 | proposed = build_host_candidate(current, ledger_data) |
|
0 commit comments