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): a slow conversation open no longer overrides a newer selection (#1861)
0xken15d57233818be0
diff --git a/desktop/lib/super_tabs/controller.dart b/desktop/lib/super_tabs/controller.dartindex c3df85640..a388f08a4 100644--- a/desktop/lib/super_tabs/controller.dart+++ b/desktop/lib/super_tabs/controller.dart@@ -131,6 +131,18 @@ class SuperTabController extends ChangeNotifier {SuperTabSnapshot? snapshot;String selectedId = 'lead';+ /// Counts the reader's moves ([_moveView]), so a slow [select] cannot land+ /// over a newer choice.+ int _selectRequest = 0;++ /// Every move of what the reader looks at goes through here: a [select]+ /// still reading its conversation then knows it was overtaken.+ void _moveView({String? to, bool devices = false}) {+ _selectRequest++;+ devicesSelected = devices;+ if (to != null) selectedId = to;+ }+/// The newest change of the Swarm this tab has read, in epoch milliseconds: what tells the app and the tag list/// that it changed (spec ruling 8).int lastChangedAt = -1;@@ -276,7 +288,7 @@ class SuperTabController extends ChangeNotifier {/// its draft and terminal choice stay available when the person returns.void selectDevices() {if (_disposed || accessRevoked || devicesSelected) return;- devicesSelected = true;+ _moveView(devices: true);_saveSoon();_changed();}@@ -381,7 +393,7 @@ class SuperTabController extends ChangeNotifier {return;}_terminals[conversationId] = '*';- devicesSelected = false;+ _moveView();_saveSoon();_changed();}@@ -396,7 +408,7 @@ class SuperTabController extends ChangeNotifier {if (_terminals[conversationId] == agentId && !devicesSelected) {return;}- devicesSelected = false;+ _moveView();if (agentId == null) {_terminals.remove(conversationId);} else {@@ -913,14 +925,17 @@ class SuperTabController extends ChangeNotifier {}/// Opens conversation [id], reading it first when it is not held- /// ([loadGroup]); false when it cannot be read.+ /// ([loadGroup]); false when it cannot be read, or another was opened while+ /// it was.Future<bool> select(String id) async {+ final ask = ++_selectRequest;// A held group is selected at once, before this returns.- if (snapshot?.conversation(id) == null && !await loadGroup(id)) {- return false;+ if (snapshot?.conversation(id) == null) {+ if (!await loadGroup(id)) return false;+ // The reader moved on while this was read: it must not pull them back.+ if (ask != _selectRequest) return false;}if (id == selectedId && !devicesSelected) return true;- devicesSelected = false;_acted();final group = snapshot!.conversation(id)!;// A workgroup is shown under its project, so its project opens. A Chat with@@ -930,7 +945,7 @@ class SuperTabController extends ChangeNotifier {unawaited(loadDormant(group.projectId));if (group.closed) closedOpenProjects.add(group.projectId);}- selectedId = id;+ _moveView(to: id);_viewVersion++;operationNotice = null;_saveSoon();@@ -1655,7 +1670,7 @@ class SuperTabController extends ChangeNotifier {result['conversationId'] is String) {// A successful create selects its confirmed destination even when the// following read is offline. Never leave the old group's composer active.- selectedId = result['conversationId'] as String;+ _moveView(to: result['conversationId'] as String);}_pending = null;try {diff --git a/desktop/test/super_tab_dormant_groups_test.dart b/desktop/test/super_tab_dormant_groups_test.dartindex 9da654e83..06f4eda8f 100644--- a/desktop/test/super_tab_dormant_groups_test.dart+++ b/desktop/test/super_tab_dormant_groups_test.dart@@ -127,6 +127,106 @@ void main() {expect(c.selectedId, 'finished');});+ test('late loadGroup does not override a newer select', () async {+ final hold = Completer<void>();+ final c = SuperTabController(+ tabId: 'tab',+ accountId: 'owner',+ request: (method, path, {body}) async {+ if (path.endsWith('/groups/finished')) await hold.future;+ return server.request(method, path, body: body);+ },+ save: server.save,+ pollInterval: Duration.zero,+ );+ await c.refresh();+ final slow = c.select('finished');+ // The reader moves on while the closed group is still being read.+ expect(await c.select('offline'), isTrue);+ hold.complete();+ expect(await slow, isFalse);+ expect(c.selectedId, 'offline');+ });++ test('late loadGroup does not leave a newer Devices view', () async {+ final hold = Completer<void>();+ final c = SuperTabController(+ tabId: 'tab',+ accountId: 'owner',+ request: (method, path, {body}) async {+ if (path.endsWith('/groups/finished')) await hold.future;+ return server.request(method, path, body: body);+ },+ save: server.save,+ pollInterval: Duration.zero,+ );+ await c.refresh();+ final slow = c.select('finished');+ c.selectDevices();+ hold.complete();+ expect(await slow, isFalse);+ expect(c.devicesSelected, isTrue);+ expect(c.selectedId, 'lead');+ });++ for (final move in ['a new conversation', 'its terminals', 'one terminal']) {+ test('late loadGroup does not override $move chosen meanwhile', () async {+ server.state['agents'] = [+ {+ 'id': 'b',+ 'name': 'b',+ 'machineId': 'm',+ 'harnessId': 'native-b',+ 'contributorId': 'owner',+ 'configuration': {'engine': 'codex'},+ },+ ];+ group('lead')['agentIds'] = ['b'];+ final hold = Completer<void>();+ // Holds a create between selecting its conversation and reading the+ // change, where a late open could still land over it.+ final saving = Completer<void>();+ late final SuperTabController c;+ c = SuperTabController(+ tabId: 'tab',+ accountId: 'owner',+ request: (method, path, {body}) async {+ if (path.endsWith('/groups/finished')) await hold.future;+ return server.request(method, path, body: body);+ },+ save: (state) async {+ if (c.selectedId != 'lead') await saving.future;+ return server.save(state);+ },+ pollInterval: Duration.zero,+ );+ await c.refresh();+ final slow = c.select('finished');+ Future<Object?> made = Future.value();+ switch (move) {+ case 'a new conversation':+ made = c.command({+ 'type': 'conversation.create',+ 'title': 'New feature',+ 'brief': '',+ 'checks': <dynamic>[],+ });+ await pumpEventQueue();+ expect(c.selectedId, startsWith('group-'));+ case 'its terminals':+ c.selectGroupTerminals('lead');+ default:+ c.selectTerminal('lead', 'b');+ }+ final chosen = c.selectedId;+ hold.complete();+ expect(await slow, isFalse);+ expect(c.selectedId, chosen);+ saving.complete();+ await made;+ });+ }+test('read marks and drafts of a closed group survive opening again',() async {