Skip to content

Commit ffc7249

Browse files
committed
Merge origin/main into feat/session-folder-group-defaults
2 parents 5c82f48 + f6f0fd9 commit ffc7249

380 files changed

Lines changed: 14038 additions & 2476 deletions

File tree

Some content is hidden

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

‎.github/actions/setup-node-env/action.yml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,19 @@ runs:
425425
restore-keys: |
426426
${{ github.repository }}-build-all-v1-${{ inputs.build-all-cache-scope }}-${{ runner.os }}-${{ runner.arch }}-node-${{ inputs.node-version }}-
427427
428+
# Prune before saving: prefix-key restores accrete every prior lockfile
429+
# generation into the archive (measured 2.05 GiB, ~36s restore per job).
430+
# Pruning collapses it to the current lockfile's closure; a dropped entry
431+
# costs one registry refetch in a later job at worst.
432+
- name: Prune pnpm store before save
433+
if: ${{ inputs.install-deps == 'true' && inputs.use-actions-cache == 'true' && (inputs.dependency-cache != 'true' || steps.dependency-cache.outputs.cache-hit != 'true') && inputs.save-actions-cache == 'true' && runner.os != 'Windows' && steps.setup-pnpm.outputs.store-cache-hit != 'true' }}
434+
shell: bash
435+
working-directory: ${{ steps.package-manager.outputs.project-dir }}
436+
run: |
437+
du -sh "${{ steps.setup-pnpm.outputs.store-path }}" || true
438+
pnpm store prune
439+
du -sh "${{ steps.setup-pnpm.outputs.store-path }}" || true
440+
428441
- name: Save pnpm store cache
429442
if: ${{ inputs.install-deps == 'true' && inputs.use-actions-cache == 'true' && (inputs.dependency-cache != 'true' || steps.dependency-cache.outputs.cache-hit != 'true') && inputs.save-actions-cache == 'true' && runner.os != 'Windows' && steps.setup-pnpm.outputs.store-cache-hit != 'true' }}
430443
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5

‎.github/workflows/ci.yml‎

Lines changed: 137 additions & 63 deletions
Large diffs are not rendered by default.

‎apps/macos/Sources/OpenClaw/NodeMode/MacNodeHostWorker.swift‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@ struct MacNodeHostWorkerLaunch: Equatable, Sendable {
3737
let command: [String]
3838
let currentDirectoryURL: URL?
3939
let environment: [String: String]
40+
let configurationGeneration: UInt64
4041

4142
init(
4243
command: [String],
4344
currentDirectoryURL: URL? = nil,
44-
environment: [String: String] = [:])
45+
environment: [String: String] = [:],
46+
configurationGeneration: UInt64 = 0)
4547
{
4648
self.command = command
4749
self.currentDirectoryURL = currentDirectoryURL
4850
self.environment = environment
51+
self.configurationGeneration = configurationGeneration
4952
}
5053
}
5154

