Skip to content

fix(core): ensure AgentLoopContext getters are preserved in updatePolicy#22175

Closed
aishaneeshah wants to merge 1 commit into
mainfrom
publish-bug
Closed

fix(core): ensure AgentLoopContext getters are preserved in updatePolicy#22175
aishaneeshah wants to merge 1 commit into
mainfrom
publish-bug

Conversation

@aishaneeshah

@aishaneeshah aishaneeshah commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes a regression where selecting "Always Allow" on a tool confirmation would cause a crash with "Cannot read properties of undefined (reading 'publish')".

Details

The bug was in packages/core/src/scheduler/policy.ts. The code was using the spread operator { ...context } on an object implementing AgentLoopContext (typically a Config instance). In JavaScript, the spread operator only copies own enumerable properties and does not copy prototype getters. Since messageBus and config are defined as getters on the class prototype, they were missing from the resulting deps object, leading to undefined access.

Fix:

  • Explicitly map config and messageBus from the context instead of using the spread operator.

Related Issues

Closes #21982

How to Validate

  1. Run any tool that requires confirmation (e.g., shell).
  2. Select "Always allow" or "Always allow and save".
  3. Verify that the policy update succeeds without a crash.
  4. Run policy tests: npm test -w @google/gemini-cli-core -- src/scheduler/policy.test.ts.

@aishaneeshah aishaneeshah requested a review from a team as a code owner March 12, 2026 15:33
@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 resolves a critical regression that prevented subagents from properly functioning with policy-protected tools due to incorrect inheritance of messageBus and toolRegistry properties. The fix ensures that these essential communication and registry components are correctly threaded through the subagent configuration, restoring stability and enabling subagents to execute their tasks as intended. It also adds a robust check to prevent similar issues in the future.

Highlights

  • Regression Fix: Addressed a regression where subagents crashed with 'Cannot read properties of undefined (reading 'publish')' when using policy-protected tools like shell.
  • Property Inheritance: Ensured messageBus and toolRegistry are correctly inherited by subagent configurations by explicitly defining them using Object.defineProperty.
  • Defensive Programming: Implemented a defensive guard in LocalAgentExecutor.create to verify the presence of messageBus in the context, preventing future undefined errors.
Changelog
  • packages/core/src/agents/agent-scheduler.ts
    • Explicitly defined the messageBus property on the subagent configuration using Object.defineProperty to ensure proper inheritance.
    • Updated the comment to reflect that both messageBus and toolRegistry properties are now explicitly overridden.
  • packages/core/src/agents/local-executor.ts
    • Added a defensive check in LocalAgentExecutor.create to throw an error if messageBus is missing from the context, ensuring its availability for agent execution.
Activity
  • No human activity has been recorded on this pull request yet.
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.

@github-actions

github-actions Bot commented Mar 12, 2026

Copy link
Copy Markdown

Size Change: +55 B (0%)

Total Size: 26.1 MB

Filename Size Change
./bundle/chunk-HD26CB2N.js 0 B -13.4 MB (removed) 🏆
./bundle/chunk-Z6SWWESI.js 0 B -3.62 MB (removed) 🏆
./bundle/core-ZHRT2KF2.js 0 B -40.1 kB (removed) 🏆
./bundle/devtoolsService-TZVSZVZU.js 0 B -27.7 kB (removed) 🏆
./bundle/interactiveCli-2NOF4NCU.js 0 B -1.59 MB (removed) 🏆
./bundle/oauth2-provider-YDXJJYEV.js 0 B -9.19 kB (removed) 🏆
./bundle/chunk-5W5KWHTH.js 3.62 MB +3.62 MB (new file) 🆕
./bundle/chunk-TTGR562R.js 13.4 MB +13.4 MB (new file) 🆕
./bundle/core-44YTFVKK.js 40.1 kB +40.1 kB (new file) 🆕
./bundle/devtoolsService-JW3MK6JD.js 27.7 kB +27.7 kB (new file) 🆕
./bundle/interactiveCli-UO5HFS2G.js 1.59 MB +1.59 MB (new file) 🆕
./bundle/oauth2-provider-KZCM6VZP.js 9.19 kB +9.19 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
./bundle/chunk-34MYV7JD.js 2.45 kB 0 B
./bundle/chunk-37ZTTFQF.js 966 kB 0 B
./bundle/chunk-5AUYMPVF.js 858 B 0 B
./bundle/chunk-664ZODQF.js 124 kB 0 B
./bundle/chunk-DAHVX5MI.js 206 kB 0 B
./bundle/chunk-FXR7IA3Q.js 1.95 MB 0 B
./bundle/chunk-IUUIT4SU.js 56.5 kB 0 B
./bundle/chunk-RJTRUG2J.js 39.8 kB 0 B
./bundle/devtools-36NN55EP.js 696 kB 0 B
./bundle/dist-T73EYRDX.js 356 B 0 B
./bundle/gemini.js 689 kB 0 B
./bundle/getMachineId-bsd-TXG52NKR.js 1.55 kB 0 B
./bundle/getMachineId-darwin-7OE4DDZ6.js 1.55 kB 0 B
./bundle/getMachineId-linux-SHIFKOOX.js 1.34 kB 0 B
./bundle/getMachineId-unsupported-5U5DOEYY.js 1.06 kB 0 B
./bundle/getMachineId-win-6KLLGOI4.js 1.72 kB 0 B
./bundle/keychain-token-storage-LF5BRABV.js 0 B -518 B (removed) 🏆
./bundle/memoryDiscovery-URXPIMBI.js 922 B 0 B
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B
./bundle/src-QVCVGIUX.js 47 kB 0 B
./bundle/tree-sitter-7U6MW5PS.js 274 kB 0 B
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB 0 B
./bundle/undici-4X2YZID5.js 360 B 0 B
./bundle/keychain-token-storage-DE6DMTTU.js 518 B +518 B (new file) 🆕

compressed-size-action

@gemini-cli gemini-cli Bot added area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Mar 12, 2026

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

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.

Code Review

This pull request correctly addresses a regression that caused subagents to crash when using policy-protected tools. The fix in agent-scheduler.ts properly threads the messageBus to the subagent configuration by using Object.defineProperty, which aligns with the existing pattern for toolRegistry. Additionally, the new guard clause in local-executor.ts provides a robust defensive check to ensure the messageBus is present, improving the overall stability of agent creation. The changes are sound and effectively resolve the issue.

@aishaneeshah aishaneeshah changed the title fix(core): ensure messageBus is correctly threaded in subagents fix(core): ensure AgentLoopContext getters are preserved in updatePolicy Mar 13, 2026
@yclian

yclian commented Mar 15, 2026

Copy link
Copy Markdown

Thanks for the fix @aishaneeshah - verified working at my end locally.

auto-merge was automatically disabled March 16, 2026 17:59

Pull request was closed

@aishaneeshah aishaneeshah deleted the publish-bug branch March 17, 2026 14:17
@sripasg sripasg added the size/xs An extra small PR label Jun 2, 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. size/xs An extra small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: run_shell_command fails with 'Cannot read properties of undefined (reading \'publish\')'

4 participants