Skip to content

feat(storage): add depth-annotated delegation ancestry/subtree queries - #3542

Merged
Sinity merged 1 commit into
masterfrom
feature/insights/delegation-tree-query
Aug 2, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/insights/delegation-tree-query

Conversation

@Sinity

@Sinity Sinity commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Summary

Adds one-call, depth-annotated delegation ancestry (root-to-node) and subtree (node-to-descendants) queries over delegation_facts, exposed through the existing get/read MCP surface via new delegation:ancestry:<id>/delegation:subtree:<id> ObjectRef prefixes.

Problem

Delegation in this archive is a tree (subagents dispatch their own subagents), and delegation_facts already models arbitrary depth implicitly (each row is one parent→child edge). What's missing is a query surface returning a whole ancestry chain or subtree in one call, depth-annotated, without N+1 queries or client-side reassembly.

Solution

  • Design decision (argued from evidence, not assumed): work_evidence_nodes/edges (index v46+) supports arbitrary-depth traversal by construction but is measured "structurally hollow" (constant authority/confidence, 100% NULL time/actor, zero rows sourced from Claude Code delegation — only Workflow orchestration runs populate it). A pure on-demand adapter already exists (polylogue/insights/delegation_work_evidence.py, polylogue-1vpm.6.1) projecting delegation_facts into that vocabulary, with no production caller — establishing that delegation_facts is the richer typed source of truth and the generic graph is a consumer-side adapter, not a persistence target. Built natively over delegation_facts (via the delegations view) rather than growing a second persisted graph.
  • ArchiveStore.get_delegation_ancestry(session_id) / get_delegation_subtree(session_id) (storage/sqlite/archive_tiers/archive.py) — WITH RECURSIVE CTEs over delegations, depth-annotated, no N+1.
  • Cycle/orphan handling reuses the existing mapping_state != 'quarantined' exclusion (no second vocabulary invented); a defensive visited-path guard is kept and proven necessary by a constructed two-node-cycle test (from genuinely resolved, non-quarantined edges the topology quarantine pass never inspects).
  • New delegation:ancestry:/delegation:subtree: ObjectRef prefixes (core/refs.py) route through the existing get/read MCP tools via resolve_ref (api/archive.py) — no new MCP tool/dispatcher entry needed.
  • docs/plans/classifier-fingerprints.json/lifecycle.py/archive_tiers/index.py: also declares INDEX_SCHEMA_VERSION v54 (SEMANTIC_REPARSE) for PR feat(sources): add per-file acquisition logging and tighten claude-ai detection #3537's looks_like_ai tightening, which the classifier-fingerprint gate (PR feat(devtools): gate parser/classifier decision-boundary drift #3532, merged after this branch was cut) correctly flagged as undeclared drift blocking push.

Non-goals

Rewriting delegation_facts' identity-matching mechanism (owned by polylogue-1vpm.7, already fixed). Building the HTML/report rendering (this surface's shape is designed to feed the html-report skill's delegation-tree pattern directly, without restitching, but the renderer itself is out of scope). Live corpus depth/fan-out re-measurement (deferred pending the coordinator's separately-managed reindex).

Verification

devtools test tests/unit/storage/test_delegations_view.py tests/unit/api/test_facade_contracts.py tests/unit/core/test_refs.py tests/unit/insights/test_delegation_work_evidence.py — 390 passed, 1 pre-existing failure (test_archive_tiers_api_raw_artifacts_read_source_tier, stale hardcoded timestamp) confirmed identical on unmodified master. devtools verify --quick exit 0 (ruff format/check, mypy --strict, render-all-check, classifier-fingerprints, schema-versioning).

Ref polylogue-qsb4

Co-Authored-By: Claude [email protected]

@coderabbitai

coderabbitai Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 29 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 40a3aa3d-60df-43d6-bdd8-8eb4bcfbbc81

📥 Commits

Reviewing files that changed from the base of the PR and between 2a02f46 and 5fc74c3.

📒 Files selected for processing (6)
  • polylogue/api/archive.py
  • polylogue/core/refs.py
  • polylogue/storage/sqlite/archive_tiers/archive.py
  • polylogue/surfaces/payloads.py
  • tests/unit/api/test_facade_contracts.py
  • tests/unit/storage/test_delegations_view.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.

