From ac86981e9c6789b6da8df2753fd9bd38284e7841 Mon Sep 17 00:00:00 2001 From: kumarabhirup Date: Sat, 21 Feb 2026 11:44:52 -0800 Subject: [PATCH 1/2] dx: improve .env.example token placeholder (#37) Remove the hardcoded 'change-me' token value and leave OPENCLAW_GATEWAY_TOKEN empty so users are forced to set it. Added a clear comment with the openssl generation command and a note that Docker/Podman setup scripts auto-generate it. --- .env.example | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 8bc4defd4290d..c432341400ef9 100644 --- a/.env.example +++ b/.env.example @@ -15,8 +15,9 @@ # Gateway auth + paths # ----------------------------------------------------------------------------- # Recommended if the gateway binds beyond loopback. -OPENCLAW_GATEWAY_TOKEN=change-me-to-a-long-random-token -# Example generator: openssl rand -hex 32 +# Generate a secure random token: openssl rand -hex 32 +# Docker/Podman setup scripts auto-generate this if left empty. +OPENCLAW_GATEWAY_TOKEN= # Optional alternative auth mode (use token OR password). # OPENCLAW_GATEWAY_PASSWORD=change-me-to-a-strong-password From 1c8d93f2c8be8de42d163229188798c5ef7bae5a Mon Sep 17 00:00:00 2001 From: kumarabhirup Date: Sat, 21 Feb 2026 11:45:49 -0800 Subject: [PATCH 2/2] fix: add LRU eviction and expired-entry cleanup to web_fetch cache (#17) --- src/agents/tools/web-shared.ts | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/agents/tools/web-shared.ts b/src/agents/tools/web-shared.ts index da0fbb38bebc5..51beaac936655 100644 --- a/src/agents/tools/web-shared.ts +++ b/src/agents/tools/web-shared.ts @@ -35,6 +35,9 @@ export function readCache( cache.delete(key); return null; } + // Promote to most-recent position for LRU eviction. + cache.delete(key); + cache.set(key, entry); return { value: entry.value, cached: true }; } @@ -47,16 +50,33 @@ export function writeCache( if (ttlMs <= 0) { return; } + // Remove existing entry so .set() moves it to the end (LRU order). + cache.delete(key); if (cache.size >= DEFAULT_CACHE_MAX_ENTRIES) { - const oldest = cache.keys().next(); - if (!oldest.done) { - cache.delete(oldest.value); + // Evict expired entries first, then fall back to LRU (oldest insertion order). + const now = Date.now(); + let evicted = false; + for (const [k, v] of cache) { + if (now > v.expiresAt) { + cache.delete(k); + evicted = true; + if (cache.size < DEFAULT_CACHE_MAX_ENTRIES) { + break; + } + } + } + if (!evicted || cache.size >= DEFAULT_CACHE_MAX_ENTRIES) { + const oldest = cache.keys().next(); + if (!oldest.done) { + cache.delete(oldest.value); + } } } + const now = Date.now(); cache.set(key, { value, - expiresAt: Date.now() + ttlMs, - insertedAt: Date.now(), + expiresAt: now + ttlMs, + insertedAt: now, }); }