← Back to PRs

#12368: fix(cron): respect OPENCLAW_STATE_DIR for cron store path

by ComBba open 2026-02-09 05:50 View on GitHub →
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