@capybara-hq/kernel 0.1.0-rc.120 → 0.1.0-rc.122
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/dist/background/finish.d.ts +5 -1
- package/dist/background/finish.js +29 -18
- package/dist/background/launch.d.ts +0 -5
- package/dist/background/launch.js +1 -6
- package/dist/background/managed.js +1 -4
- package/dist/background/poll.job.d.ts +3 -25
- package/dist/background/poll.job.js +20 -112
- package/dist/background/render.d.ts +2 -8
- package/dist/background/render.js +3 -17
- package/dist/background/stop.d.ts +15 -16
- package/dist/background/stop.js +39 -76
- package/dist/background/store.d.ts +17 -45
- package/dist/background/store.js +60 -94
- package/dist/background/tasks.service.d.ts +2 -5
- package/dist/background/tasks.service.js +9 -20
- package/dist/background/wake.js +3 -2
- package/dist/catalog/admin-catalog.controller.d.ts +2 -18
- package/dist/catalog/admin-catalog.controller.js +2 -28
- package/dist/catalog/catalog-content.d.ts +1 -5
- package/dist/catalog/catalog-items.d.ts +2 -6
- package/dist/catalog/catalog-items.js +5 -26
- package/dist/catalog/catalog-scope.service.d.ts +1 -121
- package/dist/catalog/catalog-scope.service.js +12 -552
- package/dist/catalog/catalog.service.d.ts +4 -15
- package/dist/catalog/catalog.service.js +7 -35
- package/dist/catalog/job-ids.d.ts +0 -18
- package/dist/catalog/job-ids.js +0 -20
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.js +6 -20
- package/dist/catalog/org-plugin-uploads.controller.d.ts +4 -19
- package/dist/catalog/org-plugin-uploads.controller.js +6 -34
- package/dist/catalog/org-plugin-uploads.d.ts +3 -10
- package/dist/catalog/org-plugin-uploads.js +4 -18
- package/dist/catalog/org-plugin-uploads.schemas.js +0 -1
- package/dist/catalog/owned-items.d.ts +6 -11
- package/dist/catalog/owned-items.js +10 -20
- package/dist/catalog/ownership.d.ts +3 -29
- package/dist/catalog/ownership.js +4 -54
- package/dist/catalog/platform-components.d.ts +5 -11
- package/dist/catalog/platform-components.js +8 -15
- package/dist/catalog/plugin-import.d.ts +3 -42
- package/dist/catalog/plugin-import.js +26 -195
- package/dist/catalog/plugin-install.js +1 -6
- package/dist/catalog/plugin-package.d.ts +1 -0
- package/dist/catalog/plugin-package.js +5 -0
- package/dist/catalog/plugin-upgrade.d.ts +3 -26
- package/dist/catalog/plugin-upgrade.js +20 -103
- package/dist/catalog/request-rules.js +4 -6
- package/dist/catalog/scope-sync.js +2 -4
- package/dist/catalog/scope.d.ts +2 -5
- package/dist/channels/jobs.d.ts +3 -3
- package/dist/channels/jobs.js +4 -3
- package/dist/channels/outbound.d.ts +1 -0
- package/dist/channels/outbound.js +32 -8
- package/dist/config/load.d.ts +0 -25
- package/dist/config/load.js +0 -57
- package/dist/config/schema.js +2 -3
- package/dist/conversations/attachments.service.js +3 -5
- package/dist/conversations/conversations.service.d.ts +3 -3
- package/dist/conversations/conversations.service.js +3 -3
- package/dist/conversations/job-org.d.ts +3 -0
- package/dist/conversations/job-org.js +11 -0
- package/dist/conversations/prompt-suggestions.d.ts +2 -7
- package/dist/conversations/prompt-suggestions.js +29 -27
- package/dist/conversations/titles.d.ts +3 -4
- package/dist/conversations/titles.js +19 -30
- package/dist/db/kernel-schema.d.ts +6 -16
- package/dist/db/pool.js +7 -2
- package/dist/devices/devices.controller.d.ts +0 -5
- package/dist/devices/devices.controller.js +2 -20
- package/dist/devices/devices.service.d.ts +1 -17
- package/dist/devices/devices.service.js +0 -22
- package/dist/errors.d.ts +1 -5
- package/dist/errors.js +1 -5
- package/dist/evals/judge.d.ts +3 -0
- package/dist/evals/judge.js +1 -1
- package/dist/evals/run-replay.d.ts +1 -1
- package/dist/evals/run-replay.js +26 -29
- package/dist/evals/step-replay.d.ts +3 -1
- package/dist/evals/step-replay.js +10 -1
- package/dist/evals/worker.d.ts +3 -1
- package/dist/evals/worker.js +53 -21
- package/dist/extensions/deployment-config-store.js +18 -14
- package/dist/extensions/effective-config.d.ts +1 -5
- package/dist/extensions/effective-config.js +1 -5
- package/dist/extensions/hooks.d.ts +3 -1
- package/dist/extensions/hooks.js +7 -2
- package/dist/extensions/installs.d.ts +2 -14
- package/dist/extensions/installs.js +10 -32
- package/dist/extensions/org-config.d.ts +3 -4
- package/dist/extensions/org-config.js +3 -4
- package/dist/extensions/plugin-guides.d.ts +0 -1
- package/dist/extensions/plugin-guides.js +0 -1
- package/dist/extensions/plugin-icons.d.ts +0 -1
- package/dist/extensions/plugin-icons.js +0 -3
- package/dist/files/blob-sweep.job.d.ts +2 -11
- package/dist/files/blob-sweep.job.js +7 -21
- package/dist/files/hash-job.d.ts +5 -15
- package/dist/files/hash-job.js +14 -33
- package/dist/files/library-jobs.module.d.ts +1 -6
- package/dist/files/library-jobs.module.js +3 -9
- package/dist/identity/api-tokens.js +54 -40
- package/dist/identity/auth.guard.js +2 -2
- package/dist/identity/sessions.js +7 -3
- package/dist/identity/settings.js +5 -21
- package/dist/inbox/inbox.service.d.ts +2 -3
- package/dist/inbox/org-notices.d.ts +0 -14
- package/dist/inbox/platform-inbox.service.d.ts +1 -8
- package/dist/inbox/platform-inbox.service.js +2 -6
- package/dist/inbox/platform-notices.d.ts +3 -3
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -3
- package/dist/infra/database/database.module.js +2 -1
- package/dist/infra/database/org-scope.d.ts +5 -3
- package/dist/infra/database/org-scope.js +7 -1
- package/dist/infra/database/scoped-dialect.d.ts +3 -1
- package/dist/infra/database/scoped-dialect.js +17 -5
- package/dist/infra/events/kernel-events.d.ts +2 -0
- package/dist/infra/outbox/outbox.service.d.ts +2 -0
- package/dist/infra/outbox/outbox.service.js +10 -0
- package/dist/infra/outbox/registry.d.ts +0 -41
- package/dist/infra/outbox/registry.js +0 -37
- package/dist/models/embeddings.d.ts +0 -5
- package/dist/models/embeddings.js +28 -35
- package/dist/models/images.d.ts +3 -8
- package/dist/models/images.js +19 -37
- package/dist/models/purposes.d.ts +7 -2
- package/dist/models/purposes.js +16 -3
- package/dist/orgs/device-network-setting.d.ts +0 -44
- package/dist/orgs/device-network-setting.js +0 -83
- package/dist/orgs/invitations.service.js +34 -30
- package/dist/orgs/offboarding.d.ts +2 -2
- package/dist/orgs/offboarding.js +2 -2
- package/dist/orgs/orgs.service.d.ts +1 -1
- package/dist/orgs/orgs.service.js +19 -15
- package/dist/orgs/settings.service.d.ts +19 -14
- package/dist/orgs/settings.service.js +12 -37
- package/dist/platform/exclusions.js +0 -11
- package/dist/platform/ops/catalog-admin.ops.js +0 -8
- package/dist/platform/ops/devices.ops.js +0 -28
- package/dist/platform/ops/extensions-admin.ops.js +3 -3
- package/dist/platform/ops/inbox.ops.js +5 -22
- package/dist/platform/ops/org-plugins.ops.d.ts +1 -3
- package/dist/platform/ops/org-plugins.ops.js +11 -67
- package/dist/plugin-reads/plugin-reads.service.js +2 -1
- package/dist/roles/worker.module.js +0 -9
- package/dist/runtime/hook-calls.d.ts +13 -6
- package/dist/runtime/hook-calls.js +26 -4
- package/dist/runtime/maintenance.d.ts +3 -12
- package/dist/runtime/maintenance.js +25 -55
- package/dist/runtime/model-call.d.ts +4 -2
- package/dist/runtime/model-call.js +59 -58
- package/dist/runtime/providers.d.ts +27 -1
- package/dist/runtime/providers.js +57 -0
- package/dist/runtime/run-jobs.d.ts +1 -1
- package/dist/runtime/run-processors.d.ts +3 -9
- package/dist/runtime/run-worker.d.ts +2 -0
- package/dist/runtime/run-worker.js +23 -8
- package/dist/runtime/subagents/deliveries.js +6 -1
- package/dist/runtime/subagents/dispatch.d.ts +3 -3
- package/dist/runtime/write-base.service.d.ts +2 -3
- package/dist/runtime/write-base.service.js +3 -5
- package/dist/sandbox/device-sandbox-settings.d.ts +38 -92
- package/dist/sandbox/device-sandbox-settings.js +19 -325
- package/dist/sandbox/jobs.d.ts +3 -14
- package/dist/sandbox/jobs.js +2 -20
- package/dist/sandbox/modes.d.ts +5 -45
- package/dist/sandbox/modes.js +3 -60
- package/dist/sandbox/operation-authority.js +0 -11
- package/dist/sandbox/operation-intents.d.ts +32 -9
- package/dist/sandbox/operation-intents.js +241 -32
- package/dist/sandbox/operation-intents.module.js +2 -1
- package/dist/sandbox/operation-reconcile.job.d.ts +9 -11
- package/dist/sandbox/operation-reconcile.job.js +119 -33
- package/dist/sandbox/operation-revoke.d.ts +20 -0
- package/dist/sandbox/operation-revoke.js +3 -0
- package/dist/sandbox/permission-ceiling-writes.d.ts +1 -2
- package/dist/sandbox/permission-ceiling-writes.js +3 -6
- package/dist/sandbox/permission-config-publication.d.ts +1 -28
- package/dist/sandbox/permission-config-publication.js +14 -211
- package/dist/sandbox/permission-facts.d.ts +4 -15
- package/dist/sandbox/permission-facts.js +7 -29
- package/dist/sandbox/permission-instance-writes.d.ts +1 -4
- package/dist/sandbox/permission-instance-writes.js +1 -55
- package/dist/sandbox/providers.d.ts +1 -6
- package/dist/sandbox/providers.js +1 -15
- package/dist/sandbox/review/classifier.js +12 -13
- package/dist/sandbox/sandbox.module.js +3 -6
- package/dist/sandbox/sandbox.service.d.ts +17 -123
- package/dist/sandbox/sandbox.service.js +239 -998
- package/dist/shares/liveness.d.ts +1 -2
- package/dist/shares/liveness.js +1 -2
- package/dist/shares/shares.module.d.ts +1 -2
- package/dist/shares/shares.module.js +2 -5
- package/dist/shares/shares.service.js +1 -2
- package/dist/tools/builtins/image/generate.js +7 -15
- package/dist/tools/builtins/sandbox/common.d.ts +0 -2
- package/dist/tools/builtins/sandbox/common.js +1 -27
- package/dist/tools/builtins/sandbox/task-list.js +10 -10
- package/dist/tools/builtins/sandbox/task-output.d.ts +3 -10
- package/dist/tools/builtins/sandbox/task-output.js +13 -83
- package/dist/tools/builtins/sandbox/task-stop.js +18 -22
- package/dist/tools/builtins/vision/read-image.js +9 -10
- package/dist/tools/builtins/web/extract.js +9 -10
- package/package.json +3 -3
- package/src/migrations/0206_retire_org_extension_uploads.sql +125 -0
- package/src/migrations/0207_confirm_device_instance_destruction.sql +25 -0
- package/src/migrations/0208_convert_stored_permission_settings.sql +189 -0
- package/dist/background/retire-legacy-tasks.job.d.ts +0 -57
- package/dist/background/retire-legacy-tasks.job.js +0 -149
- package/dist/catalog/owned-plugin-cleanup.d.ts +0 -47
- package/dist/catalog/owned-plugin-cleanup.js +0 -140
- package/dist/config/permission-migration.d.ts +0 -34
- package/dist/config/permission-migration.js +0 -115
- package/dist/devices/legacy-cleanup.job.d.ts +0 -34
- package/dist/devices/legacy-cleanup.job.js +0 -147
- package/dist/files/library-backfill.d.ts +0 -63
- package/dist/files/library-backfill.js +0 -143
- package/dist/infra/cli/permission-cutover.d.ts +0 -59
- package/dist/infra/cli/permission-cutover.js +0 -107
- package/dist/sandbox/cloud-permission-snapshot.d.ts +0 -159
- package/dist/sandbox/cloud-permission-snapshot.js +0 -430
- package/dist/sandbox/cloud-permission-snapshot.module.d.ts +0 -8
- package/dist/sandbox/cloud-permission-snapshot.module.js +0 -34
- package/dist/sandbox/legacy-retirement.d.ts +0 -284
- package/dist/sandbox/legacy-retirement.js +0 -1165
- package/dist/sandbox/legacy-retirement.module.d.ts +0 -8
- package/dist/sandbox/legacy-retirement.module.js +0 -25
- package/dist/shares/share-objects.d.ts +0 -47
- package/dist/shares/share-objects.js +0 -93
package/dist/background/stop.js
CHANGED
|
@@ -12,10 +12,10 @@ import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
|
12
12
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
13
13
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
14
14
|
import { isDeviceProgramRestarted } from "../sandbox/request-not-sent.js";
|
|
15
|
-
import {
|
|
16
|
-
import { BackgroundTaskFinisher, } from "./finish.js";
|
|
17
|
-
import { exactRefOf, lastLinesByRef, MANAGED_STOP_GRACE_MS, onManagedInstance, stopEnd, summaryLines, } from "./managed.js";
|
|
18
|
-
import { BackgroundTaskStore,
|
|
15
|
+
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
16
|
+
import { BackgroundTaskFinisher, stoppedByOpts } from "./finish.js";
|
|
17
|
+
import { exactRefOf, LAST_LINES_UNAVAILABLE, lastLinesByRef, MANAGED_STOP_GRACE_MS, onManagedInstance, stopEnd, summaryLines, } from "./managed.js";
|
|
18
|
+
import { BackgroundTaskStore, } from "./store.js";
|
|
19
19
|
/**
|
|
20
20
|
* The most one exact stop attempt of a managed task may take: the wait for the instance's lease,
|
|
21
21
|
* the device's stop with its five-second grace, and the tail. A device that has not answered by
|
|
@@ -67,37 +67,21 @@ export function attemptFailure(err, attemptTimedOut, callerAborted) {
|
|
|
67
67
|
*/
|
|
68
68
|
export const BACKGROUND_STOP_ATTEMPT_MS = Symbol("BACKGROUND_STOP_ATTEMPT_MS");
|
|
69
69
|
/** How a task whose sandbox is not running ends (`ifRunning`'s `not_running` status). */
|
|
70
|
-
export function notRunningAs(status
|
|
70
|
+
export function notRunningAs(status) {
|
|
71
71
|
return {
|
|
72
72
|
status: "lost",
|
|
73
73
|
lostReason: status === "suspended" ? "sandbox_suspended" : "sandbox_gone",
|
|
74
|
-
killPending,
|
|
75
74
|
};
|
|
76
75
|
}
|
|
77
76
|
/** A task found in another sandbox instance (a rebuild): its processes are gone with the old one. */
|
|
78
77
|
export const RECREATED = {
|
|
79
78
|
status: "lost",
|
|
80
79
|
lostReason: "sandbox_recreated",
|
|
81
|
-
killPending: false,
|
|
82
80
|
};
|
|
83
|
-
/** The finish options of a stop asked for by `by`: who stopped it decides whether it may wake. */
|
|
84
|
-
function stoppedByOpts(by) {
|
|
85
|
-
const stoppedBy = by === "person"
|
|
86
|
-
? "person"
|
|
87
|
-
: by === "conversation_deleted"
|
|
88
|
-
? "deletion"
|
|
89
|
-
: by === "subagent_end"
|
|
90
|
-
? "subagent_end"
|
|
91
|
-
: undefined;
|
|
92
|
-
return stoppedBy === undefined ? {} : { stoppedBy };
|
|
93
|
-
}
|
|
94
81
|
/**
|
|
95
82
|
* Stops background tasks (spec 2026-11-05-background-bash-design §2.3, §4.3, permission runtime
|
|
96
83
|
* cutover phase 8.3): a managed task by its exact ref on its exact instance only, through
|
|
97
|
-
* `SandboxService.ifRunning` (it never creates or resumes a sandbox).
|
|
98
|
-
* signalled: while its instance runs it belongs to the retirement gate (`RetireLegacyTasksJob`),
|
|
99
|
-
* and its stop is refused with that gate's actionable refusal; once its instance is gone or
|
|
100
|
-
* replaced it finishes `lost` without any exec or signal.
|
|
84
|
+
* `SandboxService.ifRunning` (it never creates or resumes a sandbox).
|
|
101
85
|
*/
|
|
102
86
|
let BackgroundTaskStopper = class BackgroundTaskStopper {
|
|
103
87
|
store;
|
|
@@ -121,10 +105,9 @@ let BackgroundTaskStopper = class BackgroundTaskStopper {
|
|
|
121
105
|
* The stop first claims the task (`stopping_at`), so the poller leaves it alone while the stop
|
|
122
106
|
* takes effect and the stop's finish is its only one. A stop that loses the claim to another
|
|
123
107
|
* live stop still records its asker on a managed task, so the later finish keeps their wake
|
|
124
|
-
* rule. A
|
|
125
|
-
* it as abandoned. A managed task's stop is owed before the device is asked and never throws for
|
|
108
|
+
* rule. A managed task's stop is owed before the device is asked and never throws for
|
|
126
109
|
* the device: one that cannot settle within its attempt stays owed (`cancel-pending`, why in
|
|
127
|
-
* `cancelFailure`) for the poller. A
|
|
110
|
+
* `cancelFailure`) for the poller. A malformed ref and a
|
|
128
111
|
* failed write give the claim up and throw, the task staying `running`. `how.reported`: the
|
|
129
112
|
* caller's own result tells the model this finish (a managed task's cancellation settled from a
|
|
130
113
|
* TaskOutput read).
|
|
@@ -133,46 +116,14 @@ let BackgroundTaskStopper = class BackgroundTaskStopper {
|
|
|
133
116
|
if (!(await this.store.claimStop(task.id))) {
|
|
134
117
|
// another live stop holds the claim (a poller attempt, a second click): this asker's wake
|
|
135
118
|
// rule still holds for the finish whoever settles it
|
|
136
|
-
if (why !== "revoked"
|
|
119
|
+
if (why !== "revoked")
|
|
137
120
|
await this.store.requestCancel(task.id, why, false);
|
|
138
121
|
return (await this.store.get(task.id)) ?? task;
|
|
139
122
|
}
|
|
140
123
|
// read after the claim: an acknowledgement recording the ref before the claim is seen here,
|
|
141
124
|
// one recording it after sees the claim (both are single-row updates of the same row)
|
|
142
125
|
const cur = (await this.store.get(task.id)) ?? task;
|
|
143
|
-
|
|
144
|
-
return this.stopManaged(cur, why, signal, how.reported);
|
|
145
|
-
if (cur.status !== "running" || cur.sandboxCreatedAt === null)
|
|
146
|
-
return cur;
|
|
147
|
-
const started = { ...cur, sandboxCreatedAt: cur.sandboxCreatedAt };
|
|
148
|
-
const reported = why === "tool";
|
|
149
|
-
// a person's stop never wakes the conversation (background Bash §3, fix round 1), nor does
|
|
150
|
-
// the stop of a conversation being deleted or of a sub-agent that ended (agent map spec §5.3)
|
|
151
|
-
const stoppedBy = why === "person"
|
|
152
|
-
? "person"
|
|
153
|
-
: why === "conversation_deleted"
|
|
154
|
-
? "deletion"
|
|
155
|
-
: why === "subagent_end"
|
|
156
|
-
? "subagent_end"
|
|
157
|
-
: undefined;
|
|
158
|
-
const opts = stoppedBy === undefined ? {} : { stoppedBy };
|
|
159
|
-
let r;
|
|
160
|
-
try {
|
|
161
|
-
r = await this.legacyInstance(started, signal);
|
|
162
|
-
}
|
|
163
|
-
catch (err) {
|
|
164
|
-
await this.store
|
|
165
|
-
.releaseStop(cur.id)
|
|
166
|
-
.catch((e) => this.log.warn("cannot release a background task stop", { taskId: cur.id, err: e }));
|
|
167
|
-
throw err;
|
|
168
|
-
}
|
|
169
|
-
if (r.kind === "not_running") {
|
|
170
|
-
await this.finisher.finish(cur, notRunningAs(r.status, true), "", reported, opts);
|
|
171
|
-
}
|
|
172
|
-
else if (r.kind === "other_instance") {
|
|
173
|
-
await this.finisher.finish(cur, RECREATED, "", reported, opts);
|
|
174
|
-
}
|
|
175
|
-
return (await this.store.get(cur.id)) ?? cur;
|
|
126
|
+
return this.stopManaged(cur, why, signal, how.reported);
|
|
176
127
|
}
|
|
177
128
|
/**
|
|
178
129
|
* A managed task's stop (permission runtime cutover phase 8.3), claimed by {@link stop}: by its
|
|
@@ -219,12 +170,37 @@ let BackgroundTaskStopper = class BackgroundTaskStopper {
|
|
|
219
170
|
*/
|
|
220
171
|
async settleRevokedUnconfirmed(task) {
|
|
221
172
|
const cur = (await this.store.get(task.id)) ?? task;
|
|
222
|
-
if (cur.status !== "running" || cur.executionRef !== null
|
|
173
|
+
if (cur.status !== "running" || cur.executionRef !== null)
|
|
223
174
|
return;
|
|
224
175
|
if (cur.launchState !== "dispatched" && cur.launchState !== "cancel-pending")
|
|
225
176
|
return;
|
|
177
|
+
await this.finishRevoked(cur, { status: "stopped" });
|
|
178
|
+
}
|
|
179
|
+
/** Destruction proves the execution ended, but gives no exit status or output. */
|
|
180
|
+
async settleDestroyed(task) {
|
|
181
|
+
const cur = await this.store.get(task.id);
|
|
182
|
+
if (cur?.status === "running")
|
|
183
|
+
await this.finishRevoked(cur, { status: "lost", lostReason: "sandbox_gone" });
|
|
184
|
+
}
|
|
185
|
+
/** The provider already established the exact end under the pre-resume lease. */
|
|
186
|
+
async settleResumeExit(task, result) {
|
|
187
|
+
if (task.status !== "running")
|
|
188
|
+
return;
|
|
189
|
+
const end = stopEnd(result);
|
|
190
|
+
if (!end)
|
|
191
|
+
throw new Error("Expected a confirmed background stop or exit");
|
|
192
|
+
const by = task.cancelRequestedBy ?? (await this.deletedConversationStop(task));
|
|
193
|
+
await this.finisher.finish(task, end, LAST_LINES_UNAVAILABLE, false, stoppedByOpts(by));
|
|
194
|
+
}
|
|
195
|
+
/** Called inside the exhausted operation's dead-letter transaction, under its row lock. */
|
|
196
|
+
async settleStopUnconfirmed(task) {
|
|
197
|
+
// A reservation still pending dispatch cannot have started a process.
|
|
198
|
+
if (task.status === "running" && task.launchState !== "pending")
|
|
199
|
+
await this.finishRevoked(task, { status: "lost", lostReason: "stop_unconfirmed" });
|
|
200
|
+
}
|
|
201
|
+
async finishRevoked(cur, to) {
|
|
226
202
|
const by = cur.cancelRequestedBy ?? (await this.deletedConversationStop(cur));
|
|
227
|
-
await this.finisher.finish(cur,
|
|
203
|
+
await this.finisher.finish(cur, to, "", false, {
|
|
228
204
|
...stoppedByOpts(by),
|
|
229
205
|
keepOwed: true,
|
|
230
206
|
});
|
|
@@ -299,26 +275,13 @@ let BackgroundTaskStopper = class BackgroundTaskStopper {
|
|
|
299
275
|
// destroyed one is lost like an acknowledged task's (the uncertain record is retained)
|
|
300
276
|
if (r.status === "suspended")
|
|
301
277
|
return pending(null);
|
|
302
|
-
await this.finisher.finish(cur, notRunningAs(r.status
|
|
278
|
+
await this.finisher.finish(cur, notRunningAs(r.status), "", reported, opts);
|
|
303
279
|
}
|
|
304
280
|
else {
|
|
305
281
|
await this.finisher.finish(cur, RECREATED, "", reported, opts);
|
|
306
282
|
}
|
|
307
283
|
return (await this.store.get(cur.id)) ?? cur;
|
|
308
284
|
}
|
|
309
|
-
/**
|
|
310
|
-
* A legacy task's own instance, never signalled: a running one refuses with the retirement
|
|
311
|
-
* gate's refusal before any provider call (the gate retires it and its processes whole); one
|
|
312
|
-
* that is not running or was replaced is reported, so the task finishes without any exec or
|
|
313
|
-
* signal. A task from before devices has none.
|
|
314
|
-
*/
|
|
315
|
-
async legacyInstance(cur, signal) {
|
|
316
|
-
if (cur.deviceId === null)
|
|
317
|
-
return { kind: "not_running", status: "gone" };
|
|
318
|
-
return this.sandbox.ifRunning(cur.deviceId, { createdAt: cur.sandboxCreatedAt }, async () => {
|
|
319
|
-
throw retirementPending();
|
|
320
|
-
}, signal);
|
|
321
|
-
}
|
|
322
285
|
/**
|
|
323
286
|
* After a sub-agent run ended (spec §4.3): stops the running tasks of `conversationId` when it
|
|
324
287
|
* is a sub-agent's conversation; any other conversation is left alone. With `runId`, only the
|
|
@@ -366,7 +329,7 @@ let BackgroundTaskStopper = class BackgroundTaskStopper {
|
|
|
366
329
|
/**
|
|
367
330
|
* Stops `tasks` side by side. A stop that fails while the sandbox runs leaves its task running
|
|
368
331
|
* (logged): a managed task stays owed to the poller and ends at its own deadline at the latest;
|
|
369
|
-
* a
|
|
332
|
+
* a managed cancellation stays owed until its exact execution ends
|
|
370
333
|
* (no deadline ends it in the kernel's view).
|
|
371
334
|
*/
|
|
372
335
|
async stopAll(tasks, why) {
|
|
@@ -2,6 +2,7 @@ import type { SandboxExecutionRef } from "@capybara-hq/plugin-sdk";
|
|
|
2
2
|
import type { BackgroundLaunchState } from "../db/kernel-schema.js";
|
|
3
3
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
4
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
5
|
+
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
5
6
|
import { BackgroundLaunchLock } from "./launch-lock.js";
|
|
6
7
|
export type BackgroundTaskStatus = "running" | "completed" | "failed" | "stopped" | "timed_out" | "lost";
|
|
7
8
|
/** The status of a task that is still live; the one filter every "running tasks" read shares. */
|
|
@@ -18,8 +19,7 @@ export interface BackgroundTaskRow {
|
|
|
18
19
|
*/
|
|
19
20
|
sandboxConversationId: string;
|
|
20
21
|
/**
|
|
21
|
-
* The device
|
|
22
|
-
* is where the task's processes are. Null only for tasks from before devices (all finished).
|
|
22
|
+
* The device bound to the root conversation when this task was launched.
|
|
23
23
|
*/
|
|
24
24
|
deviceId: string | null;
|
|
25
25
|
runId: string;
|
|
@@ -27,15 +27,6 @@ export interface BackgroundTaskRow {
|
|
|
27
27
|
triggerAccountId: string;
|
|
28
28
|
description: string;
|
|
29
29
|
command: string;
|
|
30
|
-
/**
|
|
31
|
-
* A legacy row's recorded session id; null on every managed row (a task is never identified by
|
|
32
|
-
* a SID). Kept for the retirement gate's enumeration and display only.
|
|
33
|
-
*/
|
|
34
|
-
sid: string | null;
|
|
35
|
-
/**
|
|
36
|
-
* The output file: absolute on a managed row; a legacy row reserved but never started kept a
|
|
37
|
-
* relative one (`taskOutputFile` in launch.ts).
|
|
38
|
-
*/
|
|
39
30
|
outputPath: string;
|
|
40
31
|
status: BackgroundTaskStatus;
|
|
41
32
|
lostReason: string | null;
|
|
@@ -45,21 +36,19 @@ export interface BackgroundTaskRow {
|
|
|
45
36
|
deadlineAt: Date;
|
|
46
37
|
/** The sandbox instance the task started in; null until a managed start is acknowledged. */
|
|
47
38
|
sandboxCreatedAt: Date | null;
|
|
48
|
-
/** Marked lost while its process may still exist. */
|
|
49
|
-
killPending: boolean;
|
|
50
39
|
/** The bytes `TaskOutput` has already returned. */
|
|
51
40
|
readOffset: number;
|
|
52
41
|
/** When a stop claimed the task ({@link BackgroundTaskStore.claimStop}); null otherwise. */
|
|
53
42
|
stoppingAt: Date | null;
|
|
54
|
-
/**
|
|
43
|
+
/** The launch's durable state. */
|
|
55
44
|
launchState: BackgroundLaunchState;
|
|
56
|
-
/** A managed task's stable start operation
|
|
45
|
+
/** A managed task's stable start operation. */
|
|
57
46
|
operationId: string | null;
|
|
58
47
|
/** A managed task's trusted working root, persisted before dispatch. */
|
|
59
48
|
workingRoot: string | null;
|
|
60
49
|
/** A managed task's output retention deadline, part of its start input. */
|
|
61
50
|
retainUntil: Date | null;
|
|
62
|
-
/** The exact
|
|
51
|
+
/** The exact execution reference returned by the provider. */
|
|
63
52
|
executionRef: SandboxExecutionRef | null;
|
|
64
53
|
/** A managed task's held instance (its handle id), bound at dispatch. */
|
|
65
54
|
instanceId: string | null;
|
|
@@ -82,8 +71,6 @@ export interface BackgroundTaskRow {
|
|
|
82
71
|
export type CancelFailure = "unreachable" | "failed";
|
|
83
72
|
/** Who asked for a managed task's stop: their wake rule holds for its later finish. */
|
|
84
73
|
export type CancelRequester = "tool" | "person" | "conversation_deleted" | "subagent_end";
|
|
85
|
-
/** Whether `task` is a managed (exact-ref) task rather than a legacy SID one. */
|
|
86
|
-
export declare const isManagedTask: (task: Pick<BackgroundTaskRow, "launchState">) => boolean;
|
|
87
74
|
/** A managed launch's reservation: everything known before the start is dispatched. */
|
|
88
75
|
export interface ManagedTaskReservation {
|
|
89
76
|
id: string;
|
|
@@ -116,7 +103,6 @@ export type ManagedReservation = {
|
|
|
116
103
|
} | {
|
|
117
104
|
kind: "full";
|
|
118
105
|
};
|
|
119
|
-
export type BackgroundTaskInsert = Omit<BackgroundTaskRow, "status" | "finishedAt" | "exitCode" | "lostReason" | "killPending" | "readOffset" | "stoppingAt" | "launchState" | "operationId" | "workingRoot" | "retainUntil" | "executionRef" | "instanceId" | "instanceGeneration" | "cancelRequestedAt" | "cancelRequestedBy" | "cancelFailure" | "cancelFailureDetail">;
|
|
120
106
|
/**
|
|
121
107
|
* How long a stop's claim holds: a claim older than this is abandoned (its stopper died), so the
|
|
122
108
|
* poller checks the task again and another stop may claim it. Longer than any stop takes (the
|
|
@@ -130,15 +116,14 @@ export declare const STOP_CLAIM_TTL_MS: number;
|
|
|
130
116
|
*
|
|
131
117
|
* A launch reserves its managed row ({@link BackgroundTaskStore.reserveManaged}: `running`,
|
|
132
118
|
* `pending`) before the start is dispatched; the operation facade then moves its durable launch
|
|
133
|
-
* state.
|
|
134
|
-
* here and retired by `RetireLegacyTasksJob`; a legacy reservation that never started is failed
|
|
135
|
-
* by the poller ({@link BackgroundTaskStore.failAbandonedLaunches}).
|
|
119
|
+
* state. The poller fails abandoned pending reservations.
|
|
136
120
|
*/
|
|
137
121
|
export declare class BackgroundTaskStore {
|
|
138
122
|
private readonly db;
|
|
139
123
|
readonly txHost: TransactionHost;
|
|
140
124
|
private readonly launchLock;
|
|
141
|
-
|
|
125
|
+
private readonly outbox;
|
|
126
|
+
constructor(db: KernelDb, txHost: TransactionHost, launchLock: BackgroundLaunchLock, outbox: OutboxService);
|
|
142
127
|
/**
|
|
143
128
|
* Reserves a managed launch (permission runtime cutover phase 8.2) under the root conversation's
|
|
144
129
|
* launch lock, before anything is dispatched: the task id, its stable operation id, the
|
|
@@ -162,7 +147,7 @@ export declare class BackgroundTaskStore {
|
|
|
162
147
|
releaseStop(id: string): Promise<void>;
|
|
163
148
|
/**
|
|
164
149
|
* Finishes as `failed` (`lost_reason` `launch_abandoned`) every reservation that started before
|
|
165
|
-
* `before`, never dispatched (
|
|
150
|
+
* `before`, never dispatched (still pending)
|
|
166
151
|
* and is not claimed by a live stop: the launch that reserved it died (a crashed replica). A
|
|
167
152
|
* stop's claim older than {@link STOP_CLAIM_TTL_MS} does not hold it: a stop only claims a
|
|
168
153
|
* reservation and leaves the rest to the launch, so a dead launch would keep it (and its slot of
|
|
@@ -176,12 +161,6 @@ export declare class BackgroundTaskStore {
|
|
|
176
161
|
conversationId: string;
|
|
177
162
|
sandboxConversationId: string;
|
|
178
163
|
}[]>;
|
|
179
|
-
/**
|
|
180
|
-
* Inserts a legacy row: no launch writes one any more; only rows from before (and tests of their
|
|
181
|
-
* retirement) exist. `legacyDispatch` (0157) defaults to `unknown`: a row is "never dispatched"
|
|
182
|
-
* only when its reservation says so.
|
|
183
|
-
*/
|
|
184
|
-
insert(row: BackgroundTaskInsert, legacyDispatch?: "unknown" | "reserved"): Promise<void>;
|
|
185
164
|
/** The managed task launched by start operation `operationId`, if its row still exists. */
|
|
186
165
|
byOperation(operationId: string): Promise<BackgroundTaskRow | undefined>;
|
|
187
166
|
/**
|
|
@@ -192,13 +171,6 @@ export declare class BackgroundTaskStore {
|
|
|
192
171
|
get(id: string): Promise<BackgroundTaskRow | undefined>;
|
|
193
172
|
/** The running tasks of one root conversation's tree, oldest first. */
|
|
194
173
|
runningIn(sandboxConversationId: string): Promise<BackgroundTaskRow[]>;
|
|
195
|
-
/**
|
|
196
|
-
* Every running legacy task that started in an instance and no live stop claimed, across
|
|
197
|
-
* sandboxes, oldest first: what the poller finishes once its instance is gone (never by an
|
|
198
|
-
* exec). A legacy reservation that never started is failed as abandoned, a claimed task is left
|
|
199
|
-
* to its stop.
|
|
200
|
-
*/
|
|
201
|
-
runningLegacy(): Promise<BackgroundTaskRow[]>;
|
|
202
174
|
/**
|
|
203
175
|
* Every running acknowledged managed task with no live stop claim, oldest first: what the
|
|
204
176
|
* poller checks by exact status.
|
|
@@ -247,25 +219,25 @@ export declare class BackgroundTaskStore {
|
|
|
247
219
|
/** The tasks owned by any of the conversations, newest first. */
|
|
248
220
|
listFor(conversationIds: string[]): Promise<BackgroundTaskRow[]>;
|
|
249
221
|
/**
|
|
250
|
-
* Conditional `running` to a final status;
|
|
222
|
+
* Conditional `running` to a final status; no row when the task was no longer running (another
|
|
251
223
|
* path finished it first), or, with `opts.unclaimed` (the poller), when a live stop claimed it.
|
|
252
|
-
* The
|
|
224
|
+
* The returned requester is the one recorded when the conditional update won.
|
|
253
225
|
*/
|
|
254
226
|
finish(id: string, to: {
|
|
255
227
|
status: Exclude<BackgroundTaskStatus, "running">;
|
|
256
228
|
exitCode?: number | null;
|
|
257
229
|
lostReason?: string;
|
|
258
|
-
|
|
259
|
-
}, opts?: {
|
|
230
|
+
}, opts: {
|
|
260
231
|
unclaimed?: boolean;
|
|
261
|
-
|
|
262
|
-
}): Promise<
|
|
232
|
+
launchState: "terminal" | "cancel-pending";
|
|
233
|
+
}): Promise<{
|
|
234
|
+
cancel_requested_by: CancelRequester | null;
|
|
235
|
+
} | undefined>;
|
|
263
236
|
/** Moves the read offset forward only (a concurrent reader never moves it back). */
|
|
264
237
|
advanceOffset(id: string, to: number): Promise<void>;
|
|
265
|
-
clearKill(ids: string[]): Promise<void>;
|
|
266
238
|
/**
|
|
267
239
|
* Deletes finished tasks that ended before `before`; a running one is never deleted, nor a
|
|
268
|
-
* managed record whose launch or cancellation is still uncertain (only
|
|
240
|
+
* managed record whose launch or cancellation is still uncertain (only settled
|
|
269
241
|
* `terminal` rows go).
|
|
270
242
|
*/
|
|
271
243
|
pruneFinished(before: Date): Promise<number>;
|