Repository navigation
fix: spare live-account holders from the identity sweep so it can finish - #14609
Conversation
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsFINDING -- src/kiro_crew/session_lifecycle.py:1575 -- an A→B→A sweep hits False positive or not applicable? A repository writer can comment: |
Design Review (Fable 5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS Livelock silently returns wherever a spawn-stamp read fails, and no field host has yet exercised the stamp gate this fix depends on. WatchThe spare only works for stamped holders; the docstring itself admits a stamp can be empty because "the spawn-time read failed, disagreed with its pre-spawn read, or the stamping is unwired." One busy unstamped live-account session then keeps every sweep incomplete — the per-turn resweep and [DESIGN-REVIEWED] 8d875b9 |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify on a stamp-gated build: the field host (0.7.1rc2) predates the stamp gate, so the spare's premise — holders carry Not justified as shipped
What this change shipsInventory (5 items) — 4 justifiedIntent: FIX — stop the identity sweep from killing live-account subagents and from re-running every turn on a busy gateway (#14605).
Evidence checked: the rewritten pin ("no attempt to spare … registration order does not carry it") is quoted by the description itself with the reason its premise fell (the spawn stamp now carries the identity). Stamp sites counted: [FIRST-PRINCIPLES-REVIEWED] 8d875b9 |
Opus 5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
6ba398e to
44100a5
Compare
The identity sweep retired every idle kiro-backed session and companion runtime, and reported itself complete only when none of them was busy. On a gateway with a dozen live chats that never happens, so the baseline never advanced, every turn from every chat re-swept, and each sweep recycled every idle session. A parent chat that ended its turn with spawn_run children still running is idle by the semaphore test, so its retirement cancelled the children: every subagent on the host died as "AcpProcessDied ... killed (provider shutdown)" a few minutes in, on every turn any chat took, with no account change having happened. The spawn-identity stamp already records which account each child authenticated under. The sweep now spares a session or runtime whose stamp EQUALS the live fingerprint (spawned_under): not retired, not flagged, not counted against completeness. Unstamped or differently stamped holders are retired as before, and an empty live fingerprint (unreadable store; the sign-out path) spares nothing, so the fail-safe retire-everything sweep is unchanged where the stamp cannot vouch. Fixes #14605
44100a5 to
8d875b9
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed the diff and ran test/test_external_logout_detection.py locally on head 8d875b9: 170 passed. The spare is exact-equality on a nonempty live fingerprint, empty live spares nothing, and the expected= pin on release_subagent_runtime closes the respawn race. LGTM.
Problem / Motivation
Goal: Long-running subagents stop dying as "provider shutdown" on a busy gateway, and the account-identity sweep finishes instead of re-running on every turn.
On a gateway with many live chat sessions and
spawn_runsubagents in flight, every subagent is killed a few minutes into its run:44 kills in ~5 h on one host, all with the same signature, none from OOM, timeout or a model error (194 GB free throughout). Children of one parent chat always die in the same second, when any chat sends a turn; the parent's resume pointer is cleared to
discarded_sidat the same moment; idle chats get a freshkiro-clipid roughly every two minutes. No account change happened.Why it matters
Every subagent-backed workflow on a busy host is unusable: PR babysits, research fan-outs and reviews die mid-run and the parent sees only an opaque
provider shutdowntraceback. Each idle chat is also recycled into a fresh native conversation on every turn anyone takes, for nothing. The trigger fires atINFO, so operators have no signal that the safety sweep is the cause.Not a goal
What changed (motivation → approach → change)
Symptom → root cause.
retire_kiro_identity_sessionsretired every idle kiro-backed session and companion runtime, and reportedcomplete=Trueonly when none of them was busy, nothing was mid-start and no kiro-backed runtime survived. The comment said so explicitly: "with no attempt to spare one that registered after the pending change … registration order does not carry [the identity]". On a gateway with a dozen live chats that precondition is never satisfied, so the baseline never advances (note_sessions_reconciledis only called on a complete sweep), the pending fingerprint stays set, and the turn gate re-sweeps on every turn from every chat. Each sweep recycles every idle session — and a parent chat that ended its turn withspawn_runchildren still running is idle by thesemaphore.locked()test, so its retirement runs_cancel_parent_children(... verb="retire_kiro_identity_sessions")and the children die asprovider shutdown.Approach. Registration order does not carry the identity a session authenticated under, but the spawn-identity stamp (
spawn_identity, recorded by every spawn site since the stamp gate landed) does. A holder whose stamp equals the live fingerprint has provably authenticated as the live account; retiring it buys nothing and costs its children, and counting it against completeness is exactly what kept the sweep from ever finishing.Change.
kiro_prerequisite.py:spawn_identity_of(holder)(the provider-or-runtime stamp lookup the flag gate already did inline) andspawned_under(holder, live)— nonempty stamp equal to a nonempty live fingerprint, whole. Deliberately stricter thanidentity_stamp_mismatch: a mismatch is proven component-wise because a read can only lose components; a spare must not be granted on a partial match. Emptylivespares nothing.session_lifecycle.py: the sweep's session loop skipsspawned_under(sess.provider, fingerprint)holders — not retired, not flagged, not counted as skipped. The two unfiltered runtime reapers takelive=and apply the same spare to the reap and to their completeness post-conditions (registered survivors, parked drainers). Filtered (mismatch-gate) mode is untouched. The flag gate reusesspawn_identity_of.session.py: the two facade methods forwardlive=.docs/system-specs/modules/session.md: new Live-account spare paragraph in the identity-sweep section.Backwards compatibility
Compatible: the sweep's signature is unchanged;
_retire_kiro_subagent_runtimes/_retire_kiro_bg_runtimegain a keyword-onlylive=""whose default is the previous behaviour. Unstamped holders, differently-stamped holders, and every sweep run with an empty fingerprint (the sign-out path inkas_login.pycallsretire()bare on purpose) behave exactly as before.Tests
test/test_external_logout_detection.py::TestRetirementCoverage, seven new cases:Existing sweep tests call
retire_kiro_identity_sessions()with no fingerprint and are unaffected.Manual verification
N/A — unit coverage sufficient: the change is a predicate on in-memory state the existing fakes model directly. The field symptom (44
provider shutdownkills, same-second sibling deaths,discarded_sidon the parent) is documented in #14605; the host that produced it runs 0.7.1rc2, which predates both #12956 and the stamp gate, so a live re-test of this head waits for the next insider build.Related Issues
Fixes #14605. Builds on #12956 (boot-seeded baseline) and the spawn-identity stamp gate.
Pattern harvest
Rule candidate: review-prompt
Pattern: a "retire until quiescent" sweep whose completeness requires every holder to be idle at once — on a busy host that is a livelock, and each pass must be checked for collateral on holders the pass cannot prove guilty.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)