fix(llm): evidence-check a code node whose confidence is a mis-cased EXTRACTED
_bind_node_evidence flags a code node with no evidence in the source only
when the model presented it as solid, matching confidence against
(None, "", "EXTRACTED") case-sensitively. build._fold_confidence (#4529)
treats a case variant as that enum value and corrects its spelling, so a
node the model wrote as "extracted" reaches graph.json as EXTRACTED, but
skipped the evidence check and kept no verification flag. Compare
case-insensitively. A hedged value in any case (inferred, ambiguous) is
still left unflagged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 554d227b28)
This commit is contained in:
1 parent
dfd4ea95ec
commit
91c8954345
2 files changed
+46
-1
No files matched your search
+10
-1
@@ -792,7 +792,16 @@ def _bind_node_evidence(result: dict, text_units: "list[Path | FileSlice]", root
|
||||
# No evidence. Flag only a node the model itself presented as solid
|
||||
# (EXTRACTED/unset) — one it already hedged (INFERRED/AMBIGUOUS) needs no
|
||||
# second flag. Idempotent: never overwrites an existing verification.
|
||||
if n.get("confidence") in (None, "", "EXTRACTED") and not n.get(_VERIFICATION_FIELD):
|
||||
# Matched case-insensitively, the way build._fold_confidence (#4529)
|
||||
# reads it: a mis-cased enum value IS that enum value there and is
|
||||
# corrected to the canonical spelling, so a node the model wrote as
|
||||
# `"extracted"` reaches graph.json just as solid as `"EXTRACTED"` and
|
||||
# must be evidence-checked the same. A hedged spelling in any case
|
||||
# ("inferred", "ambiguous") still falls through unflagged.
|
||||
_conf = n.get("confidence")
|
||||
if isinstance(_conf, str):
|
||||
_conf = _conf.upper()
|
||||
if _conf in (None, "", "EXTRACTED") and not n.get(_VERIFICATION_FIELD):
|
||||
n[_VERIFICATION_FIELD] = _UNVERIFIED_VALUE
|
||||
downgraded += 1
|
||||
return downgraded
|
||||
|
||||
@@ -119,6 +119,42 @@ def test_existing_lower_confidence_is_not_overwritten(tmp_path):
|
||||
assert "verification" not in out["made_up()"]
|
||||
|
||||
|
||||
def test_case_variant_extracted_confidence_is_still_evidence_checked(tmp_path):
|
||||
src = tmp_path / "mod.py"
|
||||
src.write_text(_SOURCE, encoding="utf-8")
|
||||
# build._fold_confidence (#4529) treats a mis-cased enum value as THE enum
|
||||
# value and corrects its spelling, so `"extracted"` and `"Extracted"` reach
|
||||
# graph.json as EXTRACTED — exactly as solid a claim as the uppercase form.
|
||||
# Evidence-binding must therefore check them too; a case-sensitive
|
||||
# comparison let a fabricated symbol keep an unqualified EXTRACTED node.
|
||||
nodes = [
|
||||
{"id": "a", "label": "made_up_lower()", "file_type": "code",
|
||||
"source_file": "mod.py", "confidence": "extracted"},
|
||||
{"id": "b", "label": "made_up_title()", "file_type": "code",
|
||||
"source_file": "mod.py", "confidence": "Extracted"},
|
||||
]
|
||||
out = _by_label(_run([src], nodes, tmp_path))
|
||||
assert out["made_up_lower()"]["verification"] == "unverified"
|
||||
assert out["made_up_title()"]["verification"] == "unverified"
|
||||
|
||||
|
||||
def test_hedged_confidence_is_left_alone_in_any_case(tmp_path):
|
||||
# Control: a model that hedged the node needs no second flag, and that must
|
||||
# hold for the mis-cased spellings of the hedging values too — widening the
|
||||
# EXTRACTED match must not start flagging INFERRED/AMBIGUOUS nodes.
|
||||
src = tmp_path / "mod.py"
|
||||
src.write_text(_SOURCE, encoding="utf-8")
|
||||
nodes = [
|
||||
{"id": "a", "label": "hedged_lower()", "file_type": "code",
|
||||
"source_file": "mod.py", "confidence": "inferred"},
|
||||
{"id": "b", "label": "hedged_ambiguous()", "file_type": "code",
|
||||
"source_file": "mod.py", "confidence": "ambiguous"},
|
||||
]
|
||||
out = _by_label(_run([src], nodes, tmp_path))
|
||||
assert "verification" not in out["hedged_lower()"]
|
||||
assert "verification" not in out["hedged_ambiguous()"]
|
||||
|
||||
|
||||
def test_label_identifiers_helper():
|
||||
assert llm._label_identifiers("foo()") == ["foo"]
|
||||
assert llm._label_identifiers("Cls.method(x)") == ["Cls", "method"]
|
||||
|
||||
Reference in new issue
Block a user