docs+chore: audit findings + tooling (base of the remediation stack) #15

Merged
user2595 merged 9 commits from audit/loop-1 into main 2026-06-16 04:52:59 +00:00
5 changed files with 38 additions and 30 deletions
Showing only changes of commit 9726042964 - Show all commits

View File

@@ -96,10 +96,7 @@ def fetch_references(paper_id: str) -> list[Citation]:
context: str | None = contexts[0] if contexts else None context: str | None = contexts[0] if contexts else None
cited_id: str = ( cited_id: str = (
external_ids.get("DOI") external_ids.get("DOI") or external_ids.get("ArXiv") or cited_paper.get("paperId") or ""
or external_ids.get("ArXiv")
or cited_paper.get("paperId")
or ""
) )
if cited_id: if cited_id:
citations.append(Citation(citing_id=paper_id, cited_id=cited_id, context=context)) citations.append(Citation(citing_id=paper_id, cited_id=cited_id, context=context))

View File

@@ -365,11 +365,7 @@ def find_connections(
continue continue
seen_pairs.add(pair) # type: ignore[arg-type] seen_pairs.add(pair) # type: ignore[arg-type]
pair_chunks = [ pair_chunks = [c for c in chunks if c.get("bibkey") in {bibkey, other}]
c
for c in chunks
if c.get("bibkey") in {bibkey, other}
]
prompt = _CONNECTION_PROMPT.format(chunks_block=_format_chunks(pair_chunks)) prompt = _CONNECTION_PROMPT.format(chunks_block=_format_chunks(pair_chunks))
raw = _safe_llm_generate(llm, prompt, settings.synthesis_llm_model) raw = _safe_llm_generate(llm, prompt, settings.synthesis_llm_model)
if not raw.strip(): if not raw.strip():

View File

@@ -240,9 +240,36 @@ def _parse_claims(markdown: str) -> list[Claim]:
_STOPWORDS: frozenset[str] = frozenset( _STOPWORDS: frozenset[str] = frozenset(
{ {
"the", "a", "an", "in", "on", "of", "to", "is", "are", "was", "were", "the",
"and", "or", "but", "for", "with", "this", "that", "it", "we", "they", "a",
"be", "as", "at", "by", "from", "has", "have", "not", "which", "an",
"in",
"on",
"of",
"to",
"is",
"are",
"was",
"were",
"and",
"or",
"but",
"for",
"with",
"this",
"that",
"it",
"we",
"they",
"be",
"as",
"at",
"by",
"from",
"has",
"have",
"not",
"which",
} }
) )
@@ -360,12 +387,8 @@ def _detect_conflicts(
for bk2 in bibkeys[i + 1 :]: for bk2 in bibkeys[i + 1 :]:
# Check if any chunk from bk1 contains a conflict keyword # Check if any chunk from bk1 contains a conflict keyword
# and any chunk from bk2 also does — heuristic signal only # and any chunk from bk2 also does — heuristic signal only
bk1_has_conflict = any( bk1_has_conflict = any(_CONFLICT_KEYWORDS.search(c) for c in by_bib[bk1])
_CONFLICT_KEYWORDS.search(c) for c in by_bib[bk1] bk2_has_conflict = any(_CONFLICT_KEYWORDS.search(c) for c in by_bib[bk2])
)
bk2_has_conflict = any(
_CONFLICT_KEYWORDS.search(c) for c in by_bib[bk2]
)
if bk1_has_conflict and bk2_has_conflict: if bk1_has_conflict and bk2_has_conflict:
conflicts.append((slug, bk1, bk2)) conflicts.append((slug, bk1, bk2))

View File

@@ -55,9 +55,7 @@ def isolated_leads_dir(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Path:
monkeypatch.setattr("codex.cli.get_settings", lambda: settings, raising=False) monkeypatch.setattr("codex.cli.get_settings", lambda: settings, raising=False)
monkeypatch.setattr("codex.synthesis.get_settings", lambda: settings) monkeypatch.setattr("codex.synthesis.get_settings", lambda: settings)
monkeypatch.setattr( monkeypatch.setattr("codex.config.get_settings", lambda: settings, raising=False)
"codex.config.get_settings", lambda: settings, raising=False
)
return leads_path return leads_path

View File

@@ -201,9 +201,7 @@ def test_grounding_guard_last_sentence_grounded_earlier_hallucination_ignored()
This test verifies that a claim whose text = the last sentence grounds correctly. This test verifies that a claim whose text = the last sentence grounds correctly.
""" """
# The last sentence of the claim text is directly grounded in the fixture chunk. # The last sentence of the claim text is directly grounded in the fixture chunk.
grounded_sentence = ( grounded_sentence = "the hyperbolic volume is V = L(gamma1) + L(gamma2) + L(gamma3)"
"the hyperbolic volume is V = L(gamma1) + L(gamma2) + L(gamma3)"
)
claim = Claim( claim = Claim(
text=grounded_sentence, text=grounded_sentence,
bibkey="Springborn2008", bibkey="Springborn2008",
@@ -523,9 +521,7 @@ def test_idempotent_no_rewrite_when_unchanged(
call_count = 0 call_count = 0
original_compile = compile_concept original_compile = compile_concept
def counting_compile( def counting_compile(concept: Concept, chunks: list[Any], **kwargs: Any) -> ConceptPage:
concept: Concept, chunks: list[Any], **kwargs: Any
) -> ConceptPage:
nonlocal call_count nonlocal call_count
call_count += 1 call_count += 1
return original_compile(concept, chunks, **kwargs) return original_compile(concept, chunks, **kwargs)
@@ -569,9 +565,7 @@ def test_force_all_recompiles_even_when_unchanged(
call_count = 0 call_count = 0
original_compile = compile_concept original_compile = compile_concept
def counting_compile( def counting_compile(concept: Concept, chunks: list[Any], **kwargs: Any) -> ConceptPage:
concept: Concept, chunks: list[Any], **kwargs: Any
) -> ConceptPage:
nonlocal call_count nonlocal call_count
call_count += 1 call_count += 1
return original_compile(concept, chunks, **kwargs) return original_compile(concept, chunks, **kwargs)