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
- Use OpenClaw normally for a few weeks
- Check context usage with
/status or via the control UI
- Notice context percentage climbing over time
- Use
/new or /reset to start fresh
- Bug: Old transcript file is not deleted
- New session starts with a new
sessionId, but old .jsonl file remains on disk
- Context percentage continues climbing from where it left off
Expected Behavior
When /new or /reset is triggered:
- Old transcript file should be deleted from disk
- New session ID should be generated
- Session store should be updated with new ID
- Context should start at 0%
Actual Behavior
When /new or /reset is triggered:
- ✅ New session ID is generated (
crypto.randomUUID())
- ✅ Session store is updated with new ID
- ❌ Old transcript file is NEVER deleted
- ❌ 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
-
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
-
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.
Bug:
/newand/resetcommands don't delete transcript files, causing context bloatSummary
When
/newor/resetis 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
/statusor via the control UI/newor/resetto start freshsessionId, but old.jsonlfile remains on diskExpected Behavior
When
/newor/resetis triggered:Actual Behavior
When
/newor/resetis triggered:crypto.randomUUID())Impact
/newcommand becomes ineffective - it doesn't actually reset.jsonlfiles accumulate on diskRoot Cause
File:
dist/reply-DptDUVRg.js(in OpenClaw source)Location: Around line 64543
Code path:
Evidence:
fs.unlinkSync(transcriptPath))/new//resetpathProposed Fix
Add transcript deletion immediately after
previousSessionEntryis set (around line 64550):Required imports (already present):
resolveSessionTranscriptPath- imported from./paths-BuajeM4x.jsunlinkSync- imported fromnode:fsWorkaround Until Fix
Manual deletion:
Threshold monitoring script (runs every 15 minutes):
Environment
Related Issues
/newand/resetcommands reset verbose mode to offThis is a different bug from those - it's specifically about transcript file not being deleted.