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.

fix(mobile): a terminal switched off by an unanswered negotiation is asked about again

dee8127297f579d
diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dart
index 42646e5e8..066f5c422 100644
--- a/mobile/lib/state/app_state.dart
+++ b/mobile/lib/state/app_state.dart
@@ -201,6 +201,11 @@ class MachineState {
bool terminalCapabilityLoaded = false;
bool terminalCapabilityAvailable = false;
String? terminalCapabilityError;
+
+ /// The negotiation got no answer — a timeout, a dropped socket — rather than the machine saying
+ /// no. That is not a fact about the machine, so the next sync that does get an answer asks again
+ /// (see `_syncAgentsIfChanged`); a refusal or `available: false` is an answer, and stands.
+ bool terminalCapabilityUnanswered = false;
// Whether this machine's CLI daemon understands `terminal_paste` (a clipboard paste delivered as
// one atomic tmux paste-buffer, not chunked like ordinary keystrokes — see TerminalSession.pasteText).
// False for any CLI published before this existed; the panel falls back to the old chunked path.
@@ -3390,6 +3395,11 @@ class AppNotifier extends ChangeNotifier {
);
_agentSyncTimeouts.remove(machineId);
if (!_machineWorkCurrent(machine, revision)) return;
+ // ⚠️ A terminal switched off by a negotiation that never got an answer stayed off until
+ // the next reconnect: the machine answered this, so the link is up — ask again.
+ if (machine.terminalCapabilityUnanswered) {
+ unawaited(_loadTerminalCapabilities(machine, connection, revision));
+ }
final agents = (response['agents'] as List<dynamic>? ?? [])
.map((item) => Agent.fromJson(item as Map<String, dynamic>))
.toList();
@@ -4401,6 +4411,7 @@ class AppNotifier extends ChangeNotifier {
Map<String, dynamic> result,
) {
machine.terminalCapabilityLoaded = true;
+ machine.terminalCapabilityUnanswered = false;
machine.terminalCapabilityAvailable =
result['protocolVersion'] == TerminalSession.protocolVersion &&
result['backend'] == 'tmux' &&
@@ -4442,9 +4453,10 @@ class AppNotifier extends ChangeNotifier {
if (machine.terminalCapabilityAvailable) {
_machineCache?.rememberCapabilities(machine.machine.machineId, result);
}
- } catch (_) {
+ } catch (error) {
if (!_machineWorkCurrent(machine, revision)) return;
machine.terminalCapabilityLoaded = true;
+ machine.terminalCapabilityUnanswered = error is! WsRequestFailure;
machine.terminalCapabilityAvailable = false;
machine.terminalCapabilityError = 'Could not negotiate terminal protocol';
machine.terminalPasteRawAvailable = false;
diff --git a/mobile/test/app_state_machines_test.dart b/mobile/test/app_state_machines_test.dart
index d21b2a1d2..07c3b2674 100644
--- a/mobile/test/app_state_machines_test.dart
+++ b/mobile/test/app_state_machines_test.dart
@@ -430,6 +430,55 @@ void main() {
expect(machine.terminalNoTakeoverAvailable, isFalse);
});
+ test('a negotiation that got no answer is asked again once the machine answers', () async {
+ final rig = viewerApp();
+ addTearDown(rig.app.dispose);
+ rig.api.onMachines = () async => [remoteMachine('m')];
+ rig.conn('m').answers['agents_list'] = (_) => {'agents': <Object>[]};
+ rig.conn('m').answers['terminal_capabilities'] = (_) =>
+ throw const WsRequestTimeout('terminal_capabilities');
+
+ await rig.app.bootstrap();
+ await settle();
+ final machine = rig.app.stateOf('m')!;
+ expect(machine.terminalCapabilityAvailable, isFalse);
+ expect(machine.terminalCapabilityUnanswered, isTrue);
+
+ // The link comes good; the minute's sync gets its answer and asks again. Set on the state
+ // itself: announcing the connection would reload the machine and ask for another reason.
+ machine.connectionStatus = ConnectionStatus.connected;
+ rig.conn('m').answers['terminal_capabilities'] = (_) => capabilities();
+ await rig.app.syncAgentsForTest('m');
+ await settle();
+ expect(machine.terminalCapabilityAvailable, isTrue);
+ expect(machine.terminalCapabilityUnanswered, isFalse);
+ });
+
+ test('a refusal is an answer: the sync does not ask again', () async {
+ final rig = viewerApp();
+ addTearDown(rig.app.dispose);
+ rig.api.onMachines = () async => [remoteMachine('m')];
+ rig.conn('m').answers['agents_list'] = (_) => {'agents': <Object>[]};
+ rig.conn('m').answers['terminal_capabilities'] = (_) =>
+ throw refusal('UNSUPPORTED');
+
+ await rig.app.bootstrap();
+ await settle();
+ rig.app.stateOf('m')!.connectionStatus = ConnectionStatus.connected;
+ final asked = rig
+ .conn('m')
+ .requests
+ .where((r) => r.$1 == 'terminal_capabilities')
+ .length;
+ await rig.app.syncAgentsForTest('m');
+ await settle();
+ expect(
+ rig.conn('m').requests.where((r) => r.$1 == 'terminal_capabilities'),
+ hasLength(asked),
+ );
+ expect(rig.app.stateOf('m')!.terminalCapabilityUnanswered, isFalse);
+ });
+
test('a machine with tmux gone says so', () async {
final rig = viewerApp();
addTearDown(rig.app.dispose);