Skip to content

fix: privileged context state not preserved across tool calls#54

Open
freema wants to merge 1 commit intomainfrom
fix/privileged-context-state
Open

fix: privileged context state not preserved across tool calls#54
freema wants to merge 1 commit intomainfrom
fix/privileged-context-state

Conversation

@freema
Copy link
Copy Markdown
Collaborator

@freema freema commented Mar 29, 2026

Summary

  • 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 ID and restored to it in their finally blocks, silently reverting the user's privileged context selection

Changes

  • src/tools/privileged-context.ts: call setCurrentContextId() after successful context switch
  • src/firefox/index.ts: expose setCurrentContextId() on FirefoxClient
  • src/tools/firefox-prefs.ts: skip context restore when originalContextId matches the chrome context (2 finally blocks)
  • src/tools/webextension.ts: same fix for list_extensions
  • tests/tools/privileged-context.test.ts: 2 tests that fail without the fix, pass with it

Test plan

  • 392/392 tests pass
  • Lint + typecheck pass

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>
@freema freema requested a review from juliandescottes March 29, 2026 15:21
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