From 76e43f0f4ddc7fa238a9ea4bf0ca9888cf05e6ac Mon Sep 17 00:00:00 2001 From: Nitsu45 Date: Fri, 20 Nov 2026 11:11:26 +0100 Subject: [PATCH] Preserve database namespaces in bounded investigation context --- .../bug23-database-access-context-20261120.md | 51 + .../bug23-blocked-g00000187-20261120.json | 1413 +++++++++++++++++ .../analysis/investigation_compact.py | 3 + .../analysis/investigation_lean.py | 2 +- .../analysis/investigation_window.py | 5 +- .../analysis/investigator.py | 18 + .../analysis/tool_guidance.py | 42 +- .../investigation-context-v1.schema.json | 3 + .../analysis.md | 3 + .../database-context.json | 81 + .../parsed-answer.json | 15 + tests/test_database_access_context.py | 135 ++ 12 files changed, 1767 insertions(+), 4 deletions(-) create mode 100644 docs/test-results/bug23-database-access-context-20261120.md create mode 100644 docs/test-results/token-usage/bug23-blocked-g00000187-20261120.json create mode 100644 tests/fixtures/llm_rejections/20261120/bug23-unqualified-hotfix-table/analysis.md create mode 100644 tests/fixtures/llm_rejections/20261120/bug23-unqualified-hotfix-table/database-context.json create mode 100644 tests/fixtures/llm_rejections/20261120/bug23-unqualified-hotfix-table/parsed-answer.json create mode 100644 tests/test_database_access_context.py diff --git a/docs/test-results/bug23-database-access-context-20261120.md b/docs/test-results/bug23-database-access-context-20261120.md new file mode 100644 index 0000000..c34db2d --- /dev/null +++ b/docs/test-results/bug23-database-access-context-20261120.md @@ -0,0 +1,51 @@ +# BUG-000023: Datenbankzuordnung im begrenzten Prompt + +Generation 187 wurde nach einer ausdrücklich freigegebenen Antwort erneut +blockiert. Die Antwort wechselte von item_template zu item_sparse, verwendete +aber keinen Datenbanknamen. Das Tool löste die Anfrage daher in cata_world auf. +Der vorherige erfolgreiche Zugriff in H3 betraf cata_hotfixes.item_sparse. +Die tatsächlich gesendete begrenzte Promptansicht enthielt weder die +Standard-/Zusatzdatenbanken noch eine entsprechende Qualifizierungsregel. +Der gespeicherte Korrekturkontext war außerdem vor Einführung der gemeinsamen +Tabellenhinweise erzeugt worden. Die Sperre selbst war daher korrekt; die +Kontextübergabe war unvollständig. + +Neue SQL-Untersuchungskontexte erhalten database_access_version=1. Ihre +Modellansicht enthält ausschließlich den Namen der Standarddatenbank, bis zu +16 konfigurierte Datenbanknamen mit Auslassungszähler und bis zu zwölf zuvor +gelesene Tabellen als vollständig qualifizierte Namen mit Beleg-ID. Die +Tabellenhinweise werden aus bereits archivierten erfolgreichen direkten +Datenbankabfragen aller Hypothesen abgeleitet. Snapshot, Standarddatenbank, +explizite Auswahl und erlaubte Tabellen müssen zur aktuellen Bindung passen. +Es werden keine Verbindungsadressen, Nutzernamen, Zugangsdaten, Tabelleninhalte +oder vollständigen Schemas zusätzlich übertragen. + +Die Metadaten überstehen kompakte, schlanke und begrenzte Ansichten. Die +Qualifizierungsregel wird ausdrücklich an die endgültigen Systemanweisungen +der begrenzten Ansicht angehängt, statt sich auf vorherige, später ersetzte +Tool-Guidance zu verlassen. Frühere erfolgreiche Abfragen garantieren keine +aktuelle Verfügbarkeit und stellen keinen vollständigen Tabellenkatalog dar. +Unqualifizierte Tabellen verwenden weiterhin ausschließlich die Standard-DB; +der Controller verändert die angefragte Datenbank niemals automatisch. + +Bei Wiederaufnahme eines älteren Kontexts wird nur vor einem noch nicht +gespeicherten Request ein neuer Kontext mit dem Versionsmarker und den aktuellen +gemeinsamen Fehlerhinweisen geschrieben. Alte Kontext- und Requestdateien bleiben +unverändert. Bereits gespeicherte Requests behalten ihre ursprüngliche Ansicht, +auch wenn ihr Aufruf nach einem Prozessabbruch erst noch verarbeitet werden muss. +Untersuchungsbudgets und Fehlergrenzen werden nicht zurückgesetzt. + +111 lokale Tests zu Datenbankkontext, Tool-Guidance, Window-v2-Verträgen, +Promptfenstern, Mehrdatenbankzugriff, Antwortreparatur und Betreiberfreigabe +bestanden. Der neue Regressionstest verwendet einen kuratierten Ausschnitt der +tatsächlichen BUG-23-Bindung und des erfolgreichen Schemaabrufs E000009. Er +prüft die endgültigen kurzen und konsolidierenden Requests, einschließlich +20.000-Zeichen-Grenze, statt nur eine Zwischenansicht zu testen. Weitere Prüfungen +decken unzulässige Datenbanken, abweichende Snapshots, Wiederaufnahme eines alten +Korrekturkontexts sowie einen Abbruch nach Speichern eines alten Requests ohne +doppelte Modellanfrage ab. Keine kostenpflichtigen LLM-Aufrufe. + +Die Verbrauchsbilanz bis Generation 187 liegt separat unter +token-usage/bug23-blocked-g00000187-20261120.json. Der frühere Snapshot bleibt +erhalten. Der kleine Ablehnungsfall und das für die Regression erforderliche +Datenbank-Metadatenfragment liegen im kuratierten Fehlerkorpus 20261120. diff --git a/docs/test-results/token-usage/bug23-blocked-g00000187-20261120.json b/docs/test-results/token-usage/bug23-blocked-g00000187-20261120.json new file mode 100644 index 0000000..a468adb --- /dev/null +++ b/docs/test-results/token-usage/bug23-blocked-g00000187-20261120.json @@ -0,0 +1,1413 @@ +{ + "case_id": "BUG-000023", + "package_id": "api-3e26d1d655b21d2f7272d66be0badf3794639e7be28b73bb61d5f6fab24912e6", + "analysis_revision": 1, + "package_generation": 187, + "package_sha256": "6cdc022d33038abc78f4b94a3fdc657df38a6ba932a54425243edbd23c386a23", + "snapshot_date": "2026-11-20", + "state": "BLOCKED", + "routing": { + "destination": "inbox", + "reason": "INVALID_LLM_RESPONSES", + "retry_count": 4, + "retry_not_before": "2026-11-20T00:55:46.183727+00:00" + }, + "blocking_code": "PROJECT_DATABASE_TABLE_UNKNOWN", + "scope": "All rounds through generation 187. One explicitly approved response chose unqualified item_sparse in default cata_world. No new local model calls.", + "accounting": "Output already includes reasoning. Clean retains regular calls including rejected first attempts; excludes explicitly marked correction calls. Unknown classifications are not guessed.", + "unknown_classification_calls": 0, + "pricing": { + "currency": "USD", + "basis": "Rates reconstructed from archived per-call token and cost metadata; not a fresh provider price lookup.", + "input_per_million": 0.75, + "cached_input_per_million": 0.075, + "output_including_reasoning_per_million": 3.75, + "recorded_at": "2026-11-19", + "cache_storage": "Archived estimates only; actual billed lifetime unknown." + }, + "billing_eur": { + "status": "unknown", + "before": null, + "after": null + }, + "total": { + "calls": 37, + "input_tokens": { + "known_sum": 192603, + "unknown_calls": 0 + }, + "output_tokens": { + "known_sum": 36001, + "unknown_calls": 0 + }, + "reasoning_tokens": { + "known_sum": 25934, + "unknown_calls": 2 + }, + "cached_input_tokens": { + "known_sum": 83842, + "unknown_calls": 7 + }, + "uncached_input_tokens": { + "known_sum": 34729, + "unknown_calls": 7 + }, + "elapsed_seconds": { + "known_sum": 534.405432, + "unknown_calls": 0 + }, + "cache_created_tokens": { + "known_sum": 35636, + "unknown_calls": 3 + }, + "estimated_input_cost": { + "known_sum": 0.02604675, + "unknown_calls": 7 + }, + "estimated_cached_input_cost": { + "known_sum": 0.0062881499999999976, + "unknown_calls": 7 + }, + "estimated_output_cost": { + "known_sum": 0.13500375, + "unknown_calls": 0 + }, + "estimated_cost": { + "known_sum": 0.1309974, + "unknown_calls": 7 + }, + "estimated_cache_storage_cost": { + "known_sum": 0.0014848333333333334, + "unknown_calls": 3 + }, + "calculated_generation_estimate": { + "lower_usd": 0.17289105000000005, + "upper_usd": 0.22286265000000005, + "cache_storage_excluded": true + } + }, + "clean": { + "calls": 20, + "input_tokens": { + "known_sum": 112631, + "unknown_calls": 0 + }, + "output_tokens": { + "known_sum": 23383, + "unknown_calls": 0 + }, + "reasoning_tokens": { + "known_sum": 19218, + "unknown_calls": 2 + }, + "cached_input_tokens": { + "known_sum": 44153, + "unknown_calls": 4 + }, + "uncached_input_tokens": { + "known_sum": 16651, + "unknown_calls": 4 + }, + "elapsed_seconds": { + "known_sum": 392.26519900000005, + "unknown_calls": 0 + }, + "cache_created_tokens": { + "known_sum": 26993, + "unknown_calls": 2 + }, + "estimated_input_cost": { + "known_sum": 0.01248825, + "unknown_calls": 4 + }, + "estimated_cached_input_cost": { + "known_sum": 0.003311475, + "unknown_calls": 4 + }, + "estimated_output_cost": { + "known_sum": 0.08768625000000001, + "unknown_calls": 0 + }, + "estimated_cost": { + "known_sum": 0.08853097500000003, + "unknown_calls": 4 + }, + "estimated_cache_storage_cost": { + "known_sum": 0.0011247083333333335, + "unknown_calls": 2 + }, + "calculated_generation_estimate": { + "lower_usd": 0.10737300000000001, + "upper_usd": 0.14235622500000003, + "cache_storage_excluded": true + } + }, + "by_phase": { + "INTERPRETING_CASE": { + "total": { + "calls": 3, + "input_tokens": { + "known_sum": 58654, + "unknown_calls": 0 + }, + "output_tokens": { + "known_sum": 5362, + "unknown_calls": 0 + }, + "reasoning_tokens": { + "known_sum": 826, + "unknown_calls": 2 + }, + "cached_input_tokens": { + "known_sum": 0, + "unknown_calls": 3 + }, + "uncached_input_tokens": { + "known_sum": 0, + "unknown_calls": 3 + }, + "elapsed_seconds": { + "known_sum": 178.792322, + "unknown_calls": 0 + }, + "cache_created_tokens": { + "known_sum": 0, + "unknown_calls": 0 + }, + "estimated_input_cost": { + "known_sum": 0, + "unknown_calls": 3 + }, + "estimated_cached_input_cost": { + "known_sum": 0, + "unknown_calls": 3 + }, + "estimated_output_cost": { + "known_sum": 0.0201075, + "unknown_calls": 0 + }, + "estimated_cost": { + "known_sum": 0, + "unknown_calls": 3 + }, + "estimated_cache_storage_cost": { + "known_sum": 0.0, + "unknown_calls": 0 + }, + "calculated_generation_estimate": { + "lower_usd": 0.02450655, + "upper_usd": 0.064098, + "cache_storage_excluded": true + } + }, + "clean": { + "calls": 2, + "input_tokens": { + "known_sum": 44449, + "unknown_calls": 0 + }, + "output_tokens": { + "known_sum": 612, + "unknown_calls": 0 + }, + "reasoning_tokens": { + "known_sum": 0, + "unknown_calls": 2 + }, + "cached_input_tokens": { + "known_sum": 0, + "unknown_calls": 2 + }, + "uncached_input_tokens": { + "known_sum": 0, + "unknown_calls": 2 + }, + "elapsed_seconds": { + "known_sum": 143.672393, + "unknown_calls": 0 + }, + "cache_created_tokens": { + "known_sum": 0, + "unknown_calls": 0 + }, + "estimated_input_cost": { + "known_sum": 0, + "unknown_calls": 2 + }, + "estimated_cached_input_cost": { + "known_sum": 0, + "unknown_calls": 2 + }, + "estimated_output_cost": { + "known_sum": 0.002295, + "unknown_calls": 0 + }, + "estimated_cost": { + "known_sum": 0, + "unknown_calls": 2 + }, + "estimated_cache_storage_cost": { + "known_sum": 0.0, + "unknown_calls": 0 + }, + "calculated_generation_estimate": { + "lower_usd": 0.005628675, + "upper_usd": 0.035631750000000004, + "cache_storage_excluded": true + } + } + }, + "INVESTIGATING_HYPOTHESES": { + "total": { + "calls": 34, + "input_tokens": { + "known_sum": 133949, + "unknown_calls": 0 + }, + "output_tokens": { + "known_sum": 30639, + "unknown_calls": 0 + }, + "reasoning_tokens": { + "known_sum": 25108, + "unknown_calls": 0 + }, + "cached_input_tokens": { + "known_sum": 83842, + "unknown_calls": 4 + }, + "uncached_input_tokens": { + "known_sum": 34729, + "unknown_calls": 4 + }, + "elapsed_seconds": { + "known_sum": 355.61310999999995, + "unknown_calls": 0 + }, + "cache_created_tokens": { + "known_sum": 35636, + "unknown_calls": 3 + }, + "estimated_input_cost": { + "known_sum": 0.02604675, + "unknown_calls": 4 + }, + "estimated_cached_input_cost": { + "known_sum": 0.0062881499999999976, + "unknown_calls": 4 + }, + "estimated_output_cost": { + "known_sum": 0.11489625, + "unknown_calls": 0 + }, + "estimated_cost": { + "known_sum": 0.1309974, + "unknown_calls": 4 + }, + "estimated_cache_storage_cost": { + "known_sum": 0.0014848333333333334, + "unknown_calls": 3 + }, + "calculated_generation_estimate": { + "lower_usd": 0.1483845, + "upper_usd": 0.15876465, + "cache_storage_excluded": true + } + }, + "clean": { + "calls": 18, + "input_tokens": { + "known_sum": 68182, + "unknown_calls": 0 + }, + "output_tokens": { + "known_sum": 22771, + "unknown_calls": 0 + }, + "reasoning_tokens": { + "known_sum": 19218, + "unknown_calls": 0 + }, + "cached_input_tokens": { + "known_sum": 44153, + "unknown_calls": 2 + }, + "uncached_input_tokens": { + "known_sum": 16651, + "unknown_calls": 2 + }, + "elapsed_seconds": { + "known_sum": 248.59280600000002, + "unknown_calls": 0 + }, + "cache_created_tokens": { + "known_sum": 26993, + "unknown_calls": 2 + }, + "estimated_input_cost": { + "known_sum": 0.01248825, + "unknown_calls": 2 + }, + "estimated_cached_input_cost": { + "known_sum": 0.003311475, + "unknown_calls": 2 + }, + "estimated_output_cost": { + "known_sum": 0.08539125, + "unknown_calls": 0 + }, + "estimated_cost": { + "known_sum": 0.08853097500000003, + "unknown_calls": 2 + }, + "estimated_cache_storage_cost": { + "known_sum": 0.0011247083333333335, + "unknown_calls": 2 + }, + "calculated_generation_estimate": { + "lower_usd": 0.10174432500000001, + "upper_usd": 0.106724475, + "cache_storage_excluded": true + } + } + } + }, + "calls": [ + { + "result_ref": "llm/operations/6c0a36f93bea41b87241a30769bd92bb6dc387869b46d3a013ec595cfc7e9548/round-0001.json", + "phase": "INTERPRETING_CASE", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "d6d05640c1923dc48da827791bd41341b6c03c6ee636e87a6a2238b129569e65", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "entity_resolution_plan_v4", + "model": "gemini-3.8-flash", + "input_tokens": 20909, + "output_tokens": 182, + "reasoning_tokens": null, + "cached_input_tokens": null, + "uncached_input_tokens": null, + "elapsed_seconds": 138.946965, + "cache_created_tokens": 0, + "cache_status": "below_minimum", + "estimated_input_cost": null, + "estimated_cached_input_cost": null, + "estimated_output_cost": 0.0006825, + "estimated_cost": null, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.0022506749999999997, + "upper_usd": 0.01636425, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/88adb8b462df2c473b421f617b086dd65351532f28e81a7a1052e1f24da87dea/round-0001.json", + "phase": "INTERPRETING_CASE", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "6ba8d0b54b6b755a96799bec692268c99f07a551dc1d0f6581f708dde5ad9d69", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "entity_resolution_assessment_v4", + "model": "gemini-3.8-flash", + "input_tokens": 23540, + "output_tokens": 430, + "reasoning_tokens": null, + "cached_input_tokens": null, + "uncached_input_tokens": null, + "elapsed_seconds": 4.725428, + "cache_created_tokens": 0, + "cache_status": "below_minimum", + "estimated_input_cost": null, + "estimated_cached_input_cost": null, + "estimated_output_cost": 0.0016125, + "estimated_cost": null, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.003378, + "upper_usd": 0.0192675, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/572afccbd4034d9c5485045cb4bb28b61fdd40e48dc8a3fab67cfc17e997cd65/round-0001.json", + "phase": "INTERPRETING_CASE", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "dbc4761bcaeab38bd745eb7df87d925cc2af492c6775787785c0a659ef70e200", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "case_plan_v2", + "model": "gemini-3.8-flash", + "input_tokens": 14205, + "output_tokens": 4750, + "reasoning_tokens": 826, + "cached_input_tokens": null, + "uncached_input_tokens": null, + "elapsed_seconds": 35.119929, + "cache_created_tokens": 0, + "cache_status": "below_minimum", + "estimated_input_cost": null, + "estimated_cached_input_cost": null, + "estimated_output_cost": 0.0178125, + "estimated_cost": null, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.018877875, + "upper_usd": 0.02846625, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/ca6cdff81de3cbae0492c26802daa287b11bf4fabefad477a9b64f1b6db30112/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "9afcb6210f358c0ed82f2aeddf7a04ff0abd219d8c08425de4f75e6fa5c03a13", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_startup_v1", + "model": "gemini-3.8-flash", + "input_tokens": 3088, + "output_tokens": 563, + "reasoning_tokens": 463, + "cached_input_tokens": 2816, + "uncached_input_tokens": 272, + "elapsed_seconds": 8.233087, + "cache_created_tokens": 2816, + "cache_status": "created", + "estimated_input_cost": 0.000204, + "estimated_cached_input_cost": 0.00021119999999999998, + "estimated_output_cost": 0.00211125, + "estimated_cost": 0.00252645, + "estimated_cache_storage_cost": 0.00011733333333333333, + "calculated_generation_estimate": { + "lower_usd": 0.00252645, + "upper_usd": 0.00252645, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/d844b0d123ece7c9861dbe282539f7879e6e6a21b3d1d4575c6e559fd5044aae/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "c6d6f75ee93980839f0fc4a62f7b9f9345c6e11fb1ca7e63c79547bf9d4d40c2", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "investigation_startup_v1", + "model": "gemini-3.8-flash", + "input_tokens": 3101, + "output_tokens": 502, + "reasoning_tokens": 443, + "cached_input_tokens": 2816, + "uncached_input_tokens": 285, + "elapsed_seconds": 6.044376, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.00021375, + "estimated_cached_input_cost": 0.00021119999999999998, + "estimated_output_cost": 0.0018825, + "estimated_cost": 0.00230745, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.00230745, + "upper_usd": 0.00230745, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/54ef9b495e10fe49a2ffad5909c89efdbfe7ef7645b601865d12e5223b0651bc/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "d7cf436ae5e8cca7d960adf7e7e038c4324b9d436892d3e5bc70c722e4e53972", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_startup_v1", + "model": "gemini-3.8-flash", + "input_tokens": 3766, + "output_tokens": 533, + "reasoning_tokens": 453, + "cached_input_tokens": 2816, + "uncached_input_tokens": 950, + "elapsed_seconds": 6.940787, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.0007125, + "estimated_cached_input_cost": 0.00021119999999999998, + "estimated_output_cost": 0.00199875, + "estimated_cost": 0.00292245, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.00292245, + "upper_usd": 0.00292245, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/71fd77c20b2af9bb2d842927c7a39cc8e1cf3e15541f387a26054fdb1047b6e4/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "8d72e4291a48bfde5d927e9db0487ca2964147f9e299462414409acb8034ab05", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_startup_v1", + "model": "gemini-3.8-flash", + "input_tokens": 4631, + "output_tokens": 525, + "reasoning_tokens": 403, + "cached_input_tokens": 2816, + "uncached_input_tokens": 1815, + "elapsed_seconds": 5.88865, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.00136125, + "estimated_cached_input_cost": 0.00021119999999999998, + "estimated_output_cost": 0.00196875, + "estimated_cost": 0.0035412, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.0035412, + "upper_usd": 0.0035412, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/0270771b422d04af95c20c38558476ded170af96569985af436406482d8d043a/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "0a5ff36679379bf067129d509209a2d21003d316c6e9e4602f44daae66c45888", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_startup_review_v1", + "model": "gemini-3.8-flash", + "input_tokens": 3208, + "output_tokens": 2930, + "reasoning_tokens": 2327, + "cached_input_tokens": null, + "uncached_input_tokens": null, + "elapsed_seconds": 26.290713, + "cache_created_tokens": null, + "cache_status": "fallback", + "estimated_input_cost": null, + "estimated_cached_input_cost": null, + "estimated_output_cost": 0.0109875, + "estimated_cost": null, + "estimated_cache_storage_cost": null, + "calculated_generation_estimate": { + "lower_usd": 0.011228100000000001, + "upper_usd": 0.013393500000000001, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/a4ed5334e4125ed14bcbca18629a561513bba48ef92afecc570c14d9e90e05cc/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "6231eecffd8190bc6db6ab81a9cacb2e139b9ee971ef0628b22eb3e296af480f", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 3330, + "output_tokens": 452, + "reasoning_tokens": 295, + "cached_input_tokens": 2873, + "uncached_input_tokens": 457, + "elapsed_seconds": 7.848876, + "cache_created_tokens": 2873, + "cache_status": "created", + "estimated_input_cost": 0.00034275, + "estimated_cached_input_cost": 0.000215475, + "estimated_output_cost": 0.001695, + "estimated_cost": 0.0022532249999999998, + "estimated_cache_storage_cost": 0.00011970833333333333, + "calculated_generation_estimate": { + "lower_usd": 0.0022532249999999998, + "upper_usd": 0.0022532249999999998, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/23e886f4a2c5eeadfea37a9114a2282780ab8a12c14b970fdcc26da184fc793b/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "af00c708144b848d4781ffc468ad889718a35c8dba1615028e00587a8399b5c1", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 3663, + "output_tokens": 402, + "reasoning_tokens": 265, + "cached_input_tokens": 2885, + "uncached_input_tokens": 778, + "elapsed_seconds": 8.320289, + "cache_created_tokens": 2885, + "cache_status": "created", + "estimated_input_cost": 0.0005835, + "estimated_cached_input_cost": 0.000216375, + "estimated_output_cost": 0.0015075, + "estimated_cost": 0.002307375, + "estimated_cache_storage_cost": 0.00012020833333333335, + "calculated_generation_estimate": { + "lower_usd": 0.002307375, + "upper_usd": 0.002307375, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/90894bde812875d10dcc9a11218c864322aa1f10e8f2c0ee7db07eaa21a4a687/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "a3ec5df6a8ec2d88e7e7e2233cf21acf11c6ba915e6c2b622a066e9cc3e7df96", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 4566, + "output_tokens": 634, + "reasoning_tokens": 390, + "cached_input_tokens": 2885, + "uncached_input_tokens": 1681, + "elapsed_seconds": 7.95629, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.00126075, + "estimated_cached_input_cost": 0.000216375, + "estimated_output_cost": 0.0023775, + "estimated_cost": 0.0038546249999999995, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.0038546249999999995, + "upper_usd": 0.0038546249999999995, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/db5a590ab945f036b4703f8ddcf783cdcf7f28e6cf9d9dfcff02dfdce55bc98b/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "d2fc3e0a89e91105af32e2a3d4c0c934f32201320bddf6a5e34f8ad45fd07e07", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 4579, + "output_tokens": 393, + "reasoning_tokens": 229, + "cached_input_tokens": 2885, + "uncached_input_tokens": 1694, + "elapsed_seconds": 5.796668, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.0012705, + "estimated_cached_input_cost": 0.000216375, + "estimated_output_cost": 0.00147375, + "estimated_cost": 0.0029606249999999997, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.0029606249999999997, + "upper_usd": 0.0029606249999999997, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/a2f620fa28477d1e6d7a3cae9bb5b91b52f60988324993e14e7cece5fc547429/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "e8ffa7bdcf70a06be1bb4e749f79f389871df54ac7a92b7e562d05061f58fd93", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 4579, + "output_tokens": 658, + "reasoning_tokens": 442, + "cached_input_tokens": 2885, + "uncached_input_tokens": 1694, + "elapsed_seconds": 7.2397, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.0012705, + "estimated_cached_input_cost": 0.000216375, + "estimated_output_cost": 0.0024675, + "estimated_cost": 0.0039543749999999996, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.0039543749999999996, + "upper_usd": 0.0039543749999999996, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/bbf03137db61614a7898353127aae3d114e56606ca757881038446b590a4cc21/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "e8108d130bea7a422b923f7062cbb8a4ff049b03d7087adcd8ceb80dd0081f6a", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 3362, + "output_tokens": 1535, + "reasoning_tokens": 1199, + "cached_input_tokens": 2301, + "uncached_input_tokens": 1061, + "elapsed_seconds": 15.460203, + "cache_created_tokens": 2301, + "cache_status": "created", + "estimated_input_cost": 0.00079575, + "estimated_cached_input_cost": 0.00017257499999999998, + "estimated_output_cost": 0.00575625, + "estimated_cost": 0.006724575, + "estimated_cache_storage_cost": 9.5875e-05, + "calculated_generation_estimate": { + "lower_usd": 0.006724575, + "upper_usd": 0.006724575, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/b7f2e84e7ce1ab15fea771e71ef5c71f3321d1b419eefa7f3f69f110b5c356c6/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "e68a86c6985e83db1c9a86281b26fdd7e3c21d0bbd38598c194cc4138d5db5ac", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 3373, + "output_tokens": 352, + "reasoning_tokens": 223, + "cached_input_tokens": 2873, + "uncached_input_tokens": 500, + "elapsed_seconds": 5.430929, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.000375, + "estimated_cached_input_cost": 0.000215475, + "estimated_output_cost": 0.00132, + "estimated_cost": 0.001910475, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.001910475, + "upper_usd": 0.001910475, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/1704c36027e9e7cb8b3d1ec6c6ce478bbf9541e4a8d6a85ebe0c63fbb951d4ca/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "c6a611b89447c7db035da6845b607548f1f78dbfd82f133967554bae1875326c", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 3678, + "output_tokens": 389, + "reasoning_tokens": 234, + "cached_input_tokens": 2885, + "uncached_input_tokens": 793, + "elapsed_seconds": 5.422091, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.00059475, + "estimated_cached_input_cost": 0.000216375, + "estimated_output_cost": 0.00145875, + "estimated_cost": 0.002269875, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.002269875, + "upper_usd": 0.002269875, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/5f1d1465d80c74cdf8ba600d62a21e8b2c5797399b72f77a358900a8fc384843/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "d371d86fe64bff2c60be8715f87136d8b007aaed5bec86d31d458dd875276629", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 3691, + "output_tokens": 326, + "reasoning_tokens": 168, + "cached_input_tokens": 2885, + "uncached_input_tokens": 806, + "elapsed_seconds": 6.049123, + "cache_created_tokens": 2885, + "cache_status": "created", + "estimated_input_cost": 0.0006045, + "estimated_cached_input_cost": 0.000216375, + "estimated_output_cost": 0.0012225, + "estimated_cost": 0.002043375, + "estimated_cache_storage_cost": 0.00012020833333333335, + "calculated_generation_estimate": { + "lower_usd": 0.002043375, + "upper_usd": 0.002043375, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/803fd739ff81c2bc48facdcc42ee3136ae246cf9e421165c25e8b144bcadc8db/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "d371d86fe64bff2c60be8715f87136d8b007aaed5bec86d31d458dd875276629", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 3691, + "output_tokens": 317, + "reasoning_tokens": 157, + "cached_input_tokens": 2885, + "uncached_input_tokens": 806, + "elapsed_seconds": 4.462063, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.0006045, + "estimated_cached_input_cost": 0.000216375, + "estimated_output_cost": 0.00118875, + "estimated_cost": 0.002009625, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.002009625, + "upper_usd": 0.002009625, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/ce832a57a14cb384dc883f85330dd494750a55427de579f7bad75f956466c699/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "abf4f08331a13571e3ce2549f59abb72c4efce76b87a57d9f4973333a1d64ba4", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 3758, + "output_tokens": 335, + "reasoning_tokens": 217, + "cached_input_tokens": null, + "uncached_input_tokens": null, + "elapsed_seconds": 13.494263, + "cache_created_tokens": null, + "cache_status": "fallback", + "estimated_input_cost": null, + "estimated_cached_input_cost": null, + "estimated_output_cost": 0.00125625, + "estimated_cost": null, + "estimated_cache_storage_cost": null, + "calculated_generation_estimate": { + "lower_usd": 0.0015381, + "upper_usd": 0.00407475, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/d1f0925c8c965af48b7ece664c0ccdaae59563eefb9825b0cc704660eb7a858f/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "7a8bc85e43d519dc691082edf0b1215620b749d26ec5d9cfd587d547f5a19db6", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 4170, + "output_tokens": 446, + "reasoning_tokens": 256, + "cached_input_tokens": null, + "uncached_input_tokens": null, + "elapsed_seconds": 16.537045, + "cache_created_tokens": null, + "cache_status": "fallback", + "estimated_input_cost": null, + "estimated_cached_input_cost": null, + "estimated_output_cost": 0.0016725, + "estimated_cost": null, + "estimated_cache_storage_cost": null, + "calculated_generation_estimate": { + "lower_usd": 0.00198525, + "upper_usd": 0.0048000000000000004, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/380b7dd01cdcda45e7b2199227eccb966d88cb56db9f20193bf85daa46398517/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "d3fb3bb0385beb7d1b6d4b11668e4fb27dcaf8fcab215167a72ad840b84a9ebd", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 4242, + "output_tokens": 618, + "reasoning_tokens": 511, + "cached_input_tokens": null, + "uncached_input_tokens": null, + "elapsed_seconds": 6.708031, + "cache_created_tokens": 0, + "cache_status": "fallback", + "estimated_input_cost": null, + "estimated_cached_input_cost": null, + "estimated_output_cost": 0.0023175, + "estimated_cost": null, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.0026356500000000002, + "upper_usd": 0.005499, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/d4d693a4107be85a623890f5a885cb6236f0d0c8ffacb456b8514f611632bb48/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "60e425ab04d0931cfee7d39bc22b914e33861baeadbc12df9e0b8f1931e040aa", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 3716, + "output_tokens": 8379, + "reasoning_tokens": 7994, + "cached_input_tokens": 2301, + "uncached_input_tokens": 1415, + "elapsed_seconds": 72.494922, + "cache_created_tokens": 2301, + "cache_status": "created", + "estimated_input_cost": 0.00106125, + "estimated_cached_input_cost": 0.00017257499999999998, + "estimated_output_cost": 0.03142125, + "estimated_cost": 0.032655075, + "estimated_cache_storage_cost": 9.5875e-05, + "calculated_generation_estimate": { + "lower_usd": 0.032655075, + "upper_usd": 0.032655075, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/a09bbc2809c3c4c27143c827eea878b7ad373176b40e77eb6e102f2c24db0bff/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "53e8722a98aa5c801bb6c6b7e87e1c621b26e55254c36b1a6c899db782dd8a75", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 3733, + "output_tokens": 2043, + "reasoning_tokens": 1733, + "cached_input_tokens": 2301, + "uncached_input_tokens": 1432, + "elapsed_seconds": 16.957576, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.001074, + "estimated_cached_input_cost": 0.00017257499999999998, + "estimated_output_cost": 0.00766125, + "estimated_cost": 0.008907825, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.008907825, + "upper_usd": 0.008907825, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/c619a7901de5674f54e8371759fba596a7746f67d62499b198780813912e5c31/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "fdc81f7446c807bf06cab03f4656d24d0c648d3a8f3c03d23bc6e16ed15530eb", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 3402, + "output_tokens": 230, + "reasoning_tokens": 176, + "cached_input_tokens": 2873, + "uncached_input_tokens": 529, + "elapsed_seconds": 5.496911, + "cache_created_tokens": 2873, + "cache_status": "created", + "estimated_input_cost": 0.00039675, + "estimated_cached_input_cost": 0.000215475, + "estimated_output_cost": 0.0008625, + "estimated_cost": 0.001474725, + "estimated_cache_storage_cost": 0.00011970833333333333, + "calculated_generation_estimate": { + "lower_usd": 0.001474725, + "upper_usd": 0.001474725, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/4320ec1c595687fe2a7d869d4d58f58bd864fbed100cf6fe5d32218d0b35ada0/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "823897d59a04538ec34113118778dd6c8fbd518fc5794b358702c8158bb74a98", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 3482, + "output_tokens": 269, + "reasoning_tokens": 212, + "cached_input_tokens": 2873, + "uncached_input_tokens": 609, + "elapsed_seconds": 5.539993, + "cache_created_tokens": 2873, + "cache_status": "created", + "estimated_input_cost": 0.00045675, + "estimated_cached_input_cost": 0.000215475, + "estimated_output_cost": 0.00100875, + "estimated_cost": 0.0016809750000000001, + "estimated_cache_storage_cost": 0.00011970833333333333, + "calculated_generation_estimate": { + "lower_usd": 0.0016809750000000001, + "upper_usd": 0.0016809750000000001, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/e49ff8c908d0a6a9d0bfbde2189f858fa88aa9b634af9f2496cfdc5e56d20ae2/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "71bc2dec84f6745d5559a7c125166aa7e2d1d2e136cc407ff339b67a8e5c0b3f", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 3482, + "output_tokens": 209, + "reasoning_tokens": 148, + "cached_input_tokens": 2873, + "uncached_input_tokens": 609, + "elapsed_seconds": 3.192396, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.00045675, + "estimated_cached_input_cost": 0.000215475, + "estimated_output_cost": 0.00078375, + "estimated_cost": 0.001455975, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.001455975, + "upper_usd": 0.001455975, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/b5de43dfa1122fa86decfa538047ee813621839eded8ed15356d341f3439e383/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "601b656bcc15d190cbcdc7dd20d991b83089adbd6b8a85801e34e2adbf014c83", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 4105, + "output_tokens": 524, + "reasoning_tokens": 376, + "cached_input_tokens": 2885, + "uncached_input_tokens": 1220, + "elapsed_seconds": 6.866803, + "cache_created_tokens": 2885, + "cache_status": "created", + "estimated_input_cost": 0.000915, + "estimated_cached_input_cost": 0.000216375, + "estimated_output_cost": 0.001965, + "estimated_cost": 0.003096375, + "estimated_cache_storage_cost": 0.00012020833333333335, + "calculated_generation_estimate": { + "lower_usd": 0.003096375, + "upper_usd": 0.003096375, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/eab2fd8c33f57337c6061e06495fda080ccbde40a5d1f671fc105b5fc3f48332/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "7e1396f38cffa0cd7a84dca4848a880c9d2da671858b84e90b6f1c2ce0a39dd9", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 4148, + "output_tokens": 507, + "reasoning_tokens": 410, + "cached_input_tokens": 2885, + "uncached_input_tokens": 1263, + "elapsed_seconds": 5.562874, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.00094725, + "estimated_cached_input_cost": 0.000216375, + "estimated_output_cost": 0.00190125, + "estimated_cost": 0.003064875, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.003064875, + "upper_usd": 0.003064875, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/6849c974442865e5ca3e8f146ef4520c275f2e37a25fb7caa498f17089ed6dc1/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "2866210a499eb47185a40fa92ff1d6f82c6931ba6dd69b88d52b6cae4767d211", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 3738, + "output_tokens": 316, + "reasoning_tokens": 198, + "cached_input_tokens": 2885, + "uncached_input_tokens": 853, + "elapsed_seconds": 3.942876, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.00063975, + "estimated_cached_input_cost": 0.000216375, + "estimated_output_cost": 0.001185, + "estimated_cost": 0.002041125, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.002041125, + "upper_usd": 0.002041125, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/475d5f458554c35131f24fc92fb2e762c69a8d9c6d4ab9d6426fbd72e6303af3/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "81b082cdaf720332510ddabfdfdc2a6c611f35ce1609d28ea39b94bb288769f9", + "status": "SUCCESS", + "classification": "regular", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 3244, + "output_tokens": 3791, + "reasoning_tokens": 3400, + "cached_input_tokens": 2301, + "uncached_input_tokens": 943, + "elapsed_seconds": 32.226618, + "cache_created_tokens": 2301, + "cache_status": "created", + "estimated_input_cost": 0.00070725, + "estimated_cached_input_cost": 0.00017257499999999998, + "estimated_output_cost": 0.01421625, + "estimated_cost": 0.015096075, + "estimated_cache_storage_cost": 9.5875e-05, + "calculated_generation_estimate": { + "lower_usd": 0.015096075, + "upper_usd": 0.015096075, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/8f58f73379896f4edda417f564668be151dea6f1dd75d1872c8aeb64d0cef5ce/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "807b295a95178ed1fd53f5fbca81a184c5eb96813e53b2b072ad688abe4e4398", + "status": "ERROR", + "classification": "regular", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 4500, + "output_tokens": 355, + "reasoning_tokens": 302, + "cached_input_tokens": 2873, + "uncached_input_tokens": 1627, + "elapsed_seconds": 6.247584, + "cache_created_tokens": 2873, + "cache_status": "created", + "estimated_input_cost": 0.00122025, + "estimated_cached_input_cost": 0.000215475, + "estimated_output_cost": 0.00133125, + "estimated_cost": 0.0027669749999999996, + "estimated_cache_storage_cost": 0.00011970833333333333, + "calculated_generation_estimate": { + "lower_usd": 0.0027669749999999996, + "upper_usd": 0.0027669749999999996, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/6ccfd3edde468aa5c42f40ec7c75c2117ae13bf79c3eddd91eb4335ab02d4482/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "70ac79ec6a6688996ee56b1534b072551464e625f6774f5306f7cca85458b972", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 4552, + "output_tokens": 585, + "reasoning_tokens": 485, + "cached_input_tokens": 2873, + "uncached_input_tokens": 1679, + "elapsed_seconds": 7.054466, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.00125925, + "estimated_cached_input_cost": 0.000215475, + "estimated_output_cost": 0.00219375, + "estimated_cost": 0.003668475, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.003668475, + "upper_usd": 0.003668475, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/4115b3b2b3e209ed778e9ec0c51f6e5ce3a4249e00f87c89aeeedead0841f6a2/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "95be11f6114bf029b70b22d3c002baafca83e7392d26ad519c71483620c2abd3", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 4580, + "output_tokens": 325, + "reasoning_tokens": 249, + "cached_input_tokens": 2873, + "uncached_input_tokens": 1707, + "elapsed_seconds": 3.993967, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.00128025, + "estimated_cached_input_cost": 0.000215475, + "estimated_output_cost": 0.00121875, + "estimated_cost": 0.002714475, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.002714475, + "upper_usd": 0.002714475, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/9d94a56f71b21f01a9b59e1f935e199a9e59dd72e2ab77b517fb5e2b1bdd864e/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "5db1a109d3ba0c6617653be000bc3324c2ebfa40c273bcb3559d9080a5d91b62", + "status": "ERROR", + "classification": "regular", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 4642, + "output_tokens": 415, + "reasoning_tokens": 264, + "cached_input_tokens": 2885, + "uncached_input_tokens": 1757, + "elapsed_seconds": 6.988132, + "cache_created_tokens": 2885, + "cache_status": "created", + "estimated_input_cost": 0.00131775, + "estimated_cached_input_cost": 0.000216375, + "estimated_output_cost": 0.00155625, + "estimated_cost": 0.003090375, + "estimated_cache_storage_cost": 0.00012020833333333335, + "calculated_generation_estimate": { + "lower_usd": 0.003090375, + "upper_usd": 0.003090375, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/f312162a57b4add0d8cceb9efc246aa7d4bcad5e2a69117c22937d8293e9704e/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "5d6cdf40a8ea2eda5aa23f4bb166eaecf577702a1be6f9d7619c32ad09c76ff0", + "status": "ERROR", + "classification": "correction", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 4733, + "output_tokens": 217, + "reasoning_tokens": 133, + "cached_input_tokens": 2885, + "uncached_input_tokens": 1848, + "elapsed_seconds": 4.570233, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.001386, + "estimated_cached_input_cost": 0.000216375, + "estimated_output_cost": 0.00081375, + "estimated_cost": 0.002416125, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.002416125, + "upper_usd": 0.002416125, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/67408eb8469db583d37c1341e26f0531b8f260ef2c14ddc73fb16b5598c2b2ff/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "a20d2b191ae77861fe9baa715c8b5b10a1b755c84fc00cce3ce3e8ed4481e628", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 4694, + "output_tokens": 225, + "reasoning_tokens": 132, + "cached_input_tokens": 2885, + "uncached_input_tokens": 1809, + "elapsed_seconds": 4.319073, + "cache_created_tokens": 0, + "cache_status": "reused", + "estimated_input_cost": 0.00135675, + "estimated_cached_input_cost": 0.000216375, + "estimated_output_cost": 0.00084375, + "estimated_cost": 0.002416875, + "estimated_cache_storage_cost": 0.0, + "calculated_generation_estimate": { + "lower_usd": 0.002416875, + "upper_usd": 0.002416875, + "cache_storage_excluded": true + } + }, + { + "result_ref": "llm/operations/963abba804f84c3bb7ea78258345e462784d328f46415ba8bf34887c22ca0656/round-0001.json", + "phase": "INVESTIGATING_HYPOTHESES", + "config_hash": "692c8bac07efc915a44a89ac8aab1b4caa3e125d8619745f13c2ee570cb9e054", + "input_request_hash": "f93d99000ec96c8a2281f6c1b850c86592f53308b810ebc5b18c4fe3c84aa2f4", + "status": "SUCCESS", + "classification": "correction", + "prompt_version": "investigation_project_v20", + "model": "gemini-3.8-flash", + "input_tokens": 4722, + "output_tokens": 339, + "reasoning_tokens": 221, + "cached_input_tokens": 2885, + "uncached_input_tokens": 1837, + "elapsed_seconds": 6.035502, + "cache_created_tokens": 2885, + "cache_status": "created", + "estimated_input_cost": 0.00137775, + "estimated_cached_input_cost": 0.000216375, + "estimated_output_cost": 0.00127125, + "estimated_cost": 0.002865375, + "estimated_cache_storage_cost": 0.00012020833333333335, + "calculated_generation_estimate": { + "lower_usd": 0.002865375, + "upper_usd": 0.002865375, + "cache_storage_excluded": true + } + } + ] +} diff --git a/src/viano_bug_analysis/analysis/investigation_compact.py b/src/viano_bug_analysis/analysis/investigation_compact.py index cbad8bf..a4763dc 100644 --- a/src/viano_bug_analysis/analysis/investigation_compact.py +++ b/src/viano_bug_analysis/analysis/investigation_compact.py @@ -227,6 +227,9 @@ def model_view(context): view['hypotheses'][selected]['legacy_notes']=copy.deepcopy(hypotheses[selected].get('notes',[])) for field in ('previous_rejection','previous_rejection_details','database_query_failures'): if field in context:view[field]=copy.deepcopy(context[field]) + from .tool_guidance import database_access_view + access = database_access_view(context) + if access is not None:view['database_access'] = access return consolidate_origins(view) if context.get('prompt_version') in {'investigation_project_v16','investigation_project_v17','investigation_project_v18'} else view diff --git a/src/viano_bug_analysis/analysis/investigation_lean.py b/src/viano_bug_analysis/analysis/investigation_lean.py index c3fb37d..342dfcd 100644 --- a/src/viano_bug_analysis/analysis/investigation_lean.py +++ b/src/viano_bug_analysis/analysis/investigation_lean.py @@ -86,7 +86,7 @@ def build(context): 'known_schemas':schemas, 'evidence_catalog':view['evidence_catalog'],'archive_ids':view['archive_ids'], 'budget':view['budget'], - **{k:view[k] for k in ('shared_metadata','previous_rejection','previous_rejection_details','database_query_failures') if k in view}}, + **{k:view[k] for k in ('shared_metadata','previous_rejection','previous_rejection_details','database_query_failures','database_access') if k in view}}, 'output_schema':contract} # Keep actual argument contracts in the stable prefix, not inferred from # prose. No arbitrary SQL or shell is added by the lean protocol. diff --git a/src/viano_bug_analysis/analysis/investigation_window.py b/src/viano_bug_analysis/analysis/investigation_window.py index 7c787b0..001b7ae 100644 --- a/src/viano_bug_analysis/analysis/investigation_window.py +++ b/src/viano_bug_analysis/analysis/investigation_window.py @@ -202,7 +202,7 @@ def project(request, context): # Keep the separately validated output schema; describe the strict shape once. view = {k: copy.deepcopy(inp[k]) for k in ( 'hypothesis', 'alternatives', 'previous_result', 'checkpoint_intent', - 'early_review', 'previous_rejection', 'previous_rejection_details','database_query_failures') if k in inp} + 'early_review', 'previous_rejection', 'previous_rejection_details','database_query_failures','database_access') if k in inp} view['case'] = inp.get('case', {}) if 'hypothesis' not in view: hid = context['selected_hypothesis'] @@ -254,6 +254,9 @@ def project(request, context): if key in old: body[key] = old[key] result['messages'] = [{'role': 'system', 'content': instructions_v2() if v2(context) else INSTRUCTIONS}, {'role': 'user', 'content': compact(body)}] + if view.get('database_access'): + from .tool_guidance import DATABASE_ACCESS_INSTRUCTIONS + result['messages'][0]['content'] += DATABASE_ACCESS_INSTRUCTIONS if context.get('research_guidance_version') == 1: from .research_guidance import INSTRUCTIONS as research_instructions result['messages'][0]['content'] += research_instructions diff --git a/src/viano_bug_analysis/analysis/investigator.py b/src/viano_bug_analysis/analysis/investigator.py index eb2aa06..03c22cf 100644 --- a/src/viano_bug_analysis/analysis/investigator.py +++ b/src/viano_bug_analysis/analysis/investigator.py @@ -322,6 +322,8 @@ class Investigator: if raw_size > 4000 or len(json_bytes(session.get('turns', []))) > 2000: session['checkpoint'] = True session['intent'] = 'review' + if context.get('tool_schema',{}).get('x-project-bindings',{}).get('database',{}).get('database'): + context['database_access_version'] = 1 with PackageReader(self._latest(state['case_id'],state['package_id']),self.store.limits) as reader: from .tool_guidance import database_failure_history failures = database_failure_history(reader,state,context,self._read) @@ -473,6 +475,8 @@ class Investigator: context['previous_rejection_details'] = detail active['context_ref'] = active['context_ref'].removesuffix('.json') + '-database-feedback-v1.json' state,_ = self._save(state,context=context) + state,context = self._upgrade_database_context(state,context,operation) + active = state['active'] if context.get('response_repair'): from viano_bug_analysis.llm.response_recovery import admission_reason plan=context['response_repair'] @@ -712,6 +716,20 @@ class Investigator: 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"]) + def _upgrade_database_context(self,state,context,operation): + if (context.get('database_access_version') != 1 and not context.get('response_repair') + and context.get('tool_schema',{}).get('x-project-bindings',{}).get('database',{}).get('database')): + request_ref = f"llm/operations/{key(str(state['analysis_revision']) + ':' + operation)}/request.json" + with PackageReader(self._latest(state['case_id'],state['package_id']),self.store.limits) as reader: + if request_ref not in reader.files: + from .tool_guidance import database_failure_history + context['database_access_version'] = 1 + failures = database_failure_history(reader,state,context,self._read) + if failures:context['database_query_failures'] = failures + state['active']['context_ref'] = state['active']['context_ref'].removesuffix('.json') + '-database-access-v1.json' + state,_ = self._save(state,context=context) + return state,context + @staticmethod def _action_id(state): active = state['active'] diff --git a/src/viano_bug_analysis/analysis/tool_guidance.py b/src/viano_bug_analysis/analysis/tool_guidance.py index 63fc40f..10e48ab 100644 --- a/src/viano_bug_analysis/analysis/tool_guidance.py +++ b/src/viano_bug_analysis/analysis/tool_guidance.py @@ -3,6 +3,42 @@ import copy import re +DATABASE_ACCESS_INSTRUCTIONS = ('\nDatabase access: unqualified tables use only database_access.default_database. ' + 'For another configured database use database.table explicitly. previously_read_tables are scoped past ' + 'lookups, not a guarantee of current availability or a complete table inventory. Discover unknown tables ' + 'with database.tables, then database.schema; never silently substitute another database. ' + 'database_query_failures are earlier metadata failures across hypotheses, not causal evidence; ' + 'do not repeat those pairs without new catalog/schema confirmation.\n') + + +def database_access_view(context): + """Names and exact past lookup references only; no credentials or row data.""" + if context.get('database_access_version') != 1:return None + binding = context.get('tool_schema',{}).get('x-project-bindings',{}).get('database',{}) + default = binding.get('database') + if not isinstance(default,str) or not re.fullmatch(r'[A-Za-z_][A-Za-z0-9_]{0,63}',default):return None + allowlists = {default:binding.get('tables',[]), **binding.get('additional_databases',{})} + databases = [default] + sorted(n for n in allowlists if n != default) + known = {} + from viano_bug_analysis.tools.sql_database import is_table_reference + for eid, entry in sorted(context.get('evidence',{}).items(),reverse=True): + for item in entry.get('content',{}).get('items',[]): + origin, query = item.get('origin',{}), item.get('query',{}) + if not isinstance(origin,dict) or not isinstance(query,dict):continue + table = query.get('table') + if (origin.get('kind')!='mariadb' or origin.get('snapshot_id')!=binding.get('snapshot_id') + or origin.get('database')!=default or query.get('kind') not in {'database.schema','database.rows','database.count'} + or not is_table_reference(table) or not isinstance(item.get('result'),dict)):continue + database, name = table.split('.') if '.' in table else (default,table) + if origin.get('selected_database',database)!=database or origin.get('selected_table',name)!=name:continue + allowed = allowlists.get(database,[]) + if name not in allowed and list(allowed)!=['*']:continue + qualified = database+'.'+name + if qualified not in known and len(known)<12:known[qualified] = {'table':qualified,'evidence_id':eid} + return {'default_database':default,'databases':databases[:16], + 'omitted_databases':max(0,len(databases)-16),'previously_read_tables':list(known.values())} + + def database_failure_history(reader, state, context, read_call): """Bounded operational hints across hypotheses, never causal evidence.""" refs = {n['llm_ref'] for h in state['hypotheses'].values() for n in h.get('notes', []) @@ -91,7 +127,7 @@ def instructions(context): bindings = context['tool_schema'].get('x-project-bindings', {}) text = (HEADER + 'Use operation="project.query" for these arguments. Prefer a matching larger tool ' 'before separate schema/search/read calls; primitive tools remain available.\n') - if (bindings.get('database') or {}).get('additional_databases'): + if (bindings.get('database') or {}).get('additional_databases') and context.get('database_access_version') != 1: text+=('Database table references use configured_database.table. Unqualified tables use only ' 'the default database. Use database.tables to discover allowed tables across configured ' 'databases; never substitute an equally named table from another database.\n') @@ -116,9 +152,11 @@ def instructions(context): 'Replace the illustrative column/value with schema-verified, case-grounded inputs. ' 'Never emit [] or flatten an object into ["column",...,"operator",...,"value",...]. ' 'Input compression encodings do not apply to output: return ordinary JSON objects.\n') - if context.get('database_query_failures'): + if context.get('database_query_failures') and context.get('database_access_version') != 1: text += ('database_query_failures lists earlier failed metadata lookups across hypotheses, not causal evidence. ' 'Do not reuse those database/table pairs without new catalog/schema evidence that they are available. ' 'Use database.tables to discover permitted alternatives, then inspect their actual schema, or use source/package data. ' 'A failed lookup is not proof that the underlying bug has a missing implementation.\n') + if database_access_view(context) is not None: + text += DATABASE_ACCESS_INSTRUCTIONS return text diff --git a/src/viano_bug_analysis/schemas/investigation-context-v1.schema.json b/src/viano_bug_analysis/schemas/investigation-context-v1.schema.json index 2432178..51ccd42 100644 --- a/src/viano_bug_analysis/schemas/investigation-context-v1.schema.json +++ b/src/viano_bug_analysis/schemas/investigation-context-v1.schema.json @@ -945,6 +945,9 @@ } } } + }, + "database_access_version": { + "const": 1 } } } diff --git a/tests/fixtures/llm_rejections/20261120/bug23-unqualified-hotfix-table/analysis.md b/tests/fixtures/llm_rejections/20261120/bug23-unqualified-hotfix-table/analysis.md new file mode 100644 index 0000000..0951b4a --- /dev/null +++ b/tests/fixtures/llm_rejections/20261120/bug23-unqualified-hotfix-table/analysis.md @@ -0,0 +1,3 @@ +# BUG-000023: unqualified Hotfix table + +Generation 187. One explicit operator approval was applied. The next answer changed item_template to item_sparse but omitted its database qualifier. Unqualified tables resolve only to cata_world; the known successful schema query was cata_hotfixes.item_sparse (E000009, H3). The bounded user input omitted the configured default/additional database mapping and table qualification rule. Its frozen correction context predated shared database_query_failures; those hints appeared only in the new rejection context. The new reply was therefore correctly rejected and the exhausted counter immediately blocked again. This is not a connection outage, and it does not prove item_sparse is absent from all configured databases. Do not silently substitute another database. Restore compact database-access metadata and migrate pending contexts only before freezing their next request. diff --git a/tests/fixtures/llm_rejections/20261120/bug23-unqualified-hotfix-table/database-context.json b/tests/fixtures/llm_rejections/20261120/bug23-unqualified-hotfix-table/database-context.json new file mode 100644 index 0000000..eca939a --- /dev/null +++ b/tests/fixtures/llm_rejections/20261120/bug23-unqualified-hotfix-table/database-context.json @@ -0,0 +1,81 @@ +{ + "database_binding": { + "additional_databases": { + "cata_characters": [ + "*" + ], + "cata_hotfixes": [ + "*" + ] + }, + "database": "cata_world", + "kind": "mariadb", + "snapshot_id": "vps-live", + "table_reference": "database.table; unqualified tables use the default database only", + "tables": [ + "*" + ], + "time_scope": "configured_snapshot_not_current_production" + }, + "past_schema_lookup": { + "record": { + "id": "E000009", + "hypothesis_id": "H3", + "action_id": "INV-1-H3-4" + }, + "content": { + "coverage": "schema_only", + "items": [ + { + "origin": { + "additional_databases": { + "cata_characters": [ + "*" + ], + "cata_hotfixes": [ + "*" + ] + }, + "database": "cata_world", + "kind": "mariadb", + "selected_database": "cata_hotfixes", + "selected_table": "item_sparse", + "snapshot_id": "vps-live", + "table_reference": "database.table; unqualified tables use the default database only", + "tables": [ + "*" + ], + "time_scope": "configured_snapshot_not_current_production" + }, + "query": { + "kind": "database.schema", + "table": "cata_hotfixes.item_sparse" + }, + "result": { + "coverage": "schema_only", + "truncated": true, + "items": [ + { + "table": "cata_hotfixes.item_sparse", + "columns": [ + { + "COLUMN_KEY": "PRI", + "COLUMN_NAME": "ID", + "COLUMN_TYPE": "int(10) unsigned", + "IS_NULLABLE": "NO" + }, + { + "COLUMN_KEY": "", + "COLUMN_NAME": "Quality", + "COLUMN_TYPE": "int(10) unsigned", + "IS_NULLABLE": "NO" + } + ] + } + ] + } + } + ] + } + } +} diff --git a/tests/fixtures/llm_rejections/20261120/bug23-unqualified-hotfix-table/parsed-answer.json b/tests/fixtures/llm_rejections/20261120/bug23-unqualified-hotfix-table/parsed-answer.json new file mode 100644 index 0000000..bd4728c --- /dev/null +++ b/tests/fixtures/llm_rejections/20261120/bug23-unqualified-hotfix-table/parsed-answer.json @@ -0,0 +1,15 @@ +{ + "assessment": { + "reason": "Search for 60678 in repository yielded unrelated SQL matches and broadcast text. Need to check item table schema in the database to inspect item 60678's spells.", + "semantic_score": 25 + }, + "next": { + "arguments": { + "kind": "database.schema", + "table": "item_sparse" + }, + "kind": "tool", + "operation": "project.query" + }, + "observation": "Item 60678 search in git returned unrelated matches. Checking item_sparse schema to look up spell IDs attached to item 60678." +} diff --git a/tests/test_database_access_context.py b/tests/test_database_access_context.py new file mode 100644 index 0000000..b4ed6e7 --- /dev/null +++ b/tests/test_database_access_context.py @@ -0,0 +1,135 @@ +import copy +import json +from pathlib import Path +import pytest +from test_bounded_contract_v2 import context as bounded_context +from test_case_builder import case_setup +from test_investigation_tools import tool_case +from viano_bug_analysis.analysis.investigation_prompt import build_prompt +from viano_bug_analysis.analysis.tool_guidance import database_access_view +from viano_bug_analysis.llm.investigation_size import characters + + +ROOT=Path(__file__).parent/'fixtures/llm_rejections/20261120/bug23-unqualified-hotfix-table' + + +def recorded_context(): + fixture=json.loads((ROOT/'database-context.json').read_text(encoding='utf-8')) + c=bounded_context() + c['database_access_version']=1 + c['tool_schema']['x-project-bindings']['database']=fixture['database_binding'] + c['evidence']['E000009']=fixture['past_schema_lookup'] + c['database_query_failures']=[{'database':'cata_world','table':'item_template'}, + {'database':'cata_world','table':'item_sparse'}] + return c + + +@pytest.mark.parametrize('checkpoint',[False,True]) +def test_real_bug23_database_mapping_reaches_final_bounded_wire_request(checkpoint): + c=recorded_context();c['lean_session']['checkpoint']=checkpoint + before=copy.deepcopy(c) + request=build_prompt(c);body=json.loads(request['messages'][1]['content']) + access=body['input']['database_access'] + assert access['default_database']=='cata_world' + assert set(access['databases'])=={'cata_world','cata_hotfixes','cata_characters'} + assert {'table':'cata_hotfixes.item_sparse','evidence_id':'E000009'} in access['previously_read_tables'] + assert body['input']['database_query_failures']==c['database_query_failures'] + assert 'unqualified tables use only database_access.default_database' in request['messages'][0]['content'] + assert 'not causal evidence' in request['messages'][0]['content'] + assert characters(request)<=20000 and c==before + assert 'password' not in json.dumps(access).lower() + c.pop('database_access_version') + legacy=build_prompt(c) + assert 'database_access' not in json.loads(legacy['messages'][1]['content'])['input'] + assert 'database_access.default_database' not in legacy['messages'][0]['content'] + + +@pytest.mark.parametrize('change',[ + lambda i:i['origin'].update(snapshot_id='other-snapshot'), + lambda i:i['origin'].update(selected_database='cata_world'), + lambda i:i['query'].update(table='cata_auth.item_sparse'), + lambda i:i['query'].update(table='cata_hotfixes.item_sparse;DROP TABLE x'), +]) +def test_known_lookup_hints_keep_snapshot_identity_and_allowed_database_scope(change): + c=recorded_context();item=c['evidence']['E000009']['content']['items'][0] + change(item) + assert not database_access_view(c)['previously_read_tables'] + + +def test_resume_upgrades_only_pending_context_and_preserves_old_request_bytes(tool_case): + from test_investigator import LoopAdapter,run,state,CASE + from test_case_interpreter import gateway + from test_project_research import FakeDB,rows + from viano_bug_analysis.analysis import Investigator + from viano_bug_analysis.tools import InvestigationToolRouter,ToolError + from viano_bug_analysis.tools.project_query import ProjectResearch + from viano_bug_analysis.package import PackageReader,PackageValidator + class Database(FakeDB): + def binding(self):return {'kind':'mariadb','snapshot_id':'snapshot-A','database':'world', + 'tables':['*'],'additional_databases':{'hotfix':['*']}} + def validate(self,args): + if args.get('table')=='missing':raise ToolError('PROJECT_DATABASE_TABLE_UNKNOWN') + with PackageReader(tool_case[1]) as reader: + service=ProjectResearch(reader.manifest['project'],database=Database()) + calls=[] + def change(reply,c): + if calls: + assert c['database_access']['default_database']=='world' + assert c['database_query_failures']==[{'database':'world','table':'missing'}] + reply['next']={'kind':'tool','operation':'project.query','arguments':rows(table='missing' if not calls else 'switches')} + calls.append(1) + worker=Investigator(tool_case[0],gateway(LoopAdapter(change)),router=InvestigationToolRouter(project_research=service)) + original=worker._context + def legacy(*args): + c=original(*args);c.pop('database_access_version',None);return c + worker._context=legacy + first=run(worker,steps=1) + with PackageReader(first.package) as reader: + preserved={n:reader.read_bytes(n) for n in reader.files if n!='manifest.json'} + worker._context=original + second=run(worker,steps=1) + assert state(second)['active'] is None + with PackageReader(second.package) as reader: + for n,raw in preserved.items():assert reader.read_bytes(n)==raw + contexts=[n for n in reader.files if n.endswith('-database-access-v1.json')] + assert len(contexts)==1 + assert json.loads(reader.read_bytes(contexts[0]))['database_access_version']==1 + assert PackageValidator().validate(second.package).valid + + + +def test_already_frozen_request_is_replayed_without_database_metadata_upgrade(tool_case,monkeypatch): + from test_investigator import LoopAdapter,run,CASE + from test_case_interpreter import gateway + from test_project_research import FakeDB,rows + from viano_bug_analysis.analysis import Investigator + from viano_bug_analysis.tools import InvestigationToolRouter + from viano_bug_analysis.tools.project_query import ProjectResearch + from viano_bug_analysis.package import PackageReader + class Database(FakeDB): + def binding(self):return {'kind':'mariadb','snapshot_id':'snapshot-A','database':'world','tables':['*']} + with PackageReader(tool_case[1]) as reader: + service=ProjectResearch(reader.manifest['project'],database=Database()) + adapter=LoopAdapter(lambda r,c:r.update(next={'kind':'tool','operation':'project.query','arguments':rows()})) + worker=Investigator(tool_case[0],gateway(adapter),router=InvestigationToolRouter(project_research=service)) + original_context=worker._context + def legacy(*args): + c=original_context(*args);c.pop('database_access_version',None);return c + monkeypatch.setattr(worker,'_context',legacy) + upgrade=worker._upgrade_database_context + monkeypatch.setattr(worker,'_upgrade_database_context',lambda state,context,operation:(state,context)) + class Crash(BaseException):pass + original_validate=worker._validate_decision + def crash(*args):raise Crash() + monkeypatch.setattr(worker,'_validate_decision',crash) + with pytest.raises(Crash):run(worker,steps=1) + with PackageReader(tool_case[0].latest(*CASE)) as reader: + originals={n:reader.read_bytes(n) for n in reader.files if n!='manifest.json'} + monkeypatch.setattr(worker,'_context',original_context) + monkeypatch.setattr(worker,'_upgrade_database_context',upgrade) + monkeypatch.setattr(worker,'_validate_decision',original_validate) + result=run(worker,steps=1) + assert len(adapter.contexts)==1 + with PackageReader(result.package) as reader: + for n,raw in originals.items():assert reader.read_bytes(n)==raw + assert not [n for n in reader.files if n.endswith('-database-access-v1.json')]