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
feat(mobile): say what a launch back to work waited on
tony03dce3e0280a
diff --git a/mobile/lib/measurement/launch_measurement.dart b/mobile/lib/measurement/launch_measurement.dartindex 21c4cb9e0..5a4e0b405 100644--- a/mobile/lib/measurement/launch_measurement.dart+++ b/mobile/lib/measurement/launch_measurement.dart@@ -1,7 +1,36 @@+import 'dart:async';+import 'package:flutter/widgets.dart';import 'product_measurement.dart';+/// Why a launch's computers have not answered yet, each counted at most once per launch beside it as+/// `ui_phone_app_start_<wire>` (backend `PRODUCT_USAGE_PHONE_LAUNCH_MARKS`). On 2026-10-19 21 of 44+/// launches ended in no outcome at all, which could not say whether nothing was there to answer or the+/// app failed to reach what was. Seen while the launch still waits; nothing once a computer answered.+enum LaunchWait {+ /// The account's computer list, read from the backend, has none.+ noComputer('no_computer'),++ /// That list could not be read.+ listFailed('list_failed'),++ /// The backend reports every computer on the account offline.+ offline('offline'),++ /// A computer wants this phone's password (or a scanned code) before it opens.+ locked('locked'),++ /// A dial to a computer the backend reports online ended without its answer.+ connectFailed('connect_failed'),++ /// [LaunchMeasurement.waitedAfter] on screen with no computer answering.+ waited('waited_1m');++ const LaunchWait(this.wire);+ final String wire;+}+/// `app_start` on the phone: a launch that came back signed in, from `startHarness` to the first/// computer answering — the wait a returning person sits through before there is anything to use.///@@ -11,8 +40,11 @@ import 'product_measurement.dart';////// Outcomes: `ok` when a computer answered; `unknown` when the app left the screen before one did/// (whatever the wait took from there was not the launch's). A launch whose computers never answer-/// stays started, which is itself the signal.+/// stays started, which is itself the signal; what it waited on is said beside it ([waiting]).class LaunchMeasurement {+ /// How long a launch waits on screen before it is said to have waited ([LaunchWait.waited]).+ static const waitedAfter = Duration(minutes: 1);+static final _launchClock = Stopwatch();/// Starts the launch clock. Called once, from `startHarness`, before anything is awaited.@@ -26,6 +58,11 @@ class LaunchMeasurement {bool observeLifecycle = true,}) : _sinceLaunch = sinceLaunch ?? (() => _launchClock.elapsed) {measurement.addListener(_choiceChanged);+ final left = waitedAfter - _sinceLaunch();+ _waitedTimer = Timer(+ left.isNegative ? Duration.zero : left,+ () => waiting(LaunchWait.waited),+ );if (observeLifecycle) {final state = WidgetsBinding.instance.lifecycleState;if (state != null && !_onScreen(state)) foreground(false);@@ -53,6 +90,11 @@ class LaunchMeasurement {bool _left = false;Duration? _readyAt;void Function(ProductOutcome)? _open;+ Timer? _waitedTimer;++ /// What this launch waited on, not yet counted (sharing not read yet), and what has been.+ final _waits = <LaunchWait>{};+ final _counted = <LaunchWait>{};static bool _onScreen(AppLifecycleState state) =>state == AppLifecycleState.resumed || state == AppLifecycleState.inactive;@@ -69,6 +111,7 @@ class LaunchMeasurement {// A sign-out ends the launch's story; its queue goes with the account._wanted = false;_open = null;+ _waits.clear();}_choiceChanged();}@@ -91,12 +134,33 @@ class LaunchMeasurement {} else {_open = measurement.begin(ProductFlow.appStart, elapsed: _sinceLaunch());}+ _countWaits();+ }++ /// The launch is waiting on [why]: counted once, beside the launch, as soon as it is counted itself.+ /// Nothing once a computer answered or the app left the screen, or for a launch `app_start` does not+ /// describe (one that signed in).+ void waiting(LaunchWait why) {+ if (_disposed || _readyAt != null || _left) return;+ if (_accountSeen && !_wanted) return;+ if (_counted.contains(why)) return;+ _waits.add(why);+ _countWaits();+ }++ void _countWaits() {+ if (!_begun || !_wanted || !measurement.sharing) return;+ for (final why in [..._waits]) {+ _waits.remove(why);+ if (_counted.add(why)) measurement.mark(ProductFlow.appStart, why.wire);+ }}/// A computer answered. Only the first in this process ends the launch.void ready() {if (_readyAt != null || _left) return;_readyAt = _sinceLaunch();+ _waitedTimer?.cancel();_open?.call(ProductOutcome.ok);_open = null;}@@ -107,6 +171,7 @@ class LaunchMeasurement {_foreground = value;if (value || _readyAt != null || _left) return;_left = true;+ _waitedTimer?.cancel();_open?.call(ProductOutcome.unknown);_open = null;}@@ -114,6 +179,7 @@ class LaunchMeasurement {void dispose() {if (_disposed) return;_disposed = true;+ _waitedTimer?.cancel();_lifecycle?.dispose();measurement.removeListener(_choiceChanged);_open = null;diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dartindex 5616d804a..7d3530006 100644--- a/mobile/lib/state/app_state.dart+++ b/mobile/lib/state/app_state.dart@@ -2346,6 +2346,7 @@ class AppNotifier extends ChangeNotifier {// few seconds for a `harness link connect` run elsewhere, which a phone's links never come from.machine.needsLink = true;machine.agentLoadStatus = AgentLoadStatus.needsLink;+ launchMeasurement?.waiting(LaunchWait.locked);// …unless the log already vouches for it and this phone's key is new to it: then the machine// has only not read that key yet — see [_redialOnceVouched].unawaited(_redialOnceVouched(machine.machine.machineId));@@ -2541,6 +2542,12 @@ class AppNotifier extends ChangeNotifier {settling ? ConnectionStatus.connecting : nextStatus,ProductFlow.remoteConnect,);+ // A socket retries only once a dial ended without the machine's welcome (`WsConn`).+ if (nextStatus == ConnectionStatus.reconnecting &&+ !machine.needsLink &&+ _nodeOnlineFromStatus(machine.machine.status) == true) {+ launchMeasurement?.waiting(LaunchWait.connectFailed);+ }productConnections.status(machineId,connecting:@@ -2672,6 +2679,11 @@ class AppNotifier extends ChangeNotifier {// (dropping [machinesLoading]); one that answers only after an earlier failure does not.if (!machinesLoading) notifyListeners();}+ } catch (_) {+ if (_authWorkCurrent(revision)) {+ launchMeasurement?.waiting(LaunchWait.listFailed);+ }+ rethrow;} finally {if (_authWorkCurrent(revision)) _machinesFetchedFor = revision;// Said out loud: the list's own notify fires before this, so a flag@@ -2723,6 +2735,14 @@ class AppNotifier extends ChangeNotifier {.toList();// A wait for a computer that an earlier launch left open, with the computer now here.if (machines.isNotEmpty) unawaited(onboardingMeasurement.computersSeen());+ // What this launch's wait for a computer is up against, as the list says.+ if (machines.isEmpty) {+ launchMeasurement?.waiting(LaunchWait.noComputer);+ } else if (machines.every(+ (machine) => _nodeOnlineFromStatus(machine.status) == false,+ )) {+ launchMeasurement?.waiting(LaunchWait.offline);+ }final visible = machines.map((machine) => machine.machineId).toSet();// A code scanned for a machine this account does not have can never be// spent: the pairing screen waits for that machine to show up locked.diff --git a/mobile/test/app_state_flow_measurement_test.dart b/mobile/test/app_state_flow_measurement_test.dartindex 39ec370d7..16a6f3238 100644--- a/mobile/test/app_state_flow_measurement_test.dart+++ b/mobile/test/app_state_flow_measurement_test.dart@@ -1,5 +1,8 @@+import 'dart:async';+import 'package:flutter_test/flutter_test.dart';import 'package:harness_mobile/core/models.dart';+import 'package:harness_mobile/measurement/launch_measurement.dart';import 'package:harness_mobile/measurement/onboarding_measurement.dart';import 'package:harness_mobile/measurement/product_measurement.dart';@@ -309,4 +312,104 @@ void main() {expect(await sent(rig, 'sign_in'), isEmpty);});});++ group('what a launch back to work waited on', () {+ /// A launch that came back signed in, its computers [machines], counted as the app counts one.+ Future<ViewerRig> launching(+ Future<List<Machine>> Function() machines,+ ) async {+ final rig = viewerApp(productMeasurement: usage);+ addTearDown(rig.app.dispose);+ rig.app.launchMeasurement = LaunchMeasurement(+ usage,+ observeLifecycle: false,+ sinceLaunch: () => const Duration(seconds: 3),+ );+ rig.api.onMachines = machines;+ await rig.app.bootstrap();+ await settle();+ return rig;+ }++ Future<Set<String>> waits(ViewerRig rig) async => {+ for (final metric in (await sent(rig, 'app_start')).keys)+ for (final why in LaunchWait.values)+ if (metric == 'ui_phone_app_start_${why.wire}') why.wire,+ };++ test('an account with no computer', () async {+ final rig = await launching(() async => const []);+ expect(+ await sent(rig, 'app_start'),+ containsPair('ui_phone_app_start_started', 1),+ );+ expect(await waits(rig), {'no_computer'});+ });++ test('every computer reported offline', () async {+ final rig = await launching(+ () async => [+ remoteMachine('m', status: 'offline'),+ remoteMachine('n', status: 'stopped'),+ ],+ );+ expect(await waits(rig), {'offline'});+ });++ test('one computer still online is not offline', () async {+ final rig = await launching(+ () async => [remoteMachine('m', status: 'offline'), remoteMachine('n')],+ );+ expect(await waits(rig), isEmpty);+ });++ test('a list that cannot be read', () async {+ final rig = await launching(() async => throw StateError('offline'));+ expect(await waits(rig), {'list_failed'});+ });++ test('a computer that wants this phone\'s password', () async {+ final rig = await launching(() async => [remoteMachine('m')]);+ rig.app.trustSettleRound = const Duration(milliseconds: 20);+ // Each dial again is refused again: nothing vouches for this phone there.+ rig.app.onRedialForTest = (id) => scheduleMicrotask(+ () => rig.app.localFailureForTest(id, 4404, 'NO_PEER_LINK'),+ );+ rig.app.localFailureForTest('m', 4404, 'NO_PEER_LINK');+ for (var i = 0; i < 100 && !rig.app.stateOf('m')!.needsLink; i++) {+ await Future<void>.delayed(const Duration(milliseconds: 10));+ }+ expect(rig.app.stateOf('m')!.needsLink, isTrue);+ expect(await waits(rig), {'locked'});+ });++ test(+ 'a dial to a computer said to be online that fails, until one answers',+ () async {+ final rig = await launching(+ () async => [+ remoteMachine('m'),+ remoteMachine('n', status: 'offline'),+ ],+ );+ rig.app.connectionStatusForTest('n', ConnectionStatus.connecting);+ rig.app.connectionStatusForTest('n', ConnectionStatus.reconnecting);+ expect(await waits(rig), isEmpty, reason: 'n is offline');++ rig.app.connectionStatusForTest('m', ConnectionStatus.connecting);+ rig.app.connectionStatusForTest('m', ConnectionStatus.reconnecting);+ rig.app.connectionStatusForTest('m', ConnectionStatus.connected);+ expect(await waits(rig), {'connect_failed'});+ expect(+ await sent(rig, 'app_start'),+ containsPair('ui_phone_app_start_ok', 1),+ );++ // Answered: what follows is not the launch's.+ rig.app.connectionStatusForTest('m', ConnectionStatus.reconnecting);+ rig.app.localFailureForTest('m', 4404, 'NO_PEER_LINK');+ expect(await waits(rig), {'connect_failed'});+ },+ );+ });}diff --git a/mobile/test/launch_measurement_test.dart b/mobile/test/launch_measurement_test.dartindex 146f2f14a..0975bc3dc 100644--- a/mobile/test/launch_measurement_test.dart+++ b/mobile/test/launch_measurement_test.dart@@ -1,5 +1,7 @@import 'dart:convert';+import 'dart:io';+import 'package:fake_async/fake_async.dart';import 'package:flutter_test/flutter_test.dart';import 'package:harness_mobile/measurement/launch_measurement.dart';@@ -127,4 +129,157 @@ void main() {isEmpty,);});++ group('what a launch waited on', () {+ Map<String, int> waits(Map<String, int> counted) => {+ for (final why in LaunchWait.values)+ why.wire: ?counted['ui_phone_app_start_${why.wire}'],+ };++ test('each is counted once beside the open launch', () async {+ await signIn();+ launch.waiting(LaunchWait.offline);+ launch.waiting(LaunchWait.offline);+ launch.waiting(LaunchWait.connectFailed);+ final counted = await sent();+ expect(counted['ui_phone_app_start_started'], 1);+ expect(waits(counted), {'offline': 1, 'connect_failed': 1});+ launch.waiting(LaunchWait.offline);+ expect(waits(await sent()), {'offline': 1, 'connect_failed': 1});+ });++ test(+ 'seen before sharing is read, it is counted once the launch is',+ () async {+ launch.waiting(LaunchWait.noComputer);+ launch.account(signedIn: true, restored: true);+ launch.waiting(LaunchWait.listFailed);+ await signIn();+ expect(waits(await sent()), {'no_computer': 1, 'list_failed': 1});+ },+ );++ test(+ 'a computer that answers ends it, and what was seen before stays',+ () async {+ launch.waiting(LaunchWait.offline);+ launch.ready();+ launch.waiting(LaunchWait.connectFailed);+ await signIn();+ final counted = await sent();+ expect(counted['ui_phone_app_start_ok'], 1);+ expect(waits(counted), {'offline': 1});+ },+ );++ test('nothing once the app has left the screen', () async {+ await signIn();+ launch.foreground(false);+ launch.waiting(LaunchWait.offline);+ final counted = await sent();+ expect(counted['ui_phone_app_start_unknown'], 1);+ expect(waits(counted), isEmpty);+ });++ test('nothing for a launch that signs in, or after a sign-out', () async {+ launch.waiting(LaunchWait.locked);+ await signIn(restored: false);+ launch.waiting(LaunchWait.offline);+ expect(waits(await sent()), isEmpty);++ final restored = LaunchMeasurement(+ usage,+ observeLifecycle: false,+ sinceLaunch: () => clock,+ );+ addTearDown(restored.dispose);+ restored.account(signedIn: true, restored: true);+ restored.account(signedIn: false);+ restored.waiting(LaunchWait.locked);+ expect(waits(await sent()), isEmpty);+ });++ test('a minute on screen with no computer answering is said once', () {+ fakeAsync((async) {+ final timed = LaunchMeasurement(+ usage,+ observeLifecycle: false,+ sinceLaunch: () => clock,+ );+ timed.account(signedIn: true, restored: true);+ usage.account(+ 'PRIVATE_ACCOUNT',+ choice: () async => {'enabled': true, 'revision': 0},+ send: (r) async {+ reports.add(jsonDecode(jsonEncode(r)));+ return {'accepted': true};+ },+ );+ usage.flush();+ async.elapse(const Duration(seconds: 59));+ usage.flush();+ async.flushMicrotasks();+ expect(+ reports.expand((r) => (r['counters'] as Map).keys),+ isNot(contains('ui_phone_app_start_waited_1m')),+ );+ async.elapse(const Duration(seconds: 2));+ usage.flush();+ async.flushMicrotasks();+ final names = [for (final r in reports) ...(r['counters'] as Map).keys];+ expect(+ names.where((n) => n == 'ui_phone_app_start_waited_1m'),+ hasLength(1),+ );+ timed.dispose();+ });+ });++ test(+ 'no minute is said for a launch a computer answered, or once disposed',+ () {+ fakeAsync((async) {+ final answered = LaunchMeasurement(+ usage,+ observeLifecycle: false,+ sinceLaunch: () => clock,+ );+ final disposed = LaunchMeasurement(+ usage,+ observeLifecycle: false,+ sinceLaunch: () => clock,+ );+ answered.ready();+ disposed.dispose();+ expect(async.pendingTimers, hasLength(0));+ answered.dispose();+ });+ },+ );++ test('a launch already a minute old says so at once', () {+ fakeAsync((async) {+ clock = const Duration(minutes: 3);+ final late = LaunchMeasurement(+ usage,+ observeLifecycle: false,+ sinceLaunch: () => clock,+ );+ expect(async.pendingTimers.single.duration, Duration.zero);+ late.dispose();+ });+ });++ test('every reason is in the backend vocabulary', () {+ final vocabulary = File('../backend/src/types/productUsage.ts')+ .readAsStringSync();+ for (final why in LaunchWait.values) {+ expect(+ vocabulary,+ contains("'ui_phone_app_start_${why.wire}'"),+ reason: why.wire,+ );+ }+ });+ });}