Repository navigation
fix(claude): switch model, effort and permission mode in place - #28
Merged
Merged
Conversation
Changing any of them between turns replaced the retained Claude process, stopping background subagents and orphaning background shells, and lost their completions. The process now switches them with set_model, apply_flag_settings and set_permission_mode before the prompt, buffering background output that arrives meanwhile. A change that does need a new process (working directory, launch context, sandbox, thinking off, ultracode, going back to a default model or effort, entering bypass mode without its launch flag), or a switch Claude refuses, no longer stops running background work: the turn fails with RestartWouldStopBackgroundWork naming that work, and the process goes back to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
…itch A frame Claude wrote between the answers to a settings switch on an idle process, such as its announcement of a permission change, was dropped. It is now kept, in order, and read by the turn before its own output. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
@greptile-apps review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Changing a retained Claude turn's model, effort or permission mode replaced the Claude process. The reuse check compared those settings, and on any difference called
terminate()on the parked process without looking at what it was running. Background subagents were stopped, background shells were orphaned, and their completions never reached a later turn.Confirmed live with haiku before the fix: in each of
cfg-model,cfg-effort,cfg-permissionandcfg-model-agent, the next turn ran in a new Claude process and the background task's completion was lost.Fix
set_model,apply_flag_settings {effortLevel}andset_permission_mode, and waits for each success before writing the prompt. Background output that arrives meanwhile is parsed and buffered exactly as while parked.RuntimeError::RestartWouldStopBackgroundWork, which names the work (RuntimeBusy,RequiresUserAction,DeliveryState::NotSent). The process is left running. A switch Claude refuses is handled the same way, and the process goes back to its background work, with its settings marked unknown so the next turn resends them in full.set_permission_modemade the probe replace a healthy process.AgentAdapter::retained_background_summarydescribes the running work for the error.Tests
tests/retained_live_messages.rs):claude_permission_change_replaces_with_single_pool_slotasserted the old behaviour. It is nowclaude_permission_change_is_switched_in_place, and its single-pool-slot coverage moved to a thinking-off change.examples/claude_live_messages_smoke.rs, haiku): all 12 scenarios pass, the existing 8 pluscfg-model,cfg-effort,cfg-permissionandcfg-model-agent. After the model change the next turn reportedclaude-sonnet-5-5.-D warningson 1.99,cargo test --all-features(425 tests), docs, 1.88 MSRV check.Not in this PR
Background shells survived the old replacement, running outside the process tree the SDK terminates. That leak is separate and still open.
🤖 Generated with Claude Code