Skip to content

Commit fa1d34f

Browse files
committed
feat(cron): add maintenance-window role isolation
1 parent 1bfae9d commit fa1d34f

28 files changed

Lines changed: 1622 additions & 64 deletions
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
f4a00ada9d154a4d3a54e109aa6e9f73f22b09d7df9ab6745e87f88724eec06b config-baseline.json
2-
5ee177382cf32c2816dca0a4e67cd6c01df1045d600b21a6e9c11639ddb10ce8 config-baseline.core.json
1+
1794b11bb011dcc885bbb26d9f46b95975dea40e9a2698fc8e7b5bb32ac2c45a config-baseline.json
2+
7abe55c0cfde9875e1ea652c21c57ead391e6e98a31aba2e8b59351ab670239f config-baseline.core.json
33
0e654bad3f1ef9100f76e512c4453c1f26b6bc1f5ee121ce505d0624a1dad4cd config-baseline.channel.json
4-
e6a1d6f51f0d9c04bd92d51deebfaca8c7917dd28d7998d225c0074e0a095348 config-baseline.plugin.json
4+
4012b1f8de6f9527c47320a6c7120f30dc30ac1b5524ed63dadef890aad44b20 config-baseline.plugin.json

‎docs/automation/cron-jobs.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,11 @@ Model override note:
454454
webhookToken: "replace-with-dedicated-webhook-token",
455455
sessionRetention: "24h",
456456
runLog: { maxBytes: "2mb", keepLines: 2000 },
457+
maintenance: {
458+
enabled: true,
459+
window: { start: "02:00", end: "03:00", timezone: "user" },
460+
maintenanceAgents: ["maintenance"],
461+
},
457462
},
458463
}
459464
```
@@ -473,6 +478,9 @@ Disable cron: `cron.enabled: false` or `OPENCLAW_SKIP_CRON=1`.
473478
</Accordion>
474479
<Accordion title="Maintenance">
475480
`cron.sessionRetention` (default `24h`) prunes isolated run-session entries. `cron.runLog.keepLines` limits retained SQLite run-history rows per job; `maxBytes` is retained for config compatibility with older file-backed run logs.
481+
482+
`cron.maintenance` is a separate scheduler policy. When enabled, OpenClaw resolves a daily maintenance phase from `window.start`, `window.end`, and `window.timezone`. Agents listed in `maintenanceAgents` can run only during that maintenance window; all other agents are blocked during the window. Blocked cron runs persist deferred counters in job state and replay FIFO when their phase is allowed again. Heartbeat deferrals are held in memory and replayed when the phase allows. `cron status` includes additive maintenance diagnostics so operators can see the current phase and deferred counts.
483+
476484
</Accordion>
477485
</AccordionGroup>
478486

‎docs/cli/cron.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ Retention and pruning are controlled in config:
200200

201201
- `cron.sessionRetention` (default `24h`) prunes completed isolated run sessions.
202202
- `cron.runLog.keepLines` prunes retained SQLite run-history rows per job. `cron.runLog.maxBytes` remains accepted for compatibility with older file-backed run logs.
203+
- `cron.maintenance` enables a daily maintenance window shared by cron and heartbeat. Agents listed in `cron.maintenance.maintenanceAgents` run only during the maintenance phase; ordinary agents are blocked during that phase. Blocked cron runs persist deferred counters and replay FIFO when the phase allows. `openclaw cron status --json` includes additive maintenance diagnostics.
203204

204205
## Migrating older jobs
205206

‎docs/gateway/configuration-reference.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,15 @@ Current builds no longer include the TCP bridge. Nodes connect over the Gateway
12871287
maxBytes: "2mb", // default 2_000_000 bytes
12881288
keepLines: 2000, // default 2000
12891289
},
1290+
maintenance: {
1291+
enabled: true,
1292+
window: {
1293+
start: "02:00", // daily HH:MM, inclusive
1294+
end: "03:00", // daily HH:MM, exclusive; 24:00 allowed
1295+
timezone: "user", // "user", "local", or IANA timezone id
1296+
},
1297+
maintenanceAgents: ["maintenance"],
1298+
},
12901299
},
12911300
}
12921301
```
@@ -1296,6 +1305,10 @@ Current builds no longer include the TCP bridge. Nodes connect over the Gateway
12961305
- `runLog.keepLines`: newest SQLite run-history rows retained per job. Default: `2000`.
12971306
- `webhookToken`: bearer token used for cron webhook POST delivery (`delivery.mode = "webhook"`), if omitted no auth header is sent.
12981307
- `webhook`: deprecated legacy fallback webhook URL (http/https) used by `openclaw doctor --fix` to migrate stored jobs that still have `notify: true`; runtime delivery uses per-job `delivery.mode="webhook"` plus `delivery.to`, or `delivery.completionDestination` when preserving announce delivery.
1308+
- `maintenance.enabled`: enables daily maintenance-window role isolation for cron and heartbeat schedulers.
1309+
- `maintenance.window.start` / `maintenance.window.end`: daily maintenance window in `HH:MM` 24-hour time. Start is inclusive; end is exclusive. `24:00` is valid only for `end`.
1310+
- `maintenance.window.timezone`: timezone used to resolve the daily window. Use `"user"`, `"local"`, or an IANA timezone id. Default behavior follows user timezone resolution.
1311+
- `maintenance.maintenanceAgents`: explicit agent ids allowed only during maintenance. Non-maintenance agents are blocked during the maintenance phase; maintenance agents are blocked during normal phase. Blocked cron runs persist deferred counters and replay FIFO when allowed. Heartbeat deferrals are in-memory and replay when allowed.
12991312

