Skip to content

[flutter_tools] Add JSON-RPC notification support and post-handshake isolate exit handling to ExtensionConnection - #194961

Merged
auto-submit[bot] merged 5 commits into
flutter:masterfrom
bkonyi:ft-ext-protocol-notifications-cancellation
Oct 22, 2026
Merged

auto-submit[bot] merged 5 commits into
flutter:masterfrom
bkonyi:ft-ext-protocol-notifications-cancellation

Conversation

@bkonyi

@bkonyi bkonyi commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Adds extension-to-host JSON-RPC notification support (ToolExtensionService.sendNotification and ExtensionConnection.onNotification, first consumed by device log streaming in #194964) and keeps onError/onExit ports open after the handshake so unexpected isolate exits or unhandled errors immediately fail pending sendRequest(..., timeout: null) calls and close notification streams instead of hanging forever.

Part of #190755
Part of #190746

…n support to tool extension protocol

Adds bidirectional JSON-RPC 2.0 notification support (, , and ), sliding inactivity timeout monitoring with progress/heartbeat resets (), and cooperative request cancellation ( and ).

Updates  to use  instead of an unbounded .

Part of flutter#190755

Part of flutter#190746

Fixes flutter#193955
… and post-handshake isolate exit handling

Simplifies the extension protocol changes to focus on bidirectional JSON-RPC 2.0 notification support and resilient post-handshake isolate exit and error handling, removing request cancellation and heartbeat APIs.

Part of flutter#190755
Part of flutter#190746
@bkonyi bkonyi changed the title [flutter_tools] Add notification, progress heartbeat, and cancellation support to tool extension protocol [flutter_tools] Add JSON-RPC notification support and post-handshake isolate exit handling to ExtensionConnection Oct 21, 2026
…nd isolate exit handling

- Log unhandled extension isolate errors using logger.printError instead of trace so failure reasons are visible at default verbosity.
- Close receive port, error port, exit port, and notification controllers on unexpected isolate exit.
- Validate onNotification payload type and warn on malformed payloads rather than falling back to an empty map.
- Strengthen unit test assertions on StateError messages and verify notification streams emit done on unexpected isolate exit.

Part of flutter#190755
Part of flutter#190746
Fixes flutter#193955
…t listeners

- Switch _errorPort and _exitPort from RawReceivePort to ReceivePort.
- Add _handleIsolateError and _handleIsolateExit helper methods with documentation explaining unhandled error list payloads and unexpected exit handling.
- Wire stream listeners in ExtensionConnection.spawn before isolate spawning and dispatch to active connection once created.

Part of flutter#190755
Part of flutter#190746
@bkonyi
bkonyi marked this pull request as ready for review October 22, 2026 15:25

@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 introduces support for JSON-RPC 2.0 notifications between the host tool and tool extension isolates, and improves robustness by handling unexpected isolate exits and uncaught async errors. Specifically, it adds notification sending and receiving capabilities to ToolExtensionService and ExtensionConnection, and manages isolate error and exit ports to prevent hangs. Feedback suggests refactoring _handleIsolateExit to call dispose() directly to avoid duplicating cleanup logic and ensure _isDisposed is correctly set to true, preventing potential memory leaks.

…e controller cleanup

- Delegate unexpected isolate exit handling in _handleIsolateExit to dispose() to centralize resource teardown.
- Inline _closeNotificationControllers directly into dispose() as it is the single cleanup path.

Part of flutter#190755
Part of flutter#190746
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
…isolate exit handling to ExtensionConnection (flutter#194961)

Adds extension-to-host JSON-RPC notification support
(`ToolExtensionService.sendNotification` and
`ExtensionConnection.onNotification`, first consumed by device log
streaming in flutter#194964) and keeps
`onError`/`onExit` ports open after the handshake so unexpected isolate
exits or unhandled errors immediately fail pending `sendRequest(...,
timeout: null)` calls and close notification streams instead of hanging
forever.

Part of flutter#190755
Part of flutter#190746
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants