Skip to content

refactor(storage): delete dead session_links cycle-quarantine engine - #3655

Merged
Sinity merged 2 commits into
masterfrom
feature/storage/session-links-dead-cycle-engine-cleanup
Aug 3, 2026
Merged

refactor(storage): delete dead session_links cycle-quarantine engine#3655
Sinity merged 2 commits into
masterfrom
feature/storage/session-links-dead-cycle-engine-cleanup

Conversation

@Sinity

@Sinity Sinity commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Summary

Completes the remaining polylogue-4ts.10 scope left as follow-up by #3643: deletes the dead async cycle-detection/quarantine engine in storage/sqlite/queries/session_links.py (zero production callers since #3643 ported the equivalent logic into the live writer), and retargets the three wrong-oracle tests that exercised only that dead engine at the real production write path (write_parsed_session_to_archive).

Problem

#3643 ported cycle detection + quarantine into the live session_links writer (write.py's _resolve_outbound_session_links / _resolve_session_graph), but left storage/sqlite/queries/session_links.py's equivalent async engine (upsert_session_links, resolve_session_links_for_session, resolve_unresolved_links_for_child, _would_create_cycle, _quarantine_link, count_quarantined_session_links) in place with zero production callers. Three tests exercised only that dead engine while implicitly or explicitly claiming to certify production behavior:

  • tests/unit/insights/test_topology_cycle_rejection.py (a dedicated 621-line file bootstrapping a raw sqlite3 connection and calling the dead engine directly).
  • test_delegation_direction_matches_real_link_resolver in test_delegations_view.py, whose docstring explicitly claimed to drive "the ACTUAL production write path" via the dead engine's functions.
  • test_session_link_resolver_quarantines_cycle in the property write-path state machine, which manually inserted a session_links row and called the dead engine's resolve_unresolved_links_for_child to simulate a cycle.

This is exactly the wrong-oracle pattern flagged by the 2026-08-03 structural audit referenced on the bead: tests certifying behavior production code cannot exhibit.

Solution

  • Deleted the dead write engine from queries/session_links.py, keeping only list_session_links_for_session (a genuine production read path reached via query_store_archive.py).
  • Deleted tests/unit/insights/test_topology_cycle_rejection.py outright: its scenarios (two-node cycle, self-loop, diamond DAG) are already covered against the live path by test_topology_cycle_quarantine_live.py (landed with fix(storage): quarantine real cycles in the live session_links resolver #3643).
  • Retargeted test_delegation_direction_matches_real_link_resolver to drive write_parsed_session_to_archive directly instead of the dead engine's upsert_session_links/resolve_session_links_for_session. Removed the now-unused _AsyncSqliteAdapter/_AsyncCursorAdapter shim built specifically to run the dead engine.
  • Retargeted test_session_link_resolver_quarantines_cycle to reproduce the cycle via a real re-ingest through write_parsed_session_to_archive (matching the pattern in test_topology_cycle_quarantine_live.py) instead of manually inserting a row and calling the dead engine.
  • Removed now-unused imports (aiosqlite, configure_connection, asyncio where no longer needed).

AC status (polylogue-4ts.10)

  • AC1 (every write carries TopologyEdgeStatus/method, no empty-status writes): satisfied by fix(storage): quarantine real cycles in the live session_links resolver #3643, unaffected by this PR.
  • AC2 (existing rows converge via ordinary derived-tier rebuild, no bespoke backfill): unaffected, no migration added.
  • AC3 (a reader can filter edges by status, composition degrades visibly on a non-resolved parent): satisfied. list_session_links_for_session already returns status; downstream consumers already read it -- storage/insights/topology/derivation.py excludes quarantined edges from unresolved-edge composition, and insights/transforms.py threads child_link_status (including "quarantined") onto SubagentReport. Composition already degrades visibly: a quarantined edge's child never gets sessions.parent_session_id set, so it surfaces as its own root rather than silently composing through the rejected parent. No new reader surface was needed beyond confirming these existing paths.
  • AC4 (live re-measure shows zero empty status/method rows): explicitly out of scope for this PR -- requires rebuilding the production index (polylogue ops reset --index && polylogued run), a separate operator action, not a code change.

Verification

  • devtools test tests/unit/storage/test_delegations_view.py tests/unit/storage/test_topology_cycle_quarantine_live.py tests/unit/storage/test_unread_wire_batch_v46.py tests/unit/storage/test_archive_tiers_write.py tests/property/test_write_path_state_machine.py -- 120 passed
  • devtools verify --quick -- exit 0 (ruff format/check, mypy --strict, render all --check, all lab policy gates)

Ref polylogue-4ts.10

Sinity and others added 2 commits August 3, 2026 18:53
Ref polylogue-4ts.10

Problem: #3643 ported cycle detection + quarantine into the live
session_links writer (write.py's _resolve_outbound_session_links /
_resolve_session_graph), leaving storage/sqlite/queries/session_links.py's
equivalent async engine (upsert_session_links, resolve_session_links_for_
session, resolve_unresolved_links_for_child, _would_create_cycle,
_quarantine_link, count_quarantined_session_links) with zero production
callers. Three tests exercised only that dead engine while claiming to
certify production behavior: tests/unit/insights/test_topology_cycle_
rejection.py (a dedicated 621-line file), test_delegation_direction_
matches_real_link_resolver in test_delegations_view.py (explicitly
docstring-labeled "the ACTUAL production write path"), and
test_session_link_resolver_quarantines_cycle in the property write-path
state machine -- all wrong-oracle tests per the 2026-08-03 structural
audit referenced on the bead.

Solution:
- Deleted the dead write engine from queries/session_links.py, keeping
  only list_session_links_for_session (a genuine production read path via
  query_store_archive.py).
- Deleted tests/unit/insights/test_topology_cycle_rejection.py outright:
  its scenarios (two-node cycle, self-loop, diamond DAG) are already
  covered against the live path by test_topology_cycle_quarantine_live.py
  (landed with #3643).
- Retargeted test_delegation_direction_matches_real_link_resolver to
  drive write_parsed_session_to_archive directly instead of the dead
  engine's upsert_session_links/resolve_session_links_for_session.
- Retargeted test_session_link_resolver_quarantines_cycle to reproduce
  the cycle via a real re-ingest through write_parsed_session_to_archive
  (matching the pattern in test_topology_cycle_quarantine_live.py)
  instead of manually inserting a session_links row and calling the dead
  engine's resolve_unresolved_links_for_child.
- Removed now-unused imports/helpers (_AsyncSqliteAdapter/_AsyncCursorAdapter
  in test_delegations_view.py, aiosqlite/configure_connection/asyncio in
  the other two files).

This completes the remaining polylogue-4ts.10 scope noted as follow-up in
#3643: AC1 (every write carries TopologyEdgeStatus/method -- satisfied by
#3643, unaffected here), AC2 (existing rows converge via ordinary
derived-tier rebuild -- unaffected, no migration added), AC3 (a reader can
filter by status -- list_session_links_for_session already returns status;
downstream consumers already read it: storage/insights/topology/
derivation.py excludes quarantined edges from unresolved-edge composition,
insights/transforms.py threads child_link_status including "quarantined"
onto SubagentReport). Composition already degrades visibly on a
quarantined edge: the child's sessions.parent_session_id stays NULL, so it
surfaces as its own root rather than silently composing through the
rejected parent.

Not done here (explicitly out of scope for this change): AC4's live-
archive re-measure requires rebuilding the production index, which is a
separate operator action (polylogue ops reset --index && polylogued run),
not a code change.

Verification:
- devtools test tests/unit/storage/test_delegations_view.py
  tests/unit/storage/test_topology_cycle_quarantine_live.py
  tests/unit/storage/test_unread_wire_batch_v46.py
  tests/unit/storage/test_archive_tiers_write.py
  tests/unit/storage/test_lineage_normalization.py
  tests/unit/storage/test_session_topology.py
  tests/unit/storage/test_topology_edges.py -- 164 passed
- devtools test tests/property/test_write_path_state_machine.py -- 4 passed
- devtools verify --quick -- exit 0 (ruff format/check, mypy --strict,
  render all --check, all lab policy gates)

Co-Authored-By: Claude <noreply@anthropic.com>
Ref polylogue-4ts.10

Companion to 8d1d068 (which deleted the dead engine itself from
storage/sqlite/queries/session_links.py) -- this commit was meant to land
atomically with that one but the staging command silently dropped these
three modified files when git add hit a missing pathspec earlier in the
same invocation.

- queries/session_links.py: slim module docstring explaining the deletion
  and narrowed __all__ (list_session_links_for_session only).
- test_delegations_view.py: test_delegation_direction_matches_real_link_
  resolver now drives write_parsed_session_to_archive directly; removed
  the now-unused _AsyncSqliteAdapter/_AsyncCursorAdapter shim and its
  imports.
- test_write_path_state_machine.py: test_session_link_resolver_
  quarantines_cycle now reproduces the cycle via a real re-ingest through
  write_parsed_session_to_archive instead of manually inserting a
  session_links row and calling the dead engine's
  resolve_unresolved_links_for_child; removed now-unused aiosqlite/
  configure_connection imports.

Verification: same as 8d1d068 (devtools test across the touched files,
devtools verify --quick exit 0) -- rerun after this fix to confirm the
combined diff is what was actually tested:
- devtools test tests/unit/storage/test_delegations_view.py
  tests/property/test_write_path_state_machine.py -- all passed
- devtools verify --quick -- exit 0

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4e840e6e-207a-4948-a95e-a696d9e01aca

📥 Commits

Reviewing files that changed from the base of the PR and between b4558a9 and 6d5f8a1.

📒 Files selected for processing (4)
  • polylogue/storage/sqlite/queries/session_links.py
  • tests/property/test_write_path_state_machine.py
  • tests/unit/insights/test_topology_cycle_rejection.py
  • tests/unit/storage/test_delegations_view.py

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.

@Sinity
Sinity merged commit 636b63e into master Aug 3, 2026
3 checks passed
@Sinity
Sinity deleted the feature/storage/session-links-dead-cycle-engine-cleanup branch August 3, 2026 17:15
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