Repository navigation
fix(session): end a /compact quietly when its session was closed - #25912
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: one reversible early return that reuses the existing quiet [DESIGN-REVIEWED] a2b906a Description read[DESCRIPTION-READ] e7c79c7f13c9e7890470e11a6470d678a6a66b7ad9c7aeb5eeea99b51f06a1ce 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. This is a cause-level fix for issue #25859: it reuses the existing What this change shipsInventory (7 items) — 7 justifiedIntent: stop session closes during auto-compaction from showing up as failed compactions, so operators can find the real failures. FIX.
[FIRST-PRINCIPLES-REVIEWED] a2b906a Description read[DESCRIPTION-READ] a7c0ad59a13ff35bd96d1330be5f117b67c586b958bed8a8ff49254258e65a89 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.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: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
71d9815 to
ba34d0b
Compare
Closing a session while its in-place /compact runs pops the session and shuts its provider down, so the /compact stream dies with the process. The failure arm read that as a failed compaction: it logged a warning with a traceback, counted a failed compaction, and recycled, which shut the same process down a second time. Next to the user-Stop check, a failure whose key holds no session now returns "absent" with no warning, no count and no recycle. The close owns the shutdown. A key that holds a different session still recycles, because that replacement did not reap the held one. A real failure on a live session still warns, counts and recycles. Fixes #25859
ba34d0b to
a2b906a
Compare
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (3 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: a /compact whose session was closed mid-run now returns quietly instead of reporting a failure and recycling the process twice. Spec files changed as a ride-along (a minority of the diff on both file count and changed lines), not reviewed as a design decision: docs/system-specs/modules/session.md.
Problem / Motivation
Goal: Closing a session while its auto-compaction runs no longer reads as a failed compaction.
When a kiro-cli session is closed while its in-place
/compactruns,SessionLifecycleService.removepops the session and shuts its provider down. The/compactstream dies with the process, and the failure arm of_compact_in_placetreats that as a compaction failure. It logsin-place /compact failed ... recyclingat WARNING with anAcpProcessDiedtraceback, counts a failed compaction inCONTEXT_COMPACTIONS, then recycles the held session, which shuts the same process down a second time.Why it matters
The warning and the counter are how an operator finds real compaction failures, and closes drown them out: on the reporter host, 10 of 11 such warnings over 10 days were session closes. The second shutdown is wasted work on a process that is already gone.
Not a goal
/compactfailure on a live session does: it still warns, counts and recycles.remove,resetor any other teardown shuts a session down.What changed (motivation → approach → change)
A close looks like a failure → ask whether the key still holds any session → in
src/kiro_crew/session_compaction.py, right after the user-Stop check in the failure arm of_compact_in_place, a key that holds no session returns"absent"."absent"is the outcomecompact_if_neededalready returns for a key with no session, and its callers treat it as quiet. The close that empties the key (remove) shuts the session provider down itself, so this arm owns no process. A key that holds a different session keeps the recycle: that replacement did not reap the held session, andtest_recycle_pop_by_identity_spares_replacementpins that it is still shut down.docs/system-specs/modules/session.mdgets one paragraph on the case, in § Compaction Race Handling.The failure arm here is also moved by the open #24384 (into
_restart_after_failure) and #11377 adds a rotation path in the same handler; neither covers this case, and whichever lands second rebases this check across.Backwards compatibility
Compatible: only a compaction whose key holds no session changes, and its outcome goes from
"recycled"to the existing"absent".Removes nothing: the change adds one early return and keeps every other branch as it was.
Tests
test/test_compaction_session_closed.py, with fake providers whose/compactstream dies when the provider shuts down:test_a_session_closed_during_compact_ends_quietlycloses the session mid-/compactthroughremove. It expects"absent", one shutdown, noCONTEXT_COMPACTIONScount, no compact callback, no failure warning, and no successor under the key.test_a_real_compact_failure_still_warns_counts_and_recyclesfails/compacton a live session. It expects"recycled", the warning, one failed count, a notice, and a successor.Proof: PROVEN test/test_compaction_session_closed.py::test_a_session_closed_during_compact_ends_quietly (head 3a13b4925873)
Both pass 10 of 10 repeats, in reversed order, and under xdist (
pytest-randomlyis not installed here, so no seeded shuffle). The related compaction suites pass: 48 files, 2,115 tests, includingtest/test_session_compaction.py. black, isort, flake8, mypy, the line cap, the flake ratchet, the harness-parity gate and docs lint pass.Manual verification
N/A — unit coverage sufficient: the race is driven deterministically through the real
removeand_compact_in_place, which a manual close cannot time reliably.Related Issues
Fixes #25859
Sibling sweep
Swept: git grep -nE "_restart_held(key, session, pct)" -- src/kiro_crew/session_compaction.py
Sibling: src/kiro_crew/session_compaction.py:1102 -- not affected --
_recycle_unmanagednever sends /compact, so no dying stream reaches a failure arm; on main this arm is the only caller of_restart_heldPattern harvest
Not generalizable: the check needs the registry identity this one handler holds, and the other compaction arms either run no
/compactor already compare identity before acting.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)