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
Hotfix: New agent starts a Member instead of 'This project is no longer available' (#4647) (#3567)
0xken156a85ef31bff1
diff --git a/desktop/lib/super_tabs/account_keys.dart b/desktop/lib/super_tabs/account_keys.dartindex 910ccd2c6..791baa24b 100644--- a/desktop/lib/super_tabs/account_keys.dart+++ b/desktop/lib/super_tabs/account_keys.dart@@ -6,7 +6,7 @@ import '../core/local_key_value_store.dart';/// key that is no account's. What the web keeps of an account beside its/// saved views (docs/specs/2026-10-30-web-swarm-direct.md, Caching):/// - `super_tab.<account>.<swarm>`: unsent drafts, selection, what is open;-/// - `super_tab.launch.<account>.<tab>.<conversation>`: an unsent New Harness+/// - `super_tab.launch.<account>.<tab>.<conversation>` (+ New agent's: `<tab>` is `swarm:<swarm>`): an unsent New Harness/// or New Project;/// - `super_tab.hidden.<account>`: the Swarms hidden on this browser;/// - `super_tab.personal.<account>`: the Swarm last chosen in the switcher;diff --git a/desktop/lib/super_tabs/launch.dart b/desktop/lib/super_tabs/launch.dartindex 849603b89..07ad55ae9 100644--- a/desktop/lib/super_tabs/launch.dart+++ b/desktop/lib/super_tabs/launch.dart@@ -54,8 +54,20 @@ class SuperTabLaunch {if (account == null) {throw const SuperTabFailure('SIGNED_OUT', 'Sign in to create a Swarm.');}- final key = 'super_tab.launch.$account.${tab.id}.$conversationId';- final raw = await app.superTabs.storage.read(key);+ // + New agent keeps one request per Swarm, whichever tab opened it (hotfix #4647: one per tab piled up, and each+ // had to be discarded). A request an older Desktop kept under its tab moves to it.+ final perTab = 'super_tab.launch.$account.${tab.id}.$conversationId';+ final key = newAgent && tab.superTabId != null+ ? 'super_tab.launch.$account.swarm:${tab.superTabId}.$conversationId'+ : perTab;+ var raw = await app.superTabs.storage.read(key);+ if (raw == null && key != perTab) {+ raw = await app.superTabs.storage.read(perTab);+ if (raw != null) {+ await app.superTabs.storage.write(key, raw);+ await app.superTabs.storage.delete(perTab);+ }+ }if (app.currentUser?.id != account) {throw const SuperTabFailure('ACCOUNT_CHANGED', 'The account changed.');}@@ -1057,6 +1069,8 @@ class SuperTabLaunch {Future<void> persist() async {checkAccount();+ // A discarded request stays gone: a write still on its way must not bring it back (hotfix #4647).+ if (_dropped) return;await app.superTabs.storage.write(key, jsonEncode(saved));checkAccount();}@@ -1118,8 +1132,10 @@ class SuperTabLaunch {// deleted on another computer must not leave an unattached native session.final snapshot = await app.superTabs.readSnapshot(saved['tabId'] as String);checkAccount();+ final member = saved['newAgent'] == true && saved['lead'] != true;+ if (member) await _ensureMemberChat(snapshot, machine, engine);final conversationId = saved['conversationId'] as String;- if (snapshot.conversation(conversationId) == null) {+ if (!member && snapshot.conversation(conversationId) == null) {if (started) throw projectUnavailable;// Nothing can still be starting: reopening New Project should get a// fresh destination instead of loading this deleted project forever.@@ -1202,7 +1218,12 @@ class SuperTabLaunch {name = '$label $n';}saved['chatRequest'] = {- 'operationId': '${saved['operationId']}-chat',+ // A chat opened again after the last one went has an operation of its own: the same one would answer with the gone+ // chat's receipt (hotfix #4647).+ 'operationId': switch (saved['chatAgain']) {+ final int again => '${saved['operationId']}-chat-$again',+ _ => '${saved['operationId']}-chat',+ },'command': {'type': 'agent.new','kind': 'regular',@@ -1240,7 +1261,51 @@ class SuperTabLaunch {await persist();}+ /// A Member's own chat (hotfix #4647): a Swarm's first read can leave a quiet chat out, so only a read of the chat+ /// says whether it is gone. Gone, a fresh one opens: a Member has no project to lose, and the person is never left with+ /// nothing to do but discard. [snapshot] is read when not given.+ Future<void> _ensureMemberChat(+ SuperTabSnapshot? snapshot,+ String machine,+ String? engine,+ ) async {+ final chat = saved['conversationId'] as String?;+ if (chat == null) return;+ final read =+ snapshot ?? await app.superTabs.readSnapshot(saved['tabId'] as String);+ checkAccount();+ if (read.conversation(chat) != null || await _chatExists(chat)) return;+ saved+ ..remove('chatPrepared')+ ..remove('chatRequest')+ ..remove('conversationId')+ ..remove('command')+ ..['chatAgain'] = (saved['chatAgain'] as int? ?? 0) + 1;+ await persist();+ await _openMemberChat(machine, engine);+ }++ /// Whether the Swarm still has the chat [conversationId], by a read of the chat itself; a 404 or 403 says it is gone.+ Future<bool> _chatExists(String conversationId) async {+ try {+ await app.superTabs.map(+ 'GET',+ '/api/super-tabs/${saved['tabId']}/conversations/'+ '${Uri.encodeComponent(conversationId)}/messages',+ );+ return true;+ } on SuperTabFailure catch (failure) {+ if (failure.statusCode == 404 || failure.statusCode == 403) return false;+ rethrow;+ }+ }+// A started request's journal stays until the person discards it.+ static const memberChatUnavailable = SuperTabFailure(+ 'PROJECT_UNAVAILABLE',+ 'This agent’s chat is gone. Discard this request, then start the agent again.',+ );+static const projectUnavailable = SuperTabFailure('PROJECT_UNAVAILABLE','This project is no longer available. Discard this request, then create a new project.',@@ -1266,6 +1331,13 @@ class SuperTabLaunch {Agent? recovered,}) async {checkAccount();+ // A resumed start joins the chat this journal holds: make sure it is still there (hotfix #4647). A first start's+ // prepare has just checked it.+ if (recovered != null &&+ saved['newAgent'] == true &&+ saved['lead'] != true) {+ await _ensureMemberChat(null, machine, saved['engine'] as String?);+ }saved['machineId'] = machine;saved['harnessId'] = harnessId;saved['phase'] = 'joining';@@ -1452,7 +1524,10 @@ class SuperTabLaunch {// that warns first if it slows again (task #4196). No names or ids.if (saved['newAgentAt'] case final int at) {final ms = DateTime.now().millisecondsSinceEpoch - at;- appLog.info('super-tabs', 'New agent (${saved['agentKind']}) running in $ms ms');+ appLog.info(+ 'super-tabs',+ 'New agent (${saved['agentKind']}) running in $ms ms',+ );}await app.superTabs.storage.delete(key);}@@ -1467,8 +1542,12 @@ class SuperTabLaunch {try {await complete(machine, harnessId, recovered: recovered);} on SuperTabFailure catch (failure) {- // The backend no longer has the project's conversation.- if (failure.code == 'NOT_FOUND') throw projectUnavailable;+ // The backend no longer has the conversation: a Member's own chat has no project to create again (#4647).+ if (failure.code == 'NOT_FOUND') {+ throw saved['newAgent'] == true && saved['lead'] != true+ ? memberChatUnavailable+ : projectUnavailable;+ }if (const {'ACCOUNT_CHANGED','AGENT_UNAVAILABLE',@@ -1579,11 +1658,15 @@ class SuperTabLaunch {await _deleteEmptyProject();await _archiveEmptyChat();}+ _dropped = true;await app.superTabs.storage.delete(key);checkAccount();return null;}+ /// Set once [discard] dropped the request: [persist] then writes nothing.+ bool _dropped = false;+/// A Member's chat nothing joined is archived. Best effort, as below: the/// person can still archive it from the chat.Future<void> _archiveEmptyChat() async {diff --git a/desktop/test/super_tab_new_agent_launch_test.dart b/desktop/test/super_tab_new_agent_launch_test.dartindex 886dac81b..fed4511de 100644--- a/desktop/test/super_tab_new_agent_launch_test.dart+++ b/desktop/test/super_tab_new_agent_launch_test.dart@@ -63,9 +63,11 @@ void main() {'name': 'Claude Code','local': true,});- final chatId = f.connection.server.state['conversations']- .cast<Map>()- .firstWhere((g) => g['kind'] == 'agent-chat')['id'] as String;+ final chatId =+ f.connection.server.state['conversations'].cast<Map>().firstWhere(+ (g) => g['kind'] == 'agent-chat',+ )['id']+ as String;final create = f.connection.calls.firstWhere((c) => c.$1 == 'agent_create').$2;@@ -104,7 +106,10 @@ void main() {expect(await box.create(), NewHarnessOutcome.failed);expect(await box.create(), NewHarnessOutcome.created, reason: box.error);expect(_commands(f).where((c) => c['type'] == 'agent.new'), hasLength(1));- expect(f.connection.calls.where((c) => c.$1 == 'agent_create'), hasLength(1));+ expect(+ f.connection.calls.where((c) => c.$1 == 'agent_create'),+ hasLength(1),+ );final joins = f.connection.joins.map((j) => j['operationId']).toSet();expect(joins, hasLength(1));});@@ -115,32 +120,124 @@ void main() {expect(await box.create(), NewHarnessOutcome.failed);f.connection.failCreation = false;final again = await _newAgent(f);- expect(await again.create(), NewHarnessOutcome.created, reason: again.error);+ expect(+ await again.create(),+ NewHarnessOutcome.created,+ reason: again.error,+ );expect(_commands(f).where((c) => c['type'] == 'agent.new'), hasLength(1));expect(f.connection.joins, hasLength(1));});- test('Discard of a start that never ran archives the Member’s chat', () async {- final f = SuperTabLaunchFixture()..connection.loseCreate = true;- f.connection.creationRecovery = (type, payload) async => {- 'creationId': payload['creationId'],- 'state': type == 'agent_create_cancel' ? 'cancelled' : 'missing',- };- final box = await _newAgent(f);- expect(await box.create(), NewHarnessOutcome.failed);- final chatId = f.connection.server.state['conversations']- .cast<Map>()- .firstWhere((g) => g['kind'] == 'agent-chat')['id'];- final recovered = await _newAgent(f);- expect(recovered.integration!.agentKindLocked, isTrue);- expect(await recovered.integration!.discard!(), isNull);- final archive = _commands(- f,- ).singleWhere((c) => c['type'] == 'conversation.archive');- expect(archive, {- 'type': 'conversation.archive',- 'conversationId': chatId,- 'archived': true,+ test(+ 'Discard of a start that never ran archives the Member’s chat',+ () async {+ final f = SuperTabLaunchFixture()..connection.loseCreate = true;+ f.connection.creationRecovery = (type, payload) async => {+ 'creationId': payload['creationId'],+ 'state': type == 'agent_create_cancel' ? 'cancelled' : 'missing',+ };+ final box = await _newAgent(f);+ expect(await box.create(), NewHarnessOutcome.failed);+ final chatId = f.connection.server.state['conversations']+ .cast<Map>()+ .firstWhere((g) => g['kind'] == 'agent-chat')['id'];+ final recovered = await _newAgent(f);+ expect(recovered.integration!.agentKindLocked, isTrue);+ expect(await recovered.integration!.discard!(), isNull);+ final archive = _commands(f)+ .singleWhere((c) => c['type'] == 'conversation.archive');+ expect(archive, {+ 'type': 'conversation.archive',+ 'conversationId': chatId,+ 'archived': true,+ });+ },+ );++ // Hotfix #4647 (anh Dee 19:55): New agent stopped with "This project is no longer available. Discard this request,+ // then create a new project." The check before the start looked for the Member's new chat in a fresh read of the+ // Swarm, and a read can leave a quiet chat out; a Member has no project to create, either.+ group('a Member whose chat the Swarm\'s read leaves out', () {+ test('still starts and joins its chat', () async {+ final f = SuperTabLaunchFixture();+ f.connection.server.newAgentChatsDormant = true;+ final box = await _newAgent(f);+ expect(await box.create(), NewHarnessOutcome.created, reason: box.error);+ final chatId =+ f.connection.server.state['conversations'].cast<Map>().firstWhere(+ (g) => g['kind'] == 'agent-chat',+ )['id']+ as String;+ final join = f.connection.joins.single['command'] as Map;+ expect(join, containsPair('conversationId', chatId));+ expect(_commands(f).where((c) => c['type'] == 'agent.new'), hasLength(1));+ });++ test('a saved attempt whose chat is gone opens a fresh chat, never a dead '+ 'end', () async {+ final f = SuperTabLaunchFixture()..connection.failCreation = true;+ f.connection.server.chatsGoneAreNotFound = true;+ final first = await _newAgent(f);+ expect(await first.create(), NewHarnessOutcome.failed);+ final chats = f.connection.server.state['conversations'] as List;+ chats.removeWhere((g) => (g as Map)['kind'] == 'agent-chat');+ f.connection.failCreation = false;+ final again = await _newAgent(f);+ final outcome = await again.create();+ expect(outcome, NewHarnessOutcome.created, reason: again.error);+ expect(again.error ?? '', isNot(contains('project')));+ expect(_commands(f).where((c) => c['type'] == 'agent.new'), hasLength(2));+ final chatId =+ chats.cast<Map>().firstWhere((g) => g['kind'] == 'agent-chat')['id']+ as String;+ final join = f.connection.joins.single['command'] as Map;+ expect(join, containsPair('conversationId', chatId));+ });+ });++ // anh Dee 20:00 (hotfix #4647): after the failed start, 'Remove this request?' came back until he pressed Discard+ // anyway three times. One New agent request is kept per Swarm, whichever tab opened it, and one Discard clears it.+ group('Discard', () {+ String perTab(SuperTabLaunchFixture f) =>+ 'super_tab.launch.${f.app.currentUser!.id}.${f.app.activeSwarm.id}.new-agent';++ test('one press clears the request, and it never comes back', () async {+ final f = SuperTabLaunchFixture()..connection.failCreation = true;+ final first = await _newAgent(f);+ expect(await first.create(), NewHarnessOutcome.failed);+ final recovered = await _newAgent(f);+ final integration = recovered.integration!;+ expect(integration.pending, isTrue);+ expect(await recovered.discardPending(anyway: true), isNull);+ expect(recovered.discarded, isTrue);+ // A late write of the dropped request does not bring it back.+ await integration.beforeSubmit('m', 'late');+ final fresh = await _newAgent(f);+ expect(fresh.integration!.pending, isFalse);+ expect(fresh.canDiscardPending, isFalse);+ });++ test('a request a tab kept before this fix is the one request, and one '+ 'press clears it', () async {+ final f = SuperTabLaunchFixture()..connection.failCreation = true;+ final first = await _newAgent(f);+ expect(await first.create(), NewHarnessOutcome.failed);+ // Move the kept request to where an older Desktop kept it, under its tab.+ final storage = f.app.superTabs.storage;+ final swarmKey =+ 'super_tab.launch.${f.app.currentUser!.id}.swarm:$tabId.new-agent';+ final saved = await storage.read(swarmKey);+ expect(saved, isNotNull);+ await storage.write(perTab(f), saved!);+ await storage.delete(swarmKey);+ final recovered = await _newAgent(f);+ expect(recovered.integration!.pending, isTrue);+ expect(await recovered.discardPending(anyway: true), isNull);+ expect(await storage.read(perTab(f)), isNull);+ expect(await storage.read(swarmKey), isNull);+ final fresh = await _newAgent(f);+ expect(fresh.integration!.pending, isFalse);});});}diff --git a/desktop/test/support/super_tab_fixture.dart b/desktop/test/support/super_tab_fixture.dartindex 4090ae9c1..8b9b813b6 100644--- a/desktop/test/support/super_tab_fixture.dart+++ b/desktop/test/support/super_tab_fixture.dart@@ -595,6 +595,14 @@ class ConversationServer {/// The leaderboard read's answer; reads of it are listed in [leaderboardReads].Map<String, dynamic>? leaderboard;++ /// A Member's own chat that agent.new opens is left out of a Swarm's first load, as a big Swarm's read can leave out+ /// a quiet chat (hotfix #4647): only a read of the chat itself finds it.+ bool newAgentChatsDormant = false;++ /// A read of a chat's messages the Swarm no longer has answers 404; off, the older tests' reads of chats they never+ /// listed keep their empty pages.+ bool chatsGoneAreNotFound = false;final leaderboardReads = <String>[];/// Answers by the read's path instead of [leaderboard], as a server does.@@ -1762,6 +1770,7 @@ class ConversationServer {{'id': 'owner', 'generation': 'g'},],},+ if (newAgentChatsDormant) 'dormant': true,});output['conversationId'] = id;} else if (command['type'] == 'project.create') {@@ -2199,6 +2208,13 @@ class ConversationServer {if (uri.pathSegments.last == 'messages') {onRead?.call(path);final conversationId = uri.pathSegments[4];+ // A chat the Swarm no longer has is not found, as the backend answers (hotfix #4647).+ if (chatsGoneAreNotFound &&+ !(state['conversations'] as List).any(+ (g) => (g as Map)['id'] == conversationId,+ )) {+ throw const SuperTabFailure('NOT_FOUND', 'Not found.', statusCode: 404);+ }final query = uri.queryParameters;final after = int.tryParse(query['after'] ?? '');final before = int.tryParse(query['before'] ?? '');