Skip to content

Commit d913796

Browse files
authored
fix(runners): preserve node workspaces across restarts (#123889)
* fix(runners): retain node workspaces from gateway state * docs(plan): record authoritative node retention
1 parent 9adfe07 commit d913796

23 files changed

Lines changed: 1568 additions & 404 deletions

‎docs/plan/runners.md‎

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ Proposal, revision 2. Supersedes revision 1 in place (2026-08-11, operator
1313
decision). Implementation in progress; update this table in every PR that
1414
advances a milestone.
1515

16-
| # | Milestone | Status | PRs |
17-
| --- | ---------------------------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------- |
18-
| 0 | This plan (revision 2) | landed | #122454 |
19-
| 1a | Naming: session copy revert | landed | #120667 |
20-
| 1b | Naming: devices consolidation | landed | #120689 |
21-
| 1c | Cleanup: node-pairing → device-pairing merge | landed | #120726 |
22-
| 2 | `openclaw resume` + web Continue in terminal | in progress | #120664, #122870 |
23-
| 3 | `openclaw connect` one-paste onboarding + `/j/` join route | in progress | #120768, #122499 |
24-
| 4 | Picker: grouping, placement, liveness, enrichment | in progress | #120804, #122531, #122635, #122774, #122923 |
25-
| F | Real-wire session boundary harness | landed | #121212 |
26-
| 5 | Public worker ingress path | landed | #122578, #122643 |
27-
| 6 | Node worker provider (device runners) | in progress | #122683, #122769, #122829, #122939, #123013, #123033, #122966, #123157, #123280, #123612, #123641, #123665, #123673, #123700 |
28-
| 7 | Bundle push consent + runner updates | not started | — |
29-
| 8 | Stop-and-continue moves | not started | — |
30-
| 9 | Deletions (ssh sandbox, openshell, exec-host clones, …) | not started | — |
31-
| 10 | Cloud convergence (provisioners run `openclaw connect`) | not started | — |
16+
| # | Milestone | Status | PRs |
17+
| --- | ---------------------------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
18+
| 0 | This plan (revision 2) | landed | #122454 |
19+
| 1a | Naming: session copy revert | landed | #120667 |
20+
| 1b | Naming: devices consolidation | landed | #120689 |
21+
| 1c | Cleanup: node-pairing → device-pairing merge | landed | #120726 |
22+
| 2 | `openclaw resume` + web Continue in terminal | in progress | #120664, #122870 |
23+
| 3 | `openclaw connect` one-paste onboarding + `/j/` join route | in progress | #120768, #122499 |
24+
| 4 | Picker: grouping, placement, liveness, enrichment | in progress | #120804, #122531, #122635, #122774, #122923 |
25+
| F | Real-wire session boundary harness | landed | #121212 |
26+
| 5 | Public worker ingress path | landed | #122578, #122643 |
27+
| 6 | Node worker provider (device runners) | in progress | #122683, #122769, #122829, #122939, #123013, #123033, #122966, #123157, #123280, #123612, #123641, #123665, #123673, #123700, #123696, #123785, #123859, #123889 |
28+
| 7 | Bundle push consent + runner updates | not started | — |
29+
| 8 | Stop-and-continue moves | not started | — |
30+
| 9 | Deletions (ssh sandbox, openshell, exec-host clones, …) | not started | — |
31+
| 10 | Cloud convergence (provisioners run `openclaw connect`) | not started | — |
3232

3333
Revision history: revision 1 (2026-08-08) established the session/runner
3434
vocabulary, the naming rulings, and the milestone skeleton after a
@@ -241,10 +241,13 @@ the durable launch identity so an upgrade cannot strand an existing worker.
241241
Node-local opt-in advertises the current installation; default nodes remain
242242
non-hosts. The supervisor now owns two atomic durable capacity slots, bounded
243243
10-second admission, restart reconciliation, and full/free inventory edges.
244-
Device dormancy expiry, terminal launch/environment retention, and node-host
245-
workspace-generation GC now bound persistent-machine growth.
246-
Milestone 7 upgrades this to Gateway-pinned, namespaced bundle bytes. Isolation,
247-
checkout ownership, and durable offline recovery actions remain milestone 6 work.
244+
Device dormancy expiry and terminal launch/environment retention bound durable
245+
rows. Node workspace cleanup waits for a full reconnect-scoped Gateway retain
246+
snapshot, unions that authority with node-local launch and operation ownership,
247+
and then removes retired generations, transfer siblings, unreachable manifests,
248+
and empty workspace parents in bounded passes. Milestone 7 upgrades this to
249+
Gateway-pinned, namespaced bundle bytes. Isolation, checkout ownership, and
250+
durable offline recovery actions remain milestone 6 work.
248251

249252
### Trust model (operator-decided, v1)
250253

‎src/gateway/server-lifecycle.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export async function prepareGatewayLifecycle(params: {
103103
desktopSessionRegistry,
104104
nodeDesktopStreamBroker,
105105
bindDeviceNodeControl,
106+
workerPlacementRuntime,
106107
} = runtime;
107108
const completeControlUiDeviceAuthMigrationForEffectiveOperator = (
108109
device: EffectiveOperatorDeviceIdentity,
@@ -181,6 +182,9 @@ export async function prepareGatewayLifecycle(params: {
181182
listRegisteredNodePluginToolCommands: () => pluginRuntime.registry.nodeHostCommands,
182183
nodePluginToolsEnabled: cfgAtStart.gateway?.nodes?.pluginTools?.enabled !== false,
183184
nodeSkillsEnabled: cfgAtStart.gateway?.nodes?.allowSkills !== false,
185+
onRunnerInventoryChanged: (nodeId) => {
186+
void workerPlacementRuntime?.scheduleNodeWorkspaceRetention(nodeId);
187+
},
184188
onPairingInvalidated: ({ nodeId, connId }) => {
185189
void nodeDesktopServiceRef.current?.stopNode(nodeId);
186190
upsertPresence(nodeId, { reason: "disconnect" });

‎src/gateway/server-node-session-runtime.test.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function createRuntime(
4444
Parameters<typeof createGatewayNodeSessionRuntime>[0]["isPairingStateCurrent"]
4545
> = (_nodeId, expected) =>
4646
expected.identity === "identity-a" && expected.generation === "generation-a",
47+
onRunnerInventoryChanged?: (nodeId: string) => void,
4748
) {
4849
return createGatewayNodeSessionRuntime({
4950
broadcast,
@@ -52,6 +53,7 @@ function createRuntime(
5253
generation: await resolveCurrentPairingGeneration(),
5354
}),
5455
isPairingStateCurrent,
56+
onRunnerInventoryChanged,
5557
sessionEventSubscribers: createSessionEventSubscriberRegistry(),
5658
sessionMessageSubscribers: createSessionMessageSubscriberRegistry(),
5759
});
@@ -95,9 +97,15 @@ describe("gateway node session runtime", () => {
9597
});
9698
});
9799

98-
test("broadcasts runner topology changes from publication and connection replacement", () => {
100+
test("broadcasts and routes runner inventory changes from publication and replacement", () => {
99101
const broadcast = vi.fn();
100-
const runtime = createRuntime(async () => "generation-a", broadcast);
102+
const onRunnerInventoryChanged = vi.fn();
103+
const runtime = createRuntime(
104+
async () => "generation-a",
105+
broadcast,
106+
undefined,
107+
onRunnerInventoryChanged,
108+
);
101109
registerNode(runtime, "conn-original", "generation-a", []);
102110

103111
expect(
@@ -115,10 +123,12 @@ describe("gateway node session runtime", () => {
115123
{ nodeId: "node-a" },
116124
{ dropIfSlow: true },
117125
);
126+
expect(onRunnerInventoryChanged).toHaveBeenLastCalledWith("node-a");
118127

119128
registerNode(runtime, "conn-replacement", "generation-a", []);
120129

121130
expect(broadcast).toHaveBeenCalledTimes(2);
131+
expect(onRunnerInventoryChanged).toHaveBeenCalledTimes(2);
122132
expect(broadcast).toHaveBeenLastCalledWith(
123133
GATEWAY_EVENT_NODE_RUNNER_INVENTORY_CHANGED,
124134
{ nodeId: "node-a" },

‎src/gateway/server-node-session-runtime.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export function createGatewayNodeSessionRuntime(params: {
3131
listRegisteredNodePluginToolCommands?: NodeRegistryOptions["listRegisteredNodePluginToolCommands"];
3232
nodePluginToolsEnabled?: boolean;
3333
nodeSkillsEnabled?: boolean;
34+
onRunnerInventoryChanged?: (nodeId: string) => void;
3435
resolveCurrentPairingState?: NodeRegistryOptions["resolveCurrentPairingState"];
3536
isPairingStateCurrent?: NodeRegistryOptions["isPairingStateCurrent"];
3637
onPairingInvalidated?: NodeRegistryOptions["onPairingInvalidated"];
@@ -60,6 +61,7 @@ export function createGatewayNodeSessionRuntime(params: {
6061
);
6162
setNodeRunnerInventoryChangedListener(nodeRegistry, (nodeId) => {
6263
params.broadcast(GATEWAY_EVENT_NODE_RUNNER_INVENTORY_CHANGED, { nodeId }, { dropIfSlow: true });
64+
params.onRunnerInventoryChanged?.(nodeId);
6365
});
6466
const nodePresenceTimers = new Map<string, ReturnType<typeof setInterval>>();
6567
const sessionEventSubscribers = params.sessionEventSubscribers;

‎src/gateway/server-runtime-state-prepare.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export async function prepareGatewayKernelState(params: {
165165
const {
166166
workerEnvironmentService,
167167
workerLiveEvents,
168+
nodeWorkerGatewayNamespace,
168169
bindDeviceNodeControl,
169170
bindNodeWorkspaceBindingResolver,
170171
handleNodeWorkspaceTransferRequest,
@@ -176,12 +177,13 @@ export async function prepareGatewayKernelState(params: {
176177
},
177178
};
178179
const workerPlacementRuntime =
179-
workerEnvironmentService && workerEnvironmentStartup
180+
workerEnvironmentService && workerEnvironmentStartup && nodeWorkerGatewayNamespace
180181
? await startupTrace.measure("worker-environments.placement-runtime", async () => {
181182
const placementModule = await loadWorkerPlacementStartupModule();
182183
return placementModule.createGatewayWorkerPlacementRuntime({
183184
placements: workerEnvironmentStartup.placementStore,
184185
environments: workerEnvironmentService,
186+
gatewayNamespace: nodeWorkerGatewayNamespace,
185187
admitNewPlacements: true,
186188
revokeSessionAuthority: (request) => workerDispatchAuthority.revoke(request),
187189
warn: (message) => log.warn(message),
@@ -194,6 +196,12 @@ export async function prepareGatewayKernelState(params: {
194196
workerPlacementRuntime.dispatchService.dispatch,
195197
);
196198
}
199+
const bindDeviceNodeRuntime = bindDeviceNodeControl
200+
? (transport: Parameters<NonNullable<typeof bindDeviceNodeControl>>[0]) => {
201+
bindDeviceNodeControl(transport);
202+
workerPlacementRuntime?.bindNodeWorkerSupervisorTransport(transport);
203+
}
204+
: undefined;
197205
const workerPlacementControlAvailable = workerPlacementRuntime?.dispatchService;
198206
const workerPlacementDispatchAvailable = workerPlacementControlAvailable;
199207
const workerDesktopObserveAvailable =
@@ -485,7 +493,7 @@ export async function prepareGatewayKernelState(params: {
485493
pluginRuntime,
486494
workerEnvironmentService,
487495
workerLiveEvents,
488-
bindDeviceNodeControl,
496+
bindDeviceNodeControl: bindDeviceNodeRuntime,
489497
workerDispatchAuthority,
490498
workerPlacementRuntime,
491499
workerPlacementControlAvailable,

‎src/gateway/server-worker-environment-startup.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
DEVICE_WORKER_PROVIDER_ID,
2020
} from "./worker-environments/device-provider.js";
2121
import type { WorkerLiveEventReceiver } from "./worker-environments/live-events.js";
22+
import { nodeWorkerGatewayNamespace as resolveNodeWorkerGatewayNamespace } from "./worker-environments/node-worker-gateway-namespace.js";
2223
import type { NodeWorkerWorkspaceBindingResolver } from "./worker-environments/node-worker-tunnel.js";
2324
import type { NodeWorkspaceTransferHttpCallback } from "./worker-environments/node-workspace-transfer-http-contract.js";
2425
import type { WorkerSessionPlacementStore } from "./worker-environments/placement-store.js";
@@ -48,6 +49,7 @@ export type GatewayWorkerEnvironmentRuntime = {
4849
workerEnvironmentService?: WorkerEnvironmentService;
4950
workerLiveEvents?: WorkerLiveEventReceiver;
5051
workerTunnelManager?: WorkerTunnelManager;
52+
nodeWorkerGatewayNamespace?: string;
5153
bindWorkerSessionDispatch?: (dispatch: WorkerPlacementDispatchContract["dispatch"]) => void;
5254
bindDeviceNodeControl?: (transport: NodeWorkerSupervisorTransport) => void;
5355
bindNodeWorkspaceBindingResolver?: (resolver: NodeWorkerWorkspaceBindingResolver) => void;
@@ -182,8 +184,10 @@ export async function createGatewayWorkerEnvironmentRuntime(params: {
182184
getOwner: (environmentId) => params.startup.store.getTransferOwner(environmentId),
183185
});
184186
await nodeWorkspaceTransfer.initialize();
187+
const gatewayDeviceId = loadOrCreateProcessDeviceIdentity().deviceId;
188+
const nodeWorkerGatewayNamespace = resolveNodeWorkerGatewayNamespace(gatewayDeviceId);
185189
const nodeWorkerTunnelManager = createNodeWorkerTunnelManager({
186-
gatewayDeviceId: loadOrCreateProcessDeviceIdentity().deviceId,
190+
gatewayDeviceId,
187191
getEnvironment: (environmentId) => params.startup.store.get(environmentId),
188192
getTransport: () => deviceRuntime.getNodeTransport(),
189193
launchNodeWorker: async (request) => await deviceRuntime.launchNodeWorker(request),
@@ -297,6 +301,7 @@ export async function createGatewayWorkerEnvironmentRuntime(params: {
297301
workerEnvironmentService,
298302
workerLiveEvents,
299303
workerTunnelManager,
304+
nodeWorkerGatewayNamespace,
300305
bindWorkerSessionDispatch: (dispatch) => {
301306
dispatchChild = dispatch;
302307
},

‎src/gateway/server-worker-placement-startup.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ describe("worker placement startup health lifetime", () => {
7272
listWorkspaceReconciliationOwners: () => [],
7373
} as never,
7474
environments: environments as never,
75+
gatewayNamespace: "gateway-test",
7576
admitNewPlacements: true,
7677
revokeSessionAuthority: vi.fn(),
7778
warn,
@@ -157,6 +158,7 @@ describe("worker placement startup health lifetime", () => {
157158
listWorkspaceReconciliationOwners: () => [],
158159
} as never,
159160
environments: environments as never,
161+
gatewayNamespace: "gateway-test",
160162
admitNewPlacements: true,
161163
revokeSessionAuthority: vi.fn(),
162164
warn: vi.fn(),

0 commit comments

Comments
 (0)