fix: privileged context state not preserved across tool calls#54
Merged
Conversation
select_privileged_context switched the window and Marionette context but never updated currentContextId. Helper tools (set_firefox_prefs, get_firefox_prefs, list_extensions) saved the stale context and restored to it in their finally blocks, silently reverting the user's privileged context selection. - Add setCurrentContextId() to FirefoxClient public API - Call setCurrentContextId in select_privileged_context - Skip context restore in helper tools when already on the right chrome context Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
juliandescottes
approved these changes
Mar 30, 2026
Collaborator
juliandescottes
left a comment
There was a problem hiding this comment.
Thanks a lot!
The fix looks great, one nit. For the test, let's clean it up and remove the misleading BUG mentions, since the bug in question is fixed by the PR.
Comment on lines
+405
to
+406
| setCurrentContextId(contextId: string): void { | ||
| this.core.setCurrentContextId(contextId); |
Collaborator
There was a problem hiding this comment.
nit: we could use the new helper at L74:
(id: string) => this.core.setCurrentContextId(id)
Comment on lines
+58
to
+59
| // BUG: select_privileged_context does NOT call setCurrentContextId | ||
| // so currentContextId stays as 'original-content-context' |
Collaborator
There was a problem hiding this comment.
Are those "BUG" comments describing the issue fixed in the PR? If so I think we should rephrase them, in the long run they could be confusing. Here's I'm not sure if this is actually fixed or if it's a todo to fix later.
| })); | ||
| }); | ||
|
|
||
| it('select_privileged_context should update currentContextId (BUG: it does not)', async () => { |
Collaborator
There was a problem hiding this comment.
The BUG: it does not mention in the title here also seems confusing
Collaborator
|
PR was merged without addressing or answering comments, I will send a follow up. |
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.
Summary
select_privileged_contextswitched the window and Marionette context but never updatedcurrentContextIdset_firefox_prefs,get_firefox_prefs,list_extensions) saved the stale context ID and restored to it in theirfinallyblocks, silently reverting the user's privileged context selectionChanges
src/tools/privileged-context.ts: callsetCurrentContextId()after successful context switchsrc/firefox/index.ts: exposesetCurrentContextId()onFirefoxClientsrc/tools/firefox-prefs.ts: skip context restore whenoriginalContextIdmatches the chrome context (2 finally blocks)src/tools/webextension.ts: same fix forlist_extensionstests/tools/privileged-context.test.ts: 2 tests that fail without the fix, pass with itTest plan