Skip to content

fix(session): end a /compact quietly when its session was closed - #25912

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/compact-quiet-on-session-close
Oct 30, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/compact-quiet-on-session-close

Conversation

@RohanK6

@RohanK6 RohanK6 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

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 /compact runs, SessionLifecycleService.remove pops the session and shuts its provider down. The /compact stream dies with the process, and the failure arm of _compact_in_place treats that as a compaction failure. It logs in-place /compact failed ... recycling at WARNING with an AcpProcessDied traceback, counts a failed compaction in CONTEXT_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

  • No change to what a real /compact failure on a live session does: it still warns, counts and recycles.
  • No change to the user-Stop arm next to it.
  • No change to how remove, reset or 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".

Failure arm case Warning Counted Recycle
user Stop yes yes, cancelled no
session closed (key empty) no (debug line) no no
key holds a different session yes yes, failed yes, reaps the held one
real failure on a live session yes yes, failed yes

"absent" is the outcome compact_if_needed already 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, and test_recycle_pop_by_identity_spares_replacement pins that it is still shut down. docs/system-specs/modules/session.md gets 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 /compact stream dies when the provider shuts down:

  • test_a_session_closed_during_compact_ends_quietly closes the session mid-/compact through remove. It expects "absent", one shutdown, no CONTEXT_COMPACTIONS count, no compact callback, no failure warning, and no successor under the key.
  • test_a_real_compact_failure_still_warns_counts_and_recycles fails /compact on 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-randomly is not installed here, so no seeded shuffle). The related compaction suites pass: 48 files, 2,115 tests, including test/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 remove and _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_unmanaged never sends /compact, so no dying stream reaches a failure arm; on main this arm is the only caller of _restart_held

Pattern harvest

Not generalizable: the check needs the registry identity this one handler holds, and the other compaction arms either run no /compact or already compare identity before acting.

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

@RohanK6
RohanK6 requested review from a team and KiroCrewCaptain as code owners October 29, 2026 19:32
@RohanK6
RohanK6 requested a review from CrysisDeu October 29, 2026 19:32
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

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

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: one reversible early return that reuses the existing quiet "absent" outcome. Every path that empties the key (remove, reset, drain_all_providers) already takes on the provider's shutdown itself.

[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 .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

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of a2b906ac5e08a1f56c1d1eb468a6ddc0cf80d845 — 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 blocks. This is a cause-level fix for issue #25859: it reuses the existing "absent" outcome, and a real failure on a live session still takes the unchanged path.

What this change ships

Inventory (7 items) — 7 justified

Intent: stop session closes during auto-compaction from showing up as failed compactions, so operators can find the real failures. FIX.

  1. Closing a session while /compact runs no longer logs a WARNING with a traceback — justified
  2. Those closes are no longer counted as failed in CONTEXT_COMPACTIONS — justified
  3. The closed session's process is shut down once, not recycled a second time — justified
  4. The compaction outcome for that case becomes the existing "absent" instead of "recycled" — justified
  5. The user gets no "compaction failed" notice for a session they closed — justified
  6. A DEBUG line is logged for the close case — justified
  7. The session spec's Compaction Race Handling section gets one paragraph on the case, and two regression tests are added — justified

[FIRST-PRINCIPLES-REVIEWED] a2b906a

Description read

[DESCRIPTION-READ] a7c0ad59a13ff35bd96d1330be5f117b67c586b958bed8a8ff49254258e65a89

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

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] a2b906a

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

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

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] a2b906a

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

@RohanK6
RohanK6 force-pushed the fix/compact-quiet-on-session-close branch from 71d9815 to ba34d0b Compare October 29, 2026 20:18
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 29, 2026
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
@RohanK6
RohanK6 force-pushed the fix/compact-quiet-on-session-close branch from ba34d0b to a2b906a Compare October 29, 2026 22:03
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 29, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 30, 2026 00:06

@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: 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.

@KiroCrewCaptain
KiroCrewCaptain merged commit f533589 into main Oct 30, 2026
93 of 94 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/compact-quiet-on-session-close branch October 30, 2026 00:07
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 30, 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.

Closing a session during auto-compaction is logged and counted as a failed compaction

2 participants