Repository navigation
feat(reader): session lineage and topology view (#1121) - #1176
Conversation
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]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThis PR implements a lineage/topology view for the web reader, adding a new GET ChangesLineage and Topology View
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 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".
…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
|
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. |
|
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. |
Summary
Add a Lineage inspector tab to the web reader plus a new
GET /api/conversations/{id}/topologyendpoint backed by theSessionTopologyread model from #866. Closes #1121. Re-dispatch ofthe 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
SessionTopologywith cycle-safe derivation. #1121 calls for aread-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}/topologyreturns a boundedSessionTopologyenvelope:?limit=(default 200, hard cap 1000) so the reader never streamsan unbounded subtree — feat(reader): lineage and topology view in web UI #1121 AC: lineage rendering is bounded.
plots a dangling endpoint;
truncated_countsignals the gap.readinesschip (ok/partial/empty),unresolved_edge_countfor provider-native parents that did notresolve, and
cycle_detectedfor cycle-quarantine flagging.daemon/topology_http.pysohttp.pystays close to its per-file budget; budget bumped to 1380.
invalid_limitfor out-of-range
?limit=.Reader UI (
polylogue/daemon/web_shell.py,polylogue/daemon/web_shell_lineage.py): newLineageinspectortab rendering the rooted tree as an indented BFS list with edge-kind
chips (
continuation/sidechain/fork/subagent/unresolved_native), the focused conversation highlighted, anOpen parentbutton, and aCompare with parentaffordance thatdelegates 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 testsin three groups:
coerce_node_limitbounds +build_topology_envelopereadiness vocabulary, edge filter, truncation, hard-cap clamp;
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;data-tab="lineage"button,
loadLineage/renderInspectorLineage/openCompareWithParent/lineageReadinessChipJS hooks, the MK3 chip vocabulary, and thatno
__LINEAGE_JS__/__PROVENANCE_JS__template placeholdersleaked into the shipped HTML.
Rejected alternatives:
SessionTopology.model_dump()— wouldfail the feat(reader): lineage and topology view in web UI #1121 AC that lineage rendering be bounded.
inspector-tab placement because it lets the lineage tree share space
with raw and notes without crowding the header chip row that
feat(webui): aesthetics, layout, informability — surface what matters #956/refactor(proof): extract _build_subjects helper to compress discovery boilerplate #1078 already pinned.
Verification
Acceptance criteria (#1121)
materialized lineage rows —
Lineageinspector tab consumes thetopology endpoint.
rooted tree with edge-kind chips; clickable nodes call
selectConversation; sibling branches render under their sharedparent.
with a readiness chip —
readiness∈ok/partial/emptydrives the MK3 chip vocabulary.
lineage read surface from feat(topology): materialize session identity and lineage graph #866 — endpoint calls
poly.repository.get_session_topology; UI calls the endpoint.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.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::TestLineageReaderShellcovers the samethree states at the HTML/JSON contract level.
Ref #866, #859, #1118.
Summary by CodeRabbit
/api/conversations/{id}/topologyendpoint to retrieve session topology with optional query limit parameter.