Per-object document updates lose observation-time ordering during reconciliation
Reusing one document identity for successive object observations makes the functional timeline unable to order the values using their evidence dates. In the #875 replay, both typed values ultimately cite the same document, whose doc_time has been replaced by the second observation's time. Explicit reconciliation then records a simultaneous conflict instead of closing the old value.
Reproduction
Start with a document for cup-7 at 08:00, an open desk statement, an explicit phrase binding and its typed projection. Replace that document's content at 08:10, supersede its chunks, and insert a shelf statement with evidence in the new chunk. The old statement is stale but not invalidated. Materialize again and explicitly reconcile the functional location predicate: 0 corrected rows, 1 conflict, desk remains open.
The regression below models the extraction result directly after the document replacement operation; it does not claim to test an automatic extraction/alignment loop. The HTTP replay independently showed the same behavior for one external_id per object.
Expected contract to define: preserve each observation's evidence time through versioning, or document an event-ingestion identity/content policy that preserves those times. A new external ID alone is not sufficient for identical payloads: the ingest path may recognize a move/rename. Stale evidence and an explicitly ended world-time interval should remain distinct concepts; this report does not request unconditional retraction of old statements.
Executable evidence
The complete fixture and reproduction are retained at the immutable experimental commit 4864e2f19e3ab0cee58d5ef4eade6212b3ae1af6 on the fork. Its base includes #884 and dev@9f50e3c. The test was explicitly executed with a real PostgreSQL 16/pgvector database and fails at the assertion shown below (exit 101), not during compilation or setup. It is kept outside #898's upstream test diff; it is a proposed behavior reproduction, not an ignored upstream acceptance test.
With that checkout and a migrated, dedicated test database:
UTOPIA_TEST_REQUIRE_DB=1 cargo test --locked -p utopia-store --test store \
a_plan_step_follows_its_premise::a_same_identity_update_closes_the_earlier_place \
-- --ignored --exact --test-threads=1UTOPIA_DATABASE_URL must point to that database. The helper definitions are in the linked file. The reproducing test is:
#[tokio::test]
#[ignore = "#875 gap: a same-identity update leaves both places open even after reconcile"]
async fn a_same_identity_update_closes_the_earlier_place() -> anyhow::Result<()> {
let Some(url) = utopia_store::test_db::url() else {
return Ok(());
};
let pool = PgPool::connect(&url).await?;
let f = seed(&pool, "issue875-same-identity").await?;
let run = async {
let (doc, c1) = document(&pool, &f, "cup-7.json", T1, "cup-7 is on desk").await?;
statement(&pool, &f, c1, "desk", T1).await?;
bind_is_on(&pool, &f).await?;
materialize::materialize(&pool, f.kb).await?;
// 第二次推送:原地替换、记版本、doc_time 换成新的(ingest_item 的那一步),新块顶替旧块
utopia_store::documents::replace_content_and_enqueue_processing(
&pool,
doc,
"cup-7.json",
"application/json",
17,
"second-version",
Some(t(T2)),
)
.await?;
// 那一步排下的处理任务这里不跑:抽取的结果由下面两行写出来
sqlx::query("DELETE FROM jobs WHERE payload->>'document_id' = $1")
.bind(doc.to_string())
.execute(&pool)
.await?;
let text = "cup-7 is on shelf".to_string();
let piece = utopia_ingest::ChunkPiece {
seq: 0,
char_start: 0,
char_end: text.chars().count() as i32,
heading: None,
provenance: utopia_ingest::Provenance::stated(),
text: text.clone(),
};
utopia_store::documents::replace_chunks(&pool, f.kb, doc, &[piece]).await?;
let (c2,): (Uuid,) = sqlx::query_as(
"SELECT id FROM chunks WHERE document_id = $1 AND superseded_at IS NULL",
)
.bind(doc)
.fetch_one(&pool)
.await?;
statement(&pool, &f, c2, "shelf", T2).await?;
materialize::materialize(&pool, f.kb).await?;
let report = temporal::reconcile_predicate(&pool, f.kb, f.location).await?;
let desk = typed_desk(&pool, &f).await?;
assert_eq!(desk.len(), 1);
assert!(
desk[0].valid_to.is_some() || desk[0].valid_to_precision.is_some(),
"after a same-identity update and an explicit reconcile the desk row is still open \
(reconcile corrected {} rows, recorded {} conflicts): {desk:?}",
report.corrected.len(),
report.conflicts
);
anyhow::Ok(())
}
.await;
cleanup(&pool, f.org).await?;
run
}Refs #875 and #898. No production fix is included in this report.
Source: deeplethe/utopia