Skip to content

Commit c871157

Browse files
committed
feat(cron): declarative jobs with owner attribution and richer status
Adds scope-local declaration-key convergence, immutable owner attribution, richer status projection, and delivery validation to canonical cron jobs. Supersedes the #98727 routines registry approach; no parallel registry, RPC namespace, or CLI noun.
1 parent a320f77 commit c871157

43 files changed

Lines changed: 1923 additions & 424 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6249,6 +6249,9 @@ public struct SkillsUploadCommitParams: Codable, Sendable {
62496249

62506250
public struct CronJob: Codable, Sendable {
62516251
public let id: String
6252+
public let declarationkey: String?
6253+
public let displayname: String?
6254+
public let owner: [String: AnyCodable]?
62526255
public let agentid: String?
62536256
public let sessionkey: String?
62546257
public let name: String
@@ -6264,9 +6267,22 @@ public struct CronJob: Codable, Sendable {
62646267
public let delivery: AnyCodable?
62656268
public let failurealert: AnyCodable?
62666269
public let state: [String: AnyCodable]
6270+
public let nextrunatms: Int?
6271+
public let lastrunatms: Int?
6272+
public let lastrunstatus: AnyCodable?
6273+
public let lastrunerror: String?
6274+
public let lastdelivered: Bool?
6275+
public let lastdeliverystatus: AnyCodable?
6276+
public let lastdeliveryerror: String?
6277+
public let lastfailurenotificationdelivered: Bool?
6278+
public let lastfailurenotificationdeliverystatus: AnyCodable?
6279+
public let lastfailurenotificationdeliveryerror: String?
62676280

62686281
public init(
62696282
id: String,
6283+
declarationkey: String? = nil,
6284+
displayname: String? = nil,
6285+
owner: [String: AnyCodable]? = nil,
62706286
agentid: String? = nil,
62716287
sessionkey: String?,
62726288
name: String,
@@ -6281,9 +6297,22 @@ public struct CronJob: Codable, Sendable {
62816297
payload: AnyCodable,
62826298
delivery: AnyCodable?,
62836299
failurealert: AnyCodable?,
6284-
state: [String: AnyCodable])
6300+
state: [String: AnyCodable],
6301+
nextrunatms: Int? = nil,
6302+
lastrunatms: Int? = nil,
6303+
lastrunstatus: AnyCodable? = nil,
6304+
lastrunerror: String? = nil,
6305+
lastdelivered: Bool? = nil,
6306+
lastdeliverystatus: AnyCodable? = nil,
6307+
lastdeliveryerror: String? = nil,
6308+
lastfailurenotificationdelivered: Bool? = nil,
6309+
lastfailurenotificationdeliverystatus: AnyCodable? = nil,
6310+
lastfailurenotificationdeliveryerror: String? = nil)
62856311
{
62866312
self.id = id
6313+
self.declarationkey = declarationkey
6314+
self.displayname = displayname
6315+
self.owner = owner
62876316
self.agentid = agentid
62886317
self.sessionkey = sessionkey
62896318
self.name = name
@@ -6299,10 +6328,23 @@ public struct CronJob: Codable, Sendable {
62996328
self.delivery = delivery
63006329
self.failurealert = failurealert
63016330
self.state = state
6331+
self.nextrunatms = nextrunatms
6332+
self.lastrunatms = lastrunatms
6333+
self.lastrunstatus = lastrunstatus
6334+
self.lastrunerror = lastrunerror
6335+
self.lastdelivered = lastdelivered
6336+
self.lastdeliverystatus = lastdeliverystatus
6337+
self.lastdeliveryerror = lastdeliveryerror
6338+
self.lastfailurenotificationdelivered = lastfailurenotificationdelivered
6339+
self.lastfailurenotificationdeliverystatus = lastfailurenotificationdeliverystatus
6340+
self.lastfailurenotificationdeliveryerror = lastfailurenotificationdeliveryerror
63026341
}
63036342

63046343
private enum CodingKeys: String, CodingKey {
63056344
case id
6345+
case declarationkey = "declarationKey"
6346+
case displayname = "displayName"
6347+
case owner
63066348
case agentid = "agentId"
63076349
case sessionkey = "sessionKey"
63086350
case name
@@ -6318,6 +6360,16 @@ public struct CronJob: Codable, Sendable {
63186360
case delivery
63196361
case failurealert = "failureAlert"
63206362
case state
6363+
case nextrunatms = "nextRunAtMs"
6364+
case lastrunatms = "lastRunAtMs"
6365+
case lastrunstatus = "lastRunStatus"
6366+
case lastrunerror = "lastRunError"
6367+
case lastdelivered = "lastDelivered"
6368+
case lastdeliverystatus = "lastDeliveryStatus"
6369+
case lastdeliveryerror = "lastDeliveryError"
6370+
case lastfailurenotificationdelivered = "lastFailureNotificationDelivered"
6371+
case lastfailurenotificationdeliverystatus = "lastFailureNotificationDeliveryStatus"
6372+
case lastfailurenotificationdeliveryerror = "lastFailureNotificationDeliveryError"
63216373
}
63226374
}
63236375

@@ -6379,6 +6431,9 @@ public struct CronStatusParams: Codable, Sendable {}
63796431

63806432
public struct CronAddParams: Codable, Sendable {
63816433
public let name: String
6434+
public let declarationkey: String?
6435+
public let displayname: String?
6436+
public let owner: [String: AnyCodable]?
63826437
public let agentid: AnyCodable?
63836438
public let sessionkey: AnyCodable?
63846439
public let description: String?
@@ -6393,6 +6448,9 @@ public struct CronAddParams: Codable, Sendable {
63936448

63946449
public init(
63956450
name: String,
6451+
declarationkey: String? = nil,
6452+
displayname: String? = nil,
6453+
owner: [String: AnyCodable]? = nil,
63966454
agentid: AnyCodable? = nil,
63976455
sessionkey: AnyCodable?,
63986456
description: String?,
@@ -6406,6 +6464,9 @@ public struct CronAddParams: Codable, Sendable {
64066464
failurealert: AnyCodable?)
64076465
{
64086466
self.name = name
6467+
self.declarationkey = declarationkey
6468+
self.displayname = displayname
6469+
self.owner = owner
64096470
self.agentid = agentid
64106471
self.sessionkey = sessionkey
64116472
self.description = description
@@ -6421,6 +6482,9 @@ public struct CronAddParams: Codable, Sendable {
64216482

64226483
private enum CodingKeys: String, CodingKey {
64236484
case name
6485+
case declarationkey = "declarationKey"
6486+
case displayname = "displayName"
6487+
case owner
64246488
case agentid = "agentId"
64256489
case sessionkey = "sessionKey"
64266490
case description
@@ -6435,6 +6499,28 @@ public struct CronAddParams: Codable, Sendable {
64356499
}
64366500
}
64376501

6502+
public struct CronDeclarativeAddResult: Codable, Sendable {
6503+
public let created: Bool
6504+
public let updated: Bool?
6505+
public let job: CronJob
6506+
6507+
public init(
6508+
created: Bool,
6509+
updated: Bool?,
6510+
job: CronJob)
6511+
{
6512+
self.created = created
6513+
self.updated = updated
6514+
self.job = job
6515+
}
6516+
6517+
private enum CodingKeys: String, CodingKey {
6518+
case created
6519+
case updated
6520+
case job
6521+
}
6522+
}
6523+
64386524
public struct CronRunsParams: Codable, Sendable {
64396525
public let scope: AnyCodable?
64406526
public let id: String?

‎packages/gateway-protocol/src/index.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ import {
165165
ConnectParamsSchema,
166166
type CronAddParams,
167167
CronAddParamsSchema,
168+
type CronAddResult,
169+
CronAddResultSchema,
170+
type CronDeclarativeAddResult,
171+
CronDeclarativeAddResultSchema,
168172
type CronGetParams,
169173
CronGetParamsSchema,
170174
type CronJob,
@@ -1258,6 +1262,8 @@ export {
12581262
CronStatusParamsSchema,
12591263
CronGetParamsSchema,
12601264
CronAddParamsSchema,
1265+
CronAddResultSchema,
1266+
CronDeclarativeAddResultSchema,
12611267
CronUpdateParamsSchema,
12621268
CronRemoveParamsSchema,
12631269
CronRunParamsSchema,
@@ -1496,6 +1502,8 @@ export type {
14961502
CronStatusParams,
14971503
CronGetParams,
14981504
CronAddParams,
1505+
CronAddResult,
1506+
CronDeclarativeAddResult,
14991507
CronUpdateParams,
15001508
CronRemoveParams,
15011509
CronRunParams,

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ const CronDeliveryStatusSchema = Type.Union([
115115
Type.Literal("not-requested"),
116116
]);
117117
const NonBlankString = Type.String({ minLength: 1, pattern: "\\S" });
118+
const CronDeclarationKeySchema = Type.String({ minLength: 1, maxLength: 200, pattern: "\\S" });
119+
const CronDisplayNameSchema = Type.String({ minLength: 1, maxLength: 200, pattern: "\\S" });
120+
const CronOwnerSchema = Type.Object(
121+
{
122+
agentId: Type.Optional(NonEmptyString),
123+
sessionKey: Type.Optional(NonEmptyString),
124+
},
125+
{ additionalProperties: false },
126+
);
118127
const CronAnnounceChannelSchema = Type.Union([Type.Literal("last"), NonBlankString]);
119128
const CronFailoverReasonSchema = Type.Union([
120129
Type.Literal("auth"),
@@ -453,6 +462,9 @@ const CronJobStatePatchSchema = Type.Object(
453462
export const CronJobSchema = Type.Object(
454463
{
455464
id: NonEmptyString,
465+
declarationKey: Type.Optional(CronDeclarationKeySchema),
466+
displayName: Type.Optional(CronDisplayNameSchema),
467+
owner: Type.Optional(CronOwnerSchema),
456468
agentId: Type.Optional(NonEmptyString),
457469
sessionKey: Type.Optional(NonEmptyString),
458470
name: NonEmptyString,
@@ -468,6 +480,16 @@ export const CronJobSchema = Type.Object(
468480
delivery: Type.Optional(CronDeliverySchema),
469481
failureAlert: Type.Optional(Type.Union([Type.Literal(false), CronFailureAlertSchema])),
470482
state: CronJobStateSchema,
483+
nextRunAtMs: Type.Optional(Type.Integer({ minimum: 0 })),
484+
lastRunAtMs: Type.Optional(Type.Integer({ minimum: 0 })),
485+
lastRunStatus: Type.Optional(CronRunStatusSchema),
486+
lastRunError: Type.Optional(Type.String()),
487+
lastDelivered: Type.Optional(Type.Boolean()),
488+
lastDeliveryStatus: Type.Optional(CronDeliveryStatusSchema),
489+
lastDeliveryError: Type.Optional(Type.String()),
490+
lastFailureNotificationDelivered: Type.Optional(Type.Boolean()),
491+
lastFailureNotificationDeliveryStatus: Type.Optional(CronDeliveryStatusSchema),
492+
lastFailureNotificationDeliveryError: Type.Optional(Type.String()),
471493
},
472494
{ additionalProperties: false },
473495
);
@@ -500,6 +522,9 @@ export const CronGetParamsSchema = cronIdOrJobIdParams({});
500522
export const CronAddParamsSchema = Type.Object(
501523
{
502524
name: NonEmptyString,
525+
declarationKey: Type.Optional(CronDeclarationKeySchema),
526+
displayName: Type.Optional(CronDisplayNameSchema),
527+
owner: Type.Optional(CronOwnerSchema),
503528
...CronCommonOptionalFields,
504529
schedule: CronScheduleSchema,
505530
sessionTarget: CronSessionTargetSchema,
@@ -511,10 +536,24 @@ export const CronAddParamsSchema = Type.Object(
511536
{ additionalProperties: false },
512537
);
513538

539+
/** Successful declaration-key convergence result. */
540+
export const CronDeclarativeAddResultSchema = Type.Object(
541+
{
542+
created: Type.Boolean(),
543+
updated: Type.Optional(Type.Boolean()),
544+
job: CronJobSchema,
545+
},
546+
{ additionalProperties: false },
547+
);
548+
549+
/** Successful result from imperative create or declaration-key convergence. */
550+
export const CronAddResultSchema = Type.Union([CronJobSchema, CronDeclarativeAddResultSchema]);
551+
514552
/** Mutable cron job fields accepted by update APIs. */
515553
export const CronJobPatchSchema = Type.Object(
516554
{
517555
name: Type.Optional(NonEmptyString),
556+
displayName: Type.Optional(Type.Union([CronDisplayNameSchema, Type.Null()])),
518557
...CronCommonOptionalFields,
519558
schedule: Type.Optional(CronScheduleSchema),
520559
sessionTarget: Type.Optional(CronSessionTargetSchema),

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ import {
151151
} from "./crestodian.js";
152152
import {
153153
CronAddParamsSchema,
154+
CronAddResultSchema,
155+
CronDeclarativeAddResultSchema,
154156
CronGetParamsSchema,
155157
CronJobSchema,
156158
CronListParamsSchema,
@@ -582,6 +584,8 @@ export const ProtocolSchemas = {
582584
CronStatusParams: CronStatusParamsSchema,
583585
CronGetParams: CronGetParamsSchema,
584586
CronAddParams: CronAddParamsSchema,
587+
CronAddResult: CronAddResultSchema,
588+
CronDeclarativeAddResult: CronDeclarativeAddResultSchema,
585589
CronUpdateParams: CronUpdateParamsSchema,
586590
CronRemoveParams: CronRemoveParamsSchema,
587591
CronRunParams: CronRunParamsSchema,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ export type CronListParams = SchemaType<"CronListParams">;
266266
export type CronStatusParams = SchemaType<"CronStatusParams">;
267267
export type CronGetParams = SchemaType<"CronGetParams">;
268268
export type CronAddParams = SchemaType<"CronAddParams">;
269+
export type CronAddResult = SchemaType<"CronAddResult">;
270+
export type CronDeclarativeAddResult = SchemaType<"CronDeclarativeAddResult">;
269271
export type CronUpdateParams = SchemaType<"CronUpdateParams">;
270272
export type CronRemoveParams = SchemaType<"CronRemoveParams">;
271273
export type CronRunParams = SchemaType<"CronRunParams">;

‎scripts/protocol-gen-swift.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@ const DEFAULTED_OPTIONAL_INIT_PARAM_ENTRIES: readonly [string, readonly string[]
7676
["ArtifactsDownloadParams", ["agentId"]],
7777
["MessageActionParams", ["inboundTurnKind", "requesterAccountId"]],
7878
["CronListParams", ["compact"]],
79+
[
80+
"CronJob",
81+
[
82+
"declarationKey",
83+
"displayName",
84+
"owner",
85+
"nextRunAtMs",
86+
"lastRunAtMs",
87+
"lastRunStatus",
88+
"lastRunError",
89+
"lastDelivered",
90+
"lastDeliveryStatus",
91+
"lastDeliveryError",
92+
"lastFailureNotificationDelivered",
93+
"lastFailureNotificationDeliveryStatus",
94+
"lastFailureNotificationDeliveryError",
95+
],
96+
],
97+
["CronAddParams", ["declarationKey", "displayName", "owner"]],
7998
["CronRunLogEntry", ["errorReason", "failureNotificationDelivery"]],
8099
["ExecApprovalRequestParams", ["requireDeliveryRoute", "suppressDelivery"]],
81100
["PluginApprovalRequestParams", ["approvalReviewerDeviceIds"]],

‎src/agents/tools/cron-tool-canonicalize.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ const CRON_FLAT_SCHEDULE_KEYS = [
3838
] as const;
3939
const CRON_RECOVERABLE_OBJECT_KEYS: ReadonlySet<string> = new Set([
4040
"name",
41+
"declarationKey",
42+
"displayName",
43+
"owner",
4144
"schedule",
4245
"sessionTarget",
4346
"wakeMode",

‎src/agents/tools/cron-tool.schema.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ describe("createCronToolSchema", () => {
4545
expect(keysAt(schemaRecord, "job")).toEqual(
4646
[
4747
"agentId",
48+
"declarationKey",
4849
"deleteAfterRun",
4950
"delivery",
5051
"description",
52+
"displayName",
5153
"enabled",
5254
"failureAlert",
5355
"name",
56+
"owner",
5457
"payload",
5558
"schedule",
5659
"sessionKey",
@@ -67,6 +70,7 @@ describe("createCronToolSchema", () => {
6770
"deleteAfterRun",
6871
"delivery",
6972
"description",
73+
"displayName",
7074
"enabled",
7175
"failureAlert",
7276
"name",
@@ -217,6 +221,7 @@ describe("createCronToolSchema", () => {
217221
jobId: "job-1",
218222
patch: {
219223
agentId: null,
224+
displayName: null,
220225
sessionKey: null,
221226
payload: {
222227
toolsAllow: null,

0 commit comments

Comments
 (0)