Problem
An older successful materialization can publish its file lineage after a newer materialization has already written and published. The older stale_db_version plan can replace file_version=4, synced with file_version=3, pending, although storage still contains revision 4.
This was reproduced with real PostgreSQL sessions and the Cloud runtime while validating https://github.com/basicmachines-co/basic-memory-cloud/pull/2012. It is a separate existing Core publication issue, not evidence that conditional storage writes failed. No exact historical production occurrence of this ordering has been established.
Reproduction
Core pin: bccf09c
Use Cloud's apps/cloud/tests/pgq/test_materialization_overlap.py at PR2012 as the fixture:
- Start accepted revision 3 with no published file version and no stored object.
- Let worker A prepare, then accept revision 4 and let worker B prepare.
- Let A's conditional PUT land, but pause its
get_file_metadata return before Core publication.
- Let B observe accepted revision 3, write revision 4, and finish DB publication.
- Release A's metadata response and let its older publication finish.
Observed: storage remains revision 4, but NoteContent.file_version is 3 and file_write_status is pending, with db_version=4. The regression's assert row.file_version == row.db_version == 4 fails with 3 == 4.
In the fixture, use the unpublished-first-write ordering but wait for second_finished in A's metadata callback and do not hold B's PUT until first_finished. The checked-in ordering isolates the separate first-publication NULL-version guard; this alternate ordering isolates publication regression.
Investigation and constraints
Inspect RepositoryNoteMaterializationPublisher.publish_written_file_state and plan_written_note_materialization_publish. The CAS protects the current DB version read by the publisher, but that DB version can already be 4 when the older publisher plans a file-version-3 update. The successful CAS then applies a stale lineage plan.
Preserve the documented derived-state convergence policy and canonical lock ordering. Do not add SELECT-time locks or hold a transaction across storage. Account for local filesystem writers as well as Cloud conditional writes before assuming successful writes always arrive in accepted-version order.
Acceptance
- Add a real-session regression for both storage and publication completion orders.
- After the newer file has been written and published, an older completion must not leave synchronized current content falsely pending without durable convergence work.
- Preserve legitimate stale writes, moved-path cleanup, external conflicts, and current accepted content.
- Demonstrate the regression fails on the prior implementation.
- Follow through with the Cloud Core-pin update and hosted runtime regression once Core is fixed.
Problem
An older successful materialization can publish its file lineage after a newer materialization has already written and published. The older
stale_db_versionplan can replacefile_version=4, syncedwithfile_version=3, pending, although storage still contains revision 4.This was reproduced with real PostgreSQL sessions and the Cloud runtime while validating https://github.com/basicmachines-co/basic-memory-cloud/pull/2012. It is a separate existing Core publication issue, not evidence that conditional storage writes failed. No exact historical production occurrence of this ordering has been established.
Reproduction
Core pin: bccf09c
Use Cloud's
apps/cloud/tests/pgq/test_materialization_overlap.pyat PR2012 as the fixture:get_file_metadatareturn before Core publication.Observed: storage remains revision 4, but
NoteContent.file_versionis 3 andfile_write_statusispending, withdb_version=4. The regression'sassert row.file_version == row.db_version == 4fails with3 == 4.In the fixture, use the
unpublished-first-writeordering but wait forsecond_finishedin A's metadata callback and do not hold B's PUT untilfirst_finished. The checked-in ordering isolates the separate first-publication NULL-version guard; this alternate ordering isolates publication regression.Investigation and constraints
Inspect
RepositoryNoteMaterializationPublisher.publish_written_file_stateandplan_written_note_materialization_publish. The CAS protects the current DB version read by the publisher, but that DB version can already be 4 when the older publisher plans a file-version-3 update. The successful CAS then applies a stale lineage plan.Preserve the documented derived-state convergence policy and canonical lock ordering. Do not add SELECT-time locks or hold a transaction across storage. Account for local filesystem writers as well as Cloud conditional writes before assuming successful writes always arrive in accepted-version order.
Acceptance