Repository navigation
feat(topology): late-parent arrival deterministic edge repair (#1259) - #1392
Conversation
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.
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 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".
|
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. |
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_idandbranch_typefast-path columns inaddition to flipping the
topology_edgesrow toresolved. This restores theancestry-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
resolvedwhen the parentarrived. But the original
conversations.parent_conversation_idcolumn wasintentionally 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
PrepareCachecould miss the child's still-pending upsert and thechild'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=unresolvedeven though the parent was now inconversations.Solution
polylogue/storage/sqlite/queries/topology_edges.py:resolve_topology_edges_for_conversation(the parent-arrival path) nowSELECTs the children it is about to flip and
UPDATEs each child'sconversations.parent_conversation_id/branch_typewithCOALESCEso existing fast-path state is preserved and the operation stays
idempotent across re-ingest.
branch_typeis restricted to the closedBranchTypevocabulary so futureRESUME/BRANCH/REPAIREDedgekinds cannot violate the CHECK constraint on
conversations.branch_type.resolve_unresolved_edges_for_childruns after the child's ownupsert in
save_via_backend. It joins the child's unresolved edgesagainst
conversationson(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_backendcalls the new race-closure helper after the existingupsert_topology_edges+resolve_topology_edges_for_conversationpair.tests/unit/storage/test_topology_edges.py:the new repair behavior.
TestTopologyLateParentRepaircovering: 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
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]