Skip to content

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

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/reader-lineage-view-v3
May 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/reader-lineage-view-v3

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. 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 — 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; 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 feat(reader): conversation compare side-by-side #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:

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)

  • 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,
    test_node_limit_hard_cap_enforced,
    test_node_limit_hard_cap_rejects_unbounded_request,
    test_node_limit_clamps_payload_size.
  • 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.

Summary by CodeRabbit

  • New Features
    • Added /api/conversations/{id}/topology endpoint to retrieve session topology with optional query limit parameter.
    • Added "Lineage" inspector tab to web shell for visualizing conversation topology structure.
    • Topology responses include readiness status, node/edge counts, truncation information, and cycle detection.

Review Change Stack

Adds a Lineage inspector tab in the web reader plus a new
`GET /api/conversations/{id}/topology` endpoint that returns a bounded
`SessionTopology` envelope from the #866 read surface.

- daemon/topology_http.py: pure envelope projection — node_limit (default
  200, hard cap 1000), readiness vocabulary (ok / partial / empty),
  edge filter that drops references to nodes outside the kept window so
  the UI never plots a dangling endpoint, and truncated_count /
  unresolved_edge_count / cycle_detected attribution fields.
- daemon/http.py: route + handler delegating to the envelope helper and
  to `poly.repository.get_session_topology`. 404 for unknown id,
  400 invalid_limit for out-of-range ?limit=.