@@ -88,7 +91,7 @@ final class MacNodeHostWorker: MacNodeHostWorking, @unchecked Sendable {
8891
private let writerQueue = DispatchQueue(label: "ai.openclaw.node-host-worker.writer")
8992
private let session: GatewayNodeSession
9093
private let startupTimeout: TimeInterval
91-
private let onUnexpectedExit: @Sendable () -> Void
94+
private let onUnexpectedExit: @Sendable (UInt64) -> Void
9295
private var process: ManagedProcess?
9396
private var processCleanupTask: Task<Void, Never>?
9497
private var stdinPipe: Pipe?
@@ -115,7 +118,7 @@ final class MacNodeHostWorker: MacNodeHostWorking, @unchecked Sendable {
115118
init(
116119
session: GatewayNodeSession,
117120
startupTimeout: TimeInterval = MacNodeHostWorker.defaultStartupTimeout,
118-
onUnexpectedExit: @escaping @Sendable () -> Void = {})
121+
onUnexpectedExit: @escaping @Sendable (UInt64) -> Void = { _ in })
119122
{
120123
self.session = session
121124
self.startupTimeout = startupTimeout
@@ -709,6 +712,7 @@ final class MacNodeHostWorker: MacNodeHostWorking, @unchecked Sendable {
709712
notifyUnexpectedExit: Bool = false) -> Task<Void, Never>?
710713
{
711714
let wasReady = self.manifest != nil
715+
let stoppedWorker = self.launchedWorker
712716
self.startTimer?.cancel()
713717
self.startTimer = nil
714718
self.launchedWorker = nil
@@ -727,8 +731,8 @@ final class MacNodeHostWorker: MacNodeHostWorking, @unchecked Sendable {
727731
for (id, continuation) in pending {
728732
continuation.resume(returning: Self.unavailableResponse(id, "UNAVAILABLE: node-host worker stopped"))
729733
}
730-
if notifyUnexpectedExit, wasReady {
731-
self.onUnexpectedExit()
734+
if notifyUnexpectedExit, wasReady, let stoppedWorker {
735+
self.onUnexpectedExit(stoppedWorker.configurationGeneration)
732736
}
733737
guard let process = self.process else {
734738
return nil

‎apps/macos/Sources/OpenClaw/NodeMode/MacNodeHostWorkerRetryPolicy.swift‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import Foundation
33
struct MacNodeHostWorkerRetryPolicy: Sendable {
44
struct Input: Equatable, Sendable {
55
let launch: MacNodeHostWorkerLaunch
6-
let configurationGeneration: UInt64
76
}
87

98
enum UnexpectedExitDisposition: Equatable, Sendable {

‎apps/macos/Sources/OpenClaw/NodeMode/MacNodeModeCoordinator.swift‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ final class MacNodeModeCoordinator: NSObject {
130130

131131
override private convenience init() {
132132
let session = GatewayNodeSession()
133-
let nodeHostWorker = MacNodeHostWorker(session: session) {
134-
NotificationCenter.default.post(name: .openclawNodeHostWorkerFailed, object: nil)
133+
let nodeHostWorker = MacNodeHostWorker(session: session) { generation in
134+
NotificationCenter.default.post(name: .openclawNodeHostWorkerFailed, object: NSNumber(value: generation))
135135
}
136136
self.init(
137137
session: session,
@@ -259,7 +259,6 @@ final class MacNodeModeCoordinator: NSObject {
259259
}
260260

261261
func prepareForCuaDaemonStop() async {
262-
self.resetNodeHostWorkerRetryState()
263262
await self.enqueueRouteInvalidation(mode: .workerRestart).value
264263
}
265264

@@ -279,7 +278,6 @@ final class MacNodeModeCoordinator: NSObject {
279278
self.endpointRefreshTask = nil
280279
self.reconnectProbeTask?.cancel()
281280
self.reconnectProbeTask = nil
282-
self.resetNodeHostWorkerRetryState()
283281
}
284282

285283
func setPreferredGatewayStableID(
@@ -380,6 +378,15 @@ final class MacNodeModeCoordinator: NSObject {
380378
private func enqueueRouteInvalidation(
381379
mode: RouteInvalidationMode) -> Task<Void, Never>
382380
{
381+
// Worker replacement advances synchronously so a queued exit from the
382+
// old process cannot revoke or consume retry budget from its successor.
383+
switch mode {
384+
case .workerRestart, .terminalStop:
385+
self.nodeHostWorkerConfigurationGeneration &+= 1
386+
self.resetNodeHostWorkerRetryState()
387+
case .ordinaryDisconnect, .reconnectRefresh:
388+
break
389+
}
383390
self.revokeRouteAuthority()
384391
let invalidationGeneration = self.endpointAttemptGeneration
385392
let invalidatedRouteAuthorityGeneration = self.routeAuthorityGeneration
@@ -836,14 +843,16 @@ final class MacNodeModeCoordinator: NSObject {
836843
throw MacNodeHostWorkerRetryPolicy.RetryBackoffPending()
837844
}
838845
let input = MacNodeHostWorkerRetryPolicy.Input(
839-
launch: MacNodeHostWorkerLaunch(command: command),
840-
configurationGeneration: self.nodeHostWorkerConfigurationGeneration)
846+
launch: MacNodeHostWorkerLaunch(
847+
command: command,
848+
configurationGeneration: self.nodeHostWorkerConfigurationGeneration))
841849
try self.nodeHostWorkerRetryPolicy.prepareForStart(input)
842850
self.activeNodeHostWorkerInput = input
843851
}
844852

845-
func handleNodeHostWorkerFailureForTesting() {
846-
self.handleNodeHostWorkerFailure()
853+
func handleNodeHostWorkerFailureForTesting(configurationGeneration: UInt64? = nil) {
854+
self.handleNodeHostWorkerFailure(
855+
configurationGeneration: configurationGeneration ?? self.nodeHostWorkerConfigurationGeneration)
847856
}
848857

849858
func waitForNodeHostWorkerRetryForTesting() async {
@@ -866,9 +875,10 @@ final class MacNodeModeCoordinator: NSObject {
866875
}
867876
}
868877

869-
@objc private nonisolated func nodeHostWorkerFailed(_: Notification) {
878+
@objc private nonisolated func nodeHostWorkerFailed(_ notification: Notification) {
879+
guard let generation = (notification.object as? NSNumber)?.uint64Value else { return }
870880
Task { @MainActor [weak self] in
871-
self?.handleNodeHostWorkerFailure()
881+
self?.handleNodeHostWorkerFailure(configurationGeneration: generation)
872882
}
873883
}
874884

@@ -880,11 +890,9 @@ final class MacNodeModeCoordinator: NSObject {
880890

881891
@discardableResult
882892
private func handleNodeHostConfigurationChange() -> Task<Void, Never> {
883-
self.nodeHostWorkerConfigurationGeneration &+= 1
884-
self.resetNodeHostWorkerRetryState()
885893
// Worker code, plugin availability, and its manifest are startup-scoped.
886894
// Replace the process before reconnecting so updates cannot leave a stale route.
887-
return self.enqueueRouteInvalidation(mode: .workerRestart)
895+
self.enqueueRouteInvalidation(mode: .workerRestart)
888896
}
889897
}
890898

@@ -951,16 +959,16 @@ extension MacNodeModeCoordinator {
951959
let effectiveLaunch = MacNodeHostWorkerLaunch(
952960
command: launch.command,
953961
currentDirectoryURL: launch.currentDirectoryURL,
954-
environment: workerEnvironment)
955-
let input = MacNodeHostWorkerRetryPolicy.Input(
956-
launch: effectiveLaunch,
962+
environment: workerEnvironment,
957963
configurationGeneration: self.nodeHostWorkerConfigurationGeneration)
964+
let input = MacNodeHostWorkerRetryPolicy.Input(launch: effectiveLaunch)
958965
try self.nodeHostWorkerRetryPolicy.prepareForStart(input)
959966
self.activeNodeHostWorkerInput = input
960967
return try await nodeHostWorker.start(launch: effectiveLaunch)
961968
}
962969

963-
private func handleNodeHostWorkerFailure() {
970+
private func handleNodeHostWorkerFailure(configurationGeneration: UInt64) {
971+
guard configurationGeneration == self.nodeHostWorkerConfigurationGeneration else { return }
964972
guard let input = self.activeNodeHostWorkerInput else {
965973
self.logger.error("node-host worker exited without an active startup input")
966974
self.enqueueRouteInvalidation(mode: .ordinaryDisconnect)

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ struct MacNodeHostWorkerTests {
5151
@Test func `worker crash retry budget is bounded and exponentially delayed`() throws {
5252
let input = MacNodeHostWorkerRetryPolicy.Input(
5353
launch: MacNodeHostWorkerLaunch(
54-
command: ["/usr/local/bin/openclaw", "node", "worker"]),
55-
configurationGeneration: 4)
54+
command: ["/usr/local/bin/openclaw", "node", "worker"],
55+
configurationGeneration: 4))
5656
var policy = MacNodeHostWorkerRetryPolicy(maximumRetryCount: 5)
5757

5858
try policy.prepareForStart(input)
@@ -76,11 +76,12 @@ struct MacNodeHostWorkerTests {
7676
@Test func `new worker input resets an exhausted crash retry budget`() throws {
7777
let original = MacNodeHostWorkerRetryPolicy.Input(
7878
launch: MacNodeHostWorkerLaunch(
79-
command: ["/usr/local/bin/openclaw", "node", "worker"]),
80-
configurationGeneration: 4)
79+
command: ["/usr/local/bin/openclaw", "node", "worker"],
80+
configurationGeneration: 4))
8181
let updated = MacNodeHostWorkerRetryPolicy.Input(
82-
launch: original.launch,
83-
configurationGeneration: 5)
82+
launch: MacNodeHostWorkerLaunch(
83+
command: original.launch.command,
84+
configurationGeneration: 5))
8485
var policy = MacNodeHostWorkerRetryPolicy(maximumRetryCount: 1)
8586

8687
try policy.prepareForStart(original)
@@ -429,7 +430,9 @@ struct MacNodeHostWorkerTests {
429430
@Test func `ready worker exit notifies its route owner`() async throws {
430431
try await confirmation("unexpected worker exit") { confirmed in
431432
let exitGate = AsyncTestGate()
432-
let worker = MacNodeHostWorker(session: GatewayNodeSession()) {
433+
let expectedGeneration: UInt64 = 42
434+
let worker = MacNodeHostWorker(session: GatewayNodeSession()) { generation in
435+
#expect(generation == expectedGeneration)
433436
confirmed()
434437
exitGate.open()
435438
}
@@ -440,7 +443,8 @@ struct MacNodeHostWorkerTests {
440443
"""
441444

442445
_ = try await worker.start(launch: MacNodeHostWorkerLaunch(
443-
command: ["/bin/sh", "-c", script]))
446+
command: ["/bin/sh", "-c", script],
447+
configurationGeneration: expectedGeneration))
444448
await exitGate.wait()
445449
}
446450
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,27 @@ struct MacNodeModeCoordinatorTests {
304304
await coordinator.stopAndWait()
305305
}
306306

307+
@Test @MainActor func `queued failure from replaced worker does not penalize replacement`() async throws {
308+
let worker = CoordinatorNodeHostWorkerProbe()
309+
let session = GatewayNodeSession()
310+
let coordinator = MacNodeModeCoordinator(
311+
session: session,
312+
runtime: MacNodeRuntime(nodeHostWorker: worker),
313+
nodeHostWorker: worker)
314+
let command = ["/usr/local/bin/openclaw", "node", "worker"]
315+
316+
try coordinator.prepareNodeHostWorkerRetryForTesting(command: command)
317+
await coordinator.handleNodeHostConfigurationChangeForTesting()
318+
try coordinator.prepareNodeHostWorkerRetryForTesting(command: command)
319+
320+
// Generation zero belongs to the replaced process. Handle it only after
321+
// the successor input is installed so the ordering is deterministic.
322+
coordinator.handleNodeHostWorkerFailureForTesting(configurationGeneration: .zero)
323+
324+
try coordinator.prepareNodeHostWorkerRetryForTesting(command: command)
325+
await coordinator.stopAndWait()
326+
}
327+
307328
@Test func `paused node state requires route disconnect`() {
308329
#expect(MacNodeModeCoordinator.pausedStateRequiresDisconnect(true))
309330
#expect(!MacNodeModeCoordinator.pausedStateRequiresDisconnect(false))
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"startupJsGzipBytes": 333093,
3-
"reason": "folder group defaults catalog and lazy New Session route resolution",
4-
"updatedAt": "2026-08-14"
2+
"startupJsGzipBytes": 334391,
3+
"reason": "cumulative 2026-08-15 UI growth plus folder group defaults catalog and lazy New Session route resolution",
4+
"updatedAt": "2026-08-15"
55
}

0 commit comments

Comments
 (0)