@gpustack/loopwright 0.0.0-stage → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +356 -2
- package/bin/loopwright.js +3 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter-v2.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter-v2.js +122 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter.d.ts +30 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter.js +340 -0
- package/node_modules/@loopwright/agent-pi/dist/admission.d.ts +25 -0
- package/node_modules/@loopwright/agent-pi/dist/admission.js +65 -0
- package/node_modules/@loopwright/agent-pi/dist/artifacts.d.ts +15 -0
- package/node_modules/@loopwright/agent-pi/dist/artifacts.js +76 -0
- package/node_modules/@loopwright/agent-pi/dist/boundary.d.ts +18 -0
- package/node_modules/@loopwright/agent-pi/dist/boundary.js +113 -0
- package/node_modules/@loopwright/agent-pi/dist/broker-channel.d.ts +4 -0
- package/node_modules/@loopwright/agent-pi/dist/broker-channel.js +121 -0
- package/node_modules/@loopwright/agent-pi/dist/candidate.d.ts +96 -0
- package/node_modules/@loopwright/agent-pi/dist/candidate.js +1712 -0
- package/node_modules/@loopwright/agent-pi/dist/capture.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/capture.js +146 -0
- package/node_modules/@loopwright/agent-pi/dist/cas.d.ts +51 -0
- package/node_modules/@loopwright/agent-pi/dist/cas.js +836 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog-api.d.ts +3 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog-api.js +2 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog.js +280 -0
- package/node_modules/@loopwright/agent-pi/dist/circuit-breaker-limits.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/circuit-breaker-limits.js +12 -0
- package/node_modules/@loopwright/agent-pi/dist/containers.d.ts +29 -0
- package/node_modules/@loopwright/agent-pi/dist/containers.js +160 -0
- package/node_modules/@loopwright/agent-pi/dist/context.d.ts +56 -0
- package/node_modules/@loopwright/agent-pi/dist/context.js +351 -0
- package/node_modules/@loopwright/agent-pi/dist/daemon.d.ts +8 -0
- package/node_modules/@loopwright/agent-pi/dist/daemon.js +52 -0
- package/node_modules/@loopwright/agent-pi/dist/deadline.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/deadline.js +18 -0
- package/node_modules/@loopwright/agent-pi/dist/decode-capture.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/decode-capture.js +287 -0
- package/node_modules/@loopwright/agent-pi/dist/descriptor.d.ts +12 -0
- package/node_modules/@loopwright/agent-pi/dist/descriptor.js +17 -0
- package/node_modules/@loopwright/agent-pi/dist/docker-absence.d.ts +2 -0
- package/node_modules/@loopwright/agent-pi/dist/docker-absence.js +9 -0
- package/node_modules/@loopwright/agent-pi/dist/errors.d.ts +7 -0
- package/node_modules/@loopwright/agent-pi/dist/errors.js +19 -0
- package/node_modules/@loopwright/agent-pi/dist/event-sequence.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/event-sequence.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/events.d.ts +19 -0
- package/node_modules/@loopwright/agent-pi/dist/events.js +132 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-guard.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-guard.js +25 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-lease.d.ts +24 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-lease.js +316 -0
- package/node_modules/@loopwright/agent-pi/dist/execution.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/execution.js +476 -0
- package/node_modules/@loopwright/agent-pi/dist/external-mcp.d.ts +87 -0
- package/node_modules/@loopwright/agent-pi/dist/external-mcp.js +526 -0
- package/node_modules/@loopwright/agent-pi/dist/factory-bootstrap.d.ts +15 -0
- package/node_modules/@loopwright/agent-pi/dist/factory-bootstrap.js +74 -0
- package/node_modules/@loopwright/agent-pi/dist/host-session.d.ts +51 -0
- package/node_modules/@loopwright/agent-pi/dist/host-session.js +2094 -0
- package/node_modules/@loopwright/agent-pi/dist/http-mcp.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/http-mcp.js +353 -0
- package/node_modules/@loopwright/agent-pi/dist/index.d.ts +7 -0
- package/node_modules/@loopwright/agent-pi/dist/index.js +4 -0
- package/node_modules/@loopwright/agent-pi/dist/lifecycle.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/lifecycle.js +11 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-process.d.ts +35 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-process.js +92 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-transport.d.ts +25 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-transport.js +63 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp.d.ts +23 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp.js +212 -0
- package/node_modules/@loopwright/agent-pi/dist/operation.d.ts +5 -0
- package/node_modules/@loopwright/agent-pi/dist/operation.js +28 -0
- package/node_modules/@loopwright/agent-pi/dist/policy-v2.d.ts +10 -0
- package/node_modules/@loopwright/agent-pi/dist/policy-v2.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/policy.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/policy.js +260 -0
- package/node_modules/@loopwright/agent-pi/dist/preflight.d.ts +60 -0
- package/node_modules/@loopwright/agent-pi/dist/preflight.js +700 -0
- package/node_modules/@loopwright/agent-pi/dist/progress-summary.d.ts +1 -0
- package/node_modules/@loopwright/agent-pi/dist/progress-summary.js +119 -0
- package/node_modules/@loopwright/agent-pi/dist/protocol.d.ts +17 -0
- package/node_modules/@loopwright/agent-pi/dist/protocol.js +131 -0
- package/node_modules/@loopwright/agent-pi/dist/provider.d.ts +62 -0
- package/node_modules/@loopwright/agent-pi/dist/provider.js +217 -0
- package/node_modules/@loopwright/agent-pi/dist/receipt.d.ts +3 -0
- package/node_modules/@loopwright/agent-pi/dist/receipt.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/recovery.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/recovery.js +188 -0
- package/node_modules/@loopwright/agent-pi/dist/resources.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/resources.js +81 -0
- package/node_modules/@loopwright/agent-pi/dist/response.d.ts +20 -0
- package/node_modules/@loopwright/agent-pi/dist/response.js +259 -0
- package/node_modules/@loopwright/agent-pi/dist/runtime-profile.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/runtime-profile.js +37 -0
- package/node_modules/@loopwright/agent-pi/dist/sdk-worker.d.ts +14 -0
- package/node_modules/@loopwright/agent-pi/dist/sdk-worker.js +633 -0
- package/node_modules/@loopwright/agent-pi/dist/sender.d.ts +46 -0
- package/node_modules/@loopwright/agent-pi/dist/sender.js +553 -0
- package/node_modules/@loopwright/agent-pi/dist/session-host.d.ts +21 -0
- package/node_modules/@loopwright/agent-pi/dist/session-host.js +315 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot-transfer.d.ts +14 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot-transfer.js +102 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot.d.ts +19 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot.js +121 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-process.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-process.js +85 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-worker.d.ts +2 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-worker.js +105 -0
- package/node_modules/@loopwright/agent-pi/dist/tools.d.ts +36 -0
- package/node_modules/@loopwright/agent-pi/dist/tools.js +128 -0
- package/node_modules/@loopwright/agent-pi/dist/types-v2.d.ts +71 -0
- package/node_modules/@loopwright/agent-pi/dist/types-v2.js +1 -0
- package/node_modules/@loopwright/agent-pi/dist/types.d.ts +314 -0
- package/node_modules/@loopwright/agent-pi/dist/types.js +1 -0
- package/node_modules/@loopwright/agent-pi/dist/usage.d.ts +18 -0
- package/node_modules/@loopwright/agent-pi/dist/usage.js +314 -0
- package/node_modules/@loopwright/agent-pi/dist/workspace-mcp.d.ts +27 -0
- package/node_modules/@loopwright/agent-pi/dist/workspace-mcp.js +142 -0
- package/node_modules/@loopwright/agent-pi/package.json +24 -0
- package/node_modules/@loopwright/agent-pi/runtime/Dockerfile +8 -0
- package/node_modules/@loopwright/agent-pi/runtime/seccomp.json +1 -0
- package/node_modules/@loopwright/cli/dist/arguments.d.ts +19 -0
- package/node_modules/@loopwright/cli/dist/arguments.js +358 -0
- package/node_modules/@loopwright/cli/dist/closure.d.ts +93 -0
- package/node_modules/@loopwright/cli/dist/closure.js +230 -0
- package/node_modules/@loopwright/cli/dist/draft.d.ts +9 -0
- package/node_modules/@loopwright/cli/dist/draft.js +106 -0
- package/node_modules/@loopwright/cli/dist/failure-matrix.d.ts +9 -0
- package/node_modules/@loopwright/cli/dist/failure-matrix.js +701 -0
- package/node_modules/@loopwright/cli/dist/index.d.ts +6 -0
- package/node_modules/@loopwright/cli/dist/index.js +5 -0
- package/node_modules/@loopwright/cli/dist/main.d.ts +22 -0
- package/node_modules/@loopwright/cli/dist/main.js +1855 -0
- package/node_modules/@loopwright/cli/package.json +16 -0
- package/node_modules/@loopwright/controller/dist/acceptance.d.ts +43 -0
- package/node_modules/@loopwright/controller/dist/acceptance.js +446 -0
- package/node_modules/@loopwright/controller/dist/benchmark-gate.d.ts +273 -0
- package/node_modules/@loopwright/controller/dist/benchmark-gate.js +3147 -0
- package/node_modules/@loopwright/controller/dist/budget-observations.d.ts +25 -0
- package/node_modules/@loopwright/controller/dist/budget-observations.js +139 -0
- package/node_modules/@loopwright/controller/dist/bundle.d.ts +26 -0
- package/node_modules/@loopwright/controller/dist/bundle.js +64 -0
- package/node_modules/@loopwright/controller/dist/capture.d.ts +89 -0
- package/node_modules/@loopwright/controller/dist/capture.js +587 -0
- package/node_modules/@loopwright/controller/dist/compile.d.ts +3 -0
- package/node_modules/@loopwright/controller/dist/compile.js +402 -0
- package/node_modules/@loopwright/controller/dist/config.d.ts +22 -0
- package/node_modules/@loopwright/controller/dist/config.js +255 -0
- package/node_modules/@loopwright/controller/dist/controller.d.ts +177 -0
- package/node_modules/@loopwright/controller/dist/controller.js +2135 -0
- package/node_modules/@loopwright/controller/dist/credentials.d.ts +29 -0
- package/node_modules/@loopwright/controller/dist/credentials.js +189 -0
- package/node_modules/@loopwright/controller/dist/deadlines.d.ts +18 -0
- package/node_modules/@loopwright/controller/dist/deadlines.js +71 -0
- package/node_modules/@loopwright/controller/dist/errors.d.ts +27 -0
- package/node_modules/@loopwright/controller/dist/errors.js +41 -0
- package/node_modules/@loopwright/controller/dist/events.d.ts +52 -0
- package/node_modules/@loopwright/controller/dist/events.js +228 -0
- package/node_modules/@loopwright/controller/dist/files.d.ts +51 -0
- package/node_modules/@loopwright/controller/dist/files.js +386 -0
- package/node_modules/@loopwright/controller/dist/finalize.d.ts +25 -0
- package/node_modules/@loopwright/controller/dist/finalize.js +32 -0
- package/node_modules/@loopwright/controller/dist/gate.d.ts +84 -0
- package/node_modules/@loopwright/controller/dist/gate.js +640 -0
- package/node_modules/@loopwright/controller/dist/git-objects.d.ts +11 -0
- package/node_modules/@loopwright/controller/dist/git-objects.js +59 -0
- package/node_modules/@loopwright/controller/dist/git-reader.d.ts +17 -0
- package/node_modules/@loopwright/controller/dist/git-reader.js +40 -0
- package/node_modules/@loopwright/controller/dist/handlers.d.ts +6 -0
- package/node_modules/@loopwright/controller/dist/handlers.js +45 -0
- package/node_modules/@loopwright/controller/dist/handoff.d.ts +71 -0
- package/node_modules/@loopwright/controller/dist/handoff.js +554 -0
- package/node_modules/@loopwright/controller/dist/index.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/index.js +21 -0
- package/node_modules/@loopwright/controller/dist/inspect.d.ts +30 -0
- package/node_modules/@loopwright/controller/dist/inspect.js +372 -0
- package/node_modules/@loopwright/controller/dist/interpolation.d.ts +9 -0
- package/node_modules/@loopwright/controller/dist/interpolation.js +79 -0
- package/node_modules/@loopwright/controller/dist/ownership.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/ownership.js +666 -0
- package/node_modules/@loopwright/controller/dist/parser.d.ts +5 -0
- package/node_modules/@loopwright/controller/dist/parser.js +200 -0
- package/node_modules/@loopwright/controller/dist/progress.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/progress.js +904 -0
- package/node_modules/@loopwright/controller/dist/publication.d.ts +60 -0
- package/node_modules/@loopwright/controller/dist/publication.js +329 -0
- package/node_modules/@loopwright/controller/dist/reconcile.d.ts +26 -0
- package/node_modules/@loopwright/controller/dist/reconcile.js +1378 -0
- package/node_modules/@loopwright/controller/dist/recovery.d.ts +10 -0
- package/node_modules/@loopwright/controller/dist/recovery.js +315 -0
- package/node_modules/@loopwright/controller/dist/refusal-record.d.ts +43 -0
- package/node_modules/@loopwright/controller/dist/refusal-record.js +150 -0
- package/node_modules/@loopwright/controller/dist/registry.d.ts +6 -0
- package/node_modules/@loopwright/controller/dist/registry.js +374 -0
- package/node_modules/@loopwright/controller/dist/repair.d.ts +31 -0
- package/node_modules/@loopwright/controller/dist/repair.js +102 -0
- package/node_modules/@loopwright/controller/dist/report.d.ts +64 -0
- package/node_modules/@loopwright/controller/dist/report.js +596 -0
- package/node_modules/@loopwright/controller/dist/retained.d.ts +284 -0
- package/node_modules/@loopwright/controller/dist/retained.js +193 -0
- package/node_modules/@loopwright/controller/dist/rules.d.ts +31 -0
- package/node_modules/@loopwright/controller/dist/rules.js +110 -0
- package/node_modules/@loopwright/controller/dist/run-eval.d.ts +115 -0
- package/node_modules/@loopwright/controller/dist/run-eval.js +959 -0
- package/node_modules/@loopwright/controller/dist/scheduler.d.ts +10 -0
- package/node_modules/@loopwright/controller/dist/scheduler.js +41 -0
- package/node_modules/@loopwright/controller/dist/schema.d.ts +17 -0
- package/node_modules/@loopwright/controller/dist/schema.js +78 -0
- package/node_modules/@loopwright/controller/dist/source.d.ts +69 -0
- package/node_modules/@loopwright/controller/dist/source.js +872 -0
- package/node_modules/@loopwright/controller/dist/step.d.ts +38 -0
- package/node_modules/@loopwright/controller/dist/step.js +1776 -0
- package/node_modules/@loopwright/controller/dist/storage.d.ts +90 -0
- package/node_modules/@loopwright/controller/dist/storage.js +1345 -0
- package/node_modules/@loopwright/controller/dist/submission.d.ts +51 -0
- package/node_modules/@loopwright/controller/dist/submission.js +292 -0
- package/node_modules/@loopwright/controller/dist/types.d.ts +585 -0
- package/node_modules/@loopwright/controller/dist/types.js +9 -0
- package/node_modules/@loopwright/controller/dist/verification.d.ts +124 -0
- package/node_modules/@loopwright/controller/dist/verification.js +1308 -0
- package/node_modules/@loopwright/controller/dist/verifier-protocol.d.ts +105 -0
- package/node_modules/@loopwright/controller/dist/verifier-protocol.js +1312 -0
- package/node_modules/@loopwright/controller/dist/verifier-worker.d.ts +1 -0
- package/node_modules/@loopwright/controller/dist/verifier-worker.js +33 -0
- package/node_modules/@loopwright/controller/package.json +12 -0
- package/node_modules/@loopwright/core/dist/acceptance.d.ts +108 -0
- package/node_modules/@loopwright/core/dist/acceptance.js +327 -0
- package/node_modules/@loopwright/core/dist/artifacts.d.ts +63 -0
- package/node_modules/@loopwright/core/dist/artifacts.js +356 -0
- package/node_modules/@loopwright/core/dist/boundary.d.ts +21 -0
- package/node_modules/@loopwright/core/dist/boundary.js +484 -0
- package/node_modules/@loopwright/core/dist/contracts.d.ts +287 -0
- package/node_modules/@loopwright/core/dist/contracts.js +694 -0
- package/node_modules/@loopwright/core/dist/diagnostics.d.ts +21 -0
- package/node_modules/@loopwright/core/dist/diagnostics.js +51 -0
- package/node_modules/@loopwright/core/dist/evidence.d.ts +92 -0
- package/node_modules/@loopwright/core/dist/evidence.js +85 -0
- package/node_modules/@loopwright/core/dist/graph.d.ts +8 -0
- package/node_modules/@loopwright/core/dist/graph.js +44 -0
- package/node_modules/@loopwright/core/dist/identity.d.ts +162 -0
- package/node_modules/@loopwright/core/dist/identity.js +80 -0
- package/node_modules/@loopwright/core/dist/index.d.ts +30 -0
- package/node_modules/@loopwright/core/dist/index.js +39 -0
- package/node_modules/@loopwright/core/dist/limits.d.ts +99 -0
- package/node_modules/@loopwright/core/dist/limits.js +59 -0
- package/node_modules/@loopwright/core/dist/results.d.ts +161 -0
- package/node_modules/@loopwright/core/dist/results.js +98 -0
- package/node_modules/@loopwright/core/dist/scope.d.ts +13 -0
- package/node_modules/@loopwright/core/dist/scope.js +154 -0
- package/node_modules/@loopwright/core/dist/scrubber.d.ts +13 -0
- package/node_modules/@loopwright/core/dist/scrubber.js +63 -0
- package/node_modules/@loopwright/core/dist/usage.d.ts +68 -0
- package/node_modules/@loopwright/core/dist/usage.js +56 -0
- package/node_modules/@loopwright/core/package.json +12 -0
- package/node_modules/@loopwright/decisions/dist/benchmark.d.ts +23 -0
- package/node_modules/@loopwright/decisions/dist/benchmark.js +337 -0
- package/node_modules/@loopwright/decisions/dist/client.d.ts +74 -0
- package/node_modules/@loopwright/decisions/dist/client.js +292 -0
- package/node_modules/@loopwright/decisions/dist/index.d.ts +15 -0
- package/node_modules/@loopwright/decisions/dist/index.js +8 -0
- package/node_modules/@loopwright/decisions/dist/nodes.d.ts +63 -0
- package/node_modules/@loopwright/decisions/dist/nodes.js +282 -0
- package/node_modules/@loopwright/decisions/dist/primitives.d.ts +36 -0
- package/node_modules/@loopwright/decisions/dist/primitives.js +300 -0
- package/node_modules/@loopwright/decisions/dist/redaction.d.ts +23 -0
- package/node_modules/@loopwright/decisions/dist/redaction.js +146 -0
- package/node_modules/@loopwright/decisions/dist/router.d.ts +55 -0
- package/node_modules/@loopwright/decisions/dist/router.js +248 -0
- package/node_modules/@loopwright/decisions/dist/schema.d.ts +25 -0
- package/node_modules/@loopwright/decisions/dist/schema.js +536 -0
- package/node_modules/@loopwright/decisions/dist/types.d.ts +394 -0
- package/node_modules/@loopwright/decisions/dist/types.js +80 -0
- package/node_modules/@loopwright/decisions/package.json +12 -0
- package/node_modules/@loopwright/github-app/dist/action.d.ts +90 -0
- package/node_modules/@loopwright/github-app/dist/action.js +2429 -0
- package/node_modules/@loopwright/github-app/dist/config.d.ts +23 -0
- package/node_modules/@loopwright/github-app/dist/config.js +297 -0
- package/node_modules/@loopwright/github-app/dist/digests.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/digests.js +1 -0
- package/node_modules/@loopwright/github-app/dist/index.d.ts +14 -0
- package/node_modules/@loopwright/github-app/dist/index.js +13 -0
- package/node_modules/@loopwright/github-app/dist/models-config.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/models-config.js +1 -0
- package/node_modules/@loopwright/github-app/dist/output-format.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/output-format.js +1 -0
- package/node_modules/@loopwright/github-app/dist/preflight.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/preflight.js +1 -0
- package/node_modules/@loopwright/github-app/dist/publisher.d.ts +58 -0
- package/node_modules/@loopwright/github-app/dist/publisher.js +1368 -0
- package/node_modules/@loopwright/github-app/dist/qualification.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/qualification.js +1 -0
- package/node_modules/@loopwright/github-app/dist/sandbox.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/sandbox.js +1 -0
- package/node_modules/@loopwright/github-app/dist/schema.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/schema.js +1 -0
- package/node_modules/@loopwright/github-app/dist/service.d.ts +52 -0
- package/node_modules/@loopwright/github-app/dist/service.js +1658 -0
- package/node_modules/@loopwright/github-app/dist/suite-pr-lookup.d.ts +90 -0
- package/node_modules/@loopwright/github-app/dist/suite-pr-lookup.js +392 -0
- package/node_modules/@loopwright/github-app/dist/taskpack.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/taskpack.js +1 -0
- package/node_modules/@loopwright/github-app/dist/tenant-queue.d.ts +44 -0
- package/node_modules/@loopwright/github-app/dist/tenant-queue.js +423 -0
- package/node_modules/@loopwright/github-app/dist/token-broker.d.ts +50 -0
- package/node_modules/@loopwright/github-app/dist/token-broker.js +262 -0
- package/node_modules/@loopwright/github-app/dist/turnkey-memory.d.ts +35 -0
- package/node_modules/@loopwright/github-app/dist/turnkey-memory.js +1654 -0
- package/node_modules/@loopwright/github-app/dist/turnkey.d.ts +16 -0
- package/node_modules/@loopwright/github-app/dist/turnkey.js +34 -0
- package/node_modules/@loopwright/github-app/dist/types.d.ts +220 -0
- package/node_modules/@loopwright/github-app/dist/types.js +14 -0
- package/node_modules/@loopwright/github-app/dist/upstreams.d.ts +13 -0
- package/node_modules/@loopwright/github-app/dist/upstreams.js +65 -0
- package/node_modules/@loopwright/github-app/dist/webhook.d.ts +34 -0
- package/node_modules/@loopwright/github-app/dist/webhook.js +241 -0
- package/node_modules/@loopwright/github-app/dist/yaml.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/yaml.js +1 -0
- package/node_modules/@loopwright/github-app/package.json +12 -0
- package/node_modules/@loopwright/hardware-runner/dist/config.d.ts +48 -0
- package/node_modules/@loopwright/hardware-runner/dist/config.js +719 -0
- package/node_modules/@loopwright/hardware-runner/dist/evaluator.d.ts +230 -0
- package/node_modules/@loopwright/hardware-runner/dist/evaluator.js +3178 -0
- package/node_modules/@loopwright/hardware-runner/dist/index.d.ts +13 -0
- package/node_modules/@loopwright/hardware-runner/dist/index.js +9 -0
- package/node_modules/@loopwright/hardware-runner/dist/provenance.d.ts +128 -0
- package/node_modules/@loopwright/hardware-runner/dist/provenance.js +1500 -0
- package/node_modules/@loopwright/hardware-runner/dist/queue.d.ts +81 -0
- package/node_modules/@loopwright/hardware-runner/dist/queue.js +1081 -0
- package/node_modules/@loopwright/hardware-runner/dist/relay-server.d.ts +13 -0
- package/node_modules/@loopwright/hardware-runner/dist/relay-server.js +2997 -0
- package/node_modules/@loopwright/hardware-runner/dist/types.d.ts +239 -0
- package/node_modules/@loopwright/hardware-runner/dist/types.js +12 -0
- package/node_modules/@loopwright/hardware-runner/dist/worker.d.ts +49 -0
- package/node_modules/@loopwright/hardware-runner/dist/worker.js +1648 -0
- package/node_modules/@loopwright/hardware-runner/package.json +12 -0
- package/node_modules/@loopwright/memory/dist/cas.d.ts +21 -0
- package/node_modules/@loopwright/memory/dist/cas.js +510 -0
- package/node_modules/@loopwright/memory/dist/compaction.d.ts +18 -0
- package/node_modules/@loopwright/memory/dist/compaction.js +110 -0
- package/node_modules/@loopwright/memory/dist/finalizer.d.ts +23 -0
- package/node_modules/@loopwright/memory/dist/finalizer.js +538 -0
- package/node_modules/@loopwright/memory/dist/index.d.ts +9 -0
- package/node_modules/@loopwright/memory/dist/index.js +8 -0
- package/node_modules/@loopwright/memory/dist/schema.d.ts +36 -0
- package/node_modules/@loopwright/memory/dist/schema.js +510 -0
- package/node_modules/@loopwright/memory/dist/selector.d.ts +7 -0
- package/node_modules/@loopwright/memory/dist/selector.js +157 -0
- package/node_modules/@loopwright/memory/dist/store.d.ts +51 -0
- package/node_modules/@loopwright/memory/dist/store.js +554 -0
- package/node_modules/@loopwright/memory/dist/types.d.ts +442 -0
- package/node_modules/@loopwright/memory/dist/types.js +8 -0
- package/node_modules/@loopwright/memory/dist/verifier.d.ts +5 -0
- package/node_modules/@loopwright/memory/dist/verifier.js +328 -0
- package/node_modules/@loopwright/memory/package.json +12 -0
- package/node_modules/@loopwright/state/dist/admission.d.ts +321 -0
- package/node_modules/@loopwright/state/dist/admission.js +199 -0
- package/node_modules/@loopwright/state/dist/boundary.d.ts +53 -0
- package/node_modules/@loopwright/state/dist/boundary.js +194 -0
- package/node_modules/@loopwright/state/dist/checkpoint.d.ts +16 -0
- package/node_modules/@loopwright/state/dist/checkpoint.js +84 -0
- package/node_modules/@loopwright/state/dist/clock.d.ts +8 -0
- package/node_modules/@loopwright/state/dist/clock.js +27 -0
- package/node_modules/@loopwright/state/dist/connection.d.ts +55 -0
- package/node_modules/@loopwright/state/dist/connection.js +391 -0
- package/node_modules/@loopwright/state/dist/errors.d.ts +13 -0
- package/node_modules/@loopwright/state/dist/errors.js +34 -0
- package/node_modules/@loopwright/state/dist/index.d.ts +3 -0
- package/node_modules/@loopwright/state/dist/index.js +1 -0
- package/node_modules/@loopwright/state/dist/journal.d.ts +119 -0
- package/node_modules/@loopwright/state/dist/journal.js +72 -0
- package/node_modules/@loopwright/state/dist/model.d.ts +40 -0
- package/node_modules/@loopwright/state/dist/model.js +58 -0
- package/node_modules/@loopwright/state/dist/ownership.d.ts +14 -0
- package/node_modules/@loopwright/state/dist/ownership.js +45 -0
- package/node_modules/@loopwright/state/dist/pages.d.ts +11 -0
- package/node_modules/@loopwright/state/dist/pages.js +41 -0
- package/node_modules/@loopwright/state/dist/receipts.d.ts +33 -0
- package/node_modules/@loopwright/state/dist/receipts.js +97 -0
- package/node_modules/@loopwright/state/dist/schema.d.ts +28 -0
- package/node_modules/@loopwright/state/dist/schema.js +41 -0
- package/node_modules/@loopwright/state/dist/settlement.d.ts +10 -0
- package/node_modules/@loopwright/state/dist/settlement.js +129 -0
- package/node_modules/@loopwright/state/dist/store.d.ts +52 -0
- package/node_modules/@loopwright/state/dist/store.js +100 -0
- package/node_modules/@loopwright/state/dist/types.d.ts +315 -0
- package/node_modules/@loopwright/state/dist/types.js +1 -0
- package/node_modules/@loopwright/state/package.json +12 -0
- package/node_modules/@loopwright/taskpack/dist/baseline-align.d.ts +195 -0
- package/node_modules/@loopwright/taskpack/dist/baseline-align.js +1847 -0
- package/node_modules/@loopwright/taskpack/dist/digests.d.ts +61 -0
- package/node_modules/@loopwright/taskpack/dist/digests.js +715 -0
- package/node_modules/@loopwright/taskpack/dist/index.d.ts +18 -0
- package/node_modules/@loopwright/taskpack/dist/index.js +17 -0
- package/node_modules/@loopwright/taskpack/dist/models-config.d.ts +112 -0
- package/node_modules/@loopwright/taskpack/dist/models-config.js +1026 -0
- package/node_modules/@loopwright/taskpack/dist/output-format.d.ts +28 -0
- package/node_modules/@loopwright/taskpack/dist/output-format.js +157 -0
- package/node_modules/@loopwright/taskpack/dist/preflight.d.ts +130 -0
- package/node_modules/@loopwright/taskpack/dist/preflight.js +1497 -0
- package/node_modules/@loopwright/taskpack/dist/qualification.d.ts +23 -0
- package/node_modules/@loopwright/taskpack/dist/qualification.js +120 -0
- package/node_modules/@loopwright/taskpack/dist/sandbox.d.ts +121 -0
- package/node_modules/@loopwright/taskpack/dist/sandbox.js +2642 -0
- package/node_modules/@loopwright/taskpack/dist/schema.d.ts +197 -0
- package/node_modules/@loopwright/taskpack/dist/schema.js +4189 -0
- package/node_modules/@loopwright/taskpack/dist/scrubber.d.ts +47 -0
- package/node_modules/@loopwright/taskpack/dist/scrubber.js +283 -0
- package/node_modules/@loopwright/taskpack/dist/suite.d.ts +124 -0
- package/node_modules/@loopwright/taskpack/dist/suite.js +3256 -0
- package/node_modules/@loopwright/taskpack/dist/taskpack.d.ts +154 -0
- package/node_modules/@loopwright/taskpack/dist/taskpack.js +3634 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey-memory.d.ts +122 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey-memory.js +483 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey.d.ts +437 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey.js +7335 -0
- package/node_modules/@loopwright/taskpack/dist/types.d.ts +1274 -0
- package/node_modules/@loopwright/taskpack/dist/types.js +99 -0
- package/node_modules/@loopwright/taskpack/dist/upstreams.d.ts +261 -0
- package/node_modules/@loopwright/taskpack/dist/upstreams.js +2242 -0
- package/node_modules/@loopwright/taskpack/dist/yaml.d.ts +18 -0
- package/node_modules/@loopwright/taskpack/dist/yaml.js +167 -0
- package/node_modules/@loopwright/taskpack/package.json +12 -0
- package/node_modules/@loopwright/taskpack-runner/dist/compile-taskpack.d.ts +137 -0
- package/node_modules/@loopwright/taskpack-runner/dist/compile-taskpack.js +474 -0
- package/node_modules/@loopwright/taskpack-runner/dist/corpus.d.ts +8 -0
- package/node_modules/@loopwright/taskpack-runner/dist/corpus.js +129 -0
- package/node_modules/@loopwright/taskpack-runner/dist/index.d.ts +13 -0
- package/node_modules/@loopwright/taskpack-runner/dist/index.js +7 -0
- package/node_modules/@loopwright/taskpack-runner/dist/intake.d.ts +149 -0
- package/node_modules/@loopwright/taskpack-runner/dist/intake.js +135 -0
- package/node_modules/@loopwright/taskpack-runner/dist/parity.d.ts +130 -0
- package/node_modules/@loopwright/taskpack-runner/dist/parity.js +927 -0
- package/node_modules/@loopwright/taskpack-runner/dist/python-bridge.d.ts +68 -0
- package/node_modules/@loopwright/taskpack-runner/dist/python-bridge.js +517 -0
- package/node_modules/@loopwright/taskpack-runner/dist/service.d.ts +149 -0
- package/node_modules/@loopwright/taskpack-runner/dist/service.js +1796 -0
- package/node_modules/@loopwright/taskpack-runner/dist/types.d.ts +29 -0
- package/node_modules/@loopwright/taskpack-runner/dist/types.js +11 -0
- package/node_modules/@loopwright/taskpack-runner/package.json +12 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/README.md +77 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/docs/support-records.md +57 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/docs/supported-runners.md +98 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/manifest.json +205 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/expand_matrix.sh +273 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/matrix.yaml +280 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/resolve_dockerfile.sh +24 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pyproject.toml +46 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/runtime_runner/runner.py.json +5270 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/discovery/legacy-support.md +86 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/github/service.py +401 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/proposals/analysis.json +95 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/proposals/ready.json +109 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_assemble.py +263 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_check_draft.py +333 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_checks.py +1099 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_discovery.py +817 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_proposal.py +658 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_publish.py +987 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_summary.py +107 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/agent.py +610 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/assemble.py +84 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/check_draft.py +94 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/checks.py +1002 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/discovery.py +789 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/model.py +557 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/progress.py +174 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/analysis.md +40 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/proposal.md +65 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/repair.md +17 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/proposal.py +903 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/publish.py +997 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/summary.py +131 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/tool-versions.json +133 -0
- package/node_modules/package-lock.json +3025 -0
- package/package-lock.json +3025 -0
- package/package.json +52 -4
|
@@ -0,0 +1,1648 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { open } from 'node:fs/promises';
|
|
4
|
+
import { request as httpRequest } from 'node:http';
|
|
5
|
+
import { Agent as HttpsAgent, request as httpsRequest } from 'node:https';
|
|
6
|
+
import { resolve } from 'node:path';
|
|
7
|
+
import { OVERLAY_LIMITS, SecretScrubber } from '@loopwright/core';
|
|
8
|
+
import { readBoundedRegularFile } from '@loopwright/taskpack';
|
|
9
|
+
import { assertNoSymlinkAncestors, canonicalJson, expectNullProtoRecord, parseStrictJsonBytes, } from './config.js';
|
|
10
|
+
import { evaluateBenchmarkJob, isRunnerTeardownError, RunnerTeardownError, } from './evaluator.js';
|
|
11
|
+
import { EMPTY_SHA256_HEX, MAX_CAS_CHUNK_BYTES, MAX_CONTROL_BODY_BYTES, parseBenchmarkRequest, } from './relay-server.js';
|
|
12
|
+
import { HardwareRunnerError, } from './types.js';
|
|
13
|
+
export const MAX_LEASE_TTL_MS = 600_000;
|
|
14
|
+
export class RunnerTransportError extends HardwareRunnerError {
|
|
15
|
+
transientTransport = true;
|
|
16
|
+
reasonCode = 'RUNNER_TRANSPORT_ERROR';
|
|
17
|
+
httpStatus;
|
|
18
|
+
constructor(message, httpStatus, options) {
|
|
19
|
+
super('RUNNER_SANDBOX_FAILED', message, undefined, options);
|
|
20
|
+
this.name = 'RunnerTransportError';
|
|
21
|
+
if (httpStatus !== undefined) {
|
|
22
|
+
this.httpStatus = httpStatus;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function isRunnerTransportError(err) {
|
|
27
|
+
return (err instanceof RunnerTransportError
|
|
28
|
+
|| (err instanceof Error && err.transientTransport === true));
|
|
29
|
+
}
|
|
30
|
+
function tagRequestSent(err, sent) {
|
|
31
|
+
Object.defineProperty(err, 'requestSent', {
|
|
32
|
+
value: sent,
|
|
33
|
+
enumerable: false,
|
|
34
|
+
configurable: true,
|
|
35
|
+
});
|
|
36
|
+
return err;
|
|
37
|
+
}
|
|
38
|
+
function wasRequestSent(err) {
|
|
39
|
+
if (err !== null && typeof err === 'object' && 'requestSent' in err) {
|
|
40
|
+
return err.requestSent === true;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
const GRANT_KEYS = new Set([
|
|
45
|
+
'relayBootId',
|
|
46
|
+
'jobId',
|
|
47
|
+
'operationId',
|
|
48
|
+
'leaseEpoch',
|
|
49
|
+
'leaseToken',
|
|
50
|
+
'leaseTtlMs',
|
|
51
|
+
'job',
|
|
52
|
+
]);
|
|
53
|
+
const HEARTBEAT_RESPONSE_KEYS = new Set(['desiredState', 'leaseTtlMs', 'leaseEpoch']);
|
|
54
|
+
const PREEMPT_RESPONSE_KEYS = new Set(['status', 'preemptionCount']);
|
|
55
|
+
const COMPLETE_RESPONSE_KEYS = new Set(['ok', 'operationId', 'status']);
|
|
56
|
+
const BLOB_PUT_RESPONSE_KEYS = new Set(['ok', 'sha256', 'byteLength']);
|
|
57
|
+
const VALID_ERROR_CODES = new Set([
|
|
58
|
+
'CONFIG_INVALID',
|
|
59
|
+
'QUEUE_LEASE_FENCED',
|
|
60
|
+
'QUEUE_STATE_INVALID',
|
|
61
|
+
'QUEUE_CAPACITY_EXCEEDED',
|
|
62
|
+
'QUEUE_JOB_CONFLICT',
|
|
63
|
+
'ARTIFACT_INVALID',
|
|
64
|
+
'ARTIFACT_MISSING',
|
|
65
|
+
'AUTH_UNAUTHORIZED',
|
|
66
|
+
'AUTH_FORBIDDEN',
|
|
67
|
+
'PAYLOAD_TOO_LARGE',
|
|
68
|
+
'NOT_FOUND',
|
|
69
|
+
'RUNNER_SANDBOX_FAILED',
|
|
70
|
+
]);
|
|
71
|
+
const DETERMINISTIC_EVAL_ERROR_CODES = new Set([
|
|
72
|
+
'ARTIFACT_INVALID',
|
|
73
|
+
'PAYLOAD_TOO_LARGE',
|
|
74
|
+
]);
|
|
75
|
+
const SHA256_HEX_RE = /^[0-9a-f]{64}$/;
|
|
76
|
+
const PRE_SEND_SOCKET_ERROR_CODES = new Set([
|
|
77
|
+
'ECONNREFUSED',
|
|
78
|
+
'ENOTFOUND',
|
|
79
|
+
'EAI_AGAIN',
|
|
80
|
+
'EHOSTUNREACH',
|
|
81
|
+
'ENETUNREACH',
|
|
82
|
+
'EADDRNOTAVAIL',
|
|
83
|
+
'DEPTH_ZERO_SELF_SIGNED_CERT',
|
|
84
|
+
'SELF_SIGNED_CERT_IN_CHAIN',
|
|
85
|
+
'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
|
|
86
|
+
'UNABLE_TO_GET_ISSUER_CERT',
|
|
87
|
+
'UNABLE_TO_GET_ISSUER_CERT_LOCALLY',
|
|
88
|
+
'CERT_HAS_EXPIRED',
|
|
89
|
+
'CERT_NOT_YET_VALID',
|
|
90
|
+
'CERT_UNTRUSTED',
|
|
91
|
+
'CERT_REJECTED',
|
|
92
|
+
]);
|
|
93
|
+
function isPreSendSocketErrorCode(code) {
|
|
94
|
+
if (typeof code !== 'string' || code.length === 0)
|
|
95
|
+
return false;
|
|
96
|
+
return (PRE_SEND_SOCKET_ERROR_CODES.has(code)
|
|
97
|
+
|| code.startsWith('ERR_TLS_')
|
|
98
|
+
|| code.startsWith('CERT_')
|
|
99
|
+
|| code.startsWith('UNABLE_TO_VERIFY_'));
|
|
100
|
+
}
|
|
101
|
+
const DEFAULT_WORKER_CLOCK = {
|
|
102
|
+
nowMonotonicMs: () => performance.now(),
|
|
103
|
+
};
|
|
104
|
+
function parseErrorCodeFromJson(bytes) {
|
|
105
|
+
if (bytes.byteLength === 0 || bytes.byteLength > MAX_CONTROL_BODY_BYTES)
|
|
106
|
+
return null;
|
|
107
|
+
try {
|
|
108
|
+
const parsed = parseStrictJsonBytes(bytes, MAX_CONTROL_BODY_BYTES, 'ARTIFACT_INVALID', '/error');
|
|
109
|
+
if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
110
|
+
const rec = parsed;
|
|
111
|
+
if (Object.hasOwn(rec, 'code') && typeof rec.code === 'string' && VALID_ERROR_CODES.has(rec.code)) {
|
|
112
|
+
return rec.code;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// Ignore malformed error body.
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
function mapHttpError(status, bytes, fallbackMessage) {
|
|
122
|
+
const remoteCode = parseErrorCodeFromJson(bytes);
|
|
123
|
+
if (status === 401) {
|
|
124
|
+
return new HardwareRunnerError('AUTH_UNAUTHORIZED', fallbackMessage);
|
|
125
|
+
}
|
|
126
|
+
if (status === 403) {
|
|
127
|
+
return new HardwareRunnerError('AUTH_FORBIDDEN', fallbackMessage);
|
|
128
|
+
}
|
|
129
|
+
if (status === 404) {
|
|
130
|
+
return new HardwareRunnerError('NOT_FOUND', fallbackMessage);
|
|
131
|
+
}
|
|
132
|
+
if (status === 409) {
|
|
133
|
+
const code = remoteCode ?? 'QUEUE_STATE_INVALID';
|
|
134
|
+
return new HardwareRunnerError(code, fallbackMessage);
|
|
135
|
+
}
|
|
136
|
+
if (status === 413) {
|
|
137
|
+
return new HardwareRunnerError('PAYLOAD_TOO_LARGE', fallbackMessage);
|
|
138
|
+
}
|
|
139
|
+
if (status === 429) {
|
|
140
|
+
return new HardwareRunnerError('QUEUE_CAPACITY_EXCEEDED', fallbackMessage);
|
|
141
|
+
}
|
|
142
|
+
if (remoteCode !== null && status >= 400 && status < 500) {
|
|
143
|
+
return new HardwareRunnerError(remoteCode, `${fallbackMessage} (HTTP ${status})`);
|
|
144
|
+
}
|
|
145
|
+
if (status === 408 || status >= 500 || status === 0) {
|
|
146
|
+
return new RunnerTransportError(`${fallbackMessage} (HTTP ${status})`, status);
|
|
147
|
+
}
|
|
148
|
+
return new HardwareRunnerError('ARTIFACT_INVALID', `${fallbackMessage} (HTTP ${status})`);
|
|
149
|
+
}
|
|
150
|
+
function computeConservativeLeaseMarginMs(leaseTtlMs) {
|
|
151
|
+
return Math.min(1_000, Math.max(5, Math.floor(leaseTtlMs * 0.2)));
|
|
152
|
+
}
|
|
153
|
+
function validateHeartbeatResponsePayload(bytes, expectedEpoch) {
|
|
154
|
+
const raw = parseStrictJsonBytes(bytes, MAX_CONTROL_BODY_BYTES, 'ARTIFACT_INVALID', '/heartbeat');
|
|
155
|
+
const rec = expectNullProtoRecord(raw, HEARTBEAT_RESPONSE_KEYS, ['desiredState', 'leaseTtlMs'], 'ARTIFACT_INVALID', '/heartbeat');
|
|
156
|
+
if (rec.desiredState !== 'running' && rec.desiredState !== 'cancel') {
|
|
157
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'invalid heartbeat desiredState', '/heartbeat/desiredState');
|
|
158
|
+
}
|
|
159
|
+
if (typeof rec.leaseTtlMs !== 'number'
|
|
160
|
+
|| !Number.isSafeInteger(rec.leaseTtlMs)
|
|
161
|
+
|| Object.is(rec.leaseTtlMs, -0)
|
|
162
|
+
|| rec.leaseTtlMs < 10
|
|
163
|
+
|| rec.leaseTtlMs > MAX_LEASE_TTL_MS) {
|
|
164
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'invalid heartbeat leaseTtlMs', '/heartbeat/leaseTtlMs');
|
|
165
|
+
}
|
|
166
|
+
if (Object.hasOwn(rec, 'leaseEpoch') && rec.leaseEpoch !== expectedEpoch) {
|
|
167
|
+
throw new HardwareRunnerError('QUEUE_LEASE_FENCED', 'heartbeat response leaseEpoch mismatch', '/heartbeat/leaseEpoch');
|
|
168
|
+
}
|
|
169
|
+
return Object.freeze({
|
|
170
|
+
desiredState: rec.desiredState,
|
|
171
|
+
leaseTtlMs: rec.leaseTtlMs,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function validatePreemptResponsePayload(bytes, grantedJob) {
|
|
175
|
+
const raw = parseStrictJsonBytes(bytes, MAX_CONTROL_BODY_BYTES, 'ARTIFACT_INVALID', '/preempt');
|
|
176
|
+
const rec = expectNullProtoRecord(raw, PREEMPT_RESPONSE_KEYS, ['status', 'preemptionCount'], 'ARTIFACT_INVALID', '/preempt');
|
|
177
|
+
if (rec.status !== 'requeued' && rec.status !== 'preempted_exhausted') {
|
|
178
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'invalid preempt status', '/preempt/status');
|
|
179
|
+
}
|
|
180
|
+
if (typeof rec.preemptionCount !== 'number'
|
|
181
|
+
|| !Number.isSafeInteger(rec.preemptionCount)
|
|
182
|
+
|| Object.is(rec.preemptionCount, -0)
|
|
183
|
+
|| rec.preemptionCount < grantedJob.preemptionCount
|
|
184
|
+
|| rec.preemptionCount > grantedJob.maxPreemptions
|
|
185
|
+
|| rec.preemptionCount > 16) {
|
|
186
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'invalid preempt preemptionCount', '/preempt/preemptionCount');
|
|
187
|
+
}
|
|
188
|
+
if (grantedJob.preemptionCount + 1 <= grantedJob.maxPreemptions) {
|
|
189
|
+
if (rec.status !== 'requeued' || rec.preemptionCount !== grantedJob.preemptionCount + 1) {
|
|
190
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'preempt receipt inconsistent with remaining preemption budget', '/preempt');
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else if (rec.status !== 'preempted_exhausted' || rec.preemptionCount !== grantedJob.preemptionCount) {
|
|
194
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'impossible requeue receipt when preemption budget is exhausted', '/preempt');
|
|
195
|
+
}
|
|
196
|
+
return Object.freeze({
|
|
197
|
+
status: rec.status,
|
|
198
|
+
preemptionCount: rec.preemptionCount,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
function validateBlobUploadResponsePayload(bytes, expectedSha256, expectedByteLength) {
|
|
202
|
+
if (bytes.byteLength === 0) {
|
|
203
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'empty Stage A blob upload receipt from Relay', '/blobPut');
|
|
204
|
+
}
|
|
205
|
+
const raw = parseStrictJsonBytes(bytes, MAX_CONTROL_BODY_BYTES, 'ARTIFACT_INVALID', '/blobPut');
|
|
206
|
+
const rec = expectNullProtoRecord(raw, BLOB_PUT_RESPONSE_KEYS, ['ok', 'sha256', 'byteLength'], 'ARTIFACT_INVALID', '/blobPut');
|
|
207
|
+
if (rec.ok !== true
|
|
208
|
+
|| rec.sha256 !== expectedSha256
|
|
209
|
+
|| typeof rec.byteLength !== 'number'
|
|
210
|
+
|| !Number.isSafeInteger(rec.byteLength)
|
|
211
|
+
|| Object.is(rec.byteLength, -0)
|
|
212
|
+
|| rec.byteLength !== expectedByteLength) {
|
|
213
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'Stage A blob upload receipt mismatched expected ok/sha256/byteLength', '/blobPut');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function validateCompleteResponsePayload(bytes, expectedOperationId, expectedStatus) {
|
|
217
|
+
const raw = parseStrictJsonBytes(bytes, MAX_CONTROL_BODY_BYTES, 'ARTIFACT_INVALID', '/complete');
|
|
218
|
+
const rec = expectNullProtoRecord(raw, COMPLETE_RESPONSE_KEYS, ['ok', 'operationId', 'status'], 'ARTIFACT_INVALID', '/complete');
|
|
219
|
+
if (rec.ok !== true || rec.operationId !== expectedOperationId || rec.status !== expectedStatus) {
|
|
220
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'malformed lease completion acknowledgment from Relay', '/complete');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function parseLeaseGrantPayload(bytes, maxBlobBytes) {
|
|
224
|
+
const raw = parseStrictJsonBytes(bytes, MAX_CONTROL_BODY_BYTES, 'ARTIFACT_INVALID', '/grant');
|
|
225
|
+
const root = expectNullProtoRecord(raw, GRANT_KEYS, ['relayBootId', 'jobId', 'operationId', 'leaseEpoch', 'leaseToken', 'leaseTtlMs', 'job'], 'ARTIFACT_INVALID', '/grant');
|
|
226
|
+
if (typeof root.relayBootId !== 'string'
|
|
227
|
+
|| root.relayBootId.length === 0
|
|
228
|
+
|| typeof root.jobId !== 'string'
|
|
229
|
+
|| root.jobId.length === 0
|
|
230
|
+
|| typeof root.operationId !== 'string'
|
|
231
|
+
|| root.operationId.length === 0
|
|
232
|
+
|| typeof root.leaseToken !== 'string'
|
|
233
|
+
|| root.leaseToken.length === 0
|
|
234
|
+
|| typeof root.leaseEpoch !== 'number'
|
|
235
|
+
|| !Number.isSafeInteger(root.leaseEpoch)
|
|
236
|
+
|| root.leaseEpoch < 1
|
|
237
|
+
|| typeof root.leaseTtlMs !== 'number'
|
|
238
|
+
|| !Number.isSafeInteger(root.leaseTtlMs)
|
|
239
|
+
|| Object.is(root.leaseTtlMs, -0)
|
|
240
|
+
|| root.leaseTtlMs < 10
|
|
241
|
+
|| root.leaseTtlMs > MAX_LEASE_TTL_MS) {
|
|
242
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'malformed LeaseGrant fields from Relay', '/grant');
|
|
243
|
+
}
|
|
244
|
+
if (root.job === null || typeof root.job !== 'object' || Array.isArray(root.job)) {
|
|
245
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'malformed LeaseGrant.job object', '/grant/job');
|
|
246
|
+
}
|
|
247
|
+
const jobObj = root.job;
|
|
248
|
+
const subjectObj = (jobObj.subject !== null && typeof jobObj.subject === 'object' && !Array.isArray(jobObj.subject))
|
|
249
|
+
? jobObj.subject
|
|
250
|
+
: null;
|
|
251
|
+
if (subjectObj === null) {
|
|
252
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'missing LeaseGrant.job.subject', '/grant/job/subject');
|
|
253
|
+
}
|
|
254
|
+
const validatedReq = parseBenchmarkRequest({
|
|
255
|
+
version: 1,
|
|
256
|
+
kind: 'benchmark_request',
|
|
257
|
+
storeId: 'worker-grant',
|
|
258
|
+
runId: 'worker-grant',
|
|
259
|
+
lockHash: subjectObj.lockHash,
|
|
260
|
+
operationId: jobObj.operationId,
|
|
261
|
+
dispatchId: 'worker-grant',
|
|
262
|
+
dispatchGeneration: 0,
|
|
263
|
+
requestDigest: '0'.repeat(64),
|
|
264
|
+
gateId: jobObj.gateId,
|
|
265
|
+
checkId: jobObj.checkId,
|
|
266
|
+
candidateDigest: jobObj.candidateDigest,
|
|
267
|
+
subject: jobObj.subject,
|
|
268
|
+
targetCellId: jobObj.targetCellId,
|
|
269
|
+
targetHardware: jobObj.targetHardware,
|
|
270
|
+
heldOutWorkloadId: jobObj.heldOutWorkloadId,
|
|
271
|
+
...(Object.hasOwn(jobObj, 'metricThresholds') ? { metricThresholds: jobObj.metricThresholds } : {}),
|
|
272
|
+
...(Object.hasOwn(jobObj, 'maxPreemptions') ? { maxPreemptions: jobObj.maxPreemptions } : {}),
|
|
273
|
+
candidateArtifacts: jobObj.candidateArtifacts,
|
|
274
|
+
}, maxBlobBytes);
|
|
275
|
+
const preemptionCount = typeof jobObj.preemptionCount === 'number'
|
|
276
|
+
&& Number.isSafeInteger(jobObj.preemptionCount)
|
|
277
|
+
&& jobObj.preemptionCount >= 0
|
|
278
|
+
&& jobObj.preemptionCount <= 16
|
|
279
|
+
? jobObj.preemptionCount
|
|
280
|
+
: -1;
|
|
281
|
+
if (preemptionCount < 0 || preemptionCount > validatedReq.maxPreemptions || validatedReq.operationId !== root.operationId) {
|
|
282
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'invalid LeaseGrant.job preemptionCount or operationId', '/grant/job');
|
|
283
|
+
}
|
|
284
|
+
const jobPayload = Object.freeze({
|
|
285
|
+
operationId: validatedReq.operationId,
|
|
286
|
+
gateId: validatedReq.gateId,
|
|
287
|
+
checkId: validatedReq.checkId,
|
|
288
|
+
candidateDigest: validatedReq.candidateDigest,
|
|
289
|
+
subject: validatedReq.subject,
|
|
290
|
+
targetCellId: validatedReq.targetCellId,
|
|
291
|
+
targetHardware: validatedReq.targetHardware,
|
|
292
|
+
heldOutWorkloadId: validatedReq.heldOutWorkloadId,
|
|
293
|
+
metricThresholds: validatedReq.metricThresholds,
|
|
294
|
+
maxPreemptions: validatedReq.maxPreemptions,
|
|
295
|
+
preemptionCount,
|
|
296
|
+
candidateArtifacts: validatedReq.candidateArtifacts,
|
|
297
|
+
});
|
|
298
|
+
return Object.freeze({
|
|
299
|
+
relayBootId: root.relayBootId,
|
|
300
|
+
jobId: root.jobId,
|
|
301
|
+
operationId: root.operationId,
|
|
302
|
+
leaseEpoch: root.leaseEpoch,
|
|
303
|
+
leaseToken: root.leaseToken,
|
|
304
|
+
leaseTtlMs: root.leaseTtlMs,
|
|
305
|
+
job: jobPayload,
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
async function createOutboundHttpClient(config) {
|
|
309
|
+
const baseUrl = new URL(config.relayUrl);
|
|
310
|
+
const isHttps = baseUrl.protocol === 'https:';
|
|
311
|
+
let httpsAgent;
|
|
312
|
+
let caPem;
|
|
313
|
+
if (isHttps) {
|
|
314
|
+
if (config.tlsCaPath !== undefined) {
|
|
315
|
+
await assertNoSymlinkAncestors(config.tlsCaPath, {
|
|
316
|
+
checkLeaf: true,
|
|
317
|
+
code: 'CONFIG_INVALID',
|
|
318
|
+
diagPath: '/tlsCaPath',
|
|
319
|
+
});
|
|
320
|
+
const rawCa = await readBoundedRegularFile(config.tlsCaPath, 262_144, msg => {
|
|
321
|
+
throw new HardwareRunnerError('CONFIG_INVALID', msg, '/tlsCaPath');
|
|
322
|
+
});
|
|
323
|
+
caPem = Buffer.from(rawCa);
|
|
324
|
+
}
|
|
325
|
+
httpsAgent = new HttpsAgent({
|
|
326
|
+
keepAlive: true,
|
|
327
|
+
rejectUnauthorized: true,
|
|
328
|
+
...(caPem !== undefined ? { ca: caPem } : {}),
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
const basePathname = baseUrl.pathname === '/' ? '' : baseUrl.pathname.replace(/\/+$/, '');
|
|
332
|
+
const cleanHost = baseUrl.hostname.replace(/^\[|\]$/g, '');
|
|
333
|
+
const buildRequestOptions = (method, subpath, headers) => ({
|
|
334
|
+
protocol: baseUrl.protocol,
|
|
335
|
+
hostname: cleanHost,
|
|
336
|
+
...(baseUrl.port !== '' ? { port: Number(baseUrl.port) } : {}),
|
|
337
|
+
path: `${basePathname}${subpath}`,
|
|
338
|
+
method,
|
|
339
|
+
headers: {
|
|
340
|
+
authorization: `Bearer ${config.workerToken}`,
|
|
341
|
+
...headers,
|
|
342
|
+
},
|
|
343
|
+
...(isHttps
|
|
344
|
+
? {
|
|
345
|
+
agent: httpsAgent,
|
|
346
|
+
rejectUnauthorized: true,
|
|
347
|
+
...(caPem !== undefined ? { ca: caPem } : {}),
|
|
348
|
+
}
|
|
349
|
+
: {}),
|
|
350
|
+
});
|
|
351
|
+
const sendFn = (opts, cb) => isHttps ? httpsRequest(opts, cb) : httpRequest(opts, cb);
|
|
352
|
+
return {
|
|
353
|
+
requestJson({ method, path, headers = {}, body, timeoutMs, signal }) {
|
|
354
|
+
if (signal?.aborted) {
|
|
355
|
+
return Promise.reject(tagRequestSent(new HardwareRunnerError('RUNNER_SANDBOX_FAILED', 'request aborted'), false));
|
|
356
|
+
}
|
|
357
|
+
let payloadBytes = null;
|
|
358
|
+
if (body !== undefined) {
|
|
359
|
+
let serialized;
|
|
360
|
+
try {
|
|
361
|
+
serialized = canonicalJson(body);
|
|
362
|
+
}
|
|
363
|
+
catch (serErr) {
|
|
364
|
+
const wrapped = serErr instanceof Error
|
|
365
|
+
? serErr
|
|
366
|
+
: new HardwareRunnerError('ARTIFACT_INVALID', 'failed to serialize control request');
|
|
367
|
+
return Promise.reject(tagRequestSent(wrapped, false));
|
|
368
|
+
}
|
|
369
|
+
payloadBytes = Buffer.from(serialized, 'utf8');
|
|
370
|
+
if (payloadBytes.byteLength > MAX_CONTROL_BODY_BYTES) {
|
|
371
|
+
return Promise.reject(tagRequestSent(new HardwareRunnerError('PAYLOAD_TOO_LARGE', `worker control request exceeded ${MAX_CONTROL_BODY_BYTES} bytes`), false));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const effectiveHeaders = {
|
|
375
|
+
...headers,
|
|
376
|
+
...(payloadBytes !== null
|
|
377
|
+
? {
|
|
378
|
+
'content-type': 'application/json; charset=utf-8',
|
|
379
|
+
'content-length': String(payloadBytes.byteLength),
|
|
380
|
+
}
|
|
381
|
+
: {}),
|
|
382
|
+
};
|
|
383
|
+
return new Promise((resolveReq, rejectReq) => {
|
|
384
|
+
let settled = false;
|
|
385
|
+
let socketConnected = false;
|
|
386
|
+
let writeDispatched = false;
|
|
387
|
+
let responseReceived = false;
|
|
388
|
+
const computeRequestSent = (overrideSent) => {
|
|
389
|
+
if (overrideSent !== undefined)
|
|
390
|
+
return overrideSent;
|
|
391
|
+
return responseReceived || (socketConnected && writeDispatched);
|
|
392
|
+
};
|
|
393
|
+
const finishErr = (err, overrideSent) => {
|
|
394
|
+
if (settled)
|
|
395
|
+
return;
|
|
396
|
+
settled = true;
|
|
397
|
+
clearTimeout(timer);
|
|
398
|
+
signal?.removeEventListener('abort', onAbort);
|
|
399
|
+
rejectReq(tagRequestSent(err, computeRequestSent(overrideSent)));
|
|
400
|
+
};
|
|
401
|
+
const req = sendFn(buildRequestOptions(method, path, effectiveHeaders), (res) => {
|
|
402
|
+
responseReceived = true;
|
|
403
|
+
const status = res.statusCode ?? 0;
|
|
404
|
+
if (status >= 300 && status < 400) {
|
|
405
|
+
res.resume();
|
|
406
|
+
finishErr(new HardwareRunnerError('AUTH_FORBIDDEN', 'HTTP redirects from Relay are forbidden'), true);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
const chunks = [];
|
|
410
|
+
let total = 0;
|
|
411
|
+
res.on('data', (rawChunk) => {
|
|
412
|
+
const buf = Buffer.isBuffer(rawChunk) ? rawChunk : Buffer.from(rawChunk);
|
|
413
|
+
total += buf.byteLength;
|
|
414
|
+
if (total > MAX_CONTROL_BODY_BYTES) {
|
|
415
|
+
req.destroy();
|
|
416
|
+
finishErr(new HardwareRunnerError('PAYLOAD_TOO_LARGE', 'Relay control response exceeded 64 KiB'), true);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
chunks.push(buf);
|
|
420
|
+
});
|
|
421
|
+
res.on('error', err => finishErr(err, true));
|
|
422
|
+
res.on('end', () => {
|
|
423
|
+
if (settled)
|
|
424
|
+
return;
|
|
425
|
+
settled = true;
|
|
426
|
+
clearTimeout(timer);
|
|
427
|
+
signal?.removeEventListener('abort', onAbort);
|
|
428
|
+
resolveReq({
|
|
429
|
+
status,
|
|
430
|
+
bytes: chunks.length === 1 ? chunks[0] : Buffer.concat(chunks, total),
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
req.on('socket', socket => {
|
|
435
|
+
if (isHttps) {
|
|
436
|
+
const tlsSock = socket;
|
|
437
|
+
if (!tlsSock.connecting && !tlsSock.secureConnecting && tlsSock.authorized) {
|
|
438
|
+
socketConnected = true;
|
|
439
|
+
}
|
|
440
|
+
else {
|
|
441
|
+
tlsSock.once('secureConnect', () => {
|
|
442
|
+
if (tlsSock.authorized) {
|
|
443
|
+
socketConnected = true;
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
else if (!socket.connecting) {
|
|
449
|
+
socketConnected = true;
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
socket.once('connect', () => {
|
|
453
|
+
socketConnected = true;
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
const onAbort = () => {
|
|
458
|
+
const sentBeforeAbort = computeRequestSent();
|
|
459
|
+
req.destroy();
|
|
460
|
+
finishErr(new HardwareRunnerError('RUNNER_SANDBOX_FAILED', 'worker HTTP request aborted'), sentBeforeAbort);
|
|
461
|
+
};
|
|
462
|
+
const timer = setTimeout(() => {
|
|
463
|
+
const sentBeforeTimeout = computeRequestSent();
|
|
464
|
+
req.destroy();
|
|
465
|
+
finishErr(new RunnerTransportError('worker HTTP request timed out'), sentBeforeTimeout);
|
|
466
|
+
}, timeoutMs);
|
|
467
|
+
timer.unref();
|
|
468
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
469
|
+
req.on('error', err => {
|
|
470
|
+
const errnoCode = err?.code;
|
|
471
|
+
const sent = responseReceived || (socketConnected && writeDispatched && !isPreSendSocketErrorCode(errnoCode));
|
|
472
|
+
finishErr(new RunnerTransportError(`worker HTTP transport error: ${err.message}`, undefined, { cause: err }), sent);
|
|
473
|
+
});
|
|
474
|
+
if (payloadBytes !== null) {
|
|
475
|
+
req.end(payloadBytes);
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
req.end();
|
|
479
|
+
}
|
|
480
|
+
writeDispatched = true;
|
|
481
|
+
});
|
|
482
|
+
},
|
|
483
|
+
downloadBlobToStream({ jobId, creds, sha256, expectedByteLength, timeoutMs, signal, onChunk }) {
|
|
484
|
+
if (!SHA256_HEX_RE.test(sha256)) {
|
|
485
|
+
return Promise.reject(new HardwareRunnerError('ARTIFACT_INVALID', 'invalid blob sha256 digest'));
|
|
486
|
+
}
|
|
487
|
+
if ((expectedByteLength === 0) !== (sha256 === EMPTY_SHA256_HEX)) {
|
|
488
|
+
return Promise.reject(new HardwareRunnerError('ARTIFACT_INVALID', 'empty blob digest mismatch'));
|
|
489
|
+
}
|
|
490
|
+
if (signal?.aborted) {
|
|
491
|
+
return Promise.reject(new HardwareRunnerError('RUNNER_SANDBOX_FAILED', 'blob download aborted'));
|
|
492
|
+
}
|
|
493
|
+
const path = `/v1/runner/leases/${encodeURIComponent(jobId)}/blobs/${sha256}`;
|
|
494
|
+
const headers = {
|
|
495
|
+
'x-loopwright-relay-boot-id': creds.relayBootId,
|
|
496
|
+
'x-loopwright-lease-epoch': String(creds.leaseEpoch),
|
|
497
|
+
'x-loopwright-lease-token': creds.leaseToken,
|
|
498
|
+
};
|
|
499
|
+
return new Promise((resolveDl, rejectDl) => {
|
|
500
|
+
let settled = false;
|
|
501
|
+
const finishErr = (err) => {
|
|
502
|
+
if (settled)
|
|
503
|
+
return;
|
|
504
|
+
settled = true;
|
|
505
|
+
clearTimeout(timer);
|
|
506
|
+
signal?.removeEventListener('abort', onAbort);
|
|
507
|
+
const normalizedErr = err instanceof HardwareRunnerError
|
|
508
|
+
? err
|
|
509
|
+
: new RunnerTransportError(`blob download transport error: ${err.message}`);
|
|
510
|
+
rejectDl(normalizedErr);
|
|
511
|
+
};
|
|
512
|
+
const req = sendFn(buildRequestOptions('GET', path, headers), (res) => {
|
|
513
|
+
void (async () => {
|
|
514
|
+
const status = res.statusCode ?? 0;
|
|
515
|
+
if (status >= 300 && status < 400) {
|
|
516
|
+
res.resume();
|
|
517
|
+
throw new HardwareRunnerError('AUTH_FORBIDDEN', 'HTTP redirects on blob download are forbidden');
|
|
518
|
+
}
|
|
519
|
+
if (status !== 200) {
|
|
520
|
+
const errChunks = [];
|
|
521
|
+
let errLen = 0;
|
|
522
|
+
for await (const c of res) {
|
|
523
|
+
const b = Buffer.isBuffer(c) ? c : Buffer.from(c);
|
|
524
|
+
errLen += b.byteLength;
|
|
525
|
+
if (errLen > MAX_CONTROL_BODY_BYTES) {
|
|
526
|
+
res.destroy();
|
|
527
|
+
req.destroy();
|
|
528
|
+
throw new RunnerTransportError('Relay blob error response exceeded 64 KiB', status);
|
|
529
|
+
}
|
|
530
|
+
errChunks.push(b);
|
|
531
|
+
}
|
|
532
|
+
const errBytes = Buffer.concat(errChunks, errLen);
|
|
533
|
+
if (status === 401) {
|
|
534
|
+
throw new HardwareRunnerError('AUTH_UNAUTHORIZED', `unauthorized blob download ${sha256}`);
|
|
535
|
+
}
|
|
536
|
+
if (status === 403) {
|
|
537
|
+
throw new HardwareRunnerError('AUTH_FORBIDDEN', `forbidden blob download ${sha256}`);
|
|
538
|
+
}
|
|
539
|
+
if (status === 409 && parseErrorCodeFromJson(errBytes) === 'QUEUE_LEASE_FENCED') {
|
|
540
|
+
throw new HardwareRunnerError('QUEUE_LEASE_FENCED', `lease fenced during blob download ${sha256}`);
|
|
541
|
+
}
|
|
542
|
+
// Distinguish Relay/transport HTTP failures (e.g. 503/5xx/429/404) from verified candidate content errors!
|
|
543
|
+
throw new RunnerTransportError(`failed to download input blob ${sha256} from Relay (HTTP ${status})`, status);
|
|
544
|
+
}
|
|
545
|
+
const headerSha = res.headers['x-loopwright-blob-sha256'];
|
|
546
|
+
const headerLen = res.headers['x-loopwright-blob-length'];
|
|
547
|
+
if (typeof headerSha !== 'string'
|
|
548
|
+
|| !SHA256_HEX_RE.test(headerSha)
|
|
549
|
+
|| headerSha !== sha256
|
|
550
|
+
|| typeof headerLen !== 'string'
|
|
551
|
+
|| headerLen !== String(expectedByteLength)) {
|
|
552
|
+
res.destroy();
|
|
553
|
+
throw new RunnerTransportError('Relay blob response headers missing or mismatched expected digest/length', status);
|
|
554
|
+
}
|
|
555
|
+
const hasher = createHash('sha256');
|
|
556
|
+
let received = 0;
|
|
557
|
+
for await (const rawChunk of res) {
|
|
558
|
+
if (signal?.aborted) {
|
|
559
|
+
res.destroy();
|
|
560
|
+
throw new HardwareRunnerError('RUNNER_SANDBOX_FAILED', 'blob download aborted');
|
|
561
|
+
}
|
|
562
|
+
const buf = Buffer.isBuffer(rawChunk) ? rawChunk : Buffer.from(rawChunk);
|
|
563
|
+
for (let off = 0; off < buf.byteLength; off += MAX_CAS_CHUNK_BYTES) {
|
|
564
|
+
const slice = buf.subarray(off, Math.min(buf.byteLength, off + MAX_CAS_CHUNK_BYTES));
|
|
565
|
+
received += slice.byteLength;
|
|
566
|
+
if (received > expectedByteLength) {
|
|
567
|
+
res.destroy();
|
|
568
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'downloaded blob exceeded expectedByteLength');
|
|
569
|
+
}
|
|
570
|
+
hasher.update(slice);
|
|
571
|
+
await onChunk(slice);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
if (!res.complete) {
|
|
575
|
+
throw new RunnerTransportError('Relay blob download stream truncated before HTTP response completion', status);
|
|
576
|
+
}
|
|
577
|
+
if (received !== expectedByteLength || hasher.digest('hex') !== sha256) {
|
|
578
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'downloaded blob failed sha256 or byteLength verification');
|
|
579
|
+
}
|
|
580
|
+
if (!settled) {
|
|
581
|
+
settled = true;
|
|
582
|
+
clearTimeout(timer);
|
|
583
|
+
signal?.removeEventListener('abort', onAbort);
|
|
584
|
+
resolveDl();
|
|
585
|
+
}
|
|
586
|
+
})().catch(err => finishErr(err instanceof Error ? err : new Error(String(err))));
|
|
587
|
+
});
|
|
588
|
+
const onAbort = () => {
|
|
589
|
+
req.destroy();
|
|
590
|
+
finishErr(new HardwareRunnerError('RUNNER_SANDBOX_FAILED', 'blob download aborted'));
|
|
591
|
+
};
|
|
592
|
+
const timer = setTimeout(() => {
|
|
593
|
+
req.destroy();
|
|
594
|
+
finishErr(new RunnerTransportError('blob download timed out'));
|
|
595
|
+
}, timeoutMs);
|
|
596
|
+
timer.unref();
|
|
597
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
598
|
+
req.on('error', err => finishErr(new RunnerTransportError(`blob download socket error: ${err.message}`)));
|
|
599
|
+
req.end();
|
|
600
|
+
});
|
|
601
|
+
},
|
|
602
|
+
async uploadBlobFromFile({ jobId, creds, filePath, sha256, expectedByteLength, timeoutMs, signal }) {
|
|
603
|
+
const noFollow = 'O_NOFOLLOW' in constants ? constants.O_NOFOLLOW : 0;
|
|
604
|
+
await assertNoSymlinkAncestors(filePath, { checkLeaf: true, code: 'ARTIFACT_INVALID', diagPath: '/outputBlob' });
|
|
605
|
+
const handle = await open(filePath, constants.O_RDONLY | noFollow);
|
|
606
|
+
let readerTask = Promise.resolve();
|
|
607
|
+
try {
|
|
608
|
+
const st = await handle.stat();
|
|
609
|
+
if (!st.isFile()
|
|
610
|
+
|| st.isSymbolicLink()
|
|
611
|
+
|| st.nlink !== 1
|
|
612
|
+
|| (st.mode & 0o7777) !== 0o400
|
|
613
|
+
|| st.size !== expectedByteLength) {
|
|
614
|
+
throw new HardwareRunnerError('ARTIFACT_INVALID', 'sealed Stage A blob violated 0o400/nlink/size invariant before upload');
|
|
615
|
+
}
|
|
616
|
+
const path = `/v1/runner/leases/${encodeURIComponent(jobId)}/blobs/${sha256}`;
|
|
617
|
+
const headers = {
|
|
618
|
+
'content-type': 'application/octet-stream',
|
|
619
|
+
'content-length': String(expectedByteLength),
|
|
620
|
+
'x-loopwright-relay-boot-id': creds.relayBootId,
|
|
621
|
+
'x-loopwright-lease-epoch': String(creds.leaseEpoch),
|
|
622
|
+
'x-loopwright-lease-token': creds.leaseToken,
|
|
623
|
+
'x-loopwright-blob-sha256': sha256,
|
|
624
|
+
'x-loopwright-blob-length': String(expectedByteLength),
|
|
625
|
+
};
|
|
626
|
+
await new Promise((resolveUl, rejectUl) => {
|
|
627
|
+
let settled = false;
|
|
628
|
+
let localVerified = false;
|
|
629
|
+
let remoteAcked = false;
|
|
630
|
+
const finishErr = (err) => {
|
|
631
|
+
if (settled)
|
|
632
|
+
return;
|
|
633
|
+
settled = true;
|
|
634
|
+
clearTimeout(timer);
|
|
635
|
+
signal?.removeEventListener('abort', onAbort);
|
|
636
|
+
rejectUl(err);
|
|
637
|
+
};
|
|
638
|
+
const maybeFinishOk = () => {
|
|
639
|
+
if (!settled && localVerified && remoteAcked) {
|
|
640
|
+
settled = true;
|
|
641
|
+
clearTimeout(timer);
|
|
642
|
+
signal?.removeEventListener('abort', onAbort);
|
|
643
|
+
resolveUl();
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
const req = sendFn(buildRequestOptions('PUT', path, headers), (res) => {
|
|
647
|
+
const chunks = [];
|
|
648
|
+
let total = 0;
|
|
649
|
+
res.on('data', (c) => {
|
|
650
|
+
const b = Buffer.isBuffer(c) ? c : Buffer.from(c);
|
|
651
|
+
total += b.byteLength;
|
|
652
|
+
if (total > MAX_CONTROL_BODY_BYTES) {
|
|
653
|
+
req.destroy();
|
|
654
|
+
finishErr(new HardwareRunnerError('PAYLOAD_TOO_LARGE', 'Relay blob upload response exceeded 64 KiB'));
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
chunks.push(b);
|
|
658
|
+
});
|
|
659
|
+
res.on('error', err => finishErr(err));
|
|
660
|
+
res.on('end', () => {
|
|
661
|
+
if (settled)
|
|
662
|
+
return;
|
|
663
|
+
const status = res.statusCode ?? 0;
|
|
664
|
+
if (status >= 300 && status < 400) {
|
|
665
|
+
finishErr(new HardwareRunnerError('AUTH_FORBIDDEN', 'HTTP redirects on blob upload are forbidden'));
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
if (status !== 200 && status !== 201) {
|
|
669
|
+
finishErr(mapHttpError(status, Buffer.concat(chunks, total), `Stage A blob upload failed for ${sha256}`));
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
try {
|
|
673
|
+
validateBlobUploadResponsePayload(Buffer.concat(chunks, total), sha256, expectedByteLength);
|
|
674
|
+
}
|
|
675
|
+
catch (receiptErr) {
|
|
676
|
+
finishErr(receiptErr instanceof Error ? receiptErr : new Error(String(receiptErr)));
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
remoteAcked = true;
|
|
680
|
+
maybeFinishOk();
|
|
681
|
+
});
|
|
682
|
+
});
|
|
683
|
+
const onAbort = () => {
|
|
684
|
+
req.destroy();
|
|
685
|
+
finishErr(new HardwareRunnerError('RUNNER_SANDBOX_FAILED', 'Stage A blob upload aborted'));
|
|
686
|
+
};
|
|
687
|
+
const timer = setTimeout(() => {
|
|
688
|
+
req.destroy();
|
|
689
|
+
finishErr(new HardwareRunnerError('RUNNER_SANDBOX_FAILED', 'Stage A blob upload timed out'));
|
|
690
|
+
}, timeoutMs);
|
|
691
|
+
timer.unref();
|
|
692
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
693
|
+
req.on('error', err => finishErr(err));
|
|
694
|
+
readerTask = (async () => {
|
|
695
|
+
const chunkBuf = Buffer.allocUnsafe(Math.min(MAX_CAS_CHUNK_BYTES, Math.max(1, expectedByteLength)));
|
|
696
|
+
const hasher = createHash('sha256');
|
|
697
|
+
let offset = 0;
|
|
698
|
+
while (offset < expectedByteLength) {
|
|
699
|
+
if (signal?.aborted) {
|
|
700
|
+
req.destroy();
|
|
701
|
+
finishErr(new HardwareRunnerError('RUNNER_SANDBOX_FAILED', 'Stage A blob upload aborted'));
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
if (settled)
|
|
705
|
+
return;
|
|
706
|
+
const toRead = Math.min(chunkBuf.byteLength, expectedByteLength - offset);
|
|
707
|
+
const { bytesRead } = await handle.read(chunkBuf, 0, toRead, offset);
|
|
708
|
+
if (bytesRead <= 0)
|
|
709
|
+
break;
|
|
710
|
+
const slice = Buffer.from(chunkBuf.subarray(0, bytesRead));
|
|
711
|
+
hasher.update(slice);
|
|
712
|
+
offset += bytesRead;
|
|
713
|
+
if (!req.destroyed && !req.writableEnded) {
|
|
714
|
+
const canWrite = req.write(slice);
|
|
715
|
+
if (!canWrite && !req.destroyed) {
|
|
716
|
+
await new Promise(resolveDrain => {
|
|
717
|
+
const onDrain = () => {
|
|
718
|
+
req.removeListener('close', onClose);
|
|
719
|
+
resolveDrain();
|
|
720
|
+
};
|
|
721
|
+
const onClose = () => {
|
|
722
|
+
req.removeListener('drain', onDrain);
|
|
723
|
+
resolveDrain();
|
|
724
|
+
};
|
|
725
|
+
req.once('drain', onDrain);
|
|
726
|
+
req.once('close', onClose);
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
if (settled)
|
|
732
|
+
return;
|
|
733
|
+
if (signal?.aborted) {
|
|
734
|
+
req.destroy();
|
|
735
|
+
finishErr(new HardwareRunnerError('RUNNER_SANDBOX_FAILED', 'Stage A blob upload aborted'));
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
if (offset !== expectedByteLength || hasher.digest('hex') !== sha256) {
|
|
739
|
+
req.destroy();
|
|
740
|
+
finishErr(new HardwareRunnerError('ARTIFACT_INVALID', 'sealed Stage A blob changed size or digest during upload'));
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
localVerified = true;
|
|
744
|
+
if (!req.destroyed && !req.writableEnded) {
|
|
745
|
+
req.end();
|
|
746
|
+
}
|
|
747
|
+
else if (!remoteAcked) {
|
|
748
|
+
finishErr(new HardwareRunnerError('RUNNER_SANDBOX_FAILED', 'Stage A blob upload stream closed before acknowledgment'));
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
maybeFinishOk();
|
|
752
|
+
})().catch(err => {
|
|
753
|
+
req.destroy();
|
|
754
|
+
finishErr(err instanceof Error ? err : new Error(String(err)));
|
|
755
|
+
});
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
finally {
|
|
759
|
+
await readerTask.catch(() => { });
|
|
760
|
+
await handle.close();
|
|
761
|
+
}
|
|
762
|
+
},
|
|
763
|
+
watchCancelEvents({ jobId, creds, signal, onCancel, onFenced, onDisconnected }) {
|
|
764
|
+
if (signal.aborted)
|
|
765
|
+
return Promise.resolve();
|
|
766
|
+
const path = `/v1/runner/leases/${encodeURIComponent(jobId)}/events`;
|
|
767
|
+
const headers = {
|
|
768
|
+
accept: 'text/event-stream',
|
|
769
|
+
'x-loopwright-relay-boot-id': creds.relayBootId,
|
|
770
|
+
'x-loopwright-lease-epoch': String(creds.leaseEpoch),
|
|
771
|
+
'x-loopwright-lease-token': creds.leaseToken,
|
|
772
|
+
};
|
|
773
|
+
return new Promise(resolveWatch => {
|
|
774
|
+
let done = false;
|
|
775
|
+
let sawExplicitEvent = false;
|
|
776
|
+
const finish = (unexpectedDisconnect) => {
|
|
777
|
+
if (done)
|
|
778
|
+
return;
|
|
779
|
+
done = true;
|
|
780
|
+
signal.removeEventListener('abort', onAbort);
|
|
781
|
+
if (unexpectedDisconnect && !signal.aborted && !sawExplicitEvent) {
|
|
782
|
+
onDisconnected?.();
|
|
783
|
+
}
|
|
784
|
+
resolveWatch();
|
|
785
|
+
};
|
|
786
|
+
const req = sendFn(buildRequestOptions('GET', path, headers), (res) => {
|
|
787
|
+
const status = res.statusCode ?? 0;
|
|
788
|
+
if (status === 409) {
|
|
789
|
+
sawExplicitEvent = true;
|
|
790
|
+
res.resume();
|
|
791
|
+
onFenced();
|
|
792
|
+
finish(false);
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
if (status !== 200) {
|
|
796
|
+
res.resume();
|
|
797
|
+
finish(true);
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
let buffer = '';
|
|
801
|
+
res.setEncoding('utf8');
|
|
802
|
+
res.on('data', (chunk) => {
|
|
803
|
+
buffer += chunk;
|
|
804
|
+
if (buffer.length > 16_384) {
|
|
805
|
+
req.destroy();
|
|
806
|
+
finish(true);
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
let boundary = buffer.indexOf('\n\n');
|
|
810
|
+
while (boundary !== -1) {
|
|
811
|
+
const frame = buffer.slice(0, boundary);
|
|
812
|
+
buffer = buffer.slice(boundary + 2);
|
|
813
|
+
const lines = frame.split(/\r?\n/);
|
|
814
|
+
for (const line of lines) {
|
|
815
|
+
let isCancelEvent = line === 'event: cancel';
|
|
816
|
+
if (!isCancelEvent && line.startsWith('data:')) {
|
|
817
|
+
const dataPayload = line.slice(5).trim();
|
|
818
|
+
try {
|
|
819
|
+
const parsed = JSON.parse(dataPayload);
|
|
820
|
+
if (parsed !== null
|
|
821
|
+
&& typeof parsed === 'object'
|
|
822
|
+
&& !Array.isArray(parsed)
|
|
823
|
+
&& Object.hasOwn(parsed, 'desiredState')
|
|
824
|
+
&& parsed['desiredState'] === 'cancel') {
|
|
825
|
+
isCancelEvent = true;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
catch {
|
|
829
|
+
// Ignore malformed or non-JSON SSE data payloads.
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
if (isCancelEvent) {
|
|
833
|
+
sawExplicitEvent = true;
|
|
834
|
+
onCancel();
|
|
835
|
+
req.destroy();
|
|
836
|
+
finish(false);
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
boundary = buffer.indexOf('\n\n');
|
|
841
|
+
}
|
|
842
|
+
});
|
|
843
|
+
res.on('end', () => finish(true));
|
|
844
|
+
res.on('error', () => finish(true));
|
|
845
|
+
});
|
|
846
|
+
const onAbort = () => {
|
|
847
|
+
req.destroy();
|
|
848
|
+
finish(false);
|
|
849
|
+
};
|
|
850
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
851
|
+
req.on('error', () => finish(true));
|
|
852
|
+
req.end();
|
|
853
|
+
});
|
|
854
|
+
},
|
|
855
|
+
close() {
|
|
856
|
+
httpsAgent?.destroy();
|
|
857
|
+
},
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
function sleepAbortable(ms, signal) {
|
|
861
|
+
if (signal.aborted || ms <= 0)
|
|
862
|
+
return Promise.resolve();
|
|
863
|
+
return new Promise(resolveSleep => {
|
|
864
|
+
const onAbort = () => {
|
|
865
|
+
clearTimeout(timer);
|
|
866
|
+
resolveSleep();
|
|
867
|
+
};
|
|
868
|
+
const timer = setTimeout(() => {
|
|
869
|
+
signal.removeEventListener('abort', onAbort);
|
|
870
|
+
resolveSleep();
|
|
871
|
+
}, ms);
|
|
872
|
+
// Keep the timer ref'd: the outbound-only worker holds no listening sockets, so unref'ing
|
|
873
|
+
// the retry/idle timer would let Node's event loop drain prematurely instead of retrying.
|
|
874
|
+
// Shutdown/preemption still exits immediately because onAbort clears the timer.
|
|
875
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Run the outbound-only pull-lease GPU/NPU worker loop (zero inbound listening ports).
|
|
880
|
+
*/
|
|
881
|
+
export async function runHardwareWorker(options) {
|
|
882
|
+
const { config } = options;
|
|
883
|
+
if (config.sandboxBackend === 'native_os' && config.probeMode === 'physical') {
|
|
884
|
+
throw new HardwareRunnerError('RUNNER_SANDBOX_FAILED', 'native_os sandbox backend cannot enforce isolated physical accelerator device allocation; docker backend is required');
|
|
885
|
+
}
|
|
886
|
+
await assertNoSymlinkAncestors(resolve(config.workDir), {
|
|
887
|
+
checkLeaf: true,
|
|
888
|
+
code: 'CONFIG_INVALID',
|
|
889
|
+
diagPath: '/workDir',
|
|
890
|
+
});
|
|
891
|
+
await assertNoSymlinkAncestors(resolve(config.heldOutWorkloadsDir), {
|
|
892
|
+
checkLeaf: true,
|
|
893
|
+
code: 'CONFIG_INVALID',
|
|
894
|
+
diagPath: '/heldOutWorkloadsDir',
|
|
895
|
+
});
|
|
896
|
+
const clock = options.clock ?? DEFAULT_WORKER_CLOCK;
|
|
897
|
+
const processShutdown = new AbortController();
|
|
898
|
+
const processPreempt = new AbortController();
|
|
899
|
+
const onSigTerm = () => processPreempt.abort();
|
|
900
|
+
const onSigInt = () => processShutdown.abort();
|
|
901
|
+
if (options.registerProcessSignalHandlers !== false) {
|
|
902
|
+
process.once('SIGTERM', onSigTerm);
|
|
903
|
+
process.once('SIGINT', onSigInt);
|
|
904
|
+
}
|
|
905
|
+
const stopSignals = [processShutdown.signal];
|
|
906
|
+
if (options.signal !== undefined)
|
|
907
|
+
stopSignals.push(options.signal);
|
|
908
|
+
const shutdownSignal = AbortSignal.any(stopSignals);
|
|
909
|
+
const preemptSignals = [processPreempt.signal];
|
|
910
|
+
if (options.preemptSignal !== undefined)
|
|
911
|
+
preemptSignals.push(options.preemptSignal);
|
|
912
|
+
const preemptSignal = AbortSignal.any(preemptSignals);
|
|
913
|
+
const client = await createOutboundHttpClient(config);
|
|
914
|
+
const evaluator = options.evaluator ?? evaluateBenchmarkJob;
|
|
915
|
+
let polls = 0;
|
|
916
|
+
let jobsProcessed = 0;
|
|
917
|
+
let lastSettlement = null;
|
|
918
|
+
try {
|
|
919
|
+
while (true) {
|
|
920
|
+
if (preemptSignal.aborted) {
|
|
921
|
+
return { polls, jobsProcessed, lastSettlement, exitReason: 'preempted' };
|
|
922
|
+
}
|
|
923
|
+
if (shutdownSignal.aborted) {
|
|
924
|
+
return { polls, jobsProcessed, lastSettlement, exitReason: 'aborted' };
|
|
925
|
+
}
|
|
926
|
+
polls += 1;
|
|
927
|
+
const acquireSignal = AbortSignal.any([shutdownSignal, preemptSignal]);
|
|
928
|
+
const acquireSentMono = clock.nowMonotonicMs();
|
|
929
|
+
let acquireRes;
|
|
930
|
+
try {
|
|
931
|
+
acquireRes = await client.requestJson({
|
|
932
|
+
method: 'POST',
|
|
933
|
+
path: '/v1/runner/leases:acquire',
|
|
934
|
+
body: {
|
|
935
|
+
workerId: config.workerId,
|
|
936
|
+
capabilities: config.capabilities,
|
|
937
|
+
waitMs: config.pollWaitMs,
|
|
938
|
+
},
|
|
939
|
+
timeoutMs: Math.max(config.requestTimeoutMs, config.pollWaitMs + 5_000),
|
|
940
|
+
signal: acquireSignal,
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
catch (err) {
|
|
944
|
+
if (preemptSignal.aborted) {
|
|
945
|
+
return { polls, jobsProcessed, lastSettlement, exitReason: 'preempted' };
|
|
946
|
+
}
|
|
947
|
+
if (shutdownSignal.aborted) {
|
|
948
|
+
return { polls, jobsProcessed, lastSettlement, exitReason: 'aborted' };
|
|
949
|
+
}
|
|
950
|
+
if (err instanceof HardwareRunnerError && (err.code === 'AUTH_UNAUTHORIZED' || err.code === 'AUTH_FORBIDDEN')) {
|
|
951
|
+
throw err;
|
|
952
|
+
}
|
|
953
|
+
if (options.once === true) {
|
|
954
|
+
throw err;
|
|
955
|
+
}
|
|
956
|
+
await sleepAbortable(options.idleRetryDelayMs ?? 200, acquireSignal);
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
if (acquireRes.status === 204) {
|
|
960
|
+
if (options.once === true) {
|
|
961
|
+
return { polls, jobsProcessed, lastSettlement, exitReason: 'once_idle' };
|
|
962
|
+
}
|
|
963
|
+
if (config.pollWaitMs === 0) {
|
|
964
|
+
await sleepAbortable(options.idleRetryDelayMs ?? 50, acquireSignal);
|
|
965
|
+
}
|
|
966
|
+
continue;
|
|
967
|
+
}
|
|
968
|
+
if (acquireRes.status !== 200) {
|
|
969
|
+
const mappedAcquireErr = mapHttpError(acquireRes.status, acquireRes.bytes, 'failed to acquire worker lease');
|
|
970
|
+
if (options.once !== true
|
|
971
|
+
&& (acquireRes.status === 429 || acquireRes.status === 502 || acquireRes.status === 503 || acquireRes.status === 504)) {
|
|
972
|
+
await sleepAbortable(options.idleRetryDelayMs ?? 200, acquireSignal);
|
|
973
|
+
continue;
|
|
974
|
+
}
|
|
975
|
+
throw mappedAcquireErr;
|
|
976
|
+
}
|
|
977
|
+
const grant = parseLeaseGrantPayload(acquireRes.bytes, OVERLAY_LIMITS.maxMaxBytes);
|
|
978
|
+
const creds = {
|
|
979
|
+
relayBootId: grant.relayBootId,
|
|
980
|
+
leaseEpoch: grant.leaseEpoch,
|
|
981
|
+
leaseToken: grant.leaseToken,
|
|
982
|
+
};
|
|
983
|
+
const scrubber = new SecretScrubber();
|
|
984
|
+
scrubber.register(config.workerToken);
|
|
985
|
+
scrubber.register(grant.leaseToken);
|
|
986
|
+
// Anchor conservative initial lease deadline strictly to acquireSentMono (pre-request)!
|
|
987
|
+
// Never anchor to receipt time without a verified send-anchored renewal.
|
|
988
|
+
const initialSafetyMarginMs = computeConservativeLeaseMarginMs(grant.leaseTtlMs);
|
|
989
|
+
let localLeaseDeadlineMono = acquireSentMono + grant.leaseTtlMs - initialSafetyMarginMs;
|
|
990
|
+
let effectiveHbMs = Math.max(15, Math.min(config.heartbeatIntervalMs, Math.floor(grant.leaseTtlMs / 3)));
|
|
991
|
+
const jobAbort = new AbortController();
|
|
992
|
+
const watchAbort = new AbortController();
|
|
993
|
+
let wakeHeartbeatNow = null;
|
|
994
|
+
const abortState = { cause: 'none' };
|
|
995
|
+
const triggerAbort = (cause) => {
|
|
996
|
+
if (abortState.cause === 'none' || (cause === 'preempt' && abortState.cause !== 'fenced')) {
|
|
997
|
+
abortState.cause = cause;
|
|
998
|
+
}
|
|
999
|
+
jobAbort.abort();
|
|
1000
|
+
watchAbort.abort();
|
|
1001
|
+
wakeHeartbeatNow?.();
|
|
1002
|
+
};
|
|
1003
|
+
let leaseDeadlineTimer = null;
|
|
1004
|
+
const clearLeaseDeadlineTimer = () => {
|
|
1005
|
+
if (leaseDeadlineTimer !== null) {
|
|
1006
|
+
clearTimeout(leaseDeadlineTimer);
|
|
1007
|
+
leaseDeadlineTimer = null;
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
const scheduleLeaseDeadlineTimer = () => {
|
|
1011
|
+
clearLeaseDeadlineTimer();
|
|
1012
|
+
if (jobAbort.signal.aborted)
|
|
1013
|
+
return;
|
|
1014
|
+
const remainingMs = localLeaseDeadlineMono - clock.nowMonotonicMs();
|
|
1015
|
+
if (remainingMs <= 0) {
|
|
1016
|
+
triggerAbort('fenced');
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
leaseDeadlineTimer = setTimeout(() => {
|
|
1020
|
+
if (!jobAbort.signal.aborted && clock.nowMonotonicMs() >= localLeaseDeadlineMono) {
|
|
1021
|
+
triggerAbort('fenced');
|
|
1022
|
+
}
|
|
1023
|
+
else if (!jobAbort.signal.aborted) {
|
|
1024
|
+
scheduleLeaseDeadlineTimer();
|
|
1025
|
+
}
|
|
1026
|
+
}, Math.max(1, Math.ceil(remainingMs)));
|
|
1027
|
+
leaseDeadlineTimer.unref();
|
|
1028
|
+
};
|
|
1029
|
+
const assertAuthorityLive = () => {
|
|
1030
|
+
if (clock.nowMonotonicMs() >= localLeaseDeadlineMono) {
|
|
1031
|
+
triggerAbort('fenced');
|
|
1032
|
+
return false;
|
|
1033
|
+
}
|
|
1034
|
+
return !jobAbort.signal.aborted;
|
|
1035
|
+
};
|
|
1036
|
+
const onJobPreempt = () => triggerAbort('preempt');
|
|
1037
|
+
const onJobShutdown = () => triggerAbort('shutdown');
|
|
1038
|
+
if (preemptSignal.aborted) {
|
|
1039
|
+
triggerAbort('preempt');
|
|
1040
|
+
}
|
|
1041
|
+
else {
|
|
1042
|
+
preemptSignal.addEventListener('abort', onJobPreempt, { once: true });
|
|
1043
|
+
}
|
|
1044
|
+
if (!jobAbort.signal.aborted && shutdownSignal.aborted) {
|
|
1045
|
+
triggerAbort('shutdown');
|
|
1046
|
+
}
|
|
1047
|
+
else {
|
|
1048
|
+
shutdownSignal.addEventListener('abort', onJobShutdown, { once: true });
|
|
1049
|
+
}
|
|
1050
|
+
let evaluated = null;
|
|
1051
|
+
let evaluatorInfraError = null;
|
|
1052
|
+
let teardownFailure = null;
|
|
1053
|
+
// If long-poll turnaround consumed a substantial share of the lease (leaving <= max(safetyMargin, effectiveHbMs, leaseTtlMs/3)
|
|
1054
|
+
// before conservative local expiry, or already past localLeaseDeadlineMono), require an immediate request-send-anchored
|
|
1055
|
+
// :heartbeat renewal BEFORE starting the evaluator!
|
|
1056
|
+
const preStartRenewalThresholdMs = Math.max(initialSafetyMarginMs, effectiveHbMs, Math.floor(grant.leaseTtlMs / 3));
|
|
1057
|
+
if (!jobAbort.signal.aborted && localLeaseDeadlineMono - clock.nowMonotonicMs() <= preStartRenewalThresholdMs) {
|
|
1058
|
+
const preHbSentMono = clock.nowMonotonicMs();
|
|
1059
|
+
try {
|
|
1060
|
+
const preHbRes = await client.requestJson({
|
|
1061
|
+
method: 'POST',
|
|
1062
|
+
path: `/v1/runner/leases/${encodeURIComponent(grant.jobId)}:heartbeat`,
|
|
1063
|
+
body: {
|
|
1064
|
+
relayBootId: creds.relayBootId,
|
|
1065
|
+
leaseEpoch: creds.leaseEpoch,
|
|
1066
|
+
leaseToken: creds.leaseToken,
|
|
1067
|
+
state: 'running',
|
|
1068
|
+
},
|
|
1069
|
+
timeoutMs: Math.min(config.requestTimeoutMs, Math.max(50, grant.leaseTtlMs)),
|
|
1070
|
+
signal: jobAbort.signal,
|
|
1071
|
+
});
|
|
1072
|
+
if (preHbRes.status === 409) {
|
|
1073
|
+
const errCode = parseErrorCodeFromJson(preHbRes.bytes);
|
|
1074
|
+
if (errCode === 'QUEUE_LEASE_FENCED' || errCode === null) {
|
|
1075
|
+
triggerAbort('fenced');
|
|
1076
|
+
}
|
|
1077
|
+
else {
|
|
1078
|
+
evaluatorInfraError = mapHttpError(preHbRes.status, preHbRes.bytes, 'pre-start lease renewal failed');
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
else if (preHbRes.status === 200) {
|
|
1082
|
+
const parsedPreHb = validateHeartbeatResponsePayload(preHbRes.bytes, creds.leaseEpoch);
|
|
1083
|
+
if (parsedPreHb.desiredState === 'cancel') {
|
|
1084
|
+
triggerAbort('cancel');
|
|
1085
|
+
}
|
|
1086
|
+
else {
|
|
1087
|
+
const renewedMono = preHbSentMono + parsedPreHb.leaseTtlMs - computeConservativeLeaseMarginMs(parsedPreHb.leaseTtlMs);
|
|
1088
|
+
if (renewedMono <= clock.nowMonotonicMs()) {
|
|
1089
|
+
triggerAbort('fenced');
|
|
1090
|
+
}
|
|
1091
|
+
else {
|
|
1092
|
+
localLeaseDeadlineMono = renewedMono;
|
|
1093
|
+
effectiveHbMs = Math.max(15, Math.min(config.heartbeatIntervalMs, Math.floor(parsedPreHb.leaseTtlMs / 3)));
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
else {
|
|
1098
|
+
evaluatorInfraError = mapHttpError(preHbRes.status, preHbRes.bytes, 'pre-start lease renewal failed');
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
catch (preHbErr) {
|
|
1102
|
+
if (preHbErr instanceof HardwareRunnerError && preHbErr.code === 'QUEUE_LEASE_FENCED') {
|
|
1103
|
+
triggerAbort('fenced');
|
|
1104
|
+
}
|
|
1105
|
+
else if (!jobAbort.signal.aborted) {
|
|
1106
|
+
evaluatorInfraError = preHbErr instanceof HardwareRunnerError
|
|
1107
|
+
? preHbErr
|
|
1108
|
+
: new RunnerTransportError(preHbErr instanceof Error ? preHbErr.message : 'pre-start lease renewal failed');
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
if (evaluatorInfraError === null && !jobAbort.signal.aborted) {
|
|
1113
|
+
scheduleLeaseDeadlineTimer();
|
|
1114
|
+
}
|
|
1115
|
+
if (options.onLeaseAcquired !== undefined) {
|
|
1116
|
+
await options.onLeaseAcquired(grant);
|
|
1117
|
+
}
|
|
1118
|
+
let hbStopped = false;
|
|
1119
|
+
let immediateHbRequested = false;
|
|
1120
|
+
const waitNextHeartbeatTick = (ms) => {
|
|
1121
|
+
if (hbStopped || jobAbort.signal.aborted || immediateHbRequested) {
|
|
1122
|
+
immediateHbRequested = false;
|
|
1123
|
+
return Promise.resolve();
|
|
1124
|
+
}
|
|
1125
|
+
return new Promise(resolveWait => {
|
|
1126
|
+
const finishWait = () => {
|
|
1127
|
+
clearTimeout(t);
|
|
1128
|
+
jobAbort.signal.removeEventListener('abort', finishWait);
|
|
1129
|
+
wakeHeartbeatNow = null;
|
|
1130
|
+
immediateHbRequested = false;
|
|
1131
|
+
resolveWait();
|
|
1132
|
+
};
|
|
1133
|
+
const t = setTimeout(finishWait, ms);
|
|
1134
|
+
t.unref();
|
|
1135
|
+
wakeHeartbeatNow = finishWait;
|
|
1136
|
+
jobAbort.signal.addEventListener('abort', finishWait, { once: true });
|
|
1137
|
+
});
|
|
1138
|
+
};
|
|
1139
|
+
const heartbeatLoop = evaluatorInfraError === null
|
|
1140
|
+
? (async () => {
|
|
1141
|
+
while (!hbStopped && !jobAbort.signal.aborted) {
|
|
1142
|
+
await waitNextHeartbeatTick(effectiveHbMs);
|
|
1143
|
+
if (hbStopped || jobAbort.signal.aborted)
|
|
1144
|
+
break;
|
|
1145
|
+
if (!assertAuthorityLive())
|
|
1146
|
+
break;
|
|
1147
|
+
const hbStartedMono = clock.nowMonotonicMs();
|
|
1148
|
+
const remainingBudgetMs = Math.max(25, Math.ceil(localLeaseDeadlineMono - hbStartedMono));
|
|
1149
|
+
try {
|
|
1150
|
+
const hbRes = await client.requestJson({
|
|
1151
|
+
method: 'POST',
|
|
1152
|
+
path: `/v1/runner/leases/${encodeURIComponent(grant.jobId)}:heartbeat`,
|
|
1153
|
+
body: {
|
|
1154
|
+
relayBootId: creds.relayBootId,
|
|
1155
|
+
leaseEpoch: creds.leaseEpoch,
|
|
1156
|
+
leaseToken: creds.leaseToken,
|
|
1157
|
+
state: 'running',
|
|
1158
|
+
},
|
|
1159
|
+
timeoutMs: Math.min(config.requestTimeoutMs, remainingBudgetMs),
|
|
1160
|
+
signal: jobAbort.signal,
|
|
1161
|
+
});
|
|
1162
|
+
if (hbRes.status === 409) {
|
|
1163
|
+
const errCode = parseErrorCodeFromJson(hbRes.bytes);
|
|
1164
|
+
if (errCode === 'QUEUE_LEASE_FENCED' || errCode === null) {
|
|
1165
|
+
triggerAbort('fenced');
|
|
1166
|
+
break;
|
|
1167
|
+
}
|
|
1168
|
+
continue;
|
|
1169
|
+
}
|
|
1170
|
+
if (hbRes.status === 200) {
|
|
1171
|
+
const parsedHb = validateHeartbeatResponsePayload(hbRes.bytes, creds.leaseEpoch);
|
|
1172
|
+
if (parsedHb.desiredState === 'cancel') {
|
|
1173
|
+
triggerAbort('cancel');
|
|
1174
|
+
break;
|
|
1175
|
+
}
|
|
1176
|
+
// Anchor renewal strictly to hbStartedMono and honor BOTH extensions AND shorter TTL renewals!
|
|
1177
|
+
localLeaseDeadlineMono =
|
|
1178
|
+
hbStartedMono + parsedHb.leaseTtlMs - computeConservativeLeaseMarginMs(parsedHb.leaseTtlMs);
|
|
1179
|
+
effectiveHbMs = Math.max(15, Math.min(config.heartbeatIntervalMs, Math.floor(parsedHb.leaseTtlMs / 3)));
|
|
1180
|
+
scheduleLeaseDeadlineTimer();
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
catch (hbErr) {
|
|
1184
|
+
if (hbErr instanceof HardwareRunnerError && hbErr.code === 'QUEUE_LEASE_FENCED') {
|
|
1185
|
+
triggerAbort('fenced');
|
|
1186
|
+
break;
|
|
1187
|
+
}
|
|
1188
|
+
if (!assertAuthorityLive())
|
|
1189
|
+
break;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
})()
|
|
1193
|
+
: Promise.resolve();
|
|
1194
|
+
const sseWatchPromise = options.enableSseEvents !== false && evaluatorInfraError === null
|
|
1195
|
+
? client.watchCancelEvents({
|
|
1196
|
+
jobId: grant.jobId,
|
|
1197
|
+
creds,
|
|
1198
|
+
signal: watchAbort.signal,
|
|
1199
|
+
onCancel: () => triggerAbort('cancel'),
|
|
1200
|
+
onFenced: () => triggerAbort('fenced'),
|
|
1201
|
+
onDisconnected: () => {
|
|
1202
|
+
immediateHbRequested = true;
|
|
1203
|
+
wakeHeartbeatNow?.();
|
|
1204
|
+
},
|
|
1205
|
+
})
|
|
1206
|
+
: Promise.resolve();
|
|
1207
|
+
try {
|
|
1208
|
+
if (evaluatorInfraError === null && assertAuthorityLive()) {
|
|
1209
|
+
evaluated = await evaluator({
|
|
1210
|
+
config,
|
|
1211
|
+
grant,
|
|
1212
|
+
signal: jobAbort.signal,
|
|
1213
|
+
getLeaseDeadlineMonoMs: () => localLeaseDeadlineMono,
|
|
1214
|
+
nowMonotonicMs: () => clock.nowMonotonicMs(),
|
|
1215
|
+
...(options.probe !== undefined ? { probe: options.probe } : {}),
|
|
1216
|
+
downloadInputBlob: async (sha256, expectedByteLength, onChunk) => {
|
|
1217
|
+
if (!assertAuthorityLive()) {
|
|
1218
|
+
throw new HardwareRunnerError('QUEUE_LEASE_FENCED', 'local lease authority expired before blob download');
|
|
1219
|
+
}
|
|
1220
|
+
try {
|
|
1221
|
+
await client.downloadBlobToStream({
|
|
1222
|
+
jobId: grant.jobId,
|
|
1223
|
+
creds,
|
|
1224
|
+
sha256,
|
|
1225
|
+
expectedByteLength,
|
|
1226
|
+
timeoutMs: config.requestTimeoutMs,
|
|
1227
|
+
signal: jobAbort.signal,
|
|
1228
|
+
onChunk,
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
catch (dlErr) {
|
|
1232
|
+
if (dlErr instanceof HardwareRunnerError && dlErr.code === 'QUEUE_LEASE_FENCED') {
|
|
1233
|
+
triggerAbort('fenced');
|
|
1234
|
+
}
|
|
1235
|
+
throw dlErr;
|
|
1236
|
+
}
|
|
1237
|
+
},
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
catch (evalErr) {
|
|
1242
|
+
if (isRunnerTeardownError(evalErr)) {
|
|
1243
|
+
teardownFailure = evalErr instanceof HardwareRunnerError
|
|
1244
|
+
? evalErr
|
|
1245
|
+
: new RunnerTeardownError(evalErr instanceof Error ? evalErr.message : String(evalErr));
|
|
1246
|
+
}
|
|
1247
|
+
else if (evalErr instanceof HardwareRunnerError && evalErr.code === 'QUEUE_LEASE_FENCED') {
|
|
1248
|
+
triggerAbort('fenced');
|
|
1249
|
+
}
|
|
1250
|
+
else if (!jobAbort.signal.aborted) {
|
|
1251
|
+
if (evalErr instanceof HardwareRunnerError
|
|
1252
|
+
&& !isRunnerTransportError(evalErr)
|
|
1253
|
+
&& DETERMINISTIC_EVAL_ERROR_CODES.has(evalErr.code)) {
|
|
1254
|
+
const safeDetail = scrubber.scrub(evalErr.message).trim() || evalErr.code;
|
|
1255
|
+
evaluated = {
|
|
1256
|
+
status: 'denied',
|
|
1257
|
+
reason: evalErr.code,
|
|
1258
|
+
detail: safeDetail,
|
|
1259
|
+
findings: Object.freeze([
|
|
1260
|
+
Object.freeze({
|
|
1261
|
+
title: `Benchmark job rejected (${evalErr.code})`,
|
|
1262
|
+
severity: 'high',
|
|
1263
|
+
evidence: safeDetail,
|
|
1264
|
+
}),
|
|
1265
|
+
]),
|
|
1266
|
+
sealedOutputs: Object.freeze([]),
|
|
1267
|
+
cleanup: async () => { },
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
else if (evalErr instanceof HardwareRunnerError) {
|
|
1271
|
+
evaluatorInfraError = evalErr;
|
|
1272
|
+
}
|
|
1273
|
+
else {
|
|
1274
|
+
evaluatorInfraError = new HardwareRunnerError('RUNNER_SANDBOX_FAILED', evalErr instanceof Error ? evalErr.message : 'worker evaluation failed');
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
let ackedOutputCount = 0;
|
|
1279
|
+
let unackedUploadFailure = false;
|
|
1280
|
+
let jobCleanupAttempted = false;
|
|
1281
|
+
const shouldPreserveSealedOutputs = () => {
|
|
1282
|
+
if (evaluated === null || evaluated.sealedOutputs.length === 0) {
|
|
1283
|
+
return false;
|
|
1284
|
+
}
|
|
1285
|
+
if (unackedUploadFailure) {
|
|
1286
|
+
return true;
|
|
1287
|
+
}
|
|
1288
|
+
if (abortState.cause === 'preempt'
|
|
1289
|
+
|| preemptSignal.aborted
|
|
1290
|
+
|| abortState.cause === 'cancel'
|
|
1291
|
+
|| abortState.cause === 'shutdown'
|
|
1292
|
+
|| shutdownSignal.aborted
|
|
1293
|
+
|| abortState.cause === 'fenced') {
|
|
1294
|
+
return false;
|
|
1295
|
+
}
|
|
1296
|
+
return ackedOutputCount < evaluated.sealedOutputs.length;
|
|
1297
|
+
};
|
|
1298
|
+
const runEvaluatedCleanupOnce = async (preserveSealedOutputs) => {
|
|
1299
|
+
if (evaluated !== null && !jobCleanupAttempted) {
|
|
1300
|
+
jobCleanupAttempted = true;
|
|
1301
|
+
try {
|
|
1302
|
+
await evaluated.cleanup(preserveSealedOutputs ? { preserveSealedOutputs: true } : undefined);
|
|
1303
|
+
}
|
|
1304
|
+
catch (cleanErr) {
|
|
1305
|
+
const wrapped = cleanErr instanceof RunnerTeardownError
|
|
1306
|
+
? cleanErr
|
|
1307
|
+
: new RunnerTeardownError(cleanErr instanceof Error ? cleanErr.message : 'failed to clean up job workspace');
|
|
1308
|
+
teardownFailure ??= wrapped;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
};
|
|
1312
|
+
let bodyLoopErr = null;
|
|
1313
|
+
try {
|
|
1314
|
+
// Upload sealed Stage A output blobs while heartbeat and local lease authority remain active.
|
|
1315
|
+
if (teardownFailure === null
|
|
1316
|
+
&& evaluated !== null
|
|
1317
|
+
&& evaluatorInfraError === null
|
|
1318
|
+
&& assertAuthorityLive()) {
|
|
1319
|
+
for (const sealed of evaluated.sealedOutputs) {
|
|
1320
|
+
if (!assertAuthorityLive())
|
|
1321
|
+
break;
|
|
1322
|
+
try {
|
|
1323
|
+
await client.uploadBlobFromFile({
|
|
1324
|
+
jobId: grant.jobId,
|
|
1325
|
+
creds,
|
|
1326
|
+
filePath: sealed.sealedFilePath,
|
|
1327
|
+
sha256: sealed.artifact.digest.hex,
|
|
1328
|
+
expectedByteLength: sealed.artifact.byteLength,
|
|
1329
|
+
timeoutMs: Math.max(config.requestTimeoutMs, 60_000),
|
|
1330
|
+
signal: jobAbort.signal,
|
|
1331
|
+
});
|
|
1332
|
+
ackedOutputCount += 1;
|
|
1333
|
+
}
|
|
1334
|
+
catch (ulErr) {
|
|
1335
|
+
if (ulErr instanceof HardwareRunnerError && ulErr.code === 'QUEUE_LEASE_FENCED') {
|
|
1336
|
+
triggerAbort('fenced');
|
|
1337
|
+
break;
|
|
1338
|
+
}
|
|
1339
|
+
if (!jobAbort.signal.aborted) {
|
|
1340
|
+
unackedUploadFailure = true;
|
|
1341
|
+
throw ulErr;
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
// Remove disposable local job scratch directories BEFORE settling (:preempt or :complete);
|
|
1347
|
+
// only remove sealed outputs once every required output blob is remoteAcked (or no unacked upload is pending)!
|
|
1348
|
+
await runEvaluatedCleanupOnce(shouldPreserveSealedOutputs());
|
|
1349
|
+
watchAbort.abort();
|
|
1350
|
+
await sseWatchPromise.catch(() => { });
|
|
1351
|
+
// NEVER send confirmed :preempt or :complete when process/container/workspace teardown failed!
|
|
1352
|
+
if (teardownFailure !== null) {
|
|
1353
|
+
hbStopped = true;
|
|
1354
|
+
clearLeaseDeadlineTimer();
|
|
1355
|
+
jobAbort.abort();
|
|
1356
|
+
await heartbeatLoop.catch(() => { });
|
|
1357
|
+
lastSettlement = Object.freeze({
|
|
1358
|
+
jobId: grant.jobId,
|
|
1359
|
+
operationId: grant.operationId,
|
|
1360
|
+
leaseEpoch: grant.leaseEpoch,
|
|
1361
|
+
outcome: 'unknown',
|
|
1362
|
+
acknowledgment: 'local_only',
|
|
1363
|
+
relayErrorCode: teardownFailure.code,
|
|
1364
|
+
});
|
|
1365
|
+
if (options.onJobSettled !== undefined) {
|
|
1366
|
+
await options.onJobSettled(lastSettlement);
|
|
1367
|
+
}
|
|
1368
|
+
throw teardownFailure;
|
|
1369
|
+
}
|
|
1370
|
+
if (abortState.cause === 'preempt' || preemptSignal.aborted) {
|
|
1371
|
+
hbStopped = true;
|
|
1372
|
+
clearLeaseDeadlineTimer();
|
|
1373
|
+
jobAbort.abort();
|
|
1374
|
+
await heartbeatLoop.catch(() => { });
|
|
1375
|
+
let preemptSummary;
|
|
1376
|
+
try {
|
|
1377
|
+
const preemptRes = await client.requestJson({
|
|
1378
|
+
method: 'POST',
|
|
1379
|
+
path: `/v1/runner/leases/${encodeURIComponent(grant.jobId)}:preempt`,
|
|
1380
|
+
body: {
|
|
1381
|
+
relayBootId: creds.relayBootId,
|
|
1382
|
+
leaseEpoch: creds.leaseEpoch,
|
|
1383
|
+
leaseToken: creds.leaseToken,
|
|
1384
|
+
reason: 'worker_preempted',
|
|
1385
|
+
},
|
|
1386
|
+
timeoutMs: config.requestTimeoutMs,
|
|
1387
|
+
});
|
|
1388
|
+
if (preemptRes.status === 200) {
|
|
1389
|
+
const parsedPreempt = validatePreemptResponsePayload(preemptRes.bytes, grant.job);
|
|
1390
|
+
preemptSummary = Object.freeze({
|
|
1391
|
+
jobId: grant.jobId,
|
|
1392
|
+
operationId: grant.operationId,
|
|
1393
|
+
leaseEpoch: grant.leaseEpoch,
|
|
1394
|
+
outcome: 'preempted',
|
|
1395
|
+
acknowledgment: 'confirmed',
|
|
1396
|
+
preemptionStatus: parsedPreempt.status,
|
|
1397
|
+
preemptionCount: parsedPreempt.preemptionCount,
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
else {
|
|
1401
|
+
const errCode = parseErrorCodeFromJson(preemptRes.bytes);
|
|
1402
|
+
if (preemptRes.status === 409 && errCode === 'QUEUE_LEASE_FENCED') {
|
|
1403
|
+
preemptSummary = Object.freeze({
|
|
1404
|
+
jobId: grant.jobId,
|
|
1405
|
+
operationId: grant.operationId,
|
|
1406
|
+
leaseEpoch: grant.leaseEpoch,
|
|
1407
|
+
outcome: 'fenced',
|
|
1408
|
+
acknowledgment: 'fenced',
|
|
1409
|
+
relayErrorCode: 'QUEUE_LEASE_FENCED',
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
else {
|
|
1413
|
+
preemptSummary = Object.freeze({
|
|
1414
|
+
jobId: grant.jobId,
|
|
1415
|
+
operationId: grant.operationId,
|
|
1416
|
+
leaseEpoch: grant.leaseEpoch,
|
|
1417
|
+
outcome: 'unknown',
|
|
1418
|
+
acknowledgment: 'unknown',
|
|
1419
|
+
...(errCode !== null ? { relayErrorCode: errCode } : {}),
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
catch (preemptErr) {
|
|
1425
|
+
if (!wasRequestSent(preemptErr)) {
|
|
1426
|
+
throw preemptErr;
|
|
1427
|
+
}
|
|
1428
|
+
preemptSummary = Object.freeze({
|
|
1429
|
+
jobId: grant.jobId,
|
|
1430
|
+
operationId: grant.operationId,
|
|
1431
|
+
leaseEpoch: grant.leaseEpoch,
|
|
1432
|
+
outcome: 'unknown',
|
|
1433
|
+
acknowledgment: 'unknown',
|
|
1434
|
+
...(preemptErr instanceof HardwareRunnerError ? { relayErrorCode: preemptErr.code } : {}),
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
lastSettlement = preemptSummary;
|
|
1438
|
+
if (options.onJobSettled !== undefined) {
|
|
1439
|
+
await options.onJobSettled(lastSettlement);
|
|
1440
|
+
}
|
|
1441
|
+
return { polls, jobsProcessed, lastSettlement, exitReason: 'preempted' };
|
|
1442
|
+
}
|
|
1443
|
+
// Never call :preempt on infrastructure/sandbox errors (eviction budget is strictly for real preemption!).
|
|
1444
|
+
if (evaluatorInfraError !== null) {
|
|
1445
|
+
hbStopped = true;
|
|
1446
|
+
clearLeaseDeadlineTimer();
|
|
1447
|
+
jobAbort.abort();
|
|
1448
|
+
await heartbeatLoop.catch(() => { });
|
|
1449
|
+
throw evaluatorInfraError;
|
|
1450
|
+
}
|
|
1451
|
+
// Handle local graceful shutdown (SIGINT / caller stopSignal) BEFORE checking assertAuthorityLive()
|
|
1452
|
+
// so local cancellation never masquerades as a Relay fence!
|
|
1453
|
+
if (abortState.cause === 'shutdown' || shutdownSignal.aborted) {
|
|
1454
|
+
hbStopped = true;
|
|
1455
|
+
clearLeaseDeadlineTimer();
|
|
1456
|
+
jobAbort.abort();
|
|
1457
|
+
await heartbeatLoop.catch(() => { });
|
|
1458
|
+
lastSettlement = Object.freeze({
|
|
1459
|
+
jobId: grant.jobId,
|
|
1460
|
+
operationId: grant.operationId,
|
|
1461
|
+
leaseEpoch: grant.leaseEpoch,
|
|
1462
|
+
outcome: 'cancelled',
|
|
1463
|
+
acknowledgment: 'local_only',
|
|
1464
|
+
});
|
|
1465
|
+
if (options.onJobSettled !== undefined) {
|
|
1466
|
+
await options.onJobSettled(lastSettlement);
|
|
1467
|
+
}
|
|
1468
|
+
return { polls, jobsProcessed, lastSettlement, exitReason: 'aborted' };
|
|
1469
|
+
}
|
|
1470
|
+
if (abortState.cause === 'cancel' || abortState.cause === 'fenced' || !assertAuthorityLive()) {
|
|
1471
|
+
hbStopped = true;
|
|
1472
|
+
clearLeaseDeadlineTimer();
|
|
1473
|
+
jobAbort.abort();
|
|
1474
|
+
await heartbeatLoop.catch(() => { });
|
|
1475
|
+
const isCancel = abortState.cause === 'cancel';
|
|
1476
|
+
lastSettlement = Object.freeze({
|
|
1477
|
+
jobId: grant.jobId,
|
|
1478
|
+
operationId: grant.operationId,
|
|
1479
|
+
leaseEpoch: grant.leaseEpoch,
|
|
1480
|
+
outcome: isCancel ? 'cancelled' : 'fenced',
|
|
1481
|
+
acknowledgment: isCancel ? 'local_only' : 'fenced',
|
|
1482
|
+
});
|
|
1483
|
+
if (options.onJobSettled !== undefined) {
|
|
1484
|
+
await options.onJobSettled(lastSettlement);
|
|
1485
|
+
}
|
|
1486
|
+
if (options.once === true) {
|
|
1487
|
+
return { polls, jobsProcessed, lastSettlement, exitReason: 'once_completed' };
|
|
1488
|
+
}
|
|
1489
|
+
continue;
|
|
1490
|
+
}
|
|
1491
|
+
if (evaluated === null) {
|
|
1492
|
+
hbStopped = true;
|
|
1493
|
+
clearLeaseDeadlineTimer();
|
|
1494
|
+
jobAbort.abort();
|
|
1495
|
+
await heartbeatLoop.catch(() => { });
|
|
1496
|
+
return { polls, jobsProcessed, lastSettlement, exitReason: 'aborted' };
|
|
1497
|
+
}
|
|
1498
|
+
const completeBody = {
|
|
1499
|
+
relayBootId: creds.relayBootId,
|
|
1500
|
+
leaseEpoch: creds.leaseEpoch,
|
|
1501
|
+
leaseToken: creds.leaseToken,
|
|
1502
|
+
status: evaluated.status,
|
|
1503
|
+
reason: evaluated.reason,
|
|
1504
|
+
...(evaluated.detail !== undefined ? { detail: evaluated.detail } : {}),
|
|
1505
|
+
...(evaluated.metrics !== undefined ? { metrics: evaluated.metrics } : {}),
|
|
1506
|
+
...(evaluated.findings !== undefined ? { findings: evaluated.findings } : {}),
|
|
1507
|
+
...(evaluated.hardwareProvenance !== undefined ? { hardwareProvenance: evaluated.hardwareProvenance } : {}),
|
|
1508
|
+
...(evaluated.sealedOutputs.length > 0
|
|
1509
|
+
? { outputArtifacts: evaluated.sealedOutputs.map(item => item.artifact) }
|
|
1510
|
+
: {}),
|
|
1511
|
+
};
|
|
1512
|
+
let completeRes;
|
|
1513
|
+
try {
|
|
1514
|
+
completeRes = await client.requestJson({
|
|
1515
|
+
method: 'POST',
|
|
1516
|
+
path: `/v1/runner/leases/${encodeURIComponent(grant.jobId)}:complete`,
|
|
1517
|
+
body: completeBody,
|
|
1518
|
+
timeoutMs: config.requestTimeoutMs,
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
catch (completeTransportErr) {
|
|
1522
|
+
hbStopped = true;
|
|
1523
|
+
clearLeaseDeadlineTimer();
|
|
1524
|
+
jobAbort.abort();
|
|
1525
|
+
await heartbeatLoop.catch(() => { });
|
|
1526
|
+
// Only publish 'unknown' when the HTTP request was actually dispatched over the wire!
|
|
1527
|
+
if (wasRequestSent(completeTransportErr)) {
|
|
1528
|
+
lastSettlement = Object.freeze({
|
|
1529
|
+
jobId: grant.jobId,
|
|
1530
|
+
operationId: grant.operationId,
|
|
1531
|
+
leaseEpoch: grant.leaseEpoch,
|
|
1532
|
+
outcome: 'unknown',
|
|
1533
|
+
acknowledgment: 'unknown',
|
|
1534
|
+
...(completeTransportErr instanceof HardwareRunnerError
|
|
1535
|
+
? { relayErrorCode: completeTransportErr.code }
|
|
1536
|
+
: {}),
|
|
1537
|
+
});
|
|
1538
|
+
if (options.onJobSettled !== undefined) {
|
|
1539
|
+
await options.onJobSettled(lastSettlement);
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
throw completeTransportErr;
|
|
1543
|
+
}
|
|
1544
|
+
hbStopped = true;
|
|
1545
|
+
clearLeaseDeadlineTimer();
|
|
1546
|
+
jobAbort.abort();
|
|
1547
|
+
await heartbeatLoop.catch(() => { });
|
|
1548
|
+
if (completeRes.status !== 200) {
|
|
1549
|
+
const remoteErrCode = parseErrorCodeFromJson(completeRes.bytes);
|
|
1550
|
+
if (completeRes.status === 409 && remoteErrCode === 'QUEUE_LEASE_FENCED') {
|
|
1551
|
+
lastSettlement = Object.freeze({
|
|
1552
|
+
jobId: grant.jobId,
|
|
1553
|
+
operationId: grant.operationId,
|
|
1554
|
+
leaseEpoch: grant.leaseEpoch,
|
|
1555
|
+
outcome: 'fenced',
|
|
1556
|
+
acknowledgment: 'fenced',
|
|
1557
|
+
relayErrorCode: 'QUEUE_LEASE_FENCED',
|
|
1558
|
+
});
|
|
1559
|
+
if (options.onJobSettled !== undefined) {
|
|
1560
|
+
await options.onJobSettled(lastSettlement);
|
|
1561
|
+
}
|
|
1562
|
+
if (options.once === true) {
|
|
1563
|
+
return { polls, jobsProcessed, lastSettlement, exitReason: 'once_completed' };
|
|
1564
|
+
}
|
|
1565
|
+
continue;
|
|
1566
|
+
}
|
|
1567
|
+
const mappedCompleteErr = mapHttpError(completeRes.status, completeRes.bytes, `failed to complete lease ${grant.jobId}`);
|
|
1568
|
+
if (completeRes.status >= 500 || completeRes.status === 408 || completeRes.status === 429) {
|
|
1569
|
+
lastSettlement = Object.freeze({
|
|
1570
|
+
jobId: grant.jobId,
|
|
1571
|
+
operationId: grant.operationId,
|
|
1572
|
+
leaseEpoch: grant.leaseEpoch,
|
|
1573
|
+
outcome: 'unknown',
|
|
1574
|
+
acknowledgment: 'unknown',
|
|
1575
|
+
relayErrorCode: mappedCompleteErr.code,
|
|
1576
|
+
});
|
|
1577
|
+
if (options.onJobSettled !== undefined) {
|
|
1578
|
+
await options.onJobSettled(lastSettlement);
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
throw mappedCompleteErr;
|
|
1582
|
+
}
|
|
1583
|
+
try {
|
|
1584
|
+
validateCompleteResponsePayload(completeRes.bytes, grant.operationId, evaluated.status);
|
|
1585
|
+
}
|
|
1586
|
+
catch (completeReceiptErr) {
|
|
1587
|
+
lastSettlement = Object.freeze({
|
|
1588
|
+
jobId: grant.jobId,
|
|
1589
|
+
operationId: grant.operationId,
|
|
1590
|
+
leaseEpoch: grant.leaseEpoch,
|
|
1591
|
+
outcome: 'unknown',
|
|
1592
|
+
acknowledgment: 'unknown',
|
|
1593
|
+
...(completeReceiptErr instanceof HardwareRunnerError
|
|
1594
|
+
? { relayErrorCode: completeReceiptErr.code }
|
|
1595
|
+
: {}),
|
|
1596
|
+
});
|
|
1597
|
+
if (options.onJobSettled !== undefined) {
|
|
1598
|
+
await options.onJobSettled(lastSettlement);
|
|
1599
|
+
}
|
|
1600
|
+
throw completeReceiptErr;
|
|
1601
|
+
}
|
|
1602
|
+
jobsProcessed += 1;
|
|
1603
|
+
lastSettlement = Object.freeze({
|
|
1604
|
+
jobId: grant.jobId,
|
|
1605
|
+
operationId: grant.operationId,
|
|
1606
|
+
leaseEpoch: grant.leaseEpoch,
|
|
1607
|
+
outcome: 'completed',
|
|
1608
|
+
acknowledgment: 'confirmed',
|
|
1609
|
+
status: evaluated.status,
|
|
1610
|
+
});
|
|
1611
|
+
if (options.onJobSettled !== undefined) {
|
|
1612
|
+
await options.onJobSettled(lastSettlement);
|
|
1613
|
+
}
|
|
1614
|
+
if (options.once === true) {
|
|
1615
|
+
return { polls, jobsProcessed, lastSettlement, exitReason: 'once_completed' };
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
catch (loopErr) {
|
|
1619
|
+
bodyLoopErr = loopErr;
|
|
1620
|
+
}
|
|
1621
|
+
finally {
|
|
1622
|
+
hbStopped = true;
|
|
1623
|
+
clearLeaseDeadlineTimer();
|
|
1624
|
+
watchAbort.abort();
|
|
1625
|
+
jobAbort.abort();
|
|
1626
|
+
preemptSignal.removeEventListener('abort', onJobPreempt);
|
|
1627
|
+
shutdownSignal.removeEventListener('abort', onJobShutdown);
|
|
1628
|
+
await Promise.allSettled([heartbeatLoop, sseWatchPromise]);
|
|
1629
|
+
if (evaluated !== null && !jobCleanupAttempted) {
|
|
1630
|
+
await runEvaluatedCleanupOnce(shouldPreserveSealedOutputs());
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
if (teardownFailure !== null && !isRunnerTeardownError(bodyLoopErr)) {
|
|
1634
|
+
throw teardownFailure;
|
|
1635
|
+
}
|
|
1636
|
+
if (bodyLoopErr !== null) {
|
|
1637
|
+
throw bodyLoopErr;
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
finally {
|
|
1642
|
+
if (options.registerProcessSignalHandlers !== false) {
|
|
1643
|
+
process.removeListener('SIGTERM', onSigTerm);
|
|
1644
|
+
process.removeListener('SIGINT', onSigInt);
|
|
1645
|
+
}
|
|
1646
|
+
client.close();
|
|
1647
|
+
}
|
|
1648
|
+
}
|