Skip to content

Convert Claude Code or Codex into the most intelligent Deep Research Agent. Collect, search, and synthesize web research into a persistent, searchable wiki that builds on itself. Hosted API + MCP: hyperresearch.ai

fix: an unknown retraction result never erases a known retraction (#146)

Jordan Gibbs750a51bac43b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 39f81df..6c4c763 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
- Add scholarly metadata filters and metadata-only browsing to CLI and MCP search, including semantic filtering and a cache upgrade that preserves unchecked retraction status.
- **BEHAVIOR CHANGE — crawl4ai's headless browser verifies TLS certificates (#137).** crawl4ai defaults `BrowserConfig.ignore_https_errors` to True and launches Chromium with `--ignore-certificate-errors` on every start, so the provider `hpr install` switches a vault to fetched most HTML with verification off. Setting `ignore_https_errors = False` alone changes nothing (checked against a self-signed server on crawl4ai 0.8.6); the provider now also drops those launch flags, on both the plain launch and the login-profile (managed browser) launch, and refuses to start if a crawl4ai release moves the code it overrides. A refused certificate raises `CertVerificationError` naming the code (`ERR_CERT_AUTHORITY_INVALID`, ...) and the new opt-out, `[fetch] browser_verify_tls = false`. Before, it came back as an empty page and was reported as junk. As on the builtin and PDF lanes, the failure is final: no unverified retry, no escalation. In a batch it is a logged skip. The visible-window lane (`--visible` with a login profile) still ignores certificate errors, since some of the walled sites it serves have broken chains. Batch fetches also stopped mislabelling results: `arun_many` returns them in completion order, and they were paired with the requested URLs by position.
+- **An OpenAlex outage no longer erases a known retraction.** Only OpenAlex reports retractions; when it errors, `lookup_metadata` falls through to Semantic Scholar, which answers "unknown". `sources score --fresh` (and the ship-time `sources retractions` sweep) wrote that unknown over a stored `is_retracted = 1`, so a retracted citation passed the gate. Unknown now keeps a stored retraction. A stored false is still replaced, since older versions wrote an unchecked false for every S2 result.
- **A run tag is a slug (#116).** `Vault.run_dir()` joined the tag onto `research/runs/` unchecked, and pathlib replaces the base on an absolute segment, so `hpr run init ../../x` or `hpr run init C:/anything` scaffolded a run workspace outside the vault and every later `run` subcommand followed it there. Tags are now validated at that one seam: letters, digits, `-`, `_` and `.`, starting with a letter or digit, which is what `hpr vault-tag` mints. `run`, `levers` and `citecheck` report a bad tag as a clean error instead of a traceback. Same bug class as the `claims ingest --tag` traversal fixed in 0.11.1; exposure is low because the tag comes from the operator or the orchestrating agent, not from fetched content.
- **The builtin provider fetches PDFs (#82, reported by @earldodd).** The PDF lane (`_is_pdf_url` / `_fetch_pdf`) lived inside the crawl4ai provider only, so a vault still on `provider = "builtin"` (the default until `hpr install` switches it) had no PDF handling at all: a direct `.pdf` link was decoded as HTML text and rejected by the junk gate as "Binary PDF garbage in content", identically for every mirror of the same document, and an arXiv `/abs/` link saved the 900-word abstract page instead of the paper. The lane now lives in `web/pdf.py` and both providers use it; the crawl4ai module keeps the old names. The builtin provider also detects a PDF from its bytes when the URL does not look like one. When the PDF lane declines a URL and the HTML fallback turns out to be junk, `hpr fetch -j` now says why the lane declined it (`PDF lane: HTTP 403`, `no extractable text layer`, ...) instead of the generic junk verdict, and the pymupdf document handle is closed on the exception path instead of leaking one per encrypted PDF.
- **`serply` web provider.** Google organic results with page fetch through the same `SERPLY_API_KEY`; opt-in via `[web] provider = "serply"`, no new dependency.
diff --git a/src/hyperresearch/core/scholar.py b/src/hyperresearch/core/scholar.py
index 1bf9416..547389a 100644
--- a/src/hyperresearch/core/scholar.py
+++ b/src/hyperresearch/core/scholar.py
@@ -423,7 +423,7 @@ def score_sources(
conn = vault.db
ttl = vault.config.ranking.api_cache_ttl_days
- query = "SELECT n.id, n.path, n.doi FROM notes n WHERE n.doi IS NOT NULL"
+ query = "SELECT n.id, n.path, n.doi, n.is_retracted FROM notes n WHERE n.doi IS NOT NULL"
params: tuple = ()
if tag:
query += " AND n.id IN (SELECT note_id FROM tags WHERE tag = ?)"
@@ -449,13 +449,23 @@ def score_sources(
missing.append(row["id"])
continue
+ # Only OpenAlex reports retractions. When it errors (5xx, timeout) the
+ # lookup falls through to Semantic Scholar, which answers "unknown".
+ # Unknown must never erase a retraction OpenAlex already reported, or
+ # a --fresh sweep during an outage would wave a retracted citation
+ # through the ship gate. A stored false is not kept: it may be the
+ # unchecked false older versions wrote for S2 results.
+ is_retracted = meta_result["is_retracted"]
+ if is_retracted is None and row["is_retracted"] == 1:
+ is_retracted = True
+
# DB update
conn.execute(
"UPDATE notes SET citation_count = ?, venue = ?, is_retracted = ? WHERE id = ?",
(
meta_result["citation_count"],
meta_result["venue"],
- None if meta_result["is_retracted"] is None else int(meta_result["is_retracted"]),
+ None if is_retracted is None else int(is_retracted),
row["id"],
),
)
@@ -467,11 +477,11 @@ def score_sources(
fm, body = parse_frontmatter(text)
fm.citation_count = meta_result["citation_count"]
fm.venue = meta_result["venue"]
- fm.is_retracted = meta_result["is_retracted"]
+ fm.is_retracted = is_retracted
note_path.write_text(render_note(fm, body), encoding="utf-8")
scored += 1
- if meta_result["is_retracted"]:
+ if is_retracted:
retracted.append(row["id"])
conn.commit()
diff --git a/tests/test_core/test_scholar_enrichment.py b/tests/test_core/test_scholar_enrichment.py
index 8a4c0dd..3fc197b 100644
--- a/tests/test_core/test_scholar_enrichment.py
+++ b/tests/test_core/test_scholar_enrichment.py
@@ -179,6 +179,36 @@ class TestScoreSources:
tmp_vault.db, "", filters=SearchFilters(retraction="not-retracted"),
) == []
+ def test_openalex_outage_keeps_a_known_retraction(self, doi_vault, monkeypatch, no_sleep):
+ from hyperresearch.core.frontmatter import parse_frontmatter
+ from hyperresearch.core.sync import compute_sync_plan, execute_sync
+
+ _stub_openalex(monkeypatch, {"10.1%2Fretracted": OPENALEX_RETRACTED})
+ scholar.score_sources(doi_vault)
+
+ # OpenAlex down on the fresh sweep: the lookup falls through to S2,
+ # which has no retraction data.
+ calls = _stub_openalex(monkeypatch, {
+ "semanticscholar": {"citationCount": 31, "venue": "BadJournal"},
+ })
+ result = scholar.score_sources(doi_vault, fresh=True)
+ assert any("semanticscholar.org" in c for c in calls)
+ assert "retracted-paper" in result["retracted"]
+
+ row = doi_vault.db.execute(
+ "SELECT citation_count, is_retracted FROM notes WHERE id = 'retracted-paper'"
+ ).fetchone()
+ assert row["citation_count"] == 31
+ assert row["is_retracted"] == 1
+ text = (doi_vault.notes_dir / "retracted-paper.md").read_text(encoding="utf-8")
+ assert parse_frontmatter(text)[0].is_retracted is True
+
+ execute_sync(doi_vault, compute_sync_plan(doi_vault, force=True))
+ row = doi_vault.db.execute(
+ "SELECT is_retracted FROM notes WHERE id = 'retracted-paper'"
+ ).fetchone()
+ assert row["is_retracted"] == 1
+
def test_authority_is_vault_relative_percentile(self, doi_vault, monkeypatch):
_stub_openalex(monkeypatch, {
"10.1%2Fcited": OPENALEX_CITED, # 512 citations