Skip to content

[flutter_tools] Add structured extension.log notifications for tool extensions - #196714

Merged
auto-submit[bot] merged 6 commits into
flutter:masterfrom
bkonyi:ft-ext-log-notifications
Nov 25, 2026
Merged

auto-submit[bot] merged 6 commits into
flutter:masterfrom
bkonyi:ft-ext-log-notifications

Conversation

@bkonyi

@bkonyi bkonyi commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Adds structured extension.log JSON-RPC notifications from tool extension isolates to the host Logger:

  • Add ExtensionLogLevel and ExtensionLogMessage in package:flutter_tools_core (lib/src/log.dart).
  • Add ToolExtensionService.log and reserve ToolExtensionEntryPoint.logNotificationMethod ('extension.log') in package:flutter_tools_extension.
  • Route extension.log notifications in ExtensionConnection to the host Logger (printStatus, printWarning, printError, printTrace), warn on malformed payloads, and reject onNotification('extension.log') with ArgumentError.

Part of #190755
Part of #190746

…xtensions

Adds structured logging notifications from tool extension isolates to the host Logger:

- Add `ExtensionLogLevel` and `ExtensionLogMessage` in `package:flutter_tools_core` (`lib/src/log.dart`).

- Add `ToolExtensionService.log` and reserve `ToolExtensionEntryPoint.logNotificationMethod` (`'extension.log'`) in `package:flutter_tools_extension`.

- Route `extension.log` notifications in `ExtensionConnection` to the host `Logger` (`printStatus`, `printWarning`, `printError`, `printTrace`), warn on malformed payloads, and reject `onNotification('extension.log')` with `ArgumentError`.

Part of flutter#190755
Part of flutter#190746
@bkonyi bkonyi added the CICD Run CI/CD label Nov 16, 2026
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Nov 16, 2026
@bkonyi
bkonyi marked this pull request as ready for review November 16, 2026 22:28

@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 a structured logging mechanism for tool extensions, allowing them to send log notifications over the JSON-RPC channel. It adds an ExtensionLogMessage class for serialization, updates ExtensionConnection to route these logs to the host logger, and includes comprehensive tests for the new functionality. A review comment was provided regarding potential timezone-sensitivity issues in the DateTime equality check within ExtensionLogMessage.

chingjun
chingjun previously approved these changes Nov 17, 2026
Aligns `extension.log` handling with the tool extension specification:

- Mark `ToolExtensionService.log` as `@nonVirtual` and default `timestamp` to the current UTC time when omitted (normalizing explicit timestamps to UTC).

- Strip ANSI SGR escape sequences from `extension.log` messages in `ExtensionConnection` when `!logger.supportsColor`, and append `AnsiTerminal.resetAll` when ANSI CSI sequences are present on color-enabled terminals so unclosed styles do not bleed into subsequent CLI lines.

Part of flutter#190755
Part of flutter#190746
@bkonyi bkonyi added the t: extensions Issues related to Flutter Tools extensions label Nov 18, 2026
Reorders `ExtensionLogLevel` values by ascending severity (`trace`, `info`, `warning`, `error`) and updates `ExtensionLogMessage.operator ==` and `hashCode` to compare `timestamp?.microsecondsSinceEpoch` so local `DateTime` values compare equal after UTC round-tripping through `toMap()` and `fromJson()`.

Part of flutter#190755
Part of flutter#190746
Moves `extension.log` JSON-RPC notification handling out of `ExtensionConnection._spawnAndHandshake` into `ExtensionConnection._handleLogNotification` to simplify handshake setup.

