Skip to content

[Fix]: Recover from lost provider sessions when starting a turn#1938

Open
ashvinnihalani wants to merge 1 commit intopingdotgg:mainfrom
ashvinnihalani:t3code/upstream-session-reuse
Open

[Fix]: Recover from lost provider sessions when starting a turn#1938
ashvinnihalani wants to merge 1 commit intopingdotgg:mainfrom
ashvinnihalani:t3code/upstream-session-reuse

Conversation

@ashvinnihalani
Copy link
Copy Markdown

@ashvinnihalani ashvinnihalani commented Apr 11, 2026

What Changed

  • Require an active provider session before treating thread.session as reusable
  • Add regression coverage for starting a fresh session when only projected state exists

Why

Starting a new turn could fail after the provider session was lost because the app still believed the old session was reusable.

This change makes the next turn recover automatically by starting a fresh provider session instead of trying to reuse stale session state.

UI Changes

None.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Medium Risk
Changes session-reuse logic in the turn-start path to require a live provider session, which could alter when sessions are restarted vs reused. Risk is moderate because it affects orchestration/provider session lifecycle and could impact turn startup behavior across providers.

Overview
Fixes a turn-start failure mode where a thread’s projected thread.session state could be treated as reusable even after the underlying provider session was lost.

ensureSessionForThread now only considers an existing session reusable when a matching active provider session is present (via listSessions()); otherwise it starts and binds a fresh provider session. Adds a regression test covering the “projected-only session state” scenario to ensure a new session is started and the turn is still sent.

Reviewed by Cursor Bugbot for commit c11ff5d. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix ProviderCommandReactor to start a fresh session when provider session is lost

When a thread has a projected session state but no active provider session, the reactor was incorrectly treating it as an existing session and skipping session initialization. The fix resolves the active provider session earlier in ProviderCommandReactor.ts and requires both a non-stopped projected session and a live active session before reusing an existing session.

Macroscope summarized c11ff5d.

- Require an active provider session before treating thread.session as reusable
- Add regression coverage for starting a fresh session when only projected state exists
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 11, 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: 26edf4d2-2d35-47e1-82e0-d78a4858978e

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:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Apr 11, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 11, 2026

Approvability

Verdict: Approved

This is a small, well-scoped bug fix that adds a defensive check to verify an active session actually exists before attempting to reuse it. The change consists of moving one function call and adding one condition check, with a comprehensive test covering the fix.

You can customize Macroscope's approvability policy. Learn more.

@binbandit
Copy link
Copy Markdown
Contributor

Can you please use a more conventional PR title?

eg:

fix: lost provider session recovery

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

Labels

size:XS 0-9 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.

2 participants