Skip to content

fix(chat): answer /compact at once in a brand-new chat - #24761

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/compact-fresh-session-15722
Oct 27, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/compact-fresh-session-15722

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: /compact sent as the first message of a brand-new dashboard chat answers at once instead of holding the chat for 300 s and reporting a timeout.

In a new chat on the kiro-cli backend, /compact as the first message shows the compacting state with input disabled, then after 300 s shows "⚠ Compaction timed out." for a compaction that never started.

Why it matters

Anyone who tries /compact early in a new chat loses the chat for five minutes and gets a misleading timeout notice.

Not a goal

Intended?

No. #14700 lists this exact case under "Not a goal" as "a separate change", so it was left open on purpose, not chosen as the behavior. Nothing in docs/system-specs/modules/providers.md, code comments or tests says a fresh session should wait out the timeout. On main @ 561b345 the only early exit in the /compact arm is if _replay_pending: in _turn_compact_command (src/kiro_crew/dashboard/chat_turn/slash_commands.py:805). A fresh session with no replay owed falls to the else arm and awaits client.wait_for_compaction() for the full budget (slash_commands.py:820-829).

Repro

Read from code on main @ 561b345 (no local test runs on this host; the new test runs in CI):

  1. New dashboard chat, kiro-cli backend, first message /compact.
  2. turn_admission.py:1138-1139 arms first_turn_history_owed because the claim is FRESH (is_new and not resumed). provider_switch_replay_pending is False, so _replay_pending is False.
  3. kiro-cli answers the prompt with "Conversation too short to compact." and end_turn and sends no _kiro.dev/compaction/status (the reporter's direct ACP check in [bug] /compact as the first message of a brand-new dashboard chat waits 300 s and reports a timeout #15722).
  4. _turn_compact_command skips the _replay_pending arm, compacts_inline is False for kiro-cli, so it broadcasts role: compacting and waits compact_wait_budget_secs(). Result timeout -> "⚠ Compaction timed out." The reporter saw this twice (04:39:57 -> 04:45:13, 04:47:12 -> 04:52:25 UTC) with log line Deferred compaction: waiting for compaction result.

What changed (motivation → approach → change)

  • Symptom: a 300 s wait and a false timeout on /compact in a new chat.
  • Cause: the /compact arm only knows the replay-pending way a session can be empty. A FRESH session that no ordinary prompt has reached is empty too.
  • Signal: the gateway already tracks this. first_turn_history_owed is armed at admission from a FRESH claim and settled only when a non-slash turn keeps its history with the provider (_turn_settle_debts), so while it is armed the native session holds no conversation. It also covers a second /compact in a row, which a one-shot is_new check would miss.
  • Change: in _turn_compact_command, a new arm after the replay-pending one: on a backend that does not compact inline, when first_turn_history_owed_pending(session_key) is True, append COMPACT_FRESH_SESSION_NOTICE ("Nothing to compact yet: the agent's session starts with your next message."; worded about the agent's session, not the chat, because a session restarted under an existing chat is fresh too while the chat still shows its messages) and return. It sends no compacting frame, waits for nothing, does not re-arm skills context and does not settle the debt.
  • COMPACT_FRESH_SESSION_NOTICE sits beside COMPACT_REPLAY_PENDING_NOTICE in chat_turn/recovery.py. The providers spec gets one bullet for the new case.

Backwards compatibility

Compatible: only a /compact on a session whose first-turn history debt is still armed changes. It used to wait and time out, and now answers at once. Every other /compact path is unchanged.

Removes nothing: the diff adds one arm and one constant and takes away no path, record, key or function.

Tests

  • test/test_dashboard_chat_compaction.py::TestRunChatCompactDeferredWait::test_fresh_session_compact_returns_without_waiting: a FRESH kiro-cli session (is_new=True, resumed=False, debt armed, no replay) given /compact makes no wait_for_compaction call, sends no compacting frame, arms no reinjection, does not settle the debt, and appends exactly COMPACT_FRESH_SESSION_NOTICE with no timeout notice. On main this test fails: the turn awaits wait_for_compaction (the mock returns timeout) and appends "⚠ Compaction timed out."
  • Existing /compact tests use a MagicMock sessions double whose first_turn_history_owed_pending is not True, so they still take the wait arm unchanged.

Proof: not provable -- other: this host never runs tests locally; the new test runs in CI

Static gates run locally on the changed files: black, isort, flake8 clean; scripts/docs-lint.sh passes. mypy and the test suite run in CI.

Manual verification

N/A — unit coverage is enough. The change is one branch in the turn-end /compact handler, and the test drives _run_chat end to end through it.

Related Issues

Fixes #15722

Follow-up to #14700 (same shape for a replay-pending session).

Sibling sweep

Swept: git grep -n "wait_for_compaction(" -- src/
Sibling: src/kiro_crew/slack/handler_runtime/commands.py -- not affected -- refuses /compact unless a live session already exists, so a prior message has given it a conversation
Sibling: src/kiro_crew/telegram/dispatch/commands.py -- not affected -- compacts only an already-live session started by an earlier message
Sibling: src/kiro_crew/discord/transport_dispatch_commands.py -- not affected -- compacts only an already-live session started by an earlier message

Pattern harvest

Not generalizable: this is one missing "session is still empty" arm in the dashboard /compact handler, and the signal for it is local to this runner.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality (CI)
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

@CrysisDeu
CrysisDeu requested review from a team and KiroCrewCaptain as code owners October 27, 2026 06:17
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: the fix reuses the existing first_turn_history_owed signal, and the new early-return arm is easy to revert.

Notes

  • The debt is cleared only once a non-slash turn's history has been delivered. A first prompt that failed before that point leaves it set even though kiro-cli may already hold a partial conversation, so a later /compact would wrongly say "Nothing to compact yet". A user can recover by sending one more message.
  • The arm also short-circuits every other backend that does not compact inline, including KAS and codex-acp, which do report a status. On an empty session that loses nothing.

[DESIGN-REVIEWED] a7e9cfc

Description read

[DESCRIPTION-READ] 1ccf2ba6ab9982c87144a97d6a4604b3a3a8c567250dbb36aa561eb4e08710e1

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 27, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of a7e9cfc0a902e2fedb7ac1b2ad913ef140ee933a — 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. The fix reuses the existing first_turn_history_owed_pending signal, which already has two other consumers, turn_admission.py:1124 and context_cap.py:295. It also has a test that fails on base.

What this change ships

Inventory (4 items) — 4 justified

Intent: a user who sends /compact as the first message of a new dashboard chat gets an immediate answer instead of a 5-minute lockout and a false timeout. This is a FIX (#15722).

  1. In a brand-new chat, /compact now answers at once: no compacting state, input stays enabled, no timeout notice — justified
  2. New notice text: "Nothing to compact yet: the agent's session starts with your next message." — justified
  3. The same immediate answer applies when the agent's session was restarted under an existing chat, while the first-turn history debt is still armed — justified
  4. Providers spec gains one bullet for the fresh-session /compact case — justified

[FIRST-PRINCIPLES-REVIEWED] a7e9cfc

Description read

[DESCRIPTION-READ] 722a941383cd1c2e2cb06869faec3a6bb33384b83763978413c657497cd7e67c

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 27, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision a7e9cfc0a902e2fedb7ac1b2ad913ef140ee933a 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 readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] a7e9cfc

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

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

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] a7e9cfc

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

@CrysisDeu
CrysisDeu force-pushed the fix/compact-fresh-session-15722 branch from 2b1e587 to e6a455d Compare October 27, 2026 06:38
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 27, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/compact-fresh-session-15722 branch from e6a455d to 9dbd8ed Compare October 27, 2026 07:09
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 27, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

CI status on 9dbd8ed: Backend Tests (3.12, 2) and Backend Tests (Windows) (2) fail only on test/test_crew_log_fullscan_guard.py::test_a_warm_session_read_that_earns_a_savepoint_reads_only_the_gap (XPASS(strict)). That is main red, tracked in #24765, with the fix in #24774. This diff does not touch crew-log code. Coverage Gate fails closed because of those shards. I will rebase once #24774 lands.

Replies to the non-blocking notes:

  • Design and Opus notes (notice wording): agreed. A session restarted under an existing chat, or one whose first turn was cancelled, is still fresh, but the chat shows messages. The rebase push changes the notice to "Nothing to compact yet: the agent's session starts with your next message." That describes the agent's session, not the chat.
  • First Principles item 1 (a short chat that already has messages): out of scope here. Once a turn has kept its history the debt is settled, so this arm no longer fires and the wait arm runs as before. Handling kiro-cli's "too short" reply on a non-empty session means matching its text, which fix(chat): answer /compact at once while conversation replay is pending #14700 set aside as a separate change.

A /compact sent as the first message of a new dashboard chat reached a fresh kiro-cli session that holds no conversation. kiro-cli ends that turn with 'Conversation too short to compact.' and sends no compaction status, so the deferred wait ran the full compaction timeout and then reported a timeout.

The fresh session's first-turn history debt is armed at admission and settled only by a kept non-slash turn, so it already tells the gateway the native session is empty without matching kiro-cli text. On a backend that does not compact inline, answer such a /compact at once with a 'nothing to compact yet' notice and leave the debt and skills context for the next prompt.

Fixes #15722
@CrysisDeu
CrysisDeu force-pushed the fix/compact-fresh-session-15722 branch from 9dbd8ed to a7e9cfc Compare October 27, 2026 13:03
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 27, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Head a7e9cfc is rebased on main after #24774 and includes the notice wording change. All checks are done: 0 pending, 0 failing. The 8 cancelled runs are duplicates, cancelled when the push and the body edit both started runs at 13:03. Each one has a passing twin on this head.

Reply to the new non-blocking note, about a first prompt that failed before delivery: the user sees "Nothing to compact yet" once, and the next message settles the debt. Telling that case apart would mean reading kiro-cli's partial state. That is outside this fix, so I left it as is. On KAS and codex-acp the arm only fires while the session is empty, so nothing is lost there.

@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 27, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 27, 2026 15:08

@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 (4 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: answers /compact at once on a fresh provider session instead of waiting out the compaction timeout; with a test. 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/providers.md.

@KiroCrewCaptain
KiroCrewCaptain merged commit c879fc2 into main Oct 27, 2026
110 of 118 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/compact-fresh-session-15722 branch October 27, 2026 15:10
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 27, 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.

[bug] /compact as the first message of a brand-new dashboard chat waits 300 s and reports a timeout

2 participants