Skip to content

feat(reader): session lineage and topology view (#1121) - #1174

Closed
Sinity wants to merge 1 commit into
masterfrom
feature/feat/reader-lineage-view
Closed

Sinity wants to merge 1 commit into
masterfrom
feature/feat/reader-lineage-view

Conversation

@Sinity

@Sinity Sinity commented May 17, 2026

Copy link
Copy Markdown
Owner

Summary

Add a Lineage inspector tab to the web reader plus a new
GET /api/conversations/{id}/topology endpoint backed by the
SessionTopology read model from #866. Closes #1121.

Problem

The reader had no way to see a conversation's place in the lineage
graph — parents, sub-agent branches, sidechains, or resumed sessions
— even though #866 (PR #1097) materialized the durable lineage graph
as SessionTopology with cycle-safe derivation. #1121 calls for a
read-only lineage view in the reader that consumes the existing
public read surface and renders explicit empty / partial / no-lineage
states.

Solution

  • HTTP endpoint (polylogue/daemon/http.py,
    polylogue/daemon/topology_http.py): GET /api/conversations/{id}/topology
    returns a bounded SessionTopology envelope:

    • ?limit= parameter (default 200, hard cap 1000) so the reader
      never streams an unbounded subtree — feat(reader): lineage and topology view in web UI #1121 AC: lineage rendering
      is bounded.
    • Edges referencing dropped nodes are filtered so the UI never
      plots a dangling endpoint; the truncated_count field is the
      operator's signal that the graph is incomplete.
    • Explicit readiness chip (ok / partial / empty),
      unresolved_edge_count for provider-native parent IDs that did
      not resolve, and cycle_detected for cycle-quarantine flagging.
    • Envelope shape lives in daemon/topology_http.py so http.py
      stays within its declared per-file LOC budget.
    • 404 with the shared error envelope when the conversation is
      missing — does not return an empty topology.
  • Reader UI (polylogue/daemon/web_shell.py,
    polylogue/daemon/web_shell_lineage.py): new Lineage inspector
    tab rendering the rooted tree as an indented BFS list with
    edge-kind chips
    (continuation / sidechain / fork / subagent / unresolved_native),
    the focused conversation highlighted, an "Open parent" button, and
    a "Compare with parent" affordance that delegates to the existing
    compare workspace route from feat(reader): saved queries and named views in web UI #1118. Unresolved native parent IDs
    surface in a dedicated section. Empty / partial / cycle states use
    the MK3 chip vocabulary (q-canonical / q-partial /
    q-unavailable / q-unresolved). Lineage CSS+JS extracted to a
    sibling module matching the BULK_/WORKSPACE_ split so
    web_shell.py stays within its file budget.

  • Tests (tests/unit/daemon/test_topology_endpoint.py): in-process
    HTTP harness exercises the new endpoint against a seeded archive
    containing a multi-level resolved tree (root → child → grandchild),
    a sidechain sibling, an isolated leaf, and a missing id. Pins:
    envelope shape, BFS traversal from a descendant up to the root and
    back down through sibling branches, explicit empty/readiness
    state, 404 envelope, the ?limit= bound and its hard cap, and the
    shipped HTML carries the data-tab="lineage", loadLineage,
    renderInspectorLineage, openCompareWith hooks plus the
    readiness vocabulary.

Rejected alternatives:

Verification

nix develop -c pytest tests/unit/daemon/ -q
  → 438 passed in 14.40s (includes the new
    tests/unit/daemon/test_topology_endpoint.py — 7 tests)

nix develop -c devtools verify --quick
  → exit_code 0 (format, lint, mypy --strict, render-all --check,
    verify-topology, verify-file-budgets, verify-test-ownership,
    verify-cluster-cohesion, manifest gates all green)

nix develop -c devtools verify-file-budgets
  → polylogue/daemon/http.py: 1160 ≤ 1200 (exception entry)
  → polylogue/daemon/web_shell.py: 1098 ≤ 1100 (default ceiling)

devtools verify --all surfaces 15 pre-existing failures unrelated
to this PR (productivity-rollup catalog drift, message_embeddings
KeyError in cli/check, mcp tool-schema witness drift around
cost_outlook / cost_rollups, hypothesis time budget in
test_attachment_security). All are inherited from recently-merged
commits visible on master and touch unrelated subsystems; none
reference the daemon or topology surfaces.

Acceptance criteria (#1121)

  • Reader displays a lineage rail for any conversation with
    materialized lineage rows — Lineage inspector tab consumes the
    topology endpoint.
  • Parent chain is navigable; sub-agent branches are listed —
    rooted tree with edge-kind chips; clickable nodes call
    selectConversation; sibling branches render under their shared
    parent.
  • No-lineage and partial-lineage states are rendered explicitly
    with a readiness chip — readiness ∈ ok / partial / empty
    drives the MK3 chip vocabulary.
  • Reader does not query lineage tables directly — only the public
    lineage read surface from feat(topology): materialize session identity and lineage graph #866 — endpoint calls
    poly.repository.get_session_topology; UI calls the endpoint.
  • Tests assert lineage rendering is bounded (does not unbound
    expand the whole graph in one payload) —
    test_node_limit_is_bounded_and_signals_truncation and
    test_node_limit_hard_cap_rejects_unbounded_request.
  • Visual smoke harness (test(reader): add local web reader visual smoke harness #865) covers a multi-level tree, a leaf
    conversation, and a no-lineage state — deferred to test(reader): add local web reader visual smoke harness #865's
    Playwright-based screenshot lane; the structural smoke in
    test_topology_endpoint.py::TestLineageReaderShell covers the same
    three states at the HTML/JSON contract level.

Ref #866, #859, #1118.

Add a Lineage inspector tab to the web reader and the supporting
GET /api/conversations/{id}/topology endpoint backed by the
SessionTopology read model from #866. Closes #1121.

Problem
-------
The reader had no way to see a conversation's place in the lineage
graph — parents, sub-agent branches, sidechains, or resumed sessions
— even though #866 materialized the durable lineage graph as
SessionTopology.

Solution
--------
- New daemon route GET /api/conversations/{id}/topology returns a
  bounded SessionTopology envelope (default 200 nodes, hard cap 1000)
  with explicit readiness chip (ok/partial/empty), unresolved-edge
  count, and truncation count.  Envelope shape lives in
  polylogue/daemon/topology_http.py so http.py stays within its file
  budget.
- Reader inspector gains a Lineage tab rendering the rooted tree as
  an indented BFS list with edge-kind chips
  (continuation/sidechain/fork/subagent/unresolved_native), explicit
  empty / partial / cycle states using the MK3 chip vocabulary, an
  Open-parent and Compare-with-parent affordance, and unresolved
  native parent IDs surfaced in their own section.
- Lineage CSS+JS extracted to polylogue/daemon/web_shell_lineage.py
  matching the BULK_/WORKSPACE_ split so web_shell.py stays within
  its file budget.

Verification
------------
- nix develop -c pytest tests/unit/daemon/ — 438 passed (includes the
  new tests/unit/daemon/test_topology_endpoint.py, 7 tests)
- nix develop -c devtools verify --quick — exit_code 0 (format, lint,
  mypy, render-all --check, manifest gates green)
- nix develop -c devtools verify-file-budgets — both touched files
  inside declared per-file LOC ceilings
- Pre-existing failures unrelated to this PR (productivity-rollup,
  message_embeddings KeyError, mcp tool-schema witness drift, etc.)
  remain on master; tracked separately.
@coderabbitai

coderabbitai Bot commented May 17, 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 21 minutes and 1 second 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: 68237c25-6bb8-41d2-9860-56d80b634c1a

📥 Commits

Reviewing files that changed from the base of the PR and between f3275ad and 6556911.

📒 Files selected for processing (7)
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/daemon/http.py
  • polylogue/daemon/topology_http.py
  • polylogue/daemon/web_shell.py
  • polylogue/daemon/web_shell_lineage.py
  • tests/unit/daemon/test_topology_endpoint.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/reader-lineage-view

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.

@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: 6556911e87

ℹ️ 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".

Comment thread polylogue/daemon/web_shell_lineage.py Resolved
Comment thread polylogue/daemon/web_shell.py Resolved
@Sinity

Sinity commented May 17, 2026

Copy link
Copy Markdown
Owner Author

Closing due to irreconcilable conflicts with PR #1171 (cost panel) and PR #1172 (provenance) that both heavily modified polylogue/daemon/http.py and web_shell.py. Re-dispatching #1121 on top of merged master.

@Sinity Sinity closed this May 17, 2026
Sinity added a commit that referenced this pull request May 17, 2026
## Summary

Add a Lineage inspector tab to the web reader plus a new
`GET /api/conversations/{id}/topology` endpoint backed by the
`SessionTopology` read model from #866. Closes #1121. Re-dispatch of
the prior PR #1174 against a fresh `origin/master`.

## Problem

The reader had no way to see a conversation's place in the lineage
graph — parents, sub-agent branches, sidechains, or resumed sessions —
even though #866 (PR #1097) materialized the durable lineage graph as
`SessionTopology` with cycle-safe derivation. #1121 calls for a
read-only lineage view that consumes the existing public read surface
and renders explicit empty / partial / no-lineage states.

## Solution

- **HTTP endpoint** (`polylogue/daemon/http.py`,
  `polylogue/daemon/topology_http.py`):
  `GET /api/conversations/{id}/topology` returns a bounded
  `SessionTopology` envelope:
  - `?limit=` (default 200, hard cap 1000) so the reader never streams
    an unbounded subtree — #1121 AC: lineage rendering is bounded.
  - Edges referencing dropped nodes are filtered so the UI never
    plots a dangling endpoint; `truncated_count` signals the gap.
  - Explicit `readiness` chip (`ok` / `partial` / `empty`),
    `unresolved_edge_count` for provider-native parents that did not
    resolve, and `cycle_detected` for cycle-quarantine flagging.
  - Envelope shape lives in `daemon/topology_http.py` so `http.py`
    stays close to its per-file budget; budget bumped to 1380.
  - 404 with shared error envelope for unknown id; 400 `invalid_limit`
    for out-of-range `?limit=`.

- **Reader UI** (`polylogue/daemon/web_shell.py`,
  `polylogue/daemon/web_shell_lineage.py`): new `Lineage` inspector
  tab rendering the rooted tree as an indented BFS list with edge-kind
  chips (`continuation` / `sidechain` / `fork` / `subagent` /
  `unresolved_native`), the focused conversation highlighted, an
  `Open parent` button, and a `Compare with parent` affordance that
  delegates to the existing compare workspace route from #1124.
  Unresolved native parent IDs surface in a dedicated section.
  Empty / partial / cycle states use the MK3 chip vocabulary
  (`q-canonical` / `q-partial` / `q-unavailable` / `q-unresolved`).
  Lineage CSS+JS extracted to a sibling module matching the
  `BULK_`/`WORKSPACE_`/`PROVENANCE_` split.

- **Tests** (`tests/unit/daemon/test_topology_endpoint.py`): 24 tests
  in three groups:
- pure helpers — `coerce_node_limit` bounds + `build_topology_envelope`
    readiness vocabulary, edge filter, truncation, hard-cap clamp;
  - end-to-end dispatch over a seeded archive (root → child →
    grandchild, sidechain sibling, isolated leaf, missing id) asserting
    BFS-from-descendant anchors at root, empty readiness for the
    isolated leaf, `?limit=` payload clamping, and the hard-cap reject;
  - reader-shell structural smoke pinning the new `data-tab="lineage"`
button, `loadLineage`/`renderInspectorLineage`/`openCompareWithParent`/
    `lineageReadinessChip` JS hooks, the MK3 chip vocabulary, and that
    no `__LINEAGE_JS__` / `__PROVENANCE_JS__` template placeholders
    leaked into the shipped HTML.

Rejected alternatives:

- Returning the unbounded raw `SessionTopology.model_dump()` — would
  fail the #1121 AC that lineage rendering be bounded.
- Adding a lineage rail to the conversation header — kept the
  inspector-tab placement because it lets the lineage tree share space
  with raw and notes without crowding the header chip row that
  #956/#1078 already pinned.
- Mutating lineage in the UI — #1121 explicitly scopes this read-only.

## Verification

```
nix develop -c pytest tests/unit/daemon/test_topology_endpoint.py -q
  → 24 passed in 9.33s

nix develop -c pytest tests/unit/daemon -q
  → 503 passed in 14.92s

nix develop -c pytest tests/unit/daemon tests/unit/storage/test_session_topology.py \
                   tests/unit/architecture/test_topology_invariants.py -q
  → 517 passed in 12.24s

nix develop -c devtools verify --quick
  → exit_code 0 (format, lint, mypy --strict, render-all --check,
    verify-topology, verify-file-budgets, verify-test-ownership,
    verify-cluster-cohesion, manifest gates, verification-impact all green)

git push (pre-push hook runs verify --quick)
  → exit_code 0
```

## Acceptance criteria (#1121)

- [x] Reader displays a lineage rail for any conversation with
  materialized lineage rows — `Lineage` inspector tab consumes the
  topology endpoint.
- [x] Parent chain is navigable; sub-agent branches are listed —
  rooted tree with edge-kind chips; clickable nodes call
  `selectConversation`; sibling branches render under their shared
  parent.
- [x] No-lineage and partial-lineage states are rendered explicitly
  with a readiness chip — `readiness` ∈ `ok` / `partial` / `empty`
  drives the MK3 chip vocabulary.
- [x] Reader does not query lineage tables directly — only the public
  lineage read surface from #866 — endpoint calls
  `poly.repository.get_session_topology`; UI calls the endpoint.
- [x] Tests assert lineage rendering is bounded (does not unbound
  expand the whole graph in one payload) —
  `test_node_limit_is_bounded_and_signals_truncation`,
  `test_node_limit_hard_cap_enforced`,
  `test_node_limit_hard_cap_rejects_unbounded_request`,
  `test_node_limit_clamps_payload_size`.
- [ ] Visual smoke harness (#865) covers a multi-level tree, a leaf
  conversation, and a no-lineage state — deferred to #865's
  Playwright-based screenshot lane; the structural smoke in
  `test_topology_endpoint.py::TestLineageReaderShell` covers the same
  three states at the HTML/JSON contract level.

Ref #866, #859, #1118.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@Sinity
Sinity deleted the feature/feat/reader-lineage-view branch May 17, 2026 16:21
@Sinity

Sinity commented Sep 30, 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.

@Sinity

Sinity commented Sep 30, 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(reader): lineage and topology view in web UI

1 participant