Handle terminal investigation budgets without rejecting valid assessments

This commit is contained in:
Nico committed 2026-11-21 17:51:03 +01:00
1 parent 76e43f0f4d
commit 930cab243d
6 files changed
+2454 -2

No files matched your search

File diff suppressed because it is too large. Load diff
@@ -714,7 +714,11 @@ class Investigator:
else:
operation="testing.request_human" if next_action["executor"]=="human" else "testing.request_automated"
if operation not in context["budget_policy"]["action_costs"]:raise InvestigationError("INVESTIGATION_TEST_COST")
budget_apply(projected,{"operation":"reserve","hypothesis_id":hid,"action_id":self._action_id(state),"action":operation},context["budget_policy"])
# Settlement can legitimately end the account. The controller owns
# that transition; it must not reject the valid final assessment
# merely because the model also proposed another research action.
if projected['accounts'][hid]['status'] not in TERMINAL:
budget_apply(projected,{"operation":"reserve","hypothesis_id":hid,"action_id":self._action_id(state),"action":operation},context["budget_policy"])
def _upgrade_database_context(self,state,context,operation):
if (context.get('database_access_version') != 1 and not context.get('response_repair')
@@ -892,6 +896,12 @@ class Investigator:
assessment=decision["assessment"]
budget.settle(case_id,package_id,hid,previous["record"]["action_id"],semantic_score=assessment["semantic_score"],reason=assessment["reason"])
next_action=decision["next"];kind=next_action["kind"]
terminal_status=budget.snapshot(case_id,package_id).state['accounts'][hid]['status']
skipped_action = kind in {'tool','test'} and terminal_status in TERMINAL
if skipped_action:
# Keep the frozen response intact for auditing. Only execution is
# suppressed, after durable, idempotent settlement of the result.
kind='defer'
action_id=self._action_id(state)
if kind in {"tool","test"}:
operation=next_action["operation"] if kind=="tool" else "testing.request_human" if next_action["executor"]=="human" else "testing.request_automated"
@@ -959,7 +969,7 @@ class Investigator:
if snap.state["accounts"][hid]["status"] not in TERMINAL:
if kind=="reject":budget.reject(case_id,package_id,hid,reason=next_action["reason"])
else:budget.complete(case_id,package_id,hid,reason=next_action["reason"])
h["disposition"]=kind
h["disposition"]=snap.state['accounts'][hid]['status'] if snap.state['accounts'][hid]['status'] in TERMINAL else kind
if kind != 'recall' and context.get('prompt_version') not in {'investigation_project_v15','investigation_project_v16','investigation_project_v17','investigation_project_v18'}:
state.get('recalled_evidence', {}).pop(hid, None)
if kind != 'recall' and context['policy'].get('prompt_window_version') in {1,2}:
@@ -989,6 +999,8 @@ class Investigator:
if q["id"] in update["resolve_questions"]:q["resolved"]=True
for text in update["add_questions"]:h["questions"].append({"id":f"Q{len(h['questions'])+1:04d}","text":text,"resolved":False})
note={"kind":"assessment","text":update["note"],"llm_ref":active["llm_ref"]}
if skipped_action:
note['text'] += f" [Controller: proposed research not executed; {terminal_status}.]"
if 'causal_review' in update:
note.update(causal_review=copy.deepcopy(update['causal_review']),
requested_confidence=update['confidence'],effective_confidence=h['confidence'])
@@ -0,0 +1,5 @@
# BUG-000023: budget boundary misclassified as invalid response
Generation 282, revision 1, H1 iteration 21. H1 has 1 remaining unit and an awaiting-assessment action costing 10. Policy max_reward_bps=8000 caps its refund at 8, so no legal assessment can fund a new tool (minimum action cost 10). The controller projects settlement, obtains budget_exhausted, then rejects the proposed next action with BUDGET_TERMINAL. It fails to commit the valid pending assessment and transitions through three LLM correction attempts to INVALID_LLM_RESPONSES. This is controller budget/scheduling behavior, not a malformed reply or database outage. H2 and H3 retain 83 and 82 units. Expected behavior: safely settle pending evidence once, consolidate H1 without new research if needed, let the scheduler continue eligible hypotheses. Never reset the budget, turn exhaustion into causal refutation, or grant semantic refunds without evidence.
Implemented recovery: full response validation still applies, but no projected reservation is attempted after terminal settlement. Execution durably settles the pending result and suppresses the proposed tool/test when the account is terminal. The frozen response stays unchanged, the skipped execution is recorded in the assessment note, and provisional lean observations are consolidated through the existing scheduler. Terminal budget disposition survives final consolidation. Regression coverage includes this saved ledger at semantic scores 0, 20, 40 and 100, and complete bounded-loop runs with a crash immediately after durable settlement.
@@ -0,0 +1,322 @@
{
"budget": {
"accounts": {
"H1": {
"actions": {
"INV-1-H1-1": {
"action": "project.query",
"assessment_reason": "The table schema listing only catalogs table names matching 'item' without examining item 60678 or associated spell scripts.",
"cost": 10,
"evidence_sha256": "5ce1005b912a48bbc394400e12a76fd7a834fb487ab758f778f900ad44831316",
"failed": false,
"information_score": 25,
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000003.json",
"reward": 2,
"semantic_score": 25,
"status": "settled"
},
"INV-1-H1-12": {
"action": "project.query",
"assessment_reason": "Querying cata_hotfixes.item_sparse for ID 60678 returned no rows, indicating item 60678 is either not in this table or stored under a different column/table structure.",
"cost": 10,
"evidence_sha256": "e1452bb8dea90e8adde1a5f26361f0ad824443e78ce0dd82172218421b3af983",
"failed": false,
"information_score": 40,
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000047.json",
"reward": 3,
"semantic_score": 40,
"status": "settled"
},
"INV-1-H1-14": {
"action": "project.query",
"assessment_reason": "Line 926 in 114_western_plaguelands.sql confirms creature 44360 has aura 82880 (Shadowflame State), but does not reveal item 60678 or its spell ID. Searching the codebase for item 60678 will identify how the grenade item or its spell is defined.",
"cost": 10,
"evidence_sha256": "67c42ccc8d9e1646c8a795c32f399de6461f75ba3e11deb925062a46a8f319c1",
"failed": false,
"information_score": 40,
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000050.json",
"reward": 3,
"semantic_score": 40,
"status": "settled"
},
"INV-1-H1-15": {
"action": "project.query",
"assessment_reason": "Search results on 60678 in git history did not immediately identify the item definition on page 0; recalling quest_template record E000006 will verify quest items and objective details for quest 26922.",
"cost": 10,
"evidence_sha256": "6638e56f0c505e309872f7926b1aadd195bbd55e4409218da0dd7b5c6b253c49",
"failed": false,
"information_score": 45,
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000053.json",
"reward": 3,
"semantic_score": 45,
"status": "settled"
},
"INV-1-H1-17": {
"action": "project.query",
"assessment_reason": "E000018 confirmed cata_hotfixes.item_sparse exists and began listing columns, but was truncated before reaching the item spell columns.",
"cost": 10,
"evidence_sha256": "4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945",
"failed": false,
"information_score": 0,
"novelty_score": 0,
"result_ref": "analysis/budgets/0001/events/00000056.json",
"reward": 0,
"semantic_score": 75,
"status": "settled"
},
"INV-1-H1-2": {
"action": "project.query",
"assessment_reason": "PROJECT_DATABASE_TABLE_UNKNOWN",
"cost": 10,
"failed": true,
"information_score": 0,
"reward": 0,
"semantic_score": 0,
"status": "settled"
},
"INV-1-H1-2-recovery-1": {
"action": "project.query",
"assessment_reason": "E000010 identified item-related tables including cata_world.item_script_names and cata_hotfixes.item_sparse.",
"cost": 10,
"evidence_sha256": "4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945",
"failed": false,
"information_score": 0,
"novelty_score": 0,
"result_ref": "analysis/budgets/0001/events/00000032.json",
"reward": 0,
"semantic_score": 50,
"status": "settled"
},
"INV-1-H1-20": {
"action": "project.query",
"cost": 10,
"evidence_sha256": "5b15b0f4fd0dd130a792a2d320ecc50c956e23f1f675134b68aa934a800fb632",
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000059.json",
"status": "awaiting_assessment"
},
"INV-1-H1-3": {
"action": "project.query",
"assessment_reason": "Retrieved schema for item_script_names with primary key Id and ScriptName column.",
"cost": 10,
"evidence_sha256": "02b6d1ac5f61550b54c612aecaf3b6179c3fb27c7cb79e99830646fd38f9ac90",
"failed": false,
"information_score": 85,
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000035.json",
"reward": 6,
"semantic_score": 85,
"status": "settled"
},
"INV-1-H1-4": {
"action": "project.query",
"assessment_reason": "Confirmed item 60678 has no registered script in item_script_names, but this does not verify whether the item triggers a spell that requires spell_script_names handling.",
"cost": 10,
"evidence_sha256": "36c50a23dd511bae9ac2ccfffc5477e3457b862108fff660b7ec476a027e1812",
"failed": false,
"information_score": 45,
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000038.json",
"reward": 3,
"semantic_score": 45,
"status": "settled"
},
"INV-1-H1-6": {
"action": "project.query",
"assessment_reason": "Source search for 60678 yielded unrelated coordinates and broadcast text in historical SQL updates. Checking cata_hotfixes.item_sparse will directly provide the spell ID and properties associated with item 60678.",
"cost": 10,
"evidence_sha256": "09fe37930f201790e118dc5f22459753b164e5d0e3d7f88ba2199b0ed7681914",
"failed": false,
"information_score": 20,
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000041.json",
"reward": 1,
"semantic_score": 20,
"status": "settled"
},
"INV-1-H1-7": {
"action": "project.query",
"assessment_reason": "The schema query confirms that cata_hotfixes.item_sparse exists and is accessible, but the fragment cuts off before spell-related columns are displayed.",
"cost": 10,
"evidence_sha256": "4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945",
"failed": false,
"information_score": 0,
"novelty_score": 0,
"result_ref": "analysis/budgets/0001/events/00000044.json",
"reward": 0,
"semantic_score": 45,
"status": "settled"
}
},
"initial": 100,
"low_information_steps": 1,
"remaining": 1,
"rewarded": 21,
"spent": 120,
"status": "investigating"
},
"H2": {
"actions": {
"INV-1-H2-1": {
"action": "project.query",
"assessment_reason": "The creature spawn context confirms that creature 44329 has 0 rows in the creature spawn table, validating the absence of static spawns.",
"cost": 10,
"evidence_sha256": "28dff3c9925c9ae043ab572897e037402ac54217d273e677ba4885d96c38ff88",
"failed": false,
"information_score": 75,
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000005.json",
"reward": 6,
"semantic_score": 75,
"status": "settled"
},
"INV-1-H2-2": {
"action": "project.query",
"assessment_reason": "smart_scripts query confirmed neither creature 44360 nor 44329 has SmartAI scripting defined.",
"cost": 10,
"evidence_sha256": "7dcfb2f4adabe40f0e00eac145dcae09243c8f8163977412411d57d34ebb3ca4",
"failed": false,
"information_score": 85,
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000012.json",
"reward": 6,
"semantic_score": 85,
"status": "settled"
},
"INV-1-H2-3": {
"action": "project.query",
"assessment_reason": "Partial search results for 44360 show SQL updates configuring unit_flags and an aura/addon (82880), but more pages or targeted queries are needed to inspect quest details.",
"cost": 10,
"evidence_sha256": "ea2e60c77197d41f6f7318d90858e9b931cd60225d66c56725d817c2a608dcbd",
"failed": false,
"information_score": 65,
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000015.json",
"reward": 5,
"semantic_score": 65,
"status": "settled"
},
"INV-1-H2-4": {
"action": "project.query",
"assessment_reason": "E000006 confirms quest 26922 requires 1 kill of creature 44360 (Scourge Bone Animus Bunny) and 5 kills of creature 44329 (Stickbone Berserker).",
"cost": 10,
"evidence_sha256": "f7b6b03cad31f791569974f1dc55423059f3bd0141b5a47f69f6f3ebb90b7bbb",
"failed": false,
"information_score": 75,
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000018.json",
"reward": 6,
"semantic_score": 75,
"status": "settled"
}
},
"initial": 100,
"low_information_steps": 0,
"remaining": 83,
"rewarded": 23,
"spent": 40,
"status": "investigating"
},
"H3": {
"actions": {
"INV-1-H3-1": {
"action": "project.query",
"assessment_reason": "Directly confirms creature_template attributes for entry 44360, showing flags and blank script fields.",
"cost": 10,
"evidence_sha256": "cba7755e2b00cb5c67eb0158e2e31fde1510e5dfe61fa727f9c44337c5343258",
"failed": false,
"information_score": 85,
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000007.json",
"reward": 6,
"semantic_score": 85,
"status": "settled"
},
"INV-1-H3-2": {
"action": "project.query",
"assessment_reason": "smart_scripts query for 44360 returned no rows, proving creature 44360 has no SmartAI script entries.",
"cost": 10,
"evidence_sha256": "de6516394c2854ab1e79817c5eafd7805299a4a1fd0104263d1a7695e87bae61",
"failed": false,
"information_score": 85,
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000021.json",
"reward": 6,
"semantic_score": 85,
"status": "settled"
},
"INV-1-H3-3": {
"action": "project.query",
"assessment_reason": "Retrieved list of tables matching 'item', showing item definitions are divided between cata_hotfixes and cata_world.",
"cost": 10,
"evidence_sha256": "4143046d447d15a99af4c955671873aa9b0d79894d0668ca039d5c37f20952a8",
"failed": false,
"information_score": 70,
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000024.json",
"reward": 5,
"semantic_score": 70,
"status": "settled"
},
"INV-1-H3-4": {
"action": "project.query",
"assessment_reason": "E000009 provides the schema for cata_hotfixes.item_sparse, but the columns listing spell triggers and effects are truncated on page 0.",
"cost": 10,
"evidence_sha256": "41e758ef162f977f692ad7c67ab372f0ea597e7a3cda8432a0e56c2547b17c49",
"failed": false,
"information_score": 65,
"novelty_score": 100,
"result_ref": "analysis/budgets/0001/events/00000027.json",
"reward": 5,
"semantic_score": 65,
"status": "settled"
}
},
"initial": 100,
"low_information_steps": 0,
"remaining": 82,
"rewarded": 22,
"spent": 40,
"status": "investigating"
}
},
"seen_evidence": [
"5ce1005b912a48bbc394400e12a76fd7a834fb487ab758f778f900ad44831316",
"28dff3c9925c9ae043ab572897e037402ac54217d273e677ba4885d96c38ff88",
"cba7755e2b00cb5c67eb0158e2e31fde1510e5dfe61fa727f9c44337c5343258",
"7dcfb2f4adabe40f0e00eac145dcae09243c8f8163977412411d57d34ebb3ca4",
"ea2e60c77197d41f6f7318d90858e9b931cd60225d66c56725d817c2a608dcbd",
"f7b6b03cad31f791569974f1dc55423059f3bd0141b5a47f69f6f3ebb90b7bbb",
"de6516394c2854ab1e79817c5eafd7805299a4a1fd0104263d1a7695e87bae61",
"4143046d447d15a99af4c955671873aa9b0d79894d0668ca039d5c37f20952a8",
"41e758ef162f977f692ad7c67ab372f0ea597e7a3cda8432a0e56c2547b17c49",
"4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945",
"02b6d1ac5f61550b54c612aecaf3b6179c3fb27c7cb79e99830646fd38f9ac90",
"36c50a23dd511bae9ac2ccfffc5477e3457b862108fff660b7ec476a027e1812",
"09fe37930f201790e118dc5f22459753b164e5d0e3d7f88ba2199b0ed7681914",
"e1452bb8dea90e8adde1a5f26361f0ad824443e78ce0dd82172218421b3af983",
"67c42ccc8d9e1646c8a795c32f399de6461f75ba3e11deb925062a46a8f319c1",
"6638e56f0c505e309872f7926b1aadd195bbd55e4409218da0dd7b5c6b253c49",
"5b15b0f4fd0dd130a792a2d320ecc50c956e23f1f675134b68aa934a800fb632"
]
},
"policy": {
"action_costs": {
"testing.request_human": 40
},
"default_action_cost": 10,
"format": "viano-budget-policy",
"format_version": 1,
"low_information_threshold": 20,
"max_low_information_steps": 3,
"max_reward_bps": 8000,
"new_evidence_score": 100,
"unit": "investigation_units"
},
"hypothesis_id": "H1",
"pending_action_id": "INV-1-H1-20"
}
@@ -0,0 +1,69 @@
[
{
"llm_ref": "llm/operations/427143f74021f8dd19add9b5c55bb5bcfa654fefe416fa699ff5e79937fd419c/round-0001.json",
"controller_code": "BUDGET_TERMINAL",
"answer": {
"assessment": {
"reason": "Querying cata_hotfixes.item_sparse for ID 60678 yielded zero rows, indicating the item is either not present in hotfixes or defined elsewhere.",
"semantic_score": 40
},
"next": {
"arguments": {
"case_sensitive": false,
"kind": "source.search",
"limit": 10,
"offset": 0,
"path_prefix": "",
"text": "60678"
},
"kind": "tool",
"operation": "project.query"
},
"observation": "cata_hotfixes.item_sparse contains no record for ID 60678; searching repository codebase for references to item 60678 to determine its spell or script association."
}
},
{
"llm_ref": "llm/operations/74c3baa510ef3a806f27f3b32f3a47eaaaa0faf5598e3b3f45e4dbcc6558d423/round-0001.json",
"controller_code": "BUDGET_TERMINAL",
"answer": {
"assessment": {
"reason": "cata_hotfixes.item_sparse returned 0 rows for item ID 60678, indicating the item entry is not stored under that ID in item_sparse or item definitions reside elsewhere.",
"semantic_score": 20
},
"next": {
"arguments": {
"case_sensitive": false,
"kind": "source.search",
"limit": 10,
"offset": 0,
"path_prefix": "",
"text": "60678"
},
"kind": "tool",
"operation": "project.query"
},
"observation": "cata_hotfixes.item_sparse contains no record for item ID 60678. Searching the codebase for references to item 60678 or quest 26922 to identify the spell or script used by the grenade."
}
},
{
"llm_ref": "llm/operations/2bffb8b5542053fd6b4819175e76af0034dbaa63dfd555607c997e7b594e689f/round-0001.json",
"controller_code": "BUDGET_TERMINAL",
"answer": {
"assessment": {
"reason": "Query for ID 60678 in cata_hotfixes.item_sparse returned 0 rows, meaning item 60678 is not in cata_hotfixes.item_sparse or stored under another item table.",
"semantic_score": 40
},
"next": {
"arguments": {
"kind": "database.tables",
"limit": 20,
"offset": 0,
"text": "item"
},
"kind": "tool",
"operation": "project.query"
},
"observation": "cata_hotfixes.item_sparse returned no rows for ID 60678. Listing item tables in cata_world to locate where item definitions are stored."
}
}
]
+71
View File
@@ -229,3 +229,74 @@ def test_v2_completion_after_checkpoints(tool_case):
result = run(loop_for(tool_case, Finish()), steps=20)
assert result.status == 'COMPLETED'
assert PackageValidator().validate(result.package).valid
@pytest.mark.parametrize('crash_after_settlement',[False,True])
def test_terminal_settlement_preserves_observation_and_skips_followup(tool_case,monkeypatch,crash_after_settlement):
from viano_bug_analysis.budget import BudgetConfig
class Continue(Adapter):
async def generate(self, config, request, **kwargs):
body=json.loads(request['messages'][1]['content'])
if body['task'] in {'startup_choose_query','review_initial_hypotheses'}:
return await super().generate(config,request,**kwargs)
self.calls.append(body)
previous=body['input']['previous_result']
assessment={'semantic_score':50,'reason':'Scoped result assessed.'} if previous else None
if body['task']=='investigate_one_step':
out={'assessment':assessment,'observation':'Preserve this last observation.',
'next':{'kind':'tool','operation':'project.query','arguments':rows()}}
else:
out={'assessment':assessment,'confidence':'plausible','findings':[],
'uncertainties':['Cause remains unconfirmed.'],'next_question':None,
'retire':[],'next':{'kind':'finish','reason':'No further funded research.'}}
return ProviderResponse(out,'fixture',100,50)
adapter=Continue()
config=BudgetConfig(default_action_cost=40)
loop=loop_for(tool_case,adapter)
loop.config=InvestigationConfig(lean_loop=True,lean_protocol=2,startup_batch_review=True,lean_checkpoint_steps=0,
prompt_window_version=2,response_recovery_version=1)
loop.budget_config=config
if crash_after_settlement:
original=BudgetManager.settle
def interrupted(manager,*args,**kwargs):
result=original(manager,*args,**kwargs)
if result.state['accounts'][args[2]]['status']=='budget_exhausted':
raise RuntimeError('simulated crash after durable settlement')
return result
with monkeypatch.context() as patch:
patch.setattr(BudgetManager,'settle',interrupted)
with pytest.raises(InvestigationError,match='INVESTIGATION_INPUT'):
run(loop,steps=30)
result=run(loop,steps=30)
assert result.status=='COMPLETED'
accounts=BudgetManager(tool_case[0],config).snapshot(*CASE).state['accounts']
for account in accounts.values():
assert account['status']=='budget_exhausted'
assert 2 <= len(account['actions']) <= 3
assert all(a['status']=='settled' for a in account['actions'].values())
assert all(h['invalid_responses']==0 and h['disposition']=='budget_exhausted'
for h in state(result)['hypotheses'].values())
assert all(any('proposed research not executed; budget_exhausted' in n['text'] for n in h['notes'])
for h in state(result)['hypotheses'].values())
checkpoints=[b for b in adapter.calls if b['task']=='consolidate_investigation_session']
assert len(checkpoints)==3
assert all('Preserve this last observation.' in json.dumps(b) for b in checkpoints)
count=len(adapter.calls)
assert run(loop).package==result.package and len(adapter.calls)==count
assert PackageValidator().validate(result.package).valid
@pytest.mark.parametrize('score',[0,20,40,100])
def test_bug23_saved_pending_result_always_exhausts_budget(score):
from viano_bug_analysis.budget.engine import apply
fixture=Path(__file__).parent/'fixtures/llm_rejections/20261121/bug23-budget-terminal/budget-context.json'
context=json.loads(fixture.read_text(encoding='utf-8'))
before=copy.deepcopy(context['budget'])
after=apply(before,{'operation':'settle','hypothesis_id':context['hypothesis_id'],
'action_id':context['pending_action_id'],'semantic_score':score,'reason':'Regression assessment'},context['policy'])
account=after['accounts']['H1']
assert account['status']=='budget_exhausted'
assert 1 <= account['remaining'] <= 9
assert account['actions'][context['pending_action_id']]['status']=='settled'
assert after['accounts']['H2']==before['accounts']['H2']
assert after['accounts']['H3']==before['accounts']['H3']