World's first open-source enterprise world model.
Rust agent-memorybitemporalgraphragknowledge-baseknowledge-graphllmontologypgvectorpostgresqlragrustself-hostedsemantic-searchtemporal-knowledge-graphworld-model
A confident merge waits for no one, and a succession clashes with nothing (#696)
WaylandYangc9c259a186f3
diff --git a/crates/utopia-server/src/adjudication.rs b/crates/utopia-server/src/adjudication.rsindex 9980c491..b8350a94 100644--- a/crates/utopia-server/src/adjudication.rs+++ b/crates/utopia-server/src/adjudication.rs@@ -17,11 +17,6 @@ use uuid::Uuid;const BATCH_SIZE: i64 = 12;const AUTO_CONF: f32 = 0.8;const MAX_ROUNDS: usize = 20;-/// 每一百对里有几对**即使裁决器有把握也交给人**(0026)。没有这一份,人裁过的-/// 语料会收缩成只剩难题:既不再代表一般的判法,也没有样本能量出机器与人的-/// 一致率。按 id 取样而不是掷骰子:同一对每次跑到的答案一样,才好复现-const HUMAN_SAMPLE_PCT: u128 = 10;-/// 缓存键:类型 + 双方名字 + 事实摘要 + 先例(与实体 id 无关——重传文档不重复付费)。/// **先例也进键**:答案随先例变(0025 说的正是这个,治理那一路因此干脆不用缓存);/// 人又裁了一笔,键就变,旧答案自然作废,不必去清@@ -42,11 +37,6 @@ fn pair_key(item: &ReviewItem, precedents: &[String]) -> String {digest.iter().map(|b| format!("{b:02x}")).collect()}-/// 这一对是不是抽给人看的那一份(见 HUMAN_SAMPLE_PCT)-fn sampled_for_a_person(item: &ReviewItem) -> bool {- item.id.as_u128() % 100 < HUMAN_SAMPLE_PCT-}-/// 攒批没定的对要不要带工具再看一遍(0028):没判决或把握不到线;硬规则拦得住的不看/// (大类不同、版本尾巴、含名字的一句话——再看也改不了规则);有撤回的不看,那是人的事fn wants_another_look(@@ -330,22 +320,8 @@ async fn apply_verdict(via: &str,why: Option<&str>,) -> anyhow::Result<Outcome> {- // 抽给人的那一份:机器有把握也不动手(0026)。理由写进队列那一列,- // 界面会说"这一对是抽样给你的",而不是让人以为裁决器没把握- if same.is_some() && conf >= AUTO_CONF && sampled_for_a_person(item) {- let verdict = if same == Some(true) {- "same"- } else {- "different"- };- utopia_store::resolution::escalate_review(- &state.pool,- item.id,- &format!("escalate_sample|{verdict} {conf:.2}"),- )- .await?;- return Ok(Outcome::Escalated);- }+ // 有把握就动手,不再抽一成给人(0026 修订):队列里等人的,只剩机器拿不准、+ // 或闸门说合了会送出图外的那些let outcome = match same {Some(true) if conf >= AUTO_CONF => {// 执行闸门(0027):合并会立刻送出图外的东西——违规、派生、答案——留给人,diff --git a/crates/utopia-store/src/execution_gate.rs b/crates/utopia-store/src/execution_gate.rsindex dfde2c68..bdd19a8f 100644--- a/crates/utopia-store/src/execution_gate.rs+++ b/crates/utopia-store/src/execution_gate.rs@@ -18,7 +18,7 @@ use uuid::Uuid;/// 一次合并会立刻牵动的东西#[derive(Debug, Clone, Default, PartialEq)]pub struct Impact {- /// 两边各持一条同一个 functional 谓词的事实、指向不同的实体:合了就是一条+ /// 两边各持一条同一个 functional 谓词的事实、指向不同的实体,合了之后按时间也排不开:/// `functional` 违规,一致性检查下一次跑就会开出来——那是离开图的第一站。/// 记谓词标签;`inverse_functional` 对称地算pub contradictions: Vec<String>,@@ -112,27 +112,10 @@ pub fn hold(impact: &Impact) -> Option<Hold> {/// 写路径的守卫看的是「当前那一行」(`invalidated_at IS NULL`),与 `resolve_mention`/// 数度数一个写法;不走记录轴谓词——修正永远发生在现在(0019)pub async fn impact_of(pool: &PgPool, kb_id: Uuid, a: Uuid, b: Uuid) -> AppResult<Impact> {- // 与一致性检查同一个口径(`too_many`):只看实体宾语的边,不看时间——它报的- // 正是合并之后会报的那一条- let contradictions: Vec<String> = sqlx::query_scalar(- "SELECT DISTINCT r.label- FROM facts x- JOIN facts y ON y.predicate_id = x.predicate_id AND y.kb_id = x.kb_id- JOIN relation_types r ON r.id = x.predicate_id- WHERE x.kb_id = $1- AND x.invalidated_at IS NULL AND y.invalidated_at IS NULL- AND x.object_id IS NOT NULL AND y.object_id IS NOT NULL- AND ((r.functional AND x.subject_id = $2 AND y.subject_id = $3- AND x.object_id <> y.object_id)- OR (r.inverse_functional AND x.object_id = $2 AND y.object_id = $3- AND x.subject_id <> y.subject_id))- ORDER BY r.label",- )- .bind(kb_id)- .bind(a)- .bind(b)- .fetch_all(pool)- .await?;+ // 与一致性检查同一个口径:只看实体宾语的边,**按时间看**——两边各有一个不同的值,+ // 合了之后若能排成先后接替(房东先 HPBB1、后 BBHQ1),一致性检查不会报,这里也+ // 不拦。从前这里不看时间,一份换过房东的租约有两个名字就永远合不起来+ let contradictions = crate::temporal::merge_would_overlap(pool, kb_id, a, b).await?;let derived: i64 = sqlx::query_scalar("SELECT count(*) FROM derived_facts ddiff --git a/crates/utopia-store/src/temporal.rs b/crates/utopia-store/src/temporal.rsindex 0cfedad3..09f29991 100644--- a/crates/utopia-store/src/temporal.rs+++ b/crates/utopia-store/src/temporal.rs@@ -573,6 +573,150 @@ async fn tidy(Ok(())}+/// 两个实体合成一个之后,哪些唯一性关系上**还会**有两个值同时成立(执行闸门,0027)。+///+/// 两边各有一个不同的值不等于矛盾:租约的房东先是 HPBB1、后来换成 BBHQ1,两个名字各挂+/// 一个,合起来是一条先后接替的时间线。这里把两边的行当成一条时间线,按引擎会怎么排+/// ([`desired_ends`])推出每一行的终点,再看不同的值有没有哪一刻叠在一起——排不开的+/// (同一刻开始、说不出时间、置信度不够接替、两份原文写明的区间相交)才是合了之后一致性+/// 检查会报的矛盾。只看实体宾语的边,与一致性检查(`utopia_reason::check`)同一个口径。+/// 返回谓词标签,按标签排+pub async fn merge_would_overlap(+ pool: &PgPool,+ kb_id: Uuid,+ a: Uuid,+ b: Uuid,+) -> AppResult<Vec<String>> {+ #[derive(sqlx::FromRow)]+ struct Shared {+ predicate_id: Uuid,+ label: String,+ functional: bool,+ inverse_functional: bool,+ temporal: String,+ }+ let shared: Vec<Shared> = sqlx::query_as(+ "SELECT DISTINCT r.id AS predicate_id, r.label, r.functional, r.inverse_functional,+ r.temporal+ FROM facts x+ JOIN facts y ON y.predicate_id = x.predicate_id AND y.kb_id = x.kb_id+ JOIN relation_types r ON r.id = x.predicate_id+ WHERE x.kb_id = $1+ AND x.invalidated_at IS NULL AND y.invalidated_at IS NULL+ AND x.object_id IS NOT NULL AND y.object_id IS NOT NULL+ AND ((r.functional AND x.subject_id = $2 AND y.subject_id = $3+ AND x.object_id <> y.object_id)+ OR (r.inverse_functional AND x.object_id = $2 AND y.object_id = $3+ AND x.subject_id <> y.subject_id))",+ )+ .bind(kb_id)+ .bind(a)+ .bind(b)+ .fetch_all(pool)+ .await?;++ let mut labels = Vec::new();+ for s in shared {+ let mut sides = Vec::new();+ if s.functional {+ sides.push(Uniqueness::SubjectSide);+ }+ if s.inverse_functional {+ sides.push(Uniqueness::ObjectSide);+ }+ for side in sides {+ let holder_column = match side {+ Uniqueness::SubjectSide => "f.subject_id",+ Uniqueness::ObjectSide => "f.object_id",+ };+ let mut rows: Vec<Row> = sqlx::query_as(&format!(+ "SELECT f.id, f.subject_id, f.object_id, f.object_value,+ f.valid_from, f.valid_from_precision, f.valid_to, f.valid_to_precision,+ f.attested_to, f.confidence, f.end_derived, {DATED_AT} AS dated_at+ FROM facts f+ WHERE f.kb_id = $1 AND {holder_column} = ANY($2) AND f.predicate_id = $3+ AND f.invalidated_at IS NULL AND f.object_id IS NOT NULL"+ ))+ .bind(kb_id)+ .bind(vec![a, b])+ .bind(s.predicate_id)+ .fetch_all(pool)+ .await?;+ // **只算合并带进来的冲突。** 一边持有的值另一边全都已经持有,合起来还是那几个值:+ // 同一个宾语并成一行,冲突要有也是那一边原本就有的,合不合都在。租约链上实测:+ // 一份租约自己已经挂着两个没日期的房东,另一个写法只挂着其中一个,0.98 的合并被+ // 「两个房东」挡下,而那两个房东合并之前就在+ let values_of = |holder: Uuid| -> HashSet<Uuid> {+ rows.iter()+ .filter_map(|r| match side {+ Uniqueness::SubjectSide => (r.subject_id == holder).then_some(r.object_id?),+ Uniqueness::ObjectSide => {+ (r.object_id == Some(holder)).then_some(r.subject_id)+ }+ })+ .collect()+ };+ let (held_by_a, held_by_b) = (values_of(a), values_of(b));+ if held_by_a.is_subset(&held_by_b) || held_by_b.is_subset(&held_by_a) {+ continue;+ }+ // 合成一个之后的样子:持有者那一侧都是同一个实体+ for row in &mut rows {+ match side {+ Uniqueness::SubjectSide => row.subject_id = a,+ Uniqueness::ObjectSide => row.object_id = Some(a),+ }+ }+ if still_overlaps(side, &rows, s.temporal == "state") {+ labels.push(s.label.clone());+ break;+ }+ }+ }+ labels.sort();+ labels.dedup();+ Ok(labels)+}++/// 一行排完之后的 [起, 止),`None` 是那一侧无界+type Span = (Option<DateTime<Utc>>, Option<DateTime<Utc>>);++/// 一条时间线按引擎排完之后,不同的值有没有哪一刻同时成立(纯函数)。`placed`:谓词是+/// 状态,引擎会排它;事件与恒常不排,照行上写着的终点比+fn still_overlaps(side: Uniqueness, rows: &[Row], placed: bool) -> bool {+ let ends = if placed {+ desired_ends(side, rows).0+ } else {+ HashMap::new()+ };+ // 每一行排完之后的 [起, 止):起点是排序用的时刻,说不出时间的行从无穷早起;+ // 终点是引擎推的,或原文写明的+ let spans: Vec<Span> = rows+ .iter()+ .map(|r| {+ let end = ends.get(&r.id).map(End::instant).unwrap_or_else(|| r.end());+ (r.key(), end)+ })+ .collect();+ for i in 0..rows.len() {+ for j in i + 1..rows.len() {+ if same_value(side, &rows[i], &rows[j]) {+ continue;+ }+ let ((si, ei), (sj, ej)) = (spans[i], spans[j]);+ let starts_before_end =+ |s: Option<DateTime<Utc>>, e: Option<DateTime<Utc>>| match (s, e) {+ (Some(s), Some(e)) => s < e,+ _ => true,+ };+ if starts_before_end(si, ej) && starts_before_end(sj, ei) {+ return true;+ }+ }+ }+ false+}+/// 把几条时间线各自重算一遍(调用方已按 [`lock_timelines`] 拿到锁)。撤回合并、删除或/// 恢复文档在自己的事务里改完行之后调pub async fn tidy_timelines_tx(@@ -1545,6 +1689,38 @@ mod tests {);}+ /// 合并前的闸门:两个值能排成先后接替就不算叠在一起;排不开的才算+ #[test]+ fn two_values_overlap_only_when_the_engine_cannot_order_them() {+ let succession = vec![+ row("HPBB1", Some(day(2016, 5, 16)), None),+ row("BBHQ1", None, Some(day(2020, 8, 13))),+ ];+ assert!(!still_overlaps(Uniqueness::SubjectSide, &succession, true));++ let same_day = vec![+ row("P", Some(day(2020, 1, 1)), None),+ row("Q", Some(day(2020, 1, 1)), None),+ ];+ assert!(still_overlaps(Uniqueness::SubjectSide, &same_day, true));++ let no_time = vec![row("K", None, None), row("N", Some(day(2020, 1, 1)), None)];+ assert!(still_overlaps(Uniqueness::SubjectSide, &no_time, true));++ // 两份原文写明的区间相交:引擎不替人挑+ let mut stated = vec![+ row("C", Some(day(2018, 1, 1)), None),+ row("D", Some(day(2019, 6, 1)), None),+ ];+ stated[0].valid_to = Some(day(2019, 12, 31));+ stated[0].valid_to_precision = Some("day".into());+ assert!(still_overlaps(Uniqueness::SubjectSide, &stated, true));++ // 事件与恒常不经引擎排:两个说不出时间的值照旧算撞+ let eternal = vec![row("X", None, None), row("Y", None, None)];+ assert!(still_overlaps(Uniqueness::SubjectSide, &eternal, false));+ }+/// 置信度不够的后任不许关上前任,交给人;前任止于它之后第一个够格的后任#[test]fn a_doubtful_successor_is_held_and_the_next_sure_one_closes() {diff --git a/crates/utopia-store/tests/an_automatic_merge_is_gated_by_what_it_can_undo.rs b/crates/utopia-store/tests/an_automatic_merge_is_gated_by_what_it_can_undo.rsindex 6cd4d53b..2281ae46 100644--- a/crates/utopia-store/tests/an_automatic_merge_is_gated_by_what_it_can_undo.rs+++ b/crates/utopia-store/tests/an_automatic_merge_is_gated_by_what_it_can_undo.rs@@ -230,3 +230,113 @@ async fn a_merge_that_would_leave_the_graph_is_held() -> anyhow::Result<()> {assert_eq!(gone.rows_affected(), 1, "一次性 org 没删掉");Ok(())}++/// 一个值接替了另一个:两个名字各挂一个、合起来是先后接替的时间线,不是矛盾。+/// 同一天开始的两个值才排不开(Blackbaud 总部租约:房东先 HPBB1、后 BBHQ1,+/// 「Lease Agreement」与「Lease Agreement dated May 16, 2016」各挂一个,从前闸门把这一对+/// 当矛盾留给人,同一份租约就一直是两个实体)+#[tokio::test]+async fn a_value_that_took_over_from_another_is_not_a_contradiction() -> anyhow::Result<()> {+ let Some(url) = utopia_store::test_db::url() else {+ return Ok(());+ };+ let pool = PgPool::connect(&url).await?;+ let f = seed(&pool).await?;+ let dated = |s: Uuid, o: Uuid, from: &'static str| {+ let pool = pool.clone();+ let (kb, p) = (f.kb, f.ceo_of);+ async move {+ sqlx::query(+ "INSERT INTO facts (id, kb_id, subject_id, predicate_id, object_id,+ valid_from, valid_from_precision)+ VALUES ($1, $2, $3, $4, $5, $6::timestamptz, 'day')",+ )+ .bind(Uuid::now_v7())+ .bind(kb)+ .bind(s)+ .bind(p)+ .bind(o)+ .bind(format!("{from}T00:00:00Z"))+ .execute(&pool)+ .await?;+ anyhow::Ok(())+ }+ };+ dated(f.a, f.c1, "2019-01-01").await?;+ dated(f.b, f.c2, "2021-01-01").await?;+ let succession = impact_of(&pool, f.kb, f.a, f.b).await?;++ let g = seed(&pool).await?;+ let same_day = |s: Uuid, o: Uuid| {+ let pool = pool.clone();+ let (kb, p) = (g.kb, g.ceo_of);+ async move {+ sqlx::query(+ "INSERT INTO facts (id, kb_id, subject_id, predicate_id, object_id,+ valid_from, valid_from_precision)+ VALUES ($1, $2, $3, $4, $5, '2020-01-01T00:00:00Z', 'day')",+ )+ .bind(Uuid::now_v7())+ .bind(kb)+ .bind(s)+ .bind(p)+ .bind(o)+ .execute(&pool)+ .await?;+ anyhow::Ok(())+ }+ };+ same_day(g.a, g.c1).await?;+ same_day(g.b, g.c2).await?;+ let clash = impact_of(&pool, g.kb, g.a, g.b).await?;++ for fx in [&f, &g] {+ sqlx::query("DELETE FROM knowledge_bases WHERE id = $1")+ .bind(fx.kb)+ .execute(&pool)+ .await?;+ sqlx::query("DELETE FROM users WHERE id = $1")+ .bind(fx.user)+ .execute(&pool)+ .await?;+ sqlx::query("DELETE FROM organizations WHERE id = $1")+ .bind(fx.org)+ .execute(&pool)+ .await?;+ }+ assert_eq!(hold(&succession), None, "先后接替不是矛盾:{succession:?}");+ assert_eq!(hold(&clash), Some(Hold::Contradiction("CEO of".into())));+ Ok(())+}++#[tokio::test]+async fn a_clash_one_side_already_had_is_not_the_merges() -> anyhow::Result<()> {+ let Some(url) = utopia_store::test_db::url() else {+ return Ok(());+ };+ let pool = PgPool::connect(&url).await?;+ let f = seed(&pool).await?;+ // b 自己已经挂着两个没日期的值;a 只挂着其中一个+ fact(&pool, f.kb, f.b, f.ceo_of, f.c1).await?;+ fact(&pool, f.kb, f.b, f.ceo_of, f.c2).await?;+ fact(&pool, f.kb, f.a, f.ceo_of, f.c1).await?;+ let impact = impact_of(&pool, f.kb, f.a, f.b).await?;++ sqlx::query("DELETE FROM knowledge_bases WHERE id = $1")+ .bind(f.kb)+ .execute(&pool)+ .await?;+ sqlx::query("DELETE FROM users WHERE id = $1")+ .bind(f.user)+ .execute(&pool)+ .await?;+ sqlx::query("DELETE FROM organizations WHERE id = $1")+ .bind(f.org)+ .execute(&pool)+ .await?;+ assert!(+ impact.contradictions.is_empty(),+ "the clash was on b before the merge: {impact:?}"+ );+ Ok(())+}diff --git a/docs/decisions/0026-a-decision-records-why.md b/docs/decisions/0026-a-decision-records-why.mdindex c9af0fa6..b28b5804 100644--- a/docs/decisions/0026-a-decision-records-why.md+++ b/docs/decisions/0026-a-decision-records-why.md@@ -1,6 +1,6 @@# 0026 · A decision records why-- **Status**: Implemented · migration 0038 adds `resolution_reviews.rationale`; every human decide path (`decide_review`, the batch, an answer to the agent, a manual merge from the entity panel) takes an optional rationale, keeps it on the row and writes it as `why` on the ledger event; `Precedent.why` carries it into the prompt lines and the `ledger_search` tool; the batch adjudicator now reads the same precedents and keys its verdict cache on them; one confident pair in ten goes to a person (`escalate_sample`); the model's own `why` is written beside machine decisions+- **Status**: Implemented · migration 0038 adds `resolution_reviews.rationale`; every human decide path (`decide_review`, the batch, an answer to the agent, a manual merge from the entity panel) takes an optional rationale, keeps it on the row and writes it as `why` on the ledger event; `Precedent.why` carries it into the prompt lines and the `ledger_search` tool; the batch adjudicator now reads the same precedents and keys its verdict cache on them; ~~one confident pair in ten goes to a person~~ removed 2026-09-14 (decision 5, revised); the model's own `why` is written beside machine decisions- **Written**: 2026-09-08 (conventions in the [README](README.md))- **Related**: [0025](0025-governance-reads-the-ledger-before-it-decides.md) made governance read the ledger; this record makes what it reads worth reading. #356 asked for it. The impact gate (#357) and the investigating adjudicator (#358) build on it; a rationale vocabulary that converges is a rule in the sense of [0021](0021-a-rule-reads-attributes-and-concludes-a-type.md).@@ -34,6 +34,8 @@ The batch adjudicator now asks `precedents_for` for each pair and sends the rend`HUMAN_SAMPLE_PCT = 10`, chosen by `review id % 100`, so the same pair is sampled on every run and a run is reproducible. The pair is escalated with `escalate_sample|<verdict> <confidence>` instead of being applied; the card says it was sampled and what the adjudicator would have said, so nobody reads it as doubt. Two things come out of it: the human corpus keeps ordinary pairs in it, and every sampled row holds both the machine's verdict and the person's, which is the raw material for an agreement rate.+> **Revised 2026-09-14: no confident pair is held for a person.** The sample is removed. On the Blackbaud lease bench it held a pair the adjudicator had judged the same at 0.95, so the lease stayed split into several entities and questions about it came back with several answers. What goes to a person is now only what the machine is unsure of, or what the gate (0027) holds. The reason for the sample, an agreement rate against people, has another source: every agent decision a person answers (0025) already holds both verdicts. Rows escalated as `escalate_sample` before this change keep their label, and the governor takes them like any other waiting pair.+### 6. The machine's why is kept, and is not a precedent`apply_verdict` writes the model's one-line `why` into the ledger on the merges and keeps it makes. `precedents_for` still reads only people's rows, as 0025 decided; the line is there so that Decisions shows what the machine went on, and so that a later reader can compare it with what the person wrote on the sampled pairs.@@ -54,5 +56,5 @@ The duplicate card has an input beside Keep / Merge; the batch toolbar has one i- **Impact, not confidence** (#357). Answered by [0027](0027-an-automatic-merge-is-gated-by-what-it-can-undo.md): a merge that would leave the graph is held for a person whatever the confidence.- **An adjudicator that investigates** (#358). Answered by [0028](0028-the-adjudicator-looks-before-it-asks.md): the batch escalates its unsettled pairs into the governor's loop, with governance off too.-- **The agreement rate.** The sampled rows carry both verdicts; nothing computes the rate yet, and nothing moves `HUMAN_SAMPLE_PCT` from it.+- **The agreement rate.** The sample is gone (decision 5, revised). The rows a person answers under the agent (0025) carry both verdicts; nothing computes the rate yet.- **History on a merge target.** The merge shows under the withdrawals it caused in the same second, which is honest chronology and hard to read. Folding consequences under their cause is presentation, and belongs with the rationale it now has.diff --git a/docs/decisions/0027-an-automatic-merge-is-gated-by-what-it-can-undo.md b/docs/decisions/0027-an-automatic-merge-is-gated-by-what-it-can-undo.mdindex 7b66687e..d19df1b1 100644--- a/docs/decisions/0027-an-automatic-merge-is-gated-by-what-it-can-undo.md+++ b/docs/decisions/0027-an-automatic-merge-is-gated-by-what-it-can-undo.md@@ -38,6 +38,10 @@ The queue reason is `escalate_impact|<kind> <value>`: `contradiction CEO of`, `dThe contradiction query looks at entity-object edges only, ignores time and ignores literal values, because that is what `too_many` in the reasoning crate looks at. A stricter predictor would hold pairs for violations the check would never open; a looser one would let through the ones it would.+> **Revised 2026-09-14: the contradiction reads time, as the check has since #635.** The consistency check started asking whether two values hold at the same moment in #635, and this query did not follow. The cost showed on the Blackbaud lease bench. The landlord changed from HPBB1 to BBHQ1, and the lease came out under two names, one holding each landlord. The gate called that pair a contradiction and held it for a person every run, so the lease stayed split and questions about it came back with two answers.+>+> `temporal::merge_would_overlap` now takes both sides' rows on each unique state predicate as one timeline and ends each row the way the temporal engine would (0022, #679). A contradiction is two values that still hold at one moment: the same start, a value with no time, a successor too doubtful to take over, or two stated intervals that cross. A succession is not one. Event and eternal predicates are not placed by the engine and are compared as their rows stand. The query still reads entity-object edges only.+## What a reader seesA pair the adjudicator would have merged shows in Duplicates with the held reason in place of a confidence. In the Agent queue the same pair is a proposal that begins "held for a person". Nothing changes for pairs that touch nothing.@@ -45,9 +49,9 @@ A pair the adjudicator would have merged shows in Duplicates with the held reaso## Dead ends- **Exports as a hold.** `kb.exported` is in the ledger, but an export is of the base, not of the pair: holding every merge in a base that has ever been exported is a switch, not a gate, and the switch already exists (governance, or the adjudicator's own). A per-deployment opt-in, "automatic merges may leave the system", waits until someone asks for it.-- **Size as impact.** The number of facts that would move says how visible a mistake is, not whether it comes back; `revert_merge` returns a hub as fully as a shell. And the sample 0026 keeps for people measures how often the machine is wrong, which is the number size would have been a proxy for.+- **Size as impact.** The number of facts that would move says how visible a mistake is, not whether it comes back; `revert_merge` returns a hub as fully as a shell. And the rows people answer under the agent (0025) measure how often the machine is wrong, which is the number size would have been a proxy for; 0026's one-in-ten sample did this until it was removed on 2026-09-14.- **A higher bar instead of a hold.** 0.95 for pairs with derivations, say. A held pair costs a person one look; a merge that leaves the graph costs a revert that does not fully revert. The asymmetry is the whole point of the issue.-- **Time-aware contradictions.** Two CEOs in different years are not a contradiction in the world, but the check does not know that yet either; when it does, this query follows it (decision 5).+- **Time-aware contradictions.** Two CEOs in different years are not a contradiction in the world. Both the check and this query now know it (decision 5, revised 2026-09-14).## Open questionsdiff --git a/docs/decisions/README.md b/docs/decisions/README.mdindex b2f0bfb6..cdac2d9d 100644--- a/docs/decisions/README.md+++ b/docs/decisions/README.md@@ -49,8 +49,8 @@ The test for writing one: if someone (including us) looks at a piece of code in| 0023 | [RSS observations are not documents](0023-rss-observations-are-not-documents.md) | Implemented in #326 || 0024 | [The world axis reaches the second](0024-the-world-axis-reaches-the-second.md) | Implemented · the precision ladder runs year → second (not below: no source states less), a stored value is truncated to its precision by CHECK on all three tables, a clock time without a zone is a date, one list spells the ladder in the extractor, the renderers, the export and the evaluator; a derived bound takes the precision of the premise that set it || 0025 | [Governance reads the ledger before it decides](0025-governance-reads-the-ledger-before-it-decides.md) | Cut 1 implemented · a per-base `governance` switch, a `govern` job that works the duplicates queue first in, first out with each head's cluster, precedents pulled from the ledger into the prompt, a gate where the agent's own confidence decides and history lowers the bar or blocks (revised after the first big-file run), every look a row in `agent_decisions`, answers through the person's own decide path · the switch, the Agent queue, the proposal chip and the Overview section in the UI · a pair the batch cannot settle is looked at again with tools and then decided or asked about, within a daily budget · two reverts in a week turn the switch off and raise an alert · identity rules the model reads and two it cannot argue with (name shapes, type families), measured against a hand-labeled set of 411 name pairs by `scripts/bench/govern.mjs` |-| 0026 | [A decision records why](0026-a-decision-records-why.md) | Implemented · `resolution_reviews.rationale` and `why` on the ledger event from every human decide path, precedents quote it into the prompt and the `ledger_search` tool, the batch adjudicator reads precedents and keys its cache on them, one confident pair in ten goes to a person anyway (`escalate_sample`), the model's own why is kept beside machine decisions · the impact gate (#357) and the investigating adjudicator (#358) follow |-| 0027 | [An automatic merge is gated by what it can undo](0027-an-automatic-merge-is-gated-by-what-it-can-undo.md) | Implemented · `execution_gate` in the store, asked by the batch adjudicator and the governor before an automatic merge: a contradiction the consistency check would open, a derivation resting on either side, or an answer that named either side holds the pair for a person as `escalate_impact` whatever the confidence · keeps are not gated · exports and a per-deployment opt-in stay open |+| 0026 | [A decision records why](0026-a-decision-records-why.md) | Implemented · `resolution_reviews.rationale` and `why` on the ledger event from every human decide path, precedents quote it into the prompt and the `ledger_search` tool, the batch adjudicator reads precedents and keys its cache on them, the one-in-ten sample for a person was removed 2026-09-14, the model's own why is kept beside machine decisions · the impact gate (#357) and the investigating adjudicator (#358) follow |+| 0027 | [An automatic merge is gated by what it can undo](0027-an-automatic-merge-is-gated-by-what-it-can-undo.md) | Implemented · `execution_gate` in the store, asked by the batch adjudicator and the governor before an automatic merge: a contradiction the consistency check would open (read on the time axis since 2026-09-14: a succession is not one), a derivation resting on either side, or an answer that named either side holds the pair for a person as `escalate_impact` whatever the confidence · keeps are not gated · exports and a per-deployment opt-in stay open || 0028 | [The adjudicator looks before it asks](0028-the-adjudicator-looks-before-it-asks.md) | Implemented · `consequences` joins the second look's tools (what a merge would touch, from 0027's gate, and whether the types share a family) · with governance off the batch adjudicator sends its unsettled pairs through the same loop under the same budget, each look a row in `agent_decisions` · the number that justifies or retires it comes from 0026's sample split by `via` || 0029 | [A rule may say "or", once](0029-a-rule-may-say-or-once.md) | Implemented · a `group_seq` on a rule's conditions (migration `0039`): same group joins with **and**, groups join with **or**, one level and no nesting — because a hit carries the readings that made it true and a disjunction has no premises of its own · the combination cap is per group, two groups on one interval are one conclusion with the first group's proof, `not_in` joins the ops · "no such attribute at all" is deliberately not here (no premise, and a missing reading means nobody wrote it down) · the editor writes blocks and the table reads the sentence back with its "or" in it || 0030 | [A rule may read what a rule concluded](0030-a-rule-may-read-what-a-rule-concluded.md) | Cuts 1–2 · A rule could not read another rule's conclusion (`attribute_facts()` reads `facts`, subject scope is `entities.type_id`, one pass), so `A → B → C` has to be written as one flattened rule. The answer is the fixed point the axiom side already runs, **inside one call and in memory** — which answers 0013's objection instead of waiving it, since a run stays a pure function of the asserted facts. A derived typing enters as a **premise**, not a filter, so the conclusion narrows to the window the entity was actually a `B`; a rule may read its own conclusions because the derivable space is finite; `fact_derivations` gains `premise_derived_id` and the proof becomes a tree; retirement cascades for free because recompute is total. The page showing which rules feed which is next |diff --git a/scripts/bench/corpora/contracts/lease_bench.py b/scripts/bench/corpora/contracts/lease_bench.pyindex dfe2411d..fd5525d8 100644--- a/scripts/bench/corpora/contracts/lease_bench.py+++ b/scripts/bench/corpora/contracts/lease_bench.py@@ -142,8 +142,9 @@ def setup(label, with_base):kb = api("POST", f"/workspaces/{ws}/kbs", {"name": f"Blackbaud HQ lease ({label})", "ontology_packs": []})["id"]print("kb", kb)time.sleep(4)- # 与召回测量台同一个理由:抽取之后会改图的开关一律关掉,量的是抽取本身- api("PATCH", f"/kbs/{kb}", {"auto_extend_ontology": False, "materialize_inferences": False, "governance": False})+ # 本体是这里声明的那一套,不让它自己长;治理开着——库生下来就开着它(0050),+ # 同一份租约被写成几个名字,合不合得起来正是要量的+ api("PATCH", f"/kbs/{kb}", {"auto_extend_ontology": False, "materialize_inferences": False, "governance": True})ids = {}for key, name, desc in CLASSES:ids[key] = api("POST", f"/kbs/{kb}/ontology/entity-types", {"key": key, "label": name, "description": desc})["id"]diff --git a/scripts/bench/recall.mjs b/scripts/bench/recall.mjsindex faf901ad..6c89295a 100644--- a/scripts/bench/recall.mjs+++ b/scripts/bench/recall.mjs@@ -202,8 +202,9 @@ psql(`DELETE FROM extraction_drops WHERE kb_id='${KB}'`);psql(`DELETE FROM ontology_misses WHERE kb_id='${KB}'`);// 自动扩本体上一轮长出来的关系:留着就进下一轮的提示词,两轮条件不同psql(`DELETE FROM relation_types WHERE kb_id='${KB}' AND created_at > '${packTs}'::timestamptz + interval '1 second'`);-// 四个会在抽取之后改图的开关一律关掉:测的是抽取本身,推理物化和治理闸门会在打分前增删事实-psql(`UPDATE knowledge_bases SET auto_extend_ontology=FALSE, auto_type_resolution=FALSE, materialize_inferences=FALSE, governance=FALSE WHERE id='${KB}'`);+// 会在抽取之后改本体、增派生事实的开关关掉,两轮的本体与打分口径才一样。治理开着:+// 库生下来就开着它(0050),量的是产品本来的样子+psql(`UPDATE knowledge_bases SET auto_extend_ontology=FALSE, auto_type_resolution=FALSE, materialize_inferences=FALSE, governance=TRUE WHERE id='${KB}'`);psql(`UPDATE chunks SET extracted_at=NULL WHERE document_id IN (SELECT id FROM documents WHERE kb_id='${KB}' AND filename IN (${names}))`);console.log(`本体 ${num(`SELECT count(*) FROM relation_types WHERE kb_id='${KB}'`)} 个关系 / ${num(`SELECT count(*) FROM entity_types WHERE kb_id='${KB}'`)} 个类`);