Skip to content

Commit 19aad4a

Browse files
authored
fix(macos): cron editor drops advanced delivery routes (#118047)
* fix(macos): preserve advanced cron delivery routing * fix(macos): mark cron routing labels verbatim * fix(macos): keep cron routing inventory stable
1 parent b3da16f commit 19aad4a

6 files changed

Lines changed: 82 additions & 6 deletions

File tree

‎apps/macos/Sources/OpenClaw/CronJobEditor+Helpers.swift‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ extension CronJobEditor {
148148
} else if self.job?.delivery?.bestEffort == true {
149149
delivery["bestEffort"] = false
150150
}
151+
if let destination = self.job?.delivery?.completionDestination {
152+
delivery["completionDestination"] = destination.mapValues(\.value)
153+
}
154+
}
155+
if let threadId = self.job?.delivery?.threadId { delivery["threadId"] = threadId.value }
156+
if let destination = self.job?.delivery?.failureDestination {
157+
delivery["failureDestination"] = destination.mapValues(\.value)
151158
}
152159
return delivery
153160
}

‎apps/macos/Sources/OpenClaw/CronModels.swift‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ enum CronDeliveryMode: String, CaseIterable, Identifiable, Codable {
5757

5858
struct CronDelivery: Codable, Equatable {
5959
var mode: CronDeliveryMode
60-
var channel: String?
61-
var to: String?
62-
var bestEffort: Bool?
60+
var channel: String?, to: String?, bestEffort: Bool?, threadId: AnyCodable?
61+
/// Preserve Gateway-validated destination objects exactly so native edits cannot erase routing state.
62+
var completionDestination: [String: AnyCodable]?, failureDestination: [String: AnyCodable]?
6363
}
6464

6565
enum CronSchedule: Codable, Equatable {

‎apps/macos/Sources/OpenClaw/CronSettings+Rows.swift‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ extension CronSettings {
231231
if let thinking, !thinking.isEmpty { StatusPill(text: "think \(thinking)", tint: .secondary) }
232232
if let timeoutSeconds { StatusPill(text: "\(timeoutSeconds)s", tint: .secondary) }
233233
if job.supportsAnnounceDelivery {
234-
let delivery = job.delivery
235-
if let delivery {
234+
if let delivery = job.delivery {
235+
self.advancedDeliveryPills(delivery)
236236
if delivery.mode == .announce {
237237
StatusPill(text: "announce", tint: .secondary)
238238
if let channel = delivery.channel, !channel.isEmpty {
@@ -271,4 +271,23 @@ extension CronSettings {
271271
}
272272
}
273273
}
274+
275+
@ViewBuilder
276+
private func advancedDeliveryPills(_ delivery: CronDelivery) -> some View {
277+
if let threadId = delivery.threadId?.value {
278+
StatusPill.verbatim(
279+
"threadId \(String(describing: threadId))",
280+
tint: .secondary)
281+
}
282+
if let to = delivery.completionDestination?["to"]?.value as? String {
283+
StatusPill.verbatim("completionDestination \(to)", tint: .secondary)
284+
}
285+
if let failure = delivery.failureDestination {
286+
let target = failure["to"]?.value as? String
287+
?? failure["channel"]?.value as? String
288+
?? failure["accountId"]?.value as? String
289+
let suffix = target.map { " \($0)" } ?? ""
290+
StatusPill.verbatim("failureDestination" + suffix, tint: .secondary)
291+
}
292+
}
274293
}

‎apps/macos/Sources/OpenClaw/StatusPill.swift‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ struct StatusPill: View {
44
let text: String
55
let tint: Color
66

7+
/// Protocol identifiers and runtime values are operator data, not localized UI copy.
8+
static func verbatim(_ text: String, tint: Color) -> Self {
9+
Self(text: text, tint: tint)
10+
}
11+
712
var body: some View {
813
Text(self.text)
914
.font(.caption2.weight(.semibold))

‎apps/macos/Tests/OpenClawIPCTests/CronJobEditorSmokeTests.swift‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,22 @@ struct CronJobEditorSmokeTests {
4747
channel: nil,
4848
to: nil,
4949
bestEffortDeliver: nil),
50-
delivery: CronDelivery(mode: .announce, channel: "whatsapp", to: "+15551234567", bestEffort: true),
50+
delivery: CronDelivery(
51+
mode: .announce,
52+
channel: "whatsapp",
53+
to: "+15551234567",
54+
bestEffort: true,
55+
threadId: AnyCodable(42),
56+
completionDestination: [
57+
"mode": AnyCodable("webhook"),
58+
"to": AnyCodable("https://example.test/complete"),
59+
],
60+
failureDestination: [
61+
"mode": AnyCodable("announce"),
62+
"channel": AnyCodable("telegram"),
63+
"to": AnyCodable("ops"),
64+
"accountId": AnyCodable("alerts"),
65+
]),
5166
state: CronJobState(
5267
nextRunAtMs: 1_700_000_100_000,
5368
runningAtMs: nil,
@@ -58,6 +73,12 @@ struct CronJobEditorSmokeTests {
5873

5974
let view = self.makeEditor(job: job, channelsStore: channelsStore)
6075
_ = view.body
76+
77+
let delivery = view.buildDelivery()
78+
#expect(delivery["threadId"] as? Int == 42)
79+
#expect((delivery["completionDestination"] as? [String: Any])?["to"] as? String ==
80+
"https://example.test/complete")
81+
#expect((delivery["failureDestination"] as? [String: Any])?["accountId"] as? String == "alerts")
6182
}
6283

6384
@Test func `cron job editor exercises builders`() {

‎apps/macos/Tests/OpenClawIPCTests/CronModelsTests.swift‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,30 @@ struct CronModelsTests {
7272
#expect(decoded == payload)
7373
}
7474

75+
@Test func `delivery advanced routing encodes and decodes`() throws {
76+
for threadId in [#""thread-42""#, "42"] {
77+
let json = """
78+
{
79+
"mode": "announce",
80+
"threadId": \(threadId),
81+
"completionDestination": { "mode": "webhook", "to": "https://example.test/complete" },
82+
"failureDestination": {
83+
"mode": "announce",
84+
"channel": "telegram",
85+
"to": "ops",
86+
"accountId": "alerts"
87+
}
88+
}
89+
"""
90+
let delivery = try JSONDecoder().decode(CronDelivery.self, from: Data(json.utf8))
91+
let roundTripped = try JSONDecoder().decode(CronDelivery.self, from: JSONEncoder().encode(delivery))
92+
93+
#expect(roundTripped == delivery)
94+
#expect(roundTripped.completionDestination?["mode"]?.value as? String == "webhook")
95+
#expect(roundTripped.failureDestination?["accountId"]?.value as? String == "alerts")
96+
}
97+
}
98+
7599
@Test func `payload command encodes and decodes`() throws {
76100
let payload = CronPayload.command(
77101
argv: ["printf", "done"],

0 commit comments

Comments
 (0)