Skip to content

Commit 505a371

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/fix-895
2 parents 393e413 + 21c533e commit 505a371

17 files changed

Lines changed: 1228 additions & 364 deletions

‎apps/.i18n/native-source.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30587,31 +30587,31 @@
3058730587
},
3058830588
{
3058930589
"kind": "conditional-branch",
30590-
"line": 148,
30590+
"line": 147,
3059130591
"path": "apps/macos/Sources/OpenClaw/ChannelsStore+Lifecycle.swift",
3059230592
"source": "Logged out and cleared credentials.",
3059330593
"surface": "apple",
3059430594
"id": "native.apple.313dabb10c37e00c"
3059530595
},
3059630596
{
3059730597
"kind": "conditional-branch",
30598-
"line": 149,
30598+
"line": 148,
3059930599
"path": "apps/macos/Sources/OpenClaw/ChannelsStore+Lifecycle.swift",
3060030600
"source": "No WhatsApp session found.",
3060130601
"surface": "apple",
3060230602
"id": "native.apple.b98078a5cac29eaf"
3060330603
},
3060430604
{
3060530605
"kind": "conditional-branch",
30606-
"line": 173,
30606+
"line": 172,
3060730607
"path": "apps/macos/Sources/OpenClaw/ChannelsStore+Lifecycle.swift",
3060830608
"source": "Telegram token cleared.",
3060930609
"surface": "apple",
3061030610
"id": "native.apple.de729686d8ba05d6"
3061130611
},
3061230612
{
3061330613
"kind": "conditional-branch",
30614-
"line": 174,
30614+
"line": 173,
3061530615
"path": "apps/macos/Sources/OpenClaw/ChannelsStore+Lifecycle.swift",
3061630616
"source": "No Telegram token configured.",
3061730617
"surface": "apple",

‎apps/macos/Sources/OpenClaw/ChannelsStore+Lifecycle.swift‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ extension ChannelsStore {
3131
async let schemaLoad: Void = self.loadConfigSchema()
3232
async let configLoad: Void = self.loadConfig(force: false)
3333
_ = await (schemaLoad, configLoad)
34-
while !Task.isCancelled {
35-
try? await Task.sleep(nanoseconds: UInt64(self.interval * 1_000_000_000))
34+
while await SimpleTaskSupport.waitForNextOperation(interval: self.interval) {
3635
await self.refresh(probe: false)
3736
}
3837
}

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,8 @@ final class CronJobsStore {
4141
GatewayPushSubscription.restartTask(task: &self.eventTask) { [weak self] push in
4242
self?.handle(push: push)
4343
}
44-
self.pollTask = Task.detached { [weak self] in
45-
guard let self else { return }
46-
await self.refreshJobs()
47-
while !Task.isCancelled {
48-
try? await Task.sleep(nanoseconds: UInt64(self.interval * 1_000_000_000))
49-
await self.refreshJobs()
50-
}
44+
SimpleTaskSupport.startDetachedLoop(task: &self.pollTask, interval: self.interval) { [weak self] in
45+
await self?.refreshJobs()
5146
}
5247
}
5348

@@ -167,20 +162,14 @@ final class CronJobsStore {
167162
}
168163

169164
private func scheduleRefresh(delayMs: Int = 250) {
170-
self.refreshTask?.cancel()
171-
self.refreshTask = Task { [weak self] in
172-
guard let self else { return }
173-
try? await Task.sleep(nanoseconds: UInt64(delayMs) * 1_000_000)
174-
await self.refreshJobs()
165+
SimpleTaskSupport.schedule(task: &self.refreshTask, delay: TimeInterval(delayMs) / 1000) { [weak self] in
166+
await self?.refreshJobs()
175167
}
176168
}
177169

178170
private func scheduleRunsRefresh(jobId: String, delayMs: Int = 200) {
179-
self.runsTask?.cancel()
180-
self.runsTask = Task { [weak self] in
181-
guard let self else { return }
182-
try? await Task.sleep(nanoseconds: UInt64(delayMs) * 1_000_000)
183-
await self.refreshRuns(jobId: jobId)
171+
SimpleTaskSupport.schedule(task: &self.runsTask, delay: TimeInterval(delayMs) / 1000) { [weak self] in
172+
await self?.refreshRuns(jobId: jobId)
184173
}
185174
}
186175

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ final class PresenceReporter {
1818
self.task = Task.detached { [weak self] in
1919
guard let self else { return }
2020
await self.push(reason: "launch")
21-
while !Task.isCancelled {
22-
try? await Task.sleep(nanoseconds: UInt64(self.interval * 1_000_000_000))
21+
while await SimpleTaskSupport.waitForNextOperation(interval: self.interval) {
2322
await self.push(reason: "periodic")
2423
}
2524
}

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,48 @@ enum SimpleTaskSupport {
1717
static func startDetachedLoop(
1818
task: inout Task<Void, Never>?,
1919
interval: TimeInterval,
20+
sleep: @escaping @Sendable (UInt64) async throws -> Void = { try await Task.sleep(nanoseconds: $0) },
2021
operation: @escaping @Sendable () async -> Void)
2122
{
2223
guard task == nil else { return }
2324
task = Task.detached {
2425
await operation()
25-
while !Task.isCancelled {
26-
try? await Task.sleep(nanoseconds: UInt64(interval * 1_000_000_000))
26+
while await self.waitForNextOperation(interval: interval, sleep: sleep) {
27+
guard !Task.isCancelled else { break }
2728
await operation()
2829
}
2930
}
3031
}
32+
33+
static func schedule(
34+
task: inout Task<Void, Never>?,
35+
delay: TimeInterval,
36+
sleep: @escaping @Sendable (UInt64) async throws -> Void = { try await Task.sleep(nanoseconds: $0) },
37+
beforeOperationCheck: @escaping @Sendable () -> Void = {},
38+
operation: @escaping @MainActor @Sendable () async -> Void)
39+
{
40+
task?.cancel()
41+
task = Task {
42+
guard await self.waitForNextOperation(interval: delay, sleep: sleep) else { return }
43+
beforeOperationCheck()
44+
guard !Task.isCancelled else { return }
45+
await operation()
46+
}
47+
}
48+
49+
nonisolated static func waitForNextOperation(
50+
interval: TimeInterval,
51+
sleep: @escaping @Sendable (UInt64) async throws -> Void = { try await Task.sleep(nanoseconds: $0) }) async
52+
-> Bool
53+
{
54+
guard !Task.isCancelled else { return false }
55+
// Cancellation wakes the sleep. Report it before the next operation so stopped stores
56+
// and superseded debounce tasks cannot issue stale gateway refreshes.
57+
do {
58+
try await sleep(UInt64(interval * 1_000_000_000))
59+
} catch {
60+
return false
61+
}
62+
return !Task.isCancelled
63+
}
3164
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import Testing
2+
@testable import OpenClaw
3+
4+
private actor SimpleTaskSignal {
5+
private var signaled = false
6+
private var waiters: [CheckedContinuation<Void, Never>] = []
7+
8+
func signal() {
9+
self.signaled = true
10+
let waiters = self.waiters
11+
self.waiters.removeAll()
12+
for waiter in waiters {
13+
waiter.resume()
14+
}
15+
}
16+
17+
func wait() async {
18+
if self.signaled {
19+
return
20+
}
21+
await withCheckedContinuation { continuation in
22+
self.waiters.append(continuation)
23+
}
24+
}
25+
}
26+
27+
private actor SimpleTaskOperationProbe {
28+
private var recordedCalls: [String] = []
29+
30+
func recordCall(_ value: String) {
31+
self.recordedCalls.append(value)
32+
}
33+
34+
func calls() -> [String] {
35+
self.recordedCalls
36+
}
37+
}
38+
39+
struct SimpleTaskSupportTests {
40+
@Test
41+
@MainActor
42+
func `cancelling during sleep does not run another operation`() async {
43+
let sleepStarted = SimpleTaskSignal()
44+
let operation = SimpleTaskOperationProbe()
45+
var task: Task<Void, Never>?
46+
47+
SimpleTaskSupport.startDetachedLoop(
48+
task: &task,
49+
interval: 60,
50+
sleep: { nanoseconds in
51+
await sleepStarted.signal()
52+
try await Task.sleep(nanoseconds: nanoseconds)
53+
},
54+
operation: {
55+
await operation.recordCall("loop")
56+
})
57+
58+
await sleepStarted.wait()
59+
guard let runningTask = task else {
60+
Issue.record("detached loop did not start")
61+
return
62+
}
63+
64+
SimpleTaskSupport.stop(task: &task)
65+
await runningTask.value
66+
67+
#expect(await operation.calls() == ["loop"])
68+
#expect(task == nil)
69+
}
70+
71+
@Test
72+
@MainActor
73+
func `rescheduling cancels the superseded operation`() async {
74+
let firstSleepStarted = SimpleTaskSignal()
75+
let operation = SimpleTaskOperationProbe()
76+
var task: Task<Void, Never>?
77+
78+
SimpleTaskSupport.schedule(
79+
task: &task,
80+
delay: 60,
81+
sleep: { nanoseconds in
82+
await firstSleepStarted.signal()
83+
try await Task.sleep(nanoseconds: nanoseconds)
84+
},
85+
operation: {
86+
await operation.recordCall("first")
87+
})
88+
89+
await firstSleepStarted.wait()
90+
guard let firstTask = task else {
91+
Issue.record("first scheduled task did not start")
92+
return
93+
}
94+
95+
SimpleTaskSupport.schedule(
96+
task: &task,
97+
delay: 0,
98+
sleep: { _ in },
99+
operation: {
100+
await operation.recordCall("second")
101+
})
102+
guard let secondTask = task else {
103+
Issue.record("replacement task did not start")
104+
return
105+
}
106+
107+
await firstTask.value
108+
await secondTask.value
109+
SimpleTaskSupport.stop(task: &task)
110+
111+
#expect(await operation.calls() == ["second"])
112+
#expect(task == nil)
113+
}
114+
115+
@Test
116+
@MainActor
117+
func `cancelling after sleep completes does not run the scheduled operation`() async {
118+
let operation = SimpleTaskOperationProbe()
119+
var task: Task<Void, Never>?
120+
121+
SimpleTaskSupport.schedule(
122+
task: &task,
123+
delay: 0,
124+
sleep: { _ in },
125+
beforeOperationCheck: {
126+
withUnsafeCurrentTask { currentTask in
127+
currentTask?.cancel()
128+
}
129+
},
130+
operation: {
131+
await operation.recordCall("stale")
132+
})
133+
134+
guard let runningTask = task else {
135+
Issue.record("scheduled task did not start")
136+
return
137+
}
138+
139+
await runningTask.value
140+
SimpleTaskSupport.stop(task: &task)
141+
142+
#expect(await operation.calls().isEmpty)
143+
#expect(task == nil)
144+
}
145+
}

‎docs/concepts/qa-e2e-automation.md‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,19 @@ explicit subset, including portable scenarios with no channel restriction.
213213
Matrix live implementations live under
214214
`extensions/qa-lab/src/live-transports/matrix/scenarios/`.
215215

216-
The adapter provisions a disposable Tuwunel homeserver in Docker (default
217-
image `ghcr.io/matrix-construct/tuwunel:v1.5.1`, server name `matrix-qa.test`,
218-
port `28008`), registers temporary driver, SUT, and observer users, seeds the
219-
required rooms, and records the redacted request/response boundary. It then
220-
runs the real Matrix plugin inside a child QA gateway scoped to that transport
221-
(no `qa-channel`) and tears the environment down.
216+
The adapter provisions a disposable Tuwunel homeserver in Docker (default image
217+
`ghcr.io/matrix-construct/tuwunel:v1.8.2`, pinned to its multi-architecture OCI
218+
index digest; server name `matrix-qa.test`, port `28008`), registers temporary
219+
driver, SUT, and observer users, seeds the required rooms, and records the
220+
redacted request/response boundary. It then runs the real Matrix plugin inside
221+
a child QA gateway scoped to that transport (no `qa-channel`) and tears the
222+
environment down.
223+
224+
The v1.8.2 GHCR index resolves to
225+
`sha256:6f950bb139411a7964781e986321e395e045e4a6a52240a4dda9d23d04075f78`.
226+
`docker buildx imagetools inspect ghcr.io/matrix-construct/tuwunel:v1.8.2`
227+
reports manifests for `linux/arm64`, `linux/amd64`, `linux/amd64/v2`, and
228+
`linux/amd64/v3`.
222229

223230
Common options:
224231

‎docs/docs.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
},
7171
{
7272
"source": "/concepts/qa-matrix",
73-
"destination": "/concepts/qa-e2e-automation#matrix-smoke-lanes"
73+
"destination": "/concepts/qa-e2e-automation#matrix-live-lane"
7474
},
7575
{
7676
"source": "/plugins/reference/qa-matrix",

0 commit comments

Comments
 (0)