-
-
Notifications
You must be signed in to change notification settings - Fork 69.5k
Bug: Daily session reset does not clear bootstrap file cache — workspace files become stale #38494
Description
Bug: Daily session reset does not clear bootstrap file cache — workspace files become stale
Summary
Workspace bootstrap files (MEMORY.md, USER.md, etc.) are cached in-memory per sessionKey but the daily session reset only rotates sessionId, not sessionKey. This means the bootstrap file cache is never invalidated by daily resets, causing the agent to see stale workspace file content indefinitely until the gateway process restarts.
Steps to Reproduce
- Start the gateway (files are loaded from disk on first session run and cached)
- Modify a workspace file (e.g., change a preference in
USER.md) - Wait for the daily reset (default 4:00 AM local time)
- Send a message to trigger a new session
- Expected: Agent sees the updated file content
- Actual: Agent still sees the file content from when the gateway process started (or when the
sessionKeywas first used)
Root Cause
In src/agents/bootstrap-cache.ts:
const cache = new Map();
async function getOrLoadBootstrapFiles(params) {
const existing = cache.get(params.sessionKey); // keyed by sessionKey
if (existing) return existing; // cache hit → stale files returned
const files = await loadWorkspaceBootstrapFiles(params.workspaceDir);
cache.set(params.sessionKey, files);
return files;
}The cache is keyed by sessionKey (e.g., agent:main:main), which remains constant across daily resets. Daily reset creates a new sessionId but does not call clearBootstrapSnapshot(sessionKey).
The clearBootstrapSnapshot function exists and is called in ensureSessionRuntimeCleanup, but the daily reset code path does not invoke ensureSessionRuntimeCleanup.
Evidence
- Gateway started: March 5, 00:00 (verified via
ps aux) - MEMORY.md updated: March 6, 14:49 (git log)
- USER.md updated: March 6, 14:49 (git log)
- Daily reset: March 7, 04:00 (default config, CST timezone)
- New session created: March 7, 04:39 (JSONL first entry timestamp)
systemPromptReport.injectedWorkspaceFilesrawChars for MEMORY.md: 2503 — matches the March 4 version (2504 chars), not the current version (2835 chars)systemPromptReport.injectedWorkspaceFilesrawChars for USER.md: 880 — matches the March 1 version (881 chars), not the current version (891 chars)
Suggested Fix
Call clearBootstrapSnapshot(sessionKey) during the daily reset flow, so that the next run for that sessionKey re-reads workspace files from disk.
Alternatively, consider:
- Making the cache TTL-based (e.g., re-read files if cache is older than N minutes)
- Clearing the cache when a new
sessionIdis minted for an existingsessionKey - Watching workspace files for changes (fs.watch) and invalidating on modification
Environment
- OpenClaw version: latest npm (as of March 7, 2026)
- OS: macOS (Apple Silicon), Darwin 25.3.0
- Model: claude-opus-4-6
- Session config: default (daily reset at 4:00 AM, no custom idle settings)
Impact
Any changes to workspace bootstrap files (AGENTS.md, SOUL.md, USER.md, MEMORY.md, TOOLS.md, HEARTBEAT.md) are invisible to the agent until the gateway process is manually restarted. This is particularly confusing because:
- The files are correctly updated on disk
- Daily resets occur as expected
- The agent appears to have a "fresh" session (new sessionId)
- But the injected workspace context is stale