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): harnesses made signed-out come home when you sign in

0xdiego2593aa4e05eb69
diff --git a/desktop/lib/core/models.dart b/desktop/lib/core/models.dart
index be530f20d..6ae05bf2f 100644
--- a/desktop/lib/core/models.dart
+++ b/desktop/lib/core/models.dart
@@ -86,6 +86,17 @@ class SharedHarness {
}
/// Control-plane machine (GET /api/machines).
+/// Two spellings of the same machine or computer id.
+///
+/// The backend stores a computer id with its dashes stripped
+/// (`d11a1f3bca2a44e9…`) while `~/.harness/computer-id` — which is what the
+/// daemon serves under while signed out, and therefore what a tile made then is
+/// keyed by — keeps them (`d11a1f3b-ca2a-44e9-…`). The same id, written two
+/// ways, and a plain `==` between them never matches. Anything comparing an id
+/// that crossed that boundary has to come through here.
+bool sameMachineId(String a, String b) =>
+ a.replaceAll('-', '').toLowerCase() == b.replaceAll('-', '').toLowerCase();
+
class Machine {
final String machineId;
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index 45563d179..243d62da2 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -2978,18 +2978,30 @@ class AppNotifier extends ChangeNotifier {
/// them under the one it does, and remember it for next time.
Future<void> _followLocalMachineId(int revision) async {
final store = _paneLayout;
- final current = localMachineState?.machine.machineId;
+ final local = localMachineState?.machine;
+ final current = local?.machineId;
if (store == null || current == null) return;
final remembered = await store.loadLocalMachineId();
if (!_authWorkCurrent(revision)) return;
var from = remembered != null && remembered != current ? remembered : null;
+ // THIS COMPUTER'S OWN ID, on a tile, is this computer under the identity it
+ // had while signed out — and that is a fact rather than a reading. The
+ // daemon serves this machine under `computerId()` with no account and under
+ // the account's `machineId` with one, and the machine row carries BOTH, so
+ // a tile keyed by the first is one this window made before signing in.
+ //
+ // It outranks the remembered id because the remembered id can be wrong in
+ // the one direction that matters: a pass that could not re-seat used to
+ // record the new id anyway, erasing the only clue the next pass had. Seen
+ // on a real desk — two harnesses made signed-out, `local_machine_id` already
+ // the account's, and no way back (owner, 2026-09-24).
+ final strandedOnThisComputer = _strandedGuestTiles(local);
+ if (strandedOnThisComputer != null) from = strandedOnThisComputer;
// A guest's list is this computer and nothing else, so a tile waiting for a
// machine the list does not have can only be this computer under the account
- // it left — IF every such tile names the same one. That reading beats the
- // remembered id: a desk saved before the id was remembered, or remembered by
- // a launch that could not re-seat, still comes home. Signed in, an unknown id
- // is a machine that was deleted, and nothing is inferred.
- if (isGuest) {
+ // it left — IF every such tile names the same one. Kept for the desk saved
+ // before any of the ids above were recorded.
+ if (from == null && isGuest) {
final unknown = {
for (final pane in allPanes)
if (!machineStates.containsKey(pane.machineId)) pane.machineId,
@@ -3002,7 +3014,32 @@ class AppNotifier extends ChangeNotifier {
await _reseatDesk(from: from, to: current, dropOthers: isGuest);
if (!_authWorkCurrent(revision)) return;
}
- await store.saveLocalMachineId(current);
+ // ONLY ONCE THE DESK REALLY NAMES THIS MACHINE.
+ //
+ // This used to run whatever happened above, which is what made a single
+ // missed re-seat permanent: the id it wrote was the evidence the next launch
+ // needed. If tiles are still sitting on this computer's signed-out id, the
+ // desk has not been re-seated and the old id has to stand.
+ if (_strandedGuestTiles(local) == null) {
+ await store.saveLocalMachineId(current);
+ }
+ }
+
+ /// This computer's signed-out id, when tiles are still keyed by it.
+ ///
+ /// Returns the id AS THE TILES SPELL IT — the re-key rewrites what is on the
+ /// desk, and the two sides spell the same id differently. See [sameMachineId].
+ String? _strandedGuestTiles(Machine? local) {
+ final computerId = local?.computerId;
+ if (computerId == null || computerId.isEmpty) return null;
+ if (sameMachineId(computerId, local!.machineId)) return null;
+ for (final pane in allPanes) {
+ if (sameMachineId(pane.machineId, computerId) &&
+ !machineStates.containsKey(pane.machineId)) {
+ return pane.machineId;
+ }
+ }
+ return null;
}
/// The account left this window — signed out from Settings, or a session that
diff --git a/desktop/test/guest_window_test.dart b/desktop/test/guest_window_test.dart
index 061c8e010..00301ab31 100644
--- a/desktop/test/guest_window_test.dart
+++ b/desktop/test/guest_window_test.dart
@@ -16,6 +16,7 @@ library;
import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/core/models.dart';
import 'package:harness/state/pane_layout_store.dart';
import 'swarm_state_test.dart' show MemoryStore, createApp;
@@ -93,6 +94,25 @@ void main() {
expect(await layout.loadLocalMachineId(), 'machine-xyz');
});
+ test('a desk keyed by the DASHED computer id still re-keys', () async {
+ // The tiles carry `~/.harness/computer-id` verbatim — the daemon served
+ // them under it while signed out — and the account's machine is a
+ // different id entirely. The re-key rewrites what is actually on the desk.
+ const dashed = 'd11a1f3b-ca2a-44e9-ae68-a942e044e6d8';
+ final store = await savedDesk(dashed);
+ final layout = PaneLayoutStore(storage: store);
+ await layout.rekeyMachine(
+ from: dashed,
+ to: '001bcba1e7e9deb6f8756c053a951ce2',
+ );
+
+ expect(savedPanes((await layout.loadSwarms())!), [
+ ('001bcba1e7e9deb6f8756c053a951ce2', 'a1'),
+ ('001bcba1e7e9deb6f8756c053a951ce2', 'a2'),
+ ('other-machine', 'b1'),
+ ]);
+ });
+
test('a desk that already names the right id is left alone', () async {
final store = await savedDesk('machine-xyz');
final before = await store.read('swarm_layout_v1');
@@ -102,15 +122,43 @@ void main() {
});
});
- group('what a guest window is', () {
- test('a desktop window without an account is a guest; a viewer never is', () {
- final app = createApp();
- addTearDown(app.dispose);
- expect(app.signedIn, isTrue, reason: 'presumed until the CLI answers');
- expect(app.isGuest, isFalse);
-
- app.signedIn = false;
- expect(app.isGuest, isTrue);
+ group('the two spellings of one computer id', () {
+ // The backend strips the dashes; `~/.harness/computer-id` keeps them, and
+ // that file is what the daemon serves under while signed out — so it is what
+ // a tile made then is keyed by. A plain `==` across that boundary never
+ // matches, and the re-key that depends on it silently does nothing.
+ const dashed = 'd11a1f3b-ca2a-44e9-ae68-a942e044e6d8';
+ const plain = 'd11a1f3bca2a44e9ae68a942e044e6d8';
+
+ test('the same id written two ways is the same id', () {
+ expect(sameMachineId(dashed, plain), isTrue);
+ expect(sameMachineId(plain, dashed), isTrue);
+ expect(sameMachineId(dashed, dashed), isTrue);
+ });
+
+ test('case is not part of the id either', () {
+ expect(sameMachineId(plain.toUpperCase(), dashed), isTrue);
+ });
+
+ test('two different ids stay different', () {
+ expect(sameMachineId(plain, '001bcba1e7e9deb6f8756c053a951ce2'), isFalse);
+ // Not a prefix match: one is not the other with the rest cut off.
+ expect(sameMachineId(plain, plain.substring(0, 20)), isFalse);
});
});
+
+ group('what a guest window is', () {
+ test(
+ 'a desktop window without an account is a guest; a viewer never is',
+ () {
+ final app = createApp();
+ addTearDown(app.dispose);
+ expect(app.signedIn, isTrue, reason: 'presumed until the CLI answers');
+ expect(app.isGuest, isFalse);
+
+ app.signedIn = false;
+ expect(app.isGuest, isTrue);
+ },
+ );
+ });
}