Skip to content

fix: prevent session stuck at running on turn completion#1364

Open
sfncore wants to merge 1 commit intopingdotgg:mainfrom
sfncore:fix/stuck-session-on-turn-completion
Open

fix: prevent session stuck at running on turn completion#1364
sfncore wants to merge 1 commit intopingdotgg:mainfrom
sfncore:fix/stuck-session-on-turn-completion

Conversation

@sfncore
Copy link

@sfncore sfncore commented Mar 24, 2026

What changed

turn.completed events with a mismatched turnId are no longer silently dropped by the STRICT_PROVIDER_LIFECYCLE_GUARD in ProviderRuntimeIngestion. A warning log is emitted instead.

Why

When the runtime emits turn.completed with a turnId that doesn't match the thread's tracked activeTurnId, the guard prevented the thread.session.set command from being dispatched. The session stayed at "running" permanently — the UI showed "working for X minutes" indefinitely with no way to send new messages. Switching threads and back sometimes fixed it (full state resync).

Files changed

  • ProviderRuntimeIngestion.tsturn.completed always applies regardless of turnId mismatch; warning log on mismatch
  • ProviderRuntimeIngestion.test.ts — updated 2 tests to match new behavior

All 25 existing tests pass.


Note

Medium Risk
Changes provider lifecycle guarding so turn.completed can clear a running session even when turnId mismatches, which could mask real turn-tracking bugs or end a session earlier than expected. Scope is limited to runtime ingestion and covered by updated tests plus a new warning log for observability.

Overview
Prevents threads from getting stuck in a perpetual running state by changing ProviderRuntimeIngestion to always apply turn.completed events even when STRICT_PROVIDER_LIFECYCLE_GUARD detects a turnId mismatch or missing turnId.

When this mismatch occurs under strict guarding, the ingestion layer now emits a warning log and still dispatches the session transition to ready/error. Tests were updated to assert the new behavior (mismatched turn.completed now clears activeTurnId and readies the session).

Written by Cursor Bugbot for commit 64ae7ce. This will update automatically on new commits. Configure here.

Note

Fix session stuck in running state on turn completion when turnId mismatches

  • The lifecycle guard in ProviderRuntimeIngestion.ts previously rejected turn.completed events when the turnId didn't match the active turn, leaving sessions stuck in the running state.
  • Now turn.completed is always accepted regardless of turnId mismatch or missing active turn, unconditionally transitioning the session to ready.
  • A warning is logged with mismatch context (threadId, eventTurnId, activeTurnId) when STRICT_PROVIDER_LIFECYCLE_GUARD is enabled and a mismatch is detected.
  • Behavioral Change: a turn.completed from a different turn now clears the running state; previously it had no effect.

Macroscope summarized 64ae7ce.

…tched turnId

The STRICT_PROVIDER_LIFECYCLE_GUARD in ProviderRuntimeIngestion silently
dropped turn.completed events when the event's turnId didn't match the
thread's tracked activeTurnId. This caused the session to remain
permanently stuck at "running" status — the UI showed "working for X
minutes" indefinitely with no way to send new messages.

The fix ensures turn.completed always transitions the session to "ready"
regardless of turnId mismatch. A warning log is emitted when a mismatch
is detected to aid future debugging of why turnIds diverge.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f378573c-72e1-4ca8-afe3-48341315be34

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Mar 24, 2026
@rdoupe
Copy link

rdoupe commented Mar 24, 2026

Adding context from the now-closed PR #1348: that thread explicitly referenced user-filed issues #1069 and #1335 around stale/incorrect Working/Completed status behavior.

Linking those here so #1364 has the same issue lineage in one place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants