Skip to content

fix(core): fail fast in MessageBus.request() on publish failure#26225

Closed
Adib234 wants to merge 3 commits into
mainfrom
adibakm/message-bus
Closed

fix(core): fail fast in MessageBus.request() on publish failure#26225
Adib234 wants to merge 3 commits into
mainfrom
adibakm/message-bus

Conversation

@Adib234

@Adib234 Adib234 commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a bug where MessageBus.request() would silently hang for 60 seconds if publish() failed. It also fixes a potential process crash caused by unhandled rejections from floating publish() calls, and addresses security concerns regarding sensitive data in logs.

Details

  • Fail fast in request(): Added a .catch() block to the publish() call inside MessageBus.request() to immediately reject the request and clean up listeners/timeouts if publication fails.
  • Rethrow in publish(): Modified MessageBus.publish() to re-throw errors after emitting them on the 'error' event, ensuring callers get explicit failures.
  • Security Sanitization: Integrated sanitizeToolArgs into MessageBus.publish() to redact sensitive information (passwords, tokens, etc.) from debug logs and error messages, preventing accidental secret leakage.
  • Resilient Floating Promises: Refactored all floating publish() calls to use a type-safe pattern (instanceof Promise) that gracefully handles test mocks returning undefined or throwing synchronously, while still providing robust error handling in production.
  • Test Alignment & Coverage: Updated unit tests to expect rejections on invalid input and added 6 new test cases to verify fail-fast behavior, sanitization, and pattern resiliency.

Related Issues

Fixes #22588

How to Validate

Run unit tests for the core package:

npm test -w @google/gemini-cli-core -- src/confirmation-bus/message-bus.test.ts

Verify that all 22 tests pass. Also run other affected tests:

npm test -w @google/gemini-cli-core -- src/scheduler/policy.test.ts src/tools/message-bus-integration.test.ts src/tools/web-fetch.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:
    • MacOS
      • npm run

Link: #22588

Modified MessageBus.publish to re-throw errors and MessageBus.request to catch them, preventing 60s silent hangs. Also updated floating publish calls to prevent unhandled promise rejections.
@Adib234 Adib234 requested review from a team as code owners April 29, 2026 20:28
@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 critical issues related to error handling and promise management within the MessageBus and related components. The primary goal is to ensure that MessageBus.request() fails quickly and predictably when a message publication fails, rather than silently hanging. Additionally, it prevents unhandled promise rejections from 'floating' publish() calls, enhancing the overall stability and reliability of the system's asynchronous operations.

Highlights

  • Fail Fast in MessageBus.request(): The MessageBus.request() method now immediately rejects and cleans up resources if the underlying publish() call fails, preventing silent hangs.
  • Rethrow Errors in MessageBus.publish(): The MessageBus.publish() method has been updated to re-throw errors after emitting them, allowing callers to handle publication failures explicitly.
  • Floating Promise Safety: All instances of 'floating' publish() calls across BaseTool, LocalSubagentInvocation, Scheduler, and StateManager have been updated with .catch() handlers or try/catch blocks to prevent unhandled promise rejections and potential process crashes.
  • Updated Unit Tests: Unit tests for the message-bus have been aligned to expect rejections on invalid input and policy failures, ensuring robust error handling.
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.

@github-actions

github-actions Bot commented Apr 29, 2026

Copy link
Copy Markdown

Size Change: +845 B (0%)

Total Size: 33.9 MB

