Skip to content

feat(topology): persist unresolved provider-native parent edges + closed enum (#1258) - #1377

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/topology-unresolved-edges-1258-v3
May 19, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/topology-unresolved-edges-1258-v3

Conversation

@Sinity

@Sinity Sinity commented May 19, 2026

Copy link
Copy Markdown
Owner

Bumps SCHEMA_VERSION 5→6 to add a topology_edges table that durably records
every parent reference emitted by a parser, including references whose parent
has not yet been ingested (out-of-order ingestion) or has been hard-deleted.

Closes #1258.

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

@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 22 minutes and 12 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: 8c8e20d1-1353-4017-8a2b-80d47f157a32

📥 Commits

Reviewing files that changed from the base of the PR and between d7af77a and 5cafe6d.

📒 Files selected for processing (17)
  • AGENTS.md
  • docs/architecture.md
  • docs/internals.md
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/archive/topology/__init__.py
  • polylogue/archive/topology/edge.py
  • polylogue/pipeline/prepare.py
  • polylogue/pipeline/prepare_enrichment.py
  • polylogue/pipeline/prepare_models.py
  • polylogue/storage/repository/archive/repository_writes.py
  • polylogue/storage/repository/archive/writes/conversations.py
  • polylogue/storage/sqlite/queries/topology_edges.py
  • polylogue/storage/sqlite/schema_ddl.py
  • polylogue/storage/sqlite/schema_ddl_archive.py
  • tests/unit/storage/test_dead_schema_sweep.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-unresolved-edges-1258-v3

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 enabled auto-merge (squash) May 19, 2026 15:58
@Sinity
Sinity force-pushed the feature/feat/topology-unresolved-edges-1258-v3 branch from 58f0692 to 25c0ce3 Compare May 19, 2026 16:29
…sed enum (#1258)

Bumps SCHEMA_VERSION 5→6 to add a `topology_edges` table that durably records
every parent reference emitted by a parser, including references whose parent
has not yet been ingested (out-of-order ingestion) or has been hard-deleted.

Closes #1258.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@Sinity
Sinity force-pushed the feature/feat/topology-unresolved-edges-1258-v3 branch from 25c0ce3 to 5cafe6d Compare May 19, 2026 16:35
@Sinity
Sinity merged commit 9293cc2 into master May 19, 2026
3 of 5 checks passed
@Sinity
Sinity deleted the feature/feat/topology-unresolved-edges-1258-v3 branch May 19, 2026 16:35
Sinity added a commit that referenced this pull request May 19, 2026
…#1392)

## 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 `UPDATE`s 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]>
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): persist unresolved provider-native parent edges (#866 slice A)

1 participant