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(desktop): limit device list reads for the Add Phone card

tony985d309318c6
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index ed2e7daf9..22324e186 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -1163,6 +1163,8 @@ class AppNotifier extends ChangeNotifier {
_phoneOfferAway = null;
_missedWhileAway = null;
_phoneOfferAfterWorkAsked = false;
+ _phoneOfferAfterWorkUnanswered = 0;
+ _accountHasPhone = false;
_closeOwnerMemories();
_stopMachineRecovery();
api.resetAccountCache();
@@ -7491,6 +7493,17 @@ class AppNotifier extends ChangeNotifier {
/// [_offerPhoneAfterWork] has been asked in this run, for this account: one devices read a run.
bool _phoneOfferAfterWorkAsked = false;
+ /// Device reads [_offerPhoneAfterWork] has had in this run that gave no list to judge by. An
+ /// older CLI with no device list answers none at every finished turn, so it stops asking after
+ /// [_phoneOfferUnansweredReads] rather than read at each one for the rest of the run.
+ int _phoneOfferAfterWorkUnanswered = 0;
+ static const _phoneOfferUnansweredReads = 3;
+
+ /// A devices read in this run found a phone or a browser on this account: no card, and no read to
+ /// find that out again at each return to the window ([_offerPhoneAway]) — each one reaches the
+ /// backend through the daemon, for the many accounts that already have a phone.
+ bool _accountHasPhone = false;
+
/// The card for a computer that has never shown it ([_phoneOfferSeen]), on an account with no phone
/// or browser yet: once, after one of the person's own harnesses here finished a turn — beside work
/// that just went well, not over a launch.
@@ -7501,6 +7514,7 @@ class AppNotifier extends ChangeNotifier {
/// showed the first card, or opened Add Phone, has seen it.
Future<void> _offerPhoneAfterWork() async {
if (_phoneOfferAfterWorkAsked ||
+ _accountHasPhone ||
_phoneOffer ||
viewer != null ||
!signedIn ||
@@ -7510,23 +7524,26 @@ class AppNotifier extends ChangeNotifier {
_phoneOfferAfterWorkAsked = true;
final revision = _authRevision;
if (await _phoneOfferSeen()) return;
+ // No list to judge by: asked again at a later finished turn, a few times a run at most.
+ void unanswered() => _phoneOfferAfterWorkAsked =
+ ++_phoneOfferAfterWorkUnanswered >= _phoneOfferUnansweredReads;
bool hasPhone;
try {
final devices = await loadDevices();
if (devices == null) {
- // No list to judge by: asked again at the next finished turn.
- _phoneOfferAfterWorkAsked = false;
+ unanswered();
return;
}
hasPhone = devices.devices.any(
(device) => !device.isMachine && !device.self,
);
} catch (_) {
- _phoneOfferAfterWorkAsked = false;
+ unanswered();
return;
}
if (!_authWorkCurrent(revision) || !signedIn || _phoneOffer) return;
if (hasPhone) {
+ _accountHasPhone = true;
_markPhoneOfferSeen();
return;
}
@@ -7629,6 +7646,7 @@ class AppNotifier extends ChangeNotifier {
({String agent, bool waited, DateTime at}) missed,
) async {
if (_phoneOffer ||
+ _accountHasPhone ||
viewer != null ||
!signedIn ||
status != AppStatus.authenticated) {
@@ -7647,7 +7665,9 @@ class AppNotifier extends ChangeNotifier {
} catch (_) {
return;
}
- if (!_authWorkCurrent(revision) || !signedIn || _phoneOffer || hasPhone) {
+ if (!_authWorkCurrent(revision) || !signedIn || _phoneOffer) return;
+ if (hasPhone) {
+ _accountHasPhone = true;
return;
}
final minutes = phoneOfferClock().difference(missed.at).inMinutes;
diff --git a/desktop/test/phone_offer_test.dart b/desktop/test/phone_offer_test.dart
index c1ab37e77..386cf3123 100644
--- a/desktop/test/phone_offer_test.dart
+++ b/desktop/test/phone_offer_test.dart
@@ -286,6 +286,24 @@ void main() {
expect(none.reads, 2);
});
+ test(
+ 'a list that never comes is asked for three times a run at most',
+ () async {
+ // An older CLI with no device list: not a read at every finished turn for the whole run.
+ for (final api in [
+ _DevicesApi(null),
+ _DevicesApi(_listing([]), fails: true),
+ ]) {
+ final (app, _) = await returning(api);
+ for (var i = 0; i < 6; i++) {
+ await turnEnds(app);
+ }
+ expect(api.reads, 3);
+ expect(app.phoneOfferShowing, isFalse);
+ }
+ },
+ );
+
test(
'a failed turn offers nothing, and a run reads the list once',
() async {
@@ -544,6 +562,41 @@ void main() {
},
);
+ test(
+ 'an account found to have a phone is not read again in this run',
+ () async {
+ Future<void> awayAndBack(AppNotifier app, int times) async {
+ for (var i = 0; i < times; i++) {
+ leave(app);
+ await finishes(app, id: 'n$i');
+ await back(app, const Duration(minutes: 10));
+ }
+ }
+
+ // Each read reaches the backend through the daemon: once a run is enough to know.
+ final phone = _DevicesApi(_listing([_device('phone')]));
+ final (app, _) = await working(phone);
+ await awayAndBack(app, 3);
+ expect(app.phoneOfferShowing, isFalse);
+ expect(phone.reads, 1);
+
+ // Found by the card after work first: the same.
+ final known = _DevicesApi(_listing([_device('browser')]));
+ final (worked, _) = await working(known);
+ await worked.offerPhoneAfterWorkForTest();
+ expect(known.reads, 1);
+ await awayAndBack(worked, 2);
+ expect(worked.phoneOfferShowing, isFalse);
+ expect(known.reads, 1);
+
+ // No list is no answer: asked again at the next return.
+ final unread = _DevicesApi(null);
+ final (other, _) = await working(unread);
+ await awayAndBack(other, 2);
+ expect(unread.reads, 2);
+ },
+ );
+
test('not for a shared computer\'s harness, nor while signed out, nor with nowhere to remember', () async {
final (shared, _) = await working(_DevicesApi(_listing([])));
const sharedMachine = Machine(
diff --git a/docs/design/2026-10-20-desktop-phone-conversion.md b/docs/design/2026-10-20-desktop-phone-conversion.md
index d7eecb3b1..459ca54c9 100644
--- a/docs/design/2026-10-20-desktop-phone-conversion.md
+++ b/docs/design/2026-10-20-desktop-phone-conversion.md
@@ -46,7 +46,8 @@ first offer.
- "Own harness" is the same test the window uses for its own work counters: not a shared computer, not a plain
terminal, open in a pane of this window, not a subagent.
-- Asked once per run. If the account's device list cannot be read, it asks again at the next finished turn.
+- Asked once per run. If the account's device list cannot be read, it asks again at the next finished turn, up to
+ 3 reads a run (an older CLI has no device list at all).
- A computer that already showed the card, or opened Add Phone, has seen it (`phone_offer_seen`).
- An account that already has a phone or browser marks the computer seen and shows nothing.
@@ -80,6 +81,7 @@ told them while they were away:
### Rules shared by every card
- Only on an account with **no phone or browser** yet (`loadDevices`). No list to judge by: no card this time.
+ An account found to have one is not read again in that run: each read reaches the backend through the daemon.
- **At most 3 cards per computer**, every kind together (the first offer, after work, after time away).
- **× or Add Phone opened (from the card or any other way in) stops the cards on this computer for good.**
- A card left unanswered stays on screen until the app closes or the person signs out. On a later run, the card
@@ -162,7 +164,8 @@ A Desktop released first still offers the cards; its counts wait for the CLI.
## Known limits
- A computer that put the first card away before this release has only `phone_offer_done`, which cannot tell a ×
- from a signed-in launch. It may see the card once more; its × then stops it for good.
+ from a signed-in launch. It may see the card once more, and left unanswered, the card after time away up to the
+ 3-card cap; a × or Add Phone then stops it for good.
- Away time follows the window (`appLifecycleChanged`), not the person. A window left behind another app for 5
minutes while the person sat at the computer counts as away. The card then says what happened, which stays true.
- Counts are per computer, not per person: a person with two computers can see up to 3 cards on each.