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.

Hotfix: New agent whose agent stopped says so and starts again, never a stuck request (#4709) (#3580)

0xken151f54ce426d2d
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index ee0291fdf..4204e92ac 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -2667,13 +2667,18 @@ class AppNotifier extends ChangeNotifier {
// Nothing will start for these either: a cancel that went through (its
// journal delete did not), or a harness that started and stopped again.
// Read as pending, Check status repeated "not started yet" forever.
- if (result['creationId'] == creationId &&
- (result['state'] == 'cancelled' || result['state'] == 'unavailable')) {
- throw SuperTabFailure(
+ if (result['creationId'] == creationId && result['state'] == 'cancelled') {
+ throw const SuperTabFailure(
'CREATION_FAILED',
- result['state'] == 'cancelled'
- ? 'This startup request was cancelled. Try again to start this project.'
- : 'The harness started and then stopped. Try again to start this project.',
+ 'This startup request was cancelled. Try again to start this project.',
+ );
+ }
+ // Its own code, so the request that started it can say what to do (hotfix #4709).
+ if (result['creationId'] == creationId &&
+ result['state'] == 'unavailable') {
+ throw const SuperTabFailure(
+ 'CREATION_STOPPED',
+ 'The harness started and then stopped. Start it again.',
);
}
if (result['creationId'] != creationId ||
diff --git a/desktop/lib/super_tabs/launch.dart b/desktop/lib/super_tabs/launch.dart
index 07ad55ae9..9eea8471e 100644
--- a/desktop/lib/super_tabs/launch.dart
+++ b/desktop/lib/super_tabs/launch.dart
@@ -347,9 +347,16 @@ class SuperTabLaunch {
try {
await launch.resume();
} on SuperTabFailure catch (failure) {
- if (failure.code == 'CREATION_FAILED') {
- saved.remove('phase');
- saved.remove('creationId');
+ if (failure.code == 'CREATION_FAILED' ||
+ failure.code == 'CREATION_STOPPED') {
+ // Nothing of that start joins: the next one is a new agent, with a join of its own
+ // (hotfix #4709).
+ saved
+ ..remove('phase')
+ ..remove('creationId')
+ ..remove('harnessId')
+ ..remove('command')
+ ..['joinId'] = superTabOperationId();
await launch.persist();
integration.pending = false;
integration.resume = null;
@@ -396,6 +403,12 @@ class SuperTabLaunch {
String machineNameOf(String machine) =>
app.stateOf(machine)?.machine.displayName ?? machine;
+ /// What a request whose harness stopped before it joined says (hotfix #4709): Start begins it again.
+ SuperTabFailure get stopped => SuperTabFailure(
+ 'CREATION_STOPPED',
+ 'The $who stopped on $machineName before it joined. Press Start to try again.',
+ );
+
String get startedNote =>
'The $who started on $machineName. Check status to add it to the project.';
String get waitingNote {
@@ -1354,6 +1367,9 @@ class SuperTabLaunch {
'Waiting for the new harness to appear on its machine.',
);
}
+ // Its machine still lists it, but it is not running: adding it would give the Swarm an agent that never answers
+ // (hotfix #4709).
+ if (native.isStopped) throw stopped;
// Whether it leads was read when the box opened. A project that got its
// Product Manager since keeps it: agent.add would make this one its lead
// (Hollis, review of #2803). This one was started as a PM, so it does not
@@ -1551,6 +1567,7 @@ class SuperTabLaunch {
if (const {
'ACCOUNT_CHANGED',
'AGENT_UNAVAILABLE',
+ 'CREATION_STOPPED',
'COORDINATOR_TAKEN',
'FILES_UNCONFIRMED',
}.contains(failure.code)) {
@@ -1598,6 +1615,7 @@ class SuperTabLaunch {
(saved['files'] as List? ?? const []).isEmpty,
);
} on SuperTabFailure catch (failure) {
+ if (failure.code == 'CREATION_STOPPED') throw stopped;
if (failure.code != 'CREATION_PENDING') rethrow;
throw SuperTabFailure(
'CREATION_PENDING',
diff --git a/desktop/test/super_tab_new_agent_launch_test.dart b/desktop/test/super_tab_new_agent_launch_test.dart
index fed4511de..f12f39d53 100644
--- a/desktop/test/super_tab_new_agent_launch_test.dart
+++ b/desktop/test/super_tab_new_agent_launch_test.dart
@@ -1,5 +1,6 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/state/new_harness.dart';
+import 'package:harness/super_tabs/controller.dart' show SuperTabFailure;
import 'package:harness/super_tabs/launch.dart';
import 'super_tab_launch_test.dart' show SuperTabLaunchFixture, tabId;
@@ -240,4 +241,90 @@ void main() {
expect(fresh.integration!.pending, isFalse);
});
});
+
+ // Hotfix #4709 (anh Dee, Mac 3): New agent ended at "The harness started on Mac 3. Check status to add it to the
+ // project." and nothing joined; Mac 3 ran no harness. A saved request whose agent is not running says so and Start
+ // begins again, and an own computer added in v2 (team-account only, no checkout) takes its person's agent.
+ group('a Member on a computer added in v2', () {
+ void v2Computer(SuperTabLaunchFixture f) =>
+ ((f.connection.server.state['machines'] ??= <dynamic>[]) as List).add({
+ 'machineId': 'm',
+ 'name': 'Mac 3',
+ 'contributorId': f.app.currentUser!.id,
+ 'teamAccountOnly': true,
+ 'observation': {
+ 'readiness': {'checkouts': <dynamic>[]},
+ },
+ });
+
+ test('joins on the first try', () async {
+ final f = SuperTabLaunchFixture();
+ v2Computer(f);
+ final box = await _newAgent(f);
+ expect(await box.create(), NewHarnessOutcome.created, reason: box.error);
+ final join = f.connection.joins.single['command'] as Map;
+ expect(join, containsPair('machineId', 'm'));
+ expect(join, containsPair('harnessId', 'native-lead'));
+ });
+
+ for (final (why, status) in [
+ ('stopped on its computer', <String, dynamic>{'state': 'unavailable'}),
+ (
+ 'listed but not running',
+ <String, dynamic>{
+ 'state': 'created',
+ 'agent': {
+ 'id': 'native-lead',
+ 'name': 'Claude Code',
+ 'engine': 'claude',
+ 'status': 'stopped',
+ },
+ },
+ ),
+ ]) {
+ test('a saved request whose agent $why says so, and Start starts it '
+ 'again', () async {
+ final f = SuperTabLaunchFixture();
+ v2Computer(f);
+ f.connection.failJoin = const SuperTabFailure(
+ 'INTERNAL_ERROR',
+ 'An internal server error occurred',
+ statusCode: 500,
+ );
+ final first = await _newAgent(f);
+ expect(await first.create(), NewHarnessOutcome.failed);
+ f.connection.creationRecovery = (type, payload) async => {
+ 'creationId': payload['creationId'],
+ ...status,
+ };
+ final again = await _newAgent(f);
+ expect(again.integration!.pending, isTrue);
+ expect(await again.create(), NewHarnessOutcome.failed);
+ expect(
+ again.error,
+ 'The harness stopped on Test host before it joined. Press Start to '
+ 'try again.',
+ );
+ expect(again.integration!.pending, isFalse);
+ expect(again.canDiscardPending, isFalse);
+ expect(f.connection.joins, hasLength(1));
+ f.connection.creationRecovery = null;
+ expect(
+ await again.create(),
+ NewHarnessOutcome.created,
+ reason: again.error,
+ );
+ expect(
+ f.connection.calls.where((c) => c.$1 == 'agent_create'),
+ hasLength(2),
+ );
+ expect(f.connection.joins, hasLength(2));
+ // Its own join, never the stopped one's replayed.
+ expect(
+ f.connection.joins.last['operationId'],
+ isNot(f.connection.joins.first['operationId']),
+ );
+ });
+ }
+ });
}