From 5a657130c962ed625ab4f87f77c370e016c8d1b5 Mon Sep 17 00:00:00 2001 From: paisley <8197966+su8su@users.noreply.github.com> Date: Wed, 18 Mar 2026 11:10:05 +0800 Subject: [PATCH] feat: set default session retention to 7 days (#565) --- electron/gateway/config-sync.ts | 8 ++++++- electron/utils/openclaw-auth.ts | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/electron/gateway/config-sync.ts b/electron/gateway/config-sync.ts index 31454f78e..ee82ce03a 100644 --- a/electron/gateway/config-sync.ts +++ b/electron/gateway/config-sync.ts @@ -9,7 +9,7 @@ import { getProviderEnvVar, getKeyableProviderTypes } from '../utils/provider-re import { getOpenClawDir, getOpenClawEntryPath, isOpenClawPresent } from '../utils/paths'; import { getUvMirrorEnv } from '../utils/uv-env'; import { listConfiguredChannels } from '../utils/channel-config'; -import { syncGatewayTokenToConfig, syncBrowserConfigToOpenClaw, sanitizeOpenClawConfig } from '../utils/openclaw-auth'; +import { syncGatewayTokenToConfig, syncBrowserConfigToOpenClaw, syncSessionIdleMinutesToOpenClaw, sanitizeOpenClawConfig } from '../utils/openclaw-auth'; import { buildProxyEnv, resolveProxySettings } from '../utils/proxy'; import { syncProxyConfigToOpenClaw } from '../utils/openclaw-proxy'; import { logger } from '../utils/logger'; @@ -152,6 +152,12 @@ export async function syncGatewayConfigBeforeLaunch( } catch (err) { logger.warn('Failed to sync browser config to openclaw.json:', err); } + + try { + await syncSessionIdleMinutesToOpenClaw(); + } catch (err) { + logger.warn('Failed to sync session idle minutes to openclaw.json:', err); + } } async function loadProviderEnv(): Promise<{ providerEnv: Record; loadedProviderKeyCount: number }> { diff --git a/electron/utils/openclaw-auth.ts b/electron/utils/openclaw-auth.ts index 730cf59a9..e413c39f4 100644 --- a/electron/utils/openclaw-auth.ts +++ b/electron/utils/openclaw-auth.ts @@ -826,6 +826,45 @@ export async function syncBrowserConfigToOpenClaw(): Promise { }); } +/** + * Ensure session idle-reset is configured in ~/.openclaw/openclaw.json. + * + * By default OpenClaw resets the "main" session daily at 04:00 local time, + * which means conversations disappear after roughly one day. ClawX sets + * `session.idleMinutes` to 10 080 (7 days) so that conversations are + * preserved for a week unless the user has explicitly configured their own + * value. When `idleMinutes` is set without `session.reset` / + * `session.resetByType`, OpenClaw stays in idle-only mode (no daily reset). + */ +export async function syncSessionIdleMinutesToOpenClaw(): Promise { + const DEFAULT_IDLE_MINUTES = 10_080; // 7 days + + return withConfigLock(async () => { + const config = await readOpenClawJson(); + + const session = ( + config.session && typeof config.session === 'object' + ? { ...(config.session as Record) } + : {} + ) as Record; + + // Only set idleMinutes if the user has not configured it yet. + if (session.idleMinutes !== undefined) return; + + // If the user has explicit reset / resetByType / resetByChannel config, + // they are actively managing session lifecycle — don't interfere. + if (session.reset !== undefined + || session.resetByType !== undefined + || session.resetByChannel !== undefined) return; + + session.idleMinutes = DEFAULT_IDLE_MINUTES; + config.session = session; + + await writeOpenClawJson(config); + console.log(`Synced session.idleMinutes=${DEFAULT_IDLE_MINUTES} (7d) to openclaw.json`); + }); +} + /** * Update a provider entry in every discovered agent's models.json. */