- daemon/web_shell.py + daemon/web_shell_lineage.py: Lineage tab with
  BFS-indented rooted tree, edge-kind chips, focused-node highlight,
  unresolved-parent block, and Open parent / Compare with parent
  actions (the latter delegates to the existing compare workspace from
  #1124). JS extracted to its own module so web_shell.py stays under
  its file-size budget.
- tests/unit/daemon/test_topology_endpoint.py: 24 tests covering the
  envelope projection (readiness vocabulary, hard cap, edge filter),
  end-to-end dispatch over a seeded archive (multi-level tree, isolated
  leaf, descendant request anchoring at root, 404, ?limit= bound,
  invalid_limit), plus reader-shell structural smoke for the new
  Lineage tab and JS hooks.

Closes #1121.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented May 17, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6b9e4327-61b7-4a3c-a6e4-477db2361558

📥 Commits

Reviewing files that changed from the base of the PR and between bd026f1 and 250dd55.

📒 Files selected for processing (8)
  • docs/plans/file-size-budgets.yaml
  • 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

📝 Walkthrough

Walkthrough

This PR implements a lineage/topology view for the web reader, adding a new GET /api/conversations/{id}/topology endpoint that returns bounded JSON envelopes representing conversation lineage trees. The feature includes envelope building with server-enforced node limits, readiness classification, and JavaScript-based tree rendering integrated as a new "Lineage" inspector tab.

Changes

Lineage and Topology View

Layer / File(s) Summary
Topology envelope building and serialization
polylogue/daemon/topology_http.py
Introduces coerce_node_limit, JSON node/edge serializers, _readiness status calculation, and build_topology_envelope that bounds nodes/edges, filters dangling references, and computes readiness (ok/partial/empty) from truncation/unresolved edges/cycle signals.
Topology HTTP endpoint and routing
polylogue/daemon/http.py
Adds GET /api/conversations/{id}/topology[?limit=N] route dispatch and _handle_get_conversation_topology handler; validates limits, fetches topology, returns 404 not_found or bounded envelope via build_topology_envelope.
Web shell Lineage tab integration
polylogue/daemon/web_shell.py
Imports LINEAGE_JS, adds Lineage inspector tab button, introduces state.lineage for lazy-loaded topology payload, routes tab rendering, and injects __LINEAGE_JS__ into HTML template.
Lineage JavaScript component and tree rendering
polylogue/daemon/web_shell_lineage.py
Exports LINEAGE_JS constant containing embedded JavaScript that fetches topology endpoint, renders rooted lineage trees with edge-kind chips, readiness status display, and wires "Open parent" and "Compare with parent" actions to existing reader routes.
Topology endpoint and envelope unit tests
tests/unit/daemon/test_topology_endpoint.py
Covers coerce_node_limit validation (defaults, bounds, rejection rules); build_topology_envelope readiness/truncation/cycle behavior and edge filtering; endpoint routing with 404/invalid_limit responses; and HTML wiring smoke tests (Lineage tab, JS hooks, chip vocabulary, no unresolved placeholders).
Configuration and documentation updates
docs/plans/file-size-budgets.yaml, docs/plans/topology-target.yaml, docs/topology-status.md
Updates file-size budgets and topology projections to reflect new modules (topology_http.py, web_shell_lineage.py) and their line-of-code metrics; increments summary counts (Stable: 644→646, Total declared: 771→773).

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant ReaderUI as Reader UI
  participant Endpoint as GET /topology
  participant Repo as poly.repository
  participant Envelope as build_topology_envelope
  participant Readiness as _readiness
  participant JSRenderer as Lineage JS
  Browser->>ReaderUI: click Lineage tab
  ReaderUI->>ReaderUI: renderInspectorLineage()
  ReaderUI->>Endpoint: fetch /api/conversations/{id}/topology?limit=N
  Endpoint->>Repo: get_session_topology(conv_id)
  alt conversation found
    Repo-->>Envelope: SessionTopology
    Envelope->>Envelope: slice nodes by limit
    Envelope->>Envelope: filter edges (drop dangling refs)
    Envelope->>Readiness: node/edge/cycle counts
    Readiness-->>Envelope: readiness status
    Envelope-->>Endpoint: bounded envelope
    Endpoint-->>JSRenderer: 200 JSON envelope
    JSRenderer->>JSRenderer: render tree + chips
    JSRenderer->>JSRenderer: show readiness status
    JSRenderer-->>Browser: Lineage tree UI
  else conversation missing
    Repo-->>Endpoint: None
    Endpoint-->>JSRenderer: 404 not_found
    JSRenderer-->>Browser: error message
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A topology thread through the warren we weave,
Lineage branches where conversations breathe,
Parents and children in trees now displayed,
Bounded and readied, a feature well-made! 🌳✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/reader-lineage-view-v3

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 merged commit b3f36da into master May 17, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/feat/reader-lineage-view-v3 branch May 17, 2026 16:18

@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: 250dd55d24

ℹ️ 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/topology_http.py Resolved
Sinity added a commit that referenced this pull request May 19, 2026
…ts (#1203) (#1343)

## Summary

Bridges the lineage topology view (#1121) into the workspace stack route
and
adds per-message "continue this thread in another agent" deep-link
shortcuts.
Implements the #1203 work that was outstanding from MK3 Slice 6
(`docs/design/mk3/docs/10-implementation-slices.md:104`).

## Problem

MK3 Slice 6 called for the bridge between topology and the stack
workspace —
"select this branch chip, open its parent chain as a stack workspace".
#1121 /
PR #1176 landed the lineage and topology view; #1057 added the workspace
shell
modes (tabs / stack / compare / timeline). The stack lane previously
accepted
manually-entered conversation ids only — there was no UI affordance for
"render the root → sub-agent → continuation chain as a stack", and the
conversation header carried no branch chip telling the operator that a
conversation belonged to a multi-branch cluster.

Separately, the reader had no path back to the originating agent: an
operator
who wanted to keep working a thread in Claude Code or Codex had to copy
the
message text by hand. That is exactly the friction the MK3 design called
out
as the "thread-resumption hub" idea (also tracked in the #1203 ambitious
section).

## Solution

**Substrate / daemon**

- `polylogue/daemon/topology_http.py` grows
`build_parent_chain_envelope()`
which projects a `SessionTopology` into a stack-ready chain (root →
target
→ descendants) with `branch_kind`, `parent_id`, `siblings`, and
`focus_id`
surfaced. Uses the existing `SessionTopology.ancestors() / descendants()
/
  siblings()` helpers so the lineage walk stays in `insights/`.
- `GET /api/conversations/{id}/topology/parent-chain` returns the
envelope.
  `?descendants=0` narrows to the ancestor chain only.
- `polylogue/daemon/thread_continue.py` owns the per-agent URL-template
  registry (built-ins: `claude-code`, `codex`, `copy-prompt` clipboard
  fallback) and the URL constructor. Overrides flow through
  `POLYLOGUE_READER_AGENT_TEMPLATES`; invalid JSON falls back to the
built-ins so the reader never crashes on a malformed env var. Templates
  are substituted client-side so the daemon never observes the message
  text the operator is "continuing" elsewhere.
- `GET /api/thread-continue-templates` returns the active registry
envelope.

**Reader surface**

- Conversation header (`web_shell.py`) renders a topology branch chip
  (continuation / sidechain / fork / subagent / root) using the MK3 q-*
chip vocabulary, plus an "open chain" button next to it. The chip click
  routes to the Lineage inspector tab as the popover surface.
- Lineage inspector tab (`web_shell_lineage.py`) gains a third action,
  "Open chain as stack", so the same affordance is reachable from either
  the header or the inspector.
- Workspace JS (`web_shell_workspace.py`) gains
`openParentChainAsStack(id)`
  which fetches the parent-chain envelope and routes to
  `/w/stack?ids=…&focus=…`.
- Per-message action rail (`web_shell_reader.py`) gains a `continue`
button
  that opens a small popover menu of agent templates. The `copy-prompt`
entry writes to `navigator.clipboard`; every other entry hands off to
the
  OS URL handler. The template registry is fetched once per session and
  cached.

**Alternatives rejected**

- Computing the parent chain client-side from the existing `/topology`
  envelope. Rejected: that envelope is BFS-ordered and bounded by node
  count; the stack needs the explicit ancestor walk + focus anchor. A
dedicated endpoint also keeps the topology→stack contract single-sourced
  for tests.
- Persisting agent URL templates in `polylogue.toml` like the embedding
keys. Rejected for this PR scope: an env-var override is sufficient for
  the operator workflow and avoids a config-schema migration. Can be
  promoted to TOML later without breaking the endpoint shape.

## Verification

```
$ devtools verify --quick
"exit_code": 0
$ devtools verify --seed-testmon --skip-slow
"passed": 8219, "xfailed": 2, "exit_code": 0
$ pytest tests/unit/daemon/ -q
622 passed
$ pytest tests/unit/daemon/test_topology_stack.py tests/unit/daemon/test_thread_continue.py -q
53 passed
```

File-size budgets updated to reflect the +14 lines on `web_shell.py`
(branch chip helpers, `openLineageInspector`) and +52 lines on `http.py`
(two new handlers + dispatch). Topology projection re-rendered to
include the new `daemon/thread_continue.py` module.

Closes #1203
@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.

  • 65.F015 / P2: Fix and current-source recheck assigned to polylogue-bwuz0; not claimed fixed. The HTTP route delegates bounding at polylogue/daemon/topology_http.py:130 to the shared helper, which still takes only the first node_limit nodes at polylogue/operations/topology_envelope.py:99. It preserves target_id in the copied envelope but neither reserves a target node nor retains its filtered ancestor/thread entries when that node falls outside the prefix.

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