openclaw - ✅(Solved) Fix [Bug]: Cron isolated runs orphan session files: sessionFile not persisted to sessions.json [2 pull requests, 1 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#65151Fetched 2026-04-12 13:25:20
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Participants
Timeline (top)
cross-referenced ×2labeled ×2referenced ×2

Every cron job with sessionTarget: "isolated" leaves an orphaned .jsonl file on disk that openclaw doctor reports as unreferenced.

Root cause

In createCronPromptExecutor (src/cron/isolated-agent/run-executor.ts), sessionFile is computed correctly:

const sessionFile = resolveSessionTranscriptPath(params.cronSession.sessionEntry.sessionId, params.agentId);

This path is passed into runEmbeddedPiAgent / runCliAgent so the transcript is written to disk. However, it is never assigned back to the session entry:  
 
// missing:                                                                                                                                               
params.cronSession.sessionEntry.sessionFile = sessionFile;      
                                                                                                                                                          
When finalizeCronRun later calls persistSessionEntry(), the entry written to sessions.json has no sessionFile field. The .jsonl exists on disk but the    
index has no pointer to it.                                                                                                                               
                                                                                                                                                          
Reproduction                                                    

1. Define any cron job with sessionTarget: "isolated" and payload.kind: "agentTurn"                                                                       
2. Let it run
3. Run openclaw doctor — the run's .jsonl is reported as an orphan                                                                                        
                                                                                                                                                          
Fix
                                                                                                                                                          
Add one line immediately after sessionFile is computed in createCronPromptExecutor:                                                                       
 
params.cronSession.sessionEntry.sessionFile = sessionFile;                                                                                                
                                                                
Environment

- Version: 2026.4.10                                                                                                                                      
- Platform: Linux x86_64

Root Cause

Root cause

Fix Action

Fixed

PR fix notes

PR #65175: fix(cron): persist sessionFile for isolated cron runs to prevent orphans

Description (problem / solution / changelog)

Isolated cron runs compute sessionFile via resolveSessionTranscriptPath but never assign it back to the session entry. When finalizeCronRun persists the entry to sessions.json, the sessionFile field is missing, leaving the .jsonl transcript as an orphan that openclaw doctor reports as unreferenced.

One-line fix: assign sessionFile back to the session entry immediately after computing it.

Fixes #65151

Changed files

  • src/cron/isolated-agent/run-executor.ts (modified, +4/-0)

PR #65181: fix(cron): persist sessionFile to sessionEntry for isolated runs (#65151)

Description (problem / solution / changelog)

Summary

Fixes #65151

Cron jobs with sessionTarget: "isolated" were leaving orphaned .jsonl files on disk that openclaw doctor reported as unreferenced.

Root Cause

In createCronPromptExecutor (src/cron/isolated-agent/run-executor.ts), sessionFile was computed correctly and passed to runCliAgent/runEmbeddedPiAgent, but it was never assigned back to the session entry:

// Before (missing):
const sessionFile = resolveSessionTranscriptPath(...);
// Missing: params.cronSession.sessionEntry.sessionFile = sessionFile;

When finalizeCronRun later calls persistSessionEntry(), the entry written to sessions.json had no sessionFile field. The .jsonl exists on disk but the index has no pointer to it.

Fix

Add one line immediately after sessionFile is computed:

params.cronSession.sessionEntry.sessionFile = sessionFile;

Testing

Added comprehensive test coverage in run-executor.session-file.test.ts:

  • ✅ sessionFile is persisted to sessionEntry when executor is created
  • ✅ sessionFile path format is correct
  • ✅ existing sessionFile is overwritten if already set
  • ✅ resolveSessionTranscriptPath is called with correct arguments
  • ✅ handles session with existing sessionFile field gracefully

Checklist

  • Bug fix with clear root cause
  • Single-line fix with high impact
  • Comprehensive test coverage
  • No breaking changes
  • No CHANGELOG update (let maintainers handle)

Changed files

  • src/cron/isolated-agent/run-executor.session-file.test.ts (added, +179/-0)
  • src/cron/isolated-agent/run-executor.ts (modified, +3/-0)

Code Example

const sessionFile = resolveSessionTranscriptPath(params.cronSession.sessionEntry.sessionId, params.agentId);

  This path is passed into runEmbeddedPiAgent / runCliAgent so the transcript is written to disk. However, it is never assigned back to the session entry:  
   
  // missing:                                                                                                                                               
  params.cronSession.sessionEntry.sessionFile = sessionFile;      
                                                                                                                                                            
  When finalizeCronRun later calls persistSessionEntry(), the entry written to sessions.json has no sessionFile field. The .jsonl exists on disk but the    
  index has no pointer to it.                                                                                                                               
                                                                                                                                                            
  Reproduction                                                    

  1. Define any cron job with sessionTarget: "isolated" and payload.kind: "agentTurn"                                                                       
  2. Let it run
  3. Run openclaw doctor — the run's .jsonl is reported as an orphan                                                                                        
                                                                                                                                                            
  Fix
                                                                                                                                                            
  Add one line immediately after sessionFile is computed in createCronPromptExecutor:                                                                       
   
  params.cronSession.sessionEntry.sessionFile = sessionFile;                                                                                                
                                                                  
  Environment

  - Version: 2026.4.10                                                                                                                                      
  - Platform: Linux x86_64


### Steps to reproduce

1. Define any cron job with sessionTarget: "isolated" and payload.kind: "agentTurn"                                                                       
2. Let it run
3. 3. Run openclaw doctor — the run's .jsonl is reported as an orphan 

### Expected behavior

OpenClaw manages all session files in a consistent way and orphan session files don't accumulate. 

### Actual behavior

Every cron job with `sessionTarget: "isolated"` leaves an orphaned `.jsonl` file on disk that `openclaw doctor` reports as unreferenced. 

### OpenClaw version

2026.4.10

### Operating system

Ubuntu 24.04

### Install method

npm

### Model

openai-codex/gpt-5.4 

### Provider / routing chain

openclaw -> openai-codex

### Additional provider/model setup details

_No response_

### Logs, screenshots, and evidence
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

Every cron job with sessionTarget: "isolated" leaves an orphaned .jsonl file on disk that openclaw doctor reports as unreferenced.

Root cause

In createCronPromptExecutor (src/cron/isolated-agent/run-executor.ts), sessionFile is computed correctly:

const sessionFile = resolveSessionTranscriptPath(params.cronSession.sessionEntry.sessionId, params.agentId);

This path is passed into runEmbeddedPiAgent / runCliAgent so the transcript is written to disk. However, it is never assigned back to the session entry:  
 
// missing:                                                                                                                                               
params.cronSession.sessionEntry.sessionFile = sessionFile;      
                                                                                                                                                          
When finalizeCronRun later calls persistSessionEntry(), the entry written to sessions.json has no sessionFile field. The .jsonl exists on disk but the    
index has no pointer to it.                                                                                                                               
                                                                                                                                                          
Reproduction                                                    

1. Define any cron job with sessionTarget: "isolated" and payload.kind: "agentTurn"                                                                       
2. Let it run
3. Run openclaw doctor — the run's .jsonl is reported as an orphan                                                                                        
                                                                                                                                                          
Fix
                                                                                                                                                          
Add one line immediately after sessionFile is computed in createCronPromptExecutor:                                                                       
 
params.cronSession.sessionEntry.sessionFile = sessionFile;                                                                                                
                                                                
Environment

- Version: 2026.4.10                                                                                                                                      
- Platform: Linux x86_64


### Steps to reproduce

1. Define any cron job with sessionTarget: "isolated" and payload.kind: "agentTurn"                                                                       
2. Let it run
3. 3. Run openclaw doctor — the run's .jsonl is reported as an orphan 

### Expected behavior

OpenClaw manages all session files in a consistent way and orphan session files don't accumulate. 

### Actual behavior

Every cron job with `sessionTarget: "isolated"` leaves an orphaned `.jsonl` file on disk that `openclaw doctor` reports as unreferenced. 

### OpenClaw version

2026.4.10

### Operating system

Ubuntu 24.04

### Install method

npm

### Model

openai-codex/gpt-5.4 

### Provider / routing chain

openclaw -> openai-codex

### Additional provider/model setup details

_No response_

### Logs, screenshots, and evidence

```shell

Impact and severity

Orphan session files accumulate and 'openclaw doctor' keeps flagging these as issues.

Additional information

No response

extent analysis

TL;DR

Add the missing line params.cronSession.sessionEntry.sessionFile = sessionFile; in createCronPromptExecutor to fix the issue of orphaned .jsonl files.

Guidance

  • The root cause is the missing assignment of sessionFile to params.cronSession.sessionEntry.sessionFile, which prevents the session entry from being written to sessions.json with the correct sessionFile field.
  • To verify the fix, run a cron job with sessionTarget: "isolated" and check if openclaw doctor still reports orphaned .jsonl files.
  • After applying the fix, re-run the affected cron jobs to ensure that the sessionFile field is correctly populated in the session entries.
  • To mitigate the issue temporarily, manually remove the orphaned .jsonl files reported by openclaw doctor, but this is not a permanent solution.

Example

const sessionFile = resolveSessionTranscriptPath(params.cronSession.sessionEntry.sessionId, params.agentId);
params.cronSession.sessionEntry.sessionFile = sessionFile; // Add this line

Notes

This fix assumes that the sessionFile path is correctly computed and that the issue is solely due to the missing assignment. If the issue persists after applying the fix, further investigation may be needed.

Recommendation

Apply the workaround by adding the missing line of code, as this directly addresses the identified root cause of the issue.

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

OpenClaw manages all session files in a consistent way and orphan session files don't accumulate.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING