Skip to content

fix(lineage): compose sibling variants canonically - #2922

Merged
Sinity merged 4 commits into
masterfrom
feature/integration/lineage-handoffs
Jul 16, 2026
Merged

Sinity merged 4 commits into
masterfrom
feature/integration/lineage-handoffs

Conversation

@Sinity

@Sinity Sinity commented Jul 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

Make write-side lineage signatures use the same canonical sibling-variant order
as composed reads, and prevent a missing branch point from fabricating an
inherited prefix during later ingestion. Add production-route regressions for
parent/child order, replacement, missing sibling cuts, and dangling-ancestor
reingest.

Problem

Writer-side prefix alignment considered only variant zero while composed reads
include all sibling variants. This made physical child tails depend on ingest
order and could retain a duplicated sibling. Separately, a missing branch point
caused writer alignment to inherit the accumulated parent prefix even though
readers correctly expose only the child's bounded tail.

Solution

  • Order writer signatures by (position, variant_index, block position) and
    include every sibling variant.
  • Treat an absent branch point as no inherited writer-side prefix.
  • Exercise the real SQLite writer, physical rows and links, async composed
    reader, parent replacement, dangling cuts, and child reingest.
  • Generate replacement timestamps with monotonic real datetime arithmetic so
    the state machine cannot accidentally model fresh writes as stale after 59
    updates.

Ref polylogue-866e. Ref polylogue-t8t. The supplied t8t continuity package was
not applied because it implemented only two of seven routes and introduced a
competing scenario seam.

Acceptance status

  • Satisfied for this slice: canonical sibling ordering and parent-first versus
    child-first convergence; bounded behavior when a direct branch cut is
    missing; no fabricated prefix on dangling-ancestor reingest.
  • Still open under polylogue-866e: persisted semantic cut witnesses,
    crash/rollback fault injection, exhaustive saved examples, and complete
    nested-ancestor completeness propagation.
  • No polylogue-t8t acceptance criterion is claimed.

Verification

  • Focused lineage/property/storage run after coordinator review — 28 passed,
    1 inherited property failure.
  • Baseline origin/master property run — 1 failed with three distinct
    counterexamples; this branch removes the two sibling-replacement failures but
    retains the pre-existing nested dangling-completeness counterexample.
  • devtools test -k 'session_links or composed' — 11 passed.
  • Dangling-ancestor deterministic regression — passed.
  • devtools verify --quick — 16/16 checks passed, run
    20260716T014100Z-quick-2135389-bff17c2f.
  • Pre-push quick gate — 16/16 checks passed, run
    20260716T014141Z-quick-2136224-5f98b796.

Anti-vacuity: restoring the primary-only signature query leaves the sibling in
the child tail; removing the missing-cut guard fabricates a prefix and drops
part of the child's physical replay. Both mutations fail production-route
regressions.

Summary by CodeRabbit

  • Bug Fixes

    • Improved transcript lineage composition for messages with multiple variants.
    • Prevented incomplete or dangling lineage branches from producing fabricated inherited content.
    • Added safeguards for very deep lineage chains and preserved correct behavior during replacement and re-ingestion.
  • Tests

    • Expanded coverage for variant-aware lineage, deep compositions, and query behavior.
    • Improved timestamp generation for more reliable state-based testing.

Sinity and others added 3 commits July 16, 2026 03:19
The write-side signature stream omitted non-primary variants while composed
reads retained them, making prefix-tail extraction depend on ingest order.

Order signatures by position and variant index, and drop inherited signatures
when a branch point is no longer present so re-ingest cannot fabricate a
complete prefix. Add parent-first/child-first, replacement, and dangling-cut
production regressions; make the state-machine freshness clock monotonic.

Ref polylogue-866e.

Co-Authored-By: Claude <[email protected]>
Exercise the production writer after an ancestor branch cut disappears.
The child must remain spawned-fresh with its complete physical replay, rather
than inheriting a surviving but semantically incomplete prefix.

Ref polylogue-866e.

Co-Authored-By: Claude <[email protected]>
Use real datetime arithmetic for generated replacement timestamps so
state-machine runs remain valid beyond the first minute and continue to
exercise fresh-write behavior rather than accidental stale rejection.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 665afbdf-81ce-43af-9b49-e17678ed32e8

