Skip to content

feat(core): isolate sub-agent activeExtensionName via AsyncLocalStorage#25396

Closed
mahimashanware wants to merge 5 commits intogoogle-gemini:feature/plan-mode-custom-dirs-phase-3from
mahimashanware:feature/plan-mode-custom-dirs-phase-4
Closed

feat(core): isolate sub-agent activeExtensionName via AsyncLocalStorage#25396
mahimashanware wants to merge 5 commits intogoogle-gemini:feature/plan-mode-custom-dirs-phase-3from
mahimashanware:feature/plan-mode-custom-dirs-phase-4

Conversation

@mahimashanware
Copy link
Copy Markdown
Contributor

Summary

Phase 4 of the dynamic extension plan directory resolution implementation. This PR introduces the concept of an activeExtensionName throughout the Config and AgentLoopContext and implements robust AsyncLocalStorage isolation for sub-agents.

Details

  • Global Context Propagation: Modifies Config to track activeExtensionName alongside WorkspaceContext.
  • Sub-agent Isolation: Integrates the "Lazy-Loading" design's requirement for strict scoping. Uses AsyncLocalStorage in scoped-config.ts to implement runWithScopedActiveExtension. This ensures that any context switches triggered by a sub-agent (e.g., executing a command that activates an extension context) remain isolated and do not leak back and pollute the global main session.
  • Tools Context Update: Context routing passed to tools respects this scoping to safely map tool invocations to the proper plan directory.

Related Issues

Depends on Phase 3 (PR #25384).

How to Validate

Run unit tests for scoped config execution:

npm test -w @google/gemini-cli-core -- src/config/scoped-config.test.ts src/agents/local-executor.test.ts

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • Linux
      • npm run

@mahimashanware mahimashanware requested review from a team as code owners April 14, 2026 16:01
@github-actions
Copy link
Copy Markdown

🛑 Action Required: Evaluation Approval

Steering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged.

Maintainers:

  1. Go to the Workflow Run Summary.
  2. Click the yellow 'Review deployments' button.
  3. Select the 'eval-gate' environment and click 'Approve'.

Once approved, the evaluation results will be posted here automatically.

@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 significantly enhances the dynamic extension plan directory resolution by introducing a mechanism to isolate the activeExtensionName for sub-agents. This ensures that operations performed within a sub-agent's context, particularly those involving extension-specific configurations like plan directories, do not inadvertently alter or interfere with the main agent's context. The changes provide a more robust and predictable environment for agent execution, especially when dealing with multiple extensions or nested agent calls.

Highlights

  • Sub-agent Context Isolation: Implemented robust AsyncLocalStorage isolation for sub-agents to prevent activeExtensionName context leaks. This ensures that extension activations triggered by a sub-agent remain scoped and do not affect the global session.
  • Active Extension Tracking: Modified the Config and AgentLoopContext to track the activeExtensionName, which is crucial for dynamic extension plan directory resolution.
  • Scoped Plan Directory Resolution: Updated various tools and prompt providers (PromptProvider, EditToolInvocation, ExitPlanModeTool, ToolRegistry, WriteFileToolInvocation) to respect the activeExtensionName when resolving plan directories, allowing for custom plan directories per active extension.
  • New Scoping Utilities: Introduced runWithScopedActiveExtension and getActiveExtensionOverride in scoped-config.ts to manage and retrieve the isolated activeExtensionName.
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.

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.

@mahimashanware mahimashanware marked this pull request as draft April 14, 2026 16:07
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 introduces scoped isolation for the active extension name using AsyncLocalStorage, ensuring that sub-agents do not leak context. It updates the Config class and various tools, including Edit, WriteFile, and ExitPlanMode, to retrieve extension-specific settings such as the plans directory. A review comment correctly identifies code duplication in exit-plan-mode.ts regarding the resolution of the plans directory, suggesting a refactor for better consistency.

Comment on lines +132 to +142
private getResolvedPlansDir(): string {
let customDir: string | undefined;
const activeExt = this.config.activeExtensionName;
if (activeExt) {
customDir = this.config.getExtensionSetting<string>(
activeExt,
'plan.directory',
);
}
return this.config.storage.getPlansDir(customDir);
}
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

This getResolvedPlansDir method is a duplicate of the one in the ExitPlanModeTool class (lines 56-66). To ensure consistent path resolution, use a single, robust function (like resolveToRealPath) for all related path validations across components. Consider refactoring to remove this duplication, for instance by resolving the plans directory once in ExitPlanModeTool and passing it to the ExitPlanModeInvocation constructor.

References
  1. Ensure consistent path resolution by using a single, robust function (e.g., resolveToRealPath) for all related path validations, including internal validations in components like WorkspaceContext.

@mahimashanware mahimashanware force-pushed the feature/plan-mode-custom-dirs-phase-3 branch from ece2b0c to 0bb1927 Compare April 15, 2026 05:15
@gemini-cli gemini-cli Bot added the area/extensions Issues related to Gemini CLI extensions capability label Apr 15, 2026
@mahimashanware mahimashanware force-pushed the feature/plan-mode-custom-dirs-phase-3 branch from 0bb1927 to aad3e4b Compare April 15, 2026 20:32
@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli Bot commented Apr 29, 2026

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we have updated our contribution policy (see Discussion #17383).

We only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. All other community pull requests are subject to closure after 14 days if they do not align with our current focus areas. For this reason, we strongly recommend that contributors only submit pull requests against issues explicitly labeled as 'help-wanted'.

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding and for being part of our community!

@gemini-cli gemini-cli Bot closed this Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/extensions Issues related to Gemini CLI extensions capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant