Repository navigation
feat(storage): add depth-annotated delegation ancestry/subtree queries - #3542
Conversation
|
Warning Review limit reached
Next review available in: 29 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
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 |
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]>
ec95a78 to
5fc74c3
Compare
Summary
Adds one-call, depth-annotated delegation ancestry (root-to-node) and subtree (node-to-descendants) queries over
delegation_facts, exposed through the existingget/readMCP surface via newdelegation:ancestry:<id>/delegation:subtree:<id>ObjectRef prefixes.Problem
Delegation in this archive is a tree (subagents dispatch their own subagents), and
delegation_factsalready 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
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) projectingdelegation_factsinto that vocabulary, with no production caller — establishing thatdelegation_factsis the richer typed source of truth and the generic graph is a consumer-side adapter, not a persistence target. Built natively overdelegation_facts(via thedelegationsview) 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 RECURSIVECTEs overdelegations, depth-annotated, no N+1.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 genuinelyresolved, non-quarantined edges the topology quarantine pass never inspects).delegation:ancestry:/delegation:subtree:ObjectRef prefixes (core/refs.py) route through the existingget/readMCP tools viaresolve_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'slooks_like_aitightening, 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 --quickexit 0 (ruff format/check, mypy --strict, render-all-check, classifier-fingerprints, schema-versioning).Ref polylogue-qsb4
Co-Authored-By: Claude [email protected]