Skip to content

fix(dream): reconcile snapshot state after supersedes reclassification - #44

Open
TurgutKural wants to merge 3 commits into
GottZ:rootfrom
TurgutKural:fix/dream-supersedes-state-reconcile
Open

TurgutKural wants to merge 3 commits into
GottZ:rootfrom
TurgutKural:fix/dream-supersedes-state-reconcile

Conversation

@TurgutKural

Copy link
Copy Markdown
Contributor

Problem

WriteLinks can update an existing (source_block_id, target_block_id) relation from supersedes to another relationship via ON CONFLICT DO UPDATE.

A high-confidence supersedes relation marks the target as:

  • lifecycle_state='snapshot'
  • superseded_by=<source>

When that same pair is later reclassified to topical or recurrent, the relation changes but the lifecycle side effect is not reverted. replaceStaleLinks does not catch this because the target is still part of the kept pair set.

A read-only production audit found 21 active snapshot blocks without a current matching supersedes relation; 18/21 currently have the same source-target pair reclassified as topical or recurrent.

Fix

  • Reconcile target supersession state after relevant relation changes.
  • Preserve snapshot state if another eligible current superseder remains.
  • Restore to the existing knowledge / superseded_by=NULL semantics when none remain.
  • Apply the same invariant to current dangling-link cleanup where an active target can otherwise be orphaned.
  • Keep the existing weighted-confidence semantics.
  • Persisted eligibility checks use the stored REAL confidence representation (>= 0.7::real).
  • No schema, migration, retrieval, prompt, or lifecycle redesign.

Tests added

  • TestWriteLinks_SupersedesReclassification_RestoresSnapshot
  • TestWriteLinks_SupersedesToRecurrent_RestoresSnapshot
  • TestWriteLinks_Reclassification_PreservesOtherSuperseder
  • TestWriteLinks_StaleSupersedesRemoval_RestoresSnapshot
  • TestWriteLinks_ValidSupersedesRewrite_PreservesSnapshot
  • TestCleanupDanglingLinks_ArchivedTargetDoesNotResurrect
  • TestWriteLinks_SupersedesConfidenceDowngrade_RestoresSnapshot
  • TestWriteLinks_PersistsWeightedAndRawConfidenceSeparately
  • TestWriteLinks_SupersedesBoundaryConfidence_PreservesSnapshot

Corpus impact

A read-only preview indicates that 21 current orphan snapshots would be restored under the fixed invariant, while 14 valid supersedes relation targets would remain snapshot/current; one multi-superseder pointer would be realigned.

This PR performs no production data repair, UPDATE, migration, cleanup, or container change.

Turgut added 3 commits September 19, 2026 16:04
WriteLinks can reclassify an existing source-target pair from supersedes to topical or recurrent through ON CONFLICT DO UPDATE without reverting the supersedes snapshot side-effect. replaceStaleLinks only restores state for physical stale-link removal, leaving orphan snapshot state. Reconcile target lifecycle state from the current eligible supersedes set, preserve a snapshot when another valid superseder remains, and reuse the existing knowledge/superseded_by=NULL restore semantics. Keep existing weighted-confidence behavior and do not introduce new lifecycle semantics or thresholds.
@TurgutKural
TurgutKural marked this pull request as ready for review September 19, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant