| 1 | # 0010 · An unnamed relation stays empty |
| 2 | |
| 3 | - **Status**: Implemented · `facts.predicate_id` is nullable, `related_to` is gone, display |
| 4 | falls back to the source's wording through `fact_surface_predicate(uuid)`, guarded by |
| 5 | `no_predicate_still_shows.rs` · both `mapped_to` follow-ups done with |
| 6 | [0011](0011-a-mapping-is-not-a-fact.md) (#126); the seed table and |
| 7 | `ensure_default_ontology` left with #128 · the two pieces of dead code noted 2026-09-02 are |
| 8 | cleared |
| 9 | - **Written**: 2026-08-30 (undated in the original; the day its migration ran) · condensed |
| 10 | into English 2026-09-03 |
| 11 | - **Related**: [0009](0009-no-type-is-a-type.md) the twin on the type side; |
| 12 | [0001](0001-ontology-import-and-governance.md) holds the sentence this record overturns; |
| 13 | [0011](0011-a-mapping-is-not-a-fact.md) takes `mapped_to` the rest of the way |
| 14 | |
| 15 | ## The problem |
| 16 | |
| 17 | `related_to` encoded "the extractor found an edge but the ontology has no matching relation" |
| 18 | — a program state. Yet it sat in `relation_types` as a `builtin` relation, listed on the |
| 19 | ontology page beside `acquired` and `works_at`, as though someone had decided the relation |
| 20 | between the two things is called "related". Nobody had. |
| 21 | |
| 22 | The cost was measured before deleting it: in one 348-chunk KB, 533 facts hung on it and |
| 23 | every one displayed as 有关联, while every one also carried the source's wording in |
| 24 | `fact_evidence.proposed_predicate`. The meaning was in the database all along, covered by a |
| 25 | fake vocabulary word. |
| 26 | |
| 27 | ## Decisions |
| 28 | |
| 29 | 1. **`facts.predicate_id` becomes nullable and `related_to` is deleted.** The reader sees |
| 30 | more: on a real corpus (14,706 facts, 5,934 on `related_to`), 93 graph edges that all |
| 31 | read "related" now read `placed_pressure_on` / `agreed_to_resign` / `countersued` / |
| 32 | `revived_legal_action` / `license_from`. |
| 33 | 2. **Display falls back to the source's wording through one SQL function, |
| 34 | `fact_surface_predicate(uuid)`.** The most frequent wording wins, ties by lexical order — |
| 35 | the rule `predicate_match::merge_key` uses, and deterministic, so one edge has one name |
| 36 | on the graph, in the panel and in the history. Only 3.0% of facts (16 of 533) had more |
| 37 | than one wording. One function rather than a subquery in each of the eight read paths: |
| 38 | eight copies diverge, and divergence here means different names on different pages. |
| 39 | 3. **The reader must see where a word comes from**, or the lie is retold another way. Rows |
| 40 | carry `inferred`: edges outside the ontology are drawn in a lighter gray; the panel and |
| 41 | document output say on hover "not in the ontology; this is the source's wording"; facts |
| 42 | with neither show an italic "unnamed relation" — never a made-up word. |
| 43 | 4. **Data changed in place, no migration path.** The database held test data before release. |
| 44 | Once users have run for half a year, 0001's "only new extractions; rebuild the backlog" |
| 45 | applies again. |
| 46 | 5. **`mapped_to` follows.** Only `related_to` was excluded from the prompt, so the model |
| 47 | used `mapped_to` (entity → data-source schema) on entity↔entity pairs 41 times. It leaves |
| 48 | the prompt, then `relation_types` altogether ([0011](0011-a-mapping-is-not-a-fact.md)): |
| 49 | the same error, control flow written as vocabulary. The `FALLBACK_RELATION_*` constant |
| 50 | and branches, the `extraction_drops` reason "no fallback relation", and the "fallback |
| 51 | predicate" wording went with it. |
| 52 | |
| 53 | ## Dead ends |
| 54 | |
| 55 | - **0001's sentence "`related_to` is honest vagueness; a wrong guess is confident error."** |
| 56 | The second half stands, the first is wrong. Staying at "I don't know" is more honest than |
| 57 | guessing — but implementing that honesty as a word in the ontology turned it into an |
| 58 | **assertion**: a relation displayed as "related" claims such a relation exists. The honest |
| 59 | expression is empty, next to "the source said `acquired`". 0001's aside "(kept in the |
| 60 | ontology as the code-level fallback)" is void: the fallback now happens at read time. |
| 61 | - **Twenty inner joins the compiler cannot see.** Once the column is nullable, every `JOIN |
| 62 | relation_types` on a read path is a silent filter; `cargo check` and clippy say nothing — |
| 63 | the same three-valued trap as 0009's `NULL <> uuid`. Eleven became `LEFT JOIN` plus |
| 64 | fallback; six were already right (four filter by `r.key`, two read `functional` / |
| 65 | `temporal`). Three misses were caught by the database and none by the compiler (an |
| 66 | `r.label` without COALESCE, an `f.id` referenced outside its CTE, a stale `rt.id`), plus |
| 67 | two mis-numbered placeholders — the eighth time "SQL is invisible to the compiler" in this |
| 68 | repository, so DB tests are not optional when SQL strings change. The most expensive miss: |
| 69 | `fact_snapshot` through an inner join returned `None`, so rejecting a predicate-less fact |
| 70 | would have left no ledger entry — and the ledger exists so the record survives the fact. |
| 71 | - **420 legacy exceptions.** Of 5,934 fallback facts, 420 have no source wording, all from |
| 72 | the two oldest KBs (`Industry Corpus` 275, `General` 145), before `add_evidence` recorded |
| 73 | `proposed_predicate` unconditionally. They now display empty; they used to display |
| 74 | "related" — zero information either way. |
| 75 | - **End-to-end on the full clone**: 5,934 facts go NULL and 5,514 recover their wording; |
| 76 | graph 457 edges — 364 ontology, 93 wording, 0 unnamed; rejecting a predicate-less fact |
| 77 | leaves a self-contained snapshot in the decision ledger. `no_predicate_still_shows.rs` |
| 78 | guards the line: a fact with no predicate must be visible on every read path, and turning |
| 79 | any `LEFT JOIN relation_types` back into `JOIN` makes it red (both controls verified). |
| 80 | |
| 81 | ## Revisions |
| 82 | |
| 83 | - 2026-08-30: we deleted the data, not the code, and it grew back in seven minutes. |
| 84 | Migration 0052 deleted the `relation_types` **row**; the seed was code |
| 85 | (`DEFAULT_RELATION_TYPES`), and `ensure_default_ontology` ran at KB creation, on the |
| 86 | ontology page and at every extraction — 0052 applied at 17:54, `bench demo-autoextend` |
| 87 | re-created a `builtin=true` row at 18:01. Worse, 0052 also dropped the prompt's exclusion |
| 88 | filter on the premise "no row now, so the escape hatch and the reminder disappear |
| 89 | together"; the premise was false, so `related_to` was listed in the prompt for the first |
| 90 | time — and 0001 had measured that of 359 uses, 321 were the model picking from the list. |
| 91 | The two must change together; changing one is worse than neither. (#128 removed the |
| 92 | function and the seed table; regrowth is now impossible.) |
| 93 | - 2026-08-30: the guard assertion was empty. `SELECT count(*) FROM relation_types WHERE key |
| 94 | = 'related_to' AND builtin` passed because the fixture built the KB with raw SQL and never |
| 95 | called `ensure_default_ontology` — asserting on bare ground. The test now seeds first, and |
| 96 | the control was verified (adding `related_to` back to the seed table turns it red). |
| 97 | - 2026-09-02: two pieces of dead code. `graph.rs` `confirmed_mappings()` had zero callers |
| 98 | (chat reads `mappings::confirmed`), and the `r.key = 'mapped_to'` join in `confirm_fact` |
| 99 | matched zero rows. Both removed since (0016 A3). |