Skip to content

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.

fix(mobile): end an in-progress phone connect as cancelled on background

tony0ee18dd8434a
diff --git a/docs/product-measurement.md b/docs/product-measurement.md
index 4397e8439..b8419bd21 100644
--- a/docs/product-measurement.md
+++ b/docs/product-measurement.md
@@ -20,7 +20,7 @@ automatically proven improvement. Changes still need review, tests and a deliber
| Which features get tried and used again? | First measured installations and daily first/repeat feature reach | Locally deduplicated installation-days, not unique accounts. Reads the apps make on their own (history, history paging, Store list, model list; `PRODUCT_USAGE_AUTOMATIC_ACTIONS`) count reliability only. The Store and model lists get reach only from the request an app marks `userAction` when a person opens them (`<action>_user_*`, `PRODUCT_USAGE_USER_OPENED_ACTIONS`); history has none. |
| Where do app flows break? | Setup, Harness/tmux/clipboard steps, sign-in, workspace/remote connections, computer linking, viewer-pane opening and manual update checking/staging; a setup step whose tool was missing at a check (`setup_desktop_setup_<step>_missing`); the agents a new computer downloads beside setup (`setup_desktop_agent_download_<opencode\|codex\|claude>_started`, `_ok`, `_failed`, with under 1 min, 1–5 min and over 5 min) | Fixed started/ok/failed/cancelled/unknown counts and coarse duration buckets. Opening a viewer pane is not rendering its content; staging an update is not a successful relaunch. A setup step stays open from the first check until its tool is in place, so a tool that was missing and then installed is one ok step and one `_missing` mark; only a setup that ends failed fails its step. Earlier Desktop releases counted every check that found a tool missing as a failed step (on 2026-10-16 the Harness step read 72 failed of 221 while 0 setups failed): compare releases separately. `_missing` is any tool a check found absent or out of date (a Harness CLI older than this Desktop needs, on a computer already in use, counts too), not only new computers. A step left waiting (the review, a Linux Terminal handoff, manual mode, someone who walks away) now ends `unknown` at the 15-minute observation bound instead of `failed`, so expect `setup_*_unknown` to rise, mostly on Linux. `_missing` and the download counts are anonymous setup counts only. A download whose prerequisite (curl, Harness's Node) never arrived counts as started and failed; `ok` means the agent's program is in place, judged per engine. |
| Where does the phone's onboarding stall? | After sign-in: waiting for the first computer, opening its session, the first message, the notification prompt. A sign-in that went through, by button, counted again under the account's sharing. Waits past a minute split into 1–5 min, 5–15 min, 15 min–1 h and over 1 h for the computer and the first message. Once per step per sign-in: `resumed` (reopened in a run that did not sign in), "Not you? Sign out", the address sent from the share sheet, a joining computer that wants its password or is offline, `joined_after_leaving` (the computer turned up after the app left the wait), `new_account` (a sign-in that created the account). Once per install: `first_open` (signed out `setup_phone_first_open`, signed in `ui_phone_first_open`) | Stage totals per day, not a linked funnel. A wait's `ok` is a computer that turned up while its screen was open: add `joined_after_leaving` for the computers that came while the app was away (16–19 October 2026: 5 `ok` in 49 fresh waits, while 91% of the phone's people had a computer on the same account). `new_account` is an account minutes old at sign-in, its first Harness sign-in anywhere. `first_open` is set once per install by a local flag that is never sent: the step between a store's download and a sign-in. Subtract `resumed` from starts for fresh starts; an unmatched start is a closed app or a step still waiting. A resumed step's duration starts at the reopening. Signed-in sign-in counts are successes only; failures and cancels before an account remain the signed-out counts', but a success is marked `retried` (a failed or cancelled try came first in that app run) or `switched` (another button was tried first). Phone reports carry release and iOS/Android, so every phone count also splits by those two margins (above 20 collector days); debug builds are not kept. A chosen sign-out sends what is queued first (up to 2 s), so "Not you? Sign out" reaches the totals. The first message is the first line sent after the hand-over in any session, or a task typed into New Harness; before 2026-10-20 only the session the hand-over opened counted and leaving it cancelled the step (compare releases separately). Each step of a sign-in that created its account is marked `new_account` when counted and `new_account_ok` when it ends ok, so new people's funnel reads apart. The phone sends what it queued as it leaves the screen, since iOS can end a suspended app with its counts still in RAM. |
-| How fast does the phone get back to work? | A launch that came back signed in, to its first computer answering (`app_start`); a dial the person asked for ("Try again", `connect_user`) apart from the app's own (`connect_auto`), beside the unchanged `remote_connect`; a stopped harness resumed from the phone, to its first live turn (`resume_recovery`) | A launch that signs in is the onboarding's and is not counted; one that leaves the screen before a computer answers is `unknown`, one whose computers never answer stays started. What a launch waited on is counted beside it, once each, until a computer answers or the app leaves the screen (`ui_phone_app_start_<why>`): `no_computer` and `list_failed` (the account's list had none, or could not be read), `offline` (it said every computer was offline), `locked` (a computer wanted the phone's password), `connect_failed` (a dial to a computer said to be online failed) and `waited_1m` (a minute on screen); a launch can name several. An asked-for dial fails at 12 s, as Desktop Connect does. A phone dial is `failed` only when the phone knows why (locked or offline), `unknown` otherwise; the reasons (`connect_error_*`) are Desktop health counters. |
+| How fast does the phone get back to work? | A launch that came back signed in, to its first computer answering (`app_start`); a dial the person asked for ("Try again", `connect_user`) apart from the app's own (`connect_auto`), beside the unchanged `remote_connect`; a stopped harness resumed from the phone, to its first live turn (`resume_recovery`) | A launch that signs in is the onboarding's and is not counted; one that leaves the screen before a computer answers is `unknown`, one whose computers never answer stays started. What a launch waited on is counted beside it, once each, until a computer answers or the app leaves the screen (`ui_phone_app_start_<why>`): `no_computer` and `list_failed` (the account's list had none, or could not be read), `offline` (it said every computer was offline), `locked` (a computer wanted the phone's password), `connect_failed` (a dial to a computer said to be online failed) and `waited_1m` (a minute on screen); a launch can name several. An asked-for dial fails at 12 s, as Desktop Connect does. A phone dial is `failed` only when the phone knows why (locked or offline), `unknown` otherwise; the reasons (`connect_error_*`) are Desktop health counters. The phone's `remote_connect` is one computer's socket dialling, from connecting or reconnecting until it connects (`ok`) or drops (`failed`). `cancelled` is a dial still going when the app went to the background (the pause, not the app switcher or a system sheet): a suspended app never hears the socket's answer, so the dial ends there rather than staying without an outcome, and a dial after the app is back is a new count. From 1.0.8 build 72 a dial still in progress when the app goes to the background ends `cancelled`; earlier builds left it without an outcome (79 of the 252 on 2026-10-20): compare releases separately. `connect_user` and `connect_auto` are not ended this way. |
| Are the phone's side pages used? | Find and Computers opens, by a sideways swipe on the terminal or by a button (Computers' row in Settings, its link on a long wait at home) | Which page and which way, nothing more. Find's key and screen-reader actions are not counted; a swipe that lets Find go back opened nothing. |
| Does Desktop's Add Phone card get used, and where else is Add Phone opened? | The card's flow (`ui_desktop_phone_offer_*`): started once it is on screen, `ok` by its Add Phone, `cancelled` by its ×, `unknown` when it went another way (Add Phone opened from elsewhere, a sign-out); every Add Phone opening by its way in (`ui_desktop_add_phone_<offer\|titlebar\|menu\|account\|machines\|command>`) | The card is offered once per computer, so its starts are computers, not people, and it has no 15-minute bound: started minus outcomes is an app closed with the card still up. An opening is the dialog shown, not a phone paired. `menu` includes a key bound to Harness ▸ Add Phone… on macOS; `command` is `> add phone` or a key bound to it elsewhere. A computer that opened signed in was marked offered without ever showing the card; from 2026-10-20 it shows the card once after one of its own harnesses finishes a turn, if the account has no phone or browser, counted apart as `ui_desktop_phone_offer_after_work_*` (vocabulary 4). The same card also shows to a person back after 5 minutes or more away to one of their harnesses that waited on them or finished meanwhile, counted as `ui_desktop_phone_offer_away_waited_*` / `ui_desktop_phone_offer_away_finished_*` (vocabulary 4): at most 3 cards a computer, every kind together, and none once a card's × or Add Phone was used there ([design](design/2026-10-20-desktop-phone-conversion.md)). The browser counts none. Vocabulary 3: counted from the start, but sent only once the local CLI has answered that it forwards them, so a Desktop on an older CLI sends none. |
| Is measurement losing coverage? | Updated collector installation-days, pruned queues, full observation maps, unmatched app starts | Loss signals warrant caution. No signal does not prove complete collection. |
diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dart
index 550478de7..2c386fd8b 100644
--- a/mobile/lib/state/app_state.dart
+++ b/mobile/lib/state/app_state.dart
@@ -1409,6 +1409,19 @@ class AppNotifier extends ChangeNotifier {
}
}
+ /// Ends every dial still going as `cancelled`: the person left the screen before it had an answer,
+ /// which is neither a success nor a failure of the socket. Each count is dropped from
+ /// [_measurementConnections] as it ends, so the socket's own answer later finds none to end again
+ /// (no second outcome), and a dial after the app is back starts a fresh count.
+ void _cancelMeasurementConnections() {
+ if (_measurementConnections.isEmpty) return;
+ final open = _measurementConnections.values.toList();
+ _measurementConnections.clear();
+ for (final finish in open) {
+ finish(ProductOutcome.cancelled);
+ }
+ }
+
/// Straight to the backend, signed with this app's own session.
ApiClient _newApiClient() =>
ApiClient(config: config, session: session, auth: viewer.auth);
@@ -10586,6 +10599,10 @@ class AppNotifier extends ChangeNotifier {
///
/// And write the machine cache now ([_keepMachineCache]): this is the last moment the app is sure
/// to run, since closing it from the app switcher starts by sending it here.
+ ///
+ /// A dial still going ends `cancelled` ([_cancelMeasurementConnections]) before the counts are
+ /// sent: an app the OS suspends in its first seconds away never hears the socket's answer, and
+ /// the dial would stay without an outcome.
void handleAppPaused() {
// The first pause of this time away: a second without a resume between (the OS repeating
// itself) does not move the moment the phone actually left.
@@ -10600,6 +10617,7 @@ class AppNotifier extends ChangeNotifier {
}
// The agents this run learned between lists, for the next launch — see [_keepMachineCache].
_keepMachineCache();
+ _cancelMeasurementConnections();
_sendMeasurementBeforeBackground();
}
diff --git a/mobile/test/app_state_flow_measurement_test.dart b/mobile/test/app_state_flow_measurement_test.dart
index a37150501..e3a07a40a 100644
--- a/mobile/test/app_state_flow_measurement_test.dart
+++ b/mobile/test/app_state_flow_measurement_test.dart
@@ -99,6 +99,117 @@ void main() {
});
});
+ group('a dial still going when the app goes to the background', () {
+ // The OS suspends the app within seconds, so the socket's answer may never be heard; the dial
+ // is cancelled by the person leaving, before the counts are sent.
+
+ const outcomes = ['started', 'ok', 'failed', 'cancelled', 'unknown'];
+
+ /// How many `remote_connect` dials started and ended each way, apart from the duration buckets.
+ Future<Map<String, int>> dials(ViewerRig rig) async {
+ final all = await sent(rig, 'remote_connect');
+ return {
+ for (final outcome in outcomes)
+ if (all.containsKey('ui_phone_remote_connect_$outcome'))
+ outcome: all['ui_phone_remote_connect_$outcome']!,
+ };
+ }
+
+ test('is cancelled, once, and that goes out with the pause', () async {
+ final rig = await sharing({'m': []});
+ final before = rig.api.usageReports.length;
+ rig.app.sendMeasurementBeforeBackground = true;
+ rig.app.connectionStatusForTest('m', ConnectionStatus.connecting);
+
+ rig.app.handleAppPaused();
+ rig.app.handleAppPaused();
+ await pumpEventQueue();
+
+ // In the report the pause itself sent, not one of a later flush.
+ final reported = <String, int>{};
+ for (final report in rig.api.usageReports.skip(before)) {
+ (report['counters'] as Map).forEach((metric, value) {
+ reported['$metric'] = (reported['$metric'] ?? 0) + (value as int);
+ });
+ }
+ expect(reported, containsPair('ui_phone_remote_connect_started', 1));
+ expect(reported, containsPair('ui_phone_remote_connect_cancelled', 1));
+ expect(reported, isNot(contains('ui_phone_remote_connect_ok')));
+ expect(reported, isNot(contains('ui_phone_remote_connect_failed')));
+ });
+
+ test('is no second outcome when the socket answers after all', () async {
+ final rig = await sharing({'m': [], 'n': []});
+ rig.app.connectionStatusForTest('m', ConnectionStatus.connecting);
+ rig.app.connectionStatusForTest('n', ConnectionStatus.reconnecting);
+ rig.app.handleAppPaused();
+
+ rig.app.connectionStatusForTest('m', ConnectionStatus.connected);
+ rig.app.connectionStatusForTest('n', ConnectionStatus.disconnected);
+
+ expect(await dials(rig), {'started': 2, 'cancelled': 2});
+ });
+
+ test('every machine still dialling is cancelled, each once', () async {
+ final rig = await sharing({'m': [], 'n': [], 'o': []});
+ rig.app.connectionStatusForTest('m', ConnectionStatus.connecting);
+ rig.app.connectionStatusForTest('n', ConnectionStatus.reconnecting);
+ rig.app.connectionStatusForTest('o', ConnectionStatus.connecting);
+ rig.app.connectionStatusForTest('o', ConnectionStatus.connected);
+
+ rig.app.handleAppPaused();
+
+ expect(await dials(rig), {'started': 3, 'ok': 1, 'cancelled': 2});
+ });
+
+ test('that had connected before stays ok, and only ok', () async {
+ final rig = await sharing({'m': []});
+ rig.app.connectionStatusForTest('m', ConnectionStatus.connecting);
+ rig.app.connectionStatusForTest('m', ConnectionStatus.connected);
+
+ rig.app.handleAppPaused();
+
+ expect(await dials(rig), {'started': 1, 'ok': 1});
+ });
+
+ test('that failed before stays failed, and only failed', () async {
+ final rig = await sharing({'m': []});
+ rig.app.connectionStatusForTest('m', ConnectionStatus.connecting);
+ rig.app.connectionStatusForTest('m', ConnectionStatus.disconnected);
+
+ rig.app.handleAppPaused();
+
+ expect(await dials(rig), {'started': 1, 'failed': 1});
+ });
+
+ test(
+ 'is followed by a new count when the app dials after resuming',
+ () async {
+ final rig = await sharing({'m': []});
+ rig.app.connectionStatusForTest('m', ConnectionStatus.connecting);
+ rig.app.handleAppPaused();
+ rig.app.handleAppResumed();
+ await settle();
+
+ rig.app.connectionStatusForTest('m', ConnectionStatus.connecting);
+ rig.app.connectionStatusForTest('m', ConnectionStatus.connected);
+
+ expect(await dials(rig), {'started': 2, 'cancelled': 1, 'ok': 1});
+ },
+ );
+
+ test('is not cancelled by losing the foreground for a moment', () async {
+ // A system sheet or the app switcher does not stop the dial; only the background does.
+ final rig = await sharing({'m': []});
+ rig.app.connectionStatusForTest('m', ConnectionStatus.connecting);
+
+ rig.app.handleAppInactive();
+ rig.app.connectionStatusForTest('m', ConnectionStatus.connected);
+
+ expect(await dials(rig), {'started': 1, 'ok': 1});
+ });
+ });
+
group('dials', () {
test('a socket coming back by itself is the app\'s own', () async {
final rig = await sharing({'m': []});