diff --git a/crates/utopia-store/src/materialize.rs b/crates/utopia-store/src/materialize.rs index 04290048b..f4683d951 100644 --- a/crates/utopia-store/src/materialize.rs +++ b/crates/utopia-store/src/materialize.rs @@ -390,39 +390,51 @@ async fn materialize_in_tx( .bind(d.statement) .execute(&mut **tx) .await?; - // 证据每次都抄:证据是同一段原文的同一处引文 - sqlx::query( - "INSERT INTO fact_evidence (fact_id, chunk_id, quote, document_id, doc_version, - proposed_predicate, quote_start, quote_end) - SELECT $1, chunk_id, quote, document_id, doc_version, proposed_predicate, - quote_start, quote_end - FROM fact_evidence WHERE fact_id = $2 - ON CONFLICT DO NOTHING", - ) - .bind(fact) - .bind(d.statement) - .execute(&mut **tx) - .await?; - // 角色词只抄行还没有的角色(0070 决定 1 的修订):并进已有行的陈述若对同一角色 - // 说了别的值,抄过来这一行就同时读到两个值;别的值由决定 4 带过来 - sqlx::query( - "INSERT INTO statement_qualifiers (fact_id, role, value, entity_id, chunk_id) - SELECT $1, q.role, q.value, q.entity_id, q.chunk_id - FROM statement_qualifiers q - WHERE q.fact_id = $2 - AND NOT EXISTS (SELECT 1 FROM statement_qualifiers n - WHERE n.fact_id = $1 AND n.role = q.role) - ON CONFLICT DO NOTHING", - ) - .bind(fact) - .bind(d.statement) - .execute(&mut **tx) - .await?; } // 3a. 已批准的规则算隐含行(0044 决定 3 第五片)。读数只查缓存:缓存里没有的这一轮 // 不算,`read_phrases` 填上之后再来。短语规则按陈述触发,类别词规则按实体触发 let implied = imply_in_tx(tx, kb_id, &mut written, &mut unreadable).await?; record_unreadable(tx, kb_id, &unreadable).await?; + // 证据和角色词整库一次补:来源陈述的引文和角色词抄到活着的类型化行和隐含行上,排在 3a 之后 + // 本轮写下的行也覆盖;行已有的靠主键跳过(0070 决定 4)。 + // Rows the target already holds are filtered out before the insert: on a base with nothing new + // to copy that anti-join is cheaper than letting `ON CONFLICT` probe every row (#1544). + sqlx::query( + "INSERT INTO fact_evidence (fact_id, chunk_id, quote, document_id, doc_version, + proposed_predicate, quote_start, quote_end) + SELECT t.id, e.chunk_id, e.quote, e.document_id, e.doc_version, e.proposed_predicate, + e.quote_start, e.quote_end + FROM facts t + JOIN (SELECT fact_id, statement_id FROM typed_fact_sources + UNION ALL SELECT fact_id, statement_id FROM implied_fact_sources) src + ON src.fact_id = t.id + JOIN fact_evidence e ON e.fact_id = src.statement_id + WHERE t.kb_id = $1 AND t.layer = 'typed' AND t.invalidated_at IS NULL + AND NOT EXISTS (SELECT 1 FROM fact_evidence h + WHERE h.fact_id = t.id AND h.chunk_id = e.chunk_id) + ON CONFLICT DO NOTHING", + ) + .persistent(false) + .bind(kb_id) + .execute(&mut **tx) + .await?; + sqlx::query( + "INSERT INTO statement_qualifiers (fact_id, role, value, entity_id, chunk_id) + SELECT t.id, q.role, q.value, q.entity_id, q.chunk_id + FROM facts t + JOIN (SELECT fact_id, statement_id FROM typed_fact_sources + UNION ALL SELECT fact_id, statement_id FROM implied_fact_sources) src + ON src.fact_id = t.id + JOIN statement_qualifiers q ON q.fact_id = src.statement_id + WHERE t.kb_id = $1 AND t.layer = 'typed' AND t.invalidated_at IS NULL + AND NOT EXISTS (SELECT 1 FROM statement_qualifiers h + WHERE h.fact_id = t.id AND h.role = q.role AND h.chunk_id = q.chunk_id) + ON CONFLICT DO NOTHING", + ) + .persistent(false) + .bind(kb_id) + .execute(&mut **tx) + .await?; // 3b. 见证跟着来源陈述走(0064 决定 3、5):类型化的行自己没有出处。物化与算隐含行 // 用的写入口在陈述没有见证时填的是此刻(那是给人写的事实用的缺省),这里改回陈述的。 // 排在 3a 之后:规则算出的行也是这样写下的 @@ -649,21 +661,6 @@ async fn imply_in_tx( .bind(d.entity) .execute(&mut **tx) .await?; - // 证据:短语规则抄触发它的那条陈述的引文——读的人从这句得出的结论,证据就是这句 - if let Some(statement) = d.statement { - sqlx::query( - "INSERT INTO fact_evidence (fact_id, chunk_id, quote, document_id, doc_version, - proposed_predicate, quote_start, quote_end) - SELECT $1, chunk_id, quote, document_id, doc_version, proposed_predicate, - quote_start, quote_end - FROM fact_evidence WHERE fact_id = $2 - ON CONFLICT DO NOTHING", - ) - .bind(fact) - .bind(statement) - .execute(&mut **tx) - .await?; - } } Ok(implied) } diff --git a/crates/utopia-store/tests/store/a_bound_statement_becomes_a_typed_fact.rs b/crates/utopia-store/tests/store/a_bound_statement_becomes_a_typed_fact.rs index cb26cc6dd..8f9e0b041 100644 --- a/crates/utopia-store/tests/store/a_bound_statement_becomes_a_typed_fact.rs +++ b/crates/utopia-store/tests/store/a_bound_statement_becomes_a_typed_fact.rs @@ -222,11 +222,10 @@ async fn a_bound_statement_becomes_a_typed_fact() -> anyhow::Result<()> { .bind(typed_id) .fetch_one(&pool) .await?; - // 并进来的那条说 since 2021:行已有 since,不抄,只读建行那条的 2019; - // 它说的 until 行还没有,跟进来 + // 并进来的那条说 since 2021:两条都在活的分块上,两个值都抄过来(0070 决定 2、4) let qualifiers: Vec<(String, String, Uuid)> = sqlx::query_as( "SELECT role, value #>> '{}', chunk_id FROM statement_qualifiers - WHERE fact_id = $1 ORDER BY role", + WHERE fact_id = $1 ORDER BY role, value #>> '{}'", ) .bind(typed_id) .fetch_all(&pool) @@ -238,6 +237,7 @@ async fn a_bound_statement_becomes_a_typed_fact() -> anyhow::Result<()> { 2, vec![ ("since".to_string(), "2019".to_string(), stated_chunk), + ("since".to_string(), "2021".to_string(), again_chunk), ("until".to_string(), "2024".to_string(), again_chunk), ] ) diff --git a/crates/utopia-store/tests/store/a_re_push_that_moves_lines_moves_the_typed_rows_lines_too.rs b/crates/utopia-store/tests/store/a_re_push_that_moves_lines_moves_the_typed_rows_lines_too.rs new file mode 100644 index 000000000..c9e208ea3 --- /dev/null +++ b/crates/utopia-store/tests/store/a_re_push_that_moves_lines_moves_the_typed_rows_lines_too.rs @@ -0,0 +1,241 @@ +//! 0070 决定 4:每次物化都把来源陈述的证据与角色词补到活着的类型化行上,不只在建行/并行时。 +//! +//! 一条绑定的陈述说 `lines: 40-52`,物化成类型化行;来源重推同一个 external_id, +//! 旧块被取代、新块说 `lines: 58-70`;再物化一遍,类型化行读出来只有 58-70。 +//! +//! 没有 `UTOPIA_DATABASE_URL` 时跳过而不是失败。自建自拆,绝不碰已有的库。 + +use sqlx::PgPool; +use utopia_store::materialize::materialize; +use uuid::Uuid; + +#[tokio::test] +async fn a_re_push_that_moves_lines_moves_the_typed_rows_lines_too() -> 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 = 'materialize-repush-test'") + .execute(&pool) + .await?; + let (org, ws, kb) = (Uuid::now_v7(), Uuid::now_v7(), Uuid::now_v7()); + sqlx::query("INSERT INTO organizations (id, name) VALUES ($1, 'materialize-repush-test')") + .bind(org) + .execute(&pool) + .await?; + sqlx::query( + "INSERT INTO workspaces (id, org_id, name) VALUES ($1, $2, 'materialize-repush-test')", + ) + .bind(ws) + .bind(org) + .execute(&pool) + .await?; + sqlx::query( + "INSERT INTO knowledge_bases (id, workspace_id, name) + VALUES ($1, $2, 'materialize-repush-test')", + ) + .bind(kb) + .bind(ws) + .execute(&pool) + .await?; + + let run = async { + let (test_class, file_class, covers) = (Uuid::now_v7(), Uuid::now_v7(), Uuid::now_v7()); + for (id, key) in [(test_class, "test"), (file_class, "file")] { + sqlx::query( + "INSERT INTO entity_types (id, kb_id, key, label, color, shape) + VALUES ($1, $2, $3, $3, '#7fd0ff', 'circle')", + ) + .bind(id) + .bind(kb) + .bind(key) + .execute(&pool) + .await?; + } + sqlx::query( + "INSERT INTO relation_types (id, kb_id, key, label, temporal) + VALUES ($1, $2, 'covers_file', 'covers file', 'state')", + ) + .bind(covers) + .bind(kb) + .execute(&pool) + .await?; + let (parses_date, parse_rs, statement) = (Uuid::now_v7(), Uuid::now_v7(), Uuid::now_v7()); + for (id, type_id, name) in [ + (parses_date, test_class, "test-parses-a-date"), + (parse_rs, file_class, "parse.rs"), + ] { + sqlx::query( + "INSERT INTO entities (id, kb_id, type_id, canonical_name) VALUES ($1, $2, $3, $4)", + ) + .bind(id) + .bind(kb) + .bind(type_id) + .bind(name) + .execute(&pool) + .await?; + } + sqlx::query( + "INSERT INTO facts (id, kb_id, subject_id, object_id, layer, phrase, confidence) + VALUES ($1, $2, $3, $4, 'open', 'covers', 0.9)", + ) + .bind(statement) + .bind(kb) + .bind(parses_date) + .bind(parse_rs) + .execute(&pool) + .await?; + sqlx::query( + "INSERT INTO phrase_bindings + (id, kb_id, phrase, subject_type_id, object_type_id, object_is_value, + relation_type_id, direction, status) + VALUES ($1, $2, 'covers', $3, $4, false, $5, 'forward', 'bound')", + ) + .bind(Uuid::now_v7()) + .bind(kb) + .bind(test_class) + .bind(file_class) + .bind(covers) + .execute(&pool) + .await?; + + // 一份文档的一块:陈述在这块上说 lines + let doc = Uuid::now_v7(); + sqlx::query("INSERT INTO documents (id, kb_id, filename, sha256) VALUES ($1, $2, 'ci.json', 'ci')") + .bind(doc) + .bind(kb) + .execute(&pool) + .await?; + let says_lines_on = |chunk: Uuid, seq: i32, lines: &'static str| { + let pool = pool.clone(); + async move { + sqlx::query( + "INSERT INTO chunks (id, kb_id, document_id, seq, text) VALUES ($1, $2, $3, $4, $5)", + ) + .bind(chunk) + .bind(kb) + .bind(doc) + .bind(seq) + .bind(lines) + .execute(&pool) + .await?; + sqlx::query( + "INSERT INTO fact_evidence (fact_id, chunk_id, quote, document_id, quote_start, quote_end) + VALUES ($1, $2, $3, $4, 0, 11)", + ) + .bind(statement) + .bind(chunk) + .bind(lines) + .bind(doc) + .execute(&pool) + .await?; + sqlx::query( + "INSERT INTO statement_qualifiers (fact_id, role, value, chunk_id) + VALUES ($1, 'lines', to_jsonb($3::text), $2)", + ) + .bind(statement) + .bind(chunk) + .bind(lines) + .execute(&pool) + .await?; + anyhow::Ok(()) + } + }; + let (old_chunk, new_chunk) = (Uuid::now_v7(), Uuid::now_v7()); + says_lines_on(old_chunk, 0, "lines 40-52").await?; + materialize(&pool, kb).await?; + let typed: Uuid = sqlx::query_scalar( + "SELECT id FROM facts WHERE kb_id = $1 AND layer = 'typed' AND invalidated_at IS NULL", + ) + .bind(kb) + .fetch_one(&pool) + .await?; + + // 重推:旧块被取代,新块说 58-70 + sqlx::query("UPDATE chunks SET superseded_at = now() WHERE id = $1") + .bind(old_chunk) + .execute(&pool) + .await?; + says_lines_on(new_chunk, 1, "lines 58-70").await?; + + let other_kb = Uuid::now_v7(); + sqlx::query( + "INSERT INTO knowledge_bases (id, workspace_id, name) + VALUES ($1, $2, 'materialize-repush-other-test')", + ) + .bind(other_kb) + .bind(ws) + .execute(&pool) + .await?; + let read_typed = || async { + let read = + utopia_store::graph::statement_qualifiers_for(&pool, &[typed], None).await?; + let said: Vec<(String, Option)> = read + .get(&typed) + .map(|qualifiers| { + qualifiers + .iter() + .map(|q| (q.role.clone(), q.value.clone())) + .collect() + }) + .unwrap_or_default(); + let mut evidence: Vec = + sqlx::query_scalar("SELECT chunk_id FROM fact_evidence WHERE fact_id = $1") + .bind(typed) + .fetch_all(&pool) + .await?; + evidence.sort(); + anyhow::Ok((said, evidence)) + }; + + materialize(&pool, other_kb).await?; + assert_eq!( + read_typed().await?, + ( + vec![("lines".to_string(), Some(serde_json::json!("lines 40-52")))], + vec![old_chunk] + ) + ); + + materialize(&pool, kb).await?; + assert_eq!( + read_typed().await?, + ( + vec![("lines".to_string(), Some(serde_json::json!("lines 58-70")))], + vec![old_chunk, new_chunk] + ) + ); + + // 再重推:新块被取代,第三块带 mood——来源不再算数,类型化行下一轮就退休 + let mood_chunk = Uuid::now_v7(); + sqlx::query("UPDATE chunks SET superseded_at = now() WHERE id = $1") + .bind(new_chunk) + .execute(&pool) + .await?; + says_lines_on(mood_chunk, 2, "lines 58-70").await?; + sqlx::query( + "INSERT INTO statement_qualifiers (fact_id, role, value, chunk_id) + VALUES ($1, 'mood', '\"will\"'::jsonb, $2)", + ) + .bind(statement) + .bind(mood_chunk) + .execute(&pool) + .await?; + materialize(&pool, kb).await?; + let live_typed: Vec = sqlx::query_scalar( + "SELECT id FROM facts WHERE kb_id = $1 AND layer = 'typed' AND invalidated_at IS NULL", + ) + .bind(kb) + .fetch_all(&pool) + .await?; + assert_eq!(live_typed, Vec::::new()); + 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/an_implied_row_reads_the_role_words_of_the_statement_that_implied_it.rs b/crates/utopia-store/tests/store/an_implied_row_reads_the_role_words_of_the_statement_that_implied_it.rs new file mode 100644 index 000000000..8020a754f --- /dev/null +++ b/crates/utopia-store/tests/store/an_implied_row_reads_the_role_words_of_the_statement_that_implied_it.rs @@ -0,0 +1,144 @@ +//! 0070 决定 4:规则算出的行读出触发它的那条陈述的角色词,不只证据。 +//! +//! 一条陈述在它的块上说 `lines 40-52`,触发一条批准的蕴含规则;物化之后隐含行读出来 +//! 也是 `lines 40-52`。 +//! +//! 没有 `UTOPIA_DATABASE_URL` 时跳过而不是失败。自建自拆,绝不碰已有的库。 + +use sqlx::PgPool; +use utopia_store::materialize::materialize; +use uuid::Uuid; + +#[tokio::test] +async fn an_implied_row_reads_the_role_words_of_the_statement_that_implied_it() -> 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 = 'implied-role-words-test'") + .execute(&pool) + .await?; + let ids: Vec = (0..11).map(|_| Uuid::now_v7()).collect(); + let (org, ws, kb, person, company, works_for) = + (ids[0], ids[1], ids[2], ids[3], ids[4], ids[5]); + let (lin, aster, statement, doc, chunk) = (ids[6], ids[7], ids[8], ids[9], ids[10]); + // Only locally generated UUIDs are interpolated into fixture SQL. + sqlx::raw_sql(&format!( + "INSERT INTO organizations(id,name) VALUES ('{org}','implied-role-words-test'); + INSERT INTO workspaces(id,org_id,name) VALUES ('{ws}','{org}','implied-role-words-test'); + INSERT INTO knowledge_bases(id,workspace_id,name) VALUES ('{kb}','{ws}','implied-role-words-test'); + 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'); + INSERT INTO entities(id,kb_id,canonical_name,type_id) VALUES + ('{lin}','{kb}','Lin Zhao','{person}'), + ('{aster}','{kb}','Aster Labs','{company}'); + INSERT INTO implication_rules(id,kb_id,trigger,phrase,subject_type_id,object_type_id, + conclude_property_id,reading,status,decided_by) + VALUES ('{rule}','{kb}','phrase','signed with','{person}','{company}','{works_for}', + NULL,'approved','person'); + INSERT INTO facts(id,kb_id,subject_id,object_id,layer,phrase,confidence) + VALUES ('{statement}','{kb}','{lin}','{aster}','open','signed with',0.9); + INSERT INTO documents(id,kb_id,filename,sha256) VALUES ('{doc}','{kb}','ci.json','ci'); + INSERT INTO chunks(id,kb_id,document_id,seq,text) + VALUES ('{chunk}','{kb}','{doc}',0,'lines 40-52'); + INSERT INTO fact_evidence(fact_id,chunk_id,quote,document_id,quote_start,quote_end) + VALUES ('{statement}','{chunk}','lines 40-52','{doc}',0,11); + INSERT INTO statement_qualifiers(fact_id,role,value,chunk_id) + VALUES ('{statement}','lines',to_jsonb('lines 40-52'::text),'{chunk}');", + rule = Uuid::now_v7(), + )) + .execute(&pool) + .await?; + + let run = async { + materialize(&pool, kb).await?; + let implied: Uuid = sqlx::query_scalar( + "SELECT id FROM facts WHERE kb_id = $1 AND implied AND invalidated_at IS NULL", + ) + .bind(kb) + .fetch_one(&pool) + .await?; + + let read = utopia_store::graph::statement_qualifiers_for(&pool, &[implied], None).await?; + let said: Vec<(String, Option)> = read + .get(&implied) + .map(|qualifiers| { + qualifiers + .iter() + .map(|q| (q.role.clone(), q.value.clone())) + .collect() + }) + .unwrap_or_default(); + assert_eq!( + said, + vec![("lines".to_string(), Some(serde_json::json!("lines 40-52")))] + ); + + let moved_chunk = Uuid::now_v7(); + sqlx::query("UPDATE chunks SET superseded_at = now() WHERE id = $1") + .bind(chunk) + .execute(&pool) + .await?; + sqlx::query("INSERT INTO chunks (id, kb_id, document_id, seq, text) VALUES ($1, $2, $3, 1, 'lines 58-70')") + .bind(moved_chunk) + .bind(kb) + .bind(doc) + .execute(&pool) + .await?; + sqlx::query( + "INSERT INTO fact_evidence (fact_id, chunk_id, quote, document_id, quote_start, quote_end) + VALUES ($1, $2, 'lines 58-70', $3, 0, 11)", + ) + .bind(statement) + .bind(moved_chunk) + .bind(doc) + .execute(&pool) + .await?; + sqlx::query( + "INSERT INTO statement_qualifiers (fact_id, role, value, chunk_id) + VALUES ($1, 'lines', to_jsonb('lines 58-70'::text), $2)", + ) + .bind(statement) + .bind(moved_chunk) + .execute(&pool) + .await?; + materialize(&pool, kb).await?; + let reread = utopia_store::graph::statement_qualifiers_for(&pool, &[implied], None).await?; + let moved: Vec<(String, Option)> = reread + .get(&implied) + .map(|qualifiers| { + qualifiers + .iter() + .map(|q| (q.role.clone(), q.value.clone())) + .collect() + }) + .unwrap_or_default(); + let mut evidence: Vec = + sqlx::query_scalar("SELECT chunk_id FROM fact_evidence WHERE fact_id = $1") + .bind(implied) + .fetch_all(&pool) + .await?; + evidence.sort(); + let mut expected_evidence = vec![chunk, moved_chunk]; + expected_evidence.sort(); + assert_eq!( + (moved, evidence), + ( + vec![("lines".to_string(), Some(serde_json::json!("lines 58-70")))], + expected_evidence + ) + ); + 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/main.rs b/crates/utopia-store/tests/store/main.rs index c09226f71..59799ec35 100644 --- a/crates/utopia-store/tests/store/main.rs +++ b/crates/utopia-store/tests/store/main.rs @@ -78,6 +78,7 @@ mod a_purge_is_final; mod a_purge_judges_its_blobs_once; mod a_qualifier_is_not_the_edges_identity; mod a_question_picks_its_definitions; +mod a_re_push_that_moves_lines_moves_the_typed_rows_lines_too; mod a_reader_keeps_its_key_for_its_provider; mod a_relation_points_only_inside_its_own_kb; mod a_remembered_episode_strips_nul; @@ -124,6 +125,7 @@ mod an_exact_name_search_returns_only_that_entity; mod an_exploration_says_what_it_covered; mod an_export_carries_the_whole_ledger; mod an_identity_name_attaches_by_its_exact_name; +mod an_implied_row_reads_the_role_words_of_the_statement_that_implied_it; mod an_instance_list_names_what_a_type_lacks; mod an_old_version_keeps_no_vector; mod an_open_statement_keeps_the_documents_words; diff --git a/docs/decisions/0070-a-role-word-speaks-while-its-chunk-is-live.md b/docs/decisions/0070-a-role-word-speaks-while-its-chunk-is-live.md index 14f6683b7..954eaba75 100644 --- a/docs/decisions/0070-a-role-word-speaks-while-its-chunk-is-live.md +++ b/docs/decisions/0070-a-role-word-speaks-while-its-chunk-is-live.md @@ -1,6 +1,6 @@ # 0070 · A role word speaks while its chunk is live -- **Status**: In progress · 2026-10-25 · [#1267](https://github.com/deeplethe/utopia/issues/1267) · decision 1 built (migration 0121), decisions 2 and 3 built (`record_axis::role_word_speaks_given`, the three `mood` checks included) · open: decision 4 +- **Status**: Implemented · 2026-11-28 · #1428, #1450, #1544, migration 0121 · open: flagging contested role words - **Written**: 2026-10-16 (conventions in the [README](README.md)) - **Related**: [0037](0037-a-relation-carries-its-own-attributes.md) decided that a qualifier is not part of a fact's identity and that the first value stays; [0044](0044-the-ontology-is-a-view-over-what-documents-say.md) owns the open statement and the role words on it; [0054](0054-a-source-may-push-statements-in-the-open-contract.md) decision 7 is the re-push that supersedes a chunk; migration `0061` created `statement_qualifiers`; [0048](0048-provenance-references-stay-inside-the-knowledge-base.md) gets one more edge to keep inside the base; [0019](0019-the-second-clock-can-be-rewound.md) is the record axis `as_of` reads on; [#1267](https://github.com/deeplethe/utopia/issues/1267), [#1272](https://github.com/deeplethe/utopia/issues/1272) @@ -26,6 +26,8 @@ The backfill copies each existing `(fact, role)` value onto every evidence chunk *Revised with migration 0121 (2026-10-30).* As first written this decision put each role word on every evidence chunk of its fact. That holds for open statements. A typed row can have several source statements, and their chunks are all its evidence, so copying a value onto all of them would let a statement speak for a value it never said. A typed row takes a role word only on the chunk of a source statement that said the same value; the migration falls back to every evidence chunk only when no source gave that value. At runtime `materialize` copies onto a typed row only the roles the row does not have yet: a statement that merges in brings its new roles, and a different value for a role the row already has stays on the statement, or the row would read two. Bringing the other values across is decision 4. +*Revised with decision 4 (2026-11-28).* `materialize` no longer holds back a role the row already has. On each run it copies every row the row's statements carry, so a typed row whose statements disagree reads both values, the way two live statements do (decision 2). ([`a_bound_statement_becomes_a_typed_fact`](../../crates/utopia-store/tests/store/a_bound_statement_becomes_a_typed_fact.rs), [`a_re_push_that_moves_lines_moves_the_typed_rows_lines_too`](../../crates/utopia-store/tests/store/a_re_push_that_moves_lines_moves_the_typed_rows_lines_too.rs), [`an_implied_row_reads_the_role_words_of_the_statement_that_implied_it`](../../crates/utopia-store/tests/store/an_implied_row_reads_the_role_words_of_the_statement_that_implied_it.rs)) + `chunk_id` is a new provenance edge, and 0048's invariant covers it: the owner-derived trigger `statement_qualifiers_same_kb` checks that the chunk's document is in the fact's base, and the export preflight scans the edge. **2. A superseded chunk stops speaking for the statement.** diff --git a/docs/decisions/README.md b/docs/decisions/README.md index 3baf81a41..6ee8174ef 100644 --- a/docs/decisions/README.md +++ b/docs/decisions/README.md @@ -75,7 +75,7 @@ By domain; the domains are the files of [../design/](../design/README.md). **Sta | 0010 | [An unnamed relation stays empty](0010-no-relation-is-no-relation.md) | Implemented | partly (by 0044) | | 0037 | [A relation carries its own attributes](0037-a-relation-carries-its-own-attributes.md) | In progress | partly (by 0044) | | 0048 | [Provenance references stay inside the knowledge base](0048-provenance-references-stay-inside-the-knowledge-base.md) | Implemented | | -| 0070 | [A role word speaks while its chunk is live](0070-a-role-word-speaks-while-its-chunk-is-live.md) | In progress | | +| 0070 | [A role word speaks while its chunk is live](0070-a-role-word-speaks-while-its-chunk-is-live.md) | Implemented | | ### [governance](../design/governance.md)