Skip to content

[Bug]: Daily reset leaves orphaned session transcript files on disk #35481

@fujiwarakasei

Description

@fujiwarakasei

[Bug]: Daily reset leaves orphaned session transcript files on disk

Environment

  • OpenClaw version: 2026.3.2
  • OS: macOS (Darwin 25.3.0, arm64)
  • Node: v25.6.1
  • Model: anthropic/claude-opus-4-6
  • Channels: Telegram (DM + group topics) + Discord

Summary

When the daily session reset (default 4:00 AM local time) triggers, the old session transcript file (.jsonl) is left on disk with no reference in sessions.json. This creates "orphaned" (headless) files that accumulate over time, wasting disk space and making it difficult to distinguish intentional resets from bugs.

By contrast, auto-compaction correctly archives old transcripts by renaming them with a .reset.<timestamp> suffix.

Steps to Reproduce

  1. Configure a gateway with Telegram group topics (default session.reset config — daily at 4:00 AM)
  2. Have an active conversation in a topic before 4:00 AM (e.g., last message at 00:27 JST)
  3. Wait until after 4:00 AM
  4. Send a new message to the same topic

What Happened

  • sessions.json mapping for the topic key was updated to point to a new sessionId
  • A new 3KB transcript file was created
  • The old transcript file (656KB, with full conversation history) was left on disk with no reference — orphaned

Before (13:33 JST):

sessions.json → sessionId: 7c52aa72
disk: 7c52aa72-topic-398.jsonl (656KB) ← active

After sending a message (13:38 JST):

sessions.json → sessionId: 8dfa557a  ← new
disk: 7c52aa72-topic-398.jsonl (656KB) ← ORPHANED, no reference
disk: 8dfa557a-topic-398.jsonl (3KB)   ← new active

Expected Behavior

Daily reset should archive the old transcript file the same way auto-compaction does:

7c52aa72-topic-398.jsonl → 7c52aa72-topic-398.jsonl.reset.2026-03-05T04-00-00.000Z

This would:

  • Prevent disk space leaks from accumulating orphan files
  • Make it clear when and why a session was reset (traceable via .reset.<timestamp> suffix)
  • Align behavior with auto-compaction, which already handles archival correctly

Evidence of Accumulation

In a 3-day period with ~14 Telegram topics, 12 orphaned session files accumulated (totaling ~4MB), none of which are referenced by sessions.json. Meanwhile, compaction-archived files are clearly marked:

# Compaction — properly archived ✅
3b1f9c18-topic-398.jsonl.reset.2026-03-04T06-52-02.465Z

# Daily reset — orphaned ❌
7ae013fb-topic-398.jsonl  (310KB, unreferenced)
7c52aa72-topic-398.jsonl  (656KB, unreferenced)

Additional Context

  • session.maintenance.mode defaults to warn, so these orphan files are never cleaned up automatically unless the user explicitly runs openclaw sessions cleanup --enforce
  • The orphan files have no metadata (no .reset. suffix, no timestamp) to indicate they were intentionally archived vs. produced by a bug
  • Related: Issue Session unexpectedly reset mid-conversation when heartbeat arrives during exec notification #4099 (session unexpectedly reset mid-conversation) — orphan files from that issue are indistinguishable from daily-reset orphans
  • Telegram group topics (chatType: "group") and DMs (chatType: "direct") are both affected; Discord channel sessions (chatType: "channel") appear unaffected by the default daily reset

Suggested Fix

In the daily reset code path (likely initSessionState() in src/auto-reply/reply/session.ts), rename the old transcript file with a .reset.<timestamp> suffix before creating the new session, matching the existing compaction archival behavior.

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