Skip to content

Commit b869d5e

Browse files
authored
fix(workers): skip shared-host quiescence sweeps (#120969)
* fix(workers): skip shared-host quiescence sweeps Refs #120952. * test(workers): update shared-host fixtures Refs #120952. * fix(workers): reconcile shared-host lease metadata * fix(workers): fence unknown lease isolation * chore(plugin-sdk): refresh API baseline * fix(workers): fence tunnel isolation updates * docs(workers): clarify shared-host final fences * ci: invalidate Vitest cache for state schemas * refactor(workers): import stableWorkerPathComponent from its defining module workspace-sync.ts crossed the 700-line lint budget by one; drop its re-export and point consumers at workspace-sync-helpers directly.
1 parent 262cf17 commit b869d5e

27 files changed

Lines changed: 375 additions & 96 deletions

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,23 @@ runs:
154154
# Blacksmith transparently accelerates the upstream Actions cache API.
155155
# The scheduled/dispatch warmer writes one immutable protected archive;
156156
# all CI shards restore it into isolated runner-local directories.
157-
key: ${{ github.repository }}-vitest-fs-v3-protected-${{ runner.os }}-${{ runner.arch }}-node-${{ inputs.node-version }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', '**/package.json', '**/tsconfig*.json', 'vitest.config.*', 'test/vitest/**', '!**/node_modules/**') }}-${{ github.run_id }}-${{ github.run_attempt }}
157+
key: ${{ github.repository }}-vitest-fs-v3-protected-${{ runner.os }}-${{ runner.arch }}-node-${{ inputs.node-version }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', '**/package.json', '**/tsconfig*.json', 'vitest.config.*', 'test/vitest/**', 'src/state/*.sql', '!**/node_modules/**') }}-${{ github.run_id }}-${{ github.run_attempt }}
158158
restore-keys: |
159-
${{ github.repository }}-vitest-fs-v3-protected-${{ runner.os }}-${{ runner.arch }}-node-${{ inputs.node-version }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', '**/package.json', '**/tsconfig*.json', 'vitest.config.*', 'test/vitest/**', '!**/node_modules/**') }}-
159+
${{ github.repository }}-vitest-fs-v3-protected-${{ runner.os }}-${{ runner.arch }}-node-${{ inputs.node-version }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', '**/package.json', '**/tsconfig*.json', 'vitest.config.*', 'test/vitest/**', 'src/state/*.sql', '!**/node_modules/**') }}-
160160
161161
- name: Restore Vitest transform cache
162162
if: inputs.vitest-fs-cache == 'true' && inputs.save-vitest-fs-cache != 'true' && runner.os != 'Windows'
163163
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
164164
with:
165165
path: /var/tmp/openclaw-vitest-fs-cache
166-
key: ${{ github.repository }}-vitest-fs-v3-protected-${{ runner.os }}-${{ runner.arch }}-node-${{ inputs.node-version }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', '**/package.json', '**/tsconfig*.json', 'vitest.config.*', 'test/vitest/**', '!**/node_modules/**') }}-${{ github.run_id }}-${{ github.run_attempt }}
166+
key: ${{ github.repository }}-vitest-fs-v3-protected-${{ runner.os }}-${{ runner.arch }}-node-${{ inputs.node-version }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', '**/package.json', '**/tsconfig*.json', 'vitest.config.*', 'test/vitest/**', 'src/state/*.sql', '!**/node_modules/**') }}-${{ github.run_id }}-${{ github.run_attempt }}
167167
restore-keys: |
168-
${{ github.repository }}-vitest-fs-v3-protected-${{ runner.os }}-${{ runner.arch }}-node-${{ inputs.node-version }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', '**/package.json', '**/tsconfig*.json', 'vitest.config.*', 'test/vitest/**', '!**/node_modules/**') }}-
168+
${{ github.repository }}-vitest-fs-v3-protected-${{ runner.os }}-${{ runner.arch }}-node-${{ inputs.node-version }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', '**/package.json', '**/tsconfig*.json', 'vitest.config.*', 'test/vitest/**', 'src/state/*.sql', '!**/node_modules/**') }}-
169169
170170
- name: Configure Vitest transform cache
171171
if: inputs.vitest-fs-cache == 'true' && runner.os != 'Windows'
172172
env:
173-
CACHE_GENERATION: ${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', '**/package.json', '**/tsconfig*.json', 'vitest.config.*', 'test/vitest/**', '!**/node_modules/**') }}
173+
CACHE_GENERATION: ${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', '**/package.json', '**/tsconfig*.json', 'vitest.config.*', 'test/vitest/**', 'src/state/*.sql', '!**/node_modules/**') }}
174174
CACHE_WRITER: ${{ inputs.save-vitest-fs-cache == 'true' && '1' || '0' }}
175175
shell: bash
176176
run: |

‎docs/.generated/plugin-sdk-api-baseline.sha256‎

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

‎docs/plugins/manifest.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ Provider plugins that implement both `resolveUsageAuth` and `fetchUsageSnapshot`
724724

725725
General embedding providers should declare `contracts.embeddingProviders` for each adapter registered with `api.registerEmbeddingProvider(...)`. Use the general contract for reusable vector generation, including providers consumed by memory search. `contracts.memoryEmbeddingProviders` is deprecated memory-specific compatibility and remains only while existing providers migrate to the generic embedding provider seam.
726726

727-
Worker providers must declare each `api.registerWorkerProvider(...)` id in `contracts.workerProviders`. Core persists durable intent before calling `provision`; providers validate their settings before external allocation, and repeated calls with the same operation id must adopt the same lease. Core also persists that validated settings snapshot and passes it with `leaseId` to `inspect({ leaseId, profile })` and `destroy({ leaseId, profile })`, including after the named profile is changed or removed. Destruction is idempotent, inspection returns the closed `active` / `destroyed` / `unknown` status union, and SSH private-key material is referenced only through `SecretRef`. Provisioned SSH endpoints must also include a public `hostKey` from trusted provisioning output as exactly `algorithm base64`, without a hostname or comment, so core can pin the host before connecting. They may include up to 10 ordered, unique `fallbackPorts`, excluding the primary `port`; core persists those candidates and rotates among them only for idempotent probes, content-addressed transfers, receipt/lock-guarded artifact installation, convergent managed-worktree mirroring, and tunnel reconnects. Ambiguous unguarded stateful commands fail closed and are not replayed across candidates. Providers that mint dynamic identity refs may implement authoritative `resolveSshIdentity({ leaseId, profile, keyRef })`; providers without it use core's generic secret resolver. An authoritative `unknown` orphans an active local record; after a persisted destroy request it confirms teardown.
727+
Worker providers must declare each `api.registerWorkerProvider(...)` id in `contracts.workerProviders`. Core persists durable intent before calling `provision`; providers validate their settings before external allocation, and repeated calls with the same operation id must adopt the same lease. Core also persists that validated settings snapshot and passes it with `leaseId` to `inspect({ leaseId, profile })` and `destroy({ leaseId, profile })`, including after the named profile is changed or removed. Destruction is idempotent, inspection returns the closed `active` / `destroyed` / `unknown` status union, and SSH private-key material is referenced only through `SecretRef`. Provisioned SSH endpoints must also include a public `hostKey` from trusted provisioning output as exactly `algorithm base64`, without a hostname or comment, so core can pin the host before connecting. They may include up to 10 ordered, unique `fallbackPorts`, excluding the primary `port`; core persists those candidates and rotates among them only for idempotent probes, content-addressed transfers, receipt/lock-guarded artifact installation, convergent managed-worktree mirroring, and tunnel reconnects. Ambiguous unguarded stateful commands fail closed and are not replayed across candidates. A lease may set `sharedHost: true` when the SSH account also owns unrelated processes; core then avoids host-wide process freezing during workspace reconciliation. Omitted or `false` means a dedicated worker host. Active inspection repeats this fact so core can reconcile provider-owned isolation for leases persisted before the field existed; tunnel startup waits for that first authoritative inspection. Providers that mint dynamic identity refs may implement authoritative `resolveSshIdentity({ leaseId, profile, keyRef })`; providers without it use core's generic secret resolver. An authoritative `unknown` orphans an active local record; after a persisted destroy request it confirms teardown.
728728

729729
`contracts.gatewayMethodDispatch` currently accepts `"authenticated-request"`. It is an API hygiene gate for native plugin HTTP routes that intentionally dispatch Gateway control-plane methods in-process, not a sandbox against malicious native plugins. Use it only for tightly reviewed bundled/operator surfaces that already require Gateway HTTP auth. An entitled route remains reachable while Gateway root-work admission is closed only when it also declares `auth: "gateway"` and the route-specific `gatewayRuntimeScopeSurface: "trusted-operator"`; ordinary sibling routes from the same plugin remain behind the admission boundary. This keeps suspension status and resume reachable without granting the whole plugin an admission bypass. Keep parsing and response shaping bounded outside dispatch; substantive or mutating work must go through Gateway method dispatch, which owns admission and scope enforcement.
730730

‎docs/plugins/sdk-overview.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ and external URLs. Registering another provider replaces the current provider.
119119

120120
Worker providers must also declare their id in `contracts.workerProviders`.
121121
Core persists durable intent before `provision(profile, operationId)`. Providers validate settings before external allocation and throw `WorkerProviderError` for permanent profile rejection. `provision` must adopt the same lease when the operation id repeats.
122-
Core persists the validated profile settings with the lease and supplies that snapshot to `destroy({ leaseId, profile })`, which must be idempotent, and `inspect({ leaseId, profile })`, which returns `active`, `destroyed`, or `unknown`. This lets providers route lifecycle calls after a gateway restart or named-profile removal. SSH endpoints use a `SecretRef` for `keyRef`, never inline key material, and include a `hostKey` from trusted provisioning output as exactly `algorithm base64`, without a hostname or comment. Core pins `hostKey` and never trusts a key from the first connection. Providers may also return up to 10 ordered, unique `fallbackPorts` (integer ports from 1 through 65535, excluding the primary `port`); core validates and persists those advertised candidates for idempotent probes, content-addressed transfers, receipt/lock-guarded artifact installation, convergent managed-worktree mirroring, and tunnel reconnects. Ambiguous unguarded stateful commands fail closed and are not replayed across candidates. A provider that mints a dynamic `keyRef` can implement `resolveSshIdentity({ leaseId, profile, keyRef })`; when present, that resolver is authoritative, while providers without it use the configured generic secret resolver.
122+
Core persists the validated profile settings with the lease and supplies that snapshot to `destroy({ leaseId, profile })`, which must be idempotent, and `inspect({ leaseId, profile })`, which returns `active`, `destroyed`, or `unknown`. This lets providers route lifecycle calls after a gateway restart or named-profile removal. SSH endpoints use a `SecretRef` for `keyRef`, never inline key material, and include a `hostKey` from trusted provisioning output as exactly `algorithm base64`, without a hostname or comment. Core pins `hostKey` and never trusts a key from the first connection. Providers may also return up to 10 ordered, unique `fallbackPorts` (integer ports from 1 through 65535, excluding the primary `port`); core validates and persists those advertised candidates for idempotent probes, content-addressed transfers, receipt/lock-guarded artifact installation, convergent managed-worktree mirroring, and tunnel reconnects. Ambiguous unguarded stateful commands fail closed and are not replayed across candidates. A lease may set `sharedHost: true` when the SSH account also owns unrelated processes; core then avoids host-wide process freezing during workspace reconciliation. Omitted or `false` means a dedicated worker host. Active inspection repeats this fact so core can reconcile provider-owned isolation for leases persisted before the field existed; tunnel startup waits for that first authoritative inspection. A provider that mints a dynamic `keyRef` can implement `resolveSshIdentity({ leaseId, profile, keyRef })`; when present, that resolver is authoritative, while providers without it use the configured generic secret resolver.
123123
Providers with renewable leases can also implement `renew(leaseId)`.
124124
`inspect` must throw on transient or indeterminate failures; return `unknown` only for authoritative absence. Core marks an active local record orphaned, or treats the absence as teardown completion after a persisted destroy request.
125125

‎extensions/qa-lab/src/static-ssh-worker-provider.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe("QA Lab static-SSH worker provider", () => {
3232
expect(provider.id).toBe("static-ssh");
3333
expect(first).toStrictEqual({
3434
leaseId: "static-ssh:operation-123",
35+
sharedHost: true,
3536
ssh: {
3637
host: "worker.example.test",
3738
port: 22,
@@ -152,6 +153,7 @@ describe("QA Lab static-SSH worker provider", () => {
152153
provider.inspect({ leaseId: "static-ssh:operation-123", profile: PROFILE }),
153154
).resolves.toStrictEqual({
154155
status: "active",
156+
sharedHost: true,
155157
});
156158
await expect(
157159
provider.inspect({ leaseId: "static-ssh:", profile: PROFILE }),

‎extensions/qa-lab/src/static-ssh-worker-provider.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@ export function createStaticSshWorkerProvider(): WorkerProvider {
7777
return {
7878
leaseId: `${STATIC_SSH_LEASE_PREFIX}${opId}`,
7979
ssh: parseStaticSshWorkerSettings(profile),
80+
sharedHost: true,
8081
};
8182
},
8283
async inspect({ leaseId }) {
8384
const active =
8485
leaseId.startsWith(STATIC_SSH_LEASE_PREFIX) &&
8586
leaseId.length > STATIC_SSH_LEASE_PREFIX.length;
86-
return { status: active ? "active" : "unknown" };
87+
return active ? { status: "active", sharedHost: true } : { status: "unknown" };
8788
},
8889
// Development-only: a static worker is a shared host, not an isolation boundary.
8990
// Destroy releases the logical lease; it does not stop or clean the host.

‎src/gateway/worker-environments/placement-dispatch-test-fixtures.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export function createDispatchEnvironmentFixtures(generation = 1) {
104104
profileId: "development",
105105
profileSnapshot,
106106
provisionOperationId: "provision-1",
107+
sharedHost: false,
107108
bootstrapReceipt,
108109
teardownTerminalState: null,
109110
lastError: null,

‎src/gateway/worker-environments/service-validation.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,40 @@ import { redactSensitiveText } from "../../logging/redact.js";
55
import type { WorkerLease, WorkerLeaseStatus, WorkerSshEndpoint } from "../../plugins/types.js";
66
import { normalizeWorkerSshEndpoint } from "./store.js";
77

8-
export function inspectionStatus(value: unknown): WorkerLeaseStatus["status"] {
8+
export function requireWorkerLeaseStatus(value: unknown): WorkerLeaseStatus {
99
if (!isRecord(value)) {
1010
throw new Error("Worker provider returned an invalid inspection result");
1111
}
1212
const status = value.status;
1313
if (status !== "active" && status !== "destroyed" && status !== "unknown") {
1414
throw new Error("Worker provider returned an invalid inspection status");
1515
}
16-
return status;
16+
if (status === "active") {
17+
if (value.sharedHost !== undefined && typeof value.sharedHost !== "boolean") {
18+
throw new Error("Worker provider returned an invalid inspection result");
19+
}
20+
return { status, sharedHost: value.sharedHost === true };
21+
}
22+
if (value.sharedHost !== undefined) {
23+
throw new Error("Worker provider returned an invalid inspection result");
24+
}
25+
return { status };
1726
}
1827

1928
export function requireWorkerLease(value: unknown): WorkerLease {
2029
if (
2130
!isRecord(value) ||
2231
typeof value.leaseId !== "string" ||
2332
!value.leaseId.trim() ||
24-
!isRecord(value.ssh)
33+
!isRecord(value.ssh) ||
34+
(value.sharedHost !== undefined && typeof value.sharedHost !== "boolean")
2535
) {
2636
throw new Error("Worker provider returned an invalid provision result");
2737
}
2838
return {
2939
leaseId: value.leaseId.trim(),
3040
ssh: normalizeWorkerSshEndpoint(value.ssh as WorkerSshEndpoint),
41+
...(value.sharedHost === true ? { sharedHost: true } : {}),
3142
};
3243
}
3344

0 commit comments

Comments
 (0)