openclaw - ✅(Solved) Fix [Bug]: Daily session reset regresses #57020 — sessionFile not rotated [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#78607Fetched 2026-05-07 03:34:44
View on GitHub
Comments
1
Participants
2
Timeline
8
Reactions
2
Author
Assignees
Timeline (top)
labeled ×2referenced ×2assigned ×1closed ×1

Daily session reset updates sessionId in sessions.json but the previous sessionFile path keeps being reused indefinitely. The transcript JSONL never rotates, so context grows across days/weeks. This is a regression of #57020 (closed 2026-04-25) — the same bug returned in v2026.4.27 (or in one of v2026.4.25 → v2026.4.27) and persists through v2026.5.4. The fix code path in resolveAndPersistSessionFile() still exists but is no longer effective for sessions that already had a sessionFile persisted before the reset boundary.

Root Cause

When the daily reset triggers, baseEntry comes from sessionStore[sessionKey] which ALREADY has the new sessionId persisted (the reset wrote it before this resolver runs). So baseEntry.sessionId === sessionId is always true on the path that triggers the reset, and the existing sessionFile is reused. The fix that landed for #57020 still exists in code but no longer gets exercised by the reset path because something upstream now writes the new sessionId into sessionStore before calling this resolver.

Fix Action

Fix / Workaround

Workaround verified: manual /reset (or /new) triggers a full session reset including sessionFile rotation. Same workaround that #57020 documented.

I will trigger a manual /reset locally as a workaround once this is filed.

PR fix notes

PR #78618: fix: rotate sessionFile after daily reset

Description (problem / solution / changelog)

Summary

  • stop reusing a persisted sessionFile when its basename no longer matches the current sessionId
  • preserve topic transcript paths that still belong to the active session
  • add regression coverage for path resolution, daily reset rotation, custom transcript preservation, and already-stale generated transcript repair

Testing

  • node scripts/test-projects.mjs --maxWorkers=1 src/config/sessions/sessions.test.ts src/auto-reply/reply/session.test.ts src/gateway/server-methods/agent.test.ts src/gateway/server.sessions.reset-models.test.ts
  • pnpm exec oxfmt --check --threads=1 CHANGELOG.md src/auto-reply/reply/session.test.ts src/config/sessions/paths.ts src/config/sessions/sessions.test.ts src/gateway/server-methods/agent.ts src/gateway/server-methods/agent.test.ts
  • git diff --check origin/main...HEAD

Real behavior proof

  • Behavior or issue addressed: Daily Gateway agent session rollover must persist a new generated transcript file when the stored generated sessionFile points at a different UUID than the current session. This covers openclaw/openclaw#78607’s stale generated transcript state.
  • Real environment tested: Disposable local OpenClaw Gateway from this PR checkout’s code diff; proof was run before the final changelog-only attribution amend, and the current head is a95a37499706ea703e0895063600861de2244c65. Isolated HOME, OPENCLAW_STATE_DIR, and OPENCLAW_CONFIG_PATH; plugins disabled; loopback token auth; no mocked session store or mocked Gateway handler.
  • Exact steps or command run after this patch: Seeded /tmp/openclaw-proof-78607/state/agents/main/sessions/sessions.json with a 26-hour-old agent:main:main entry whose sessionId was 63b16647-ea0c-4a22-808b-ce616326b445 but whose generated sessionFile basename was 685a51f7-7adf-48b1-89ca-d3ab86dd6e0f.jsonl; started pnpm openclaw gateway run --port 19107 --bind loopback --auth token --token proof-token --allow-unconfigured --ws-log compact; called the live Gateway health and agent methods through src/gateway/call.js using backend gateway-client token auth; then reread the persisted sessions store from disk.
  • Evidence after fix: Copied live terminal output from the disposable Gateway harness:
    GATEWAY_HEALTH
    {
      "ok": true,
      "channels": {},
      "channelOrder": [],
      "channelLabels": {}
    }
    
    AGENT_CALL_ERROR
    Error: Anthropic API key is missing. Configure one before running the agent.
    
    AFTER
    {
      "sessionId": "66b4b63c-f6be-4dfa-8b13-cd5aae653089",
      "sessionFile": "66b4b63c-f6be-4dfa-8b13-cd5aae653089.jsonl",
      "updatedAt": 1778117113871,
      "sessionStartedAt": 1778117113870,
      "lastInteractionAt": 1778117113870
    }
    
    ASSERTIONS
    sessionId changed: true
    sessionFile changed: true
    sessionFile matches sessionId: true
  • Observed result after fix: The real Gateway agent request crossed the daily rollover path, generated a new session id, and persisted sessionFile to the matching generated <new-sessionId>.jsonl path before provider execution failed due the intentionally credential-free disposable environment.
  • What was not tested: Real model completion was not tested; the bug is the Gateway session-store write that happens before provider execution, and the live Gateway call reached and proved that write.

Fixes openclaw/openclaw#78607

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • src/auto-reply/reply/session.test.ts (modified, +30/-0)
  • src/config/sessions/paths.ts (modified, +68/-0)
  • src/config/sessions/sessions.test.ts (modified, +52/-0)
  • src/gateway/server-methods/agent.test.ts (modified, +132/-0)
  • src/gateway/server-methods/agent.ts (modified, +13/-0)

Code Example

# sessions.json entry for the affected session:
sessionKey: agent:main:main
  sessionId: 63b16647-ea0c-4a22-808b-ce616326b445   (updated recently)
  sessionFile: /home/ubuntu/.openclaw/agents/main/sessions/685a51f7-7adf-48b1-89ca-d3ab86dd6e0f.jsonl
  sessionStartedAt: 1778044514861   (2026-05-06)
  compactionCount: 11

# Transcript header — predates sessionId by 6 days, 11 compactions later still
# the active file:
$ head -1 /home/ubuntu/.openclaw/agents/main/sessions/685a51f7-7adf-48b1-89ca-d3ab86dd6e0f.jsonl
{"type":"session","version":3,"id":"685a51f7-7adf-48b1-89ca-d3ab86dd6e0f","timestamp":"2026-04-30T18:04:00.324Z","cwd":"/home/ubuntu/.openclaw/workspace"}

$ ls -la /home/ubuntu/.openclaw/agents/main/sessions/685a51f7-7adf-48b1-89ca-d3ab86dd6e0f.jsonl
-rw-rw-r-- 1 ubuntu ubuntu 6889076 May  6 19:38 (~6.6 MB, growing)

# No JSONL exists with the current sessionId name:
$ ls /home/ubuntu/.openclaw/agents/main/sessions/63b16647-* 2>&1
ls: cannot access ...: No such file or directory

# Gateway version progression on this machine while the session never rotated
# its sessionFile:
- 2026-04-252026.4.21
- 2026-04-282026.4.23, 2026.4.25
- 2026-04-30 19:512026.4.27 (last upgrade with normal-looking session creation)
- 2026-05-05/062026.5.4 (current)

# The 30-Apr 19:51 startup is the last time a fresh sessionFile was created for
# this session. Multiple reset boundaries since (>= 6 daily resets) without
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

Daily session reset updates sessionId in sessions.json but the previous sessionFile path keeps being reused indefinitely. The transcript JSONL never rotates, so context grows across days/weeks. This is a regression of #57020 (closed 2026-04-25) — the same bug returned in v2026.4.27 (or in one of v2026.4.25 → v2026.4.27) and persists through v2026.5.4. The fix code path in resolveAndPersistSessionFile() still exists but is no longer effective for sessions that already had a sessionFile persisted before the reset boundary.

Steps to reproduce

  1. Start a fresh session under v2026.4.27+ (or upgrade an existing per-channel-peer/main session at any point during this version range).
  2. Chat normally over multiple days, crossing several daily reset boundaries (default 4AM).
  3. Inspect sessions.json (~/.openclaw/agents/<agent>/sessions/sessions.json) for the relevant sessionKey (e.g. agent:main:main).
  4. Compare:
    • sessions.json → sessionId
    • sessions.json → sessionFile basename
  5. Observe the IDs no longer match: sessionId is recent, but sessionFile points to a transcript JSONL whose header timestamp (head -1) predates sessionId by days.

Expected behavior

On daily reset, sessionId rotates AND a new sessionFile path is generated so a fresh JSONL transcript is created. The old transcript should be archived (per resetArchiveRetention) and the new one used from then on. This was the behavior observed after the fix for #57020 landed (between 2026-04-25 and 2026-04-30 in our environment).

Actual behavior

sessionId rotates daily (visible in sessions.json — updatedAt advances, sessionStartedAt advances) but sessionFile is reused indefinitely. The same JSONL keeps growing across weeks — in our case 685a51f7-...jsonl, header timestamp 2026-04-30T18:04:00Z, still the active sessionFile on 2026-05-06 with sessionId=63b16647-... (which has no matching JSONL with that name on disk).

Code path inspection (dist/session-file-BwLxTARg.js — bundled in 2026.5.4):

const baseEntry = params.sessionEntry ?? sessionStore[sessionKey] ?? {...}; const shouldReusePersistedSessionFile = baseEntry.sessionId === sessionId;

When the daily reset triggers, baseEntry comes from sessionStore[sessionKey] which ALREADY has the new sessionId persisted (the reset wrote it before this resolver runs). So baseEntry.sessionId === sessionId is always true on the path that triggers the reset, and the existing sessionFile is reused. The fix that landed for #57020 still exists in code but no longer gets exercised by the reset path because something upstream now writes the new sessionId into sessionStore before calling this resolver.

OpenClaw version

2026.5.4 (regression introduced somewhere between 2026.4.25 and 2026.4.27)

Operating system

Ubuntu 24.04 (Oracle Cloud ARM64)

Install method

npm global

Model

anthropic/claude-opus-4-7

Provider / routing chain

openclaw -> anthropic

Additional provider/model setup details

session config in openclaw.json: { "session": { "dmScope": "main" } }

No explicit session.reset config — relying on the documented default (daily at 4AM local Europe/Madrid, gateway local timezone).

Logs, screenshots, and evidence

# sessions.json entry for the affected session:
sessionKey: agent:main:main
  sessionId: 63b16647-ea0c-4a22-808b-ce616326b445   (updated recently)
  sessionFile: /home/ubuntu/.openclaw/agents/main/sessions/685a51f7-7adf-48b1-89ca-d3ab86dd6e0f.jsonl
  sessionStartedAt: 1778044514861   (2026-05-06)
  compactionCount: 11

# Transcript header — predates sessionId by 6 days, 11 compactions later still
# the active file:
$ head -1 /home/ubuntu/.openclaw/agents/main/sessions/685a51f7-7adf-48b1-89ca-d3ab86dd6e0f.jsonl
{"type":"session","version":3,"id":"685a51f7-7adf-48b1-89ca-d3ab86dd6e0f","timestamp":"2026-04-30T18:04:00.324Z","cwd":"/home/ubuntu/.openclaw/workspace"}

$ ls -la /home/ubuntu/.openclaw/agents/main/sessions/685a51f7-7adf-48b1-89ca-d3ab86dd6e0f.jsonl
-rw-rw-r-- 1 ubuntu ubuntu 6889076 May  6 19:38 (~6.6 MB, growing)

# No JSONL exists with the current sessionId name:
$ ls /home/ubuntu/.openclaw/agents/main/sessions/63b16647-* 2>&1
ls: cannot access ...: No such file or directory

# Gateway version progression on this machine while the session never rotated
# its sessionFile:
- 2026-04-25 — 2026.4.21
- 2026-04-28 — 2026.4.23, 2026.4.25
- 2026-04-30 19:51 — 2026.4.27 (last upgrade with normal-looking session creation)
- 2026-05-05/06 — 2026.5.4 (current)

# The 30-Apr 19:51 startup is the last time a fresh sessionFile was created for
# this session. Multiple reset boundaries since (>= 6 daily resets) without

Impact and severity

Affected: any session that had a sessionFile persisted in the store before its first daily reset under v2026.4.27+ (i.e., effectively all long-lived sessions on upgraded environments).

Severity: Medium-High — sessions never truly reset, context grows indefinitely across days/weeks. Compaction (we have 11 so far) mitigates active in-context size but the on-disk transcript and the conversation history that compaction reads from grow unboundedly. This regresses #57020 which had previously fixed this exact behavior.

Frequency: Every daily reset boundary, on every long-lived session.

Workaround verified: manual /reset (or /new) triggers a full session reset including sessionFile rotation. Same workaround that #57020 documented.

Additional information

This is a regression of:

The fix code path is still present in v2026.5.4 (dist/session-file-BwLxTARg.js → resolveAndPersistSessionFile(): shouldReusePersistedSessionFile = baseEntry.sessionId === sessionId), but it is no longer effective because the reset path appears to update sessionStore[sessionKey].sessionId BEFORE calling this resolver, so the resolver always sees baseEntry.sessionId matching the new sessionId and skips the rotation guard.

Likely root cause locations to check:

  • src/config/sessions/init.ts (or equivalent) — initSessionState() / daily-reset trigger: check whether it now writes the new sessionId into sessions.json before invoking resolveAndPersistSessionFile, instead of letting the resolver see the old (mismatching) sessionId in baseEntry.
  • The original fix design assumed baseEntry.sessionId reflects the PRE-reset state when the resolver is called. That invariant no longer holds.

Suggested fix shapes (any of):

  1. Pass the previous sessionId explicitly into resolveAndPersistSessionFile so the guard can detect a reset regardless of what's already in baseEntry.
  2. Have the reset path clear baseEntry.sessionFile (set to undefined) before calling the resolver, like the original fix proposal suggested.
  3. Have initSessionState detect "reset boundary crossed" and pass an explicit isReset=true flag through to the resolver so it can force-rotate sessionFile.

Window of regression on our environment:

  • Last known good: v2026.4.25 or early v2026.4.27 (last sessionFile creation: 30-Apr 18:04 UTC, ~1h45m before the v2026.4.27 systemd unit restart).
  • Confirmed broken: v2026.4.27 runtime onwards through v2026.5.4 (no rotation for 6 consecutive daily reset boundaries).

I will trigger a manual /reset locally as a workaround once this is filed.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

On daily reset, sessionId rotates AND a new sessionFile path is generated so a fresh JSONL transcript is created. The old transcript should be archived (per resetArchiveRetention) and the new one used from then on. This was the behavior observed after the fix for #57020 landed (between 2026-04-25 and 2026-04-30 in our environment).

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix [Bug]: Daily session reset regresses #57020 — sessionFile not rotated [1 pull requests, 1 comments, 2 participants]