The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(desktop): prevent native accessibility tree crashes (#620)
Dee56d71adf501b
diff --git a/desktop/lib/core/connected_semantics.dart b/desktop/lib/core/connected_semantics.dartnew file mode 100644index 000000000..b7688357e--- /dev/null+++ b/desktop/lib/core/connected_semantics.dart@@ -0,0 +1,276 @@+import 'dart:ui' as ui;++import 'package:flutter/foundation.dart';+import 'package:flutter/rendering.dart';+import 'package:flutter/widgets.dart';++import '../logging/app_log.dart';++/// Flutter 3.47 can serialize dirty semantics nodes from hidden subtrees, even+/// though they are not reachable from the view's semantics root. The desktop+/// AX bridge rejects that update after partially changing its tree; a later+/// reparent then dereferences a null parent and terminates the process.+///+/// Filter at Flutter's public builder seam, before the native update is made.+/// Derive connectivity from the current framework tree. Keep immutable copies+/// of node updates while their paint nodes exist: a clean hidden portal may+/// reconnect without Flutter serializing it again. Replay its latest data when+/// it reconnects, and discard snapshots when nodes leave the framework tree.+/// https://github.com/flutter/flutter/issues/193410+mixin ConnectedSemanticsBinding on RendererBinding {+ bool _reportedDisconnectedSemantics = false;+ final _updates = <int, _NodeUpdate>{};+ final _previousConnected = <int>{};++ @protected+ ui.SemanticsUpdateBuilder createPlatformSemanticsUpdateBuilder() =>+ super.createSemanticsUpdateBuilder();++ @override+ ui.SemanticsUpdateBuilder createSemanticsUpdateBuilder() {+ final delegate = createPlatformSemanticsUpdateBuilder();+ if (kIsWeb ||+ (defaultTargetPlatform != TargetPlatform.macOS &&+ defaultTargetPlatform != TargetPlatform.windows)) {+ return delegate;+ }+ final connected = <int>{};+ final attached = <int>{};+ for (final view in renderViews) {+ final root = view.owner?.semanticsOwner?.rootSemanticsNode;+ if (root == null) continue;+ // OverlayPortal has different paint and accessibility parents. In the+ // failing Slider/IndexedStack case the hidden portal's child is still+ // in paint order, but its traversal parent is no longer in the tree.+ final portals = <Object, List<SemanticsNode>>{};+ void collect(SemanticsNode node) {+ attached.add(node.id);+ final identifier = node.traversalChildIdentifier;+ if (node.traversalParentIdentifier == null && identifier != null) {+ portals.putIfAbsent(identifier, () => []).add(node);+ }+ node.visitChildren((child) {+ collect(child);+ return true;+ });+ }++ collect(root);+ final visited = <SemanticsNode>{};+ void visit(SemanticsNode node) {+ if (!visited.add(node)) return;+ connected.add(node.id);+ if (!node.mergeAllDescendantsIntoThisNode) {+ node.visitChildren((child) {+ if (child.traversalChildIdentifier == null ||+ node.traversalParentIdentifier != null) {+ visit(child);+ }+ return true;+ });+ }+ for (final child+ in portals[node.traversalParentIdentifier] ??+ const <SemanticsNode>[]) {+ if (child.attached) visit(child);+ }+ }++ visit(root);+ }+ _updates.removeWhere((id, _) => !attached.contains(id));+ return _ConnectedSemanticsUpdateBuilder(+ delegate,+ connected: connected,+ updates: _updates,+ previousConnected: _previousConnected,+ onDiscard: (id) {+ if (_reportedDisconnectedSemantics) return;+ _reportedDisconnectedSemantics = true;+ appLog.warn(+ 'accessibility',+ 'Filtered disconnected semantics node $id before the native update',+ );+ },+ );+ }+}++/// Used by the production entry point; native/widget fixtures mix the same+/// protection into their test binding so they exercise the real boundary.+class HarnessWidgetsBinding extends WidgetsFlutterBinding+ with ConnectedSemanticsBinding {}++typedef _NodeUpdate = void Function(ui.SemanticsUpdateBuilder, Set<int>);++class _ConnectedSemanticsUpdateBuilder implements ui.SemanticsUpdateBuilder {+ _ConnectedSemanticsUpdateBuilder(+ this._delegate, {+ required this.connected,+ required this.updates,+ required this.previousConnected,+ this.onDiscard,+ });++ final Map<int, _NodeUpdate> updates;+ final Set<int> previousConnected;+ final _changed = <int>{};+ final ui.SemanticsUpdateBuilder _delegate;+ final Set<int> connected;+ final void Function(int id)? onDiscard;++ // Root 0 can never be another node's child. Leave traversal/hit-test order+ // otherwise intact: OverlayPortal legitimately uses different lists.+ static Int32List _children(Int32List ids, Set<int> connected) {+ if (ids.every((id) => id != 0 && connected.contains(id))) return ids;+ return Int32List.fromList(+ ids.where((id) => id != 0 && connected.contains(id)).toList(),+ );+ }++ @override+ void updateNode({+ required int id,+ required ui.SemanticsFlags flags,+ required int actions,+ required int maxValueLength,+ required int currentValueLength,+ required int textSelectionBase,+ required int textSelectionExtent,+ required int platformViewId,+ required int scrollChildren,+ required int scrollIndex,+ required int traversalParent,+ required double scrollPosition,+ required double scrollExtentMax,+ required double scrollExtentMin,+ required ui.Rect rect,+ required String identifier,+ required String label,+ required List<ui.StringAttribute> labelAttributes,+ required String value,+ required List<ui.StringAttribute> valueAttributes,+ required String increasedValue,+ required List<ui.StringAttribute> increasedValueAttributes,+ required String decreasedValue,+ required List<ui.StringAttribute> decreasedValueAttributes,+ required String hint,+ required List<ui.StringAttribute> hintAttributes,+ required String tooltip,+ required ui.TextDirection? textDirection,+ required Float64List transform,+ required Float64List hitTestTransform,+ required Int32List childrenInTraversalOrder,+ required Int32List childrenInHitTestOrder,+ required Int32List additionalActions,+ int headingLevel = 0,+ String linkUrl = '',+ ui.SemanticsRole role = ui.SemanticsRole.none,+ required List<String>? controlsNodes,+ ui.SemanticsValidationResult validationResult =+ ui.SemanticsValidationResult.none,+ ui.SemanticsHitTestBehavior hitTestBehavior =+ ui.SemanticsHitTestBehavior.defer,+ required ui.SemanticsInputType inputType,+ required ui.Locale? locale,+ required String minValue,+ required String maxValue,+ }) {+ if (!connected.contains(id)) onDiscard?.call(id);+ // Framework matrices and typed arrays can be reused and mutated after this+ // batch. Own the data that may be replayed when a hidden node reconnects.+ transform = Float64List.fromList(transform);+ hitTestTransform = Float64List.fromList(hitTestTransform);+ childrenInTraversalOrder = Int32List.fromList(childrenInTraversalOrder);+ childrenInHitTestOrder = Int32List.fromList(childrenInHitTestOrder);+ additionalActions = Int32List.fromList(additionalActions);+ labelAttributes = List.of(labelAttributes);+ valueAttributes = List.of(valueAttributes);+ increasedValueAttributes = List.of(increasedValueAttributes);+ decreasedValueAttributes = List.of(decreasedValueAttributes);+ hintAttributes = List.of(hintAttributes);+ controlsNodes = controlsNodes == null ? null : List.of(controlsNodes);+ _changed.add(id);+ updates[id] = (delegate, currentConnected) => delegate.updateNode(+ id: id,+ flags: flags,+ actions: actions,+ maxValueLength: maxValueLength,+ currentValueLength: currentValueLength,+ textSelectionBase: textSelectionBase,+ textSelectionExtent: textSelectionExtent,+ platformViewId: platformViewId,+ scrollChildren: scrollChildren,+ scrollIndex: scrollIndex,+ traversalParent: traversalParent,+ scrollPosition: scrollPosition,+ scrollExtentMax: scrollExtentMax,+ scrollExtentMin: scrollExtentMin,+ rect: rect,+ identifier: identifier,+ label: label,+ labelAttributes: labelAttributes,+ value: value,+ valueAttributes: valueAttributes,+ increasedValue: increasedValue,+ increasedValueAttributes: increasedValueAttributes,+ decreasedValue: decreasedValue,+ decreasedValueAttributes: decreasedValueAttributes,+ hint: hint,+ hintAttributes: hintAttributes,+ tooltip: tooltip,+ textDirection: textDirection,+ transform: transform,+ hitTestTransform: hitTestTransform,+ childrenInTraversalOrder: _children(+ childrenInTraversalOrder,+ currentConnected,+ ),+ childrenInHitTestOrder: _children(+ childrenInHitTestOrder,+ currentConnected,+ ),+ additionalActions: additionalActions,+ headingLevel: headingLevel,+ linkUrl: linkUrl,+ role: role,+ controlsNodes: controlsNodes,+ validationResult: validationResult,+ hitTestBehavior: hitTestBehavior,+ inputType: inputType,+ locale: locale,+ minValue: minValue,+ maxValue: maxValue,+ );+ }++ @override+ void updateCustomAction({+ required int id,+ String? label,+ String? hint,+ int overrideId = -1,+ }) => _delegate.updateCustomAction(+ id: id,+ label: label,+ hint: hint,+ overrideId: overrideId,+ );++ @override+ ui.SemanticsUpdate build() {+ // Native AX deletes unreachable nodes. A newly reachable node needs its+ // snapshot even when Flutter considers it clean and omits it from this batch.+ final pending = <int>{+ ..._changed,+ ...connected.difference(previousConnected),+ };+ for (final id in pending) {+ if (connected.contains(id)) updates[id]?.call(_delegate, connected);+ }+ previousConnected+ ..clear()+ ..addAll(connected);+ return _delegate.build();+ }+}diff --git a/desktop/lib/main.dart b/desktop/lib/main.dartindex cdcea7f77..74ced9675 100644--- a/desktop/lib/main.dart+++ b/desktop/lib/main.dart@@ -1,4 +1,5 @@import 'app_shell.dart';+import 'core/connected_semantics.dart';import 'desktop_workspace.dart'if (dart.library.js_interop) 'web/web_entry.dart';@@ -9,5 +10,10 @@ import 'desktop_workspace.dart'/// its store bar, native builds never compile it./// `../mobile` mounts a phone shell into its own vendored copy of/// [startHarness] rather than depending on this package.-Future<void> main() =>- startHarness(authenticatedScreen: authenticatedWorkspace, frame: appFrame);+Future<void> main() {+ HarnessWidgetsBinding();+ return startHarness(+ authenticatedScreen: authenticatedWorkspace,+ frame: appFrame,+ );+}diff --git a/desktop/lib/main_local_manual.dart b/desktop/lib/main_local_manual.dartindex b2c08afd0..042fdeff6 100644--- a/desktop/lib/main_local_manual.dart+++ b/desktop/lib/main_local_manual.dart@@ -1,3 +1,5 @@+import 'core/connected_semantics.dart';+import 'package:flutter/material.dart';import 'package:flutter_riverpod/flutter_riverpod.dart';@@ -13,7 +15,7 @@ import 'state/app_state.dart';/// This entrypoint fails closed unless every value is supplied explicitly by/// `scripts/start-terminal-local-manual.sh`. It is not used by release builds.Future<void> main() async {- WidgetsFlutterBinding.ensureInitialized();+ HarnessWidgetsBinding();const enabled = bool.fromEnvironment('LOCAL_TERMINAL_MANUAL');const apiBaseUrl = String.fromEnvironment('LOCAL_MANUAL_API_BASE_URL');const apiKey = String.fromEnvironment('LOCAL_MANUAL_API_KEY');diff --git a/desktop/test/connected_semantics_test.dart b/desktop/test/connected_semantics_test.dartnew file mode 100644index 000000000..a8327f4db--- /dev/null+++ b/desktop/test/connected_semantics_test.dart@@ -0,0 +1,273 @@+import 'dart:ui' as ui;++import 'package:flutter/foundation.dart';+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness/core/connected_semantics.dart';++class _Binding extends AutomatedTestWidgetsFlutterBinding+ with ConnectedSemanticsBinding {+ bool guarded = true;+ final batches = <Map<int, Map<Symbol, dynamic>>>[];++ @override+ ui.SemanticsUpdateBuilder createPlatformSemanticsUpdateBuilder() =>+ _RecordingBuilder(batches);++ @override+ ui.SemanticsUpdateBuilder createSemanticsUpdateBuilder() => guarded+ ? super.createSemanticsUpdateBuilder()+ : createPlatformSemanticsUpdateBuilder();+}++class _RecordingBuilder implements ui.SemanticsUpdateBuilder {+ _RecordingBuilder(this.batches);+ final List<Map<int, Map<Symbol, dynamic>>> batches;+ final nodes = <int, Map<Symbol, dynamic>>{};+ final delegate = ui.SemanticsUpdateBuilder();++ @override+ dynamic noSuchMethod(Invocation call) {+ switch (call.memberName) {+ case #updateNode:+ nodes[call.namedArguments[#id] as int] = Map.of(call.namedArguments);+ return Function.apply(delegate.updateNode, [], call.namedArguments);+ case #updateCustomAction:+ return Function.apply(+ delegate.updateCustomAction,+ [],+ call.namedArguments,+ );+ case #build:+ batches.add(nodes);+ return delegate.build();+ }+ return super.noSuchMethod(call);+ }+}++// Model the native bridge's retained tree. Flutter's regular widget semantics+// assertions inspect the framework tree and miss extra nodes in the wire update.+List<int> _disconnectedUpdates(List<Map<int, Map<Symbol, dynamic>>> batches) {+ final tree = <int, List<int>>{};+ final disconnected = <int>[];+ for (final batch in batches) {+ for (final entry in batch.entries) {+ tree[entry.key] = List<int>.from(entry.value[#childrenInTraversalOrder]);+ }+ final connected = <int>{};+ void visit(int id) {+ expect(connected.add(id), isTrue, reason: 'Cycle or duplicate child $id');+ expect(tree.containsKey(id), isTrue, reason: 'Missing child $id');+ for (final child in tree[id]!) {+ visit(child);+ }+ }++ if (tree.containsKey(0)) visit(0);+ disconnected.addAll(batch.keys.where((id) => !connected.contains(id)));+ tree.removeWhere((id, _) => !connected.contains(id));+ }+ return disconnected;+}++Widget _sliders(int selected) => MaterialApp(+ home: Scaffold(+ body: IndexedStack(+ index: selected,+ children: [+ Center(+ child: Slider(+ value: .5,+ onChanged: (_) {},+ semanticFormatterCallback: (_) => 'First slider',+ ),+ ),+ Center(+ child: Slider(+ value: .5,+ onChanged: (_) {},+ semanticFormatterCallback: (_) => 'Second slider',+ ),+ ),+ ],+ ),+ ),+);++void axTest(String name, WidgetTesterCallback body) => testWidgets(+ name,+ body,+ variant: const TargetPlatformVariant({+ TargetPlatform.macOS,+ TargetPlatform.windows,+ }),+);++void main() {+ final binding = _Binding();+ setUp(() {+ binding.guarded = true;+ binding.batches.clear();+ });+ tearDown(() {+ debugDefaultTargetPlatformOverride = null;+ });++ axTest('fixture exposes the unguarded hidden-slider update', (tester) async {+ binding.guarded = false;+ final semantics = tester.ensureSemantics();+ try {+ await tester.pumpWidget(_sliders(0));+ expect(_disconnectedUpdates(binding.batches), isNotEmpty);+ } finally {+ semantics.dispose();+ }+ });++ axTest(+ 'hidden sliders never reach the native tree when resizing or switching',+ (tester) async {+ final semantics = tester.ensureSemantics();+ try {+ for (var i = 0; i < 30; i++) {+ await tester.binding.setSurfaceSize(+ Size(800 + (i % 3) * 80, 600 + (i % 4) * 60),+ );+ await tester.pumpWidget(_sliders(i % 2));+ expect(_disconnectedUpdates(binding.batches), isEmpty);+ final visible = binding.batches.last.values.where(+ (node) =>+ node[#value] == (i.isEven ? 'First slider' : 'Second slider'),+ );+ expect(visible, hasLength(1));+ expect(+ visible.single[#actions] & ui.SemanticsAction.increase.index,+ isNonZero,+ );+ expect(+ visible.single[#actions] & ui.SemanticsAction.decrease.index,+ isNonZero,+ );+ }+ expect(tester.takeException(), isNull);+ } finally {+ semantics.dispose();+ await tester.binding.setSurfaceSize(null);+ }+ },+ );++ axTest('switching without resize restores clean portal nodes', (+ tester,+ ) async {+ final semantics = tester.ensureSemantics();+ try {+ for (var i = 0; i < 30; i++) {+ await tester.pumpWidget(_sliders(i % 2));+ await tester.pumpAndSettle();+ expect(_disconnectedUpdates(binding.batches), isEmpty);+ }+ } finally {+ semantics.dispose();+ }+ });++ axTest('dialogs and editable controls keep their labels and actions', (+ tester,+ ) async {+ final semantics = tester.ensureSemantics();+ final controller = TextEditingController(text: 'Draft');+ try {+ await tester.pumpWidget(+ MaterialApp(+ home: Builder(+ builder: (context) => Scaffold(+ body: Column(+ children: [+ TextField(+ controller: controller,+ decoration: const InputDecoration(labelText: 'Message'),+ ),+ TextButton(+ onPressed: () => showDialog<void>(+ context: context,+ builder: (context) => AlertDialog(+ title: const Text('Question'),+ actions: [+ TextButton(+ onPressed: () => Navigator.pop(context),+ child: const Text('Answer'),+ ),+ ],+ ),+ ),+ child: const Text('Ask'),+ ),+ ],+ ),+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ await tester.tap(find.byType(TextField));+ await tester.pumpAndSettle();+ final fields = binding.batches+ .expand((b) => b.values)+ .where((n) => n[#value] == 'Draft');+ expect(fields, isNotEmpty);+ expect(+ fields.any(+ (node) => node[#actions] & ui.SemanticsAction.setText.index != 0,+ ),+ isTrue,+ );+ for (var i = 0; i < 5; i++) {+ await tester.tap(find.text('Ask'));+ await tester.pumpAndSettle();+ expect(tester.getSemantics(find.text('Question')).label, 'Question');+ await tester.tap(find.text('Answer'));+ await tester.pumpAndSettle();+ }+ expect(_disconnectedUpdates(binding.batches), isEmpty);+ expect(find.text('Draft'), findsOneWidget);+ expect(tester.takeException(), isNull);+ } finally {+ semantics.dispose();+ await tester.pumpWidget(const SizedBox());+ controller.dispose();+ }+ });++ axTest('rebuilding semantics uses current IDs after disable and enable', (+ tester,+ ) async {+ for (var i = 0; i < 5; i++) {+ final semantics = tester.ensureSemantics();+ binding.batches.clear();+ try {+ await tester.pumpWidget(_sliders(i % 2));+ await tester.pump();+ expect(binding.batches, isNotEmpty);+ expect(_disconnectedUpdates(binding.batches), isEmpty);+ } finally {+ semantics.dispose();+ }+ await tester.pumpWidget(const SizedBox());+ }+ });++ testWidgets('unaffected platforms retain the standard builder', (+ tester,+ ) async {+ debugDefaultTargetPlatformOverride = TargetPlatform.linux;+ expect(binding.createSemanticsUpdateBuilder(), isA<_RecordingBuilder>());+ debugDefaultTargetPlatformOverride = TargetPlatform.windows;+ expect(+ binding.createSemanticsUpdateBuilder(),+ isNot(isA<_RecordingBuilder>()),+ );+ debugDefaultTargetPlatformOverride = null;+ });+}diff --git a/desktop/tool/accessibility_regression/host.swift b/desktop/tool/accessibility_regression/host.swiftnew file mode 100644index 000000000..591f197e9--- /dev/null+++ b/desktop/tool/accessibility_regression/host.swift@@ -0,0 +1,61 @@+// Appended only to the runner's disposable macOS host. Production uses no+// private Flutter selectors. This fixture toggles the engine's existing setter+// to reproduce the accessibility bridge recreation normally driven by macOS.+private enum AccessibilityRegression {+ static func install(window: NSWindow, controller: FlutterViewController) {+ let channel = FlutterMethodChannel(+ name: "harness/accessibility_regression", binaryMessenger: controller.engine.binaryMessenger)+ channel.setMethodCallHandler { [weak window, weak controller] call, result in+ guard let window = window, let controller = controller else {+ result(FlutterError(code: "missing_window", message: nil, details: nil))+ return+ }+ switch call.method {+ case "semantics":+ guard let enabled = call.arguments as? Bool,+ controller.engine.responds(to: NSSelectorFromString("setSemanticsEnabled:")) else {+ result(FlutterError(code: "unsupported_engine", message: nil, details: nil))+ return+ }+ controller.engine.setValue(enabled, forKey: "semanticsEnabled")+ result(nil)+ case "resize":+ let step = call.arguments as! Int+ window.setContentSize(NSSize(width: 700 + (step % 3) * 70, height: 500 + (step % 4) * 50))+ result(nil)+ case "activate":+ var seen = Set<ObjectIdentifier>()+ var sliders = [NSObject]()+ var buttons = [NSObject]()+ func visit(_ value: Any) {+ guard let node = value as? NSAccessibilityProtocol,+ let object = value as? NSObject else { return }+ guard seen.insert(ObjectIdentifier(node as AnyObject)).inserted else { return }+ if node.accessibilityRole() == .slider { sliders.append(object) }+ if node.accessibilityRole() == .button { buttons.append(object) }+ for child in node.accessibilityChildren() ?? [] { visit(child) }+ }+ visit(controller.view)+ guard sliders.count == 1 else {+ result(FlutterError(code: "slider_count", message: "Expected 1 visible slider, found \(sliders.count)", details: nil))+ return+ }+ // Flutter's AXPlatformNodeCocoa implements the legacy AppKit action+ // entry point; this is also what macOS accessibility clients invoke.+ guard buttons.count == 1 else {+ result(FlutterError(code: "button_count", message: "Expected 1 button, found \(buttons.count)", details: nil))+ return+ }+ let button = buttons[0]+ guard button.accessibilityActionNames().contains(.press) else {+ result(false)+ return+ }+ button.accessibilityPerformAction(.press)+ result(true)+ default:+ result(FlutterMethodNotImplemented)+ }+ }+ }+}diff --git a/desktop/tool/accessibility_regression/main.dart b/desktop/tool/accessibility_regression/main.dartnew file mode 100644index 000000000..cf97cd779--- /dev/null+++ b/desktop/tool/accessibility_regression/main.dart@@ -0,0 +1,100 @@+// Native release regression for flutter/flutter#193410. The runner builds this+// in a disposable app; it never loads Harness state or opens a transport.+import 'dart:async';+import 'dart:io';++import 'package:flutter/material.dart';+import 'package:flutter/services.dart';++import 'package:harness/core/connected_semantics.dart';++const _host = MethodChannel('harness/accessibility_regression');+final _selected = ValueNotifier<int>(0);+final _values = [ValueNotifier<double>(.5), ValueNotifier<double>(.5)];+int _actions = 0;++Widget _slider(int index) => Center(+ child: ValueListenableBuilder<double>(+ valueListenable: _values[index],+ builder: (_, value, _) => Slider(+ value: value,+ onChanged: (value) {+ _values[index].value = value;+ },+ ),+ ),+);++Future<void> _run() async {+ // The unguarded build is an explicit diagnostic mode, not a product setting.+ if (const bool.fromEnvironment('AX_REGRESSION_UNGUARDED')) {+ WidgetsFlutterBinding.ensureInitialized();+ } else {+ HarnessWidgetsBinding();+ }+ await _host.invokeMethod<void>('semantics', true);+ runApp(+ MaterialApp(+ home: Scaffold(+ body: Column(+ children: [+ Expanded(+ child: ValueListenableBuilder<int>(+ valueListenable: _selected,+ builder: (_, selected, _) => IndexedStack(+ index: selected,+ children: [_slider(0), _slider(1)],+ ),+ ),+ ),+ TextButton(+ onPressed: () => _actions++,+ child: const Text('Native action'),+ ),+ ],+ ),+ ),+ ),+ );+ await Future<void>.delayed(const Duration(milliseconds: 150));+ for (var step = 0; step < 160; step++) {+ if (step % 5 == 4) {+ await _host.invokeMethod<void>('semantics', false);+ await Future<void>.delayed(const Duration(milliseconds: 20));+ await _host.invokeMethod<void>('semantics', true);+ }+ _selected.value = step % 2;+ await _host.invokeMethod<void>('resize', step);+ await Future<void>.delayed(const Duration(milliseconds: 35));+ // A rejected stock-engine tree has no actionable controls. Let resizing+ // reach the native reparenting crash instead of stopping on that symptom.+ if (const bool.fromEnvironment('AX_REGRESSION_UNGUARDED')) continue;+ // The native fixture requires one visible slider, then presses a button+ // through AppKit and the real Flutter AX bridge. This engine advertises+ // slider increment but does not implement dispatching it; tap is supported.+ final before = _actions;+ final result = await _host.invokeMethod<bool>('activate');+ for (var attempt = 0; _actions == before && attempt < 100; attempt++) {+ await Future<void>.delayed(const Duration(milliseconds: 10));+ }+ if (result != true || _actions != before + 1) {+ throw StateError(+ 'Native button action failed at step $step: $result, $_actions vs $before',+ );+ }+ // Exercise value changes as well as view switching.+ _values[_selected.value].value = step.isEven ? .25 : .75;+ await Future<void>.delayed(const Duration(milliseconds: 15));+ }+ stdout.writeln(+ 'ACCESSIBILITY_REGRESSION_PASS cycles=160 native_actions=$_actions',+ );+ exit(0);+}++void main() {+ runZonedGuarded(() => unawaited(_run()), (Object error, StackTrace stack) {+ stderr.writeln('$error\n$stack');+ exit(1);+ });+}diff --git a/desktop/tool/accessibility_regression/run.py b/desktop/tool/accessibility_regression/run.pynew file mode 100644index 000000000..325b13b41--- /dev/null+++ b/desktop/tool/accessibility_regression/run.py@@ -0,0 +1,155 @@+#!/usr/bin/env python3+"""Build/run the native release accessibility regression in a disposable macOS app.++Usage: python3 tool/accessibility_regression/run.py --flutter /path/to/flutter+Add --unguarded to verify the known stock-engine crash instead of the fix.+No Harness state, installed app, SDK sources, or system accessibility settings+are changed. A JSON receipt and build/process logs remain in the printed folder.+"""+import argparse+from datetime import datetime, timezone+import hashlib+import json+import os+from pathlib import Path+import plistlib+import re+import shutil+import signal+import subprocess+import sys+import tempfile+import time+++def now():+ return datetime.now(timezone.utc).isoformat()+++def copy_sources(source, destination):+ """Copy the exact production guard and its relative imports, with hashes."""+ pending = [source / 'core/connected_semantics.dart']+ copied = {}+ while pending:+ path = pending.pop().resolve()+ relative = str(path.relative_to(source))+ if relative in copied:+ continue+ data = path.read_bytes()+ target = destination / relative+ target.parent.mkdir(parents=True, exist_ok=True)+ target.write_bytes(data)+ copied[relative] = hashlib.sha256(data).hexdigest()+ for directive in re.findall(r'(?:import|export)\s+[^;]+;', data.decode()):+ for uri in re.findall(r"'([^']+\.dart)'", directive):+ if not uri.startswith(('dart:', 'package:')):+ pending.append(path.parent / uri)+ return copied+++def run(command, cwd, log, deadline, env):+ started = time.monotonic()+ with log.open('w') as output:+ process = subprocess.Popen(command, cwd=cwd, env=env, stdout=output,+ stderr=subprocess.STDOUT, start_new_session=True)+ try:+ code = process.wait(timeout=deadline)+ except BaseException:+ os.killpg(process.pid, signal.SIGKILL)+ process.wait(timeout=5)+ raise+ return {'exit_code': code, 'seconds': round(time.monotonic() - started, 3),+ 'log': str(log)}+++def main():+ # Let an outer validation deadline unwind run() and kill only our child+ # process group, including any compiler descendants.+ signal.signal(signal.SIGTERM, lambda *_: sys.exit(143))+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument('--flutter', type=Path, required=True)+ parser.add_argument('--unguarded', action='store_true')+ args = parser.parse_args()+ if sys.platform != 'darwin':+ parser.error('This fixture requires macOS; no platform row is silently skipped.')+ if shutil.disk_usage(tempfile.gettempdir()).free < 2 * 1024**3:+ parser.error('At least 2 GiB of free disk is required.')+ fixture = Path(__file__).resolve().parent+ source = fixture.parents[1] / 'lib'+ root = Path(tempfile.mkdtemp(prefix='harness-accessibility-'))+ app = root / 'app'+ flutter = str(args.flutter.resolve() / 'bin/flutter')+ env = dict(os.environ, XDG_CONFIG_HOME=str(root / 'tool-config'), FLUTTER_TEST='1')+ receipt = {'started_at': now(), 'unguarded': args.unguarded, 'root': str(root),+ 'source_commit': subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=source, text=True).strip(),+ 'steps': [], 'status': 'running'}+ print(f'ACCESSIBILITY_ROOT={root}', flush=True)+ try:+ def checked(name, command, deadline=120):+ step = run(command, root if name == 'create' else app,+ root / f'{name}.log', deadline, env)+ receipt['steps'].append(dict(name=name, **step))+ if step['exit_code']:+ raise RuntimeError(f'{name} failed; see {step["log"]}')+ checked('create', [flutter, 'create', '--platforms=macos', '--no-pub',+ '--project-name=harness_ax_regression',+ '--org=ai.autonomous.accessibilityregression', str(app)])+ (app / 'pubspec.yaml').write_text('''name: harness+publish_to: none+environment:+ sdk: ^3.13.0+dependencies:+ flutter:+ sdk: flutter+ ffi: 2.2.0+ web: 1.1.1+flutter:+ uses-material-design: true+''')+ receipt['production_sources_sha256'] = copy_sources(source, app / 'lib')+ shutil.copyfile(fixture / 'main.dart', app / 'lib/main.dart')+ window = app / 'macos/Runner/MainFlutterWindow.swift'+ swift = window.read_text()+ marker = ' super.awakeFromNib()'+ if swift.count(marker) != 1:+ raise RuntimeError('Flutter macOS template insertion point changed')+ swift = swift.replace(marker, ' AccessibilityRegression.install(window: self, controller: flutterViewController)\n' + marker)+ window.write_text(swift + '\n' + (fixture / 'host.swift').read_text())+ checked('dependencies', [flutter, 'pub', 'get', '--offline'])+ command = [flutter, 'build', 'macos', '--release', '--no-pub']+ if args.unguarded:+ command += ['--dart-define=AX_REGRESSION_UNGUARDED=true']+ checked('build', command, 300)+ bundle = app / 'build/macos/Build/Products/Release/harness_ax_regression.app'+ info = plistlib.loads((bundle / 'Contents/Info.plist').read_bytes())+ if info['CFBundleIdentifier'] != 'ai.autonomous.accessibilityregression.harnessAxRegression':+ raise RuntimeError(f'Unexpected fixture bundle identity: {info["CFBundleIdentifier"]}')+ step = run([str(bundle / 'Contents/MacOS' / info['CFBundleExecutable'])],+ app, root / 'native.log', 40, env)+ receipt['steps'].append(dict(name='native', **step))+ output = (root / 'native.log').read_text()+ if args.unguarded:+ # The broken tree can fail while reparenting (SIGSEGV) or while+ # AppKit enumerates its missing children (SIGABRT).+ if step['exit_code'] not in (-signal.SIGSEGV, -signal.SIGABRT) or 'Failed to update ui::AXTree' not in output:+ raise RuntimeError('Expected stock-engine native accessibility crash was not reproduced')+ receipt['status'] = 'baseline_crash_reproduced'+ else:+ if step['exit_code'] != 0 or 'ACCESSIBILITY_REGRESSION_PASS cycles=160 native_actions=160' not in output:+ raise RuntimeError('Native regression did not complete; see native.log')+ if 'ERROR:flutter' in output or 'returned \'kInvalidArguments\'' in output:+ raise RuntimeError('Native bridge reported an error; see native.log')+ receipt['status'] = 'passed'+ print(receipt['status'], flush=True)+ except BaseException as error:+ receipt['status'] = 'failed'+ receipt['error'] = str(error)+ raise+ finally:+ receipt['finished_at'] = now()+ (root / 'receipt.json').write_text(json.dumps(receipt, indent=2) + '\n')+ print(f'ACCESSIBILITY_RECEIPT={root / "receipt.json"}', flush=True)+++if __name__ == '__main__':+ main()diff --git a/docs/performance/2026-10-02-accessibility-crash-validation.json b/docs/performance/2026-10-02-accessibility-crash-validation.jsonnew file mode 100644index 000000000..08455c142--- /dev/null+++ b/docs/performance/2026-10-02-accessibility-crash-validation.json@@ -0,0 +1,391 @@+{+ "sourceCommit": "bb86565ef55a870a9ac817ef60e3397a4bf4d8a8",+ "sourceTree": "037e381f6c9ec2a7851229fce5ce8587e5c0a56a",+ "baselineCommit": "f537725295864d8150d439289dc24cf4f870e226",+ "platform": {+ "macOS": "26.6.2",+ "architecture": "arm64"+ },+ "toolchain": {+ "frameworkVersion": "3.47.2",+ "channel": "[user-branch]",+ "repositoryUrl": "https://github.com/flutter/flutter.git",+ "frameworkRevision": "d3b14c876900e553bc736ca19295fc09e3853e8e",+ "frameworkCommitDate": "2026-08-26 16:07:51 -0700",+ "engineRevision": "a804b261645ef8c13eb3d5c44a5c2fb0340c5539",+ "engineCommitDate": "2026-08-26 18:46:13.000Z",+ "engineContentHash": "1cf1c4773fb941c4c74a7f8bb144a8837596c0f4",+ "engineBuildDate": "2026-08-26 15:23:07.677",+ "dartSdkVersion": "3.13.2",+ "devToolsVersion": "2.60.0",+ "flutterVersion": "3.47.2"+ },+ "pubspecLockSha256": "0987d3b363535b314a292bab02ff8ec5bc51691398f8ede9406b9885925c00b7",+ "rootCause": {+ "exception": "EXC_BAD_ACCESS / SIGSEGV, address 0x48",+ "stack": [+ "ui::AXNode::id() const",+ "flutter::AccessibilityBridge::CreateRemoveReparentedNodesUpdate()",+ "flutter::AccessibilityBridge::CommitUpdates()",+ "-[FlutterViewController updateSemantics:]"+ ],+ "description": "Disconnected dirty OverlayPortal nodes corrupt the native accessibility tree. A later reparent dereferences a null parent. Filtering also requires restoring clean nodes when they reconnect."+ },+ "focused": {+ "testsPassed": 11,+ "variants": [+ "macOS",+ "Windows"+ ],+ "changedDartAnalysis": "passed",+ "switchWithoutResizeRegression": "Failed on the first filtering-only implementation; passes with node snapshot replay."+ },+ "nativeMacos": {+ "command": "python3 tool/accessibility_regression/run.py --flutter /path/to/flutter",+ "fixed": {+ "status": "passed",+ "exitCode": 0,+ "runtimeSeconds": 11.355,+ "cycles": 160,+ "semanticsRestarts": 32,+ "nativeAppKitButtonActions": 160,+ "nativeBridgeErrors": 0+ },+ "stockEngine": {+ "argument": "--unguarded",+ "status": "baseline_crash_reproduced",+ "exitCode": -11,+ "runtimeSeconds": 1.301,+ "crashStackMatchesReportedCrash": true+ },+ "productionSourcesSha256": {+ "core/connected_semantics.dart": "1ce2e9c8a91954e06056ccf17e2354b3a8eca353b3429d2623641fe12a364fa9",+ "logging/app_log.dart": "00b91e3b4e8b429453773b4e558020b40ce78960999d391015900fb4ece9957e",+ "logging/log_file.dart": "f962f08e6ad3373109924fc87c861b23d62be0d3833e0f6e5d7ae2703b95f438",+ "logging/log_append.dart": "a10c8d50f136b62c4f95f0a2453a433436c2c8c443c67aed8f383dcdfd4f9ffa",+ "logging/log_append_native.dart": "cd205c906bca1ef59d3596a04e2fce0f51cbf83e6d3514658f3dcec73ce0e252",+ "logging/log_append_io.dart": "e6d6971b9e9ef3a6652dae1e0da1b6e5e469dcdad4b1cce85e99d989bca59ff8",+ "core/harness_file_store.dart": "53593c8d07ff664e960949bb6e989ca4172b898ae15c646d79f5c8d662c9094c",+ "core/harness_file_store_web.dart": "e45ee84f97a7115127a6427c53e12c69d249e362c3a8328dceb81e4e96c1ee49",+ "core/local_key_value_store.dart": "0037ead698dc89cd35f8435759bb7acb53e776cc84296516b81a6866019accc2",+ "core/browser_lock.dart": "844e3fff9e11c0b99448989c927f724b681e56a55375ff57e548c26254aabe6a",+ "core/harness_file_store_native.dart": "a1bab68fa395164ca63ed1de0fa05ad4a48dfc9784e0645120020c43fd43f3e9",+ "core/viewer_mode.dart": "f64230618a793e9a48b472fe6641963c6a000dae7949f80dadaeabe44e546d73",+ "core/runtime_platform.dart": "d3c5482dc8c5ad8b7388fd09a346e9d60eebdcd30d89ca6c43c10b81f7592e53",+ "core/host_platform.dart": "66618cf60dab1fee2ff4bd0cf6e292be616d54fa8bbbbcd537da32d85080f296",+ "logging/error_burst_filter.dart": "d41c50a11e8ddb7639114e7f6304c803a0a18fe5803b45c620bde0e20fa94a7a"+ }+ },+ "broadDesktop": {+ "passingTestCases": 5646,+ "skippedTestCases": 16,+ "reproducedBaselineAssertionFailures": 44,+ "assertionFailures": [+ {+ "file": "test/agent_pause_state_test.dart",+ "test": "a confirmed pause remains in inventory when its refresh fails",+ "result": "failure",+ "skipped": false+ },+ {+ "file": "test/boot_flow_widget_test.dart",+ "test": "offline unlinked remote with a pending agent opens machine recovery",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/machines_manager_test.dart",+ "test": "Search unifies categories and preserves management commands (native=false)",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/machines_manager_test.dart",+ "test": "Search unifies categories and preserves management commands (native=true)",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/share_toolbar_test.dart",+ "test": "Share defaults hidden and its saved Settings toggle updates the toolbar (native=false)",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/share_toolbar_test.dart",+ "test": "Share defaults hidden and its saved Settings toggle updates the toolbar (native=true)",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/box_flows_test.dart",+ "test": "dismissed edits resume and explicit agent/project choices become defaults",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/box_flows_test.dart",+ "test": "each source pane retains its own draft and launch defaults",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/daemon_workspace_test.dart",+ "test": "the pair brain an unavailable companion engine explains setup and retries in the same DSH",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/desktop_dialog_interaction_test.dart",+ "test": "composer closes on Escape and restores its draft on reopen",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/desktop_dialog_interaction_test.dart",+ "test": "composer closes on outside click and restores its draft on reopen",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/desktop_dialog_interaction_test.dart",+ "test": "Cmd-P and Cmd-N replace each other without losing the composer",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/desktop_dialog_interaction_test.dart",+ "test": "long mixed mouse and keyboard setup keeps the draft and dismisses one level",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/desktop_search_polish_test.dart",+ "test": "native scopes put machines first and keep typed words and focus",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/desktop_welcome_composer_test.dart",+ "test": "Cmd-P round trip restores the tab draft and chosen options",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/desktop_welcome_composer_test.dart",+ "test": "each new tab keeps its own draft after switching",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/desktop_welcome_composer_test.dart",+ "test": "page launches once into its own tab and blocks another start while pending",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/desktop_welcome_composer_test.dart",+ "test": "Escape from search restores the embedded draft",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/harness_placement_test.dart",+ "test": "setup with Work profile handles escape without starting",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/harness_placement_test.dart",+ "test": "setup with Default profile handles outside without starting",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/harness_placement_test.dart",+ "test": "new-tab creation keeps the task and pending receipt through picker shortcuts",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/harness_store_entry_test.dart",+ "test": "Store Open uses the dock with its harness and task",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/harness_store_entry_test.dart",+ "test": "Store Try uses the dock with its harness and task",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/harness_store_entry_test.dart",+ "test": "returning from Store restores the creation draft and selected project",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/new_harness_install_e2e_test.dart",+ "test": "pick with keys, install with narration, then create",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/new_harness_install_e2e_test.dart",+ "test": "a failed install explains itself; New Harness retries and creates",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/new_harness_install_e2e_test.dart",+ "test": "a dropped socket says the install may still be finishing",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/new_harness_install_e2e_test.dart",+ "test": "the pane fits a 960px window at 2.0x text",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/new_harness_install_e2e_test.dart",+ "test": "the pane fits a 520px window at 1.0x text",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/new_harness_install_pane_test.dart",+ "test": "the harness list with no history, Claude Code leads and every harness is listed",+ "result": "failure",+ "skipped": false+ },+ {+ "file": "test/new_harness_install_pane_test.dart",+ "test": "what the form opens on Code and Claude Code when nothing was used before",+ "result": "failure",+ "skipped": false+ },+ {+ "file": "test/new_harness_install_e2e_test.dart",+ "test": "the pane fits a 520px window at 2.0x text",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/new_harness_install_pane_test.dart",+ "test": "installing on the way to start outside dismissal cannot abandon a running installation",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/new_harness_install_pane_test.dart",+ "test": "installing on the way to start the right pane narrates the machine, step by step",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/new_harness_install_pane_test.dart",+ "test": "installing on the way to start a failed install stays on screen, with how to retry",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/pane_model_status_test.dart",+ "test": "an agent whose frame says neither keeps the header it had",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/swarm_split_test.dart",+ "test": "hovering the right edge splits with its project and keeps the terminal",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/swarm_split_test.dart",+ "test": "hovering the down edge splits with its project and keeps the terminal",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/swarm_split_test.dart",+ "test": "split creation dismissal restores terminal input immediately",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/terminal_panel_presentation_test.dart",+ "test": "retained header uses current callbacks, names, projects and status",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/terminal_panel_presentation_test.dart",+ "test": "narrow headers preserve identity and close control at large text",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/terminal_tail_lifecycle_test.dart",+ "test": "all delayed local panes start at bottom",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/terminal_tail_lifecycle_test.dart",+ "test": "all delayed remote panes start at bottom",+ "result": "error",+ "skipped": false+ },+ {+ "file": "test/workspace_start_guide_test.dart",+ "test": "a failed first start stays actionable and retries once",+ "result": "error",+ "skipped": false+ }+ ],+ "stalledTestCases": [+ "Settings switches the creature on and off without leaving Settings",+ "button and shortcut share only the focused agent and return terminal focus",+ "illustrated Tim lives in the footer and hover preserves focus",+ "empty and view-only panes keep an inactive Share button"+ ],+ "incompleteFiles": [+ "test/daemon_off_test.dart",+ "test/share_toolbar_test.dart"+ ],+ "browserOnlyFiles": "Nine test/web files were not executed on the VM platform. Web behavior is unchanged by the platform-gated guard.",+ "status": "Not a passing full suite. All observed assertion failures reproduce on unchanged main; four stalled cases reproduce in bounded baseline checks.",+ "unvisitedFilesAndLoaderRetries": {+ "testsPassed": 112,+ "status": "passed"+ },+ "candidateOnlyAssertionFailures": []+ },+ "evidenceReuse": {+ "initialBroadRunParent": "30d2381b4",+ "finalParent": "f537725295864d8150d439289dc24cf4f870e226",+ "desktopChangesBetweenParents": [+ "desktop/scripts/upload-desktop-linux.sh",+ "desktop/scripts/upload-desktop.sh"+ ],+ "sameFlutterSdkAndDependencyLock": true,+ "affectedTestsAndNativeCheckRerunAfterReconnectionFix": true+ },+ "unverified": [+ "Native Windows execution",+ "Intel macOS native execution"+ ],+ "timing": {+ "requestReceived": "2026-10-02T13:57:03Z",+ "initialValidationStarted": "2026-10-02T14:29:55.184618+00:00",+ "finalImplementationReady": "2026-10-02T14:50:33Z",+ "finalValidationStarted": "2026-10-02T14:50:33.539361Z",+ "validationCompleted": "2026-10-02T15:06:38.695172+00:00",+ "merge": "pending",+ "publication": "pending"+ },+ "pullRequest": "https://github.com/autonomous-ai/openharness/pull/620"+}