13001313
### `cron.retry`
13011314

‎packages/gateway-protocol/src/schema/cron.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ export const CronJobStateSchema = Type.Object(
329329
lastFailureNotificationDeliveryStatus: Type.Optional(CronDeliveryStatusSchema),
330330
lastFailureNotificationDeliveryError: Type.Optional(Type.String()),
331331
lastFailureAlertAtMs: Type.Optional(Type.Integer({ minimum: 0 })),
332+
deferredMaintenanceRuns: Type.Optional(Type.Integer({ minimum: 0 })),
333+
firstDeferredMaintenanceAtMs: Type.Optional(Type.Integer({ minimum: 0 })),
334+
lastDeferredMaintenanceAtMs: Type.Optional(Type.Integer({ minimum: 0 })),
332335
},
333336
{ additionalProperties: false },
334337
);
@@ -352,6 +355,9 @@ const CronJobStatePatchSchema = Type.Object(
352355
lastFailureNotificationDeliveryStatus: Type.Optional(CronDeliveryStatusSchema),
353356
lastFailureNotificationDeliveryError: Type.Optional(Type.String()),
354357
lastFailureAlertAtMs: Type.Optional(Type.Integer({ minimum: 0 })),
358+
deferredMaintenanceRuns: Type.Optional(Type.Integer({ minimum: 0 })),
359+
firstDeferredMaintenanceAtMs: Type.Optional(Type.Integer({ minimum: 0 })),
360+
lastDeferredMaintenanceAtMs: Type.Optional(Type.Integer({ minimum: 0 })),
355361
},
356362
{ additionalProperties: false },
357363
);

