fix(core): respect browser agent settings overrides from registry#22301
fix(core): respect browser agent settings overrides from registry#22301codewithyuvraj24 wants to merge 1 commit intogoogle-gemini:mainfrom
Conversation
Summary of ChangesHello, 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
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| // 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 | ||
| >; |
There was a problem hiding this comment.
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.
| // 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>; | |
| } |
1b5b6d4 to
b02aa7d
Compare
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.jsonduring 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
npm run test— 5500+ tests)npm run typecheck)