Skip to content

Bug: /new and /reset commands don't delete transcript files, causing context bloat #14869

@TheFruggg

Description

@TheFruggg

Bug: /new and /reset commands don't delete transcript files, causing context bloat

Summary

When /new or /reset is used to start a fresh session, the old transcript file (.jsonl) is never deleted. This causes sessions to accumulate context indefinitely until reaching 100% capacity (~205k tokens), severely degrading response quality.

Steps to Reproduce

  1. Use OpenClaw normally for a few weeks
  2. Check context usage with /status or via the control UI
  3. Notice context percentage climbing over time
  4. Use /new or /reset to start fresh
  5. Bug: Old transcript file is not deleted
  6. New session starts with a new sessionId, but old .jsonl file remains on disk
  7. Context percentage continues climbing from where it left off

Expected Behavior

When /new or /reset is triggered:

  1. Old transcript file should be deleted from disk
  2. New session ID should be generated
  3. Session store should be updated with new ID
  4. Context should start at 0%

Actual Behavior

When /new or /reset is triggered:

  1. ✅ New session ID is generated (crypto.randomUUID())
  2. ✅ Session store is updated with new ID
  3. Old transcript file is NEVER deleted
  4. ❌ Context accumulates indefinitely until 100%

Impact

  • Memory leak: Transcript files accumulate indefinitely
  • Quality degradation: Sessions reach 100% context, making responses unusable
  • No recovery: /new command becomes ineffective - it doesn't actually reset
  • Disk usage: Large .jsonl files accumulate on disk

Root Cause

File: dist/reply-DptDUVRg.js (in OpenClaw source)
Location: Around line 64543

Code path:

// When /new or /reset is detected:
if (trimmedBodyLower === triggerLower || strippedForResetLower === triggerLower) {
  isNewSession = true;
  bodyStripped = "";
  resetTriggered = true;  // Line 64536 or 64543
  break;
}

// Later:
const entry = sessionStore[sessionKey];  // Has old sessionId
const previousSessionEntry = resetTriggered && entry ? { ...entry } : void 0;

// BUT: Transcript deletion is missing here!

// Later still:
sessionId = crypto.randomUUID();  // New ID generated

Evidence:

  • OpenClaw HAS code to delete transcripts (fs.unlinkSync(transcriptPath))
  • But it's ONLY used for session corruption errors (see corruption handling path)
  • The deletion logic is completely missing from the /new//reset path

Proposed Fix

Add transcript deletion immediately after previousSessionEntry is set (around line 64550):

const previousSessionEntry = resetTriggered && entry ? { ...entry } : void 0;

// Delete old transcript file when reset is triggered
if (resetTriggered && entry?.sessionId) {
  const oldTranscriptPath = resolveSessionTranscriptPath(entry.sessionId);
  try {
    unlinkSync(oldTranscriptPath);
  } catch (err) {
    // Ignore errors if file doesn't exist
  }
}

const now = Date.now();

Required imports (already present):

  • resolveSessionTranscriptPath - imported from ./paths-BuajeM4x.js
  • unlinkSync - imported from node:fs

Workaround Until Fix

  1. Manual deletion:

    cd ~/.openclaw/agents/{agent}/sessions
    rm -f {session-id}.jsonl
    jq 'del(.["agent:{agent}:main"])' sessions.json > sessions.json.new
    mv sessions.json.new sessions.json
  2. Threshold monitoring script (runs every 15 minutes):

    #!/bin/bash
    THRESHOLD=60
    SESSION_INFO=$(openclaw session info agent:jarvis:main --json)
    USAGE_PERCENT=$(echo "$SESSION_INFO" | jq -r '(.totalTokens * 100) / .contextTokens' | bc)
    if [ "$USAGE_PERCENT" -ge "$THRESHOLD" ]; then
      rm ~/.openclaw/agents/jarvis/sessions/*.jsonl
    fi

Environment

  • OpenClaw Version: 2026.2.9
  • Node.js: v24.13.0
  • OS: Linux 6.14.0-37-generic (x64)

Related Issues

This is a different bug from those - it's specifically about transcript file not being deleted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    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