Skip to content

fix: Project session topology from canonical session_links - #5188

Merged
Sinity merged 2 commits into
masterfrom
fix/topology-from-session-links
Sep 15, 2026
Merged

Sinity merged 2 commits into
masterfrom
fix/topology-from-session-links

Conversation

@Sinity

@Sinity Sinity commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Summary

Two public read paths still built the session graph by walking sessions.parent_session_id / root_session_id. They now project from canonical session_links, which this bead (polylogue-27ezu) makes the edge authority.

Problem

polylogue-27ezu decides that session_links is the edge authority: the session parent/root columns may accelerate lookup but must never synthesize an edge or replace its provenance. Two constructions at head contradicted AC2:

  • archive_tiers/archive.py::get_session_tree resolved the root via _root_session_id_for_tree and scanned sessions.root_session_id.
  • Found by census during the work, in the same file and therefore inside the declared target: session_lineage_edges — public through the daemon lineage list rows (operations/daemon_reads.py::_lineage_edges_payload) — materialized one-hop edges from parent_session_id / parent_session_id IN (...), and ignored composability entirely.

The repository read path (storage/repository/archive/tree.py) walked the parent column in a loop for get_parent / get_children / get_root / get_session_tree.

Solution

get_session_tree collects the link-connected neighbourhood (_topology_closure over _incident_session_links, both directions) and composes it through the single engine compose_session_topology; node order is the engine's BFS-from-root order, matching the facade's declared stable_order="depth,session_id". _root_session_id_for_tree is deleted.

session_lineage_edges selects composing session_links rows (resolved_dst_session_id IS NOT NULL AND topology_status_composes_sql()). A child with contradictory composable parents reports no parent and is dropped from the parent's child tuple — an excluded edge stays visible as evidence but is never traversed (AC5, which this route previously ignored).

repository/archive/tree.py projects from derive_session_topology_async over canonical link reads; the walk loop is gone. queries/session_links.py extracts SESSION_LINK_COLUMNS so the new sync reader and existing async readers select the same provenance columns — a divergence there would silently drop fields on one surface.

storage/repository/archive/reads.py was inspected and needed no change: it is a 22-line mixin composition, and the residual lived in the mixin it composes.

On the modified test

tests/unit/storage/test_query_unit_time_expression.py::test_get_session_tree_does_not_epoch_collide_timeless_sibling seeded only the accelerator columns and asserted the child appeared in the tree — so it could only pass while the implementation walked parent_session_id. It asserted the mechanism being removed.

The fixture now also seeds the canonical session_links row; the assertion is unchanged, so the test keeps its own invariant (a timeless sibling is not dropped by a NULL ordering key) and its anti-vacuity condition is documented in place. The code was not weakened to satisfy it.

New anti-vacuity tests prove authority in both directions: nulling the accelerator keeps the tree and the lineage edge; deleting the canonical row while the accelerator still claims "child of root" removes both.

Verification

devtools test tests/unit/storage/test_session_topology.py tests/unit/storage/test_tree_laws.py \
  tests/unit/api/test_topology_api.py                → PASSED exit 0  (receipt 20260915T141703Z-…)
devtools test tests/unit/storage tests/unit/api tests/unit/mcp tests/unit/pipeline \
  tests/unit/daemon tests/unit/operations            → PASSED exit 0, 7472 passed in 41:03
devtools verify --quick                              → exit 0, all 17 gates
devtools render all --check                          → exit 0, grep "out of sync" = 0

⚠ Landing order

archive_tiers/archive.py and queries/session_links.py are both IN the derived-schema identity closure (devtools schema closure, independently confirmed). This change moves the stamped derived identity and must land before a production rebuild starts; a mid-run landing silently invalidates it. repository/archive/tree.py is out.

This confirms the bead's most recent note and refutes an earlier note claiming all four files were outside the closure.

Residuals

  • AC8 unsatisfied: provider-shaped production-route coverage across clean / incremental / parent-first / child-first / resumed builds needs the rebuilt archive.
  • AC9 unsatisfied: the every-link-classifies census needs the rebuilt corpus; the bead's 9,497 links / 1,426 unresolved are discovery denominators, not fixtures.
  • AC1 is met for this residual; it was not re-proven for routes already closed by chore: Unify session topology as one complete session_links-owned publi… #5007 / fix: preserve topology page truncation signal #5012 / Project the coordination session tree from canonical session_links #5161. A grep at head finds no other session-graph walk (delegations hits are a different relation).
  • AC4 unchanged: UNRESOLVED_NATIVE stays read-compat only and is never emitted by the canonical mapper. Codex's structurally-absent parent_dispatch still yields child-side-only edges resolving as edge_only, which is correct and was left alone.
  • The bead's 28-entry write_scope remains broader than what was touched; the widening to session_lineage_edges and the shared column constant is evidenced above.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

Sinity and others added 2 commits September 15, 2026 16:22
The archive tier and the repository tree mixin both walked
sessions.parent_session_id, synthesizing edges the canonical
session_links relation never asserted. Both now compose through the one
topology engine; the parent/root columns stay write-side accelerators.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
session_lineage_edges materialized one-hop parent/child edges from the
sessions.parent_session_id accelerator, so a daemon lineage page could
show an edge the canonical relation never asserted and could traverse a
quarantined or conflicting one. It now reads composing session_links rows
and reports no parent for a contradicted child.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 49 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 942f3c75-b425-4a1c-ae09-4e71128d3895

📥 Commits

Reviewing files that changed from the base of the PR and between 9e4913c and eb7f36a.

📒 Files selected for processing (5)
  • polylogue/storage/repository/archive/tree.py
  • polylogue/storage/sqlite/archive_tiers/archive.py
  • polylogue/storage/sqlite/queries/session_links.py
  • tests/unit/storage/test_query_unit_time_expression.py
  • tests/unit/storage/test_session_topology.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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-09-15T14:33:50.710411Z eb7f36a PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Sinity
Sinity merged commit 99eca30 into master Sep 15, 2026
3 checks passed
@Sinity
Sinity deleted the fix/topology-from-session-links branch September 15, 2026 14:29
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