‎src/config/schema.help.quality.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ const TARGET_KEYS = [
141141
"cron.runLog",
142142
"cron.runLog.maxBytes",
143143
"cron.runLog.keepLines",
144+
"cron.maintenance",
145+
"cron.maintenance.enabled",
146+
"cron.maintenance.window",
147+
"cron.maintenance.window.start",
148+
"cron.maintenance.window.end",
149+
"cron.maintenance.window.timezone",
150+
"cron.maintenance.maintenanceAgents",
144151
"session",
145152
"session.scope",
146153
"session.dmScope",
@@ -760,6 +767,25 @@ describe("config help copy quality", () => {
760767
expect(keepLines.includes("2000")).toBe(true);
761768
});
762769

770+
it("documents cron maintenance-window controls", () => {
771+
const maintenance = FIELD_HELP["cron.maintenance"];
772+
expect(/role isolation|maintenance/i.test(maintenance)).toBe(true);
773+
774+
const enabled = FIELD_HELP["cron.maintenance.enabled"];
775+
expect(/maintenanceAgents/i.test(enabled)).toBe(true);
776+
777+
const window = FIELD_HELP["cron.maintenance.window"];
778+
expect(window.includes("23:00")).toBe(true);
779+
expect(window.includes("02:00")).toBe(true);
780+
781+
const timezone = FIELD_HELP["cron.maintenance.window.timezone"];
782+
expect(timezone.includes('"user"')).toBe(true);
783+
expect(timezone.includes("America/Los_Angeles")).toBe(true);
784+
785+
const agents = FIELD_HELP["cron.maintenance.maintenanceAgents"];
786+
expect(agents.includes("ops-maint")).toBe(true);
787+
});
788+
763789
it("documents approvals filters and target semantics", () => {
764790
const sessionFilter = FIELD_HELP["approvals.exec.sessionFilter"];
765791
expect(/substring|regex/i.test(sessionFilter)).toBe(true);

‎src/config/schema.help.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,20 @@ export const FIELD_HELP: Record<string, string> = {
17131713
"Compatibility setting for older file-backed cron run logs (for example `2mb`, default `2000000`). SQLite run history pruning is row-count based.",
17141714
"cron.runLog.keepLines":
17151715
"How many trailing run-history rows to retain per cron job (default `2000`). Increase for longer forensic history or lower for smaller disks.",
1716+
"cron.maintenance":
1717+
"Maintenance-window scheduler controls for role isolation between normal agents and dedicated maintenance agents across cron and heartbeat flows.",
1718+
"cron.maintenance.enabled":
1719+
"Enables maintenance-window phase isolation. When enabled, only maintenanceAgents run during the configured window, and those agents are blocked outside it.",
1720+
"cron.maintenance.window":
1721+
"Defines the daily maintenance window with start/end 24-hour times and timezone. Use cross-midnight windows such as `23:00` to `02:00` for overnight maintenance.",
1722+
"cron.maintenance.window.start":
1723+
"Sets the inclusive maintenance window start time in `HH:MM` 24-hour format. Use values such as `02:00` to begin maintenance gating at a predictable local time.",
1724+
"cron.maintenance.window.end":
1725+
"Sets the exclusive maintenance window end time in `HH:MM` 24-hour format. Use `24:00` only for end-of-day windows that should run until midnight.",
1726+
"cron.maintenance.window.timezone":
1727+
'Timezone for maintenance window evaluation. Use "user" (default), "local", or an IANA timezone such as `America/Los_Angeles`.',
1728+
"cron.maintenance.maintenanceAgents":
1729+
"Use this explicit agent-id allowlist to reserve maintenance-only workers for the maintenance window. Example: [`ops-maint`, `cleanup-bot`]. Listed agents are blocked during normal runtime.",
17161730
transcripts:
17171731
"Core transcript capture settings for recording-capable agent tools and configured live meeting auto-start sources. Keep disabled unless operators explicitly want agents to capture or import meeting transcripts.",
17181732
"transcripts.enabled":

‎src/config/schema.labels.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,13 @@ export const FIELD_LABELS: Record<string, string> = {
862862
"cron.runLog": "Cron Run Log Pruning",
863863
"cron.runLog.maxBytes": "Cron Run Log Max Bytes",
864864
"cron.runLog.keepLines": "Cron Run Log Keep Lines",
865+
"cron.maintenance": "Cron Maintenance",
866+
"cron.maintenance.enabled": "Cron Maintenance Enabled",
867+
"cron.maintenance.window": "Cron Maintenance Window",
868+
"cron.maintenance.window.start": "Cron Maintenance Start",
869+
"cron.maintenance.window.end": "Cron Maintenance End",
870+
"cron.maintenance.window.timezone": "Cron Maintenance Timezone",
871+
"cron.maintenance.maintenanceAgents": "Cron Maintenance Agents",
865872
transcripts: "Transcripts",
866873
"transcripts.enabled": "Transcripts Enabled",
867874
"transcripts.maxUtterances": "Transcripts Max Utterances",

‎src/config/types.agents.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ export type AgentConfig = {
135135
allowAgents?: string[];
136136
/** Per-agent default model for spawned sub-agents (string or {primary,fallbacks}). */
137137
model?: AgentModelConfig;
138+
/** Per-agent default thinking level for spawned sub-agents. */
139+
thinking?: string;
138140
/** Require explicit agentId in sessions_spawn (no default same-as-caller). */
139141
requireAgentId?: boolean;
140142
};

‎src/config/types.cron.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ export type CronFailureDestinationConfig = {
2828
mode?: "announce" | "webhook";
2929
};
3030

31+
export type CronMaintenanceWindowConfig = {
32+
/** Start time (24h, HH:MM). Inclusive. */
33+
start?: string;
34+
/** End time (24h, HH:MM). Exclusive. Use 24:00 for end-of-day. */
35+
end?: string;
36+
/** Timezone for maintenance window ("user", "local", or IANA TZ id). Default: "user". */
37+
timezone?: string;
38+
};
39+
40+
export type CronMaintenanceConfig = {
41+
/** Enable maintenance-window scheduler phase isolation. */
42+
enabled?: boolean;
43+
/** Daily maintenance window definition. */
44+
window?: CronMaintenanceWindowConfig;
45+
/** Agent ids that run only during maintenance windows. */
46+
maintenanceAgents?: string[];
47+
};
48+
3149
export type CronConfig = {
3250
enabled?: boolean;
3351
store?: string;
@@ -58,6 +76,8 @@ export type CronConfig = {
5876
maxBytes?: number | string;
5977
keepLines?: number;
6078
};
79+
/** Maintenance-window execution controls for cron + heartbeat schedulers. */
80+
maintenance?: CronMaintenanceConfig;
6181
failureAlert?: CronFailureAlertConfig;
6282
/** Default destination for failure notifications across all cron jobs. */
6383
failureDestination?: CronFailureDestinationConfig;

0 commit comments

Comments
 (0)