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 held harness clears within seconds once started, and takes typing meanwhile (#1119)
Deee6d5082d2ce0
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dartindex 39c2f57bc..bd6d275b6 100644--- a/desktop/lib/screens/swarm_screen.dart+++ b/desktop/lib/screens/swarm_screen.dart@@ -7428,7 +7428,6 @@ class _SwarmScreenState extends State<SwarmScreen> {agent != null &&agent.terminalAvailable &&agent.launchState != 'failed' &&- agent.launchState != 'held' &&machine.nodeOnline != false &&!(machine.isLocalMachine && !machine.usesLocalTransport) &&!(machine.isRemote && !machine.isLocalMachine && machine.needsLink) &&diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex fbd982d0c..a6e5f267f 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -3,7 +3,7 @@ import '../core/permission_modes.dart';import 'dart:async';import 'dart:io'show Directory, FileSystemEntity, FileSystemEntityType, Platform, exit, pid;-import 'dart:math' show Random;+import 'dart:math' show Random, min;import 'package:dio/dio.dart';@@ -349,7 +349,18 @@ class MachineState {// connect. The CLI owns E2EE entirely now; this is just "is trust established yet", not a// crypto/pairing state the app has any data for.bool needsLink = false;- List<Agent> agents = [];+ List<Agent> _agents = [];++ /// This machine's agents. Every change counts in [agentsRevision].+ List<Agent> get agents => _agents;+ set agents(List<Agent> value) {+ _agents = value;+ agentsRevision++;+ }++ /// Moves with every change of [agents]: a list read before one is older than it+ /// ([AppNotifier._syncAgentsIfChanged]).+ int agentsRevision = 0;AgentLoadStatus agentLoadStatus = AgentLoadStatus.idle;bool agentsRefreshing = false;String? agentsLoadError;@@ -922,6 +933,16 @@ class AppNotifier extends ChangeNotifier {// (agent_synced/agent_created/agent_renamed/agent_deleted) that normally keep it live — catches the// rare case a push event was dropped. Runs silently: see _syncAgentsIfChanged.final Map<String, Timer> _agentSyncTimers = {};++ /// Machines with a harness the daemon holds back ([_watchHeldLaunches]).+ final Map<String, Timer> _heldSyncTimers = {};++ /// Reads in a row that found nothing new, per machine ([_watchHeldLaunches]).+ final Map<String, int> _heldSyncRounds = {};++ /// How often a machine with a held harness is read again ([_watchHeldLaunches]).+ @visibleForTesting+ Duration heldLaunchSyncInterval = const Duration(seconds: 3);// Keeps the local `harness` daemon alive for the whole app run — started once after the first// successful bootstrap (see `ensureCliDaemonReady`), cancelled on dispose. Cancelling only stops this// Dart-side loop; the daemon itself self-daemonizes and must keep running after the app quits.@@ -7140,13 +7161,67 @@ class AppNotifier extends ChangeNotifier {void _stopAgentSyncTimer(String machineId) {_agentSyncTimers.remove(machineId)?.cancel();+ _heldSyncTimers.remove(machineId)?.cancel();+ _heldSyncRounds.remove(machineId);}void _stopAllAgentSyncTimers() {- for (final timer in _agentSyncTimers.values) {+ for (final timer in [+ ..._agentSyncTimers.values,+ ..._heldSyncTimers.values,+ ]) {timer.cancel();}_agentSyncTimers.clear();+ _heldSyncTimers.clear();+ _heldSyncRounds.clear();+ }++ /// Reads a machine's agents again while one of them is held: after [heldLaunchSyncInterval], then+ /// twice as long each time nothing changed, up to ten times it (3, 6, 12, 24, then 30 s), one read+ /// at a time.+ ///+ /// The daemon starts a held harness by itself (a conversation it could not yet verify, a move+ /// waiting for a turn to end), but the start reaches the app only with its next agent sync: on a+ /// fresh VM (2026-10-09) the reopened conversations ran for a minute under "Waiting", until the+ /// [agentSyncInterval] tick. The quiet re-read ([_syncAgentsIfChanged]) brings it within seconds;+ /// a hold that lasts (a turn running for minutes) costs a list every half minute.+ void _watchHeldLaunches(MachineState machine) {+ final machineId = machine.machine.machineId;+ final held =+ machine.connectionStatus == ConnectionStatus.connected &&+ machine.agents.any((agent) => agent.launchState == 'held');+ if (!held) {+ _heldSyncTimers.remove(machineId)?.cancel();+ _heldSyncRounds.remove(machineId);+ return;+ }+ if (_heldSyncTimers.containsKey(machineId)) return;+ final round = _heldSyncRounds[machineId] ?? 0;+ _heldSyncTimers[machineId] = Timer(+ heldLaunchSyncInterval * min(1 << min(round, 4), 10),+ () {+ final current = machineStates[machineId];+ if (current == null) {+ _heldSyncTimers.remove(machineId);+ _heldSyncRounds.remove(machineId);+ return;+ }+ final before = current.agentsRevision;+ unawaited(+ _syncAgentsIfChanged(current).whenComplete(() {+ if (_heldSyncTimers[machineId]?.isActive == false) {+ _heldSyncTimers.remove(machineId);+ }+ if (machineStates[machineId] != current) return;+ _heldSyncRounds[machineId] = current.agentsRevision == before+ ? round + 1+ : 0;+ _watchHeldLaunches(current);+ }),+ );+ },+ );}/// Silent safety-net reconciliation, ticked every [agentSyncInterval] while a machine is connected.@@ -7165,6 +7240,7 @@ class AppNotifier extends ChangeNotifier {}final connection = _conn(machine.machine.machineId);final nameRevision = machine._agentRevision;+ final listRevision = machine.agentsRevision;try {final response = await connection.request('agents_list',@@ -7174,6 +7250,8 @@ class AppNotifier extends ChangeNotifier {if (!_machineDiscoveryCurrent(machine, revision, discoveryRevision)) {return;}+ // A push that landed while this was asked is newer than the answer.+ if (machine.agentsRevision != listRevision) return;final agents = _agentSnapshot(machine,(response['agents'] as List<dynamic>? ?? [])@@ -9697,6 +9775,7 @@ class AppNotifier extends ChangeNotifier {_cancelTurnActivity(machine.machine.machineId, agentId);}machine.agents = agents;+ _watchHeldLaunches(machine);for (final agent in agents) {_reconcileAgentActivity(machine, agent, previous[agent.id]);if (previous[agent.id]?.name != agent.name) {@@ -9810,6 +9889,7 @@ class AppNotifier extends ChangeNotifier {}machine.agentLoadStatus = AgentLoadStatus.loaded;machine.agentsLoadError = null;+ _watchHeldLaunches(machine);_syncViewerPane(machine, agent);// A terminal that adopted an engine, or let one go: the tiles already// attached to it keep their stream and change their face. The dial'sdiff --git a/desktop/lib/widgets/pane_grid.dart b/desktop/lib/widgets/pane_grid.dartindex b11d75c2a..e4a3d082d 100644--- a/desktop/lib/widgets/pane_grid.dart+++ b/desktop/lib/widgets/pane_grid.dart@@ -1702,15 +1702,14 @@ class _PaneContent extends StatelessWidget {// Launch progress/failure describes the engine, not permission to// type into its terminal. Connection and control ownership still// gate input independently in TerminalPanel/TerminalSession.- // A held harness's terminal is the daemon's waiting shell, which- // ignores what is typed: nothing there reaches the agent.+ // A held harness stays writable: the app hears of the daemon starting+ // it a moment late, and the pane may already be the agent's.readOnly:machine == null ||needsLink ||offline ||agent == null ||- !agent.terminalAvailable ||- agent.launchState == 'held',+ !agent.terminalAvailable,notice: notice,onToggleComposer: () => notifier.toggleComposer(pane.id),onClose: single && !swarmMode ? null : close,diff --git a/desktop/test/held_launch_sync_test.dart b/desktop/test/held_launch_sync_test.dartnew file mode 100644index 000000000..1c1f855cc--- /dev/null+++ b/desktop/test/held_launch_sync_test.dart@@ -0,0 +1,160 @@+import 'dart:async';++import 'package:flutter_test/flutter_test.dart';+import 'package:harness/auth/auth_session.dart';+import 'package:harness/core/config.dart';+import 'package:harness/core/models.dart';+import 'package:harness/state/app_state.dart';+import 'package:harness/ws/ws_conn.dart';++/// A daemon that holds an agent back, then starts it: what `agents_list` answers is [state].+class _Daemon extends WsConn {+ _Daemon()+ : super(+ wsBaseUrl: 'ws://fixture.invalid',+ autonomousEnv: 'test',+ machineId: 'm',+ accessTokenProvider: (_, _) async => '',+ onAuthFailure: (_) {},+ onEvent: (_) {},+ onStatus: (_) {},+ );+ var state = 'held';+ var lists = 0;+ var inFlight = 0, mostInFlight = 0;++ /// When set, `agents_list` answers only when the test completes it, with the state at the ask.+ Completer<void>? gate;+ Map<String, dynamic> agent() => {+ 'id': 'a1',+ 'name': 'fix the dial scroll',+ 'engine': 'claude',+ 'terminal': {'available': true},+ 'launch': {+ 'state': state,+ if (state == 'held') 'service': 'search',+ if (state == 'held')+ 'detail': 'Waiting for the search service to verify this conversation.',+ },+ };+ @override+ Future<Map<String, dynamic>> request(+ String type, {+ Map<String, dynamic> payload = const {},+ Duration timeout = const Duration(seconds: 20),+ }) async {+ if (type != 'agents_list') return const {};+ lists++;+ final answer = agent();+ inFlight++;+ if (inFlight > mostInFlight) mostInFlight = inFlight;+ try {+ await gate?.future;+ } finally {+ inFlight--;+ }+ return {+ 'agents': [answer],+ };+ }+}++void main() {+ TestWidgetsFlutterBinding.ensureInitialized();++ late _Daemon daemon;+ late AppNotifier app;+ setUp(() {+ daemon = _Daemon();+ app = AppNotifier(+ config: AppConfig.dev,+ authSession: AuthSession(),+ configStore: null,+ connectionForTest: (_) => daemon,+ )..heldLaunchSyncInterval = const Duration(milliseconds: 20);+ const m = Machine(+ machineId: 'm',+ authMode: MachineAuthMode.remote,+ name: 'This Mac',+ );+ app.machines = [m];+ app.machineStates['m'] = MachineState(m)+ ..localOnly = true+ ..nodeOnline = true+ ..connectionStatus = ConnectionStatus.connected+ ..agentLoadStatus = AgentLoadStatus.loaded;+ });+ tearDown(() => app.dispose());++ Agent agent() => app.stateOf('m')!.agents.singleWhere((a) => a.id == 'a1');++ // On a fresh VM (2026-10-09) the daemon started reopened conversations it had held, and the app+ // showed them "Waiting" for a minute more: until its 60 s agent sync.+ test('a held harness is read again until the daemon has started it, then no more', () async {+ await app.handleEventForTest('m', {+ 'type': 'agent_synced',+ 'payload': {'agent': daemon.agent()},+ });+ expect(agent().launchState, 'held');+ await Future<void>.delayed(const Duration(milliseconds: 70));+ expect(daemon.lists, greaterThan(0), reason: 'read again while held');+ expect(agent().launchState, 'held');++ daemon.state = 'ready';+ // Backing off from 20 ms while nothing changed: 40, then 80 ms to the next read.+ await Future<void>.delayed(const Duration(milliseconds: 250));+ expect(agent().launchState, 'ready');+ final settled = daemon.lists;+ await Future<void>.delayed(const Duration(milliseconds: 100));+ expect(daemon.lists, settled, reason: 'nothing held: no more reads');+ });++ test(+ 'a read asked before a push is thrown away, and reads never overlap',+ () async {+ await app.handleEventForTest('m', {+ 'type': 'agent_synced',+ 'payload': {'agent': daemon.agent()},+ });+ daemon.gate = Completer<void>();+ // A read is asked while held, and answers only after the daemon's own push said ready.+ await Future<void>.delayed(const Duration(milliseconds: 100));+ expect(daemon.inFlight, 1);+ daemon.state = 'ready';+ await app.handleEventForTest('m', {+ 'type': 'agent_synced',+ 'payload': {'agent': daemon.agent()},+ });+ expect(agent().launchState, 'ready');+ daemon.gate!.complete();+ await Future<void>.delayed(const Duration(milliseconds: 50));+ expect(+ agent().launchState,+ 'ready',+ reason: 'the older "held" answer is not applied',+ );+ expect(daemon.mostInFlight, 1);+ },+ );++ test('backs off while nothing changes', () async {+ app.heldLaunchSyncInterval = const Duration(milliseconds: 10);+ await app.handleEventForTest('m', {+ 'type': 'agent_synced',+ 'payload': {'agent': daemon.agent()},+ });+ // 10, 20, 40, 80, then 100 ms apart: about five reads in 300 ms, not thirty.+ await Future<void>.delayed(const Duration(milliseconds: 300));+ expect(daemon.lists, inInclusiveRange(4, 7));+ });++ test('a machine with nothing held is not read again', () async {+ daemon.state = 'ready';+ await app.handleEventForTest('m', {+ 'type': 'agent_synced',+ 'payload': {'agent': daemon.agent()},+ });+ await Future<void>.delayed(const Duration(milliseconds: 100));+ expect(daemon.lists, 0);+ });+}diff --git a/desktop/test/pane_launch_failure_test.dart b/desktop/test/pane_launch_failure_test.dartindex 96d73fa6d..56dd57239 100644--- a/desktop/test/pane_launch_failure_test.dart+++ b/desktop/test/pane_launch_failure_test.dart@@ -199,10 +199,11 @@ void main() {);testWidgets(- 'a held harness whose waiting shell is up says Waiting, and takes no typing',+ 'a held harness whose waiting shell is up says Waiting, and still takes typing',(tester) async {- // The daemon's waiting pane is a live shell (`heldPaneArgv`) that ignores- // input: what is typed there would be lost.+ // The daemon's waiting pane is a live shell (`heldPaneArgv`). The app hears+ // of the start a moment after it, when the pane is already the agent's: a+ // VM run had the person locked out of a running agent under "Waiting".await app.handleEventForTest('m', {'type': 'agent_synced','payload': {@@ -225,7 +226,7 @@ void main() {expect(find.textContaining('close this pane to cancel'), findsWidgets);expect(tester.widget<TerminalPanel>(find.byType(TerminalPanel)).readOnly,- isTrue,+ isFalse,);await tester.pumpWidget(const SizedBox());},