Skip to content

Project the coordination session tree from canonical session_links - #5161

Merged
Sinity merged 1 commit into
masterfrom
fix/topology-coordination-session-links
Sep 14, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/topology-coordination-session-links

Conversation

@Sinity

@Sinity Sinity commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Summary

The coordination context envelope was a second source of truth for session topology. It now composes through the one canonical session_links-owned graph engine, and reports its own bound instead of hiding it.

Problem

polylogue-27ezu decided one session_links-owned topology projection. PR #5007/#5012 landed that spine — _archive_session_topology is gone, and api/cli/mcp/daemon all reach storage/derived/topology/derivation.py through repository.get_session_topology. But the census that produced the bead's write_scope missed polylogue/coordination/envelope.py::_session_tree_payload, which is reachable from the public MCP context surface and was still building its own graph:

  • Resolved edges were synthesized from sessions.parent_session_id + branch_type — the exact red condition in AC2. tests/unit/coordination/test_envelope.py asserted this as correct: its fixture carried a single session_links row, and the two "resolved edges" it expected had no canonical row behind them at all.
  • A private edge mapper flattened an unresolved link's declared link_type to a generic "unresolved_native" kind, collapsing resolvedness into type (AC4 red).
  • cycle_detected=False was hard-coded, and quarantined/contradicted edges were invisible (AC5 red).
  • edges[:limit] truncated silently, and the compact projection trimmed nodes[:3]/edges[:3] again — a partial tree was indistinguishable from a whole one (AC6 red).

Separately, compose_session_topology raised KeyError when a composable edge resolved to a parent outside the bounded node scope.

Solution

  • compose_session_topology (was _compose) is now the public, single graph classification engine, narrowed to a TopologyNodeInput (session_id, origin, title) so a caller holding raw sessions rows reaches it without constructing a SessionRecord.
  • A resolved edge whose parent is out of scope is excluded with the named reason parent-out-of-scope instead of crashing or vanishing.
  • _session_tree_payload uses the parent/root columns for node discovery only and projects every edge from session_links. The target sorts first in discovery so a tight bound can never trim away the session the tree was requested for.
  • CoordinationSessionTreeEdgePayload gains composable / composability_reason; CoordinationSessionTreePayload gains conflicting_parent_detected, nodes_complete, edges_complete, truncated_node_count, truncated_edge_count, generation_id. The compact projection folds its own trim into those fields.
  • The fixture now carries the canonical link rows production's write_parsed_session_to_archive mints, so the existing assertions prove edges come from session_links.

Two anti-vacuity tests: test_coordination_tree_edges_come_only_from_session_links deletes the resolved link rows while leaving parent_session_id fully intact — red for any route that synthesizes from the accelerator columns; test_coordination_tree_reports_its_own_truncation is red if the completeness fields are dropped or the silent trim returns.

Verification

devtools test tests/unit/coordination/test_envelope.py tests/unit/storage/test_session_topology.py \
  tests/unit/storage/test_topology_edges.py tests/unit/api/test_topology_api.py \
  tests/unit/daemon/test_topology_endpoint.py tests/unit/daemon/test_topology_stack.py \
  tests/unit/mcp/test_envelope_contracts.py tests/unit/storage/test_tree_laws.py \
  tests/unit/pipeline/test_branching.py

devtools test: PASSED exit=0 diagnosis=pytest_passed — 127 passed.

devtools verify --quick → exit 0. devtools render all --check → exit 0, no out of sync lines. devtools gate layering → "violations":[],"count":0.

Schema closure

devtools schema closure reports out for all four source files touched (coordination/envelope.py, coordination/payloads.py, storage/derived/topology/derivation.py, storage/derived/topology/__init__.py). This change does not move the derived-schema identity and does not invalidate a seeded fixture cache or an in-flight rebuild.

Residuals

Not fixed here, reported as remaining polylogue-27ezu scope:

  • storage/sqlite/archive_tiers/archive.py::get_session_tree + _root_session_id_for_tree still walk parent_session_id/root_session_id with no session_links read. Public reach: Polylogue.get_session_tree (api/archive.py:7104), the sync wrapper (api/sync/sessions.py:168), and the MCP resource polylogue://session-tree/{conv_id} (mcp/server_resources.py:289). All four consumers are list-shaped (membership only, no edge traversal), so this is a scoping rather than an edge-provenance defect — but AC2 is not met until it reads canonical rows.
  • storage/repository/archive/tree.py (get_root/get_children/get_parent/get_session_tree) is a third parent-walk implementation with zero callers in production or tests apart from one incidental SessionRepository.get_session_tree call at tests/unit/pipeline/test_branching.py:423. Left in place pending an explicit retirement decision.
  • derive_session_topology_sync still describes itself as a test adapter and has no production callers.
  • read_archive_session_envelope still returns a truncated transcript with no completeness flag (Repair branch points invalidated by deferred prefix re-extraction #5090's recorded residual). This PR does not touch that path.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

The coordination context envelope built its own session graph: edges were
synthesized from sessions.parent_session_id + branch_type, a private mapper
flattened an unresolved link's declared type to a generic "unresolved_native"
kind, cycle_detected was hard-coded False, and edges[:limit] truncated
silently while the payload still read as a whole tree.

It now discovers candidate nodes through the parent/root accelerator columns
and hands the canonical session_links rows to compose_session_topology --
the one graph classification engine -- so every edge, its declared type,
composability and provenance comes from session_links. Truncation and
exclusion are reported on the payload instead of being hidden.

compose_session_topology is narrowed to TopologyNodeInput (session_id,
origin, title) so a caller holding raw `sessions` rows can reach the engine
without a second graph construction, and a resolved edge whose parent falls
outside the bounded scope is now excluded as "parent-out-of-scope" rather
than raising KeyError.

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 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 43 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: de6f3a72-9d91-49d2-a6b3-4677247e4988

📥 Commits

Reviewing files that changed from the base of the PR and between 890a292 and 1ef4478.

📒 Files selected for processing (5)
  • polylogue/coordination/envelope.py
  • polylogue/coordination/payloads.py
  • polylogue/storage/derived/topology/__init__.py
  • polylogue/storage/derived/topology/derivation.py
  • tests/unit/coordination/test_envelope.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 14, 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-14T22:28:38.587489Z 1ef4478 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 43668d1 into master Sep 14, 2026
3 checks passed
@Sinity
Sinity deleted the fix/topology-coordination-session-links branch September 14, 2026 23:10
Sinity added a commit that referenced this pull request Sep 15, 2026
## 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 #5007 / #5012 / #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.com/claude-code)

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

---------

Co-authored-by: Claude Opus 5 (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.

1 participant