📥 Commits

Reviewing files that changed from the base of the PR and between e0bc472 and 1ec3ac1.

📒 Files selected for processing (6)
  • polylogue/storage/runtime/store_constants.py
  • polylogue/storage/sqlite/archive_tiers/write.py
  • polylogue/storage/sqlite/queries/message_query_reads.py
  • tests/property/test_write_path_state_machine.py
  • tests/unit/storage/test_archive_tiers_write.py
  • tests/unit/storage/test_lineage_normalization.py

📝 Walkthrough

Walkthrough

The change centralizes lineage depth limits, replaces recursive writer composition with iterative traversal, includes all message variants in owned signatures, and adds coverage for variant branches, dangling lineage, deep chains, and deterministic timestamps.

Changes

Lineage composition and variant handling

Layer / File(s) Summary
Iterative lineage composition
polylogue/storage/runtime/store_constants.py, polylogue/storage/sqlite/archive_tiers/write.py, polylogue/storage/sqlite/queries/message_query_reads.py
Exports a shared lineage depth limit, applies it to reader and writer paths, and composes writer lineage iteratively with memoization and cycle/depth guards.
Variant-aware signature extraction
polylogue/storage/sqlite/archive_tiers/write.py, tests/unit/storage/test_archive_tiers_write.py
Includes all message variants in owned signature extraction and updates the query-plan assertion for the revised SQL projection and ordering.
Lineage normalization regressions
tests/unit/storage/test_lineage_normalization.py, tests/property/test_write_path_state_machine.py
Adds coverage for variant branches, dangling ancestors, deep lineage, and replacement/re-ingestion; state-machine timestamps now advance using a monotonic UTC counter.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Writer
  participant SessionLinks
  participant ComposedCache
  participant Reader

  Writer->>SessionLinks: Traverse ancestor chain iteratively
  Writer->>ComposedCache: Compose prefixes and owned tails
  Writer->>ComposedCache: Cache composed signatures
  Reader->>SessionLinks: Resolve lineage links
  Reader->>ComposedCache: Compose transcript with shared depth limit
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main lineage-canonicalization change.
Description check ✅ Passed The description is mostly complete, covering summary, problem, solution, and verification; only template sections like Changelog/Risks are not explicit.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/integration/lineage-handoffs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e222e6a2b6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Writer-side signature composition reused the recursive sync reader's 64-level guard even though the primary async reader composes iteratively to 1024. Valid branch points beyond that cutoff could therefore become spawned-fresh during extraction or re-ingest.\n\nWalk writer lineage iteratively with the same shared runaway limit as the async reader, retaining the sync envelope's explicit stack-safe truncation boundary. Add a 66-level production write/re-ingest regression that proves the root branch point remains canonical and physically deduplicated.\n\nCo-Authored-By: Claude <[email protected]>
@Sinity

Sinity commented Jul 16, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@Sinity
Sinity merged commit b55f3fd into master Jul 16, 2026
2 checks passed
@Sinity
Sinity deleted the feature/integration/lineage-handoffs branch July 16, 2026 02:17

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ec3ac1ec0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

LEFT JOIN blocks b ON b.session_id = m.session_id AND b.message_id = m.message_id
WHERE m.session_id = ? AND m.variant_index = 0
ORDER BY m.position, b.position
WHERE m.session_id = ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Filter lineage signatures to the active sibling path

When a parent has an inactive sibling before a later active-path message, a fork typically replays only the active path. Including every variant makes the parent signatures A, inactive-B, C while the child has A, C, ...; prefix alignment therefore stops after A, retains a duplicate C in the child, and records an earlier branch point. The added regression masks this because _msg sets is_active_path=True even for its variant-1 sibling; use active-path membership while still allowing an active nonzero variant.

Useful? React with 👍 / 👎.

@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 77.F007 / P2: fixed-already at the checked revision: Writer signature composition now walks iteratively until a root or visited session, with no 64-level cutoff; a valid deep inherited branch point is not discarded because of writer depth truncation. See polylogue/storage/sqlite/archive_tiers/write.py:11121.

Only the rows listed above are dispositioned. Held findings remain open.

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