-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Description
Problem
When SANDBOX_SLEEP_AFTER is configured to reduce costs, the container may be sleeping when OpenClaw's internal cron jobs should fire. This causes important scheduled tasks (like daily briefs) to be skipped entirely.
The cron scheduler runs inside the OpenClaw gateway, which runs inside the container. If the container is asleep, crons don't fire.
Current behavior
- Container sleeps after inactivity period
- Cron job scheduled for 07:30 → container is asleep → job skipped
- Next external request wakes container → scheduler recalculates next run → job scheduled for tomorrow
Expected behavior
- Container wakes just before critical cron times
- Jobs fire on schedule
Proposed Solution
Add Cloudflare Workers Scheduled Triggers to wake the container before important cron times.
Changes
1. wrangler.jsonc - Add triggers section:
2. src/scheduled-handler.ts - New file:
import { getSandbox } from '@cloudflare/sandbox';
import type { MoltbotEnv } from './types';
import { ensureMoltbotGateway } from './gateway';
export async function handleScheduled(
event: ScheduledEvent,
env: MoltbotEnv,
ctx: ExecutionContext
): Promise<void> {
console.log('[Scheduled] Wake trigger at', new Date(event.scheduledTime).toISOString());
const sandbox = getSandbox(env.Sandbox, 'moltbot', { keepAlive: true });
await ensureMoltbotGateway(sandbox, env);
console.log('[Scheduled] Container awakened successfully');
}3. src/index.ts - Export the handler:
import { handleScheduled } from './scheduled-handler';
export default {
fetch: app.fetch,
scheduled: handleScheduled,
};Benefits
- No extra cost: Scheduled triggers are free
- User-configurable: Users can edit
wrangler.jsoncto match their cron schedules - Documented: README explains how to customize triggers for different timezones
Alternative considered
Documenting that users should set SANDBOX_SLEEP_AFTER=never, but this increases costs (~$30/month vs ~$5-10/month with sleep).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels