fix: fast-idle session on openclaw.cache-ttl (turn complete signal)

Previously the daemon waited IDLE_TIMEOUT_S (60s) after the last file
change before marking a session complete. But the JSONL file is kept
open by the gateway indefinitely, so file inactivity was never reliable.

Fix: detect the 'openclaw.cache-ttl' custom record which the gateway
emits after every completed assistant turn. When pendingToolCalls == 0,
start a 3-second grace timer instead of the full 60s idle timeout.

Result: live status clears within ~3 seconds of the agent's final reply
instead of lingering for 60+ seconds (or indefinitely on active sessions).

Fixes: session stays 'active' long after work is done
This commit is contained in:
sol
2026-03-09 15:26:14 +00:00
parent 3e93e40109
commit b7c5124081

View File

@@ -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;