Skip to content

feat(topology): cycle rejection and quarantine (#1260) - #1395

Merged
Sinity merged 2 commits into
masterfrom
feature/feat/topology-cycle-rejection-1260
May 19, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/feat/topology-cycle-rejection-1260

Conversation

@Sinity

@Sinity Sinity commented May 19, 2026

Copy link
Copy Markdown
Owner

Summary

When resolving a topology edge would create a cycle in the
conversations.parent_conversation_id fast-path graph, the resolver
now refuses to backfill the cycle-creating edge. The offending edge is
left in topology_edges with status='quarantined' and a structured
raw_evidence JSON document recording the detected cycle path so the
operator can audit what was rejected. Surfaces the quarantine state in
the daemon workload probe.

Closes #1260. Ref #866 (slice C).

Problem

#1258 (slice A) made topology_edges durable for unresolved parent
references; #1259 (slice B) added the late-parent repair that, on
parent arrival, flips unresolved edges to resolved and backfills
the child's parent_conversation_id. Neither slice protected against
the case where the parent backfill would close a cycle (A → B → A,
longer cycles, self-cycle A → A). Without rejection, the fast-path
ancestry walk used by derive_session_topology_async,
thread_root_id and other downstream readers could enter an infinite
loop (or terminate only via the existing cycle-safe guards, but with
nonsensical lineage). The #866 / #1260 acceptance criteria require
explicit rejection with structured evidence — no silent drop.

Solution

  • polylogue/archive/topology/edge.py — TopologyEdgeStatus gains a
    QUARANTINED value.
  • polylogue/storage/sqlite/schema_ddl_archive.py — topology_edges
    CHECK constraint extended to allow quarantined. SCHEMA_VERSION is
    bumped 6 → 7 (no migration chain; per the existing policy, mismatch
    triggers re-ingest from source).
  • polylogue/storage/sqlite/queries/topology_edges.py — both resolver
    entry points (resolve_topology_edges_for_conversation and
    resolve_unresolved_edges_for_child) now invoke
    _would_create_cycle before any UPDATE. The helper walks the
    proposed parent's existing ancestry via parent_conversation_id,
    detects self-cycle and budget-exceeded as cycles, and returns the
    full path so the rejection record is auditable. On cycle:
    _quarantine_edge writes status='quarantined' plus a JSON
    {reason, cycle_path, detected_at} to raw_evidence; the
    conversations row is NOT touched. A new helper
    count_quarantined_topology_edges is exported for diagnostics.
  • devtools/daemon_workload_probe.py — adds
    topology_quarantine_state (unresolved/resolved/quarantined counts
    • oldest quarantined timestamp) and pulls topology_edges into the
      boundary table set. REPORT_VERSION bumped 2 → 3.
  • tests/unit/insights/test_topology_cycle_rejection.py — new
    evidence-bearing tests covering 2-node, 3-node, and self-cycle
    rejection through both resolver entry points; the diamond-DAG
    no-false-positive case (B→D, C→D both legit); the sibling-isolation
    case (cycle on one child must not quarantine a clean sibling sharing
    the parent batch); two idempotency assertions; and the
    count_quarantined_topology_edges diagnostic.
  • tests/unit/storage/test_dead_schema_sweep.py — pin updated for
    SCHEMA_VERSION 7.

Re-ingest plan

This PR bumps SCHEMA_VERSION 6 → 7 by widening the
topology_edges.status CHECK to include quarantined. Per the
existing schema policy (docs/internals.md § Schema Versioning Model):

  • Operator action: polylogue reset --database && polylogued run
    re-acquires from source.
  • Auto-rebuilt downstream: derived insights and FTS rebuild as part of
    the normal convergence pass; the blob store is unaffected.
  • Expected impact: re-ingest time on the order of a normal full
    catch-up; no extra disk usage.

No existing data needs format conversion — the change is purely an
expansion of the allowed status vocabulary.

Verification

  • nix develop -c pytest tests/unit/insights/test_topology_cycle_rejection.py -x — 9 passed
  • nix develop -c pytest tests/unit/insights/ tests/unit/storage/test_topology_edges.py -x — 151 passed (no regressions on the existing slice A/B suite)
  • nix develop -c devtools verify --quick — exit_code 0 (lint, format, mypy, render-all, manifest gates, verify-test-clock-hygiene)

Two pre-existing failures observed in broader runs (cli() got an unexpected keyword argument 'cursor' in CLI tests, and the
SimpleNamespace topology_edges attribute error in
test_prepare_runtime) are present on master and unrelated to this PR.

🤖 Generated with Claude Code

Sinity and others added 2 commits May 20, 2026 00:40
Both resolver paths (resolve_topology_edges_for_conversation and
resolve_unresolved_edges_for_child) now check whether backfilling
conversations.parent_conversation_id would create a cycle in the
fast-path ancestry graph. On detection the edge is moved to
status='quarantined' with raw_evidence JSON recording the cycle path;
the conversations row is left untouched so the ancestry walk never
enters the cycle. Add count_quarantined_topology_edges helper and
surface topology_quarantine_state in the daemon workload probe so
operators see cycle rejections. Bump SCHEMA_VERSION to 7 for the
extended TopologyEdgeStatus CHECK and topology_edges in the boundary
table set.

Ref #1260 (slice C of #866).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- frozen_clock.fixed_now() for test timestamps (verify-test-clock-hygiene).
- mypy: explicit ConversationId() construction, generic tuple param annotation,
  intermediate typed binding for fetchone() return.
- Update test_dead_schema_sweep pin: SCHEMA_VERSION 6 → 7 (#1260 quarantine status).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@Sinity
Sinity merged commit bf715ca into master May 19, 2026
2 of 5 checks passed
@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 1 minute and 40 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: c5637e9c-f0af-406f-99b1-96da64b670fc

📥 Commits

Reviewing files that changed from the base of the PR and between 281e2f2 and 1637fd0.

📒 Files selected for processing (7)
  • devtools/daemon_workload_probe.py
  • polylogue/archive/topology/edge.py
  • polylogue/storage/sqlite/queries/topology_edges.py
  • polylogue/storage/sqlite/schema_ddl.py
  • polylogue/storage/sqlite/schema_ddl_archive.py
  • tests/unit/insights/test_topology_cycle_rejection.py
  • tests/unit/storage/test_dead_schema_sweep.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/topology-cycle-rejection-1260

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 deleted the feature/feat/topology-cycle-rejection-1260 branch May 19, 2026 22:42

@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: 1637fd0cdb

ℹ️ 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): cycle rejection and quarantine (#866 slice C)

1 participant