Problem: delegation_facts already models arbitrary-depth dispatch trees
implicitly (a child that itself dispatches subagents gets its own rows
keyed by its own session_id as parent), but no query surface returned a
whole ancestry chain or subtree in one call -- callers had to stitch
per-session delegation lookups together client-side (N+1).

What changed:
- ArchiveStore.get_delegation_ancestry/get_delegation_subtree
  (storage/sqlite/archive_tiers/archive.py): one recursive CTE each over
  the `delegations` view, depth-annotated, no N+1. Quarantined
  (cycle-break) edges are excluded from traversal by construction, reusing
  session_links' TopologyEdgeStatus vocabulary rather than inventing a
  second one. A defensive visited-path guard is still carried on every
  recursive step: quarantine is asserted by the topology resolver over
  session_links alone, while `delegations` also admits edges resolved by
  an independent content-identity mechanism the resolver never inspects,
  so two such edges could in principle compose into a cycle quarantine
  never saw. A test constructs exactly that two-node cycle from genuinely
  `resolved` (non-quarantined) edges and confirms the guard terminates.
- core/refs.py: delegation_ancestry_object_id/delegation_subtree_object_id
  (and parsers), reusing the existing "delegation" ObjectRef kind via new
  `ancestry:`/`subtree:` object-id prefixes rather than adding new kinds.
- surfaces/payloads.py: DelegationAncestryPayload/DelegationSubtreePayload
  and their node payloads.
- api/archive.py: resolve_ref dispatches the two new prefixes to
  _resolve_delegation_ancestry_object_ref/_resolve_delegation_subtree_object_ref,
  so the existing `get`/`read` MCP tools expose the traversal immediately
  (`get(ref="delegation:ancestry:<session_id>")` /
  `delegation:subtree:<session_id>`) with no new MCP tool or dispatcher
  wiring needed.

Design decision (open question this bead had to resolve): delegation
stays a native recursive-CTE surface over delegation_facts, not a
projection into work_evidence_nodes/edges. work_evidence_nodes/edges is
measured "structurally hollow" (constant authority/confidence, 100% NULL
time/actor/execution-context) and populated only from Workflow runs
today, 0 rows from Claude Code subagent dispatch. A pure adapter already
exists (insights/delegation_work_evidence.py, from polylogue-1vpm.6.1)
that projects delegation rows into the generic work-evidence vocabulary
on demand for callers who need it -- but it has no production caller
either, and delegation_facts remains the richer, typed source of truth
(honest per-dispatch cost/token/model columns the generic graph
intentionally does not carry). Adding a second, persisted graph
projection now would require new triggers to keep it in sync, still
leave the hollow columns unfilled for delegation-sourced edges, and
create a second source of truth before the receiving graph is proven
out. The native recursive-CTE surface is lower risk and immediately
correct.

Verification:
- devtools test tests/unit/storage/test_delegations_view.py
  tests/unit/api/test_facade_contracts.py tests/unit/core/test_refs.py
  tests/unit/insights/test_delegation_work_evidence.py: 390 passed, 1
  pre-existing failure unrelated to this change (confirmed via git stash
  against unmodified master: test_archive_tiers_api_raw_artifacts_read_source_tier
  fails identically with a stale hardcoded timestamp assertion).
- devtools verify --quick: ruff format/check, mypy --strict, render
  all --check all green. `lab policy classifier-fingerprints` fails
  identically on unmodified master (confirmed via git stash) --
  pre-existing drift in polylogue/sources/parsers/claude/ai_parser.py,
  not touched by this change.

Ref polylogue-qsb4

Co-Authored-By: Claude <[email protected]>
@Sinity
Sinity force-pushed the feature/insights/delegation-tree-query branch from ec95a78 to 5fc74c3 Compare August 2, 2026 11:32
@Sinity
Sinity merged commit 51bbe3c into master Aug 2, 2026
3 checks passed
@Sinity
Sinity deleted the feature/insights/delegation-tree-query branch August 2, 2026 11:39
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