Skip to content

fix(core): respect browser agent settings overrides from registry#22301

Open
codewithyuvraj24 wants to merge 1 commit intogoogle-gemini:mainfrom
codewithyuvraj24:gsoc-fix-browser-agent-settings-#22267
Open

fix(core): respect browser agent settings overrides from registry#22301
codewithyuvraj24 wants to merge 1 commit intogoogle-gemini:mainfrom
codewithyuvraj24:gsoc-fix-browser-agent-settings-#22267

Conversation

@codewithyuvraj24
Copy link
Copy Markdown

Fixes #22267

What happened?

The Browser Agent completely ignored configuration overrides provided in global or project-level settings.json (e.g., maxTurns, maxTimeMinutes). The browserAgentFactory.ts recreated a raw definition with hardcoded defaults instead of retrieving the pre-merged definition from the AgentRegistry.

Root Cause

In createBrowserAgentDefinition(), the factory called BrowserAgentDefinition(config, ...) directly, which always returns hardcoded defaults. Meanwhile, the AgentRegistry had already merged user overrides from settings.json during initialization — but this merged definition was never consulted.

Fix

Modified browserAgentFactory.ts to first check for an existing definition in the AgentRegistry via config.getAgentRegistry()?.getDefinition(BROWSER_AGENT_NAME). If found, it uses that (preserving all user overrides). If not found, it falls back to the original behavior.

Testing

  • All existing browserAgentFactory.test.ts tests pass (13/13)
  • Full test suite passes (npm run test — 5500+ tests)
  • TypeScript type checking passes (npm run typecheck)

@codewithyuvraj24 codewithyuvraj24 requested a review from a team as a code owner March 13, 2026 08:15
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug where the Browser Agent failed to apply user-defined settings overrides, leading to unexpected behavior. The fix ensures that agent configurations are correctly loaded from the AgentRegistry, preserving custom settings. Additionally, the changes introduce enhanced policy management by allowing policy updates based on skillName, providing more granular control over tool permissions.

Highlights

  • Browser Agent Configuration Fix: Resolved an issue where the Browser Agent ignored configuration overrides from settings.json, ensuring maxTurns and maxTimeMinutes are respected.
  • Agent Definition Retrieval: Modified browserAgentFactory.ts to first attempt retrieving the Browser Agent definition from the AgentRegistry to preserve user-defined overrides.
  • Skill-based Policy Updates: Extended the policy update mechanism to support skillName for dynamically adding allow rules, enhancing flexibility for skill activation.
Changelog
  • packages/core/src/agents/browser/browserAgentFactory.ts
    • Imported BROWSER_AGENT_NAME for agent identification.
    • Modified createBrowserAgentDefinition to check AgentRegistry for existing definitions before creating a new one, ensuring user overrides are respected.
  • packages/core/src/confirmation-bus/types.ts
    • Added skillName property to the UpdatePolicy interface.
  • packages/core/src/policy/config.ts
    • Updated createPolicyUpdater to handle skillName in UpdatePolicy messages, converting it to argsPattern for policy rules.
    • Added logic to create new policy rules based on skillName for dynamic allow decisions.
  • packages/core/src/policy/utils.ts
    • Modified buildArgsPatterns to generate argument patterns based on skillName if provided.
  • packages/core/src/tools/activate-skill.ts
    • Imported PolicyUpdateOptions type.
    • Overrode getPolicyUpdateOptions in ActivateSkillToolInvocation to return skillName for policy updates.
  • packages/core/src/tools/tools.ts
    • Added skillName property to the PolicyUpdateOptions interface.
Activity
  • All existing browserAgentFactory.test.ts tests passed (13/13).
  • The full test suite passed (npm run test — 5500+ tests).
  • TypeScript type checking passed (npm run typecheck).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request primarily fixes an issue where browser agent settings overrides were being ignored. The fix correctly retrieves the agent definition from the registry, though it introduces an unsafe type assertion that could be improved for better type safety. Additionally, the PR adds a new feature to support 'always allow' policies for skill activations, with consistent changes across policy, confirmation, and tool files. My review includes one high-severity suggestion to enhance the type safety of the main bug fix.

Comment on lines +144 to +149
// We know it's a LocalAgentDefinition, we can safely assume it has the right schema
// since we registered it as such.
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
baseDefinition = registryDef as unknown as LocalAgentDefinition<
typeof BrowserTaskResultSchema
>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The use of as unknown as bypasses TypeScript's type safety and relies on an assumption that might not hold true in the future. To make the code more robust and prevent potential runtime errors, it's better to add a runtime check for the schema. This allows for a safer, more direct type cast.

Suggested change
// We know it's a LocalAgentDefinition, we can safely assume it has the right schema
// since we registered it as such.
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
baseDefinition = registryDef as unknown as LocalAgentDefinition<
typeof BrowserTaskResultSchema
>;
// We know it's a LocalAgentDefinition, but a runtime check of the schema
// provides greater safety than a type assertion alone.
if (
(registryDef as LocalAgentDefinition).outputConfig?.schema ===
BrowserTaskResultSchema
) {
baseDefinition =
registryDef as LocalAgentDefinition<typeof BrowserTaskResultSchema>;
}

@codewithyuvraj24 codewithyuvraj24 force-pushed the gsoc-fix-browser-agent-settings-#22267 branch from 1b5b6d4 to b02aa7d Compare March 13, 2026 08:17
@gemini-cli gemini-cli bot added area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality priority/p2 Important but can be addressed in a future release. 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Browser Agent ignores settings.json overrides (e.g., maxTurns)

1 participant