Skip to content

Commit 1d2986b

Browse files
authored
fix: prevent incompatible cloud runtime dispatches (#126585)
* fix(ui): gate cloud profiles by runtime mode * test(gateway): expect cloud placement mode * test(gateway): keep route suite within lint budget
1 parent 68ae235 commit 1d2986b

25 files changed

Lines changed: 327 additions & 64 deletions

‎docs/gateway/cloud-workers.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ While a placement is active, OpenClaw automatically samples available space on t
182182
- **OpenClaw** uses `worker-turn` placement. The restricted `openclaw worker` process runs each turn on the leased node and proxies inference through the Gateway.
183183
- **Codex** uses `remote-exec` placement only when the selected provider advertises an SSH-backed execution carrier. The bundled Crabbox node provider does not, so Codex dispatch to Crabbox fails before allocation.
184184

185+
The Control UI disables cloud destinations whose advertised mode does not match the selected runtime.
186+
185187
Other runtimes remain unavailable unless their harness explicitly declares a cloud placement mode. Cloud targets are not offered for external CLI session catalogs. Remote-exec fails closed if the selected provider or placement sandbox is unavailable; it never falls back to running the operation on the Gateway host.
186188

187189
The equivalent RPC flow is:

‎packages/gateway-protocol/src/schema/agents-models-skills.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ describe("ModelsListResultSchema", () => {
270270
id: "codex",
271271
fallback: "openclaw",
272272
cloudPlacementSupported: true,
273+
cloudPlacementExecutionMode: "remote-exec",
273274
devicePlacementSupported: false,
274275
source: "model",
275276
},

‎packages/gateway-protocol/src/schema/agents-models-skills.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { Static } from "typebox";
33
import { Type } from "typebox";
44
import { closedObject } from "./closed-object.js";
5+
import { WorkerExecutionModeSchema } from "./environments.js";
56
import { NonEmptyString } from "./primitives.js";
67
import { GitHubSetupHandleSchema } from "./secrets.js";
78

@@ -19,6 +20,7 @@ const GatewayAgentRuntimeSchema = closedObject({
1920
id: NonEmptyString,
2021
fallback: Type.Optional(Type.Union([Type.Literal("openclaw"), Type.Literal("none")])),
2122
cloudPlacementSupported: Type.Optional(Type.Boolean()),
23+
cloudPlacementExecutionMode: Type.Optional(WorkerExecutionModeSchema),
2224
devicePlacementSupported: Type.Optional(Type.Boolean()),
2325
source: Type.Union([
2426
Type.Literal("env"),

‎packages/gateway-protocol/src/schema/environments.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ describe("worker environment protocol schemas", () => {
229229
id: "aws",
230230
providerId: "crabbox",
231231
trust: "disposable",
232+
executionMode: "remote-exec",
232233
machines: [
233234
{
234235
id: "standard",
@@ -239,6 +240,8 @@ describe("worker environment protocol schemas", () => {
239240
},
240241
],
241242
},
243+
{ id: "worker", providerId: "static-ssh", executionMode: "worker-turn" },
244+
{ id: "legacy", providerId: "static-ssh" },
242245
],
243246
}),
244247
).toBe(true);
@@ -254,6 +257,12 @@ describe("worker environment protocol schemas", () => {
254257
profiles: [{ id: "aws", providerId: "crabbox", trust: "temporary" }],
255258
}),
256259
).toBe(false);
260+
expect(
261+
Value.Check(EnvironmentsListResultSchema, {
262+
environments: [],
263+
profiles: [{ id: "aws", providerId: "crabbox", executionMode: "sandbox" }],
264+
}),
265+
).toBe(false);
257266
expect(
258267
Value.Check(EnvironmentsListResultSchema, {
259268
environments: [],

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,18 @@ export const WorkerMachineOptionsSchema = Type.Array(WorkerMachineOptionSchema,
128128
maxItems: 32,
129129
});
130130

131+
/** Placement execution modes shared by runtime requirements and worker providers. */
132+
export const WorkerExecutionModeSchema = Type.Union([
133+
Type.Literal("worker-turn"),
134+
Type.Literal("remote-exec"),
135+
]);
136+
131137
/** Configured worker target exposed without provider settings or credentials. */
132138
const WorkerEnvironmentProfileSummarySchema = closedObject({
133139
id: NonEmptyString,
134140
providerId: NonEmptyString,
135141
trust: Type.Optional(EnvironmentTrustSchema),
142+
executionMode: Type.Optional(WorkerExecutionModeSchema),
136143
machines: Type.Optional(WorkerMachineOptionsSchema),
137144
});
138145

@@ -199,6 +206,7 @@ export type RuntimeTargetIssue = Static<typeof RuntimeTargetIssueSchema>;
199206
export type WorkerSlotSummary = Static<typeof WorkerSlotSummarySchema>;
200207
export type WorkerEnvironmentMetadata = Static<typeof WorkerEnvironmentMetadataSchema>;
201208
export type WorkerMachineOption = Static<typeof WorkerMachineOptionSchema>;
209+
export type WorkerExecutionMode = Static<typeof WorkerExecutionModeSchema>;
202210
export type EnvironmentSummary = Static<typeof EnvironmentSummarySchema>;
203211
export type EnvironmentsCreateParams = Static<typeof EnvironmentsCreateParamsSchema>;
204212
export type EnvironmentsCreateResult = Static<typeof EnvironmentsCreateResultSchema>;

‎src/gateway/server-methods/environments.test.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type TestWorkerRecord = WorkerEnvironmentRecord &
4444
type TestWorkerService = {
4545
list: () => TestWorkerRecord[];
4646
get: (environmentId: string) => TestWorkerRecord | undefined;
47+
supportsExecutionMode: (profileId: string, mode: "worker-turn" | "remote-exec") => boolean;
4748
listMachineOptions: (
4849
profileId: string,
4950
) => Promise<
@@ -147,6 +148,7 @@ function workerService(overrides: Partial<TestWorkerService> = {}) {
147148
return {
148149
list: vi.fn(() => []),
149150
get: vi.fn(() => undefined),
151+
supportsExecutionMode: vi.fn(() => false),
150152
listMachineOptions: vi.fn(async () => undefined),
151153
create: vi.fn(async () => workerRecord()),
152154
destroy: vi.fn(async () => workerRecord({ state: "destroyed" })),
@@ -494,7 +496,7 @@ describe("environment gateway methods", () => {
494496
expect(worker?.worker).not.toHaveProperty("keyRef");
495497
});
496498

497-
it("adds provider machine options to configured profile summaries", async () => {
499+
it("adds known provider capabilities to configured profile summaries", async () => {
498500
const listMachineOptions = vi.fn(async (profileId: string) =>
499501
profileId === "aws"
500502
? [
@@ -511,7 +513,14 @@ describe("environment gateway methods", () => {
511513
const [ok, payload] = await callEnvironmentMethod(
512514
"environments.list",
513515
{},
514-
{ service: workerService({ listMachineOptions }) },
516+
{
517+
service: workerService({
518+
listMachineOptions,
519+
supportsExecutionMode: vi.fn(
520+
(profileId, mode) => profileId === "aws" && mode === "remote-exec",
521+
),
522+
}),
523+
},
515524
);
516525

517526
expect(ok).toBe(true);
@@ -520,6 +529,7 @@ describe("environment gateway methods", () => {
520529
{
521530
id: "aws",
522531
providerId: "crabbox",
532+
executionMode: "remote-exec",
523533
machines: [
524534
{
525535
id: "standard",
@@ -534,6 +544,11 @@ describe("environment gateway methods", () => {
534544
],
535545
});
536546
expect(listMachineOptions.mock.calls).toEqual([["aws"], ["zeta"]]);
547+
expect(
548+
(payload as { profiles: Array<Record<string, unknown>> }).profiles.find(
549+
(profile) => profile.id === "zeta",
550+
),
551+
).not.toHaveProperty("executionMode");
537552
});
538553

539554
it.each([

‎src/gateway/server-methods/environments.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,20 @@ async function listWorkerProfilesWithMachines(context: GatewayRequestContext) {
229229
const summaries = listWorkerProfiles(context);
230230
return await Promise.all(
231231
summaries.map(async (summary) => {
232+
const executionMode = (["worker-turn", "remote-exec"] as const).find(
233+
(mode) =>
234+
context.workerEnvironmentService?.supportsExecutionMode?.(summary.id, mode) === true,
235+
);
236+
const resolvedSummary = Object.assign(summary, executionMode ? { executionMode } : {});
232237
try {
233238
const options = await context.workerEnvironmentService?.listMachineOptions?.(summary.id);
234239
const machines = options ?? [];
235-
return machines.length > 0
236-
? { id: summary.id, providerId: summary.providerId, machines }
237-
: summary;
240+
return machines.length > 0 ? Object.assign(resolvedSummary, { machines }) : resolvedSummary;
238241
} catch (error) {
239242
context.logGateway.warn(
240243
`worker machine catalog unavailable (${summary.id}): ${formatForLog(error)}`,
241244
);
242-
return summary;
245+
return resolvedSummary;
243246
}
244247
}),
245248
);

‎src/gateway/server-methods/models-list-result.openai-routes.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ const IMPLICIT_CODEX_RUNTIME = {
2323
const IMPLICIT_OPENCLAW_RUNTIME = {
2424
id: "openclaw",
2525
cloudPlacementSupported: true,
26+
cloudPlacementExecutionMode: "worker-turn",
2627
devicePlacementSupported: true,
2728
source: "implicit",
2829
} as const;
2930
const MODEL_CODEX_RUNTIME = { ...IMPLICIT_CODEX_RUNTIME, source: "model" } as const;
30-
const MODEL_OPENCLAW_RUNTIME = { ...IMPLICIT_OPENCLAW_RUNTIME, source: "model" } as const;
3131

3232
function preparedOwnerFacts(config: OpenClawConfig) {
3333
return {
@@ -472,7 +472,7 @@ describe("models.list OpenAI routes", () => {
472472
expect.objectContaining({
473473
id: "gpt-worker",
474474
provider: "openai",
475-
agentRuntime: MODEL_OPENCLAW_RUNTIME,
475+
agentRuntime: { ...IMPLICIT_OPENCLAW_RUNTIME, source: "model" },
476476
}),
477477
],
478478
});

‎src/gateway/server-methods/models.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ describe("models.list", () => {
697697
agentRuntime: {
698698
id: "openclaw",
699699
cloudPlacementSupported: true,
700+
cloudPlacementExecutionMode: "worker-turn",
700701
devicePlacementSupported: true,
701702
source: "implicit",
702703
},
@@ -757,6 +758,7 @@ describe("models.list", () => {
757758
agentRuntime: {
758759
id: "openclaw",
759760
cloudPlacementSupported: true,
761+
cloudPlacementExecutionMode: "worker-turn",
760762
devicePlacementSupported: true,
761763
source: "implicit",
762764
},
@@ -808,6 +810,7 @@ describe("models.list", () => {
808810
agentRuntime: {
809811
id: "openclaw",
810812
cloudPlacementSupported: true,
813+
cloudPlacementExecutionMode: "worker-turn",
811814
devicePlacementSupported: true,
812815
source: "implicit",
813816
},

‎src/gateway/server.models-voicewake-misc.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ const expectedSortedCatalog = (gptTestZTags?: string[]): ModelCatalogRpcEntry[]
149149
agentRuntime: {
150150
id: "openclaw",
151151
cloudPlacementSupported: true,
152+
cloudPlacementExecutionMode: "worker-turn",
152153
devicePlacementSupported: true,
153154
source: "implicit",
154155
},
@@ -162,6 +163,7 @@ const expectedSortedCatalog = (gptTestZTags?: string[]): ModelCatalogRpcEntry[]
162163
agentRuntime: {
163164
id: "openclaw",
164165
cloudPlacementSupported: true,
166+
cloudPlacementExecutionMode: "worker-turn",
165167
devicePlacementSupported: true,
166168
source: "implicit",
167169
},
@@ -794,6 +796,7 @@ describe("gateway server models + voicewake", () => {
794796
agentRuntime: {
795797
id: "openclaw",
796798
cloudPlacementSupported: true,
799+
cloudPlacementExecutionMode: "worker-turn",
797800
devicePlacementSupported: true,
798801
source: "implicit",
799802
},
@@ -851,6 +854,7 @@ describe("gateway server models + voicewake", () => {
851854
agentRuntime: {
852855
id: "openclaw",
853856
cloudPlacementSupported: true,
857+
cloudPlacementExecutionMode: "worker-turn",
854858
devicePlacementSupported: true,
855859
source: "implicit",
856860
},
@@ -875,6 +879,7 @@ describe("gateway server models + voicewake", () => {
875879
agentRuntime: {
876880
id: "openclaw",
877881
cloudPlacementSupported: true,
882+
cloudPlacementExecutionMode: "worker-turn",
878883
devicePlacementSupported: true,
879884
source: "implicit",
880885
},

0 commit comments

Comments
 (0)