tinyhumansai/openhuman · error

[ptt] cancel failed during preempt

Error message

[ptt] cancel failed during preempt

What it means

While starting a new push-to-talk session, a previous session was active and had to be preempted, but cancelling its audio capture (deps.audioCapture.cancel) threw. The warn is non-fatal to the new session — preemption continues and the new session claims the slot — but the old capture stream may still be running, potentially leaking microphone audio or producing a stale finalized session later.

Source

Thrown at app/src/services/pttService.ts:185

      threadId,
      heldMs: deps.now() - session.startedAtMs,
      finalizedByWatchdog: fromWatchdog,
      transcriptLen: trimmed.length,
    });
  };

  return {
    async onStart(sessionId) {
      // Preempt: if another session is active, cancel it.
      if (active) {
        deps.logger.debug('[ptt] onStart while active — preempting', {
          old: active.sessionId,
          new: sessionId,
        });
        try {
          await deps.audioCapture.cancel();
        } catch (err) {
          deps.logger.warn('[ptt] cancel failed during preempt', { err: String(err) });
        }
        if (active.watchdogTimer) clearTimeout(active.watchdogTimer);
        active = null;
      }

      // Claim the slot BEFORE any awaits so concurrent onStart calls preempt
      // this in-progress session rather than racing with it.
      active = {
        sessionId,
        startedAtMs: deps.now(),
        watchdogTimer: null,
        finalizedByWatchdog: false,
      };
      const claimed = active;

      await deps.playChime('open');
      await deps.showOverlay(true, sessionId);

View on GitHub (pinned to 7491200858)

Solutions

  1. Inspect err to determine whether the audio device was already stopped or the capture backend errored
  2. Check for orphaned capture sessions (a stale onStop for the old session is tolerated and logged as 'stale onStop — ignored')
  3. If preemption failures recur, verify the audio capture backend implementation handles cancel-while-starting and cancel-after-stop states
  4. Confirm microphone device state — a device that disappeared mid-session can make cancel fail
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at app/src/services/pttService.ts:185 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tinyhumansai/openhuman@7491200858 (2026-08-17). Data as JSON: /api/errors/13e49a3037b2aec9. Report an issue: GitHub.