#12368: fix(cron): respect OPENCLAW_STATE_DIR for cron store path
stale
Cluster:
Cron Job Fixes
## Summary
The cron store path now respects the OPENCLAW_STATE_DIR (and CLAWDBOT_STATE_DIR for backwards compatibility) environment variable when resolving the default path.
## Problem
Previously, the cron store always defaulted to ~/.openclaw/cron/jobs.json even when OPENCLAW_STATE_DIR was set to a custom location. This prevented proper isolation for multi-instance setups (e.g., main + rescue bot).
## Solution
Modified resolveCronStorePath() to check for OPENCLAW_STATE_DIR/CLAWDBOT_STATE_DIR at runtime before falling back to the default path.
Priority order:
1. Explicit storePath from config (unchanged)
2. OPENCLAW_STATE_DIR / CLAWDBOT_STATE_DIR env vars (NEW)
3. Default path using CONFIG_DIR (fallback)
## Related Issues
- Similar root cause as #9866 (device identity)
- Related to #8793 (hardcoded paths issue)
## Testing
Added test coverage for:
- OPENCLAW_STATE_DIR resolution
- CLAWDBOT_STATE_DIR fallback
- Priority ordering
- Home directory expansion (~)
## Backwards Compatibility
Fully backwards compatible - no breaking changes.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Changes `resolveCronStorePath()` (`src/cron/store.ts`) to resolve the cron store location at runtime using `OPENCLAW_STATE_DIR` (falling back to `CLAWDBOT_STATE_DIR`) when no explicit `cron.store` path is configured, instead of always using the module-load-time `CONFIG_DIR` default. Updates unit tests in `src/cron/store.test.ts` to cover env var precedence and `~` expansion, and adds a GitHub issue template documenting the original problem and expected behavior.
The runtime path resolution is used by the gateway cron service (`src/gateway/server-cron.ts`) when creating `CronService`, so this aligns cron persistence with the repository-wide state-dir override logic in `resolveConfigDir()` (`src/utils.ts`).
<h3>Confidence Score: 4/5</h3>
- Mostly safe to merge, but the updated test file currently fails at runtime due to missing vitest hook imports.
- Core logic change is small and follows the existing `resolveConfigDir()` env-var precedence, but `src/cron/store.test.ts` uses `beforeEach`/`afterAll` without importing them, which will break CI/unit tests.
- src/cron/store.test.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#8698: fix(cron): default enabled to true for new jobs
by emmick4 · 2026-02-04
80.2%
#12303: fix(cron): correct nextRunAtMs calculation and prevent timer stall
by colddonkey · 2026-02-09
80.2%
#6827: fix: cron scheduler cleanup orphaned .tmp files on startup
by fatelei · 2026-02-02
80.0%
#10894: Docs: fix legacy branding, add config reference, expand cron troubl...
by biv0711 · 2026-02-07
79.1%
#9088: fix(cron): ensure nextRunAtMs is computed when enabled is undefined...
by divol89 · 2026-02-04
79.0%
#17916: [ fix ] : correct config directory path during onboarding
by Dijo-404 · 2026-02-16
78.7%
#8744: fix(cron): load persisted cron jobs on gateway startup
by revenuestack · 2026-02-04
78.1%
#3335: Fixes cron jobs
by hkirat · 2026-01-28
77.9%
#4467: fix: DEFAULT_SANDBOX_WORKSPACE_ROOT respects STATE_DIR
by Aphroq · 2026-01-30
77.9%
#21553: fix: resolve workspace template dir in bundled dist/ layout
by echoVic · 2026-02-20
77.7%