openclaw - 💡(How to fix) Fix `cron run` manual trigger doesn't faithfully reproduce the scheduled execution environment [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#71777Fetched 2026-04-26 05:08:29
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
labeled ×3

Running cron run <job> manually (for testing/debugging) behaves differently from the scheduled run. Observed differences include working directory, environment variables, and session context loading. This makes cron bugs hard to reproduce on a fresh shell — you can't trust that "it works when I run it manually" matches the scheduled behavior.

Root Cause

Running cron run <job> manually (for testing/debugging) behaves differently from the scheduled run. Observed differences include working directory, environment variables, and session context loading. This makes cron bugs hard to reproduce on a fresh shell — you can't trust that "it works when I run it manually" matches the scheduled behavior.

RAW_BUFFERClick to expand / collapse

Summary

Running cron run <job> manually (for testing/debugging) behaves differently from the scheduled run. Observed differences include working directory, environment variables, and session context loading. This makes cron bugs hard to reproduce on a fresh shell — you can't trust that "it works when I run it manually" matches the scheduled behavior.

Observed in

  • macOS deployment (Mac Mini, LaunchAgent-scheduled cron jobs)
  • Windows deployment (Task Scheduler-equivalent)
  • Originally noted against v2026.2.26; same pattern persists in our deployment notes through current versions, though this issue may already be partially addressed by recent cron work that I haven't tested against.

Examples of divergence

  1. Working directory. Scheduled run starts in the agent workspace. Manual run starts in the shell's cwd.
  2. Environment. Scheduled run inherits LaunchAgent/service-level env (minimal PATH, no terminal-set vars). Manual run inherits the interactive shell env, including any direnv / shell aliases / PATH overrides.
  3. Context file loading. Scheduled run loads agents.md / soul.md / heartbeat context per the cron schedule policy. Manual run sometimes skips heartbeat context and loads a different combination.

The third one is the most painful — a manual cron run "passing" doesn't necessarily mean the scheduled run will load the same context.

Suggested fix

Either default behavior or an explicit flag (cron run --as-scheduled) that faithfully reproduces the scheduled execution environment:

  • chdir to the agent workspace
  • Reconstruct the env using the same logic the scheduler uses
  • Load the same context files in the same order, including heartbeat

This would make cron debugging substantially easier and turn manual cron run into a true "what would happen at the scheduled time" preview.

Severity

Low-Medium. It's a developer-experience issue, not a production correctness issue, but it's a recurring source of "why did this work in testing but not in prod" confusion.

Note

Lots of recent cron work (#69285, #67807, #63105, etc.) has improved the cron infrastructure substantially. If any of that already addresses this, please point me at it and I'll update our internal docs accordingly.

extent analysis

TL;DR

Implementing a --as-scheduled flag for cron run to replicate the scheduled execution environment would help resolve the discrepancies between manual and scheduled runs.

Guidance

  • Investigate recent cron infrastructure improvements (e.g., #69285, #67807, #63105) to determine if any existing changes address the issue.
  • Consider implementing a --as-scheduled flag to faithfully reproduce the scheduled execution environment, including working directory, environment variables, and context file loading.
  • To verify the fix, compare the behavior of manual cron run with and without the --as-scheduled flag to ensure it matches the scheduled run behavior.
  • Review the cron schedule policy to ensure that the --as-scheduled flag loads the correct context files, including heartbeat context, in the same order as the scheduled run.

Example

No code snippet is provided as the issue does not contain specific code references.

Notes

The issue's severity is classified as Low-Medium, and resolving it would improve the developer experience by making manual cron run a more accurate representation of the scheduled behavior.

Recommendation

Apply a workaround by implementing the suggested --as-scheduled flag to improve the accuracy of manual cron run tests, as this would provide a more reliable way to reproduce the scheduled execution environment.

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…

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 - 💡(How to fix) Fix `cron run` manual trigger doesn't faithfully reproduce the scheduled execution environment [1 participants]