Skip to content

fix(threads): replay the thread's tail after a provider switch or dropped session (#1493 A, #237) - #1494

Merged
currentbits merged 2 commits into
mainfrom
coder/1493-a-keep-context-on-provider-switch-20ee20
Oct 6, 2026
Merged

currentbits merged 2 commits into
mainfrom
coder/1493-a-keep-context-on-provider-switch-20ee20

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Item A of #1493, also #237.

Bug: setProvider (electron/services-threads.js) nulled sessionId on a provider or model-pin change but set neither replayContext nor handoffFrom. So buildHandoffPrefix returned "" and the next run started with no history. Automatic quota failover (runner-quota-wait.js) goes through the same path, so a thread that failed over mid-task also restarted blind. A worktree move that drops the session (Store.updateThread worktreePath rule) had the same hole.

Fix: whenever a session is dropped on a thread that had one, set replayContext: true. The next send then digests the thread's own retained tail, the same mechanism a rewind (#254) uses. The runner clears the flag after use.

Verified independently

  • The new provider-switch-context.test.js fails on main (4 of 5): manual switch, quota failover, model-pin switch, and worktree move. The test that a brand-new thread gets no prefix passes on both.
  • typecheck exits 0.
  • test:electron passes 4161 of 4161.

🤖 Generated with Claude Code

Willem and others added 2 commits October 6, 2026 15:17
setProvider dropped the old CLI's session without setting replayContext,
so the next run (and every quota failover, which routes through it) started
with no history. Any session drop in setProvider now sets replayContext,
reusing the #254 rewind digest of the thread's own retained tail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-06T13:22:59.873674Z 4dff0dd PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4dff0dd03a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +615 to +619
if (patch.sessionId === null) {
// The new CLI (or re-pinned model) starts with no memory of this thread.
// Replay its own retained tail on the next send, same as a rewind (#254),
// or a switch mid-task (and quota failover) restarts blind (#1493).
patch.replayContext = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Exclude the current prompt from quota-failover replay

On automatic quota failover, the first attempt has already appended the current user message before setProvider enables replayContext; the resumed startRun then builds the replay tail from that transcript and separately appends the same prompt to the CLI input. Consequently every session-bearing failover sends the request twice (user: keep going inside the hand-off block and keep going again afterward), which can cause duplicated actions and displaces older messages from the capped replay tail. The replay path should omit the in-flight user message when fromQuotaFailover is set.

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant