Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
dd96f29
test: pin the K251770 two-hop recall case to the shipped graph and ca…
Asembris Nov 23, 2026
ba1d1f2
feat: contrast depth-1 and depth-2 verdicts in the investigation when…
Asembris Nov 23, 2026
d55a07d
feat: link the two-hop K251770 discovery from the landing hero and pa…
Asembris Nov 23, 2026
c0730bc
docs: add the two-hop K251770 discovery and its depth contrast to the…
Asembris Nov 23, 2026
6353d78
fix: skip depth-contrast queries when a direct predicate already rais…
Asembris Nov 23, 2026
38d9930
test: cover the two-hop journey, evidence links and depth rules in Pl…
Asembris Nov 23, 2026
abe82de
build: rebuild web/dist for the two-hop showcase
Asembris Nov 23, 2026
521e991
fix: refresh the depth contrast after each reassessment and drop supe…
Asembris Nov 23, 2026
98c892f
test: verify the depth contrast follows a rejected REMstar citation path
Asembris Nov 23, 2026
59b0d7e
build: rebuild web/dist for the depth contrast refresh fix
Asembris Nov 23, 2026
2e61574
feat: return the reviewed citation's authoritative graph state from t…
Asembris Nov 23, 2026
3623f00
test: cover the review API citation record, including reviews of an e…
Asembris Nov 23, 2026
1fcb3a4
fix: show the reviewed citation from the graph in the provenance draw…
Asembris Nov 23, 2026
37c48a9
test: seed an outdated review and cover drawer reject, confirm and re…
Asembris Nov 23, 2026
5f5614d
build: rebuild web/dist for the provenance review-state fix
Asembris Nov 23, 2026
f674df2
test: run the outdated-review Playwright test on its own freshly seed…
Asembris Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[![Data: openFDA, cached](https://img.shields.io/badge/data-openFDA_·_cached_offline-e7a948?style=flat-square&labelColor=0b1322)](data/PROVENANCE.md)
[![License: MIT](https://img.shields.io/badge/license-MIT-f1ebdd?style=flat-square&labelColor=0b1322)](LICENSE)

**[The discovery](#the-discovery)** · **[Judge walkthrough](#judge-walkthrough)** · **[Why Relate](#why-relate)** · **[Architecture](#architecture)** · **[Results](#results-honestly)** · **[Docs](#go-deeper)**
**[The discovery](#the-discovery)** · **[Two hops deep](#two-hops-deep)** · **[Judge walkthrough](#judge-walkthrough)** · **[Why Relate](#why-relate)** · **[Architecture](#architecture)** · **[Results](#results-honestly)** · **[Docs](#go-deeper)**

</div>

Expand All @@ -41,6 +41,33 @@ Every value in this table is asserted against the shipped store by [`tests/test_

**Why it matters.** FDA's September 2023 draft guidance on [selecting a predicate device](https://www.fda.gov/regulatory-information/search-fda-guidance-documents/best-practices-selecting-predicate-device-support-premarket-notification-510k-submission) recommends predicates without design-related recalls. [Kadakia et al. (JAMA 2023)](https://pubmed.ncbi.nlm.nih.gov/36625810/) found that devices cleared using predicates with Class I recalls had a 6.4× higher risk (RR 6.40, 95% CI 3.59–11.40) of a Class I recall of their own. Forebear is for the regulatory or quality engineer who has to check that before citing a predicate.

## Two hops deep

BreathePal's predicate carries the recall itself, so a one-hop lookup already finds it. **SleepRes PAP System (K251770) is the case where only the graph does.** Its own predicate, the DreamStation 2, has no recall in the shipped FDA records. That predicate's predicates do: two REMstar clearances that FDA lists on Class I design recall **Z-1974-2021**.

| Query depth | What it walks | Verdict for K251770 |
| --- | --- | --- |
| **1 generation** | K251770 → K200480 (no recall on file) | `NO_DESIGN_RECALL_SIGNAL`, marked **provisional** because grand-predicates were not traversed |
| **2 generations** | K251770 → K200480 → K130077 and K131982, both on Z-1974-2021 | `REVIEW_LINEAGE`, evidence complete |

| | Evidence | Source |
| --- | --- | --- |
| **Candidate** | K251770 · SleepRes PAP System · Sleepres, Inc. · cleared 2025-12-15 | [FDA summary PDF](https://www.accessdata.fda.gov/cdrh_docs/pdf25/K251770.pdf#page=5) |
| **Hop 1** | p. 5: *"Predicate Device: Philips DreamStation 2 - K200480"* | same PDF, page 5 |
| **Predicate** | K200480 · DreamStation 2 System · Respironics · cleared 2020-07-10 | [FDA summary PDF](https://www.accessdata.fda.gov/cdrh_docs/pdf20/K200480.pdf#page=4) |
| **Hop 2** | p. 4: *"Primary Predicate Device: REMSTAR AUTO A-FLEX HT (K131982)"*, *"Secondary Predicate Device: REMSTAR SE (K130077)"* | K200480 PDF, page 4 |
| **Recall** | Z-1974-2021 · event 88058 · Class I · Device Design · initiated 2021-06-14 (PE-PUR foam). FDA's record lists K130077 and K131982, not K200480 | [FDA recall Z-1974-2021](https://www.accessdata.fda.gov/scripts/cdrh/cfdocs/cfRES/res.cfm?id=187815) |

The recall began after the DreamStation 2 was cleared and 4 years 6 months before SleepRes was. The investigation page shows both depths side by side (*Why the graph matters*), with each hop's quote, a link to the FDA PDF at the cited page, and the recall record. The same simplified query as [below](#why-relate), with `*1..1` and then `*1..2`:

```text
*1..1 (no rows)
*1..2 ['K251770', 'K200480', 'K131982'] Z-1974-2021 2021-06-14
['K251770', 'K200480', 'K130077'] Z-1974-2021 2021-06-14
```

Every value here, including both verdicts and both query results, is asserted against the shipped store and the cached FDA page text by [`tests/test_two_hop_story.py`](tests/test_two_hop_story.py). As with BreathePal, FDA attributes the recall to product families that list these clearances; it is a question for the predicate rationale, not a finding that SleepRes is unsafe.

## Judge walkthrough

No API key, external database or other service is needed: the graph and the web build are committed. Pick one way to run it.
Expand All @@ -67,10 +94,11 @@ powershell -ExecutionPolicy Bypass -File .\run.ps1

1. **Watch the thread.** A short opening film follows K252078 → K113053 → the 2021 Class I recall (Skip or Esc ends it). Deep link: [`#/check/K252078`](http://127.0.0.1:8765/#/check/K252078).
2. **Investigate K252078.** The verdict is **Review lineage**. Open the evidence graph or its *Timeline* mode: the recall diamonds sit *before* BreathePal's clearance.
3. **Open the evidence.** Select any thread for its verbatim quote, a link to the FDA PDF at the cited page, and the PDF's SHA-256. *What needs human review* lists every uncertainty.
4. **Write to the graph.** Click **Save assessment to graph**. Under *What K252078 cites*, reject the edge: the lineage and verdict change at once and the saved assessment is marked **stale**. Restore it.
5. **Trace recall reach.** Open **Recall reach** for [`88058,88071`](http://127.0.0.1:8765/#/reach/88058,88071), the Philips recall filed as two openFDA events: 14 recalled clearances, 26 later devices descend from them, 8 of those were cleared after the recall on their own lineage began.
6. **Optional, needs internet.** **Add a clearance** fetches an out-of-family ancestor's summary from FDA into `data/live/` and extends the tree.
3. **See what one more hop finds.** On the landing page, click **Two hops deep** under the hero (or open [`#/check/K251770`](http://127.0.0.1:8765/#/check/K251770)). *Why the graph matters* puts depth 1 (**No design-recall signal · provisional**) next to depth 2 (**Review lineage**, Class I design recall Z-1974-2021), with a PDF link at the cited page for each hop.
4. **Open the evidence.** Select any thread for its verbatim quote, a link to the FDA PDF at the cited page, and the PDF's SHA-256. *What needs human review* lists every uncertainty.
5. **Write to the graph.** Click **Save assessment to graph**. Under *What K252078 cites*, reject the edge: the lineage and verdict change at once and the saved assessment is marked **stale**. Restore it.
6. **Trace recall reach.** Open **Recall reach** for [`88058,88071`](http://127.0.0.1:8765/#/reach/88058,88071), the Philips recall filed as two openFDA events: 14 recalled clearances, 26 later devices descend from them, 8 of those were cleared after the recall on their own lineage began.
7. **Optional, needs internet.** **Add a clearance** fetches an out-of-family ancestor's summary from FDA into `data/live/` and extends the tree.

<details>
<summary><b>Manual setup, checks and the browser suite</b></summary>
Expand Down
6 changes: 6 additions & 0 deletions docs/UX_EXPERIENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ the favicon.
plain-language finding sentence, built only from the assessment payload. It names the page, the recall class, the root
cause, the start date, and how long before the clearance the recall began. Coverage chips show evidence completeness,
ancestors, unread summaries, doubtful links, conditional signals, and a jump link to the review queue.
- **Why the graph matters** (only when depth changes the verdict). The same deterministic rules run at depth 1 and
depth 2, side by side, joined by a *+1 hop* thread. Shown only when the depth-1 verdict differs and every strong
signal sits at generation 2 or deeper, so it never appears for a case like K252078 whose direct predicate already
carries the recall. Below the two verdicts, each hop is listed with a quote excerpt centred on the cited K-number, a
link to the FDA PDF at that page, and its provenance drawer, then the recall record. The shipped example is K251770
(`#/check/K251770`); the landing page links to it under the hero as *Two hops deep*.
- **Critical chain.** The route that raised the verdict, as cards joined by status-coded threads. Each card and each
thread opens its provenance.
- **Evidence graph.** Generation columns that fit the panel width. Status-coded threads, and nodes coloured by recall
Expand Down
9 changes: 7 additions & 2 deletions forebear/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .ingest import IngestError
from .investigation import runner as inv_runner
from .investigation import store as inv_store
from .lineage import assess, compare, date_relation, recall_attribution, recall_reach
from .lineage import assess, citation_state, compare, date_relation, recall_attribution, recall_reach

agent.load_env()
use_live_cache() # live ingests never touch the committed data/raw cache
Expand Down Expand Up @@ -265,12 +265,17 @@ class ReviewIn(BaseModel):
@app.post("/api/citation/review")
async def review(body: ReviewIn):
src, dst = _norm_k(body.src), _norm_k(body.dst)
r = await run(lambda g: g.review_citation(src, dst, body.status, body.note, reviewer=body.via))

def write(g): # the review and the edge's new state are read in one store call
r = g.review_citation(src, dst, body.status, body.note, reviewer=body.via)
return r and r | {"citation": citation_state(g.citation_edge(src, dst))}
r = await run(write)
if r is None:
raise HTTPException(404, f"No citation {src} -> {dst}")
return r



class TriageIn(BaseModel):
src: str
dst: str
Expand Down
12 changes: 12 additions & 0 deletions forebear/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,18 @@ def set_triage(self, src: str, dst: str, label: str, quote: str, model: str) ->
{"src": src, "dst": dst, "label": label, "quote": quote, "model": model})
return rows[0] if rows else None

def citation_edge(self, src: str, dst: str) -> dict | None:
"""The full current state of one citation edge, in the shape lineage hops use, plus how the lineage rules
treat it now. The authoritative record a client shows after reviewing the edge."""
rows = self.q(
f"""MATCH (a:Device {{k:$src}})-[r:CITES]->(b:Device {{k:$dst}})
RETURN {{{_HOP_FIELDS}}} AS hop, ({LINEAGE_EDGE}) AS in_lineage, ({ADVISORY_EDGE}) AS advisory,
toString(r.retired_at) AS retired_at""", {"src": src, "dst": dst})
if not rows:
return None
r = rows[0]
return r["hop"] | {"in_lineage": bool(r["in_lineage"]), "advisory": bool(r["advisory"]), "retired_at": r["retired_at"]}

def citation(self, src: str, dst: str) -> dict | None:
rows = self.q("""MATCH (a:Device {k:$src})-[c:CITES]->(b:Device {k:$dst})
RETURN c.kind AS kind, c.snippet AS snippet""", {"src": src, "dst": dst})
Expand Down
11 changes: 11 additions & 0 deletions forebear/lineage.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,17 @@ def trust(h: dict) -> str:
return "uncertain" if doubt(h) else "extracted"


def citation_state(h: dict | None) -> dict | None:
"""One citation edge (graph.citation_edge) labelled as the lineage rules treat it now: 'retired', 'advisory', a
trusted hop's trust() ('human_verified', 'extracted' or 'uncertain'), or None when it is out of lineage (rejected
by a person or removed by the audit)."""
if h is None:
return None
label = ("retired" if h.get("retired_at") else "advisory" if h.get("advisory")
else trust(h) if h.get("in_lineage") else None)
return h | {"trust": label}


def advisory_basis(h: dict) -> list[str]:
"""Which automated sources call an untrusted citation a predicate."""
out = []
Expand Down
11 changes: 11 additions & 0 deletions tests/test_api_journey.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,14 @@ def test_phase35_source_corrected_assessments(client):
assert {c["dst"]: c["kind"] for c in rt045["citations"]} == {
"K060044": "predicate", "K130328": "reference", "K023135": "reference",
}


def test_review_returns_the_authoritative_citation(client):
r = client.post("/api/citation/review", json={"src": "K200480", "dst": "K131982", "status": "rejected"}).json()
c = r["citation"]
assert (c["src"], c["dst"], c["review"], c["reviewer"], c["trust"], c["in_lineage"]) == \
("K200480", "K131982", "rejected", "user", None, False)
assert c["page"] == 4 and c["reviewed_source_sha256"] == c["source_sha256"] and len(c["source_sha256"]) == 64
c = client.post("/api/citation/review", json={"src": "K200480", "dst": "K131982", "status": ""}).json()["citation"]
assert (c["review"], c["trust"], c["in_lineage"]) == (None, "extracted", True)
assert client.post("/api/citation/review", json={"src": "K200480", "dst": "K999999", "status": ""}).status_code == 404
31 changes: 30 additions & 1 deletion tests/test_summary_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest

from forebear import ingest, summaries
from forebear.lineage import assess, doubt
from forebear.lineage import assess, citation_state, doubt

K = "K261000"
URL_PATH = f"/cdrh_docs/pdf26/{K}.pdf"
Expand Down Expand Up @@ -220,3 +220,32 @@ def test_a_citation_restored_from_the_reviewed_pdf_keeps_its_review(tiny, fda):
ingest.add_clearance(tiny, K, refresh=True)
h = _hop(tiny, "K000003")
assert h["reviewed_source_sha256"] == h["source_sha256"] and doubt(h) == []


# ---------------------------------------------------------------- the record a client shows after a review
def test_citation_state_reports_an_outdated_review_until_it_is_redone(tiny, fda):
ingest.add_clearance(tiny, K)
tiny.review_citation(K, "K000009", "confirmed", "read v1 p.1", reviewer="user")
c = citation_state(tiny.citation_edge(K, "K000009"))
assert (c["review"], c["reviewer"], c["trust"]) == ("confirmed", "user", "human_verified")
assert c["reviewed_source_sha256"] == c["source_sha256"] and c["in_lineage"] and not c["advisory"]

fda.pdf = make_pdf(V2)
ingest.add_clearance(tiny, K, refresh=True)
c = citation_state(tiny.citation_edge(K, "K000009"))
assert c["review"] == "confirmed" and c["reviewed_source_sha256"] != c["source_sha256"]
assert c["trust"] == "uncertain" and "review_outdated" in doubt(c)

tiny.review_citation(K, "K000009", "confirmed", "read v2 p.1", reviewer="user")
c = citation_state(tiny.citation_edge(K, "K000009"))
assert c["trust"] == "human_verified" and c["reviewed_source_sha256"] == c["source_sha256"]


def test_citation_state_labels_rejected_and_cleared_edges(tiny):
tiny.review_citation("K000005", "K000004", "rejected", None, reviewer="user")
c = citation_state(tiny.citation_edge("K000005", "K000004"))
assert (c["review"], c["in_lineage"], c["trust"]) == ("rejected", False, None)
tiny.review_citation("K000005", "K000004", "", None, reviewer="user")
c = citation_state(tiny.citation_edge("K000005", "K000004"))
assert (c["review"], c["in_lineage"], c["trust"]) == (None, True, "extracted")
assert citation_state(tiny.citation_edge("K000005", "K000001")) is None
Loading
Loading