World's first open-source enterprise world model.
Rust agent-memorybitemporalgraphragknowledge-baseknowledge-graphllmontologypgvectorpostgresqlragrustself-hostedsemantic-searchtemporal-knowledge-graphworld-model
A row a rule implies is attested by the statements it read, not by the moment it was computed (#1012)
Maya Kidfe47a8bc8ce5
diff --git a/crates/utopia-cli/src/main.rs b/crates/utopia-cli/src/main.rsindex 2d518cad..dd0e0015 100644--- a/crates/utopia-cli/src/main.rs+++ b/crates/utopia-cli/src/main.rs@@ -82,7 +82,7 @@ struct ManifestDataDir {/// not a side effect of a code change.// 是迁移文件的**个数**,不是最大的编号(守卫 `schema_version_policy_compares_against_current`// 按个数比):编号有空缺时两者不同——0071 由一个开放 PR 占着,0072 先落,个数是 71-const CURRENT_SCHEMA_VERSION: u32 = 91;+const CURRENT_SCHEMA_VERSION: u32 = 92;fn main() -> anyhow::Result<()> {dotenvy::dotenv().ok();diff --git a/crates/utopia-server/src/time_resolution.rs b/crates/utopia-server/src/time_resolution.rsindex 4d66383a..371cfdfb 100644--- a/crates/utopia-server/src/time_resolution.rs+++ b/crates/utopia-server/src/time_resolution.rs@@ -684,7 +684,7 @@ async fn attest_statements(moved += 1;}}- // 已经物化出来的类型化行跟着它们的陈述走+ // 已经物化出来的、规则算出来的类型化行跟着它们的陈述走let typed = utopia_store::materialize::sync_typed_attestation(pool, doc.kb_id).await?;if moved > 0 || typed > 0 {tracing::info!(document_id = %doc.id, statements = moved, typed, "陈述按它所在那一节的日期作了证");diff --git a/crates/utopia-store/src/graph.rs b/crates/utopia-store/src/graph.rsindex fced2b7c..5183313b 100644--- a/crates/utopia-store/src/graph.rs+++ b/crates/utopia-store/src/graph.rs@@ -950,8 +950,8 @@ async fn attest_earlier<'e>(/// 一条陈述的见证:它所在那一节里文本说话的那一刻,连同那条日期的名字(0064 决定 3)。////// 只往早挪(同 [`attest_earlier`]):同一句话在更早的文档里说过,见证就是更早的那份。-/// 名字跟着日期走——日期没动,名字也不动。物化出来的类型化行自己没有出处,跟着陈述走-/// (`materialize::sync_typed_attestation`,调用方在写完一篇文档的陈述之后叫一次)+/// 名字跟着日期走——日期没动,名字也不动。物化出来的、规则算出来的类型化行自己没有出处,+/// 跟着陈述走(`materialize::sync_typed_attestation`,调用方在写完一篇文档的陈述之后叫一次)pub async fn attest_statement(pool: &PgPool,fact_id: Uuid,diff --git a/crates/utopia-store/src/materialize.rs b/crates/utopia-store/src/materialize.rsindex 15f85aed..dba74c6d 100644--- a/crates/utopia-store/src/materialize.rs+++ b/crates/utopia-store/src/materialize.rs@@ -413,12 +413,13 @@ async fn materialize_in_tx(.execute(&mut **tx).await?;}- // 3a. 见证跟着来源陈述走(0064 决定 3、5):类型化的行自己没有出处。上面的写入口在- // 陈述没有见证时填的是此刻(那是给人写的事实用的缺省),这里改回陈述的- sync_typed_attestation(&mut **tx, kb_id).await?;- // 3b. 已批准的规则算隐含行(0044 决定 3 第五片)。读数只查缓存:缓存里没有的这一轮+ // 3a. 已批准的规则算隐含行(0044 决定 3 第五片)。读数只查缓存:缓存里没有的这一轮// 不算,`read_phrases` 填上之后再来。短语规则按陈述触发,类别词规则按实体触发let implied = imply_in_tx(tx, kb_id, &mut written).await?;+ // 3b. 见证跟着来源陈述走(0064 决定 3、5):类型化的行自己没有出处。物化与算隐含行+ // 用的写入口在陈述没有见证时填的是此刻(那是给人写的事实用的缺省),这里改回陈述的。+ // 排在 3a 之后:规则算出的行也是这样写下的+ sync_typed_attestation(&mut **tx, kb_id).await?;Ok((Outcome {retired,@@ -433,8 +434,12 @@ async fn materialize_in_tx(}/// 类型化行的见证 = 它的来源陈述里最早的那个见证,连同那条日期的名字;来源陈述一条见证-/// 都没有的,它也没有(任何时点都成立,0064 决定 5)。只动从陈述物化出来的行:人写的、-/// 规则算的没有 `typed_fact_sources`,不在这里+/// 都没有的,它也没有(任何时点都成立,0064 决定 5)。来源陈述有两处:物化进这一行的+/// (`typed_fact_sources`),和规则读出这一行的(`implied_fact_sources`);类别词规则的+/// 来源是实体,不带见证。+///+/// 动的行:有陈述物化进来的,和规则算出来的(`implied`)。人写的行只被规则的结论并进来时+/// 不动——它的见证是人写下它的那一刻,并进来时 `attest_earlier` 已经往早挪过pub async fn sync_typed_attestation<'e>(ex: impl sqlx::Executor<'e, Database = sqlx::Postgres>,kb_id: Uuid,@@ -442,15 +447,23 @@ pub async fn sync_typed_attestation<'e>(let moved = sqlx::query("UPDATE facts tSET attested_from = src.at, attested_by = src.by- FROM (SELECT ts.fact_id,+ FROM (SELECT u.fact_id,min(s.attested_from) AS at,(array_agg(s.attested_by ORDER BY s.attested_from NULLS LAST, s.id))[1] AS by- FROM typed_fact_sources ts- JOIN facts s ON s.id = ts.statement_id- WHERE s.kb_id = $1- GROUP BY ts.fact_id) src+ FROM (SELECT ts.fact_id, ts.statement_id+ FROM typed_fact_sources ts+ JOIN facts k ON k.id = ts.statement_id AND k.kb_id = $1+ UNION ALL+ -- 规则的来源按规则的库筛:类别词规则的来源是实体,没有陈述+ SELECT i.fact_id, i.statement_id+ FROM implied_fact_sources i+ JOIN implication_rules r ON r.id = i.rule_id AND r.kb_id = $1) u+ LEFT JOIN facts s ON s.id = u.statement_id+ GROUP BY u.fact_id) srcWHERE t.id = src.fact_id AND t.kb_id = $1 AND t.layer = 'typed'AND t.invalidated_at IS NULL+ AND (t.implied+ OR EXISTS (SELECT 1 FROM typed_fact_sources ts WHERE ts.fact_id = t.id))AND (t.attested_from IS DISTINCT FROM src.atOR t.attested_by IS DISTINCT FROM src.by)",)diff --git a/crates/utopia-store/tests/a_row_a_rule_implied_follows_its_statements.rs b/crates/utopia-store/tests/a_row_a_rule_implied_follows_its_statements.rsnew file mode 100644index 00000000..056d8d77--- /dev/null+++ b/crates/utopia-store/tests/a_row_a_rule_implied_follows_its_statements.rs@@ -0,0 +1,177 @@+//! 迁移 0101:这之前规则算出的行,见证跟着它读的陈述走。+//!+//! 照这之前的来路造:物化照常算出隐含行,再把它们的见证改回那时写下的样子——处理那一刻,+//! 没有日期的名字。那时规则算的行入库时陈述没有见证就填此刻,陈述后来作了证也不跟。+//!+//! - 没说时间的陈述算出的行:留空,任何时点都成立+//! - 陈述在物化之后才作了证的:跟到那天,连同那条日期的名字+//! - 类别词从实体算出的行:没有陈述可跟,留空+//! - 人写的行只被规则的结论并进来:见证还是人写下它的那一刻+//!+//! 再跑一遍迁移,一样不动。迁移的语句不按 kb 过滤,改的是全库的行,所以这个测试在 tests/+//! 顶层自成一个二进制(与 0096、0099 同理)。没有 `UTOPIA_DATABASE_URL` 时跳过而不是失败。+//! 自建自拆,绝不碰已有的库。++use chrono::{DateTime, TimeZone, Utc};+use sqlx::PgPool;+use utopia_store::graph::{self, FactObject, Validity};+use uuid::Uuid;++const MIGRATION: &str =+ include_str!("../../../migrations/0101_a_row_a_rule_implies_follows_its_statements.sql");++async fn anchor(+ pool: &PgPool,+ fact: Uuid,+) -> anyhow::Result<(Option<DateTime<Utc>>, Option<String>)> {+ Ok(+ sqlx::query_as("SELECT attested_from, attested_by FROM facts WHERE id = $1")+ .bind(fact)+ .fetch_one(pool)+ .await?,+ )+}++/// 主语到宾语之间活着的那一行类型化事实+async fn typed_row(pool: &PgPool, kb: Uuid, subject: Uuid, object: Uuid) -> anyhow::Result<Uuid> {+ Ok(sqlx::query_scalar(+ "SELECT id FROM facts+ WHERE kb_id = $1 AND subject_id = $2 AND object_id = $3+ AND layer = 'typed' AND invalidated_at IS NULL",+ )+ .bind(kb)+ .bind(subject)+ .bind(object)+ .fetch_one(pool)+ .await?)+}++#[tokio::test]+async fn a_row_a_rule_implied_before_follows_its_statements() -> anyhow::Result<()> {+ let Some(url) = utopia_store::test_db::url() else {+ return Ok(());+ };+ let pool = PgPool::connect(&url).await?;+ let ids: Vec<Uuid> = (0..15).map(|_| Uuid::now_v7()).collect();+ let (org, ws, kb, person, company, works_for, origin) =+ (ids[0], ids[1], ids[2], ids[3], ids[4], ids[5], ids[6]);+ let (lin, aster, brightway, meridian, film, uk) =+ (ids[7], ids[8], ids[9], ids[10], ids[11], ids[12]);+ let (signed_rule, kind_rule) = (ids[13], ids[14]);+ // Only locally generated UUIDs are interpolated into fixture SQL.+ sqlx::raw_sql(&format!(+ "INSERT INTO organizations(id,name) VALUES ('{org}','rule-rows-before-0101');+ INSERT INTO workspaces(id,org_id,name) VALUES ('{ws}','{org}','rule-rows-before-0101');+ INSERT INTO knowledge_bases(id,workspace_id,name) VALUES ('{kb}','{ws}','rule-rows-before-0101');+ INSERT INTO entity_types(id,kb_id,key,label,color,shape) VALUES+ ('{person}','{kb}','person','person','#000','circle'),+ ('{company}','{kb}','organization','organization','#000','circle');+ INSERT INTO relation_types(id,kb_id,key,label,kind,temporal) VALUES+ ('{works_for}','{kb}','works_for','works for','relation','state'),+ ('{origin}','{kb}','country_of_origin','country of origin','relation','state');+ INSERT INTO entities(id,kb_id,canonical_name,type_id,specific_type) VALUES+ ('{lin}','{kb}','Lin Zhao','{person}',NULL),+ ('{aster}','{kb}','Aster Labs','{company}',NULL),+ ('{brightway}','{kb}','Brightway','{company}',NULL),+ ('{meridian}','{kb}','Meridian Systems','{company}',NULL),+ ('{film}','{kb}','Loud Tour',NULL,'British film'),+ ('{uk}','{kb}','United Kingdom',NULL,NULL);+ INSERT INTO implication_rules(id,kb_id,trigger,phrase,subject_type_id,object_type_id,+ conclude_property_id,reading,status,decided_by) VALUES+ ('{signed_rule}','{kb}','phrase','signed with','{person}','{company}','{works_for}',+ NULL,'approved','person'),+ ('{kind_rule}','{kb}','kind_word','british film',NULL,NULL,'{origin}',+ 'country_of_nationality','approved','person');+ INSERT INTO phrase_readings(kb_id,reading,phrase,entity_id) VALUES+ ('{kb}','country_of_nationality','british film','{uk}');"+ ))+ .execute(&pool)+ .await?;++ let run = async {+ let processed = Utc.with_ymd_and_hms(2026, 9, 30, 3, 0, 0).unwrap();+ let signed_day = Utc.with_ymd_and_hms(2026, 9, 4, 0, 0, 0).unwrap();+ let written_day = Utc.with_ymd_and_hms(2026, 8, 1, 0, 0, 0).unwrap();+ let signed = |object: Uuid| {+ let pool = pool.clone();+ async move {+ anyhow::Ok(+ graph::insert_open_statement(+ &pool,+ kb,+ lin,+ "signed with",+ FactObject::Entity(object),+ None,+ 0.9,+ )+ .await?+ .0,+ )+ }+ };+ signed(aster).await?;+ let later = signed(brightway).await?;+ let (by_hand, _) = graph::insert_fact(+ &pool,+ kb,+ lin,+ Some(works_for),+ meridian,+ Validity {+ attested_at: Some(written_day),+ ..Validity::default()+ },+ 0.9,+ )+ .await?;+ signed(meridian).await?;+ utopia_store::materialize::materialize(&pool, kb).await?;+ // 物化之后陈述才作证:只动陈述,那时算出的行不跟+ assert!(graph::attest_statement(&pool, later, signed_day, "签约日 2026年9月4日").await?);+ // 这之前写下的样子:规则算的行都是处理那一刻,没有日期的名字+ sqlx::query(+ "UPDATE facts SET attested_from = $2, attested_by = NULL WHERE kb_id = $1 AND implied",+ )+ .bind(kb)+ .bind(processed)+ .execute(&pool)+ .await?;+ let undated = typed_row(&pool, kb, lin, aster).await?;+ let dated_later = typed_row(&pool, kb, lin, brightway).await?;+ let by_kind = typed_row(&pool, kb, film, uk).await?;+ assert_eq!(typed_row(&pool, kb, lin, meridian).await?, by_hand);+ for row in [undated, dated_later, by_kind] {+ assert_eq!(anchor(&pool, row).await?, (Some(processed), None));+ }++ // 跑两遍:第二遍一样不动+ for _ in 0..2 {+ sqlx::raw_sql(MIGRATION).execute(&pool).await?;+ assert_eq!(+ anchor(&pool, undated).await?,+ (None, None),+ "an undated statement"+ );+ assert_eq!(+ anchor(&pool, dated_later).await?,+ (Some(signed_day), Some("签约日 2026年9月4日".to_string())),+ "the statement attested after the row was computed"+ );+ assert_eq!(anchor(&pool, by_kind).await?, (None, None), "a kind word");+ assert_eq!(+ anchor(&pool, by_hand).await?,+ (Some(written_day), None),+ "a person's row a rule merged into"+ );+ }+ anyhow::Ok(())+ }+ .await;++ sqlx::query("DELETE FROM organizations WHERE id = $1")+ .bind(org)+ .execute(&pool)+ .await?;+ run+}diff --git a/crates/utopia-store/tests/store/a_statement_is_attested_by_what_its_document_says.rs b/crates/utopia-store/tests/store/a_statement_is_attested_by_what_its_document_says.rsindex 063865c2..fb413db6 100644--- a/crates/utopia-store/tests/store/a_statement_is_attested_by_what_its_document_says.rs+++ b/crates/utopia-store/tests/store/a_statement_is_attested_by_what_its_document_says.rs@@ -3,16 +3,19 @@//! - 抽取写下的开放陈述不再拿处理文档的那一刻当见证:文档没说就留空;//! - 留空的行在世界轴上任何时点都成立(下界开放);没日期的事件除外,它照旧任何时点都不成立;//! - `attest_statement` 写上见证和那条日期的名字,只往早挪;-//! - 物化出来的类型化行跟着它的来源陈述走。+//! - 物化出来的类型化行跟着它的来源陈述走;+//! - 规则算出来的行也跟着它读的陈述走,类别词规则从实体算的行没有见证;人写的行只被规则的+//! 结论并进来时,见证还是人写下它的那一刻。//!//! 没有 `UTOPIA_DATABASE_URL` 时跳过而不是失败。自建自拆,绝不碰已有的库。use chrono::{DateTime, TimeZone, Utc};use sqlx::PgPool;-use utopia_store::graph::{self, FactObject};+use utopia_store::graph::{self, FactObject, Validity};use uuid::Uuid;const ORG: &str = "statement-attested-by-document-test";+const RULE_ORG: &str = "rule-row-attested-by-its-statement-test";async fn anchor(pool: &PgPool,@@ -156,3 +159,162 @@ async fn an_unattested_statement_holds_at_every_moment_and_an_attested_one_from_.await?;run}++/// 主语到宾语之间活着的那一行类型化事实+async fn typed_row(pool: &PgPool, kb: Uuid, subject: Uuid, object: Uuid) -> anyhow::Result<Uuid> {+ Ok(sqlx::query_scalar(+ "SELECT id FROM facts+ WHERE kb_id = $1 AND subject_id = $2 AND object_id = $3+ AND layer = 'typed' AND invalidated_at IS NULL",+ )+ .bind(kb)+ .bind(subject)+ .bind(object)+ .fetch_one(pool)+ .await?)+}++/// 规则算出来的行(0073 的隐含行)跟着它读的陈述走:陈述没说时间,它就没有见证、任何时点+/// 都成立;陈述后来作了证,它跟到那天。类别词规则从实体算的行没有陈述可跟,也没有见证。+/// 人写的行被规则的结论并进来,见证还是人写下它的那一刻+#[tokio::test]+async fn a_row_a_rule_implies_follows_the_statement_it_read() -> anyhow::Result<()> {+ let Some(url) = utopia_store::test_db::url() else {+ return Ok(());+ };+ let pool = PgPool::connect(&url).await?;+ sqlx::query("DELETE FROM organizations WHERE name = $1")+ .bind(RULE_ORG)+ .execute(&pool)+ .await?;+ let ids: Vec<Uuid> = (0..14).map(|_| Uuid::now_v7()).collect();+ let (org, ws, kb, person, company, works_for, origin) =+ (ids[0], ids[1], ids[2], ids[3], ids[4], ids[5], ids[6]);+ let (lin, aster, meridian, film, uk, signed_rule, kind_rule) =+ (ids[7], ids[8], ids[9], ids[10], ids[11], ids[12], ids[13]);+ // 两条批准了的规则:「signed with」(人 → 机构)蕴含 works_for;类别词「british film」+ // 蕴含 country_of_origin,宾语由读数缓存给出+ sqlx::raw_sql(&format!(+ "INSERT INTO organizations(id,name) VALUES ('{org}','{RULE_ORG}');+ INSERT INTO workspaces(id,org_id,name) VALUES ('{ws}','{org}','{RULE_ORG}');+ INSERT INTO knowledge_bases(id,workspace_id,name) VALUES ('{kb}','{ws}','{RULE_ORG}');+ INSERT INTO entity_types(id,kb_id,key,label,color,shape) VALUES+ ('{person}','{kb}','person','person','#000','circle'),+ ('{company}','{kb}','organization','organization','#000','circle');+ INSERT INTO relation_types(id,kb_id,key,label,kind,temporal) VALUES+ ('{works_for}','{kb}','works_for','works for','relation','state'),+ ('{origin}','{kb}','country_of_origin','country of origin','relation','state');+ INSERT INTO entities(id,kb_id,canonical_name,type_id,specific_type) VALUES+ ('{lin}','{kb}','Lin Zhao','{person}',NULL),+ ('{aster}','{kb}','Aster Labs','{company}',NULL),+ ('{meridian}','{kb}','Meridian Systems','{company}',NULL),+ ('{film}','{kb}','Loud Tour',NULL,'British film'),+ ('{uk}','{kb}','United Kingdom',NULL,NULL);+ INSERT INTO implication_rules(id,kb_id,trigger,phrase,subject_type_id,object_type_id,+ conclude_property_id,reading,status,decided_by) VALUES+ ('{signed_rule}','{kb}','phrase','signed with','{person}','{company}','{works_for}',+ NULL,'approved','person'),+ ('{kind_rule}','{kb}','kind_word','british film',NULL,NULL,'{origin}',+ 'country_of_nationality','approved','person');+ INSERT INTO phrase_readings(kb_id,reading,phrase,entity_id) VALUES+ ('{kb}','country_of_nationality','british film','{uk}');"+ ))+ .execute(&pool)+ .await?;++ let run = async {+ let long_ago = Utc.with_ymd_and_hms(2015, 1, 1, 0, 0, 0).unwrap();+ let signed_day = Utc.with_ymd_and_hms(2026, 9, 4, 0, 0, 0).unwrap();+ let written_day = Utc.with_ymd_and_hms(2026, 8, 1, 0, 0, 0).unwrap();++ // 一条没说时间的陈述:规则从它算出的行没有见证,任何时点都成立——与同一条陈述物化+ // 出来的行一样,不是算出它的那一刻。类别词算出的行也是+ let (signed, _) = graph::insert_open_statement(+ &pool,+ kb,+ lin,+ "signed with",+ FactObject::Entity(aster),+ None,+ 0.9,+ )+ .await?;+ let outcome = utopia_store::materialize::materialize(&pool, kb).await?;+ assert_eq!(outcome.implied, 2, "{outcome:?}");+ let by_rule = typed_row(&pool, kb, lin, aster).await?;+ let by_kind = typed_row(&pool, kb, film, uk).await?;+ assert_eq!(anchor(&pool, by_rule).await?, (None, None));+ assert_eq!(anchor(&pool, by_kind).await?, (None, None));+ for row in [by_rule, by_kind] {+ assert!(+ holds_at(&pool, row, long_ago).await?,+ "no time at all: holds at every moment"+ );+ assert!(holds_at(&pool, row, Utc::now()).await?);+ }++ // 陈述后来由它所在那一节的日期作证,时间解析那条路:先给陈述作证,再同步类型化的行。+ // 规则算出的行跟到那天,连同那条日期的名字;类别词那行没有陈述,照旧没有+ assert!(graph::attest_statement(&pool, signed, signed_day, "签约日 2026年9月4日").await?);+ utopia_store::materialize::sync_typed_attestation(&pool, kb).await?;+ let followed = (Some(signed_day), Some("签约日 2026年9月4日".to_string()));+ assert_eq!(anchor(&pool, by_rule).await?, followed);+ assert!(!holds_at(&pool, by_rule, long_ago).await?);+ assert!(holds_at(&pool, by_rule, signed_day).await?);+ assert_eq!(anchor(&pool, by_kind).await?, (None, None));+ // 再物化一轮,不动它们+ utopia_store::materialize::materialize(&pool, kb).await?;+ assert_eq!(anchor(&pool, by_rule).await?, followed);+ assert_eq!(anchor(&pool, by_kind).await?, (None, None));++ // 人写的行由人写下它的那一刻作证。规则从一条没说时间的陈述算出同一件事、并进这一行:+ // 它有了规则的来源,见证不变+ let (by_hand, _) = graph::insert_fact(+ &pool,+ kb,+ lin,+ Some(works_for),+ meridian,+ Validity {+ attested_at: Some(written_day),+ ..Validity::default()+ },+ 0.9,+ )+ .await?;+ graph::insert_open_statement(+ &pool,+ kb,+ lin,+ "signed with",+ FactObject::Entity(meridian),+ None,+ 0.9,+ )+ .await?;+ let outcome = utopia_store::materialize::materialize(&pool, kb).await?;+ assert_eq!(+ outcome.implied, 0,+ "merged into the person's row: {outcome:?}"+ );+ let rule_sources: i64 =+ sqlx::query_scalar("SELECT count(*) FROM implied_fact_sources WHERE fact_id = $1")+ .bind(by_hand)+ .fetch_one(&pool)+ .await?;+ assert_eq!(rule_sources, 1);+ assert_eq!(+ anchor(&pool, by_hand).await?,+ (Some(written_day), None),+ "a person's row keeps the moment it was written"+ );+ Ok::<(), anyhow::Error>(())+ }+ .await;++ sqlx::query("DELETE FROM organizations WHERE name = $1")+ .bind(RULE_ORG)+ .execute(&pool)+ .await?;+ run+}diff --git a/crates/utopia-store/tests/store/main.rs b/crates/utopia-store/tests/store/main.rsindex 775641a7..dfc97cba 100644--- a/crates/utopia-store/tests/store/main.rs+++ b/crates/utopia-store/tests/store/main.rs@@ -20,6 +20,8 @@//! 合并二进制的实验里 30% 的运行栽在这里。//! - `a_rewritten_row_gets_its_statements_back`:把迁移 0096 原样跑一遍,它同样不按 kb//! 过滤——修正行、重复行都按全库找,会改到别的测试正在物化、改写的行。+//! - `a_row_a_rule_implied_follows_its_statements`:把迁移 0101 原样跑一遍,同样不按 kb+//! 过滤——它按来源重算全库类型化行的见证,会改到别的测试正在物化的行。//!//! 新加测试默认放这个目录;只有碰上面那类全局状态时才放顶层,并在这里补一行为什么。mod a_batch_decides_like_a_person;diff --git a/docs/decisions/0064-extraction-reads-time-as-it-goes.md b/docs/decisions/0064-extraction-reads-time-as-it-goes.mdindex 271bdabb..d0e5326a 100644--- a/docs/decisions/0064-extraction-reads-time-as-it-goes.md+++ b/docs/decisions/0064-extraction-reads-time-as-it-goes.md@@ -52,7 +52,7 @@ As-of is not a start. "码表所属市场为全球" in a report of 4 September s**4. Relative expressions are measured from the reference point in force.** The model still returns an interpretation and code still computes (0045 decisions 2 and 8). What changes is that the reference point of the chunk is in front of the model when it reads "三个月后", so the expression is recorded as a mention with its anchor instead of being folded into the object. With no reference point in force the mention is grade C and waits (0045 decision 4).-**5. A fact with no time holds at every moment.** This answers 0045's first open question. `attested_from` is null unless decision 3 gave one; the insert no longer falls back to `now()`; a read at a moment T keeps a row that has neither a valid time nor an attestation. The workbench says "undated" for it, "as of 2026-08-31 (数据统计截止)" for an attested one, and an interval for one the words dated. Rows written before this carry the processing moment; migration 0100 moves open statements to their earliest dated evidence and sets the rest to null, and typed rows follow the statements they were materialised from. An event with no date holds at no moment (0022), attested or not. An ending said without a date needs an anchor by CHECK; with no attestation it takes the moment the ledger recorded it.+**5. A fact with no time holds at every moment.** This answers 0045's first open question. `attested_from` is null unless decision 3 gave one; the insert no longer falls back to `now()`; a read at a moment T keeps a row that has neither a valid time nor an attestation. The workbench says "undated" for it, "as of 2026-08-31 (数据统计截止)" for an attested one, and an interval for one the words dated. Rows written before this carry the processing moment; migration 0100 moves open statements to their earliest dated evidence and sets the rest to null, and typed rows follow the statements they were materialised from. A row a rule implied (0073) follows the statements the rule read; one a kind word implied reads no statement and has no attestation. Migration 0101 moves the rule rows written before this. An event with no date holds at no moment (0022), attested or not. An ending said without a date needs an anchor by CHECK; with no attestation it takes the moment the ledger recorded it.**6. Interpretation rides with extraction.** With the context present, the mention and its interpretation are returned by the same call. The batch interpretation step stays only for re-resolution when an anchor arrives later (0045 cut 4).diff --git a/migrations/0101_a_row_a_rule_implies_follows_its_statements.sql b/migrations/0101_a_row_a_rule_implies_follows_its_statements.sqlnew file mode 100644index 00000000..cf5351c2--- /dev/null+++ b/migrations/0101_a_row_a_rule_implies_follows_its_statements.sql@@ -0,0 +1,25 @@+-- 0064 决定 5 的补遗:规则算出来的行也跟着它读的陈述作证。+--+-- 0100 让没说时间的事实在任何时点都成立,物化出来的类型化行跟着来源陈述走。规则算的+-- 隐含行(0073)没跟上:入库时陈述没有见证,写入口就填处理那一刻(那是给人写的事实留的+-- 缺省);类别词规则从实体算的行本来就没有见证,也成了处理那一刻;陈述后来由时间解析+-- 作了证,它们也不跟。于是同一条没说时间的陈述,绑定物化的那行任何时点都成立,规则算的+-- 那行只从处理那一刻起成立。+--+-- 现在物化与时间解析同步见证时,规则算的行也在内(`materialize::sync_typed_attestation`)。+-- 这里把已有的行按同一条规矩补一次:来源陈述(物化进来的、规则读的)里最早的那个见证,+-- 连同那条日期的名字,一条都没有就留空;人写的行只被规则的结论并进来的不动。与 0100 一样+-- 不按库筛,作废的行也在内+UPDATE facts t+ SET attested_from = src.at, attested_by = src.by+ FROM (SELECT u.fact_id,+ min(s.attested_from) AS at,+ (array_agg(s.attested_by ORDER BY s.attested_from NULLS LAST, s.id))[1] AS by+ FROM (SELECT fact_id, statement_id FROM typed_fact_sources+ UNION ALL+ SELECT fact_id, statement_id FROM implied_fact_sources) u+ LEFT JOIN facts s ON s.id = u.statement_id+ GROUP BY u.fact_id) src+ WHERE t.id = src.fact_id AND t.layer = 'typed'+ AND (t.implied OR EXISTS (SELECT 1 FROM typed_fact_sources ts WHERE ts.fact_id = t.id))+ AND (t.attested_from IS DISTINCT FROM src.at OR t.attested_by IS DISTINCT FROM src.by);