fix: sync ActiveTurnState.auto_approve when remember checkbox is set#2041
fix: sync ActiveTurnState.auto_approve when remember checkbox is set#2041gaord wants to merge 1 commit into
Conversation
When a user checks 'Remember for this tool' and approves a tool call, remember_thread_auto_approve() only persisted thread.auto_approve to disk but did not update the in-memory ActiveTurnState for the current turn. This meant subsequent tool calls within the same turn would still require manual approval, making the remember checkbox appear non-functional. Now remember_thread_auto_approve() also sets ActiveTurnState.auto_approve = true, so active_turn_flags() returns the correct value and the approval_decision() logic auto-approves remaining tool calls in the current turn.
There was a problem hiding this comment.
Code Review
This pull request introduces logic to update the in-memory state of an active turn to enable auto-approval. The review feedback identifies a logic flaw where early returns in the function prevent this update from occurring if the persisted state is already set to auto-approve, suggesting a refactor of the control flow to ensure consistent synchronization.
| { | ||
| let mut active = self.active.lock().await; | ||
| if let Some(state) = active.engines.get_mut(thread_id) { | ||
| if let Some(turn) = state.active_turn.as_mut() { | ||
| turn.auto_approve = true; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
The in-memory synchronization logic added here is shadowed by the early return at line 857. If thread.auto_approve is already true in the persisted record (which can happen if a turn was started with an explicit auto_approve = false override), the function returns before reaching this block. To ensure the current turn is always updated when the user selects "Remember", the persistence logic should be decoupled from the in-memory update, and the early returns at lines 853 and 856 should be refactored to allow the sync to proceed even if the persisted state is already up-to-date or if loading the thread fails. Additionally, consider adding a test case that verifies in-memory sync when a turn override is present.
|
Thanks @gaord — I harvested this fix into #2047 and preserved your commit author. I also added a focused regression assertion that verifies remember=true updates both the persisted thread policy and the active turn flags used by subsequent approvals. Local verification on #2047 includes |
Problem
When a user checks "Remember for this tool" and approves a tool call, subsequent tool calls within the same turn still require manual approval. The remember checkbox appears non-functional.
Root Cause
remember_thread_auto_approve()only persiststhread.auto_approve = trueto disk, but does not update the in-memoryActiveTurnState.auto_approvefor the current turn.When the next
ApprovalRequiredevent arrives,active_turn_flags()reads fromActiveTurnState(which is stillfalse), soapproval_decision()returnsDenyTooland the approval dialog pops up again.The persisted
thread.auto_approveonly takes effect when the next turn starts (which creates a freshActiveTurnStatefrom the stored thread record).Fix
In
remember_thread_auto_approve(), after persisting the thread record, also update the current turn'sActiveTurnState.auto_approvetotrue:This ensures
active_turn_flags()returns the correct value immediately, andapproval_decision()auto-approves remaining tool calls within the current turn.Testing
approval_required_remember_flips_thread_auto_approvecontinues to pass (it only verifies persistedthread.auto_approve).