Skip to content

refactor(subagent_manager): unchain the proven spawn depth ternary - #26482

Merged
bolichen97 merged 1 commit into
mainfrom
refactor/simplify-subagent_manager
Oct 31, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
refactor/simplify-subagent_manager

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Make the depth a spawning parent proves in subagent_manager/admission/gate.py read as three plain cases, and pin the two rules in it no test checked, without changing what depth any spawn records or which spawn the nesting cap refuses.

spawn_impl works out a child's lineage depth from its parent in one chained conditional expression: max(_parent_depths) + 1 if _parent_depths else (2 if _is_child else 1). That one line carries three cases: the deepest live parent record plus one, two for a subagent: parent key with no live record, and one for a root session. The result, raised to any depth carried in, is what the nesting cap compares against.

Two of its rules are not pinned. Replacing the no-record child's 2 with 1 or 3, or the max over parent records with min, leaves all 3817 tests in the 140 related test files green.

Why it matters

Nothing is broken today. The nested form hides the middle case, the one a reader most needs when a parent's record is gone, inside a parenthesised tail. And because two of its rules are unpinned, a later edit could change the depth a child records, and so where the nesting cap starts refusing, with no test going red.

Not a goal

  • Changing the nesting cap, the carried-depth rule, or which records count as the parent.
  • The other chained ternaries the detector reports in dashboard/, which are test-pinned or in keystone files.
  • Any other code in gate.py; ten open PRs touch the file elsewhere.

What changed (motivation → approach → change)

No spawn records a different depth and no spawn is refused differently. The one expression becomes an if/elif/else in the same branch order with the same values, and two new tests pin the two rules that were unchecked.

Where Change
subagent_manager/admission/gate.py, _proven_depth if _parent_depths: deepest record + 1, elif _is_child: 2, else: 1. The comment above it is unchanged; it describes the two subagent: parent cases, and a root session's 1 is the else.
test/test_subagent_spawn_depth_cap.py test_child_of_a_sub_agent_with_no_live_record_is_depth_two: a spawn from subagent:gone01 with no live record and no carried depth records depth 2. test_the_deepest_live_parent_record_sets_the_childs_depth, run in both registration orders: with the original run and a running continuation of it at depths 1 and 2, the child records depth 3.

Backwards compatibility

Compatible: every input gives the same _proven_depth as before, so stored depths, SEL rejected_depth_cap outcomes and refusal messages are unchanged.

Removes nothing: the diff only restructures one assignment and adds tests.

Tests

  • Two new tests (three cases), all in test/test_subagent_spawn_depth_cap.py, all passing on the parent commit as well.
  • Mutation check. Six mutants of the new block were run against the same 140 related test files (3817 tests) before the new tests existed. Three were killed: dropping the + 1, a root child at 2, and ignoring live parents. Three survived: the no-record child at 1, the same child at 3, and min for max. With the new tests, the depth-cap file alone kills all six, and two more: the last registered record winning, and the first one winning.
  • Determinism. test/test_subagent_spawn_depth_cap.py (14 tests): 20 serial repeats, 10 runs at -n 4 beside the other three test_subagent_spawn* files (73 tests), and two shuffled orders of its node ids (seeds 30103, 7741), all green. test_flake_pattern_ratchet.py: 64 passed.
  • Related tests (Python 3.12). gate.py is a hub file (the related-test runner selects 2440 test files), so the local run covers the 139 files named test_subagent*, test_admission* and test_spawn*, plus test_overload_integration_glue.py: 3820 passed in three of four runs across this branch's rebases, which leave both files unchanged. The fourth had one failure, test_subagent_reap_attribution.py::test_a_deadline_reap_names_the_deadline_not_the_death: its no-ERROR-log assertion caught asyncio's "Task was destroyed but it is pending!" for a pending pump drain task (_drain_queue_async_impl) that was garbage-collected during that test. The test passes 10 of 10 runs alone, on this branch and on main at 81dde23e17; a probe that forces a collection after every depth-cap test finds no leaked task from any of them; and dropped tasks being collected is open issue Dropped asyncio.create_task results can be garbage-collected mid-run #25953. CI runs the full suite.
  • Static gates (Python 3.12). flake8, isort, mypy, pinned black, subprocess-encoding, comment-history, brand, harness-parity, the line cap, the feature map, the memory-store seam, both docs lints, the per-file coverage self-test, the loop-lock, sync-IO, cwd-read and agent-SDK checks with their self-tests, the ACP-frame and testpaths checks, and the vendor manifest: all exit 0. scripts/scrub-lint.sh is absent from the tree. Semgrep is not installed here; CI's SAST job runs it. No frontend run: nothing under website/, .github/ or scripts/ changed.
  • Pre-PR review. Seven read-only reviewers, one lens each: repo rules (AUTOSDE), behaviour, imports and test hygiene, security and boot path, prose claims, and the Opus and GPT lane contracts (the GPT one on a Claude model, since the pinned GPT model is not available locally). No lens found a code defect. The behaviour lens compared the old and new forms over 14,762 inputs with no mismatch. The security lens ruled gate.py not keystone: the nesting cap is a resource limit, and the governance checks it calls live in other files. Two independent adjudicators upheld six of the prose lens's findings, all fixed in this description and the commit message, and one test gap: the parent-record test passed a mutant where the last registered record wins, so it runs in both orders. Both refuted one finding ("no live record" matches the file's existing wording), and they split on whether "two cases" overstated what was unpinned; it says two rules.

Manual verification

N/A: the code change restructures one assignment with identical results, and the unit tests above cover every case it has.

Screenshots / video

Why no screenshot: backend-only restructuring of one assignment plus new tests; no page, response or frame changes.

Related Issues

Part of #16523

Overlap: ten open PRs touch gate.py (#10098, #10171, #11324, #12821, #13109, #15543, #17684, #18165, #22252, #26463); none of their patches touches _proven_depth, _parent_depths or _is_child. No open PR touches test/test_subagent_spawn_depth_cap.py.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

The depth a spawning parent proves was one chained conditional
expression with three outcomes: the deepest live parent record plus
one, two for a sub-agent key with no live record, and one for a root
session. Spell it as an if/elif/else so each case reads on its own
line. Branch order and the values are unchanged.

Two rules in it were unpinned: replacing the no-record child's 2 with
1 or 3, or the max over parent records with min, left every test in
the 140 subagent, admission, spawn and overload-glue test files
green. Pin both in test_subagent_spawn_depth_cap.py, the max over
both registration orders; the pins pass on the parent commit too.
@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners October 31, 2026 00:10
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision a511a3115bdc48c54ec1cd8413217e588a2aaa78 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of a511a3115bdc48c54ec1cd8413217e588a2aaa78 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: this is a refactor that changes no behaviour, and its two new tests pin rules nothing tested before.

[DESIGN-REVIEWED] a511a31

Description read

[DESCRIPTION-READ] cc0a5b61d7023fb7ec999b8b5a01ebbfafdf0dcb04b81a6690be32af873fc401

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of a511a3115bdc48c54ec1cd8413217e588a2aaa78 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing to check.

What this change ships

Inventory (3 items) — 3 justified

Intent: make the spawn-depth rule easy to read and pin its two untested rules without changing any recorded depth. This is a refactor, neither a FIX nor an ADDITION.

  1. The proven-depth expression is rewritten as if/elif/else. Branches, order and values are unchanged, so no spawn records a different depth — justified
  2. A new test pins that a child of a subagent: parent with no live record records depth 2 — justified
  3. A new test, run in both registration orders, pins that the deepest live parent record decides the child's depth — justified

[FIRST-PRINCIPLES-REVIEWED] a511a31

Description read

[DESCRIPTION-READ] 4e00ee4229834a67aff3b057891da811a72224f9bbff136acef01d68e128bf9f

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed a511a3115bdc48c54ec1cd8413217e588a2aaa78 — this comment is updated in place on each push.

Review details

Pure refactor, semantics identical.

No findings.

[OPUS-REVIEWED] a511a31

Verdict parsed from the review's SHA-scoped output markers for commit a511a3115bdc48c54ec1cd8413217e588a2aaa78.

False positive or not applicable? A repository writer can comment:
/ai-review override fable a511a3115bdc48c54ec1cd8413217e588a2aaa78 false-positive: <reason, 20 to 500 characters>

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of a511a3115bdc48c54ec1cd8413217e588a2aaa78 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] a511a31

False positive or not applicable? A repository writer can comment:
/ai-review override gpt a511a3115bdc48c54ec1cd8413217e588a2aaa78 false-positive: <reason, 20 to 500 characters>

@bolichen97
bolichen97 enabled auto-merge (squash) October 31, 2026 00:39
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 31, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tier 1 auto-approve: refactor (2 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: replaces one nested conditional expression for the proven spawn depth with an equivalent if/elif/else and adds tests for both branches; no behaviour change.

@bolichen97
bolichen97 merged commit 03f78f1 into main Oct 31, 2026
95 checks passed
@bolichen97
bolichen97 deleted the refactor/simplify-subagent_manager branch October 31, 2026 01:22
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 31, 2026
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.

2 participants