Add source-constrained joint planning and scoped dependency-aware recovery

This commit is contained in:
Nico committed 2026-10-20 00:43:27 +02:00
1 parent d280f001fc
commit 83ef9e6d6c
23 files changed
+913 -42

No files matched your search

+17 -11
View File
@@ -25,6 +25,7 @@ MODEL_CODES = frozenset({"LLM_OUTPUT_SCHEMA", "LLM_RESPONSE", "LLM_INCOMPLETE_OU
"INTERPRETATION_GAP_SOURCES", "INTERPRETATION_ENTITY", "INTERPRETATION_RESOLVED_ENTITY_OMITTED",
"INTERPRETATION_UNRESOLVED_ENTITY_OMITTED", "INTERPRETATION_ENTITY_PROVENANCE", "INTERPRETATION_DESCRIPTION_SOURCES",
"INTERPRETATION_PROVISIONAL_GAP_SOURCES", "HYPOTHESIS_SCHEMA", "HYPOTHESIS_COUNT",
"INTERPRETATION_PATCH_SCOPE", "HYPOTHESIS_PREMISE_SOURCE", "HYPOTHESIS_DEPENDENCY_CHANGED", "HYPOTHESIS_DEPENDENCY_UNCERTAIN",
"HYPOTHESIS_DUPLICATE", "HYPOTHESIS_SOURCE_UNKNOWN", "HYPOTHESIS_GROUNDING", "HYPOTHESIS_PRIMARY_FOCUS"})
_attempt_context = contextvars.ContextVar("vba_early_correction", default=None)
@@ -100,8 +101,8 @@ def failures(reader, phase):
continue
error = read_json(reader, d["error_ref"], PHASES[phase][3], 4 * 1024**2)
call = read_json(reader, d["llm_result_ref"], "llm-call", 4 * 1024**2)
from .joint_planning import VERSION, interpretation_payload, hypothesis_payload, build_request
joint = phase == "hypotheses" and call["outcome"].get("metadata", {}).get("prompt_version") == VERSION
from .joint_planning import VERSION, interpretation_payload, hypothesis_payload, is_joint, build_request, is_joint
joint = phase == "hypotheses" and is_joint(call)
if (error["code"] != d["code"] or error["llm_result_ref"] != d["llm_result_ref"]
or call["phase"] != (State.INTERPRETING_CASE if joint else PHASES[phase][0]) or call["status"] not in {"SUCCESS", "ERROR"}
or any(call[f] != reader.manifest[f] or error[f] != reader.manifest[f] for f in ("case_id", "package_id", "analysis_revision"))):
@@ -117,7 +118,7 @@ def failures(reader, phase):
if joint:
expected = build_request(context["case_context"])
expected = replay_request(reader, expected, call, "interpretation")
if phase == "interpretation" and expected["prompt_version"] == VERSION and request.get("prompt_version") != VERSION:
if phase == "interpretation" and expected["prompt_version"] in {VERSION,"case_plan_v2"} and request.get("prompt_version") not in {VERSION,"case_plan_v2"}:
from .joint_planning import repair_interpretation
matching = next((doc for _, doc in artifacts(reader, phase) if doc["kind"] == "attempt"
and call["operation_key"] == key(f"{reader.manifest['analysis_revision']}:case-interpretation:v1:{doc['attempt_id']}")), None)
@@ -139,7 +140,7 @@ def failures(reader, phase):
from .hypothesis_contracts import validate_proposals
from .hypothesis_config import HypothesisError
try:
payload = (interpretation_payload(call, context) if phase == "interpretation" else
payload = (interpretation_payload(call, context, reader) if phase == "interpretation" else
hypothesis_payload(reader, call, context) if joint else call["outcome"]["document"])
(validate_interpretation if phase == "interpretation" else validate_proposals)(payload, context)
except (InterpretationError, HypothesisError) as invalid:
@@ -159,10 +160,11 @@ def feedback(reader, phase, failure):
ref, error, call = failure
context = read_json(reader, error["context_ref"], PHASES[phase][5], 4 * 1024**2)
payload = call["outcome"].get("document")
from .joint_planning import VERSION, interpretation_payload, hypothesis_payload
from .joint_planning import VERSION, interpretation_payload, hypothesis_payload, is_joint
if phase == "interpretation":
payload = interpretation_payload(call, context)
elif call["outcome"].get("metadata", {}).get("prompt_version") == VERSION:
try:payload = interpretation_payload(call, context, reader)
except InterpretationError:payload = None
elif is_joint(call):
from .hypothesis_config import HypothesisError
try:
payload = hypothesis_payload(reader, call, context)
@@ -265,8 +267,12 @@ def feedback(reader, phase, failure):
instruction = "Return a complete replacement JSON object conforming to the supplied schema and source rules. Do not invent facts or sources. Use empty arrays/null for unsupported claims. Distinct hypotheses must retain valid grounding and count constraints."
if phase == 'interpretation' and diagnostic_version in {'case_interpretation_resolved_v2','case_interpretation_resolved_v3','case_interpretation_resolved_v4','case_interpretation_resolved_v5','case_interpretation_resolved_v6','case_interpretation_resolved_v7','case_interpretation_resolved_v8'}:
instruction += " Keep tester observations in observed_behavior with observation sources; move technical assertions to confirmed_technical_facts with fact sources. Retain selected entity_id values and cite their original mentions plus entity or matching capture evidence. Keep lookup uncertainties scoped to their queries."
if phase == "hypotheses" and call["outcome"].get("metadata", {}).get("prompt_version") == VERSION:
if phase == "hypotheses" and is_joint(call):
instruction += " Return only hypotheses with interpretation_ids from the accepted interpretation_sources. The rejected joint transport used interpretation_paths; do not copy that field or regenerate interpretation."
if phase=="interpretation" and context.get("joint_generation",{}).get("version")==2:
from .joint_v2 import issues as statement_issues
local=statement_issues(payload,context)
return {"code":error["code"],"issues":local,"instruction":"Replace only the listed statements. Do not attribute inferred beliefs to the tester. Review every hypothesis for direct AND implicit dependency on changed statements; missing references do not prove independence."}
return {"code":error["code"],"issues":issues[:32],"instruction":instruction}
@@ -278,11 +284,11 @@ def augment(request, reader, phase, attempt):
failure = next((f for f in history if f[0] == attempt["previous_error_ref"]), None)
if failure is None or feedback(reader, phase, failure) != attempt["feedback"]:
raise InterpretationError("CORRECTION_FEEDBACK_CHANGED")
from .joint_planning import VERSION, repair_interpretation
if phase == "interpretation" and request["prompt_version"] == VERSION:
from .joint_planning import VERSION, repair_interpretation, is_joint
if phase == "interpretation" and request["prompt_version"] in {VERSION,"case_plan_v2"}:
return repair_interpretation(request, reader, failure, attempt["feedback"])
payload = failure[2]["outcome"].get("document")
if phase == "hypotheses" and failure[2]["outcome"].get("metadata", {}).get("prompt_version") == VERSION:
if phase == "hypotheses" and is_joint(failure[2]):
# Retain only the rejected hypothesis block; never resend interpretation for regeneration.
payload = payload.get("hypotheses") if isinstance(payload, dict) else None
if payload is not None: