Repository navigation
fix(session): idle sweep keeps a parent whose sub-agents are still running - #11734
Conversation
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
First Principles Review (Fable 5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The bounded probe-failure WARNING is a second fix riding under the title's fix — confirm linked issue #11709 covers that stall-visibility half too. Not justified as shipped
What this change shipsInventory (6 items) — 5 justifiedIntent: keep an idle parent's shared runtime alive while its background sub-agents still run — a FIX (defect readable on base:
The deleted pins ("The idle path is spelled separately … that axis is not what this change touches"; "keeps its long-standing key-only reset") recorded a scoping choice whose premise — no await before the idle reset — this fix itself removes; the description declares the reversal. The RSS recycle fires its callback only after a pinned reset succeeds ( [FIRST-PRINCIPLES-REVIEWED] 4795670 |
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify the trade that a persistently failing probe now holds ALL reaps — idle included, the former last-resort reaper — with only an hourly WARNING. [DESIGN-REVIEWED] 4795670 |
Opus 5 Review (fork) — ✅ no blocking findingsReviewed Review detailsThe new mid-sweep incarnation check reports a session that a concurrent sweep already reaped as "left running". FINDING — src/kiro_crew/session_cleanup.py:1136 — [OPUS-REVIEWED] 4795670 |
cixuuz
left a comment
There was a problem hiding this comment.
Small, correct fix mirroring an existing, already-tested pattern: the RSS reap path already calls await self._has_attached_subagents(key) before resetting a session (verified at line 394 of the current file), and the idle sweep's orphan branch -- which ignores the clock entirely -- was the one reset path that never consulted it. Tests cover both branches, the coroutine-vs-bool probe answer, fail-closed on a raising probe, and confirm the guard doesn't leak (a childless idle session still expires).
1228f06 to
c3387fc
Compare
|
Rebased onto current main: |
c3387fc to
77f6d34
Compare
|
Disposition for the GPT 5.6 finding on Hoisting the sub-agent probe onto the idle axis put an await where main's idle path had none, and that path reset by key alone, so a session recreated under the same key during the probe would have been reset on its predecessor's verdict. The reset is now pinned to |
34b106b to
b501786
Compare
|
Disposition for the Opus 5 finding on The module map now reads that BOTH axes ask the sub-agent probe and refuse a session with attached sub-agent work, and that only the orphan axis then re-asserts against the live set as the last read before the reset. That matches the code ( The Opus 5 check on Other reds on |
|
@iamwhatever follow-up to my earlier reply: the PR is now on head
The |
b501786 to
2458e85
Compare
|
Disposition for the GPT 5.6 and Opus 5 findings on The finding is right. In I took the narrowing fix, not the new-unknown-verdict one. The wrapper docstring ( CI reds on |
|
@iamwhatever correction to my line-reference update above: the head is now
|
2458e85 to
a30e2f5
Compare
|
Disposition for the GPT 5.6 advisory finding on The finding is right about the coverage. The code already re-reads the counter on both axes after the probe ( New test: |
|
@iamwhatever line references for your 23 Sep review, current as of head
|
Probe attached work on both idle-sweep axes, re-judge the scanned incarnation after awaits, and expose fail-closed probe failures through a bounded warning. Update the session specification and regression coverage for the complete cleanup contract.
a30e2f5 to
4795670
Compare
Problem / Motivation
An idle parent can look finished while its sub-agents are still running. The parent’s own semaphore is free after its turn, so the cleanup sweep could expire the runtime and lose the children’s work. A broken sub-agent probe also kept sessions fail-closed but only logged at debug level, which could hide a system-wide cleanup stall.
Why it matters
Background sub-agents are expected to keep working after the parent turn ends. Closing the tab or waiting past
timeout_secsmust not reset that shared runtime. Operators also need a bounded signal when the safety probe cannot answer and idle, orphan, and RSS cleanup start retaining candidates.What changed (motivation → approach → change)
src/kiro_crew/session_cleanup.pyasks the existing attached-sub-agent probe on both idle-sweep axes before any expiry side effect. After the await, it synchronously rechecks the injection counter, scanned incarnation, semaphore, and the branch-specific liveness condition. The final reset stays pinned to the scanned session. If a live slot reopens and installs a replacement during the probe, its freshly published ownership record survives the stale orphan verdict; a key that remains absent still drops the departed incarnation’s record.Probe failures still fail closed.
CleanupState.probe_failure_warned_atnow limits the visible warning to one line per hour across all keys, while each traceback remains available at debug level.docs/system-specs/modules/session.mdnow describes both axes, the four post-await checks, the live-slot ownership exception, and this bounded visibility contract.🟩 added · 🟨 changed · 🟥 removed · 🟦 unchanged
Backwards compatibility
Compatible: no accepted input or public API changes. Childless idle sessions still expire, closed slots still release stale claims, and probe failures keep the existing fail-closed behavior.
Tests
test/test_session_idle_attached_subagents.pycovers attached children on idle and orphan axes, synchronous and async probes, probe exceptions, replacement incarnations, turns that begin or complete during the await, reopened-slot ownership followed by later orphan expiry, a permit taken inside the probe with a stale clock, normal childless expiry, one warning across keys and sweeps, hourly warning repetition, and quiet successful probes.test/test_consolidate_cmd.pyandtest/test_session_coverage.pykeep the pinned-reset call contract current. The post-rebase cleanup set passes with 95 tests and 17 platform skips. Full mypy passes 1,706 source files, and all formatting, history, brand, SDK, async, changelog, docs, diff, and single-commit gates pass. Two warning regressions fail at pytest call phase on old headd74a8be42; the quiet-probe control passes there. The reopened-slot regression fails at pytest call phase on reviewed head5652a6a2d. On head2458e85d9(rebased ontoorigin/mainc66f95b1c; since the patch-identical34b106b70it adds two wording fixes and no code change: thesrc/kiro_crew/session.pymodule map now says the sub-agent probe is asked on both idle-sweep axes and only the live-set re-assert is orphan-only, and the probe-failure contract insession_cleanup.pyandsession.mdnow names only a probe that raises, since an unreadable task store is absorbed astaskq_bridge.UNKNOWN_PENDINGone layer down and never reaches the warning):test_a_held_permit_alone_stops_the_idle_expirypins the idle-axis permit re-read directly (disabling that read fails it and its orphan twin); 251 passed across the session cleanup, idle, RSS, coverage, consolidate and injection test files; the black gate, isort, flake8, mypy (session.py,session_cleanup.py) and docs lint pass. On heada30e2f505(same base; adds one test and no code change):test_an_injection_that_begins_inside_the_probe_stops_the_idle_expirypins the injection-counter re-read on the idle axis, where an injection that commits during the probe leaves the permit free andlast_usedstale; narrowing that re-read to the orphan axis fails this test and no other in the idle and reap test files. 183 passed across the idle, reap, coverage and consolidate test files; the black gate, isort, flake8, comment-history, SDK-boundary and sync-IO gates pass. On head4795670da(patch-identical toa30e2f505pergit range-diff, rebased ontoorigin/main3f16157bato pick up the Backend Lint black-step fix from #13698): 225 passed across the idle, busy-guard, cleanup, RSS, coverage and consolidate test files; the black gate, isort, flake8, mypy (session.py,session_cleanup.py), docs lint, comment-history, SDK-boundary and sync-IO gates pass.Manual verification
N/A — unit coverage drives the real
SessionManager._expire_idlecleanup wiring and directly exercises every changed branch.Screenshots / video
N/A — no user-visible UI changes.
Related Issues
Closes #11709
Pattern harvest
Rule candidate: review-prompt
Pattern: a reset path that checks the parent semaphore must also check attached child work and re-judge liveness after an awaited probe.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)