Part of flutter#190755
Part of flutter#190746
@@ -74,7 +77,9 @@ class ToolExtensionEntryPoint {
final Map<String, ExtensionRpcHandler> handlers = await service.initialize();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude bubbled up that an extension that attempts to log in a ToolExtensionService.initialize will throw a StateError because the ToolExtensionService.notificationSender hasn't been set yet (initialize() happens on line 77, notificationSender is registered on line 106).

Would it be possible to register the notificationSender before initialize is called?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do do this, Claude also bubbled up that a log sent during initialize would have the [unknown_extension] prefix if it sent before the capabilities handshake completes. This is a bit of a chicken or egg problem... We might need to buffer logs until the handshake completes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. We can't connect the IsolateChannel before initialize() without leaking a ReceivePort if startup throws, so ToolExtensionEntryPoint now queues notifications emitted during initialize() until the peer connects and ExtensionConnection buffers pre-handshake logs until getCapabilities resolves the extension name.

message = message.replaceAll(_ansiSgrPattern, '');
} else if (message.contains(_ansiCsiPrefix)) {
message = '$message${AnsiTerminal.resetAll}';
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude bubbled up some feedback here as well:

  • When colour is off, only SGR (colour) codes are stripped. Other control sequences still pass through: cursor/erase codes like \x1B[2K or \x1B[1A, OSC (title/hyperlink) codes, and bare \r. An extension could use these to overwrite or garble the host's output, including the spinner and status lines.
  • When colour is on, the appended resetAll only resets colour, not those other sequences.
  • Suggestion: strip all CSI/OSC sequences and C0 control characters except \n/\t, and keep only SGR when supportsColor is true. Extensions are trusted code, so this is about robustness rather than security.

Claude seems to have switched to Canadian English just for you :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, we're stripping non-SGR CSI/OSC sequences and C0/C1 control characters (other than \n and \t) across the board now and only keeping SGR sequences with a trailing reset when supportsColor is true. Also I'm pretty sure "Canadian English" is just called "English" 😉

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I'm pretty sure "Canadian English" is just called "English" 😉

My mistake. To avoid any confusion I'll call "American English" just "American" >:)

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good to me! Claude caught some corner cases that we should consider before merging.

Queues notifications emitted during `ToolExtensionService.initialize()` in `ToolExtensionEntryPoint` until the JSON-RPC channel connects, and buffers incoming `extension.log` notifications in `ExtensionConnection` until `extension.getCapabilities` resolves `extensionName` so startup logs use the extension's name prefix rather than `[unknown_extension]`.

Also strips non-SGR CSI sequences, OSC sequences, 2-byte ESC sequences, and C0/C1 control characters except `\t` and `\n` from `extension.log` messages, retaining SGR sequences (with a trailing `AnsiTerminal.resetAll`) only when `logger.supportsColor` is `true`.

Part of flutter#190755
Part of flutter#190746
@bkonyi
bkonyi requested a review from loic-sharma November 24, 2026 19:23
return '$sanitized${AnsiTerminal.resetAll}';
}
return sanitized;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability, maybe consider moving this to some other file since it's not strictly related to extension discovery. Not a blocker for this PR though.

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 25, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 25, 2026
Merged via the queue into flutter:master with commit 3479eea Nov 25, 2026
21 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 25, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 25, 2026
Roll Flutter from b75c5b30406a to 06f1c24345a2 (37 revisions)

flutter/flutter@b75c5b3...06f1c24

2026-11-25 [email protected] Roll Skia from a60d883b3fe3 to e84ecd98d9f2 (2 revisions) (flutter/flutter#197375)
2026-11-25 [email protected] Roll Skia from ca229e319550 to a60d883b3fe3 (4 revisions) (flutter/flutter#197371)
2026-11-25 [email protected] Roll Skia from 6f75212e5a23 to ca229e319550 (2 revisions) (flutter/flutter#197369)
2026-11-25 [email protected] Roll Skia from 75d95595f14e to 6f75212e5a23 (1 revision) (flutter/flutter#197364)
2026-11-25 [email protected] [Windows] Fix Korean 3-beolsik IME dropping space, digits and punctuation (flutter/flutter#194270)
2026-11-25 [email protected] [flutter_tools] Strip embedded credentials from repository URLs (flutter/flutter#197219)
2026-11-25 [email protected] [flutter_tools] Add structured extension.log notifications for tool extensions (flutter/flutter#196714)
2026-11-25 [email protected] [flutter_tools] Share Depfile in flutter_tools_core and make BuildTarget.targetPlatform optional (flutter/flutter#194965)
2026-11-25 [email protected] Reply null asynchronously to ignored web platform messages and unskip missing-asset tests (flutter/flutter#197267)
2026-11-25 [email protected] Roll Dart SDK from 87f515c52de9 to 5202130a51b8 (1 revision) (flutter/flutter#197363)
2026-11-25 [email protected] [web] Retain queued scene pictures via ContainerLayer render pinning (flutter/flutter#196748)
2026-11-25 [email protected] [flutter_tools] Include dependency manifests in copyAssets depfile (flutter/flutter#196596)
2026-11-25 [email protected] Print the Intel Mac deprecation warning on every command (flutter/flutter#194071)
2026-11-25 [email protected] Roll Skia from 243c0dc9f662 to 75d95595f14e (2 revisions) (flutter/flutter#197351)
2026-11-25 [email protected] iOS: Ignore platform messages after the engine is destroyed (flutter/flutter#197310)
2026-11-24 [email protected] Bump customer tests to pick up material_ui cache extent test updates (flutter/flutter#197266)
2026-11-24 [email protected] [flutter_tools] Use refreshed FlutterVersion for flutter doctor feature flags (flutter/flutter#196944)
2026-11-24 [email protected] [flutter_tools] Do not crash if buildXcodeProject temporary directory is deleted before cleanup (flutter/flutter#195918)
2026-11-24 [email protected] Fix some `parameter_assignments` warnings (flutter/flutter#196815)
2026-11-24 [email protected] [flutter_tools] Extract PlatformDebuggingOptions and move WebDebugConfig (flutter/flutter#197229)
2026-11-24 [email protected] Fix desktop apps installing to the system prefix after a failed build (flutter/flutter#196482)
2026-11-24 [email protected] [flutter_tools] Write flutter test native_assets.json outside targetDir (flutter/flutter#196300)
2026-11-24 [email protected] iOS: Check the presented composition order in platform view tests (flutter/flutter#197302)
2026-11-24 [email protected] Run the shared Vulkan embedder tests under Impeller as well as Skia (flutter/flutter#193004)
2026-11-24 [email protected] Roll Fuchsia Linux SDK from BOgXtIYxLYcCkRou2... to HtAKfFLbfAQ6g96RY... (flutter/flutter#197334)
2026-11-24 [email protected] Roll Skia from b3dec9325fe1 to 243c0dc9f662 (6 revisions) (flutter/flutter#197333)
2026-11-24 [email protected] [flutter_tools] Delete globals.dart and context_runner.dart (flutter/flutter#196095)
2026-11-24 [email protected] Update viewInsets docs for translucent and rounded system UI (flutter/flutter#196355)
2026-11-24 [email protected] [flutter_tools] Check that dartaotruntime can run before starting the frontend server (flutter/flutter#194206)
2026-11-24 [email protected] [framework] Fix DraggableScrollableSheet '_hold == null' assertion when touch lifts during snap (flutter/flutter#195771)
2026-11-24 [email protected] [web] Release ImageSource on GC and fix Picture finalizer cycles (flutter/flutter#197245)
2026-11-24 [email protected] [flutter_tools] Fix web compiler output tracking in web builds (flutter/flutter#196563)
2026-11-24 [email protected] Upgrade CI to Xcode 27.2 (flutter/flutter#196807)
2026-11-24 [email protected] Roll Packages from 5b93485 to f455dfa (6 revisions) (flutter/flutter#197316)
2026-11-24 [email protected] [Linux] Fix deadlock presenting to a Wayland subsurface (flutter/flutter#196945)
2026-11-24 [email protected] Roll Skia from 2140958ee284 to b3dec9325fe1 (1 revision) (flutter/flutter#197309)
2026-11-24 [email protected] Roll Fuchsia Test Scripts from oEU515sDqSTvD8Spx... to GPtykFNizlaauBqzs... (flutter/flutter#197313)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD t: extensions Issues related to Flutter Tools extensions tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants