Skip to content

fix(messaging): fail and reset a turn the backend never finished - #19026

Merged
iamwhatever merged 2 commits into
kirodotdev:mainfrom
javenciu:fix/messaging-timed-out-turn
Oct 11, 2026
Merged

iamwhatever merged 2 commits into
kirodotdev:mainfrom
javenciu:fix/messaging-timed-out-turn

Conversation

@javenciu

@javenciu javenciu commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On Telegram, Discord, Teams and the other messaging transports, a turn whose backend never finished is shown as cut off at its time limit and starts the next message on a fresh agent process, instead of being delivered as a finished reply on the same silent process.

When the backend goes silent, the session handle ends the turn with one of its two stop reasons for an unfinished turn: "timeout" at its own turn ceiling, or STOP_REASON_STALE_RECOVER for a stale turn its probe confirmed wedged.
messaging.driver.TurnDriver.run flushed whatever text had streamed and sent DONE with no notice: empty_turn_notice speaks only for a turn that produced no text. The partial text read as the reply.
messaging.dispatch then booked the turn with _record_success and Verdict.ANSWERED and kept the session. Telegram runs its own dispatcher, telegram/transport_dispatch.py, on the same driver, and booked record_success the same way. The silent runtime still reads alive, so the next message in the conversation was sent to it and hung again.

Why it matters

A user on a messaging channel whose backend hangs gets half an answer that looks finished, and every later message waits out the turn ceiling on the same silent process until the session is reset by hand or the gateway restarts. The turn also counts as a success, so the session's failure breaker never sees it.

