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 tab listed twice no longer takes the app down (#983)
0xken15ca9264777dea
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex 9ba53ce78..3f82d4d36 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -14555,9 +14555,13 @@ class AppNotifier extends ChangeNotifier {}// Tab order: the desk's, with this window's local-only tabs where they were.+ // A tab the desk has is placed by the desk's order alone, even one this+ // window keeps to itself (a draft the desk learned while an agent was being+ // made in it): placed twice, its id reached native's tab strip twice, which+ // trapped on it and took the app down (1.2.57).final localOnly = <(int, Swarm)>[];for (var i = 0; i < kept.length; i++) {- if (!_deskTracks(kept[i]) || !targetById.containsKey(kept[i].id)) {+ if (!targetById.containsKey(kept[i].id)) {localOnly.add((i, kept[i]));}}@@ -14567,9 +14571,22 @@ class AppNotifier extends ChangeNotifier {for (final (index, swarm) in localOnly) {ordered.insert(index.clamp(0, ordered.length), swarm);}- swarms- ..clear()- ..addAll(ordered);+ final placed = <String>{};+ final duplicates = <String>[];+ swarms.clear();+ for (final swarm in ordered) {+ if (placed.add(swarm.id)) {+ swarms.add(swarm);+ } else {+ // The copy kept shows the same panes when it is the same tab; panes+ // only this copy held are let go below, like a closed tab's.+ duplicates.add(swarm.id);+ released.addAll(swarm.panes);+ }+ }+ if (duplicates.isNotEmpty) {+ appLog.warn('desk', 'dropped duplicate tab ${duplicates.join(', ')}');+ }if (swarms.isEmpty) swarms.add(Swarm(id: 'swarm-${_nextSwarmId++}'));if (!swarms.any((s) => s.id == _activeSwarmId)) {_activeSwarmId = swarms.first.id;diff --git a/desktop/macos/Runner/SwarmTitlebar.swift b/desktop/macos/Runner/SwarmTitlebar.swiftindex 8568d6219..726915728 100644--- a/desktop/macos/Runner/SwarmTitlebar.swift+++ b/desktop/macos/Runner/SwarmTitlebar.swift@@ -2227,7 +2227,14 @@ private final class SwarmTabStrip: NSView {daemonButton.foreground = terminalForegroundvoiceLabel.font = barFontupdateDaemon(state["daemon"] as? [String: Any] ?? [:])- let rows = state["tabs"] as? [[String: Any]] ?? []+ // One tab per id, the first row kept. A payload that listed a tab twice+ // left two buttons with one id here, and the next update trapped building+ // `previous` from them, taking the app down (1.2.57).+ var seenIds = Set<String>()+ let rows = (state["tabs"] as? [[String: Any]] ?? []).filter { row in+ guard let id = row["id"] as? String else { return true }+ return seenIds.insert(id).inserted+ }let nextActiveId = state["activeId"] as? String ?? ""// A closed tab left the keyboard with Flutter (Dart's `tabStripFocused`).// Expose the Return hint without drawing a focus ring for this passive hold.@@ -2238,7 +2245,7 @@ private final class SwarmTabStrip: NSView {let previousOrder = tabs.map(\.swarmId)tabOrderChanged = tabOrderChanged || ids != previousOrderfor tab in tabs where !ids.contains(tab.swarmId) { tab.removeFromSuperview() }- let previous = Dictionary(uniqueKeysWithValues: tabs.map { ($0.swarmId, $0) })+ let previous = Dictionary(tabs.map { ($0.swarmId, $0) }, uniquingKeysWith: { first, _ in first })tabs = rows.enumerated().compactMap { index, row inguard let id = row["id"] as? String else { return nil }let tab = previous[id] ?? SwarmTabButton(id: id)diff --git a/desktop/test/desk_sync_test.dart b/desktop/test/desk_sync_test.dartindex b72f65021..6b631a9bd 100644--- a/desktop/test/desk_sync_test.dart+++ b/desktop/test/desk_sync_test.dart@@ -835,6 +835,46 @@ void main() {expect(api.batches, isEmpty, reason: 'canonical geometry never echoes');});+ test('a tab this window keeps to itself that the desk also has is listed once', () async {+ // A draft (a New Tab, untouched) is not the desk's. When the desk has+ // its id anyway — this window shared it while an agent was being made+ // in it, and the agent never came — the tab was laid out twice: once in+ // the desk's order, once where this window had it. Native's tab strip+ // then trapped on the duplicate id and took the app down (1.2.57).+ final api = _DeskApi()+ ..doc = DeskDoc(+ revision: 1,+ tabs: [tab('d1', name: 'One', custom: true, agents: ['a1'])],+ );+ final app = createApp()..api = api;+ addTearDown(app.dispose);+ await app.deskStartForTest();+ app.newSwarm(draft: true, newTabPage: true);+ final draft = app.activeSwarmId;+ expect(app.isDraftSwarm(draft), isTrue);++ for (final revision in [9, 10]) {+ api.doc = DeskDoc(+ revision: revision,+ tabs: [+ tab('d1', name: 'One', custom: true, agents: ['a1']),+ tab(draft),+ ],+ );+ await app.handleEventForTest('m', {+ 'type': 'desk_changed',+ 'payload': {'revision': revision},+ });+ await Future<void>.delayed(Duration.zero);++ expect(+ app.swarms.map((s) => s.id),+ ['d1', draft],+ reason: 'rev $revision: once, where the desk has it',+ );+ }+ });+test('a document that did not move a tab\'s order leaves this window\'s tiles, sizes and pins alone', () async {final api = _DeskApi()..doc = DeskDoc(