Repository navigation
fix(slack): clear working indicators on CancelledError mid-stream - #20353
Conversation
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: |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns: one shared cancel exit with an idempotent, ownership-aware clear fixes the root cause, not each exit one by one. Notes
[DESIGN-REVIEWED] f2df761 Description read[DESCRIPTION-READ] ac170d5db6e20f6a419a718485bf3202ecab8688085f9d363c78bff3538a2b51 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 |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix sits on the one exit all three phases share, and the leftover early-exit clears ( What this change shipsInventory (5 items) — 5 justifiedIntent: stop a cancelled Slack turn (
[FIRST-PRINCIPLES-REVIEWED] f2df761 Description read[DESCRIPTION-READ] 8d8982876ee9d2d9e52a408a0f3d4cd9d54e437f1ff60790a97fc7e3cb1a5392 That sha256 names the PR description this verdict read. Recompute it with |
a19a409 to
f6bf3d9
Compare
GPT 6.1 Review — ✅ no blocking findings (all downgraded on adjudication)GPT 6.1 flagged blocking issues on This comment is updated in place on each push. Review detailsBLOCKING -- src/kiro_crew/slack/handler.py:1032 -- Detached cleanup clears a successor turn’s status
Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1 is LOW harm. The failure needs four things at once: a False positive or not applicable? A repository writer can comment: |
mbriones98
left a comment
There was a problem hiding this comment.
Checks green and readiness passed at f6bf3d9; no behavior change.
|
HOLD at f6bf3d9. The new
What clears this: one disposition per item on the PR. Minor: the Tests section names — crew-pr-reviewer (r101) |
f6bf3d9 to
dfadbdd
Compare
|
Rebuilt on latest main at dfadbdd. The first version patched Dispositions for the HOLD at f6bf3d9:
Minor: the Tests section now names Sibling found in the sweep: the transport |
dfadbdd to
e5e69e0
Compare
|
GPT 6.1 findings at dfadbdd, addressed at e5e69e0:
|
|
HOLD at e5e69e0. The fix is in the right place now. These current-head review items have no reply yet:
To clear: one reply per item. I read the code and tests but did not run them. — crew-pr-reviewer (r124) |
74c30b7 to
415ac04
Compare
iamwhatever
left a comment
There was a problem hiding this comment.
REQUEST_CHANGES at 415ac04, for follow-up tracking only.
The fix is sound. One except asyncio.CancelledError arm in handle_message covers every phase, the turn owns the clear and the flag, and the replay hand-off at turn.py#L536 answers both items from my r124 HOLD. The new tests cover each cancel phase, and CI is green.
Two items in your latest dispositions are deferred with no linked issue:
- The four inline status/Stop-block clears in
_run_turn's early exits (turn.py#L798-L866), which First Principles flags as a second spelling ofclear_working_indicators. - A review turn whose draft post fails leaves the thread status set, because that exit returns before release_working_indicators without clearing.
Please either fix them here or open one issue per item and link both in the PR description. The GPT successor-status race reply is acceptable as a cosmetic trade-off.
— crew-pr-reviewer (r127)
|
@iamwhatever re r127 at 415ac04: both deferred items now have their own issue, and the description links them under "Not a goal":
The GPT successor-status race stays accepted as a cosmetic trade-off, as you noted. The code is unchanged and the head is still 415ac04. |
A cancel (!stop, warm-pool reclaim, shutdown) passes every `except Exception` arm, so the hand-listed clears in the turn and delivery phases never run and the "...is working" status and inline Stop block stay in the thread. handle_message now catches CancelledError around all three phases, schedules turn.clear_working_indicators() as a tracked task and re-raises. The turn publishes _working_ts as soon as it posts the Stop block, and delivery marks the indicators cleared so a later cancel does not remove a review-mode status it kept. Fixes #11448 Co-authored-by: Zezhen Xu <zezhexu@amazon.com>
415ac04 to
b2b65d7
Compare
|
Rebased on current main (resolved a conflict with the new GPT F1 (upheld): fixed. The compaction replay now awaits GPT F2 (downgraded by adjudication): not changed. It is a cosmetic race on a successor's status, and the fix would need a new per-thread ordering contract. The pre-stream early exits in |
…he turn helper _deliver_answer cleared the thread status and deleted the Stop block inline and set _indicators_cleared by hand, a second spelling of _SlackTurn.clear_working_indicators. Delivery now calls the helper (keep_status for a review turn) and release_working_indicators() once a review draft lands, so the turn owns both the clear and the flag. A compaction replay now clears the abandoned attempt's indicators through the helper before the nested handle_message runs. A cancel that lands before the nested turn owns a status leaves no stale status, and a cancel that unwinds the parent after the replay does not clear the replay's. Refs #11448 The working-indicator tests move to test/test_slack_handler_working_indicators.py so test/test_slack_handler_turn_outcomes.py stays under the 2,000-line cap.
b2b65d7 to
f2df761
Compare
iamwhatever
left a comment
There was a problem hiding this comment.
Approve at f2df761.
A cancel in any phase now clears the "…is working" status and the Stop block. One except asyncio.CancelledError arm wraps all three phases (handler.py#L1022-L1033). Delivery and the compaction replay clear through the same idempotent helper (turn.py#L282-L302). The tests cover a cancel in each phase, review mode and both replay orders. The two deferrals from our r127 review are tracked in #24947 and #24948, and the renderer sibling is #23619. All checks are green.
AI findings judged non-blocking:
- GPT 6.1 (downgraded) and the Design note: the detached clear can erase a queued successor's status (handler.py#L1032). The flicker is cosmetic: the successor still delivers and sets its status again on its next tool call. Fixing it would need a per-thread ordering contract.
I read the diff and CI. I did not run tests.
— crew-pr-reviewer (r134)
Problem / Motivation
Goal: Clear the native "…is working" Slack thread-status label and the inline Stop block on every turn exit, including when the turn coroutine is cancelled mid-stream.
A Slack turn can be cancelled at any await: a
!stop, a warm-pool reclaim, or a gateway shutdown.asyncio.CancelledErroris aBaseException, so it passes everyexcept Exceptionarm. The clears for both indicators sit at hand-listed exits in the turn and delivery phases, so a cancel skips them. The "…is working" label and the Stop button then stay in the thread for good.Why it matters
Users see a stuck "…is working" label and a dead Stop button after a stop, a gateway restart or a session reclaim.
Not a goal
SlackRenderer.close()) has the same gap. It is tracked in Slack transport renderer leaves "…is working" status after a cancelled turn #23619._run_turnearly-exit clears throughclear_working_indicatorsis tracked in Slack _run_turn early exits clear the working indicators by hand instead of clear_working_indicators #24947, and a review turn whose draft post fails leaving "Awaiting review…" set is tracked in Slack review turn leaves "Awaiting review…" status when the draft post fails #24948.What changed (motivation → approach → change)
The clear now lives at the one exit every phase shares.
handle_messagewraps its three phases inexcept asyncio.CancelledError:. That arm startsturn.clear_working_indicators()as a tracked task and re-raises at once. The turn records the Stop block ts as soon as it posts it, so the arm can find it from any phase. Delivery marks the indicators cleared once it takes them down, so a later cancel does not remove a review-mode status delivery chose to keep.This replaces the first version of this PR, which patched
handle_messagebefore it was split intohandler_runtime/phases (#21040). It also answers both review findings: a cancel in the delivery region is now covered, and the shutdown case is best-effort.Backwards compatibility
Compatible: only a cancelled turn behaves differently, and it now clears what it posted.
Removes nothing: no API, function, key or data path is removed or renamed.
Tests
TestWorkingIndicatorCleanupintest/test_slack_handler_working_indicators.py:test_a_replay_cancelled_before_its_status_clears_the_first_attempts).test/test_handler_turn.pylists the new turn coroutine for the sync-I/O plant guard.Proof: PROVEN test_cancelled_turn_clears_thread_status test_cancelled_turn_deletes_working_block test_cancel_in_delivery_clears_both_indicators (head e5e69e0)
Manual verification
N/A — unit coverage sufficient: the tests drive
handle_messagewith a cancel at each phase against the mock Slack client.Related Issues
Fixes #11448
Sibling sweep
Swept: git grep -nE "set_thread_status(.*(_STATUS_WORKING|is_typing)|build_working_blocks(" -- src/
Sibling: src/kiro_crew/slack/handler_runtime/turn.py -- changed here
Sibling: src/kiro_crew/slack/handler_runtime/stream.py -- not affected -- refreshes the status inside the same turn, cleared by the new arm
Sibling: src/kiro_crew/slack/renderer.py -- tracked in #23619
Pattern harvest
Rule candidate: review-prompt
Pattern: a working indicator cleared only at listed exits, with no clear on the shared CancelledError exit
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)