Skip to content

refactor(proof): extract _build_subjects helper to compress discovery boilerplate - #1078

Merged
Sinity merged 1 commit into
masterfrom
worktree-agent-ad1ac00b
May 16, 2026
Merged

Sinity merged 1 commit into
masterfrom
worktree-agent-ad1ac00b

Conversation

@Sinity

@Sinity Sinity commented May 16, 2026

Copy link
Copy Markdown
Owner

Summary

Extracts _build_subjects(kind, items, mapper) private helper in polylogue/proof/subjects.py, collapsing 5 discovery functions from ~15 lines each to 4–5 lines each.

Problem

Five functions followed the identical iterate→map→sort pattern; the structural boilerplate buried the actual mapping logic.

Solution

Single 18-line helper. Five functions refactored, three left alone (distinct kind-per-item, pre-filtering, or hardcoded tuples). Net: 71 ins / 60 del. Zero behavior change — all 73 proof tests pass.

Verification

pytest tests/unit/proof/ -v  # 73 passed
devtools verify --quick  # exit 0

… boilerplate

The five subject-discovery functions that iterate a source, map each item
to SubjectRef(kind, id, attrs, source_span), and return tuple(sorted(...))
now delegate to a private _build_subjects(kind, items, mapper) helper.

Functions refactored:
  provider_capability_subjects  — plain lambda mapper
  operation_spec_subjects       — plain lambda mapper
  insight_surface_subjects      — plain lambda mapper
  maintenance_target_subjects   — plain lambda mapper
  artifact_path_subjects        — nested _map_path function (complex attrs)

Functions left unchanged (vary kind per item, hardcoded tuples, or
pre-filtering logic that does not fit the pattern):
  architecture_control_subjects, command_subjects, json_command_subjects,
  query_law_subjects, schema_roundtrip_subjects, error_surface_subjects,
  trace_operation_subjects, observable_diagnostic_subjects,
  workflow_claim_subjects, schema_annotation_subjects

No behavior change. All 82 proof tests pass (1 pre-existing failure
unrelated to this change).

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented May 16, 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 59 minutes and 57 seconds 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: 6a4cf4bb-2520-42c5-b981-ec17905d138b

📥 Commits

Reviewing files that changed from the base of the PR and between 0631b1a and ff70cd7.

📒 Files selected for processing (1)
  • polylogue/proof/subjects.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch worktree-agent-ad1ac00b

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 f8508de into master May 16, 2026
4 checks passed
@Sinity
Sinity deleted the worktree-agent-ad1ac00b branch May 16, 2026 09:34
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]>
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