diff --git a/src/status-watcher.js b/src/status-watcher.js index 2f953a3..8ed1732 100644 --- a/src/status-watcher.js +++ b/src/status-watcher.js @@ -379,6 +379,21 @@ class StatusWatcher extends EventEmitter { return; } + // OpenClaw cache-ttl custom record: reliable "turn complete" signal. + // Emitted after every assistant turn. Use it to fast-idle the session + // instead of waiting the full IDLE_TIMEOUT_S. + if (record.type === 'custom' && record.customType === 'openclaw.cache-ttl') { + if (state.pendingToolCalls === 0) { + // Turn is done — fast-idle: fire idle check after a short grace period (3s) + // to allow any trailing writes to flush before marking complete. + if (state.idleTimer) clearTimeout(state.idleTimer); + state.idleTimer = setTimeout(() => { + this._checkIdle(sessionKey); + }, 3000); + } + return; + } + // Legacy format fallback (for compatibility) var legacyType = record.type;