Not a goal

  • Slack is a separate change (slack/handler.handle_message, fix(slack): fail and reset a turn the backend never finished #19008). The two touch no common file and merge in either order. Slack keeps its established "⏱️ Request timed out. Please try again." copy; these transports had no timeout notice before, so they use the dashboard chat's wording ("The agent did not finish its answer ...").
  • The webhook run path (dashboard/handlers/hooks._run_hook_inner) is fixed in the collector change that adds unfinished_turn_error, not here.
  • A user's cancel and a normal end_turn are unchanged; control tests pin both.
  • No renderer is changed. The notice reaches every renderer through the text path it already renders, so no transport needs its own branch.
  • The unfinished stop-reason set is a copy, as Slack's is: UNFINISHED_STOP_REASONS in messaging.driver, "timeout" and STOP_REASON_STALE_RECOVER. One shared stop-reason set replaces these copies once the change that adds it lands.

What changed (motivation → approach → change)

  • Symptom: a channel turn ended by "timeout" or STOP_REASON_STALE_RECOVER is delivered as a finished reply, booked as a success, and the next message reuses the silent runtime.
  • Root cause: the driver's EVENT_COMPLETE branch decides only whether a textless turn needs a notice, and the three dispatchers that drive a visible renderer (the shared one, Telegram's own and Slack's transport path) book every completed turn that reached the channel as a success.
  • Change:
    • src/kiro_crew/messaging/empty_turn_copy.py: UNFINISHED_TURN_NOTICE (new): "⏱️ The agent did not finish its answer before this turn's time limit, so the turn was stopped. Your next message starts the agent again." The module still imports no ACP name. It is loaded while kiro_crew.acp.client initialises (acp/client.py imports acp/prompt_blocks.py, which imports messaging.raster, and messaging/__init__.py loads messaging.driver), so the stop reasons live in the driver instead.
    • src/kiro_crew/messaging/driver.py: UNFINISHED_STOP_REASONS (new module constant): frozenset({"timeout", STOP_REASON_STALE_RECOVER}), with STOP_REASON_STALE_RECOVER added to the module's existing kiro_crew.acp.types import.
    • src/kiro_crew/messaging/driver.py, TurnDriver.run: for a terminal in UNFINISHED_STOP_REASONS, after the final flushes and before DONE, it dispatches the notice as the turn's last TEXT_CHUNK, after a blank line when text streamed, so every renderer shows it after the partial text or alone. It sets the new unfinished_turn flag (reset at the start of each run), and sets empty_turn_notice to "" so the textless verdict is not owed on top. The returned text stays the model's partial text.
    • src/kiro_crew/messaging/dispatch.py: after the delivery check, a turn with driver.unfinished_turn is booked with sessions.record_failure and Verdict.FAILED instead of _record_success and Verdict.ANSWERED, and the session is reset, keeping the conversation, as the compaction-failure retry in the same function does. A failed reset is logged; the verdict stays FAILED. The exchange is still recorded with the partial text.
    • src/kiro_crew/telegram/transport_dispatch.py, the post-turn bookkeeping in handle_message: a turn with driver.unfinished_turn is booked with sessions.record_failure and the failed-message counter instead of record_success, the shared-death clear and the success counter, and the session is reset, keeping the conversation. A failed reset is logged.
    • Second commit, src/kiro_crew/slack/transport_dispatch.py, the post-turn bookkeeping in handle_message_transport: TurnDriver.run shows the notice on this path too, and the path booked every completed turn as a success. A turn with driver.unfinished_turn is booked with sessions.record_failure and the failed-message counter instead of record_success, the shared-death clear and the success counter, and the session is reset once, keeping the conversation. A failed reset is logged. The reset runs while the turn holds its permit, like the breaker reset the same function's except branch can make, and the release in its finally block sees, through absorb_orphaned_release (session_allocation.py:1634), that the permit died with the reset session and leaves a successor's alone. The context check is skipped for such a turn (slack/transport_dispatch.py:1015): the runtime it would measure was just reset, and the except branch skips that check too.
    • Second commit, all three dispatchers: the explicit reset runs only when record_failure answers False (messaging/dispatch.py:2437-2439, telegram/transport_dispatch.py:1249-1250, slack/transport_dispatch.py:942-943). On the failure that trips the circuit breaker (the fifth in a row, session.py:758), record_failure has already reset the session and answered True (session_allocation.py:1500-1507). A same-key message can claim a successor runtime while that reset is awaited, and a second reset would end the successor mid-turn.
  • On the event loop the change adds one renderer dispatch on the existing async path and, in each dispatcher, at most two awaited session calls (record_failure, then reset unless the breaker already reset). The shared dispatcher already makes both in the same function, for an undelivered turn and for the compaction retry.

Rejected alternatives:

  • Rendering the notice inside each renderer's on_done: the renderers seal their bodies differently (Telegram seals as ok when stop_reason != "error", Discord uses the textless notice as its placeholder), so it would take one branch per transport, and the text path already renders the same way everywhere.
  • Raising at the driver's terminal so the dispatcher's exception path books the failure: the partial text has already streamed to the channel by then, and the exception path does not tell the user the turn was cut off.
  • Re-sending the message on a fresh runtime: nothing was received, and a silent re-send would hide a backend that is down.

Backwards compatibility

Compatible: only a turn ending with "timeout" or STOP_REASON_STALE_RECOVER behaves differently. A finished turn, a textless turn, a refused or error: turn and a user's cancel are unchanged.

Removes nothing: the change adds two constants, one driver flag and one dispatcher branch, and removes no field, path or function.

Tests

  • test/test_messaging_driver.py, new class TestUnfinishedTurn, on the file's _ScriptedProvider and _RecordingRenderer with the real TurnDriver:
    • test_the_notice_follows_the_partial_text[timeout] and [stale_recover]: the rendered text is the partial text, a blank line and the notice, DONE is last, the returned text is the partial text, empty_turn_notice is "" and the turn is marked unfinished.
    • test_a_textless_unfinished_turn_shows_the_notice_alone.
    • test_a_finished_or_cancelled_turn_gets_no_timeout_notice[end_turn] and [cancelled] (controls).
  • test/test_channel_turns.py, class TestDeliveryAwareAccounting, on the file's FakeSessions and ScriptedProvider with the real dispatcher:
    • test_an_unfinished_turn_is_a_failure_and_resets_the_session[timeout] and [stale_recover]: Verdict.FAILED, one failure booked, no success, one reset.
    • test_a_finished_or_cancelled_turn_keeps_the_session[end-turn] and [cancelled] (controls).
    • test_the_real_discord_renderer_shows_the_timeout_after_the_partial_text[timeout] and [stale_recover]: the real DiscordRenderer on the file's FakeDiscordClient shows the partial text followed by the notice; the turn fails and the session is reset.
    • test_at_the_breaker_threshold_an_unfinished_turn_resets_once[timeout] and [stale_recover] (second commit): record_failure acts as the breaker does at its threshold. It resets the session itself and answers True, and a same-key successor is claimed during that reset. The turn fails, the session is reset once, and the successor is not reset.
  • test/test_telegram.py, class TestTurnLifecycleCharacterization, on the file's _dispatcher, FakeProvider and _instrument with the real Telegram dispatcher and TurnDriver:
    • test_an_unfinished_turn_is_a_failure_and_resets_the_session[timeout] and [stale_recover]: no success booked, one failure, one reset.
    • test_at_the_breaker_threshold_an_unfinished_turn_resets_once[timeout] and [stale_recover] (second commit): the same breaker shape on the Telegram dispatcher; one failure, one reset, and the successor is not reset.
    • test_a_finished_turn_is_a_success_and_keeps_the_session (control): one success, no failure, no reset.
  • test/test_slack_transport_dispatch.py, new class TestTransportUnfinishedTurn (second commit), on the file's FakeSessions, ScriptedProvider and RecordingSlackClient with the real handle_message_transport and TurnDriver:
    • test_an_unfinished_turn_is_a_failure_and_resets_the_session[timeout] and [stale_recover]: the notice is shown in the thread; one failure is booked, no success, one reset, and no context check.
    • test_at_the_breaker_threshold_an_unfinished_turn_resets_once[timeout] and [stale_recover]: the same breaker shape on the Slack transport path; one failure, one reset, and the successor is not reset.
    • test_a_finished_turn_is_a_success_and_keeps_the_session (control): one success, one context check, no reset.

Red on main (7bb9d57), the 23 new tests, pytest test/test_messaging_driver.py test/test_channel_turns.py test/test_telegram.py test/test_slack_transport_dispatch.py -k "TestUnfinishedTurn or unfinished_turn_is_a_failure or finished_or_cancelled_turn_keeps_the_session or real_discord_renderer_shows_the_timeout or finished_turn_is_a_success_and_keeps or at_the_breaker_threshold_an_unfinished_turn_resets_once or TestTransportUnfinishedTurn" -p no:cacheprovider -n 0, RC=1 in 3 of 3 runs, the same failures each time, 17 failed, 6 passed (the six controls):

E       AssertionError: Here is the first half of the pl
E       AssertionError: assert <Verdict.ANSWERED: 'answered'> is <Verdict.FAILED: 'failed'>
E       assert ('half an answer' in 'half an \nhalf an answer\n\n-# Finished in 0s' and 'did not finish its answer' in 'half an \nhalf an answer\n\n-# Finished in 0s')
E       AssertionError: assert ['telegram:kirocrew:direct:7'] == []
E       AssertionError: ['success', 'context_check']
=========== 17 failed, 6 passed, 833 deselected, 2 warnings in 6.58s ===========

The last E line is the Slack transport path booking the turn a success. On main its first test fails one step earlier, because main shows no notice in the thread.

The four channel and Telegram breaker cases the second commit adds fail on main before their reset check, because main books the unfinished turn as answered. Their own red is on the first commit, 6799eed (these two test files copied into a detached checkout of it, -k at_the_breaker_threshold_an_unfinished_turn_resets_once), 3 of 3 runs, the same failures each time:

FAILED test/test_channel_turns.py::TestDeliveryAwareAccounting::test_at_the_breaker_threshold_an_unfinished_turn_resets_once[timeout] - AssertionError: the dispatcher reset again after the breaker did: ['first',...
FAILED test/test_channel_turns.py::TestDeliveryAwareAccounting::test_at_the_breaker_threshold_an_unfinished_turn_resets_once[stale_recover] - AssertionError: the dispatcher reset again after the breaker did: ['first',...
FAILED test/test_telegram.py::TestTurnLifecycleCharacterization::test_at_the_breaker_threshold_an_unfinished_turn_resets_once[timeout] - AssertionError: the dispatcher reset again after the breaker did: ['first',...
FAILED test/test_telegram.py::TestTurnLifecycleCharacterization::test_at_the_breaker_threshold_an_unfinished_turn_resets_once[stale_recover] - AssertionError: the dispatcher reset again after the breaker did: ['first',...
================ 4 failed, 666 deselected, 2 warnings in 4.71s =================

The full message is the dispatcher reset again after the breaker did: ['first', 'successor 1']: the explicit reset ended the successor.

The Slack transport tests are red on that first commit too, because the first commit leaves that path unchanged: it shows the notice and books the turn a success. The test file was copied into a detached checkout of 6799eed and run with -k TestTransportUnfinishedTurn, 3 of 3 runs, the same failures each time:

FAILED test/test_slack_transport_dispatch.py::TestTransportUnfinishedTurn::test_an_unfinished_turn_is_a_failure_and_resets_the_session[timeout] - AssertionError: assert ['success', 'context_check'] == ['failure', 'reset'
FAILED test/test_slack_transport_dispatch.py::TestTransportUnfinishedTurn::test_an_unfinished_turn_is_a_failure_and_resets_the_session[stale_recover] - AssertionError: assert ['success', 'context_check'] == ['failure', '
FAILED test/test_slack_transport_dispatch.py::TestTransportUnfinishedTurn::test_at_the_breaker_threshold_an_unfinished_turn_resets_once[timeout] - AssertionError: ['success', 'context_check']
FAILED test/test_slack_transport_dispatch.py::TestTransportUnfinishedTurn::test_at_the_breaker_threshold_an_unfinished_turn_resets_once[stale_recover] - AssertionError: ['success', 'context_check']
============ 4 failed, 1 passed, 79 deselected, 2 warnings in 2.52s ============

The two Slack breaker cases therefore never reach their reset check on 6799eed. They were also run on this branch with the Slack branch's breaker check removed (the reset made unconditional, in a detached checkout). They failed 3 of 3 with the dispatcher reset again after the breaker did: ['first',..., and the other three Slack cases passed.

The two Telegram failures are the fourth E line: the turn was booked a success.

Green on this branch, on 7bb9d57: the four test files whole, RC=0 in 3 of 3 runs, the 23 new tests among them:

======================= 856 passed, 5 warnings in 17.64s =======================

test/test_channel_turns.py, test/test_messaging_driver.py, the Telegram test files, every test file that names transport_dispatch or empty_turn_copy, and the two Slack transport test files that list lacked (test/test_channel_activation.py and test/test_slack_events_coverage.py), 83 files run serially: 5896 passed, 2 skipped, 5 xfailed, 1 failed. The failure is test_channel_activation.py::TestChannelActivationRouting::test_group_channel_mention_mode_ignores_thread_without_session, and it does not come from this change. It fails the same way on unchanged origin/main at 7bb9d57 with the same 83-file list (5873 passed, the same 1 failed), and the file passes alone on both (17 passed). The test leaves get_session_for_thread unconfigured on a bare MagicMock, so whether the thread reply is ignored depends on state an earlier file in the run leaves behind. mypy on the five changed source files: no issues. flake8, isort, black, scripts/check_black_formatting.py, scripts/check_comment_history.py (with COMMENT_HISTORY_BASE_REF=origin/main), scripts/check_agent_sdk_boundary.py, scripts/check_harness_parity.py and scripts/docs-lint.sh pass.

Manual verification

N/A — unit coverage sufficient: the tests drive the real TurnDriver, the real dispatcher and the real DiscordRenderer with only the provider, session manager and Discord client faked.

Related Issues

Open PRs that change any of the seven files this branch changes were listed with gh pr list --repo kirodotdev/KiroCrew --state open --limit 1000 --json number,files (657 open PRs; for the 13 whose file list stops at 100, the rest of their files were read page by page from gh api repos/kirodotdev/KiroCrew/pulls/<n>/files): #6595, #6600, #7626, #10098, #10192, #10965, #11722, #11831, #14089, #15111, #15273, #17582, #18192, #18215, #18268. Each one's patch for those files was checked with git apply --check (exact context) against main (33b67ac) and against this branch, and gives the same result on both except #15273's messaging/driver.py: its TurnDriver.__init__ hunk sits next to the new unfinished_turn field, so the exact-context check fails on this branch, while a three-way merge of #15273's head with this branch (git merge-tree --write-tree) is clean. #15273 also changes the driver.run call three lines above the changed Telegram block; that hunk applies to both. #6595, #6600, #7626, #10098, #10192 and #14089 already fail hunks on main.
GitHub search (gh search prs and gh search issues --repo kirodotdev/KiroCrew, open and merged) for "telegram timeout partial reply" and "empty_turn_notice timeout" returned nothing; "stop_reason timeout" returned only merged #5504 (native slash commands on the shared runtime, another topic). Sanity check: "empty_turn_notice" finds #12344, #13416 and #16429, none about a cut-off turn with partial text.

Pattern harvest

Rule candidate: review-prompt
Pattern: a turn-end notice that only speaks for a textless turn lets a cut-off turn with partial text read as finished; every surface that books a turn must name the unfinished terminals, not only the empty one.

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

@javenciu
javenciu requested review from a team and KiroCrewCaptain as code owners October 11, 2026 03:37
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Oct 11, 2026
@javenciu
javenciu force-pushed the fix/messaging-timed-out-turn branch from 8d8ef97 to a670ccd Compare October 11, 2026 07:00
@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 11, 2026
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

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

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of f3002c20dcfe6986e3c8622f13194f617c81df91 via the fork AI-review pipeline — 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/CONCERNS are advisory.

First-Principles-Verdict: PASS

Check one thing: on Slack's transport path these turns now show "The agent did not finish…", but ## Not a goal says Slack keeps its "⏱️ Request timed out" copy.

What this change ships

Inventory (8 items) — 8 justified

Intent: when the backend on a messaging channel never finishes a turn, the user should see that the reply was cut off, and their next message should go to a fresh agent instead of the same hung process. FIX.

  1. On Telegram, Discord, Teams and the others, a partial reply ended by "timeout" or stale_recover is now followed by a "did not finish its answer" notice — justified
  2. A textless turn that never finished shows that notice instead of the empty-turn notice — justified
  3. After such a turn the session is reset with its conversation kept, so the next message starts a new agent process — justified
  4. Such a turn is booked as record_failure/Verdict.FAILED, so the failure breaker counts it — justified
  5. Such a turn increments the failed-message stats counter, not the success one — justified
  6. Slack's transport path (slack/transport_dispatch.py) gets the same notice, failure booking and reset — justified
  7. Slack's transport path skips the context-usage check after such a turn — justified
  8. When the breaker has already reset the session at its threshold, the dispatcher does not reset it a second time — justified

[FIRST-PRINCIPLES-REVIEWED] f3002c2

Description read

[DESCRIPTION-READ] 26533d4185bc6629b8c68c99c6c9ba131a287fa3f72d95a0cfffbea38e61648c

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — 🟡 CONCERNS

Design-level review of f3002c20dcfe6986e3c8622f13194f617c81df91 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

stale_recover is handled like a hard timeout: it counts toward the circuit breaker and shows "time limit" wording, but it can come from a misjudged probe on a live turn.

Watch

  • stale_recover handled as a timeout. UNFINISHED_STOP_REASONS = frozenset({"timeout", STOP_REASON_STALE_RECOVER}) → record_failure and a "before this turn's time limit" notice. In session_handle.py:5392-5412, stale_recover is a rewritten probe-ack, and kiro-cli also acks a probe cancel on a LIVE turn. The design rule there is "an oracle mistake therefore costs a regeneration, never a session", and the dashboard handles it by resetting, resuming and sending a continue-nudge. Here a probe mistake instead charges the breaker (five in a row trips it), tells the user a time limit they never hit was reached, and drops the work with no continuation. Messaging recovery now differs from chat for the same stop reason.
    Clears when: stale_recover gets its own accurate notice and either stays off the breaker or follows the dashboard's resume-and-continue recovery, or the PR shows why charging the breaker for a probe misjudgment is intended.
  • Two Slack timeout notices. "Not a goal" says Slack stays separate and keeps "⏱️ Request timed out. Please try again.", yet the second commit changes slack/transport_dispatch.py. Slack users on the transport path will now see "The agent did not finish its answer…", while slack/handler (fix(slack): fail and reset a turn the backend never finished #19008) shows the old copy. One channel ends up with two different notices for the same event, depending on which internal path ran.
    Clears when: both Slack paths show the same notice, or the description says the transport path's different copy is intended.

[DESIGN-REVIEWED] f3002c2

Description read

[DESCRIPTION-READ] 99af2f63a3b39269ec7067d31ecffac5d31e85961fda0021ce0ec7fb2a4387a9

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed f3002c20dcfe6986e3c8622f13194f617c81df91 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] f3002c2

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed f3002c20dcfe6986e3c8622f13194f617c81df91 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] f3002c2

@javenciu

Copy link
Copy Markdown
Contributor Author

Fixed in the second commit, d2d0f9e. After an unfinished turn, each dispatcher now resets the session only when record_failure answers False: src/kiro_crew/messaging/dispatch.py:2437-2439, src/kiro_crew/telegram/transport_dispatch.py:1249-1250, and Slack's transport path, which this commit also makes book the failure, at src/kiro_crew/slack/transport_dispatch.py:942-943. On the failure that trips the breaker (session.py:758), record_failure resets the session itself and answers True (session_allocation.py:1500-1507), so the turn leaves the breaker's reset as the only one, and a successor claimed during it keeps running. That is the same rule the shared-death path follows, which never resets after the breaker has (dispatch.py:1344-1364). The new test_at_the_breaker_threshold_an_unfinished_turn_resets_once, in test/test_channel_turns.py:1062, test/test_telegram.py:8780 and test/test_slack_transport_dispatch.py:365, makes record_failure reset and answer True, with a successor claimed during that reset. On a670ccd the channel and Telegram cases fail 3 of 3 for both stop reasons (AssertionError: the dispatcher reset again after the breaker did: ['first', 'successor 1']). With the breaker check taken out of the Slack branch, its two cases fail 3 of 3 the same way. Here all pass 3 of 3.

@javenciu

Copy link
Copy Markdown
Contributor Author

Slack's transport path now keeps the notice's promise. TurnDriver.run shows the notice there too, so the second commit, d2d0f9e, books an unfinished turn on that path as a failure and resets the session once, keeping the conversation, as the shared and Telegram dispatchers do. The branch is src/kiro_crew/slack/transport_dispatch.py:924-965. It books the failure and the failed-message counter instead of a success, and its reset (:945) is skipped when the breaker has already reset. The reset runs while the turn holds its permit, like the breaker reset in the same function's except branch. The release at :1391, in its finally block, then sees through absorb_orphaned_release (session_allocation.py:1634) that the permit died with the reset session, so a successor's permit is left alone. The context check is skipped for such a turn (:1015), because the runtime it would measure was just reset. TestTransportUnfinishedTurn in test/test_slack_transport_dispatch.py:312 covers both stop reasons, the breaker threshold and a finished-turn control. Its four unfinished cases fail on a670ccd (assert ['success', 'context_check'] == ['failure', 'reset']) and pass here.

@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 11, 2026
On the messaging transports (Telegram, Discord, Teams and the others),
a turn whose backend went silent was delivered as a finished reply.
When the session handle ended the turn with "timeout" (its turn
ceiling) or STOP_REASON_STALE_RECOVER (a stale turn its probe confirmed
wedged), TurnDriver flushed the partial text and sent DONE with no
notice: empty_turn_notice speaks only for a textless turn. The turn was
then booked a success and the session kept: messaging.dispatch booked
_record_success and Verdict.ANSWERED, and Telegram's own dispatcher,
telegram/transport_dispatch.py, booked record_success. The runtime
still read alive, so the next message was sent to the same silent
runtime.

TurnDriver now sends a timeout notice as the turn's last text after the
partial text (or alone), so every renderer shows it through its normal
text path, owes no textless notice on top, and marks the turn
unfinished. Both dispatchers book such a turn as a failure
(record_failure; Verdict.FAILED in messaging.dispatch, the failed-
message counter in Telegram's) and reset the session, keeping the
conversation, as messaging.dispatch's compaction-failure retry does.
The notice lives in empty_turn_copy beside the other turn notices. The
two stop reasons live in messaging.driver, its only reader, beside its
other ACP stop reasons: empty_turn_copy is loaded while
kiro_crew.acp.client initialises, so it imports no ACP name. A finished
turn and a user's cancel are unchanged.
…ath too

The unfinished-turn branch in the shared dispatcher and in Telegram's booked
the failure and then reset the session unconditionally. At the
circuit-breaker threshold record_failure already resets the session itself
and answers True, and a same-key message that arrives while that reset is
awaited can claim a successor runtime. The second reset then ended the
successor mid-turn. Both now reset only when record_failure reports that the
breaker did not.

Slack's transport path (slack/transport_dispatch.handle_message_transport)
shows the same notice, because TurnDriver.run posts it, but it booked every
completed turn as a success and never reset. It now books an unfinished turn
as a failure and resets once, with the same breaker check, while the turn
still holds its permit, and it skips the context check on the runtime it
just reset.

Tests: test_at_the_breaker_threshold_an_unfinished_turn_resets_once in
test/test_channel_turns.py, test/test_telegram.py and
test/test_slack_transport_dispatch.py, with record_failure behaving as the
breaker does at its threshold; on the Slack path also
test_an_unfinished_turn_is_a_failure_and_resets_the_session and a
finished-turn control. Each fails on the previous commit and passes here.
@javenciu
javenciu force-pushed the fix/messaging-timed-out-turn branch from d2d0f9e to f3002c2 Compare October 11, 2026 12:45
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Oct 11, 2026

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this PR, a turn that ended "timeout" or stale_recover on the shared, Telegram or Slack transport dispatchers looked like a finished reply. It was booked as a success, and the next message went to the same silent runtime, which hung again. This PR fixes that at the root. TurnDriver.run adds UNFINISHED_TURN_NOTICE as the turn's last text chunk and sets unfinished_turn. Each dispatcher then books record_failure and the failed counter, and resets the session (keeping the conversation) only when record_failure did not already trip the breaker. I checked record_failure (session_allocation.py:1494). Its False branch has no await, so no successor can be claimed between it and the explicit reset. Its True branch has already reset, so skipping the second reset protects a successor. I tried a user cancel and a normal end_turn against the new branch: both are untouched, and the controls pin them. The 17 new tests fail on main and pass here, and they drive the real driver, dispatchers and Discord renderer. I weighed both Design watch items. The breaker charge is harmless, because the breaker's only action is the same reset this path does anyway. The "time limit" wording for stale_recover and the Slack copy differing from #19008 are copy choices, not defects. Checks are green and there is no change request. — crew-pr-reviewer (deep re-check)

@iamwhatever
iamwhatever enabled auto-merge (squash) October 11, 2026 17:35
@iamwhatever
iamwhatever merged commit d8430e9 into kirodotdev:main Oct 11, 2026
104 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants