Skip to content

Bug: Daily session reset does not clear bootstrap file cache — workspace files become stale #38494

@LivingInDrm

Description

@LivingInDrm

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

  1. Start the gateway (files are loaded from disk on first session run and cached)
  2. Modify a workspace file (e.g., change a preference in USER.md)
  3. Wait for the daily reset (default 4:00 AM local time)
  4. Send a message to trigger a new session
  5. Expected: Agent sees the updated file content
  6. Actual: Agent still sees the file content from when the gateway process started (or when the sessionKey was 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.injectedWorkspaceFiles rawChars for MEMORY.md: 2503 — matches the March 4 version (2504 chars), not the current version (2835 chars)
  • systemPromptReport.injectedWorkspaceFiles rawChars 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 sessionId is minted for an existing sessionKey
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions