Skip to content

FIX: Treat Flutter SDK packages as known for Dart in PackageHallucinationScorer - #4019

Merged
Roman Lutz (romanlutz) merged 2 commits into
microsoft:mainfrom
bIackr0se:fix/dart-flutter-sdk-packages
Nov 9, 2026
Merged

Roman Lutz (romanlutz) merged 2 commits into
microsoft:mainfrom
bIackr0se:fix/dart-flutter-sdk-packages

Conversation

@bIackr0se

Copy link
Copy Markdown
Contributor

Description

PackageHallucinationScorer with PackageEcosystem.DART reported the Flutter SDK's own packages as hallucinated. The PackageHallucination scenario injects the pub.dev registry (garak-llm/dart-20250811, 67,348 names) as known_packages, and that snapshot does not contain flutter, flutter_test or flutter_localizations. Those packages are not installed from pub.dev: a project declares them with sdk: flutter in pubspec.yaml, and pub resolves them inside the Flutter SDK. So an answer that imports package:flutter, as 51 of the 60 real Flutter files below do (import 'package:flutter/material.dart';, for example), scored True even when it was correct, and the scenario's dart technique counted it as a successful attack.

This PR adds the Flutter SDK packages to the known set in __init__, as the scorer already does for the Python standard library, the Rust std entries and the Raku core modules. The names are the two directories pub searches for an sdk: flutter package (packagePath in pub's flutter.dart), at Flutter stable (c197ca5):

  • the nine packages in packages/: flutter, flutter_driver, flutter_goldens, flutter_localizations, flutter_test, flutter_tools, flutter_web_plugins, fuchsia_remote_debug_protocol, integration_test;
  • the two packages flutter_tools installs in bin/cache/pkg (getPackageDirs in flutter_cache.dart): sky_engine, flutter_gpu.

Membership stays exact, so flutter_ghost next to package:flutter is still reported. The other ecosystems are unchanged. Because the known set feeds known_package_count and known_packages_digest, the identifier of a Dart scorer changes, as it did for Raku.

Real run with the registry the scenario loads (through _GarakDartDataset), via score_async on assistant messages:

input                                                  main                          this PR
`flutter create` lib/main.dart template                True  (flutter)               False
`flutter create` test/widget_test.dart template        True  (flutter, flutter_test) False
60 files: 58 from flutter/samples + the 2 templates    59 True                       21 True

On the 60 files, the patch removes only flutter, flutter_test and flutter_localizations from the reports and adds no name. The 21 files still flagged reference package names absent from the registry snapshot, including compass_app and menubar; those remaining reports are unchanged.

The flutter create widget test returned by a stub target to PromptSendingAttack with this scorer as its objective scorer, as the scenario wires it: SUCCESS on main ("Hallucinated dart packages: flutter, flutter_test"), FAILURE with this change.

Tests and Documentation

  • New tests in tests/unit/score/test_package_hallucination_scorer.py:
    • a fenced Dart answer that imports flutter, flutter_test, flutter_localizations, flutter_driver, flutter_web_plugins, integration_test or flutter_gpu next to a known package scores False with no hallucinated packages;
    • package:flutter next to package:flutter_ghost still scores True, reporting only flutter_ghost.
  • On main all 8 new tests fail; with this change they pass.
  • pytest tests/unit/score tests/unit/scenario: 8122 passed.
  • pre-commit run on the changed files passes (ruff format, ruff check, ty, the notebook and docs hooks).
  • doc/code/scoring/1_true_false_scorers.py and its .ipynb said only the Python standard library is added automatically; the sentence now names the Flutter SDK packages for Dart as well.

Copilot AI balanced review requested due to automatic review settings November 6, 2026 21:47

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@romanlutz Roman Lutz (romanlutz) self-assigned this Nov 8, 2026
@romanlutz
Roman Lutz (romanlutz) merged commit 367d7f4 into microsoft:main Nov 9, 2026
61 of 63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants