Skip to content

fix: clean up session records and run logs on cron.remove (#46369)#712

Open
BingqingLyu wants to merge 6 commits intomainfrom
fork-pr-46506-fix-cron-remove-session-cleanup-46369
Open

fix: clean up session records and run logs on cron.remove (#46369)#712
BingqingLyu wants to merge 6 commits intomainfrom
fork-pr-46506-fix-cron-remove-session-cleanup-46369

Conversation

@BingqingLyu
Copy link
Copy Markdown
Owner

@BingqingLyu BingqingLyu commented Apr 27, 2026

Summary

Fixes openclaw#46369 — when deleting a cron job via cron.remove, only the job config was removed from jobs.json. Session records in sessions.json and the run log file remained, causing "ghost sessions" to appear in the Control UI dropdown.

The fix: After removing the job config, asynchronously clean up:

  1. Session entries matching cron:{jobId}:* from sessions.json via updateSessionStore
  2. Run log file at {cronStoreDir}/runs/{jobId}.jsonl via fs.unlink

Cleanup runs outside the critical path — failures are logged but don't block the removal response.

Changes

  • src/cron/service/ops.ts: Added cleanupRemovedJobArtifacts() called after successful job removal
  • src/cron/service.remove-cleanup.test.ts: 2 new tests verifying session and run log cleanup

Test plan

  • All 523 cron tests pass (521 existing + 2 new)
  • New test: session entries for deleted job are removed, other jobs' sessions preserved
  • New test: run log .jsonl file is deleted after job removal
  • Manual: Create cron job in Control UI → delete it → verify no ghost session in dropdown

anup00900 and others added 6 commits March 15, 2026 00:08
…6369)

When a cron job is deleted, only the job config was removed from
jobs.json. The session records in sessions.json and the run log file
remained, causing ghost sessions to appear in the Control UI.

After removing the job config, asynchronously:
1. Delete matching session entries (cron:{jobId}:*) from sessions.json
2. Delete the run log file at {cronStoreDir}/runs/{jobId}.jsonl

Cleanup failures are logged but do not block the removal response.
… path

- Use Promise.allSettled so session cleanup and run log deletion are
  independent; a failure in one does not skip the other
- Capture the removed job's agentId before filtering and pass it to
  resolveSessionStorePath so non-default-agent jobs clean the correct
  sessions.json
- Prefer resolveSessionStorePath(agentId) over static sessionStorePath
  so multi-agent deployments clean the correct sessions.json
- Match both canonical key (cron:{jobId}) and run keys (cron:{jobId}:run:*)
  to prevent ghost sessions from either key type
- Fix pre-existing oxfmt formatting in message-handler.ts
Introduced in bb06dc7 on main but never called, causing oxlint failure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: cron.remove does not clean up session records in sessions.json

2 participants