CODY-016, 017, 018: launch source cannot be missed; a failed idle exit is retried

CODY-016. The SDK pushes the launch source once, early. The Even adapter now
subscribes in its constructor, remembers the value and replays it to a
listener that subscribes later. appMenu still does not arm idle exit.

CODY-018. exitNow() returns whether the host confirmed. The adapter keeps at
most one shutdown call in flight (through the same queue as every other host
call), lets a repeat request wait on that call, and never calls the host
again after a confirmed exit, including one confirmed late. The controller
marks itself as gone only on confirmation or on a system_exit/abnormal_exit
event; otherwise it retries after 3 s, at most 4 attempts in a row, under the
same resting-screen and phone-grace guards, and starts again after activity.

CODY-017. README: one owner-reported locked-phone success; pocketed,
five-minute and ten-cycle runs unverified.

Tests: production-adapter tests with a stand-in host, including the default
30 s under a fake clock; a simulator scenario that performs the real exit
(development-only ?idleExit=fast). Not reviewed. 0.1.1 is not uploaded.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Dan
2026-11-21 14:38:29 -08:00
co-authored by Claude Fable 5.2
parent 1ae105ed18
commit bbde3c86a8
12 changed files with 679 additions and 42 deletions
+67
View File
@@ -707,6 +707,73 @@ describe('leaving the glasses when idle (the app blocks notifications while it i
expect(snapshot.log.some((e) => e.detail.includes('leaving the glasses: idle on answer'))).toBe(true);
});
it('an exit the host does not confirm is tried again, and a confirmed one is final', async () => {
controllerExtras = { idleExit: FAST, exitRetryMs: 60, exitAttempts: 4 };
await pairedController();
device.exitResults = [false, false];
device.launchedFrom('glassesMenu');
await until('left on the third attempt', () => device.exits === 1, 2000);
expect(device.exitAttempts).toBe(3);
await quiet(400);
expect(device.exitAttempts).toBe(3);
expect(snapshot.log.some((e) => e.detail === 'left the glasses')).toBe(true);
});
it('a host that keeps refusing is asked a bounded number of times, then again only after activity', async () => {
controllerExtras = { idleExit: FAST, exitRetryMs: 40, exitAttempts: 3 };
await pairedController();
device.exitResults = Array.from({ length: 10 }, () => false);
device.launchedFrom('glassesMenu');
await until('three attempts', () => device.exitAttempts === 3, 2000);
await quiet(500);
expect(device.exitAttempts).toBe(3);
expect(device.exits).toBe(0);
// A gesture is activity: the countdown and the attempts start again, and the app still works.
device.exitResults = [];
device.swipeDown();
await until('left after the next idle period', () => device.exits === 1, 2000);
expect(device.exitAttempts).toBe(4);
});
it('never leaves while a request is outstanding and the bridge cannot be reached', async () => {
controllerExtras = { idleExit: FAST };
await pairedController();
device.launchedFrom('glassesMenu');
h.hermes.next({ kind: 'complete', afterMs: 300, output: 'worth the wait' });
controller.askText('q');
await until('thinking', () => phase() === 'thinking' && h.hermes.executions === 1);
network.down = true;
await until('disconnected', () => phase() === 'disconnected');
await quiet(600); // four timeouts' worth
expect(phase()).toBe('disconnected');
expect(device.exitAttempts).toBe(0);
network.down = false;
await until('answer', () => phase() === 'answer');
await until('left once the answer had been shown and left alone', () => device.exits === 1, 2000);
});
it('once the glasses report the app closed, no idle exit is sent, and a failed one is not retried', async () => {
controllerExtras = { idleExit: FAST, exitRetryMs: 60, exitAttempts: 4 };
await pairedController();
device.launchedFrom('glassesMenu');
device.emit({ type: 'system_exit' });
await quiet(600);
expect(device.exitAttempts).toBe(0);
await controller.stop();
const stored = device.storage;
device = new FakeDevice();
for (const [k, v] of stored) device.storage.set(k, v);
controller = makeController(device);
await controller.start();
device.exitResults = Array.from({ length: 10 }, () => false);
device.launchedFrom('glassesMenu');
await until('first attempt refused', () => device.exitAttempts === 1, 2000);
device.emit({ type: 'abnormal_exit' });
await quiet(600);
expect(device.exitAttempts).toBe(1);
});
it('paging, or any gesture, restarts the countdown', async () => {
controllerExtras = { idleExit: FAST };
await pairedController();