| 1 | # 0017 · A contradiction points at an error upstream |
| 2 | |
| 3 | - **Status**: implemented · B2a (#238): engine and queue — `derive::contradictions`, migration 0020, the Review card with clues and repairs · B2b: contested edges in the alert colour and ghost edges for blocked derivations on the graph, the disputed chip on panel rows, the "did not land" section of the Derived tab with its proof chain · B2 of 0016, wider than the one line written there: contradictions become visible everywhere, not only as a new kind in the queue |
| 4 | - **Written**: 2026-09-03 (conventions in [README](README.md)) |
| 5 | - **Related**: the two unbuilt rows of the "derived vs asserted" table in [0002](0002-reasoning-engine.md) §2; [0016](0016-close-the-open-seams-before-cutting-new-ones.md) B2; the proof chain (B1, #227) supplies the "premises expand to the sentence" half of the card below |
| 6 | |
| 7 | > This record changes one phrase in 0002. There, a contradiction "goes to Review for a ruling". |
| 8 | > In discussion (2026-09-03) it became clear what a person actually does when two edges |
| 9 | > disagree: follow the signal to **where something went wrong upstream** — a fact went |
| 10 | > stale, extraction misread, resolution merged the wrong pair, the ontology is too strict. |
| 11 | > So this queue is built as an audit, and every button is a repair. |
| 12 | |
| 13 | ## The problem |
| 14 | |
| 15 | R1 derivation only yields to "this exact triple is already asserted". It does not consult |
| 16 | axioms: `part_of` transitivity derives `A part_of C` while the ledger asserts `C part_of A` |
| 17 | (asymmetric); `ceo_of` is functional and `Acme ceo_of Zhang San` is asserted, yet the |
| 18 | engine still lands `Acme ceo_of Li Si`. R0 scans `facts` only, derivations live in their |
| 19 | own table, so this class of contradiction is **invisible on both sides**: absent from |
| 20 | Review, absent from the graph. |
| 21 | |
| 22 | It is not the only invisible class. Temporal conflicts and axiom violations are known to |
| 23 | the Review page alone; on the graph and in the entity panel a contested edge looks exactly |
| 24 | like any other. |
| 25 | |
| 26 | ## Criteria |
| 27 | |
| 28 | 1. **A contradiction points at an error upstream.** The error is in one of four places: |
| 29 | stale knowledge (most common), a misread extraction, a wrong merge, an over-strict |
| 30 | ontology. The interface's job is to lay out the clues and offer the repairs. |
| 31 | 2. **Write less to the graph rather than write wrong** (0002). A derivation that hits a |
| 32 | contradiction does not land; when two derivations collide, neither lands. |
| 33 | 3. **Anything reported item by item needs an upper bound.** Only "one assertion against one |
| 34 | concrete edge" — a volume that can be predicted — goes into the queue individually, and |
| 35 | with a per-predicate cap; whatever is produced in batches is aggregated by its cause. |
| 36 | 4. **A disputed fact is visible where it sits.** The assertion stays live, but someone |
| 37 | passing it on the graph or in the panel should see that it is questioned, and reach the |
| 38 | place to fix it in one step. |
| 39 | |
| 40 | ## Decisions |
| 41 | |
| 42 | ### 1. Detection: two tiers, pure logic in `utopia-reason` |
| 43 | |
| 44 | `derive::contradictions(derived, edges, axioms)` checks every derivation against the axioms |
| 45 | of its predicate, once against assertions and once against other derivations: |
| 46 | |
| 47 | | Axiom | What counts as a contradiction | |
| 48 | |---|---| |
| 49 | | functional | same subject and predicate, different object, **validity intervals overlap** (Mira leaving and Devin taking over is a succession; the half-open interval semantics of `validity` are reused) | |
| 50 | | inverse_functional | the dual | |
| 51 | | asymmetric | the reverse edge exists with overlapping validity | |
| 52 | | irreflexive | the derivation is a self-loop | |
| 53 | |
| 54 | **Derived vs asserted**: per item. The derivation does not land; one `axiom_violations` |
| 55 | row of kind `derived_contradiction`. Capped per predicate (same shape as R1's |
| 56 | `MAX_DERIVED_PER_PREDICATE`; 50 suggested); the overflow stays out of the queue and is |
| 57 | counted in the report. |
| 58 | |
| 59 | **Derived vs derived**: aggregated. The cause is a rule set that contradicts itself — |
| 60 | `ceo_of ⊑ works_at` together with `works_at` functional necessarily produces contradictions |
| 61 | in batches. Queuing every pair would flood Review, and a person facing a hundred identical |
| 62 | "two derivations disagree" cards cannot decide anything from them. So one row per **pair of |
| 63 | rules** goes into `ontology_defects`, kind `rules_disagree`, recording both rules, the |
| 64 | count, and two or three examples. It is the dynamic form of the existing static defects |
| 65 | `transitive_and_functional` and `symmetric_and_asymmetric`: invisible in the declarations, |
| 66 | surfacing once data arrives. Neither derivation lands. |
| 67 | |
| 68 | `run()` (R0) and `materialize` (R1) share the one function: R0 already holds the edges and |
| 69 | axioms and adds a `derive` + `contradictions` pass to report; R1 uses the same result to |
| 70 | decide what stays unlanded. **Both must compute it** — otherwise R0's "clear open rows not |
| 71 | recomputed this round" would sweep away what R1 wrote. |
| 72 | |
| 73 | ### 2. The Review card: lay out the clues, lay out the repairs |
| 74 | |
| 75 | **The derived-vs-asserted card**, three parts: |
| 76 | |
| 77 | 1. **The contradiction itself**: the derived edge (rule, premise chain expandable to the |
| 78 | sentence — from B1) beside the asserted edge (evidence quote, interval, confidence). |
| 79 | Most errors are visible at a glance. |
| 80 | 2. **A diagnostic hint**, one line when a clue can be computed, none when it cannot: |
| 81 | - the assertion has no end date and the derivation starts after it → "looks stale: did |
| 82 | Zhang San's tenure end in 2024-07?" |
| 83 | - an entity on either side has same-name neighbours (the existing `same_name` machinery) |
| 84 | → "looks like a wrong merge: are these two Acmes one company?" |
| 85 | - the assertion's confidence is below 0.75 → "the extraction was unsure to begin with" |
| 86 | - none of the above → "read both sentences" |
| 87 | 3. **Actions that are repairs**, all on existing endpoints; once a repair is made the |
| 88 | violation clears on the next recomputation, with no separate resolve step: |
| 89 | |
| 90 | | Action | What it repairs | Where it lands | |
| 91 | |---|---|---| |
| 92 | | Close the assertion at a date | stale knowledge | `POST /facts/{id}/close` (same as the temporal-conflict queue, with a date input) | |
| 93 | | Retract the assertion | misread extraction / wrong merge | `reject_fact`, append-only | |
| 94 | | Go to possible duplicates | wrong merge | the Duplicates queue in Review | |
| 95 | | The ontology is too strict | wrong definition | the relation on the Ontology page | |
| 96 | | Both hold; let the derivation through | the world is like that | `resolution = accepted`; the next `materialize` lets that pair land | |
| 97 | |
| 98 | **The derived-vs-derived card** (in the ontology-defects queue): "these two declarations |
| 99 | together produced N contradicting pairs; examples below — usually a sub-property attached |
| 100 | in the wrong place, or a functional declaration that is too strict". Two actions: go to the |
| 101 | Ontology page and change a declaration; or "accept" (contradicting derivations from this |
| 102 | pair of rules never land and are not reported again). Both sides are derived and the |
| 103 | assertions beneath may each be right, so there is no "the data is wrong" here; "both hold" |
| 104 | would mean giving up the meaning of functional, which belongs on the Ontology page, so |
| 105 | there is no such button either. |
| 106 | |
| 107 | ### 3. Disputed facts are visible where they sit |
| 108 | |
| 109 | "Disputed" becomes one status with three sources: open temporal conflicts |
| 110 | (`fact_conflicts`), open axiom violations (`axiom_violations`, including the new kind), and |
| 111 | blocked derivations (the `detail` of `derived_contradiction` rows). B2 makes it a first-class |
| 112 | state of the browse pages and wires up the first two sources along the way — they are |
| 113 | equally invisible today. |
| 114 | |
| 115 | **Rows in the entity panel**: `EntityFact` already carries `stale` and `corrected`; a third |
| 116 | flag `contested: Option<Contest { kind, ref_id }>` is computed with one EXISTS. The chip |
| 117 | reads "disputed"; hover gives one sentence ("derived works_at Li Si contradicts this"); |
| 118 | click goes to the matching Review item. The row is not dimmed: the assertion is still live. |
| 119 | |
| 120 | **The Derived tab of the panel**: a new section, "derivations that did not land", read from |
| 121 | `axiom_violations.detail`, each row naming what blocked it and expanding to its premise |
| 122 | chain. Here a person sees "the engine could have drawn this edge, and what stopped it". |
| 123 | |
| 124 | **Edges on the graph**: |
| 125 | |
| 126 | - A contested assertion switches to the **alert color**, edge and all, with no reliance on |
| 127 | a node ring. The request was explicit: a ring sits on the node while the edge stays gray, |
| 128 | and peripheral vision cannot tell them apart. |
| 129 | - A blocked derivation is drawn as a **ghost edge**: the same hue mixed toward `EDGE_DIM` |
| 130 | (under premultiplied blending alpha cannot darken an edge; only the RGB can be mixed — see |
| 131 | the note at `EDGE_DIM`), thinner. It follows the Derived toggle; clicking it opens the |
| 132 | entity panel at that row. sigma's default edge program does not draw dashes, and no custom |
| 133 | program is introduced for this. |
| 134 | - The hover label chip gets a "⚠" prefix, and the tooltip states the dispute. |
| 135 | |
| 136 | **Color**: one new token, `--u-contest`, set to **#ff6a3d** (hot coral orange). It has to |
| 137 | stand apart from three colors already in use: derived edges are gold |
| 138 | (`rgb(231,197,124)`), warning chips are amber (`--u-warn` #f2b66d, too close to gold to |
| 139 | double as an edge color), and danger is pink (`--u-danger` #ff9daf, reserved for |
| 140 | destructive actions). Coral orange is bright enough on the dark ground, its hue is far from |
| 141 | all three, and it is no common type color (the type palette leans blue, green and violet). |
| 142 | Edge color `rgba(255,106,61,0.55)`; ghost edge `lerp(#ff6a3d, EDGE_DIM, 0.55)`. This is |
| 143 | the only new color; chips on the Ontology and Review pages use the same token. |
| 144 | |
| 145 | ### 4. Data |
| 146 | |
| 147 | Migration `0020` (0019 was taken by #199 / #233): |
| 148 | |
| 149 | - `axiom_violations.kind` CHECK gains `derived_contradiction` |
| 150 | - `axiom_violations` gains `detail JSONB NOT NULL DEFAULT '{}'`: the derived triple (three |
| 151 | ids and three names), the rule kind, the premise ids — without it the interface cannot |
| 152 | say what was derived; `path` holds the premises for the proof chain but cannot draw the |
| 153 | ghost edge |
| 154 | - `axiom_violations.resolution` CHECK gains `fact_closed` (closing an assertion is a repair |
| 155 | that leaves its own trace, kept apart from `fact_retracted`) |
| 156 | - `ontology_defects.kind` CHECK gains `rules_disagree`, plus `detail JSONB` (both rules, the |
| 157 | count, the examples) |
| 158 | |
| 159 | `left_fact` / `right_fact` stay non-null and keep pointing at `facts`: for derived vs |
| 160 | asserted, `left` is the contradicted assertion and `right` the derivation's last premise; |
| 161 | `rules_disagree` does not live in this table. |
| 162 | |
| 163 | ### 5. Interfaces |
| 164 | |
| 165 | - `GET /kbs/{id}/graph`: edges gain `contested: bool`; a new class of edge with |
| 166 | `blocked: true` (the ghosts) |
| 167 | - `GET /kbs/{id}/entities/{id}`: `facts[].contested`; `blocked: [...]` next to `derived` |
| 168 | - Review `violations` queue: rows gain `detail` and `hint` (the diagnostic as a code; wording |
| 169 | belongs to the frontend) |
| 170 | - `POST /kbs/{id}/review/violations/{id}`: `resolution` gains `fact_closed` (with |
| 171 | `close_at`); the server calls `close_fact` and then marks the row resolved |
| 172 | |
| 173 | ### 6. Tests |
| 174 | |
| 175 | - `utopia-reason` unit tests: one per axiom, non-overlapping intervals are no contradiction, |
| 176 | derived-vs-derived aggregates by rule pair, the cap is counted |
| 177 | - Store integration: a functional assertion stands and a derivation collides → the |
| 178 | derivation stays out and one violation carries `detail`; retract the assertion and rerun → |
| 179 | the derivation lands and the violation clears; `accepted` → both coexist; `fact_closed` |
| 180 | runs the close path; R0 and R1 agree |
| 181 | - Browser: an edge turns coral, ghost edges follow the toggle, the panel chip jumps to the |
| 182 | Review item, the Review card shows three parts and five actions |
| 183 | |
| 184 | ## Two cuts |
| 185 | |
| 186 | **B2a · engine and queue**: §1, §2, §4, and the Review parts of §5, with the integration |
| 187 | tests. Two days. |
| 188 | **B2b · visibility**: §3 plus the graph and panel interfaces, wiring existing temporal |
| 189 | conflicts and axiom violations along the way. A day and a half. |
| 190 | |
| 191 | B1 (#227) merges first after a rebase; B2a branches from it. |
| 192 | |
| 193 | ## Open questions |
| 194 | |
| 195 | - **The per-predicate cap of 50 is a guess**, awaiting a bench number like R1's twenty |
| 196 | thousand. |
| 197 | - **Granularity of `accepted`**: per pair (one derivation against one assertion). An |
| 198 | assertion hit by several derivations needs several clicks; aggregating the exemption per |
| 199 | assertion would generalize "this axiom does not apply to this assertion" too far. Per |
| 200 | pair first, measure later. |
| 201 | - **Could ghost edges be too many?** Their number is bounded by the (capped) violation |
| 202 | count, so it should stay manageable; failing that, draw them only when a related node is |
| 203 | selected. |
| 204 | - **Does the disputed status need its own SSE event?** The `review` event is already sent; |
| 205 | graph and panel can refetch on it. No new event. |