Filename Size Change
./bundle/chunk-2YAG37N7.js 0 B -656 kB (removed) 🏆
./bundle/chunk-74GSIUYA.js 0 B -49.2 kB (removed) 🏆
./bundle/chunk-B4WRUYZZ.js 0 B -14.7 MB (removed) 🏆
./bundle/chunk-EPZ54RCA.js 0 B -19.5 kB (removed) 🏆
./bundle/chunk-LCU42UHC.js 0 B -2.72 MB (removed) 🏆
./bundle/chunk-OQX7GVID.js 0 B -1.97 MB (removed) 🏆
./bundle/chunk-OYLICXPA.js 0 B -3.43 kB (removed) 🏆
./bundle/chunk-XTDTL2VG.js 0 B -3.8 kB (removed) 🏆
./bundle/chunk-YETKNMPG.js 0 B -12.6 kB (removed) 🏆
./bundle/core-QYQFBWRP.js 0 B -48.2 kB (removed) 🏆
./bundle/devtoolsService-SCLA2AHO.js 0 B -28 kB (removed) 🏆
./bundle/gemini-3KCABWKS.js 0 B -580 kB (removed) 🏆
./bundle/interactiveCli-XDVGQ5HC.js 0 B -1.32 MB (removed) 🏆
./bundle/liteRtServerManager-Q7BKZ2VR.js 0 B -2.11 kB (removed) 🏆
./bundle/oauth2-provider-U6IVUAKC.js 0 B -9.16 kB (removed) 🏆
./bundle/chunk-3A4P62QN.js 3.43 kB +3.43 kB (new file) 🆕
./bundle/chunk-3FDU2P7T.js 3.8 kB +3.8 kB (new file) 🆕
./bundle/chunk-DLIYW67L.js 656 kB +656 kB (new file) 🆕
./bundle/chunk-E2E5DHUS.js 19.5 kB +19.5 kB (new file) 🆕
./bundle/chunk-FDMWIVNT.js 14.7 MB +14.7 MB (new file) 🆕
./bundle/chunk-LWSNROLO.js 1.97 MB +1.97 MB (new file) 🆕
./bundle/chunk-SBIW5OE6.js 2.72 MB +2.72 MB (new file) 🆕
./bundle/chunk-T3NTVJGU.js 49.2 kB +49.2 kB (new file) 🆕
./bundle/chunk-VYOUL7KS.js 12.6 kB +12.6 kB (new file) 🆕
./bundle/core-47O6NTW2.js 48.2 kB +48.2 kB (new file) 🆕
./bundle/devtoolsService-7QCURTZI.js 28 kB +28 kB (new file) 🆕
./bundle/gemini-LNV5GCF3.js 580 kB +580 kB (new file) 🆕
./bundle/interactiveCli-VUJFQO3O.js 1.32 MB +1.32 MB (new file) 🆕
./bundle/liteRtServerManager-RYC6QPH6.js 2.11 kB +2.11 kB (new file) 🆕
./bundle/oauth2-provider-HH36YVNN.js 9.16 kB +9.16 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
./bundle/bundled/third_party/index.js 8 MB 0 B
./bundle/chunk-34MYV7JD.js 2.45 kB 0 B
./bundle/chunk-5AUYMPVF.js 858 B 0 B
./bundle/chunk-5PS3AYFU.js 1.18 kB 0 B
./bundle/chunk-664ZODQF.js 124 kB 0 B
./bundle/chunk-DAHVX5MI.js 206 kB 0 B
./bundle/chunk-IUUIT4SU.js 56.5 kB 0 B
./bundle/chunk-RJTRUG2J.js 39.8 kB 0 B
./bundle/cleanup-PWRGWHJA.js 0 B -932 B (removed) 🏆
./bundle/devtools-36NN55EP.js 696 kB 0 B
./bundle/dist-T73EYRDX.js 356 B 0 B
./bundle/events-XB7DADIJ.js 418 B 0 B
./bundle/examples/hooks/scripts/on-start.js 188 B 0 B
./bundle/examples/mcp-server/example.js 1.43 kB 0 B
./bundle/gemini.js 5.14 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/memoryDiscovery-QEUOLE5X.js 0 B -980 B (removed) 🏆
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 222 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 229 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 13.4 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/start-BW27KJ5N.js 0 B -652 B (removed) 🏆
./bundle/tree-sitter-7U6MW5PS.js 274 kB 0 B
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB 0 B
./bundle/cleanup-AAC6SWT5.js 932 B +932 B (new file) 🆕
./bundle/memoryDiscovery-53OPMSUP.js 980 B +980 B (new file) 🆕
./bundle/start-RBMJGCQB.js 652 B +652 B (new file) 🆕

compressed-size-action

@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 improves error handling within the MessageBus by ensuring that the publish method re-throws errors, allowing callers to handle them explicitly. Changes include adding .catch() blocks to fire-and-forget calls and updating tests to expect rejected promises. A security concern was raised regarding the potential leakage of sensitive tool arguments in error messages, suggesting that these messages should be sanitized before being thrown to prevent data exposure in logs or telemetry.

Comment thread packages/core/src/confirmation-bus/message-bus.ts
@gemini-cli gemini-cli Bot added area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Apr 29, 2026
Bojun-Vvibe added a commit to Bojun-Vvibe/oss-contributions that referenced this pull request Apr 29, 2026
- google-gemini/gemini-cli#26225: MessageBus.publish now throws after emit('error'), MessageBus.request awaits and rejects on publish failure to fix latent hang where invalid/policy-denied requests would set up a response listener that never resolved (merge-after-nits)
- QwenLM/qwen-code#3749: AlreadyReportedError marker + handleError/JsonAdapter short-circuit + parseAndFormatApiError idempotency net to stop double-wrap '[API Error: [API Error: ...]]' and duplicate stderr emission in non-interactive mode (merge-as-is)
- INDEX.md: append drip-188 section (8 entries, 4 merge-as-is + 4 merge-after-nits, 5/6 repo coverage with goose skipped)
- Added sanitization to MessageBus.publish() logs and error messages using sanitizeToolArgs to prevent secret leakage.

- Refactored floating publish() calls to use a type-safe resiliency pattern (instanceof Promise) to handle test mocks and sync throws.

Fixes CI failures and addresses security review feedback.
@github-actions

Copy link
Copy Markdown

66 tests passed successfully on gemini-3-flash-preview.

🧠 Model Steering Guidance

This PR modifies files that affect the model's behavior (prompts, tools, or instructions).

  • ⚠️ Consider adding Evals: No behavioral evaluations (evals/*.eval.ts) were added or updated in this PR. Consider adding a test case to verify the new behavior and prevent regressions.
  • 🚀 Maintainer Reminder: Please ensure that these changes do not regress results on benchmark evals before merging.

This is an automated guidance message triggered by steering logic signatures.

@cocosheng-g cocosheng-g 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.

please add more unit test coverage for the changes

- Added test case to verify request() rejects immediately upon publication failure.

- Added test cases to verify redaction of sensitive data in debug logs and error messages.

- Added test cases for pattern resiliency to handle non-promise returns and sync throws.
@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.

Bojun-Vvibe added a commit to Bojun-Vvibe/oss-contributions that referenced this pull request May 5, 2026
- google-gemini/gemini-cli#26225 MessageBus fail-fast — merge-after-nits
- QwenLM/qwen-code#3627 macOS desktop installer — merge-after-nits
- aaif-goose/goose#9014 unread state for background chats — merge-after-nits
- charmbracelet/crush#2520 Ctrl+D quit prompt — merge-as-is
@gemini-cli gemini-cli Bot added the priority/p2 Important but can be addressed in a future release. label May 9, 2026
@Adib234 Adib234 closed this May 27, 2026
@sripasg sripasg added the size/l A large sized 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/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. priority/p2 Important but can be addressed in a future release. size/l A large sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(core): MessageBus.request() silently hangs 60s when publish() fails

3 participants