Skip to content

fix: lost provider session recovery#1938

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

fix: lost provider session recovery#1938
ashvinnihalani wants to merge 1 commit intopingdotgg:mainfrom
ashvinnihalani:t3code/upstream-session-reuse

Conversation

@ashvinnihalani
Copy link
Copy Markdown
Contributor

@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 for turn start, which can affect whether sessions are restarted vs reused and could cause unexpected extra session creation if the active-session check is wrong. Scope is limited to ProviderCommandReactor plus a focused regression test.

Overview
Fixes lost provider-session recovery by only reusing thread.session when there is also a live provider session. ensureSessionForThread now resolves the active provider session up front and treats projected (non-stopped) session state as reusable only if it matches an active session, otherwise it starts and binds a fresh session.

Adds a regression test ensuring a new thread.turn.start will call startSession+sendTurn when the thread has only projected session state (e.g., after restart) and no active provider session.

Reviewed by Cursor Bugbot for commit 9c66c3d. 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 9c66c3d.

@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: 456a17ce-80fe-4f0f-843c-6e86b904f41b

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

@ashvinnihalani ashvinnihalani changed the title [Fix]: Recover from lost provider sessions when starting a turn fix: lost provider session recovery Apr 12, 2026
@ashvinnihalani
Copy link
Copy Markdown
Contributor Author

@binbandit Done

- Require an active provider session before treating thread.session as reusable
- Add regression coverage for starting a fresh session when only projected state exists
@ashvinnihalani ashvinnihalani force-pushed the t3code/upstream-session-reuse branch from c11ff5d to 9c66c3d Compare April 12, 2026 03:36
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