Repository navigation
refactor(a2a-server): implement V1 to V2 settings migration logic - #29450
Conversation
Unify configuration loading in @google/gemini-cli-a2a-server with the V2 hierarchical settings schema while preserving transparent in-memory backward compatibility for legacy V1 settings files.
- Add migrateDeprecatedSettings() and legacy compatibility getters in settings.ts to map flat V1 keys and inverted boolean flags into V2 nested paths in memory without mutating files on disk.
- Replace shallow user/workspace scope spread with customDeepMerge() with prototype pollution filtering.
- Support recursive environment variable interpolation ($VAR, ${VAR}, ${VAR:-default}) with circular reference protection.
- Add Zod V2 schema validation (settingsZodSchema / validateSettings).
- Update loadConfig(), setIsTrusted(), and createApp() to read canonical V2 settings paths with legacy fallback.
- Add unit tests covering V1-to-V2 migration, V2 deep merging, prototype pollution protection, env var resolution, and server bootstrap.
Fixes google-gemini#28261
|
📊 PR Size: size/XL
|
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 refactors the configuration management system in a2a-server to support a hierarchical V2 schema. By implementing a robust migration pipeline, the changes ensure transparent backward compatibility with existing flat V1 settings. The update improves the reliability of configuration loading through deep merging, recursive environment variable resolution, and strict schema validation, while maintaining existing functionality for end-users. Highlights
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 the 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 counterproductive. 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces full compatibility with the V2 nested settings structure in packages/a2a-server. It implements robust migration logic (migrateDeprecatedSettings), legacy compatibility getters (attachLegacyCompatibilityGetters), a prototype-pollution-safe deep merge utility (customDeepMerge), and Zod-based schema validation for configuration settings. Additionally, environment variable resolution is enhanced to support default values and circular reference detection. The feedback recommends removing the backward-compatibility fallback logic for deprecated root-level properties like folderTrust in favor of directly using the canonical V2 paths with safe defaults, ensuring strict adherence to the interface contract.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for the V2 nested settings structure in the a2a-server package, implementing a migration path from legacy V1 flat settings, Zod-based validation, and deep merging capabilities. The changes update configuration loading, workspace trust checks, and associated tests to align with the new hierarchical settings schema. The review feedback highlights two important robustness improvements: refining the isPlainObject helper to prevent non-plain objects (such as Date or RegExp) from being incorrectly merged, and using this helper within resolveEnvVarsInObjectInternal to avoid stripping prototypes of non-plain objects during environment variable resolution.
…i into b_561555622 # Conflicts: # packages/a2a-server/src/config/config.ts
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements full compatibility with the V2 nested settings structure in packages/a2a-server. It introduces a Zod schema (settingsZodSchema) for validation, migration logic (migrateDeprecatedSettings) to transition legacy V1 flat settings to V2 hierarchical paths, and a secure deep merge utility (customDeepMerge) with prototype pollution protection. Additionally, it updates configuration loading, environment variable resolution, and workspace trust checks to align with the new schema, accompanied by comprehensive unit and integration tests. There are no review comments, and I have no feedback to provide.
Summary
This change updates the configuration loader in
packages/a2a-server(
src/config/settings.tsandsrc/config/config.ts) to support thehierarchical V2 configuration schema while preserving transparent in-memory
backward compatibility with flat V1 settings files.
From an architectural perspective, this unifies the configuration processing
pipeline between
@google/gemini-cliand@google/gemini-cli-a2a-serverbyintroducing in-memory key normalization (
migrateDeprecatedSettings), recursivemulti-scope object merging (
customDeepMerge), recursive environment variableinterpolation (
resolveEnvVarsInObject), and deterministic schema validation(
validateSettings/settingsZodSchema).Details
(
migrateDeprecatedSettings):MIGRATION_MAP) and invertedboolean flags (such as
telemetryDisabledtelemetry.enabled,logLevellogging.level,coreToolstools.core,excludeToolstools.exclude,allowedToolstools.allowed,folderTrustsecurity.folderTrust.enabled,showMemoryUsageui.showMemoryUsage,checkpointinggeneral.checkpointing,and
fileFilteringcontext.fileFiltering) into theircorresponding V2 nested structure in memory without modifying user
configuration files on disk.
Settingsobject and updated
loadConfig/setIsTrustedinpackages/a2a-server/src/config/config.tsto read canonical V2 paths withfallback support.
customDeepMerge):(
{ ...userSettings, ...workspaceSettings }) withcustomDeepMergesoworkspace-scoped nested settings merge cleanly with user-scoped nested
settings without discarding sibling properties.
__proto__,constructor,prototype) during recursive merging and environment resolution to ensuredeterministic object construction.
resolveEnvVarsInObject):resolveEnvVarsInStringandresolveEnvVarsInObjectto support$VAR,${VAR}, and${VAR:-default}syntax across nested V2 objects andarrays with
WeakSetcircular-reference tracking.validateSettings/settingsZodSchema):settingsZodSchema) for V2 configurationsections and validated normalized settings during configuration loading.
packages/a2a-server/src/config/settings.test.ts,packages/a2a-server/src/config/config.test.ts, andpackages/a2a-server/src/http/app.test.tsverifying V1-to-V2 in-memoryconversion and Zod schema validation, V2 structure preservation and deep
merging across scopes, reserved key filtering in
customDeepMerge, nestedenvironment variable interpolation, and V1/V2 settings handling in
loadConfig,setIsTrusted, andcreateApp.Related Issues
fixes: GH-28261
How to Validate
```bash
npm test -w @google/gemini-cli-a2a-server -- src/config/settings.test.ts src/config/config.test.ts src/http/app.test.ts
• Expected result: All 3 test files (63/63 tests) pass, verifying:$VAR, $ {VAR}, and
• src/config/settings.test.ts (12/12 tests):
• 100% legacy V1 flat settings (telemetryDisabled, logLevel, coreTools, excludeTools, allowedTools, folderTrust,
showMemoryUsage, checkpointing, fileFiltering) are migrated in memory to V2 nested properties (telemetry.enabled,
logging.level, tools.*, security.folderTrust.enabled, ui.showMemoryUsage, general.checkpointing, context.fileFiltering)
without modifying settings.json on disk, and pass Zod V2 schema validation (validateSettings).
• 100% V2 nested settings preserve their structure and deep-merge across User and Workspace scopes via customDeepMerge
without overwriting sibling properties.
• Edge cases: customDeepMerge and resolveEnvVarsInObject filter out proto, constructor, and prototype keys
(prototype pollution protection), handle circular references via WeakSet, and recursively interpolate
${VAR:-default} across nested objects and arrays.
• src/config/config.test.ts (30/30 tests):
• loadConfig() and setIsTrusted() read canonical V2 settings (security.folderTrust.enabled, general.checkpointing.
enabled, ui.showMemoryUsage, context.fileFiltering, logging.level) while maintaining fallback support for unmigrated V1
objects and preserving environment variable overrides (GEMINI_FOLDER_TRUST, CHECKPOINTING, CUSTOM_IGNORE_FILE_PATHS,
GEMINI_CLI_TRUST_WORKSPACE).
• src/http/app.test.ts (21/21 tests):
• createApp() reads V2 security.folderTrust.enabled from loadSettings() during initial HTTP server startup.
2. Run the full @google/gemini-cli-a2a-server package test suite and repository preflight:
npm test -w @google/gemini-cli-a2a-server
npm run preflight
Pre-Merge Checklist