Skip to content

Read Windows app version from PackageInfo.fromPlatform instead of dart-define - #2149

Open
boyan01 wants to merge 4 commits into
mainfrom
fix/windows-package-info
Open

boyan01 wants to merge 4 commits into
mainfrom
fix/windows-package-info

Conversation

@boyan01

@boyan01 boyan01 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

 getPackageInfo()
-  if (Platform.isWindows) return _packageInfo (from --dart-define / hardcoded fallback)
-  try PackageInfo.fromPlatform() catch -> _packageInfo
+  info = await PackageInfo.fromPlatform()
+  if (info.version.trim().isEmpty) throw StateError(...)
+  return info

 generateUserAgent()
-  try ... catch -> return null
+  try ... catch -> rethrow

 startMessageProcessIsolate()
   BackgroundIsolateBinaryMessenger.ensureInitialized(rootIsolateToken)
+  ui.DartPluginRegistrant.ensureInitialized()
  • Remove the legacy Windows bypass and APP_VERSION / APP_BUILD_NUMBER --dart-define plumbing in lib/utils/system/package_info.dart, CI workflows, and dist/test_update_macos.sh. Windows builds already embed pubspec.yaml (and --build-name / --build-number) into Runner.rc's VS_VERSION_INFO, which package_info_plus reads via Win32 FFI.
  • Fail fast instead of falling back to a hardcoded/empty version or null User-Agent so requests are aborted locally rather than risking IP blocks from an outdated UA.
  • Register Dart-only plugins in message_worker_isolate.dart via ui.DartPluginRegistrant.ensureInitialized() so package_info_plus works on Windows/Linux worker isolates.
  • Add integration_test/package_info_test.dart covering both main and worker isolates.

Evidence

  • Before: Local Windows builds without --dart-define always reported the hardcoded fallback (7.0.1+0), and package_info_test.dart's Isolate.run test logged Bad state: BackgroundIsolateBinaryMessenger and fell back to the hardcoded version.
  • After:
    • flutter analyze on all touched Dart files: No issues found!
    • flutter test test/utils/package_info_test.dart: 15/15 All tests passed!
    • Remote Windows 11 integration test (flutter test integration_test/package_info_test.dart -d windows, no --dart-define): PASS
      • Main isolate: appName=mixin, packageName=mixin_desktop, version=7.1.1, buildNumber=632
      • Worker isolate: appName=mixin, packageName=mixin_desktop, version=7.1.1, buildNumber=632

Merge Danger

Door: two-way

Blast Radius: medium

If PackageInfo.fromPlatform() ever fails or returns an empty version on any platform/isolate, generateUserAgent() now throws instead of falling back to a hardcoded version or null, intentionally blocking network requests rather than sending an invalid/outdated User-Agent.

@gaotic

gaotic Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

AI review done for 0a0e0df in 21m 05s · 3 comments

Quality: The change addresses the original permanent rejected-future and partially initialized worker issues, and the focused tests pass. The remaining startup and cache interactions create medium-risk account and recovery failures that need fixes before merge.

Role Model Status
Reviewer GPT codex/gpt-6.2-sol · effort high ok
Summary codex/gpt-6.2-sol · effort medium ok

@gaotic gaotic 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.

AI review · GPT + Grok · dad6b9d

Request changes. Focused tests passed with +23 tests, but code inspection confirms that a transient package-info failure is cached permanently, can leave the message worker partially initialized, and traps mobile phone login on its loading state. No desktop integration test was run in this checkout.

Comment thread lib/utils/system/package_info.dart Resolved
Comment thread lib/workers/message_worker_isolate.dart Resolved
Comment thread lib/utils/system/package_info.dart Resolved
@boyan01
boyan01 requested a review from YeungKC November 26, 2026 08:36

@gaotic gaotic 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.

AI review · GPT · 0a0e0df

Request changes. Focused package-info and API-client tests passed with 17 tests. Code inspection verified the package_info_plus cache behavior and traced the account sign-out and dead-worker retry paths.

} catch (error, stack) {
e('generate user agent failed. $error $stack');
return null;
rethrow;

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.

When package metadata is unavailable during checkSignalKeys(), the request fails locally while building the User-Agent. AccountServer.initServer() treats that non-API error as a startup failure and calls signOutAndClear(), which can then retry /logout after _getUserAgent() has reset its failed future. A transient metadata failure can therefore revoke a valid session and clear its local keys. Keep metadata initialization failures from entering the sign-out path, or distinguish this local prerequisite failure before revoking the session.

} catch (error, stacktrace) {
e('message worker isolate init failed: $error, stacktrace: $stacktrace');
await runner.dispose();
Isolate.exit();

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.

This exits the worker after an initialization failure, but AccountServer retains the existing _isolateChannel and only publishes ConnectedState.disconnected when the isolate exits. A later Retry calls reconnectBlaze(), which sends reconnectBlaze to that dead channel and never starts a new worker, so message processing remains offline after package info recovers. Clear the dead channel and respawn the worker on exit, or make the retry path restart the worker.

return await PackageInfo.fromPlatform();
} catch (error, stack) {
e('get package info failed. $error $stack');
final info = await PackageInfo.fromPlatform();

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.

PackageInfo.fromPlatform() caches the PackageInfo object before this validation runs. If the plugin returns an empty version once, that invalid object remains in its static _fromPlatform cache, so the login Retry and later calls receive the same empty version without querying the platform again. Read the platform data through a path that validates it before caching, or otherwise invalidate and retry the package-info cache when the version is empty.

This branch has not been deployed

No deployments
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.

1 participant