@capybara-hq/kernel 0.1.0-rc.41 → 0.1.0-rc.43
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/bootstrap.json +3 -3
- package/dist/admin/admin.schemas.d.ts +6 -0
- package/dist/admin/org-network.service.d.ts +3 -1
- package/dist/admin/org-network.service.js +10 -2
- package/dist/app.d.ts +4 -0
- package/dist/app.js +2 -0
- package/dist/background/finish.d.ts +9 -1
- package/dist/background/finish.js +57 -4
- package/dist/background/launch.d.ts +23 -0
- package/dist/background/launch.js +55 -1
- package/dist/background/managed-output.d.ts +110 -0
- package/dist/background/managed-output.js +219 -0
- package/dist/background/managed.d.ts +52 -0
- package/dist/background/managed.js +128 -0
- package/dist/background/poll.job.d.ts +35 -1
- package/dist/background/poll.job.js +174 -9
- package/dist/background/render.js +1 -0
- package/dist/background/retire-legacy-tasks.job.d.ts +57 -0
- package/dist/background/retire-legacy-tasks.job.js +149 -0
- package/dist/background/session.d.ts +15 -5
- package/dist/background/session.js +22 -6
- package/dist/background/stop.d.ts +35 -5
- package/dist/background/stop.js +94 -8
- package/dist/background/store.d.ts +110 -3
- package/dist/background/store.js +205 -3
- package/dist/background/tasks.service.d.ts +18 -1
- package/dist/background/tasks.service.js +99 -9
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/cards.js +1 -1
- package/dist/channels/inbound.js +2 -0
- package/dist/channels/phrases.d.ts +4 -0
- package/dist/channels/phrases.js +4 -0
- package/dist/config/load.d.ts +18 -0
- package/dist/config/load.js +39 -1
- package/dist/config/permission-migration.d.ts +26 -0
- package/dist/config/permission-migration.js +64 -0
- package/dist/config/schema.d.ts +4 -1
- package/dist/config/schema.js +41 -10
- package/dist/conversations/conversations.controller.d.ts +1 -1
- package/dist/conversations/conversations.controller.js +1 -1
- package/dist/conversations/conversations.module.js +12 -0
- package/dist/conversations/conversations.service.d.ts +11 -2
- package/dist/conversations/conversations.service.js +97 -27
- package/dist/conversations/event-log.d.ts +1 -1
- package/dist/conversations/event-log.js +10 -2
- package/dist/conversations/events.d.ts +307 -4
- package/dist/conversations/events.js +286 -32
- package/dist/conversations/permission-profile-store.d.ts +50 -0
- package/dist/conversations/permission-profile-store.js +67 -0
- package/dist/conversations/permission-profile-store.module.d.ts +2 -0
- package/dist/conversations/permission-profile-store.module.js +19 -0
- package/dist/conversations/permission-profiles.controller.d.ts +84 -0
- package/dist/conversations/permission-profiles.controller.js +105 -0
- package/dist/conversations/permission-profiles.schemas.d.ts +31 -0
- package/dist/conversations/permission-profiles.schemas.js +23 -0
- package/dist/conversations/permission-profiles.service.d.ts +56 -0
- package/dist/conversations/permission-profiles.service.js +179 -0
- package/dist/ctx/create-ctx.d.ts +12 -5
- package/dist/ctx/create-ctx.js +21 -5
- package/dist/db/kernel-schema.d.ts +248 -3
- package/dist/devices/access.js +1 -1
- package/dist/devices/access.module.d.ts +2 -0
- package/dist/devices/access.module.js +19 -0
- package/dist/devices/conversation-devices.d.ts +8 -29
- package/dist/devices/conversation-devices.js +37 -73
- package/dist/devices/device-projects.service.d.ts +26 -28
- package/dist/devices/device-projects.service.js +123 -127
- package/dist/devices/devices.controller.js +3 -1
- package/dist/devices/devices.module.js +11 -9
- package/dist/devices/devices.service.d.ts +116 -8
- package/dist/devices/devices.service.js +252 -20
- package/dist/devices/dto.d.ts +16 -0
- package/dist/devices/dto.js +34 -6
- package/dist/devices/errors.d.ts +8 -0
- package/dist/devices/errors.js +10 -0
- package/dist/devices/project-rules.d.ts +44 -0
- package/dist/devices/project-rules.js +27 -0
- package/dist/devices/working-root.d.ts +6 -0
- package/dist/devices/working-root.js +12 -1
- package/dist/errors.d.ts +31 -0
- package/dist/errors.js +31 -0
- package/dist/evals/reconstruct.d.ts +19 -2
- package/dist/evals/reconstruct.js +40 -2
- package/dist/evals/recorded-permission-context.d.ts +77 -0
- package/dist/evals/recorded-permission-context.js +151 -0
- package/dist/evals/recorded-tools.d.ts +10 -1
- package/dist/evals/recorded-tools.js +27 -3
- package/dist/evals/run-replay.d.ts +8 -2
- package/dist/evals/run-replay.js +18 -2
- package/dist/evals/trajectory.d.ts +1 -1
- package/dist/evals/worker.d.ts +10 -1
- package/dist/evals/worker.js +23 -14
- package/dist/extensions/host.d.ts +4 -1
- package/dist/extensions/host.js +10 -6
- package/dist/http/api.module.js +2 -0
- package/dist/identity/accounts.d.ts +14 -1
- package/dist/identity/accounts.js +61 -5
- package/dist/identity/identity.module.js +2 -0
- package/dist/identity/settings.d.ts +28 -12
- package/dist/identity/settings.js +89 -33
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/infra/cli/kernel-cli.module.d.ts +2 -2
- package/dist/infra/cli/kernel-cli.module.js +5 -2
- package/dist/infra/cli/permission-cutover.d.ts +59 -0
- package/dist/infra/cli/permission-cutover.js +107 -0
- package/dist/infra/config/kernel-config.service.d.ts +2 -2
- package/dist/infra/config/kernel-config.service.js +35 -11
- package/dist/infra/database/startup-activation-transaction.d.ts +36 -0
- package/dist/infra/database/startup-activation-transaction.js +242 -0
- package/dist/infra/database/transaction-host.d.ts +47 -0
- package/dist/infra/database/transaction-host.js +119 -0
- package/dist/infra/database/xact-lock.d.ts +1 -0
- package/dist/infra/database/xact-lock.js +6 -0
- package/dist/infra/outbox/registry.d.ts +39 -0
- package/dist/infra/outbox/registry.js +18 -0
- package/dist/kernel.module.js +2 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +55 -28
- package/dist/local-devices/device-auth.js +1 -1
- package/dist/local-devices/device-policy.service.d.ts +35 -5
- package/dist/local-devices/device-policy.service.js +188 -13
- package/dist/local-devices/instance-bindings.d.ts +82 -0
- package/dist/local-devices/instance-bindings.js +304 -0
- package/dist/local-devices/keys.d.ts +5 -0
- package/dist/local-devices/keys.js +5 -0
- package/dist/local-devices/local-device-gateway.d.ts +19 -4
- package/dist/local-devices/local-device-gateway.js +185 -17
- package/dist/local-devices/local-device-provider.d.ts +42 -7
- package/dist/local-devices/local-device-provider.js +185 -10
- package/dist/local-devices/local-devices.module.d.ts +17 -2
- package/dist/local-devices/local-devices.module.js +49 -8
- package/dist/local-devices/machines.d.ts +35 -12
- package/dist/local-devices/machines.js +203 -8
- package/dist/local-devices/network-grants.js +3 -3
- package/dist/local-devices/network-grants.module.d.ts +2 -0
- package/dist/local-devices/network-grants.module.js +14 -0
- package/dist/local-devices/owner-report.d.ts +79 -0
- package/dist/local-devices/owner-report.js +155 -0
- package/dist/local-devices/owner-reports.d.ts +48 -0
- package/dist/local-devices/owner-reports.js +190 -0
- package/dist/local-devices/policy-summary.d.ts +24 -1
- package/dist/local-devices/policy-summary.js +48 -0
- package/dist/local-devices/relay.d.ts +82 -6
- package/dist/local-devices/relay.js +187 -16
- package/dist/local-devices/targets.d.ts +16 -1
- package/dist/local-devices/targets.js +35 -2
- package/dist/models/image-usable.d.ts +22 -0
- package/dist/models/image-usable.js +29 -0
- package/dist/models/images.d.ts +125 -0
- package/dist/models/images.js +440 -0
- package/dist/models/models.module.d.ts +3 -2
- package/dist/models/models.module.js +16 -5
- package/dist/models/org-models.schemas.js +1 -0
- package/dist/models/purposes.controller.d.ts +7 -0
- package/dist/models/purposes.controller.js +9 -0
- package/dist/models/purposes.d.ts +28 -3
- package/dist/models/purposes.js +40 -13
- package/dist/orgs/cloud-network-setting.d.ts +33 -0
- package/dist/orgs/cloud-network-setting.js +47 -0
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +8 -2
- package/dist/orgs/org-lock.d.ts +10 -4
- package/dist/orgs/org-lock.js +10 -4
- package/dist/orgs/orgs.service.d.ts +3 -1
- package/dist/orgs/orgs.service.js +8 -2
- package/dist/orgs/settings.controller.d.ts +4 -1
- package/dist/orgs/settings.controller.js +3 -3
- package/dist/orgs/settings.service.d.ts +48 -56
- package/dist/orgs/settings.service.js +144 -101
- package/dist/overrides.d.ts +6 -1
- package/dist/overrides.js +2 -0
- package/dist/platform/exclusions.js +20 -0
- package/dist/platform/ops/admin.ops.js +14 -11
- package/dist/platform/ops/agent-skills.ops.js +2 -0
- package/dist/platform/ops/devices.ops.js +10 -2
- package/dist/platform/ops/models.ops.js +10 -0
- package/dist/platform/ops/org-settings.ops.js +6 -6
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/roles/worker.module.js +4 -0
- package/dist/runtime/context/build.d.ts +3 -1
- package/dist/runtime/context/build.js +19 -3
- package/dist/runtime/context/compaction.js +5 -0
- package/dist/runtime/context/device-paths.d.ts +9 -2
- package/dist/runtime/context/device-paths.js +20 -0
- package/dist/runtime/context/permission-profile.d.ts +46 -0
- package/dist/runtime/context/permission-profile.js +194 -0
- package/dist/runtime/hook-calls.d.ts +11 -1
- package/dist/runtime/hook-calls.js +24 -1
- package/dist/runtime/maintenance.d.ts +7 -1
- package/dist/runtime/maintenance.js +43 -15
- package/dist/runtime/model-call.d.ts +32 -0
- package/dist/runtime/model-call.js +67 -0
- package/dist/runtime/permission-context-errors.d.ts +39 -0
- package/dist/runtime/permission-context-errors.js +67 -0
- package/dist/runtime/permission-context.service.d.ts +60 -0
- package/dist/runtime/permission-context.service.js +286 -0
- package/dist/runtime/project/knowledge.d.ts +7 -2
- package/dist/runtime/project/knowledge.js +5 -2
- package/dist/runtime/project/knowledge.service.d.ts +17 -2
- package/dist/runtime/project/knowledge.service.js +76 -12
- package/dist/runtime/providers.d.ts +9 -5
- package/dist/runtime/providers.js +22 -3
- package/dist/runtime/run-execution.d.ts +4 -1
- package/dist/runtime/run-execution.js +14 -5
- package/dist/runtime/run-steps.d.ts +11 -3
- package/dist/runtime/run-steps.js +27 -4
- package/dist/runtime/runtime.module.js +11 -0
- package/dist/runtime/usage-report.d.ts +10 -6
- package/dist/runtime/usage-report.js +31 -11
- package/dist/sandbox/attachments-path.d.ts +15 -0
- package/dist/sandbox/attachments-path.js +15 -0
- package/dist/sandbox/cloud-permission-snapshot.d.ts +159 -0
- package/dist/sandbox/cloud-permission-snapshot.js +407 -0
- package/dist/sandbox/cloud-permission-snapshot.module.d.ts +8 -0
- package/dist/sandbox/cloud-permission-snapshot.module.js +34 -0
- package/dist/sandbox/held-operations.d.ts +39 -0
- package/dist/sandbox/held-operations.js +119 -0
- package/dist/sandbox/jobs.d.ts +14 -3
- package/dist/sandbox/jobs.js +20 -2
- package/dist/sandbox/kernel-read.d.ts +55 -0
- package/dist/sandbox/kernel-read.js +57 -0
- package/dist/sandbox/legacy-retirement.d.ts +336 -0
- package/dist/sandbox/legacy-retirement.js +1063 -0
- package/dist/sandbox/legacy-retirement.module.d.ts +8 -0
- package/dist/sandbox/legacy-retirement.module.js +25 -0
- package/dist/sandbox/managed-device-context.d.ts +94 -0
- package/dist/sandbox/managed-device-context.js +308 -0
- package/dist/sandbox/managed-device-context.module.d.ts +6 -0
- package/dist/sandbox/managed-device-context.module.js +33 -0
- package/dist/sandbox/modes.d.ts +56 -8
- package/dist/sandbox/modes.js +92 -8
- package/dist/sandbox/operation-authority-types.d.ts +8 -0
- package/dist/sandbox/operation-authority-types.js +32 -0
- package/dist/sandbox/operation-authority.d.ts +145 -0
- package/dist/sandbox/operation-authority.js +783 -0
- package/dist/sandbox/operation-authority.module.d.ts +2 -0
- package/dist/sandbox/operation-authority.module.js +29 -0
- package/dist/sandbox/operation-intents.d.ts +206 -0
- package/dist/sandbox/operation-intents.js +1252 -0
- package/dist/sandbox/operation-intents.module.d.ts +2 -0
- package/dist/sandbox/operation-intents.module.js +21 -0
- package/dist/sandbox/operation-payloads.d.ts +33 -0
- package/dist/sandbox/operation-payloads.js +332 -0
- package/dist/sandbox/operation-reconcile.job.d.ts +49 -0
- package/dist/sandbox/operation-reconcile.job.js +247 -0
- package/dist/sandbox/permission-authority-epochs.d.ts +18 -0
- package/dist/sandbox/permission-authority-epochs.js +83 -0
- package/dist/sandbox/permission-authority-lock.d.ts +38 -0
- package/dist/sandbox/permission-authority-lock.js +147 -0
- package/dist/sandbox/permission-authority.module.d.ts +9 -0
- package/dist/sandbox/permission-authority.module.js +55 -0
- package/dist/sandbox/permission-availability.d.ts +18 -0
- package/dist/sandbox/permission-availability.js +19 -0
- package/dist/sandbox/permission-call-grants.d.ts +34 -0
- package/dist/sandbox/permission-call-grants.js +349 -0
- package/dist/sandbox/permission-call-grants.module.d.ts +2 -0
- package/dist/sandbox/permission-call-grants.module.js +21 -0
- package/dist/sandbox/permission-call-types.d.ts +82 -0
- package/dist/sandbox/permission-call-types.js +1 -0
- package/dist/sandbox/permission-ceiling-writes.d.ts +47 -0
- package/dist/sandbox/permission-ceiling-writes.js +223 -0
- package/dist/sandbox/permission-config-publication.d.ts +76 -0
- package/dist/sandbox/permission-config-publication.js +339 -0
- package/dist/sandbox/permission-context-types.d.ts +64 -0
- package/dist/sandbox/permission-context-types.js +24 -0
- package/dist/sandbox/permission-facts.d.ts +206 -0
- package/dist/sandbox/permission-facts.js +627 -0
- package/dist/sandbox/permission-facts.module.d.ts +2 -0
- package/dist/sandbox/permission-facts.module.js +20 -0
- package/dist/sandbox/permission-instance-writes.d.ts +90 -0
- package/dist/sandbox/permission-instance-writes.js +305 -0
- package/dist/sandbox/permission-runtime-reports.d.ts +83 -0
- package/dist/sandbox/permission-runtime-reports.js +354 -0
- package/dist/sandbox/permission-transitions.d.ts +31 -0
- package/dist/sandbox/permission-transitions.js +155 -0
- package/dist/sandbox/platform-full-access.d.ts +128 -0
- package/dist/sandbox/platform-full-access.js +210 -0
- package/dist/sandbox/providers.d.ts +22 -0
- package/dist/sandbox/providers.js +10 -2
- package/dist/sandbox/providers.module.d.ts +2 -0
- package/dist/sandbox/providers.module.js +19 -0
- package/dist/sandbox/request-not-sent.d.ts +13 -0
- package/dist/sandbox/request-not-sent.js +13 -0
- package/dist/sandbox/review/classifier.d.ts +2 -0
- package/dist/sandbox/review/classifier.js +8 -0
- package/dist/sandbox/review/permission-candidate.d.ts +12 -0
- package/dist/sandbox/review/permission-candidate.js +145 -0
- package/dist/sandbox/review/review.service.d.ts +5 -2
- package/dist/sandbox/review/review.service.js +60 -15
- package/dist/sandbox/sandbox-file-reader.d.ts +18 -1
- package/dist/sandbox/sandbox-file-reader.js +51 -7
- package/dist/sandbox/sandbox.module.js +26 -6
- package/dist/sandbox/sandbox.service.d.ts +230 -34
- package/dist/sandbox/sandbox.service.js +1368 -199
- package/dist/sandbox/unreachable.js +17 -3
- package/dist/sandbox/use-context.d.ts +17 -0
- package/dist/sandbox/use-context.js +1 -0
- package/dist/skills/invoke.d.ts +27 -4
- package/dist/skills/invoke.js +72 -7
- package/dist/tools/approvals.controller.d.ts +1 -0
- package/dist/tools/approvals.schemas.d.ts +1 -0
- package/dist/tools/approvals.schemas.js +3 -1
- package/dist/tools/approvals.service.d.ts +23 -10
- package/dist/tools/approvals.service.js +104 -26
- package/dist/tools/builtin-names.d.ts +3 -1
- package/dist/tools/builtin-names.js +5 -1
- package/dist/tools/builtins/artifacts.d.ts +43 -0
- package/dist/tools/builtins/artifacts.js +67 -0
- package/dist/tools/builtins/builtin-tools.d.ts +20 -2
- package/dist/tools/builtins/builtin-tools.js +61 -10
- package/dist/tools/builtins/image/generate.d.ts +59 -0
- package/dist/tools/builtins/image/generate.js +535 -0
- package/dist/tools/builtins/image/index.d.ts +2 -0
- package/dist/tools/builtins/image/index.js +2 -0
- package/dist/tools/builtins/image/paths.d.ts +12 -0
- package/dist/tools/builtins/image/paths.js +26 -0
- package/dist/tools/builtins/sandbox/bash.d.ts +25 -1
- package/dist/tools/builtins/sandbox/bash.js +201 -5
- package/dist/tools/builtins/sandbox/common.d.ts +92 -20
- package/dist/tools/builtins/sandbox/common.js +201 -17
- package/dist/tools/builtins/sandbox/deliver.js +9 -51
- package/dist/tools/builtins/sandbox/edit.js +2 -2
- package/dist/tools/builtins/sandbox/fetch-attachment.js +11 -4
- package/dist/tools/builtins/sandbox/glob.js +2 -2
- package/dist/tools/builtins/sandbox/grep.js +2 -2
- package/dist/tools/builtins/sandbox/read.js +2 -2
- package/dist/tools/builtins/sandbox/task-list.js +7 -1
- package/dist/tools/builtins/sandbox/task-output.d.ts +1 -1
- package/dist/tools/builtins/sandbox/task-output.js +172 -0
- package/dist/tools/builtins/sandbox/task-stop.js +25 -3
- package/dist/tools/builtins/sandbox/write.js +2 -2
- package/dist/tools/builtins/skill-load.js +9 -6
- package/dist/tools/device-op-resolver.d.ts +1 -1
- package/dist/tools/device-op-resolver.js +13 -3
- package/dist/tools/permission-approval-jobs.d.ts +18 -0
- package/dist/tools/permission-approval-jobs.js +92 -0
- package/dist/tools/pipeline.d.ts +17 -2
- package/dist/tools/pipeline.js +315 -26
- package/dist/tools/registry.d.ts +9 -0
- package/dist/tools/tools.module.js +15 -0
- package/package.json +4 -3
- package/src/migrations/0146_permission_authority_epochs.sql +6 -0
- package/src/migrations/0147_conversation_permission_profiles.sql +4 -0
- package/src/migrations/0148_first_message_request_hash.sql +2 -0
- package/src/migrations/0149_sandbox_operation_intents.sql +66 -0
- package/src/migrations/0150_permission_call_grants_and_approvals.sql +36 -0
- package/src/migrations/0151_starting_execution_grants.sql +8 -0
- package/src/migrations/0152_background_launch_identity.sql +66 -0
- package/src/migrations/0153_background_cancel_requester.sql +13 -0
- package/src/migrations/0154_cloud_owner_ceiling.sql +14 -0
- package/src/migrations/0155_device_instance_generations.sql +30 -0
- package/src/migrations/0156_device_owner_report.sql +7 -0
- package/src/migrations/0157_legacy_retirement.sql +116 -0
- package/src/migrations/0158_legacy_freeze_enumerated.sql +5 -0
- package/src/migrations/0159_retirement_exact_cancel.sql +9 -0
- package/src/migrations/0160_model_usage_image_kind.sql +10 -0
- package/dist/sandbox/platform-auto-mode.d.ts +0 -63
- package/dist/sandbox/platform-auto-mode.js +0 -63
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounded assembly of a managed background task's retained output (permission runtime cutover
|
|
3
|
+
* phase 8.3, design §B5). Pure: it only calls the {@link OutputReader} it is given, which reads
|
|
4
|
+
* by the task's exact execution ref (`SandboxBackground.readOutput`: no path, no exec, no
|
|
5
|
+
* resume). Every range is read as adjacent bounded requests at the next unassembled offset, so a
|
|
6
|
+
* transport capacity below 4,096 bytes (even one byte) still progresses; a capacity of zero with
|
|
7
|
+
* unread bytes is a deterministic error, never EOF. Memory stays bounded: at most the 4,096-byte
|
|
8
|
+
* parser history plus one fresh window (and the caller's own result budget), never the full
|
|
9
|
+
* retained output.
|
|
10
|
+
*/
|
|
11
|
+
import { LAST_LINES_MAX_CHARS } from "./session.js";
|
|
12
|
+
/**
|
|
13
|
+
* The retained output cannot be read: `lost` (missing or untrustworthy storage, or a snapshot
|
|
14
|
+
* that regressed), `expired` (its retention ended), `mismatch` (the kernel's cursor is past the
|
|
15
|
+
* retained snapshot). The cursor never moves on any of them.
|
|
16
|
+
*/
|
|
17
|
+
export class ManagedOutputUnavailableError extends Error {
|
|
18
|
+
reason;
|
|
19
|
+
constructor(reason, message) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.reason = reason;
|
|
22
|
+
this.name = "ManagedOutputUnavailableError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Unread bytes cannot fit the negotiated transport capacity (the reads return nothing). */
|
|
26
|
+
export class ManagedOutputCapacityError extends Error {
|
|
27
|
+
constructor() {
|
|
28
|
+
super("The task's output cannot fit the device connection's frame capacity; raise the device and deployment frame limits, reconnect and retry");
|
|
29
|
+
this.name = "ManagedOutputCapacityError";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** The provider's semantic read bound (decoded bytes per read). */
|
|
33
|
+
export const MANAGED_READ_MAX_BYTES = 65_536;
|
|
34
|
+
/** Already-delivered bytes the login-prompt parser sees again before the new ones. */
|
|
35
|
+
export const OUTPUT_HISTORY_BYTES = 4096;
|
|
36
|
+
/** The most new bytes one assembly window covers (history plus window fit 65,536 bytes). */
|
|
37
|
+
export const FRESH_WINDOW_MAX_BYTES = 61_440;
|
|
38
|
+
/** The fewest: any one UTF-8 character fits. */
|
|
39
|
+
export const FRESH_WINDOW_MIN_BYTES = 4;
|
|
40
|
+
/** The finish and stop summaries keep at most this many lines. */
|
|
41
|
+
export const LAST_LINES_MAX_LINES = 20;
|
|
42
|
+
const isSlice = (r) => !("unavailable" in r);
|
|
43
|
+
function unavailable(reason) {
|
|
44
|
+
return new ManagedOutputUnavailableError(reason, reason === "expired"
|
|
45
|
+
? "The task's retained output has expired"
|
|
46
|
+
: "The task's retained output is no longer available");
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The committed total of the retained output (a zero-budget metadata probe). Throws
|
|
50
|
+
* {@link ManagedOutputUnavailableError} when the record is lost or expired.
|
|
51
|
+
*/
|
|
52
|
+
export async function probeOutput(read, signal) {
|
|
53
|
+
signal?.throwIfAborted();
|
|
54
|
+
const r = await read(0, 0);
|
|
55
|
+
if (!isSlice(r))
|
|
56
|
+
throw unavailable(r.unavailable);
|
|
57
|
+
if (r.offset !== 0 || r.nextOffset !== 0 || r.data.length !== 0 || !safeCount(r.totalBytes)) {
|
|
58
|
+
throw new Error("The output metadata probe returned an inconsistent answer");
|
|
59
|
+
}
|
|
60
|
+
return r.totalBytes;
|
|
61
|
+
}
|
|
62
|
+
const safeCount = (n) => Number.isSafeInteger(n) && n >= 0;
|
|
63
|
+
/**
|
|
64
|
+
* Every byte of `[start, end)` of the snapshot whose total was `snapshot` (`end <= snapshot`),
|
|
65
|
+
* read as adjacent requests of at most min(65,536, end - position) bytes each, at the next
|
|
66
|
+
* unassembled offset. A later read may report a larger total (the output grew): its bytes past
|
|
67
|
+
* `end` are never requested. A total below `snapshot` is a lost record, not EOF; a read that
|
|
68
|
+
* returns nothing while bytes remain is a capacity error.
|
|
69
|
+
*/
|
|
70
|
+
export async function readOutputRange(read, start, end, snapshot, signal) {
|
|
71
|
+
if (!(safeCount(start) && safeCount(end) && start <= end && end <= snapshot)) {
|
|
72
|
+
throw new Error(`Invalid output range [${start}, ${end}) of ${snapshot}`);
|
|
73
|
+
}
|
|
74
|
+
const out = new Uint8Array(end - start);
|
|
75
|
+
let pos = start;
|
|
76
|
+
while (pos < end) {
|
|
77
|
+
signal?.throwIfAborted();
|
|
78
|
+
const budget = Math.min(MANAGED_READ_MAX_BYTES, end - pos);
|
|
79
|
+
const r = await read(pos, budget);
|
|
80
|
+
if (!isSlice(r))
|
|
81
|
+
throw unavailable(r.unavailable);
|
|
82
|
+
if (r.offset !== pos ||
|
|
83
|
+
r.data.length > budget ||
|
|
84
|
+
r.nextOffset !== pos + r.data.length ||
|
|
85
|
+
!safeCount(r.totalBytes)) {
|
|
86
|
+
throw new Error("The output read returned an inconsistent range");
|
|
87
|
+
}
|
|
88
|
+
if (r.totalBytes < snapshot)
|
|
89
|
+
throw unavailable("lost");
|
|
90
|
+
if (r.data.length === 0)
|
|
91
|
+
throw new ManagedOutputCapacityError();
|
|
92
|
+
out.set(r.data, pos - start);
|
|
93
|
+
pos += r.data.length;
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
/** How many bytes a UTF-8 lead byte starts (1 for anything that is not a multi-byte lead). */
|
|
98
|
+
const sequenceLength = (b) => b >= 0xf0 && b <= 0xf7 ? 4 : b >= 0xe0 ? (b <= 0xef ? 3 : 1) : b >= 0xc0 ? 2 : 1;
|
|
99
|
+
/**
|
|
100
|
+
* The bytes still missing to complete the character `buf` ends inside, 0 when it ends on a
|
|
101
|
+
* character boundary (or on bytes that can never form one: those decode as replacements).
|
|
102
|
+
*/
|
|
103
|
+
export function missingUtf8Bytes(buf) {
|
|
104
|
+
let i = buf.length - 1;
|
|
105
|
+
let back = 0;
|
|
106
|
+
while (i >= 0 && back < 3 && (buf[i] & 0xc0) === 0x80) {
|
|
107
|
+
i--;
|
|
108
|
+
back++;
|
|
109
|
+
}
|
|
110
|
+
if (i < 0)
|
|
111
|
+
return 0;
|
|
112
|
+
const need = sequenceLength(buf[i]);
|
|
113
|
+
const have = buf.length - i;
|
|
114
|
+
return need > have ? need - have : 0;
|
|
115
|
+
}
|
|
116
|
+
/** The length of `buf` without an incomplete trailing character. */
|
|
117
|
+
function wholeLength(buf) {
|
|
118
|
+
if (missingUtf8Bytes(buf) === 0)
|
|
119
|
+
return buf.length;
|
|
120
|
+
let i = buf.length - 1;
|
|
121
|
+
while (i >= 0 && (buf[i] & 0xc0) === 0x80)
|
|
122
|
+
i--;
|
|
123
|
+
return Math.max(0, i);
|
|
124
|
+
}
|
|
125
|
+
const decode = (b) => Buffer.from(b.buffer, b.byteOffset, b.length).toString("utf8");
|
|
126
|
+
/**
|
|
127
|
+
* `TaskOutput`'s read (design §B5): probe N; re-read the parser history `[max(0, R - 4096), R)`;
|
|
128
|
+
* then assemble fresh windows of min(max(budget, 4), 61,440) bytes from the cursor R up to N or
|
|
129
|
+
* `budget` bytes, fetching up to three adjacent bytes to complete a character a window cut. On a
|
|
130
|
+
* live stream (or before the snapshot's end) only whole characters are delivered; at a verified
|
|
131
|
+
* terminal end (`terminal`, established before the probe) every remaining byte is delivered with
|
|
132
|
+
* replacement decoding. A cursor past N is unavailable (`mismatch`), never moved back.
|
|
133
|
+
*/
|
|
134
|
+
export async function assembleTaskOutput(read, opts) {
|
|
135
|
+
const r0 = opts.offset;
|
|
136
|
+
const n = await probeOutput(read, opts.signal);
|
|
137
|
+
if (r0 > n) {
|
|
138
|
+
throw new ManagedOutputUnavailableError("mismatch", "The task's read position is past its retained output");
|
|
139
|
+
}
|
|
140
|
+
const history = await readOutputRange(read, Math.max(0, r0 - OUTPUT_HISTORY_BYTES), r0, n, opts.signal);
|
|
141
|
+
const budget = Math.max(0, Math.floor(opts.budget));
|
|
142
|
+
const chunks = [];
|
|
143
|
+
let pos = r0;
|
|
144
|
+
let withheld = false;
|
|
145
|
+
while (pos < n && pos - r0 < budget) {
|
|
146
|
+
const left = budget - (pos - r0);
|
|
147
|
+
const windowBytes = Math.min(FRESH_WINDOW_MAX_BYTES, Math.max(FRESH_WINDOW_MIN_BYTES, left));
|
|
148
|
+
let end = Math.min(n, pos + windowBytes);
|
|
149
|
+
let raw = await readOutputRange(read, pos, end, n, opts.signal);
|
|
150
|
+
const missing = missingUtf8Bytes(raw);
|
|
151
|
+
if (missing > 0 && end < n) {
|
|
152
|
+
const more = Math.min(n, end + missing);
|
|
153
|
+
raw = concat([raw, await readOutputRange(read, end, more, n, opts.signal)]);
|
|
154
|
+
end = more;
|
|
155
|
+
}
|
|
156
|
+
const finalEnd = opts.terminal && end === n;
|
|
157
|
+
const used = finalEnd ? raw.length : wholeLength(raw);
|
|
158
|
+
if (used > 0)
|
|
159
|
+
chunks.push(raw.subarray(0, used));
|
|
160
|
+
pos += used;
|
|
161
|
+
if (used < raw.length) {
|
|
162
|
+
withheld = true;
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const delivered = concat(chunks);
|
|
167
|
+
return {
|
|
168
|
+
snapshot: n,
|
|
169
|
+
history,
|
|
170
|
+
delivered,
|
|
171
|
+
text: decode(delivered),
|
|
172
|
+
parserText: decode(concat([history, delivered])),
|
|
173
|
+
nextOffset: r0 + delivered.length,
|
|
174
|
+
remaining: Math.max(n - (r0 + delivered.length), 0),
|
|
175
|
+
withheld,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function concat(parts) {
|
|
179
|
+
if (parts.length === 1)
|
|
180
|
+
return parts[0];
|
|
181
|
+
const out = new Uint8Array(parts.reduce((s, p) => s + p.length, 0));
|
|
182
|
+
let at = 0;
|
|
183
|
+
for (const p of parts) {
|
|
184
|
+
out.set(p, at);
|
|
185
|
+
at += p.length;
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The HTTP output suffix (design §B5): probe N, then every byte of `[max(0, N - tailBytes), N)`
|
|
191
|
+
* through adjacent bounded reads. N stays the end even when later reads report a larger total.
|
|
192
|
+
* A cut suffix drops only its leading partial character; no line limit applies.
|
|
193
|
+
*/
|
|
194
|
+
export async function assembleOutputSuffix(read, tailBytes, signal) {
|
|
195
|
+
const n = await probeOutput(read, signal);
|
|
196
|
+
const start = Math.max(0, n - Math.min(MANAGED_READ_MAX_BYTES, Math.max(0, Math.floor(tailBytes))));
|
|
197
|
+
let bytes = await readOutputRange(read, start, n, n, signal);
|
|
198
|
+
const truncated = start > 0;
|
|
199
|
+
if (truncated) {
|
|
200
|
+
let i = 0;
|
|
201
|
+
while (i < bytes.length && i < 3 && (bytes[i] & 0xc0) === 0x80)
|
|
202
|
+
i++;
|
|
203
|
+
bytes = bytes.subarray(i);
|
|
204
|
+
}
|
|
205
|
+
return { text: decode(bytes), truncated, end: n };
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* A finish or stop summary from a tail: the last 20 lines (a final newline does not count as a
|
|
209
|
+
* line), at most the last 4,000 characters, decoded with replacement characters.
|
|
210
|
+
*/
|
|
211
|
+
export function lastLinesOf(bytes) {
|
|
212
|
+
const text = decode(bytes);
|
|
213
|
+
const body = text.endsWith("\n") ? text.slice(0, -1) : text;
|
|
214
|
+
const lines = body.split("\n");
|
|
215
|
+
let out = lines.slice(-LAST_LINES_MAX_LINES).join("\n");
|
|
216
|
+
if (text.endsWith("\n") && out !== "")
|
|
217
|
+
out += "\n";
|
|
218
|
+
return out.length > LAST_LINES_MAX_CHARS ? out.slice(-LAST_LINES_MAX_CHARS) : out;
|
|
219
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type SandboxBackground, type SandboxExecutionRef, type SandboxExecutionStatus, type SandboxHandle, type SandboxStopResult } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { IfRunningResult, SandboxService } from "../sandbox/sandbox.service.js";
|
|
3
|
+
import type { BackgroundFinish } from "./finish.js";
|
|
4
|
+
import { type OutputReader } from "./managed-output.js";
|
|
5
|
+
import type { BackgroundTaskRow } from "./store.js";
|
|
6
|
+
/** The task's recorded ref or generation is malformed or inconsistent: it is never used. */
|
|
7
|
+
export declare class ManagedRefError extends Error {
|
|
8
|
+
constructor(taskId: string);
|
|
9
|
+
}
|
|
10
|
+
/** The device's held instance is not the one the task's ref names (a failed read, not a denial). */
|
|
11
|
+
export declare class ManagedInstanceMismatchError extends Error {
|
|
12
|
+
constructor();
|
|
13
|
+
}
|
|
14
|
+
/** The grace a stop gives the task's processes before they are killed. */
|
|
15
|
+
export declare const MANAGED_STOP_GRACE_MS = 5000;
|
|
16
|
+
/** The most bytes a summary's tail asks for (the summary keeps 20 lines, 4,000 characters). */
|
|
17
|
+
export declare const MANAGED_TAIL_BYTES = 12000;
|
|
18
|
+
/** The task's exact ref and instance generation, validated against its own recorded identity. */
|
|
19
|
+
export declare function exactRefOf(task: BackgroundTaskRow): {
|
|
20
|
+
ref: SandboxExecutionRef;
|
|
21
|
+
deviceId: string;
|
|
22
|
+
generation: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Runs `fn` with the provider's background supervision on the task's exact recorded instance
|
|
26
|
+
* only: `not_running` / `other_instance` otherwise (never resumed, never another instance's
|
|
27
|
+
* files). The held handle must be the one the ref names.
|
|
28
|
+
*/
|
|
29
|
+
export declare function onManagedInstance<T>(ifRunning: SandboxService["ifRunning"], task: BackgroundTaskRow, fn: (bg: SandboxBackground, h: SandboxHandle, ref: SandboxExecutionRef, signal: AbortSignal) => Promise<T>, signal?: AbortSignal): Promise<IfRunningResult<T>>;
|
|
30
|
+
/** The provider lost supervision of the execution: lost, with the uncertainty retained. */
|
|
31
|
+
export declare const SUPERVISION_LOST: BackgroundFinish;
|
|
32
|
+
/** How an exact status ends the task, or null while it runs. */
|
|
33
|
+
export declare function statusEnd(s: SandboxExecutionStatus): BackgroundFinish | null;
|
|
34
|
+
/**
|
|
35
|
+
* How an exact stop ends the task: `already-exited` keeps the natural exit, `stopped` is stopped,
|
|
36
|
+
* `lost` is lost; null for `cancel-pending` (recorded, not applied: no finish yet).
|
|
37
|
+
*/
|
|
38
|
+
export declare function stopEnd(r: SandboxStopResult): BackgroundFinish | null;
|
|
39
|
+
/**
|
|
40
|
+
* What a finish summary keeps when the exact tail could not be read: labelled, never mistaken for
|
|
41
|
+
* a task that wrote nothing.
|
|
42
|
+
*/
|
|
43
|
+
export declare const LAST_LINES_UNAVAILABLE = "[Last lines unavailable: the task's retained output could not be read.]";
|
|
44
|
+
/**
|
|
45
|
+
* A finish or stop summary: the exact tail's last 20 lines; null when the retained output is
|
|
46
|
+
* unavailable (lost or expired) or the tail read failed.
|
|
47
|
+
*/
|
|
48
|
+
export declare function lastLinesByRef(bg: SandboxBackground, h: SandboxHandle, ref: SandboxExecutionRef, signal: AbortSignal): Promise<string | null>;
|
|
49
|
+
/** {@link lastLinesByRef}'s answer as a finish event keeps it. */
|
|
50
|
+
export declare const summaryLines: (lines: string | null) => string;
|
|
51
|
+
/** The positional reader of the task's retained output by its exact ref. */
|
|
52
|
+
export declare const readerOf: (bg: SandboxBackground, h: SandboxHandle, ref: SandboxExecutionRef, signal: AbortSignal) => OutputReader;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { parseSandboxExecutionRef, SandboxPermissionUnsupportedError, } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { lastLinesOf } from "./managed-output.js";
|
|
3
|
+
/*
|
|
4
|
+
* The consumers' side of a managed background task (permission runtime cutover phase 8.3): every
|
|
5
|
+
* status, read, tail and stop goes to the task's exact recorded execution ref on its exact
|
|
6
|
+
* recorded instance generation, through `SandboxService.ifRunning` (never creating, resuming or
|
|
7
|
+
* rebuilding an instance) and `SandboxBackground` (never an exec, a path or a new scope).
|
|
8
|
+
*/
|
|
9
|
+
/** The task's recorded ref or generation is malformed or inconsistent: it is never used. */
|
|
10
|
+
export class ManagedRefError extends Error {
|
|
11
|
+
constructor(taskId) {
|
|
12
|
+
super(`Background task ${taskId}'s recorded execution reference is malformed or inconsistent; it cannot be read or stopped`);
|
|
13
|
+
this.name = "ManagedRefError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** The device's held instance is not the one the task's ref names (a failed read, not a denial). */
|
|
17
|
+
export class ManagedInstanceMismatchError extends Error {
|
|
18
|
+
constructor() {
|
|
19
|
+
super("The device's instance does not match the task's recorded execution");
|
|
20
|
+
this.name = "ManagedInstanceMismatchError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** The grace a stop gives the task's processes before they are killed. */
|
|
24
|
+
export const MANAGED_STOP_GRACE_MS = 5000;
|
|
25
|
+
/** The most bytes a summary's tail asks for (the summary keeps 20 lines, 4,000 characters). */
|
|
26
|
+
export const MANAGED_TAIL_BYTES = 12_000;
|
|
27
|
+
/** The task's exact ref and instance generation, validated against its own recorded identity. */
|
|
28
|
+
export function exactRefOf(task) {
|
|
29
|
+
const bad = () => new ManagedRefError(task.id);
|
|
30
|
+
if (task.executionRef === null ||
|
|
31
|
+
task.operationId === null ||
|
|
32
|
+
task.instanceId === null ||
|
|
33
|
+
task.instanceGeneration === null ||
|
|
34
|
+
task.deviceId === null ||
|
|
35
|
+
!/^[0-9]{1,16}$/.test(task.instanceGeneration))
|
|
36
|
+
throw bad();
|
|
37
|
+
let ref;
|
|
38
|
+
try {
|
|
39
|
+
ref = parseSandboxExecutionRef(task.executionRef);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
throw bad();
|
|
43
|
+
}
|
|
44
|
+
const generation = Number(task.instanceGeneration);
|
|
45
|
+
if (!Number.isSafeInteger(generation) ||
|
|
46
|
+
ref.operationId !== task.operationId ||
|
|
47
|
+
ref.instanceId !== task.instanceId ||
|
|
48
|
+
ref.instanceGeneration !== task.instanceGeneration ||
|
|
49
|
+
(task.sandboxCreatedAt !== null && task.sandboxCreatedAt.getTime() !== generation))
|
|
50
|
+
throw bad();
|
|
51
|
+
return { ref, deviceId: task.deviceId, generation };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Runs `fn` with the provider's background supervision on the task's exact recorded instance
|
|
55
|
+
* only: `not_running` / `other_instance` otherwise (never resumed, never another instance's
|
|
56
|
+
* files). The held handle must be the one the ref names.
|
|
57
|
+
*/
|
|
58
|
+
export async function onManagedInstance(ifRunning, task, fn, signal) {
|
|
59
|
+
const { ref, deviceId, generation } = exactRefOf(task);
|
|
60
|
+
return ifRunning(deviceId,
|
|
61
|
+
// an exact-ref drain: allowed on an incarnation under a retirement obligation (8.5)
|
|
62
|
+
{ createdAt: new Date(generation), exactRef: true }, async (p, h, sig) => {
|
|
63
|
+
if (h.id !== ref.instanceId)
|
|
64
|
+
throw new ManagedInstanceMismatchError();
|
|
65
|
+
const bg = p.background;
|
|
66
|
+
if (!bg)
|
|
67
|
+
throw new SandboxPermissionUnsupportedError("Managed background tasks are unavailable on this device");
|
|
68
|
+
return fn(bg, h, ref, sig);
|
|
69
|
+
}, signal);
|
|
70
|
+
}
|
|
71
|
+
/** The provider lost supervision of the execution: lost, with the uncertainty retained. */
|
|
72
|
+
export const SUPERVISION_LOST = {
|
|
73
|
+
status: "lost",
|
|
74
|
+
lostReason: "supervision_lost",
|
|
75
|
+
killPending: false,
|
|
76
|
+
};
|
|
77
|
+
function exitedEnd(exitCode, timedOut) {
|
|
78
|
+
if (timedOut)
|
|
79
|
+
return { status: "timed_out", exitCode };
|
|
80
|
+
if (exitCode === 0)
|
|
81
|
+
return { status: "completed", exitCode: 0 };
|
|
82
|
+
return { status: "failed", exitCode };
|
|
83
|
+
}
|
|
84
|
+
/** How an exact status ends the task, or null while it runs. */
|
|
85
|
+
export function statusEnd(s) {
|
|
86
|
+
if (s.state === "running")
|
|
87
|
+
return null;
|
|
88
|
+
if (s.state === "lost")
|
|
89
|
+
return SUPERVISION_LOST;
|
|
90
|
+
return exitedEnd(s.exitCode, s.timedOut);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* How an exact stop ends the task: `already-exited` keeps the natural exit, `stopped` is stopped,
|
|
94
|
+
* `lost` is lost; null for `cancel-pending` (recorded, not applied: no finish yet).
|
|
95
|
+
*/
|
|
96
|
+
export function stopEnd(r) {
|
|
97
|
+
if (r.outcome === "already-exited")
|
|
98
|
+
return exitedEnd(r.exitCode, r.timedOut);
|
|
99
|
+
if (r.outcome === "stopped")
|
|
100
|
+
return { status: "stopped" };
|
|
101
|
+
if (r.outcome === "lost")
|
|
102
|
+
return SUPERVISION_LOST;
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* What a finish summary keeps when the exact tail could not be read: labelled, never mistaken for
|
|
107
|
+
* a task that wrote nothing.
|
|
108
|
+
*/
|
|
109
|
+
export const LAST_LINES_UNAVAILABLE = "[Last lines unavailable: the task's retained output could not be read.]";
|
|
110
|
+
/**
|
|
111
|
+
* A finish or stop summary: the exact tail's last 20 lines; null when the retained output is
|
|
112
|
+
* unavailable (lost or expired) or the tail read failed.
|
|
113
|
+
*/
|
|
114
|
+
export async function lastLinesByRef(bg, h, ref, signal) {
|
|
115
|
+
try {
|
|
116
|
+
const r = await bg.tail(h, ref, { maxBytes: MANAGED_TAIL_BYTES, signal });
|
|
117
|
+
return "unavailable" in r ? null : lastLinesOf(r.data);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
// the end the caller already established stands; only its last lines are missing
|
|
121
|
+
signal.throwIfAborted();
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** {@link lastLinesByRef}'s answer as a finish event keeps it. */
|
|
126
|
+
export const summaryLines = (lines) => lines ?? LAST_LINES_UNAVAILABLE;
|
|
127
|
+
/** The positional reader of the task's retained output by its exact ref. */
|
|
128
|
+
export const readerOf = (bg, h, ref, signal) => (offset, maxBytes) => bg.readOutput(h, ref, { offset, maxBytes, signal });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Redis } from "ioredis";
|
|
1
2
|
import type { KernelConfig } from "../config/schema.js";
|
|
2
3
|
import { EventLog } from "../conversations/event-log.js";
|
|
3
4
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
@@ -5,11 +6,14 @@ import { LockService } from "../infra/lock/lock.service.js";
|
|
|
5
6
|
import type { KernelLogger } from "../log.js";
|
|
6
7
|
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
7
8
|
import { BackgroundTaskFinisher } from "./finish.js";
|
|
9
|
+
import { BackgroundTaskStopper } from "./stop.js";
|
|
8
10
|
import { BackgroundTaskStore } from "./store.js";
|
|
9
11
|
/** The poll of the running background tasks (`@LockedInterval`, every `pollSeconds`). */
|
|
10
12
|
export declare const BACKGROUND_POLL_JOB = "background-task-poll";
|
|
11
13
|
/** The daily prune of finished background tasks older than `tools.outputRetentionDays`. */
|
|
12
14
|
export declare const BACKGROUND_PRUNE_JOB = "background-task-prune";
|
|
15
|
+
/** The most owed managed cancellations one poll applies (each a lease and up to a 5 s grace). */
|
|
16
|
+
export declare const MANAGED_STOPS_PER_TICK = 8;
|
|
13
17
|
/**
|
|
14
18
|
* A reservation (`sid` null) older than this has lost its launch. The slowest legitimate launch
|
|
15
19
|
* is the pipeline's own limit for a background `Bash` call ({@link LAUNCH_EXEC_TIMEOUT_MS} plus
|
|
@@ -37,7 +41,22 @@ export declare class BackgroundTaskPollJob {
|
|
|
37
41
|
readonly config: KernelConfigService;
|
|
38
42
|
readonly lockService: LockService;
|
|
39
43
|
readonly log: KernelLogger;
|
|
40
|
-
|
|
44
|
+
private readonly stopper;
|
|
45
|
+
/**
|
|
46
|
+
* The paired activation gate: once on, a legacy (SID) task is never polled by a raw exec;
|
|
47
|
+
* its instance's poll is refused for the retirement gate ({@link pollSandbox}).
|
|
48
|
+
*/
|
|
49
|
+
private readonly activation?;
|
|
50
|
+
/** The marker that logs a refused legacy poll once per instance across the replicas. */
|
|
51
|
+
private readonly redis?;
|
|
52
|
+
constructor(store: Pick<BackgroundTaskStore, "runningStarted" | "runningManaged" | "owedCancels" | "pruneFinished" | "failAbandonedLaunches">, finisher: BackgroundTaskFinisher, eventLog: Pick<EventLog, "publishChanged">, sandbox: Pick<SandboxService, "cloudAvailable" | "availableFor" | "ifRunning">, config: KernelConfigService, lockService: LockService, log: KernelLogger, stopper: Pick<BackgroundTaskStopper, "stop">,
|
|
53
|
+
/**
|
|
54
|
+
* The paired activation gate: once on, a legacy (SID) task is never polled by a raw exec;
|
|
55
|
+
* its instance's poll is refused for the retirement gate ({@link pollSandbox}).
|
|
56
|
+
*/
|
|
57
|
+
activation?: boolean | undefined,
|
|
58
|
+
/** The marker that logs a refused legacy poll once per instance across the replicas. */
|
|
59
|
+
redis?: Pick<Redis, "set"> | undefined);
|
|
41
60
|
poll(signal?: AbortSignal): Promise<void>;
|
|
42
61
|
/**
|
|
43
62
|
* One poll of every running task (the body of {@link poll}); returns how many tasks finished.
|
|
@@ -47,8 +66,23 @@ export declare class BackgroundTaskPollJob {
|
|
|
47
66
|
* result: they never started), with a `changed: "background"` frame to their conversations.
|
|
48
67
|
*/
|
|
49
68
|
pollOnce(signal?: AbortSignal): Promise<number>;
|
|
69
|
+
/**
|
|
70
|
+
* The managed tasks (permission runtime cutover phase 8.3), by exact ref only: an acknowledged
|
|
71
|
+
* task's status on its exact instance (one lease per instance, never resumed; an exit or a lost
|
|
72
|
+
* supervision finishes it with the exact tail's last lines), and a `cancel-pending` task's owed
|
|
73
|
+
* exact stop (through the stopper, so its claim, outcome and requester's wake rule hold). A
|
|
74
|
+
* malformed ref is never used; an unavailable provider leaves its tasks as they are.
|
|
75
|
+
*/
|
|
76
|
+
private pollManaged;
|
|
77
|
+
/** The exact statuses of one instance's acknowledged managed tasks; returns how many finished. */
|
|
78
|
+
private pollManagedInstance;
|
|
50
79
|
/** Polls the tasks of one device instance; returns how many finished. */
|
|
51
80
|
private pollSandbox;
|
|
81
|
+
/**
|
|
82
|
+
* Logs at `info`, once per legacy instance across the replicas (a Redis marker; every time
|
|
83
|
+
* without one), that its tasks are left to the retirement gate. A Redis failure logs anyway.
|
|
84
|
+
*/
|
|
85
|
+
private noteRetirementOnce;
|
|
52
86
|
/** The poll exec of one instance: each task's report by id. */
|
|
53
87
|
private pollExec;
|
|
54
88
|
/** Deletes the finished tasks older than `tools.outputRetentionDays` (their rows only). */
|