@sema-agent/server 7.130.0 → 7.132.0
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/MIGRATION.md +396 -0
- package/README.md +13 -6
- package/README.zh-CN.md +9 -5
- package/USAGE.md +187 -50
- package/dist/approval-card.d.ts +3 -1
- package/dist/approval-card.js +2 -3
- package/dist/audit.d.ts +7 -10
- package/dist/audit.js +4 -1
- package/dist/auth-bridge.d.ts +4 -0
- package/dist/auth-bridge.js +10 -11
- package/dist/bench/s1/live-deps.js +2 -0
- package/dist/boot/deployment-mods.d.ts +31 -0
- package/dist/boot/deployment-mods.js +26 -0
- package/dist/boot/execution-env.d.ts +1 -1
- package/dist/boot/execution-env.js +19 -6
- package/dist/boot/memory-boundary.d.ts +2 -2
- package/dist/boot/read-deny-anchor-audit.d.ts +17 -0
- package/dist/boot/read-deny-anchor-audit.js +36 -0
- package/dist/boot/resolve-spec.d.ts +1 -5
- package/dist/boot/resolve-spec.js +56 -61
- package/dist/boot/runner-deps.d.ts +19 -8
- package/dist/boot/runner-deps.js +14 -2
- package/dist/boot/session-faces.d.ts +1 -7
- package/dist/boot/stage-02-web-admin-pull.js +9 -1
- package/dist/boot/stage-03-store-backend.d.ts +1 -1
- package/dist/boot/stage-03-store-backend.js +2 -2
- package/dist/boot/stage-04-stores.d.ts +1 -1
- package/dist/boot/stage-05-execution-env.d.ts +4 -4
- package/dist/boot/stage-05-execution-env.js +7 -10
- package/dist/boot/stage-06-runners.d.ts +2 -2
- package/dist/boot/stage-06-runners.js +5 -4
- package/dist/boot/stage-07-capability-layer.d.ts +2 -2
- package/dist/boot/stage-07-capability-layer.js +3 -3
- package/dist/boot/stage-08-reapers.d.ts +2 -2
- package/dist/boot/stage-09-leader.d.ts +3 -9
- package/dist/boot/stage-10-http-server.d.ts +3 -9
- package/dist/boot/stage-10-http-server.js +12 -10
- package/dist/boot/stores.d.ts +1 -1
- package/dist/boot/stores.js +5 -6
- package/dist/boot/web-admin.d.ts +0 -3
- package/dist/boot/web-admin.js +35 -35
- package/dist/brain.js +17 -22
- package/dist/budget.js +5 -4
- package/dist/caller-text-echo.d.ts +20 -0
- package/dist/caller-text-echo.js +24 -0
- package/dist/capabilities/brand-identity.d.ts +26 -0
- package/dist/capabilities/brand-identity.js +27 -0
- package/dist/capabilities/builtin-tools.js +2 -1
- package/dist/capabilities/center-plugins.js +1 -1
- package/dist/capabilities/center-prompts.d.ts +32 -59
- package/dist/capabilities/center-prompts.js +18 -32
- package/dist/capabilities/composite-members.d.ts +1 -0
- package/dist/capabilities/composite-members.js +1 -0
- package/dist/capabilities/engine-capabilities.js +2 -1
- package/dist/capabilities/hands-lane.d.ts +9 -6
- package/dist/capabilities/hands-lane.js +3 -3
- package/dist/capabilities/host-tool-names.d.ts +17 -0
- package/dist/capabilities/host-tool-names.js +15 -0
- package/dist/capabilities/mcp-probe.d.ts +14 -1
- package/dist/capabilities/mcp-probe.js +22 -133
- package/dist/capabilities/repo-tools.js +4 -3
- package/dist/capabilities/scenarios.d.ts +42 -47
- package/dist/capabilities/scenarios.js +19 -35
- package/dist/capabilities/select-environment-tool.js +2 -1
- package/dist/capabilities/send-user-file-tool.d.ts +0 -1
- package/dist/capabilities/send-user-file-tool.js +2 -2
- package/dist/capabilities/skills.d.ts +19 -4
- package/dist/capabilities/skills.js +30 -10
- package/dist/capabilities/tool-defer.js +2 -1
- package/dist/config-catalog.js +22 -11
- package/dist/config-invariants.js +2 -2
- package/dist/config-lkg.d.ts +9 -9
- package/dist/config-lkg.js +20 -4
- package/dist/config-provider.d.ts +3 -1
- package/dist/config-provider.js +14 -6
- package/dist/config-types.d.ts +13 -9
- package/dist/config.d.ts +2 -2
- package/dist/config.js +34 -20
- package/dist/device-ws-protocol.d.ts +1 -1
- package/dist/device-ws-protocol.js +1 -0
- package/dist/elicitation.d.ts +7 -0
- package/dist/elicitation.js +20 -5
- package/dist/env-name-allowlist-knobs.d.ts +12 -2
- package/dist/env-name-allowlist-knobs.js +5 -4
- package/dist/exec-bounds.d.ts +15 -3
- package/dist/exec-bounds.js +4 -0
- package/dist/execution-lane-caps.d.ts +9 -2
- package/dist/execution-lane-caps.js +11 -0
- package/dist/hooks/classic-stations.d.ts +86 -0
- package/dist/hooks/classic-stations.js +27 -0
- package/dist/hooks/hook-llm.d.ts +8 -5
- package/dist/hooks/hook-llm.js +80 -37
- package/dist/hooks/hook-runner.d.ts +273 -75
- package/dist/hooks/hook-runner.js +293 -317
- package/dist/http/admission.d.ts +8 -2
- package/dist/http/admission.js +103 -59
- package/dist/http/approval-sweeps.js +59 -18
- package/dist/http/checkpoint-ctx.d.ts +36 -18
- package/dist/http/checkpoint-ctx.js +14 -10
- package/dist/http/claimed-run.d.ts +13 -0
- package/dist/http/claimed-run.js +15 -0
- package/dist/http/device-placement.js +5 -10
- package/dist/http/dispatch.d.ts +0 -4
- package/dist/http/dispatch.js +6 -10
- package/dist/http/durable-run-leg.d.ts +2 -1
- package/dist/http/durable-run-leg.js +5 -3
- package/dist/http/health-self-report.d.ts +7 -5
- package/dist/http/health-self-report.js +4 -18
- package/dist/http/principal-gate.d.ts +23 -6
- package/dist/http/principal-gate.js +24 -5
- package/dist/http/refusal-body.d.ts +21 -0
- package/dist/http/refusal-body.js +4 -0
- package/dist/http/request-guards.d.ts +27 -0
- package/dist/http/request-guards.js +24 -3
- package/dist/http/resume-legs.d.ts +25 -0
- package/dist/http/resume-legs.js +48 -26
- package/dist/http/routes/approvals-assistant.js +1 -1
- package/dist/http/routes/capabilities.js +7 -17
- package/dist/http/routes/diagnostics.js +1 -1
- package/dist/http/routes/rules.js +2 -2
- package/dist/http/routes/runs.js +13 -17
- package/dist/http/routes/session-sync.js +4 -2
- package/dist/http/routes/sessions.js +23 -11
- package/dist/http/routes/shared-memory.js +2 -13
- package/dist/http/routes/side-query.js +2 -3
- package/dist/http/routes/tasks.js +34 -19
- package/dist/http/scenario-read-face.d.ts +14 -0
- package/dist/http/scenario-read-face.js +5 -0
- package/dist/http/send.d.ts +13 -1
- package/dist/http/send.js +12 -1
- package/dist/http/server.d.ts +37 -23
- package/dist/http/server.js +30 -4
- package/dist/http/stored-body-replay.d.ts +10 -3
- package/dist/http/stored-body-replay.js +27 -6
- package/dist/http/submit-ctx.d.ts +25 -0
- package/dist/http/submit-ctx.js +39 -0
- package/dist/http/wire-types.d.ts +18 -5
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/lane-home-probe.d.ts +43 -0
- package/dist/lane-home-probe.js +35 -0
- package/dist/limit-refusal.d.ts +47 -0
- package/dist/limit-refusal.js +12 -0
- package/dist/main.js +1 -1
- package/dist/mcp-assertion-header.d.ts +3 -11
- package/dist/mcp-assertion-header.js +3 -9
- package/dist/mcp-tool-faces.d.ts +5 -0
- package/dist/mcp-tool-faces.js +5 -1
- package/dist/memory-scope.d.ts +1 -1
- package/dist/model-entry-refusal.d.ts +1 -7
- package/dist/model-provider.d.ts +39 -12
- package/dist/model-provider.js +19 -2
- package/dist/model-route-endpoint.d.ts +52 -12
- package/dist/model-route-endpoint.js +48 -26
- package/dist/model-route-gap.d.ts +5 -4
- package/dist/model-route-gap.js +1 -1
- package/dist/model-select.d.ts +58 -0
- package/dist/model-select.js +31 -0
- package/dist/namespaced-rule-name.d.ts +7 -4
- package/dist/namespaced-rule-name.js +4 -3
- package/dist/observability/cost-taxonomy.d.ts +7 -7
- package/dist/observability/fail-open.d.ts +53 -12
- package/dist/observability/fail-open.js +47 -7
- package/dist/observability/metrics.js +3 -1
- package/dist/observability/prompt-manifest.d.ts +47 -82
- package/dist/observability/prompt-manifest.js +119 -17
- package/dist/observability/run-terminal.js +14 -6
- package/dist/observability/secret-env-scrub.d.ts +13 -1
- package/dist/observability/secret-env-scrub.js +13 -1
- package/dist/observability/tool-trace.d.ts +16 -21
- package/dist/observability/tool-trace.js +51 -42
- package/dist/per-task-image.d.ts +7 -1
- package/dist/per-task-image.js +3 -3
- package/dist/plain-string-record.d.ts +25 -0
- package/dist/plain-string-record.js +32 -0
- package/dist/plugins/blob-backend.d.ts +68 -13
- package/dist/plugins/blob-backend.js +53 -10
- package/dist/plugins/checkpoint-store-sql.d.ts +14 -4
- package/dist/plugins/checkpoint-store-sql.js +39 -26
- package/dist/plugins/k8s-bg-scripts.d.ts +11 -0
- package/dist/plugins/k8s-bg-scripts.js +22 -0
- package/dist/plugins/local-checkpoint-store.js +5 -2
- package/dist/plugins/local-session-store.js +3 -3
- package/dist/plugins/one-time-migrations.d.ts +147 -91
- package/dist/plugins/one-time-migrations.js +372 -208
- package/dist/plugins/permission-rule-store-sql.d.ts +13 -7
- package/dist/plugins/permission-rule-store-sql.js +4 -18
- package/dist/plugins/pg-session-storage.d.ts +4 -5
- package/dist/plugins/pg-session-storage.js +7 -17
- package/dist/plugins/remote-env-adb.d.ts +6 -0
- package/dist/plugins/remote-env-adb.js +9 -4
- package/dist/plugins/remote-env-device.js +3 -0
- package/dist/plugins/remote-env-e2b.d.ts +1 -1
- package/dist/plugins/remote-env-e2b.js +21 -9
- package/dist/plugins/remote-env-host.d.ts +9 -9
- package/dist/plugins/remote-env-host.js +10 -32
- package/dist/plugins/remote-env-k8s.d.ts +95 -26
- package/dist/plugins/remote-env-k8s.js +265 -90
- package/dist/plugins/remote-env-local-docker.d.ts +20 -1
- package/dist/plugins/remote-env-local-docker.js +77 -9
- package/dist/plugins/remote-env-ssh.d.ts +15 -0
- package/dist/plugins/remote-env-ssh.js +109 -3
- package/dist/plugins/remote-shell.d.ts +0 -1
- package/dist/plugins/remote-shell.js +1 -2
- package/dist/plugins/retention-store-sql.js +6 -2
- package/dist/plugins/schema-consistency.d.ts +54 -0
- package/dist/plugins/schema-consistency.js +52 -0
- package/dist/plugins/session-epoch-anchor.d.ts +13 -0
- package/dist/plugins/session-epoch-anchor.js +23 -0
- package/dist/plugins/shared-memory-store-sql.d.ts +9 -3
- package/dist/plugins/shared-memory-store-sql.js +5 -16
- package/dist/plugins/sql-driver.d.ts +141 -0
- package/dist/plugins/sql-driver.js +115 -1
- package/dist/plugins/sql-errors.d.ts +41 -0
- package/dist/plugins/sql-errors.js +36 -0
- package/dist/plugins/store-backend.js +2 -1
- package/dist/plugins/tidb-session-storage.d.ts +7 -11
- package/dist/plugins/tidb-session-storage.js +6 -16
- package/dist/plugins/tidb-session-store.js +1 -1
- package/dist/prompts-domain-validate.d.ts +17 -61
- package/dist/prompts-domain-validate.js +9 -119
- package/dist/question.d.ts +18 -9
- package/dist/question.js +21 -13
- package/dist/request-key-closure.d.ts +4 -4
- package/dist/request-key-closure.js +18 -13
- package/dist/rule-entry-list.d.ts +134 -24
- package/dist/rule-entry-list.js +162 -30
- package/dist/run-local.d.ts +3 -3
- package/dist/run-local.js +26 -25
- package/dist/runs.d.ts +48 -2
- package/dist/runs.js +61 -2
- package/dist/server-secret-env.d.ts +44 -18
- package/dist/server-secret-env.js +49 -8
- package/dist/session-incarnation.d.ts +15 -5
- package/dist/session-incarnation.js +16 -9
- package/dist/session-titler.js +12 -2
- package/dist/spec-fields.d.ts +34 -18
- package/dist/spec-fields.js +46 -53
- package/dist/sql-engine-posture.d.ts +29 -4
- package/dist/sql-engine-posture.js +36 -1
- package/dist/stored-request-hooks-m20.d.ts +23 -0
- package/dist/stored-request-hooks-m20.js +124 -0
- package/dist/stored-request-tool-axes-m19.d.ts +20 -5
- package/dist/stored-request-tool-axes-m19.js +30 -2
- package/dist/task-a2a.d.ts +9 -1
- package/dist/task-a2a.js +73 -47
- package/dist/task-mcp.d.ts +54 -102
- package/dist/task-mcp.js +194 -92
- package/dist/task-settings.d.ts +47 -25
- package/dist/task-settings.js +46 -61
- package/dist/text-bidi.d.ts +3 -46
- package/dist/text-bidi.js +3 -3
- package/dist/tool-approval.d.ts +1 -1
- package/dist/trace/core-keyset-guard.d.ts +24 -4
- package/dist/trace/engine-notice-wire.d.ts +11 -3
- package/dist/trace/engine-notice-wire.js +8 -1
- package/dist/trace/ledger-events.d.ts +3 -1
- package/dist/trace/ledger-sink.d.ts +29 -0
- package/dist/trace/ledger-sink.js +15 -1
- package/dist/trace/model-segment.js +1 -1
- package/dist/trace/project.d.ts +25 -6
- package/dist/trace/project.js +68 -22
- package/dist/trace/wire-projection-faces.d.ts +80 -2
- package/dist/trace/wire-projection-faces.js +23 -1
- package/dist/user-authored-text.d.ts +7 -0
- package/dist/user-authored-text.js +3 -0
- package/dist/web-admin-client/apply-effective.js +10 -5
- package/dist/web-admin-client/candidate-gate.d.ts +6 -6
- package/dist/web-admin-client/candidate-gate.js +3 -3
- package/dist/web-admin-client/http-client.js +0 -6
- package/dist/web-admin-client/read-warnings.d.ts +13 -0
- package/dist/web-admin-client/read-warnings.js +10 -0
- package/dist/web-admin-client/skills-mcp.d.ts +3 -0
- package/dist/web-admin-client/skills-mcp.js +9 -6
- package/dist/web-admin-client/types.d.ts +3 -4
- package/dist/workspace-cache.d.ts +35 -0
- package/dist/workspace-cache.js +36 -0
- package/dist/workspace-space.d.ts +3 -2
- package/dist/workspace-space.js +2 -0
- package/docs/DEVICE-EXECUTOR-PROTOCOL.md +8 -1
- package/package.json +4 -4
- package/scripts/drain-check-local.mjs +37 -3
- package/scripts/drain-check.mysql.sql +30 -2
- package/scripts/drain-check.pg.sql +29 -2
- package/dist/capabilities/memory-notice.d.ts +0 -138
- package/dist/capabilities/memory-notice.js +0 -64
- package/dist/capabilities/prompt.d.ts +0 -17
- package/dist/capabilities/prompt.js +0 -6
- package/dist/mcp-content-origin.d.ts +0 -34
- package/dist/mcp-content-origin.js +0 -10
- package/dist/tool-axis-words.d.ts +0 -27
- package/dist/tool-axis-words.js +0 -9
- package/dist/wire-name-bound.d.ts +0 -14
- package/dist/wire-name-bound.js +0 -13
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type SpaceReclaimer, type WorkspaceSpacePolicy, type CacheReclaimReason } from "../workspace-space.js";
|
|
2
2
|
import { type SpaceCommitFence } from "../workspace-space-commit.js";
|
|
3
|
-
import { type WorkspaceCacheCapability } from "../workspace-cache.js";
|
|
3
|
+
import { type CacheMissMemory, type WorkspaceCacheCapability } from "../workspace-cache.js";
|
|
4
4
|
import { type SandboxEgressGap, type SandboxIpv6 } from "../sandbox-egress-policy.js";
|
|
5
5
|
import { FileError, ExecutionError, RemoteExecutionError, type ExecutionEnv, type RemoteExecutionEnv, type WorkspaceHandle, type FileInfo, type Result, type SymlinkChain, type OutputChunk, type ExecStreamOptions, type RemoteConnectConfig, type SnapshotId, type SessionToken, type VmLifecycleOptions, type ExecutionEnvFactory, type BackgroundShellCapability, type BackgroundShellId, type BackgroundShellError, type BackgroundSpawnOptions, type BackgroundPoll } from "@sema-agent/core";
|
|
6
6
|
import type { PodSpecPatch } from "./k8s-exec-protocol.js";
|
|
7
7
|
type ExecOpts = Parameters<ExecutionEnv["exec"]>[1];
|
|
8
|
-
export { buildBgRunnerScript, buildBgLauncherScript, buildBgPollScript, buildBgKillScript, buildBgDisposeScript, buildDetachCapableExec, parseBgPollOutput, type ParsedBgPoll, } from "./k8s-bg-scripts.js";
|
|
8
|
+
export { buildBgRunnerScript, buildBgLauncherScript, buildBgPollScript, buildBgKillScript, buildBgDisposeScript, buildDetachCapableExec, buildKillAllScript, parseBgPollOutput, type ParsedBgPoll, } from "./k8s-bg-scripts.js";
|
|
9
9
|
export interface K8sEnvConfig {
|
|
10
10
|
/** API server URL. Default: in-cluster (`https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT`). */
|
|
11
11
|
apiUrl?: string;
|
|
@@ -112,6 +112,10 @@ export interface K8sEnvConfig {
|
|
|
112
112
|
* ({@link SpaceOccupant}). Absent ⇒ no claim request, the pod as before.
|
|
113
113
|
*/
|
|
114
114
|
cache?: WorkspaceCacheCapability;
|
|
115
|
+
/** The deployment's memory of cache volumes that could not be had ({@link CacheMissMemory}; the per-run binding hands every run's env the same one, only with `cache`):
|
|
116
|
+
* a space whose volume did not bind / did not mount is not asked for again for one data bound (`dataTimeoutMs` — the wait a run was willing to give it; no knob of its own).
|
|
117
|
+
* Absent (a direct construction) ⇒ no memory: every env asks for itself. */
|
|
118
|
+
cacheMisses?: CacheMissMemory;
|
|
115
119
|
/** Operator log seat (the e2b adapter's shape): `workspace_snapshot_failed` / `workspace_snapshot_prune_failed` /
|
|
116
120
|
* `workspace_space_unavailable` / `workspace_space_unreadable_occupant` / `workspace_commit_abandoned` / `workspace_latest_dangling` /
|
|
117
121
|
* `workspace_restore_failed` / `workspace_cache_fresh` / `workspace_cache_unavailable`. */
|
|
@@ -183,8 +187,8 @@ export interface K8sEnvDeps {
|
|
|
183
187
|
* - absent: `unread: "incarnation_unknown"` — there is NO space for this run: the store answered that it has no such session
|
|
184
188
|
* (deleted / never registered), or this replica holds no commit fence to key one by (see `occupantOf`) ⇒ a lane keyed by it
|
|
185
189
|
* does not open (no restore, no save, no volume) and says so in one line;
|
|
186
|
-
* - faulted: `fault` — the read did not answer (it threw,
|
|
187
|
-
* error (never its text), `incarnation_read_failed` without one. A space we could not read is not "no space" ⇒ a lane keyed by
|
|
190
|
+
* - faulted: `fault` — the read did not answer (it threw, did not come within the lane's store wall `rpcTimeoutMs` — `incarnation_read_timeout`,
|
|
191
|
+
* or answered something that is not a token): the code of the store's error (never its text), `incarnation_read_failed` without one. A space we could not read is not "no space" ⇒ a lane keyed by
|
|
188
192
|
* it refuses this env (`RemoteK8sExecutionEnv.provision`, the one pod seat): the run never starts on a workspace it believes is its own.
|
|
189
193
|
* Never a fallback to the session id.
|
|
190
194
|
*/
|
|
@@ -210,6 +214,22 @@ export interface CacheReclaimFailure {
|
|
|
210
214
|
readonly reason: Exclude<CacheReclaimReason, "occupant_unreadable">;
|
|
211
215
|
readonly detail: string;
|
|
212
216
|
}
|
|
217
|
+
/** The control-plane wall of an env built from `config` (`rpcTimeoutMs`) — the one reading: the env's own requests, the commit-fence calls and the
|
|
218
|
+
* boot binding's occupant read all run under THIS number (the session store's by-id read is one more store call of the same connect). */
|
|
219
|
+
export declare function rpcTimeoutMsOf(config: K8sEnvConfig): number;
|
|
220
|
+
/**
|
|
221
|
+
* One call to a store this adapter does not own — the run store's commit-fence rows ({@link RemoteK8sExecutionEnv.fenceCall}), the session store's
|
|
222
|
+
* by-id occupant read (`boot/execution-env.ts`) — under a wall-clock bound, and, when given, the caller's abort. A store that never answers never
|
|
223
|
+
* hangs the caller: the bound rejects with `onTimeout()`, the abort with `abort.error()`. The call itself is not cancellable — a late answer is dropped.
|
|
224
|
+
*/
|
|
225
|
+
export declare function boundedStoreCall<T>(op: () => Promise<T>, bound: {
|
|
226
|
+
readonly ms: number;
|
|
227
|
+
readonly onTimeout: () => Error;
|
|
228
|
+
readonly abort?: {
|
|
229
|
+
readonly signal: AbortSignal;
|
|
230
|
+
readonly error: () => Error;
|
|
231
|
+
};
|
|
232
|
+
}): Promise<T>;
|
|
213
233
|
export { execSocketTlsOptions } from "./k8s-exec-protocol.js";
|
|
214
234
|
/** `Error`-or-event → message. Bun's ws shim emits browser-style ErrorEvents (NOT instanceof Error) whose
|
|
215
235
|
* String() is "[object ErrorEvent]" — that masked the real TLS failure for a whole drill. */
|
|
@@ -241,14 +261,20 @@ export declare class RemoteK8sExecutionEnv implements RemoteExecutionEnv, Backgr
|
|
|
241
261
|
private destroyed;
|
|
242
262
|
/** Set after a successful resumeVM so workspaceHandle() carries the snapshot it was restored from. */
|
|
243
263
|
private handleSnapshotId?;
|
|
244
|
-
/**
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
private
|
|
248
|
-
/**
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
264
|
+
/** The foreground commands in flight (`exec` / `execStream`), each by the abort controller its runExec listens to — ONE record: `suspendVM` refuses while any
|
|
265
|
+
* runs (council #4 suspend×in-flight); `destroy` waits for them to end before the run-end snapshot and, past its wait, aborts them
|
|
266
|
+
* ({@link quiesce}). Every entry is removed by {@link endExec}, whichever way its command ended. */
|
|
267
|
+
private readonly inFlight;
|
|
268
|
+
/** Resolvers of {@link whenIdle}: woken when the last command in flight ends. */
|
|
269
|
+
private idleWaiters;
|
|
270
|
+
/** This env's one connect in flight (see {@link connect}): the explicit connect, the lazy connect and `reconnect` that arrive while it runs
|
|
271
|
+
* share it — one pod creation, one restore (the E2B race lesson). Cleared the moment it settles, whatever the outcome. */
|
|
272
|
+
private connectInFlight?;
|
|
273
|
+
/** The env's refusal — a fact of this env until `destroy`, written once ({@link holdRefusal}) and answered as it stands to every later connect (and to
|
|
274
|
+
* every later pod creation: {@link provision}): the same refusal, zero pods, zero store requests, no second line. Two causes write it:
|
|
275
|
+
* the space restore (`latest` names an archive that is there and did not come back — {@link restoreSnapshot}) and the pod's admission (the cluster created
|
|
276
|
+
* the pod and it ended `Failed` before it ran — {@link createPod}). Neither goes away by asking again: the same request answers the same. */
|
|
277
|
+
private connectRefusal?;
|
|
252
278
|
/** core `ExecutionEnv.homeDir`([ref]):本沙箱/目标机上执行用户的 home。见配置同名字段。 */
|
|
253
279
|
readonly homeDir?: string | undefined;
|
|
254
280
|
/** core 7.49.0 #1554:shell 子进程真拿到的 `CDPATH` 条目 —— 本车道的命令跑在 pod 里(镜像与 pod spec 的 env),本类不读那份 env ⇒ `"unknown"`(core 契约:说不出就说 unknown,
|
|
@@ -273,6 +299,7 @@ export declare class RemoteK8sExecutionEnv implements RemoteExecutionEnv, Backgr
|
|
|
273
299
|
private cacheUnavailableSaid;
|
|
274
300
|
private readonly logger?;
|
|
275
301
|
private readonly onWorkspaceSnapshot?;
|
|
302
|
+
private readonly cacheMisses?;
|
|
276
303
|
constructor(config: K8sEnvConfig, deps?: K8sEnvDeps);
|
|
277
304
|
/** 166-T2 — ExecutionEnv 寿命声明:pod `activeDeadlineSeconds = ceil(timeoutMs/1000)` 是平台真硬死线
|
|
278
305
|
* (k8s 到点杀 pod,无 keepalive 续期机制)⇒ 恒声明,core 在死线−60s 处 suspend(基建合格)或响亮
|
|
@@ -296,10 +323,16 @@ export declare class RemoteK8sExecutionEnv implements RemoteExecutionEnv, Backgr
|
|
|
296
323
|
* Persistence off / no store ⇒ a fresh pod, exactly as before. Persistence on but no such session (the occupant absent) ⇒ a
|
|
297
324
|
* fresh pod and one `workspace_space_unavailable` line (no restore by any other key). The occupant read FAULTED ⇒ the same
|
|
298
325
|
* loud `connect_failed` as a failed `latest` read, no pod ({@link provision} refuses it — every entry that would create one).
|
|
299
|
-
* One
|
|
300
|
-
*
|
|
326
|
+
* One connect in flight per env: a connect that arrives while another is running — the explicit one, the lazy one of the first operation,
|
|
327
|
+
* `reconnect` — gets THAT connect's answer (one pod creation, one restore, one refusal line), not a walk of its own; the share is for a connect in flight
|
|
328
|
+
* only (a connect that failed is not remembered by it — how long a failure stands is {@link connectRefusal}'s). The abort signal of the connect that
|
|
329
|
+
* started is the one in force.
|
|
330
|
+
* One refusal per env: a refusal this env holds ({@link connectRefusal} — a restore that did not come back, a pod the cluster refused at admission) is answered
|
|
331
|
+
* as it stands to every later connect on every lane — the previous commit is not waited on again, `latest` is not read again, no pod is created.
|
|
301
332
|
*/
|
|
302
333
|
connect(config?: RemoteConnectConfig): Promise<ConnectResult>;
|
|
334
|
+
/** The one walk of a connect ({@link connect} runs it once at a time). */
|
|
335
|
+
private establish;
|
|
303
336
|
/** This env holds a workspace its `destroy()` will commit ⇒ arm its seat on the space's commit fence (from here the
|
|
304
337
|
* run's terminal write fences the space; `workspace-space-commit.ts`). Each write of this run's row sets its deadline to
|
|
305
338
|
* now + the upload's own wall-clock bound (`dataTimeoutMs`). No-op unless the space lane is open. */
|
|
@@ -318,6 +351,16 @@ export declare class RemoteK8sExecutionEnv implements RemoteExecutionEnv, Backgr
|
|
|
318
351
|
/** The space lane is on but this run's session has no occupant (no such session — {@link SpaceOccupant}) — said once per env
|
|
319
352
|
* (at connect, or at a destroy with a pod). `reason` = the reading's word. */
|
|
320
353
|
private sayUnavailable;
|
|
354
|
+
/** Hold `error` as this env's refusal ({@link connectRefusal}) and answer it — the ONE writer of the slot (the restore and the pod's admission both write through it). */
|
|
355
|
+
private holdRefusal;
|
|
356
|
+
/**
|
|
357
|
+
* The cluster created this env's pod and it ended `Failed` (or `Succeeded`) before it ever ran — the kubelet refused it at admission
|
|
358
|
+
* (`SysctlForbidden` when `K8S_SANDBOX_IPV6=disabled` meets a kubelet that does not allow the two sysctls, a node-affinity miss, no capacity on the
|
|
359
|
+
* node …): the env's refusal ({@link holdRefusal}), in the one `connect_failed` form with the kubelet's reason in the sentence — so the operation that meets
|
|
360
|
+
* it, and every later one, says what the cluster said, instead of a new pod per operation. One `sandbox_pod_refused{pod, phase, reason, detail}` line per env
|
|
361
|
+
* (`detail` = the kubelet's own text, cut). A retry of the run builds a fresh env, which asks the cluster afresh.
|
|
362
|
+
*/
|
|
363
|
+
private refusePod;
|
|
321
364
|
/**
|
|
322
365
|
* A lane that is on is keyed by an occupant read that FAULTED (`unreadable`) ⇒ this env creates no pod: the refusal, in the one
|
|
323
366
|
* space-read failure form ({@link spaceReadFailed} — a failed `latest` / commit-row read says the same), naming the knob of every
|
|
@@ -335,16 +378,17 @@ export declare class RemoteK8sExecutionEnv implements RemoteExecutionEnv, Backgr
|
|
|
335
378
|
/**
|
|
336
379
|
* Lazy-connect on first use — 🔴 core NEVER calls `connect()` (verified: the Runner only calls `resumeVM` on
|
|
337
380
|
* the resume path), so an adapter that demands an explicit connect can never work through the production
|
|
338
|
-
* hand-tool path (lazy-connect belongs in the adapter).
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
381
|
+
* hand-tool path (lazy-connect belongs in the adapter). `destroyed` is terminal. Concurrent first ops share ONE pod create — through
|
|
382
|
+
* {@link connect}'s one connect in flight, the same seat the explicit connect shares. How long a failure stands is {@link connect}'s: a failure of that
|
|
383
|
+
* attempt (a pod that could not be created, a space read that failed) ⇒ the next op connects afresh; the env's refusal ({@link connectRefusal}) ⇒ the
|
|
384
|
+
* next op's connect answers that same refusal at once.
|
|
342
385
|
*/
|
|
343
386
|
private ensureConnected;
|
|
344
387
|
/**
|
|
345
388
|
* One pod creation attempt. With the cache volume open: first the space's claim ({@link attachCache} — found, or created),
|
|
346
389
|
* then the pod carrying it; a pod that only waits on a claim that does not bind within the data bound is deleted and ONE pod
|
|
347
|
-
* without the volume is created in its place (the run starts; the miss is counted
|
|
390
|
+
* without the volume is created in its place (the run starts; the miss is counted and remembered for the space — {@link K8sEnvConfig.cacheMisses}:
|
|
391
|
+
* the next runs inside one data bound go without it at once). Every other failure is the attempt's.
|
|
348
392
|
*/
|
|
349
393
|
private connectOnce;
|
|
350
394
|
/** The cache volume for this pod creation, or `undefined` (off, or not to be had — counted and said there). */
|
|
@@ -505,7 +549,7 @@ export declare class RemoteK8sExecutionEnv implements RemoteExecutionEnv, Backgr
|
|
|
505
549
|
* - space: the archive `latest` names is THERE and did not come back ({@link RestoreFailureClass}): the run is refused all the
|
|
506
550
|
* same — never an empty workspace (the user's changes are still in the bucket) — with exactly one `workspace_restore_failed`
|
|
507
551
|
* line (its `attempts`; an attempt that failed before one that succeeded is no line) and a refusal naming the two ways out,
|
|
508
|
-
* held for the env ({@link
|
|
552
|
+
* held for the env ({@link connectRefusal}).
|
|
509
553
|
* A pod that could not be created is that attempt's failure, not the archive's: returned as it is — no line, nothing held, the
|
|
510
554
|
* next connect tries again. An abort during the pause ends the restore `aborted` (not the archive's either).
|
|
511
555
|
*/
|
|
@@ -536,16 +580,38 @@ export declare class RemoteK8sExecutionEnv implements RemoteExecutionEnv, Backgr
|
|
|
536
580
|
private deletePod;
|
|
537
581
|
/**
|
|
538
582
|
* Delete the sandbox pod. Idempotent, never throws. Space lane open and a pod exists ⇒ FIRST the run-end space
|
|
539
|
-
* snapshot ({@link persistWorkspace})
|
|
583
|
+
* snapshot ({@link persistWorkspace}) — after the pod's processes are confirmed stopped, the commands still in flight having ended or been cut first ({@link quiesce}); from the
|
|
584
|
+
* moment destroy begins no new command is admitted. Its failure is loud and never blocks the delete (the pod lifetime is the
|
|
540
585
|
* leak guard). A run that never connected has no workspace to save — `latest` stays where it was. Space lane
|
|
541
586
|
* unavailable (no such session) ⇒ nothing is saved (the once-per-env line says so); unreadable ⇒ there is no pod
|
|
542
587
|
* ({@link provision} refused every creation).
|
|
543
588
|
*/
|
|
544
589
|
destroy(): Promise<void>;
|
|
545
590
|
cleanup(): Promise<void>;
|
|
591
|
+
/** A foreground command begins: register its abort controller (the one `runExec` listens to through the caller's signal composed with it). */
|
|
592
|
+
private beginExec;
|
|
593
|
+
/** A foreground command ended, however it ended: unregister it; the last one out wakes {@link whenIdle}. */
|
|
594
|
+
private endExec;
|
|
595
|
+
/** Resolves `true` once no command is in flight (at once when none is), `false` when `ms` passed first. */
|
|
596
|
+
private whenIdle;
|
|
597
|
+
/**
|
|
598
|
+
* The run is over and its workspace is about to be saved: the tar reads the tree only AFTER the pod's processes are CONFIRMED stopped
|
|
599
|
+
* ({@link killPodProcesses}: the script exits 0 only when nothing it should have killed is alive) — whether or not a command is in flight at this
|
|
600
|
+
* moment. The in-flight registry is not evidence of a quiet pod: a command ends however it ends (its own exit, a cancel, a wall) and drops out of
|
|
601
|
+
* the registry, yet ending a command does not end what it started (closing the exec socket does not stop the process). So the one exit without a
|
|
602
|
+
* stop is "no command and no pod" — nothing runs and there is no tree to read. Commands still in flight are first given one control-plane wall
|
|
603
|
+
* (`rpcTimeoutMs`) to end — a cancelled or timed-out run's commands were told to stop and end within moments, so the wait is normally short, and
|
|
604
|
+
* there is nothing to wait for when none is in flight. A wait that ran out also aborts the exec sockets still open and says one
|
|
605
|
+
* `workspace_snapshot_commands_cut{inFlight, waitedMs, killed}` line. Processes that could not be confirmed stopped ⇒ refused (`command_in_flight`, as a
|
|
606
|
+
* suspend is): a workspace that may still be changing is never saved as `latest`. Answers how long it took (the commit's data bound pays for it).
|
|
607
|
+
*/
|
|
608
|
+
private quiesce;
|
|
609
|
+
/** Kill every live process of the pod but its init, its keeper and the killing shell, and confirm they are gone ({@link buildKillAllScript} exits 0 only then); `false` = not confirmed (the exec is bounded by `rpcTimeoutMs` plus the script's own bounded re-checks; `runExec` answers a Result and does not reject). */
|
|
610
|
+
private killPodProcesses;
|
|
546
611
|
/**
|
|
547
612
|
* Run-end space snapshot, under the space's commit fence (the run store's row, `workspace-space-commit.ts`): the fence
|
|
548
|
-
* first (this run's row moves to its upload state; lost ⇒ no upload, loud) → the
|
|
613
|
+
* first (this run's row moves to its upload state; lost ⇒ no upload, loud) → the pod's processes are stopped and confirmed, the commands still in flight
|
|
614
|
+
* first ended or cut ({@link quiesce}; the wait is part of the commit's one data bound) → the one tar upload ({@link uploadSnapshot},
|
|
549
615
|
* lane `space` — it also releases the pod) → the fence again (this run's row moves to its publishing state; lost ⇒
|
|
550
616
|
* `latest` is not published, loud) → move `latest` → keep N → the row is deleted (always, saved or failed).
|
|
551
617
|
* A lost fence, an upload or a pointer failure ⇒ one `workspace_snapshot_failed` line + the `failed` outcome; `latest`
|
|
@@ -673,13 +739,16 @@ export declare class RemoteK8sExecutionEnv implements RemoteExecutionEnv, Backgr
|
|
|
673
739
|
* managed-retention sweep). For each ended space it reclaims everything the space left behind, over this deployment's k8s config (it
|
|
674
740
|
* never creates a pod): its build-cache volume (the claims labelled by the space key; only when the cache volume is configured),
|
|
675
741
|
* its snapshot objects — the `space/` partition (archives + `latest`) and the park lane's objects in `<prefix>/<sessionId>/` that carry the ended occupant's mark (only when a
|
|
676
|
-
* snapshot store is configured). Each part is independent: one part failing never skips another. A failed part ⇒
|
|
677
|
-
* (`workspace_cache_reclaim_failed{reason}` for the volume, `workspace_space_reclaim_failed{stage}` for the objects)
|
|
742
|
+
* snapshot store is configured). Each part is independent: one part failing never skips another. A failed part ⇒ `recordFailOpen` per space + ONE operator line per
|
|
743
|
+
* CLASS of failure at the end of the call (`workspace_cache_reclaim_failed{reason}` for the volume, `workspace_space_reclaim_failed{lane, stage}` for the objects): the line names the
|
|
744
|
+
* first space of the call that met it and carries `count` = how many spaces met it (an RBAC drift on a sweep of hundreds of spaces is one line, not hundreds); never throws.
|
|
678
745
|
* ONE call = ONE absolute deadline (the snapshot bound, `dataTimeoutMs`; no knob of its own), built at the entry and nowhere else: every request of the call — each
|
|
679
746
|
* space's cache-volume delete and every LIST / DELETE of its objects — runs under it. A session delete calls with its one space; the managed-retention sweep calls
|
|
680
747
|
* once per domain per round with the spaces that round ended there. When the deadline passes the request in flight is cut and every space not yet done is still
|
|
681
|
-
* walked but sends nothing: its volume says `reason: "budget"`, its objects `stage: "budget"` (the volume stays for deletion by label,
|
|
682
|
-
* bucket's lifecycle rule).
|
|
748
|
+
* walked but sends nothing: its volume says `reason: "budget"`, its objects `stage: "budget"` — the budget classes' `count` is how many spaces were left (the volume stays for deletion by label,
|
|
749
|
+
* the objects for the bucket's lifecycle rule). ONE queue, ONE bound: at most {@link SPACE_RECLAIM_CONCURRENCY} spaces are worked on at once across ALL calls of this reclaimer (the
|
|
750
|
+
* sweep's spaces and every session delete go through the same gate, so a burst of deletes cannot start a burst of reclaims); a space waiting for its turn is waiting under its call's
|
|
751
|
+
* deadline. A caller that must not wait for the seat (the session-delete answer) starts it and does not await it.
|
|
683
752
|
*/
|
|
684
753
|
export declare function createSpaceReclaimer(config: K8sEnvConfig, deps?: K8sEnvDeps): SpaceReclaimer;
|
|
685
754
|
/**
|