Skip to content

feat(topology): late-parent arrival deterministic edge repair (#1259) - #1392

Merged
Sinity merged 3 commits into
masterfrom
feature/feat/topology-late-parent-repair-1259-v2
May 19, 2026
Merged

Sinity merged 3 commits into
masterfrom
feature/feat/topology-late-parent-repair-1259-v2

Conversation

@Sinity

@Sinity Sinity commented May 19, 2026

Copy link
Copy Markdown
Owner

Summary

Slice B of #866 / closes #1259: when a late-arriving parent conversation lands,
the topology resolver now backfills the child's
conversations.parent_conversation_id and branch_type fast-path columns in
addition to flipping the topology_edges row to resolved. This restores the
ancestry-walk fast path for out-of-order ingest without requiring re-ingest of
the child, and also closes the concurrent-ingest race between parent and child
prepare cycles.

Problem

Slice A (#1258, PR #1377) persisted unresolved provider-native parent edges
and added the resolver helper that flipped them to resolved when the parent
arrived. But the original conversations.parent_conversation_id column was
intentionally left NULL on a late-arriving repair — slice A's own test
asserted this gap. Every downstream that walks parent_conversation_id
(session-topology derivation, threads, web reader lineage view) therefore
saw an orphan child until the next time the child itself was re-ingested.

There was also a race: when parent and child were prepared concurrently, the
parent's PrepareCache could miss the child's still-pending upsert and the
child's cache could miss the parent's still-pending commit. The parent's
resolver pass then found nothing to flip, and the child's later upsert wrote
status=unresolved even though the parent was now in conversations.

Solution

polylogue/storage/sqlite/queries/topology_edges.py:

  • resolve_topology_edges_for_conversation (the parent-arrival path) now
    SELECTs the children it is about to flip and UPDATEs each child's
    conversations.parent_conversation_id / branch_type with COALESCE
    so existing fast-path state is preserved and the operation stays
    idempotent across re-ingest. branch_type is restricted to the closed
    BranchType vocabulary so future RESUME/BRANCH/REPAIRED edge
    kinds cannot violate the CHECK constraint on conversations.branch_type.
  • New resolve_unresolved_edges_for_child runs after the child's own
    upsert in save_via_backend. It joins the child's unresolved edges
    against conversations on (provider_name, provider_conversation_id)
    and flips any edge whose parent now exists — closes the concurrent
    ingest race.

polylogue/storage/repository/archive/writes/conversations.py:

  • save_via_backend calls the new race-closure helper after the existing
    upsert_topology_edges + resolve_topology_edges_for_conversation pair.

tests/unit/storage/test_topology_edges.py:

  • Updated the pre-existing slice A test that asserted the gap to assert
    the new repair behavior.
  • Added TestTopologyLateParentRepair covering: late-parent backfill,
    idempotency across parent re-ingest, no-op when parent never arrives,
    multiple pending children → single parent, parent-first preservation,
    and concurrent parent+child ingest via asyncio.gather.

Hash boundary unchanged: topology edges are derived per ingest and stay
outside conversations.content_hash, same as user_corrections (#1131).
No schema change.

Verification

nix develop -c devtools verify --quick   # exit 0, 35.6 s
nix develop -c pytest tests/unit/storage/test_topology_edges.py \
                       tests/unit/storage/test_dead_schema_sweep.py \
                       tests/unit/insights/ -q
# 142 passed (insights + topology + dead-schema-sweep)
# 13 passed (test_topology_edges, including the new concurrent ingest test)

The concurrent-ingest test (test_concurrent_parent_and_child_ingest_resolves)
exercises both the parent-arrival resolver and the new child-side race-closure
helper depending on which coroutine commits first.

Ref #1259 #866.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Sinity added 3 commits May 19, 2026 23:49
Slice B of #866: extend resolve_topology_edges_for_conversation so that
flipping unresolved topology edges to resolved also backfills the child
conversation's parent_conversation_id and branch_type columns, restoring
the fast-path ancestry walk for out-of-order ingest without requiring
re-ingest of the child.

The backfill is conservative (COALESCE on both columns) so it never
overwrites parent-first fast-path state and remains idempotent across
re-ingest of the parent. branch_type is restricted to the closed
BranchType vocabulary so future RESUME/BRANCH/REPAIRED edge kinds cannot
violate the CHECK constraint.

Ref #1259 #866.
When parent and child conversations ingest concurrently, the parent's
prepare_records may build its PrepareCache without seeing the child's
edge (still being written) and the child's PrepareCache may build
without seeing the parent (not yet committed). The parent's
resolve_topology_edges_for_conversation pass then finds no unresolved
edges to flip, and the child's upsert writes status=unresolved even
though the parent is now in conversations.

Add resolve_unresolved_edges_for_child which sweeps the child's own
edges after the upsert, joins against conversations on
(provider_name, provider_conversation_id), and flips any edge whose
parent now exists. Backfills the same parent_conversation_id +
branch_type fast-path columns with the same COALESCE idempotency
guards as the parent-arrival path.

Ref #1259 #866.
@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 39 minutes and 55 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: a027947b-fc3c-4d70-9594-bd591293b3c4

📥 Commits

Reviewing files that changed from the base of the PR and between 529ea30 and 3b3d5e1.

📒 Files selected for processing (4)
  • AGENTS.md
  • polylogue/storage/repository/archive/writes/conversations.py
  • polylogue/storage/sqlite/queries/topology_edges.py
  • tests/unit/storage/test_topology_edges.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/topology-late-parent-repair-1259-v2

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 and usage tips.

@Sinity
Sinity merged commit 7295c2b into master May 19, 2026
3 of 5 checks passed
@Sinity
Sinity deleted the feature/feat/topology-late-parent-repair-1259-v2 branch May 19, 2026 22:03

@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: 3b3d5e108b

ℹ️ 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".

@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.

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.

feat(topology): late-parent arrival deterministic edge repair (#866 slice B)

1 participant