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(mobile): a resume the machine never received is sent again, not checked for ever
dee820b6db0b564
diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dartindex 75c36cc54..e7529cf48 100644--- a/mobile/lib/state/app_state.dart+++ b/mobile/lib/state/app_state.dart@@ -5566,19 +5566,38 @@ class AppNotifier extends ChangeNotifier {const unconfirmed = RestartAgentResult(error: 'The machine has not confirmed the resume yet. Tap the harness again to check.',);- final Map<String, dynamic> result;+ Future<Map<String, dynamic>> resume() => _conn(machine.machine.machineId)+ .request(+ 'agent_resume',+ payload: {'creationId': receipt, 'agentId': stopped.id},+ );+ // Whether the request whose answer is being read is `agent_resume` itself —+ // its refusals are final — rather than a status check.+ var resuming = checking == null;+ Map<String, dynamic> result;try {- result = await _conn(machine.machine.machineId).request(- checking == null ? 'agent_resume' : 'agent_create_status',- payload: {- 'creationId': receipt,- if (checking == null) 'agentId': stopped.id,- },- );+ result = resuming+ ? await resume()+ : await _conn(+ machine.machine.machineId,+ ).request('agent_create_status', payload: {'creationId': receipt});+ // ⚠️ **`missing` is the machine never having heard of it — the desktop's+ // rule.** The first send can fail before it leaves the phone (a socket+ // mid-redial is the usual way), and then every check after it answers+ // `missing`, for ever: the agent could not be resumed from this phone+ // again until the app restarted. So the SAME intent is sent again. The+ // daemon reserves a receipt before it launches anything, so a delayed+ // original and this replay cannot both open a terminal.+ if (!resuming &&+ result['creationId'] == receipt &&+ result['state'] == 'missing') {+ resuming = true;+ result = await resume();+ }} on WsRequestFailure catch (failure) {- // A refusal to a first send happened before anything launched; anything else — a timeout,+ // A refusal to a resume happened before anything launched; anything else — a timeout,// INTERNAL, a status check the machine cannot answer — leaves the outcome unknown.- if (checking != null || failure.code == 'INTERNAL') return unconfirmed;+ if (!resuming || failure.code == 'INTERNAL') return unconfirmed;return settle(_resumeFailure(failure.code, failure.detail));} catch (_) {return unconfirmed;diff --git a/mobile/test/app_state_agent_rpcs_test.dart b/mobile/test/app_state_agent_rpcs_test.dartindex 1a188f489..4e7516990 100644--- a/mobile/test/app_state_agent_rpcs_test.dart+++ b/mobile/test/app_state_agent_rpcs_test.dart@@ -743,6 +743,66 @@ void main() {});}+ test('a resume the machine never received is sent again, under the same receipt', () async {+ final rig = await withStopped();+ addTearDown(rig.app.dispose);+ // The socket was down: the request never left the phone.+ rig.conn('m').answers['agent_resume'] = (_) =>+ throw StateError('WS disconnected');+ expect((await rig.app.resumeAgent('m', 'a')).error, isNotNull);+ final receipt = rig+ .conn('m')+ .payloadsOf('agent_resume')+ .single['creationId'];++ // So the machine has no record of it — and never will.+ rig.conn('m').answers['agent_create_status'] = (p) => {+ 'creationId': p['creationId'],+ 'state': 'missing',+ };+ rig.conn('m').answers['agent_resume'] = (p) => {+ 'creationId': p['creationId'],+ 'state': 'created',+ 'agent': agentJson('a', sessionId: 's-a'),+ };++ final retried = await rig.app.resumeAgent('m', 'a');++ expect(retried.error, isNull);+ final resumes = rig.conn('m').payloadsOf('agent_resume');+ expect(resumes, hasLength(2));+ expect(resumes.last, {'creationId': receipt, 'agentId': 'a'});+ expect(rig.app.stateOf('m')!.agents.single.terminalAvailable, isTrue);+ });++ test(+ 'a replayed resume that is still lost is checked again next time',+ () async {+ final rig = await withStopped();+ addTearDown(rig.app.dispose);+ rig.conn('m').answers['agent_resume'] = (_) =>+ throw StateError('WS disconnected');+ await rig.app.resumeAgent('m', 'a');+ rig.conn('m').answers['agent_create_status'] = (p) => {+ 'creationId': p['creationId'],+ 'state': 'missing',+ };++ expect((await rig.app.resumeAgent('m', 'a')).error, isNotNull);+ await rig.app.resumeAgent('m', 'a');++ expect(rig.conn('m').payloadsOf('agent_create_status'), hasLength(2));+ expect(+ {+ for (final p in rig.conn('m').payloadsOf('agent_resume'))+ p['creationId'],+ },+ hasLength(1),+ reason: 'one intent, however many times it is sent',+ );+ },+ );+test('an INTERNAL answer leaves it to be checked', () async {final rig = await withStopped();addTearDown(rig.app.dispose);