CODY-019: a failed exit no longer overwrites a countdown restarted by activity
An exit attempt remembered only the reducer generation. A gesture that changes no state (a swipe at Ready) restarted the 30 s countdown, but when the pending host call then failed, the 3 s retry replaced that timer. The controller now counts every restart of the normal countdown (gesture, state change, phone activity) in an activity epoch, captures it when an attempt starts, and schedules no retry if it has moved. Bounded attempts, late-success memory, exit-event finality and one host call at a time are unchanged. Not reviewed. 0.1.1 is not uploaded. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -158,6 +158,13 @@ export class Controller {
|
||||
private leaving = false;
|
||||
/** Unconfirmed exit attempts since the last activity. */
|
||||
private exitFailures = 0;
|
||||
/**
|
||||
* Counts every restart of the normal countdown: a gesture, a state change, a touch on the
|
||||
* phone page. Reducer generation is not enough, because a gesture can change no state (a
|
||||
* swipe at Ready). An exit attempt that started before the latest activity must not schedule
|
||||
* its short retry over the countdown that activity restarted.
|
||||
*/
|
||||
private activityEpoch = 0;
|
||||
/** Set while a long press that STARTED a recording is still held down. */
|
||||
private heldPress: { generation: number; at: number } | null = null;
|
||||
|
||||
@@ -397,7 +404,10 @@ export class Controller {
|
||||
if (this.idleTimer) clearTimeout(this.idleTimer);
|
||||
this.idleTimer = null;
|
||||
// Anything other than our own retry is activity: the full wait and the attempt count restart.
|
||||
if (!retry) this.exitFailures = 0;
|
||||
if (!retry) {
|
||||
this.exitFailures = 0;
|
||||
this.activityEpoch += 1;
|
||||
}
|
||||
if (this.stopped || this.exited || !this.idleExitMs || !this.idleArmed || !this.hudReady) return;
|
||||
const phase = this.state.phase;
|
||||
const wait =
|
||||
@@ -425,7 +435,7 @@ export class Controller {
|
||||
private async leaveGlasses(reason: string): Promise<void> {
|
||||
if (this.exited || this.leaving) return;
|
||||
this.leaving = true;
|
||||
const generation = this.state.generation;
|
||||
const epoch = this.activityEpoch;
|
||||
this.note('lifecycle', `leaving the glasses: ${reason}`);
|
||||
this.emit();
|
||||
let confirmed = false;
|
||||
@@ -447,9 +457,11 @@ export class Controller {
|
||||
return;
|
||||
}
|
||||
// Not confirmed: refused, failed, or no answer in time. We are still on the glasses as far
|
||||
// as we know, so this must not be final. If the user did something meanwhile, their activity
|
||||
// already restarted the full countdown; otherwise try again, a bounded number of times.
|
||||
if (this.state.generation !== generation) return;
|
||||
// as we know, so this must not be final. If anything happened meanwhile (a gesture, even one
|
||||
// that changed no state, or a touch on the phone page), that activity already restarted the
|
||||
// full countdown or the phone grace period, and that timer stands: no short retry replaces
|
||||
// it. Otherwise try again, a bounded number of times.
|
||||
if (this.activityEpoch !== epoch) return;
|
||||
this.exitFailures += 1;
|
||||
if (this.exitFailures >= this.exitAttempts) {
|
||||
this.note('lifecycle', `the host did not confirm leaving after ${this.exitFailures} attempts; staying until the next activity`);
|
||||
|
||||
Reference in New Issue
Block a user