@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.38
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 +5 -5
- package/dist/admin/admin.module.d.ts +3 -2
- package/dist/admin/admin.module.js +9 -5
- package/dist/admin/audit-log.service.d.ts +51 -0
- package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
- package/dist/admin/audit.controller.d.ts +18 -6
- package/dist/admin/audit.controller.js +36 -6
- package/dist/admin/audit.schemas.d.ts +9 -1
- package/dist/admin/audit.schemas.js +22 -2
- package/dist/admin/org-network.controller.d.ts +30 -0
- package/dist/admin/org-network.controller.js +77 -0
- package/dist/admin/org-network.schemas.d.ts +16 -0
- package/dist/admin/org-network.schemas.js +27 -0
- package/dist/admin/org-network.service.d.ts +41 -0
- package/dist/admin/org-network.service.js +101 -0
- package/dist/admin/outbox-dead.controller.d.ts +4 -6
- package/dist/admin/outbox-dead.controller.js +9 -6
- package/dist/admin/outbox-dead.schemas.d.ts +16 -0
- package/dist/admin/outbox-dead.schemas.js +25 -1
- package/dist/admin/outbox-dead.service.d.ts +16 -7
- package/dist/admin/outbox-dead.service.js +34 -10
- package/dist/admin/overview.service.d.ts +3 -3
- package/dist/admin/overview.service.js +0 -1
- package/dist/agents/agent-lookup.js +2 -10
- package/dist/agents/agents.service.js +9 -20
- package/dist/agents/definition.d.ts +3 -51
- package/dist/agents/definition.js +4 -254
- package/dist/agents/org-templates.js +2 -6
- package/dist/agents/readiness.controller.d.ts +4 -12
- package/dist/agents/readiness.controller.js +4 -12
- package/dist/agents/readiness.service.d.ts +23 -11
- package/dist/agents/readiness.service.js +31 -14
- package/dist/agents/templates.d.ts +0 -6
- package/dist/agents/templates.js +8 -34
- package/dist/background/store.d.ts +2 -0
- package/dist/background/store.js +3 -1
- package/dist/background/wake-rules.js +2 -1
- package/dist/catalog/admin-catalog.controller.d.ts +1 -2
- package/dist/catalog/admin-catalog.controller.js +1 -2
- package/dist/catalog/appearance.service.js +1 -3
- package/dist/catalog/catalog-content.d.ts +1 -1
- package/dist/catalog/catalog-content.js +1 -4
- package/dist/catalog/catalog-items.js +3 -3
- package/dist/catalog/catalog-scope.service.d.ts +10 -28
- package/dist/catalog/catalog-scope.service.js +22 -73
- package/dist/catalog/cli.d.ts +0 -11
- package/dist/catalog/cli.js +0 -20
- package/dist/catalog/component-scope.service.js +0 -2
- package/dist/catalog/component-state.js +2 -2
- package/dist/catalog/install-status.d.ts +6 -0
- package/dist/catalog/install-status.js +6 -0
- package/dist/catalog/job-ids.d.ts +0 -4
- package/dist/catalog/job-ids.js +0 -4
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +2 -0
- package/dist/catalog/org-catalog.service.js +8 -3
- package/dist/catalog/org-extension-switch.d.ts +7 -2
- package/dist/catalog/org-extension-switch.js +56 -9
- package/dist/catalog/org-plugin-uploads.d.ts +6 -15
- package/dist/catalog/org-plugin-uploads.js +9 -27
- package/dist/catalog/owned-items.js +1 -3
- package/dist/catalog/platform-import-update.js +1 -1
- package/dist/catalog/plugin-import.d.ts +15 -13
- package/dist/catalog/plugin-import.js +21 -30
- package/dist/catalog/plugin-install.d.ts +3 -43
- package/dist/catalog/plugin-install.js +8 -150
- package/dist/catalog/plugin-package.d.ts +5 -10
- package/dist/catalog/plugin-package.js +12 -33
- package/dist/catalog/plugin-upgrade.js +5 -4
- package/dist/catalog/scope-jobs.d.ts +34 -34
- package/dist/catalog/scope-jobs.js +50 -37
- package/dist/catalog/scope-orgs.d.ts +1 -1
- package/dist/catalog/scope-orgs.js +1 -2
- package/dist/catalog/scope-sync-workers.d.ts +4 -3
- package/dist/catalog/scope-sync-workers.js +18 -6
- package/dist/catalog/scope-sync.d.ts +56 -59
- package/dist/catalog/scope-sync.js +96 -166
- package/dist/catalog/unshare.d.ts +3 -4
- package/dist/catalog/unshare.js +5 -8
- package/dist/channels/job-ids.d.ts +2 -6
- package/dist/channels/job-ids.js +2 -6
- package/dist/channels/outbound.d.ts +1 -1
- package/dist/channels/outbound.js +1 -1
- package/dist/channels/supervisor.d.ts +2 -3
- package/dist/channels/supervisor.js +2 -3
- package/dist/client/client-access.service.js +1 -1
- package/dist/config/env.js +19 -1
- package/dist/config/load.d.ts +0 -6
- package/dist/config/load.js +8 -27
- package/dist/config/schema.d.ts +54 -47
- package/dist/config/schema.js +198 -42
- package/dist/conversations/attachments.service.d.ts +10 -3
- package/dist/conversations/attachments.service.js +49 -16
- package/dist/conversations/conversations.controller.d.ts +0 -39
- package/dist/conversations/conversations.controller.js +0 -39
- package/dist/conversations/event-log.js +4 -1
- package/dist/conversations/events.d.ts +71 -46
- package/dist/conversations/events.js +124 -112
- package/dist/conversations/media-types.d.ts +25 -0
- package/dist/conversations/media-types.js +38 -0
- package/dist/conversations/queue.d.ts +3 -1
- package/dist/conversations/queue.service.js +9 -2
- package/dist/conversations/titles.js +6 -0
- package/dist/ctx/create-ctx.d.ts +8 -1
- package/dist/ctx/create-ctx.js +13 -3
- package/dist/ctx/net.d.ts +50 -0
- package/dist/ctx/net.js +67 -0
- package/dist/ctx/secrets.d.ts +24 -7
- package/dist/ctx/secrets.js +97 -30
- package/dist/db/kernel-schema.d.ts +27 -6
- package/dist/devices/devices.service.js +2 -1
- package/dist/errors.d.ts +10 -2
- package/dist/errors.js +10 -2
- package/dist/evals/reconstruct.d.ts +4 -17
- package/dist/evals/reconstruct.js +13 -53
- package/dist/evals/recorded-tools.d.ts +0 -27
- package/dist/evals/recorded-tools.js +2 -92
- package/dist/evals/run-replay.d.ts +1 -6
- package/dist/evals/run-replay.js +10 -17
- package/dist/evals/sets.service.d.ts +17 -5
- package/dist/evals/sets.service.js +33 -12
- package/dist/evals/snapshot.d.ts +1 -2
- package/dist/evals/snapshot.js +4 -17
- package/dist/extensions/admin-ops.d.ts +6 -1
- package/dist/extensions/admin-ops.js +17 -4
- package/dist/extensions/admin-view.d.ts +7 -4
- package/dist/extensions/admin-view.js +27 -21
- package/dist/extensions/bootstrap.js +0 -1
- package/dist/extensions/cli.js +0 -1
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/host.d.ts +9 -4
- package/dist/extensions/host.js +14 -8
- package/dist/extensions/installs.d.ts +1 -3
- package/dist/extensions/instance.d.ts +0 -2
- package/dist/extensions/instance.js +0 -3
- package/dist/extensions/org-config.d.ts +4 -4
- package/dist/extensions/org-config.js +13 -22
- package/dist/extensions/package.d.ts +6 -6
- package/dist/extensions/package.js +3 -7
- package/dist/extensions/permission-view.d.ts +2 -4
- package/dist/extensions/plugin-items.d.ts +21 -1
- package/dist/extensions/plugin-items.js +28 -0
- package/dist/extensions/sync.js +5 -10
- package/dist/extensions/unavailable.js +0 -1
- package/dist/http/api.module.js +4 -1
- package/dist/identity/audit.d.ts +0 -12
- package/dist/identity/audit.js +0 -27
- package/dist/identity/auth.controller.js +5 -9
- package/dist/identity/cookies.d.ts +4 -9
- package/dist/identity/cookies.js +8 -32
- package/dist/identity/initial-passwords.d.ts +1 -1
- package/dist/identity/initial-passwords.js +1 -2
- package/dist/identity/sessions.d.ts +0 -6
- package/dist/identity/sessions.js +0 -18
- package/dist/inbox/platform-inbox.service.d.ts +33 -1
- package/dist/inbox/platform-inbox.service.js +56 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
- package/dist/infra/cli/master-key-rewrap.js +24 -0
- package/dist/infra/config/kernel-config.service.js +0 -17
- package/dist/infra/database/transaction-host.d.ts +32 -1
- package/dist/infra/database/transaction-host.js +30 -4
- package/dist/infra/database/xact-lock.d.ts +16 -0
- package/dist/infra/database/xact-lock.js +28 -1
- package/dist/infra/health/health.controller.js +8 -0
- package/dist/infra/health/process-fault.d.ts +16 -0
- package/dist/infra/health/process-fault.js +49 -0
- package/dist/infra/lifecycle/process-guards.d.ts +8 -2
- package/dist/infra/lifecycle/process-guards.js +12 -3
- package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
- package/dist/infra/lifecycle/shutdown-signals.js +28 -13
- package/dist/infra/outbox/outbox.service.d.ts +12 -9
- package/dist/infra/outbox/outbox.service.js +22 -26
- package/dist/infra/outbox/registry.d.ts +15 -7
- package/dist/infra/outbox/registry.js +39 -23
- package/dist/lifecycle/kernel-lifecycle.js +1 -7
- package/dist/models/enablement.d.ts +5 -6
- package/dist/models/enablement.js +7 -14
- package/dist/net/public-address.d.ts +21 -1
- package/dist/net/public-address.js +56 -10
- package/dist/net/safe-fetch.d.ts +4 -1
- package/dist/net/safe-fetch.js +15 -4
- package/dist/orgs/directory-sync.js +2 -0
- package/dist/orgs/members.service.js +5 -0
- package/dist/orgs/network-allowances.service.d.ts +79 -0
- package/dist/orgs/network-allowances.service.js +371 -0
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +9 -2
- package/dist/orgs/org-lock.d.ts +28 -2
- package/dist/orgs/org-lock.js +59 -4
- package/dist/orgs/orgs.controller.d.ts +11 -2
- package/dist/orgs/orgs.controller.js +19 -3
- package/dist/orgs/orgs.module.d.ts +3 -2
- package/dist/orgs/orgs.module.js +6 -2
- package/dist/orgs/orgs.schemas.d.ts +12 -0
- package/dist/orgs/orgs.schemas.js +5 -0
- package/dist/orgs/orgs.service.js +6 -1
- package/dist/orgs/settings.controller.d.ts +3 -2
- package/dist/orgs/settings.service.d.ts +59 -14
- package/dist/orgs/settings.service.js +102 -20
- package/dist/overrides.d.ts +7 -7
- package/dist/overrides.js +4 -4
- package/dist/packages/tgz.d.ts +0 -2
- package/dist/packages/tgz.js +0 -2
- package/dist/platform/exclusions.js +0 -5
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/admin.ops.d.ts +2 -2
- package/dist/platform/ops/admin.ops.js +9 -6
- package/dist/platform/ops/agents.ops.js +1 -1
- package/dist/platform/ops/connectors.ops.js +46 -1
- package/dist/platform/ops/evals.ops.js +1 -64
- package/dist/platform/ops/extensions-admin.ops.js +1 -1
- package/dist/platform/ops/inbox.ops.js +16 -3
- package/dist/platform/ops/org-plugins.ops.js +1 -1
- package/dist/platform/ops/orgs.ops.d.ts +11 -3
- package/dist/platform/ops/orgs.ops.js +139 -5
- package/dist/platform/ops/outbox.ops.js +5 -5
- package/dist/platform/route-schemas.js +3 -0
- package/dist/roles/worker-role.d.ts +2 -3
- package/dist/roles/worker-role.js +3 -13
- package/dist/runtime/checkpointer.d.ts +3 -0
- package/dist/runtime/checkpointer.js +7 -4
- package/dist/runtime/context/build.d.ts +56 -18
- package/dist/runtime/context/build.js +143 -50
- package/dist/runtime/context/compaction.d.ts +1 -3
- package/dist/runtime/context/compaction.js +42 -8
- package/dist/runtime/context/run-context.js +1 -2
- package/dist/runtime/context/skills.d.ts +27 -56
- package/dist/runtime/context/skills.js +42 -114
- package/dist/runtime/context/tool-changes.d.ts +3 -3
- package/dist/runtime/context/tool-changes.js +6 -16
- package/dist/runtime/hook-calls.d.ts +6 -6
- package/dist/runtime/hook-calls.js +7 -7
- package/dist/runtime/langgraph-loop.js +9 -3
- package/dist/runtime/maintenance.d.ts +3 -11
- package/dist/runtime/maintenance.js +5 -20
- package/dist/runtime/model-call.d.ts +5 -0
- package/dist/runtime/model-call.js +48 -36
- package/dist/runtime/providers.d.ts +33 -35
- package/dist/runtime/providers.js +64 -109
- package/dist/runtime/run-context.service.js +7 -22
- package/dist/runtime/run-deletion.d.ts +6 -0
- package/dist/runtime/run-deletion.js +39 -16
- package/dist/runtime/run-execution.d.ts +56 -3
- package/dist/runtime/run-execution.js +81 -11
- package/dist/runtime/run-finish.js +2 -1
- package/dist/runtime/run-liveness.d.ts +11 -0
- package/dist/runtime/run-liveness.js +19 -0
- package/dist/runtime/run-orphan-check.job.js +2 -1
- package/dist/runtime/run-queue.js +8 -16
- package/dist/runtime/run-worker.d.ts +2 -2
- package/dist/runtime/run-worker.js +8 -6
- package/dist/runtime/step-log.d.ts +5 -0
- package/dist/runtime/step-log.js +9 -4
- package/dist/runtime/subagents/definition.d.ts +16 -20
- package/dist/runtime/subagents/definition.js +27 -27
- package/dist/runtime/subagents/dispatch.d.ts +6 -2
- package/dist/runtime/subagents/dispatch.js +17 -3
- package/dist/runtime/subagents/org-agents.js +1 -2
- package/dist/runtime/subagents/preamble.d.ts +3 -2
- package/dist/runtime/subagents/preamble.js +3 -2
- package/dist/runtime/subagents/render.d.ts +1 -2
- package/dist/runtime/subagents/render.js +1 -2
- package/dist/runtime/subagents/skill-fork.d.ts +2 -4
- package/dist/runtime/subagents/template-skills.d.ts +47 -0
- package/dist/runtime/subagents/template-skills.js +76 -0
- package/dist/runtime/waits.js +3 -1
- package/dist/schedules/effective-settings.d.ts +9 -3
- package/dist/schedules/effective-settings.js +5 -4
- package/dist/schedules/fire.js +11 -0
- package/dist/schedules/scheduled-tasks.service.js +5 -0
- package/dist/schedules/unattended.d.ts +2 -0
- package/dist/schedules/unattended.js +6 -1
- package/dist/skills/agent-skills.service.js +1 -2
- package/dist/skills/catalog.d.ts +1 -3
- package/dist/skills/catalog.js +1 -3
- package/dist/skills/conversation-catalog.d.ts +1 -2
- package/dist/skills/conversation-catalog.js +1 -2
- package/dist/skills/usable.js +2 -3
- package/dist/storage/storage.service.js +9 -1
- package/dist/tools/approvals.service.js +2 -4
- package/dist/tools/builtin-names.d.ts +2 -9
- package/dist/tools/builtin-names.js +4 -13
- package/dist/tools/builtins/sandbox/bash.js +3 -3
- package/dist/tools/builtins/sandbox/common.d.ts +7 -13
- package/dist/tools/builtins/sandbox/common.js +8 -115
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
- package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
- package/dist/tools/builtins/sandbox/glob.js +1 -3
- package/dist/tools/builtins/sandbox/grep.js +3 -5
- package/dist/tools/builtins/sandbox/index.d.ts +8 -5
- package/dist/tools/builtins/sandbox/index.js +10 -5
- package/dist/tools/builtins/sandbox/read.js +3 -2
- package/dist/tools/builtins/tool-search.d.ts +4 -7
- package/dist/tools/builtins/tool-search.js +6 -10
- package/dist/tools/connector-account-policies.d.ts +30 -3
- package/dist/tools/connector-account-policies.js +54 -7
- package/dist/tools/connector-content.js +1 -0
- package/dist/tools/connectors.controller.d.ts +24 -11
- package/dist/tools/connectors.controller.js +35 -6
- package/dist/tools/connectors.schemas.d.ts +14 -1
- package/dist/tools/connectors.schemas.js +14 -2
- package/dist/tools/connectors.service.d.ts +22 -0
- package/dist/tools/connectors.service.js +65 -6
- package/dist/tools/drift.d.ts +6 -2
- package/dist/tools/drift.js +10 -5
- package/dist/tools/git-push-policy.d.ts +4 -1
- package/dist/tools/git-push-policy.js +3 -1
- package/dist/tools/info.d.ts +1 -7
- package/dist/tools/info.js +5 -18
- package/dist/tools/job-ids.d.ts +0 -4
- package/dist/tools/job-ids.js +1 -6
- package/dist/tools/pipeline.d.ts +4 -10
- package/dist/tools/pipeline.js +17 -62
- package/dist/tools/policy.d.ts +6 -2
- package/dist/tools/policy.js +14 -12
- package/dist/tools/registry.js +1 -5
- package/dist/ui/views.d.ts +5 -5
- package/dist/ui/views.js +10 -16
- package/package.json +3 -3
- package/src/migrations/0137_audit_org_idx.sql +5 -0
- package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
- package/src/migrations/0139_retire_legacy_forms.sql +183 -0
- package/src/migrations/0140_retire_history_forms.sql +148 -0
- package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
- package/src/migrations/0142_backfill_event_fields.sql +74 -0
- package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
- package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
- package/src/migrations/0145_org_network_allowances.sql +12 -0
- package/dist/admin/platform-audit.service.d.ts +0 -41
- package/dist/conversations/job-ids.d.ts +0 -6
- package/dist/conversations/job-ids.js +0 -6
- package/dist/extensions/job-ids.d.ts +0 -6
- package/dist/extensions/job-ids.js +0 -6
- package/dist/infra/queue/retired-schedulers.d.ts +0 -7
- package/dist/infra/queue/retired-schedulers.js +0 -9
- package/dist/orgs/job-ids.d.ts +0 -8
- package/dist/orgs/job-ids.js +0 -8
- package/dist/runtime/context/legacy-text.d.ts +0 -22
- package/dist/runtime/context/legacy-text.js +0 -37
- package/dist/runtime/job-ids.d.ts +0 -10
- package/dist/runtime/job-ids.js +0 -10
- package/dist/runtime/retired-schedulers.d.ts +0 -7
- package/dist/runtime/retired-schedulers.js +0 -31
- package/dist/storage/job-ids.d.ts +0 -6
- package/dist/storage/job-ids.js +0 -6
- package/dist/tools/legacy-data.d.ts +0 -34
- package/dist/tools/legacy-data.js +0 -76
- package/dist/tools/legacy-keys.d.ts +0 -51
- package/dist/tools/legacy-keys.js +0 -114
|
@@ -1,65 +1,78 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
1
2
|
/**
|
|
2
3
|
* The plugin scope sync's jobs as the outbox owes them (transactional outbox spec §8.1): a leaf
|
|
3
|
-
* module (type imports only), so the import confirm (`PluginImport`, below the scope service)
|
|
4
|
-
*
|
|
4
|
+
* module (type imports only), so the import confirm (`PluginImport`, below the scope service), the
|
|
5
|
+
* extension host's deploy (`ExtensionAdminOps`, `ExtensionAdmin`) and the CLI owe them without the
|
|
6
|
+
* sync. `scope-sync.ts` (the consumer side) re-exports these names.
|
|
5
7
|
*/
|
|
6
8
|
/** The scope sync queue (no `:` in the name). */
|
|
7
9
|
export const PLUGIN_SCOPE_QUEUE = "cap-kernel-plugin-scope";
|
|
8
|
-
/** The job
|
|
10
|
+
/** The job fanning one item out to every org: one {@link SCOPE_CHUNK_JOB} per org chunk. */
|
|
9
11
|
export const SCOPE_ITEM_JOB = "scope-item";
|
|
12
|
+
/** The job converging one item in one chunk of orgs (at most {@link SCOPE_ORG_CHUNK} of them). */
|
|
13
|
+
export const SCOPE_CHUNK_JOB = "scope-item-chunk";
|
|
10
14
|
/** The job converging every item in one org. */
|
|
11
15
|
export const SCOPE_ORG_JOB = "scope-org";
|
|
16
|
+
/** How many orgs one chunk job converges. */
|
|
17
|
+
export const SCOPE_ORG_CHUNK = 100;
|
|
12
18
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* retries it with its backoff) while the extension is not enabled on the deployment yet.
|
|
19
|
+
* Optional provider (a test seam): the chunk size instead of {@link SCOPE_ORG_CHUNK}, so a test
|
|
20
|
+
* with a few orgs fans out to several chunks.
|
|
16
21
|
*/
|
|
17
|
-
export const
|
|
18
|
-
/** How long after the confirmation's commit the backstop runs (the deploy has finished by then). */
|
|
19
|
-
export const SCOPE_BACKSTOP_DELAY_MS = 5 * 60_000;
|
|
22
|
+
export const SCOPE_ORG_CHUNK_SIZE = Symbol("SCOPE_ORG_CHUNK_SIZE");
|
|
20
23
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
24
|
+
* One item job per owing transaction (`xact`: its PostgreSQL transaction id, so two owes in one
|
|
25
|
+
* transaction are one job, and a later transaction's job is never swallowed by an earlier one
|
|
26
|
+
* still running; no `:`: item ids are UUIDs).
|
|
23
27
|
*/
|
|
24
|
-
export const
|
|
25
|
-
/**
|
|
26
|
-
export const
|
|
27
|
-
/** The backstop of the item job of a scope version (distinct from the immediate one). */
|
|
28
|
-
export const scopeBackstopJobId = (itemId, version) => `${scopeItemJobId(itemId, version)}-backstop`;
|
|
28
|
+
export const scopeItemJobId = (itemId, xact) => `scope-item-${itemId}-x${xact}`;
|
|
29
|
+
/** Chunk `n` of an item job (deterministic: a redelivered item job adds the same chunks). */
|
|
30
|
+
export const scopeChunkJobId = (itemJobId, n) => `${itemJobId}-c${n}`;
|
|
29
31
|
/** One org job at a time per org. */
|
|
30
32
|
export const scopeOrgJobId = (orgId) => `scope-org-${orgId}`;
|
|
33
|
+
/** The id of the transaction in context (assigned now if it has none yet). */
|
|
34
|
+
async function currentXact(db) {
|
|
35
|
+
const r = await sql `SELECT pg_current_xact_id()::text AS xact`.execute(db);
|
|
36
|
+
const xact = r.rows[0]?.xact;
|
|
37
|
+
if (xact === undefined)
|
|
38
|
+
throw new Error("no transaction id");
|
|
39
|
+
return xact;
|
|
40
|
+
}
|
|
31
41
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
export const scopeRetryJobId = (itemId, version, n) => `scope-item-${itemId}-${version}-r${n}`;
|
|
36
|
-
/**
|
|
37
|
-
* Owes the item's scope sync in the transaction in context, once per scope version (read in that
|
|
38
|
-
* transaction, so after its own bump); `backstop` owes the delayed backstop instead, due
|
|
39
|
-
* `backstopDelayMs` later (default {@link SCOPE_BACKSTOP_DELAY_MS}). A missing item owes nothing.
|
|
42
|
+
* Owes the item's scope sync in the transaction in context, one job per transaction (see
|
|
43
|
+
* {@link scopeItemJobId}). A missing item owes nothing.
|
|
40
44
|
*/
|
|
41
|
-
export async function oweScopeItem(outbox, db, itemId
|
|
45
|
+
export async function oweScopeItem(outbox, db, itemId) {
|
|
42
46
|
const row = await db
|
|
43
47
|
.selectFrom("catalog_items")
|
|
44
|
-
.select("
|
|
48
|
+
.select("id")
|
|
45
49
|
.where("id", "=", itemId)
|
|
46
50
|
.executeTakeFirst();
|
|
47
51
|
if (!row)
|
|
48
52
|
return;
|
|
49
|
-
if (opts.backstop === true) {
|
|
50
|
-
await outbox.add({
|
|
51
|
-
queue: PLUGIN_SCOPE_QUEUE,
|
|
52
|
-
name: SCOPE_BACKSTOP_JOB,
|
|
53
|
-
jobId: scopeBackstopJobId(itemId, row.scope_version),
|
|
54
|
-
data: { kind: "item", itemId, backstop: true },
|
|
55
|
-
runAt: new Date(Date.now() + (opts.backstopDelayMs ?? SCOPE_BACKSTOP_DELAY_MS)),
|
|
56
|
-
});
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
53
|
await outbox.add({
|
|
60
54
|
queue: PLUGIN_SCOPE_QUEUE,
|
|
61
55
|
name: SCOPE_ITEM_JOB,
|
|
62
|
-
jobId: scopeItemJobId(itemId,
|
|
56
|
+
jobId: scopeItemJobId(itemId, await currentXact(db)),
|
|
63
57
|
data: { kind: "item", itemId },
|
|
64
58
|
});
|
|
65
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Owes the scope sync of the live catalog item of an extension (its plugin, by name; at most one
|
|
62
|
+
* live item has a name) in the transaction that deploys it: the extension became enabled, a new
|
|
63
|
+
* version of an enabled one was installed, or its permissions were approved while enabled (or
|
|
64
|
+
* config-declared). The sync then installs it where its scope wants it on; a replica that has not
|
|
65
|
+
* loaded the extension yet fails the chunk job, and BullMQ retries it. A builtin item (on
|
|
66
|
+
* everywhere through its required extension) owes nothing.
|
|
67
|
+
*/
|
|
68
|
+
export async function oweDeployedExtensionSync(outbox, db, extensionName) {
|
|
69
|
+
const item = await db
|
|
70
|
+
.selectFrom("catalog_items")
|
|
71
|
+
.select("id")
|
|
72
|
+
.where("name", "=", extensionName)
|
|
73
|
+
.where("deleted_at", "is", null)
|
|
74
|
+
.where("builtin", "=", false)
|
|
75
|
+
.executeTakeFirst();
|
|
76
|
+
if (item)
|
|
77
|
+
await oweScopeItem(outbox, db, item.id);
|
|
78
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
2
2
|
/**
|
|
3
3
|
* Adds one org to a `named` item's list in the caller's transaction (the caller holds the item row
|
|
4
|
-
* `FOR UPDATE`):
|
|
4
|
+
* `FOR UPDATE`): audits `catalog.scope_changed` the way a scope change
|
|
5
5
|
* does (`from` / `to` with the sorted lists; `requestId` when a request asked for it). Nothing is
|
|
6
6
|
* written when the item is not `named` (or builtin) or the org is listed already. Returns whether
|
|
7
7
|
* the list changed; the caller enqueues the item's scope sync after the commit. Adding an org other
|
|
@@ -4,7 +4,7 @@ import { notifyItemShared } from "../inbox/org-notices.js";
|
|
|
4
4
|
import { assertShareable, shareGate } from "./ownership.js";
|
|
5
5
|
/**
|
|
6
6
|
* Adds one org to a `named` item's list in the caller's transaction (the caller holds the item row
|
|
7
|
-
* `FOR UPDATE`):
|
|
7
|
+
* `FOR UPDATE`): audits `catalog.scope_changed` the way a scope change
|
|
8
8
|
* does (`from` / `to` with the sorted lists; `requestId` when a request asked for it). Nothing is
|
|
9
9
|
* written when the item is not `named` (or builtin) or the org is listed already. Returns whether
|
|
10
10
|
* the list changed; the caller enqueues the item's scope sync after the commit. Adding an org other
|
|
@@ -36,7 +36,6 @@ export async function addScopeOrg(db, actor, item, orgId, opts = {}) {
|
|
|
36
36
|
await db
|
|
37
37
|
.updateTable("catalog_items")
|
|
38
38
|
.set({
|
|
39
|
-
scope_version: sql `scope_version + 1`,
|
|
40
39
|
updated_at: sql `now()`,
|
|
41
40
|
})
|
|
42
41
|
.where("id", "=", item.id)
|
|
@@ -4,14 +4,15 @@ import type { KernelLogger } from "../log.js";
|
|
|
4
4
|
import { PluginScopeSync, type ScopeJob } from "./scope-sync.js";
|
|
5
5
|
/**
|
|
6
6
|
* The consumer of {@link PLUGIN_SCOPE_QUEUE}: {@link PluginScopeSync} runs the `scope-item`,
|
|
7
|
-
* `scope-item-
|
|
8
|
-
*
|
|
7
|
+
* `scope-item-chunk` and `scope-org` jobs the outbox delivers (any other name fails the job). A
|
|
8
|
+
* chunk or org job with a pair whose extension this replica has not loaded yet throws, so BullMQ
|
|
9
|
+
* retries it with the registry's backoff; its last attempt installs anyway.
|
|
9
10
|
*/
|
|
10
11
|
export declare class PluginScopeSyncProcessor extends WorkerHost<Worker<ScopeJob>> {
|
|
11
12
|
private readonly sync;
|
|
12
13
|
private readonly log;
|
|
13
14
|
private readonly stopping;
|
|
14
|
-
constructor(sync: PluginScopeSync, log: Pick<KernelLogger, "error">);
|
|
15
|
+
constructor(sync: PluginScopeSync, log: Pick<KernelLogger, "error" | "warn">);
|
|
15
16
|
process(job: Job<ScopeJob>): Promise<void>;
|
|
16
17
|
/** Starts consuming (worker role, after the extensions loaded; built with `autorun: false`). */
|
|
17
18
|
start(): void;
|
|
@@ -13,11 +13,12 @@ import { configuredProcessor } from "../infra/queue/configured-processor.js";
|
|
|
13
13
|
import { runJob } from "../infra/queue/run-job.js";
|
|
14
14
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
15
15
|
import { CatalogModule } from "./catalog.module.js";
|
|
16
|
-
import { PLUGIN_SCOPE_CONCURRENCY, PLUGIN_SCOPE_QUEUE, PluginScopeSync,
|
|
16
|
+
import { PLUGIN_SCOPE_CONCURRENCY, PLUGIN_SCOPE_QUEUE, PluginScopeSync, SCOPE_CHUNK_JOB, SCOPE_ITEM_JOB, SCOPE_ORG_JOB, ScopeSyncDeferred, } from "./scope-sync.js";
|
|
17
17
|
/**
|
|
18
18
|
* The consumer of {@link PLUGIN_SCOPE_QUEUE}: {@link PluginScopeSync} runs the `scope-item`,
|
|
19
|
-
* `scope-item-
|
|
20
|
-
*
|
|
19
|
+
* `scope-item-chunk` and `scope-org` jobs the outbox delivers (any other name fails the job). A
|
|
20
|
+
* chunk or org job with a pair whose extension this replica has not loaded yet throws, so BullMQ
|
|
21
|
+
* retries it with the registry's backoff; its last attempt installs anyway.
|
|
21
22
|
*/
|
|
22
23
|
let PluginScopeSyncProcessor = class PluginScopeSyncProcessor extends WorkerHost {
|
|
23
24
|
sync;
|
|
@@ -30,10 +31,16 @@ let PluginScopeSyncProcessor = class PluginScopeSyncProcessor extends WorkerHost
|
|
|
30
31
|
}
|
|
31
32
|
process(job) {
|
|
32
33
|
return runJob(PLUGIN_SCOPE_QUEUE, job, () => {
|
|
33
|
-
if (![SCOPE_ITEM_JOB,
|
|
34
|
+
if (![SCOPE_ITEM_JOB, SCOPE_CHUNK_JOB, SCOPE_ORG_JOB].includes(job.name)) {
|
|
34
35
|
throw new Error(`unknown plugin scope job ${job.name}`);
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
+
if (job.id === undefined)
|
|
38
|
+
throw new Error("a plugin scope job has no id");
|
|
39
|
+
return this.sync.process(job.data, {
|
|
40
|
+
jobId: job.id,
|
|
41
|
+
finalAttempt: job.attemptsMade + 1 >= (job.opts.attempts ?? 1),
|
|
42
|
+
signal: this.stopping.signal,
|
|
43
|
+
});
|
|
37
44
|
});
|
|
38
45
|
}
|
|
39
46
|
/** Starts consuming (worker role, after the extensions loaded; built with `autorun: false`). */
|
|
@@ -46,7 +53,12 @@ let PluginScopeSyncProcessor = class PluginScopeSyncProcessor extends WorkerHost
|
|
|
46
53
|
await this.worker.close();
|
|
47
54
|
}
|
|
48
55
|
failed(job, err) {
|
|
49
|
-
|
|
56
|
+
const meta = { name: job?.name, jobId: job?.id, attempt: job?.attemptsMade, err };
|
|
57
|
+
// waiting for a replica to load an extension is expected: retried with the backoff
|
|
58
|
+
if (err instanceof ScopeSyncDeferred)
|
|
59
|
+
this.log.warn("plugin scope job deferred", meta);
|
|
60
|
+
else
|
|
61
|
+
this.log.error("plugin scope job failed", meta);
|
|
50
62
|
}
|
|
51
63
|
error(err) {
|
|
52
64
|
this.log.error("plugin scope worker error", { err });
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ExtensionLifecycle } from "../extensions/lifecycle.js";
|
|
2
1
|
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
3
2
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
3
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
@@ -27,92 +26,90 @@ import { type ScopeJob } from "./scope-jobs.js";
|
|
|
27
26
|
* extension). A failed install, uninstall or dependency install is logged, audited
|
|
28
27
|
* `plugin.scope_sync_failed`, kept as the pair's open failure (`plugin_scope_sync_failures`, the
|
|
29
28
|
* super admin's inbox, until a later sync of the pair does not fail) and not retried until the next
|
|
30
|
-
*
|
|
31
|
-
* touching the pair's row, so an older failure stays open.
|
|
29
|
+
* sync of the item. An error outside those steps (a read, the failure write itself) ends the attempt
|
|
30
|
+
* without touching the pair's row, so an older failure stays open.
|
|
32
31
|
*
|
|
33
|
-
* Jobs (queue {@link PLUGIN_SCOPE_QUEUE})
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
32
|
+
* Jobs (queue {@link PLUGIN_SCOPE_QUEUE}), all owed through the outbox (transactional outbox spec
|
|
33
|
+
* §8.1), so none is lost:
|
|
34
|
+
* - `scope-item` (`scope-item-<itemId>-x<xact>`, one per owing transaction): owed by every
|
|
35
|
+
* transaction that changes what the item's sync converges to: its scope, disabled flag, list,
|
|
36
|
+
* owner or platform version, an import's commit that deploys no extension, and the deploy of its
|
|
37
|
+
* extension (`oweDeployedExtensionSync`: enabled, a new version of an enabled one, permissions
|
|
38
|
+
* approved). It fans out: one `scope-item-chunk` per chunk of orgs (`<item job id>-c<n>`, at
|
|
39
|
+
* most {@link SCOPE_ORG_CHUNK} orgs each), all owed in one transaction;
|
|
40
|
+
* - `scope-item-chunk`: converges the item in its orgs;
|
|
41
|
+
* - `scope-org` (`scope-org-<orgId>`): every item in one org, owed by the org's creation.
|
|
42
|
+
* A migration that changes a scope inserts its outbox rows itself. One BullMQ retry policy
|
|
43
|
+
* (registry): a chunk or org job whose extension is enabled on the deployment but not loaded on
|
|
44
|
+
* this replica yet fails after converging its other pairs, so BullMQ retries it with its backoff
|
|
45
|
+
* (on any replica); its last attempt installs anyway and records what fails. Pairs of one org are
|
|
46
|
+
* serialized across replicas by a Redis lock per org; the installer's org row lock and its
|
|
47
|
+
* one-live-install rule are the backstop.
|
|
42
48
|
*/
|
|
43
|
-
export { PLUGIN_SCOPE_QUEUE,
|
|
44
|
-
/** How many delayed retries an item job gets while its extension is not loaded here (P3-38). */
|
|
45
|
-
export declare const SCOPE_LOAD_RETRIES = 6;
|
|
46
|
-
/** The delay of each such retry. */
|
|
47
|
-
export declare const SCOPE_LOAD_RETRY_DELAY_MS = 5000;
|
|
48
|
-
/** How long a pair waits for this replica's reconcile before deferring (P3-38). */
|
|
49
|
-
export declare const SCOPE_RECONCILE_WAIT_MS = 10000;
|
|
50
|
-
/**
|
|
51
|
-
* Awaits this replica's extension reconcile for at most `ms` (a slower one carries on in the
|
|
52
|
-
* background); a failure only warns.
|
|
53
|
-
*/
|
|
54
|
-
export declare function reconcileWithin(lifecycle: Pick<ExtensionLifecycle, "reconcile">, reason: string, ms: number, log: Pick<KernelLogger, "warn">): Promise<void>;
|
|
49
|
+
export { PLUGIN_SCOPE_QUEUE, SCOPE_CHUNK_JOB, SCOPE_ITEM_JOB, SCOPE_ORG_CHUNK, SCOPE_ORG_CHUNK_SIZE, SCOPE_ORG_JOB, type ScopeJob, scopeChunkJobId, scopeItemJobId, scopeOrgJobId, } from "./scope-jobs.js";
|
|
55
50
|
/**
|
|
56
51
|
* What a sync of one (item, org) did. `deferred`: the plugin's extension is enabled on the
|
|
57
|
-
* deployment but not loaded on this replica yet (P3-38); the
|
|
52
|
+
* deployment but not loaded on this replica yet (P3-38); the job fails for a BullMQ retry.
|
|
58
53
|
*/
|
|
59
54
|
export type ScopeSyncResult = "installed" | "removed" | "needs_config" | "unchanged" | "deferred";
|
|
60
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* A chunk or org job with a pair whose extension this replica has not loaded yet (P3-38): thrown
|
|
57
|
+
* after its other pairs converged, so BullMQ retries the job with its backoff.
|
|
58
|
+
*/
|
|
59
|
+
export declare class ScopeSyncDeferred extends Error {
|
|
60
|
+
readonly itemIds: string[];
|
|
61
|
+
constructor(itemIds: string[]);
|
|
62
|
+
}
|
|
63
|
+
/** How a job runs: its BullMQ id and whether this is its last attempt. */
|
|
64
|
+
export interface ScopeJobRun {
|
|
65
|
+
/** The job's id (an item job's chunks are named after it). */
|
|
66
|
+
jobId: string;
|
|
67
|
+
/** The job's last attempt: a pair whose extension is not loaded here is attempted anyway. */
|
|
68
|
+
finalAttempt: boolean;
|
|
69
|
+
/** Stops between pairs (the worker closing). */
|
|
70
|
+
signal?: AbortSignal;
|
|
71
|
+
}
|
|
72
|
+
/** The worker's concurrency (per replica): how many chunk, item and org jobs run at once. */
|
|
61
73
|
export declare const PLUGIN_SCOPE_CONCURRENCY = 2;
|
|
74
|
+
/** `ids` in chunks of `size` (the last one shorter). */
|
|
75
|
+
export declare function chunked<T>(ids: readonly T[], size: number): T[][];
|
|
62
76
|
export declare class PluginScopeSync {
|
|
63
77
|
private readonly kdb;
|
|
64
78
|
private readonly outbox;
|
|
65
79
|
private readonly installer;
|
|
66
80
|
private readonly registry;
|
|
67
|
-
/** This replica's reconcile, awaited (bounded) before deferring an install (P3-38). */
|
|
68
|
-
private readonly lifecycle;
|
|
69
81
|
private readonly locks;
|
|
70
82
|
private readonly log;
|
|
71
83
|
readonly txHost: TransactionHost;
|
|
72
|
-
/**
|
|
73
|
-
private readonly
|
|
74
|
-
constructor(kdb: KernelDb, outbox: Pick<OutboxService, "add">, installer: PluginInstaller, registry: ExtensionRegistry,
|
|
75
|
-
/**
|
|
76
|
-
|
|
77
|
-
/** The backstop's delay (a test seam; default {@link SCOPE_BACKSTOP_DELAY_MS}). */
|
|
78
|
-
backstopDelayMs?: number);
|
|
84
|
+
/** Orgs per chunk job (a test seam; default {@link SCOPE_ORG_CHUNK}). */
|
|
85
|
+
private readonly chunkSize;
|
|
86
|
+
constructor(kdb: KernelDb, outbox: Pick<OutboxService, "add" | "addMany">, installer: PluginInstaller, registry: ExtensionRegistry, locks: LockService, log: KernelLogger, txHost: TransactionHost,
|
|
87
|
+
/** Orgs per chunk job (a test seam; default {@link SCOPE_ORG_CHUNK}). */
|
|
88
|
+
chunkSize?: number);
|
|
79
89
|
private get db();
|
|
80
90
|
/**
|
|
81
|
-
* Owes the sync of an item in every org
|
|
82
|
-
*
|
|
91
|
+
* Owes the sync of an item in every org in the transaction in context (one job per
|
|
92
|
+
* transaction), the transaction that changes what it converges to.
|
|
83
93
|
*/
|
|
84
94
|
enqueueItem(itemId: string): Promise<void>;
|
|
85
|
-
/**
|
|
86
|
-
* Owes the delayed backstop of the item's sync (ruling R24) in the transaction in context: a
|
|
87
|
-
* confirmation owes it before (or with) its deploy, so a crash before its post-deploy add still
|
|
88
|
-
* converges the orgs.
|
|
89
|
-
*/
|
|
90
|
-
enqueueBackstop(itemId: string): Promise<void>;
|
|
91
95
|
/** Owes the sync of every item in an org, in the transaction that creates the org. */
|
|
92
96
|
enqueueOrg(orgId: string): Promise<void>;
|
|
93
97
|
/**
|
|
94
|
-
* One job:
|
|
95
|
-
*
|
|
96
|
-
|
|
97
|
-
process(data: ScopeJob, signal?: AbortSignal): Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* A backstop job (ruling R24) runs only once the item's extension is loaded here or enabled on
|
|
100
|
-
* the deployment; otherwise it throws, so BullMQ retries it with its backoff (bounded by its
|
|
101
|
-
* attempts) and no pair records a `catalog.not_deployed` failure that nothing would retry. An item without an
|
|
102
|
-
* extension, or one no longer live (deleted, disabled, still waiting, builtin), passes: its pairs
|
|
103
|
-
* converge (or change nothing) as for an immediate job.
|
|
98
|
+
* One job: an item job fans out to its chunk jobs; a chunk job converges the item in its orgs,
|
|
99
|
+
* an org job every item in the org. A pair deferred because its extension is not loaded here
|
|
100
|
+
* fails the job after the others ({@link ScopeSyncDeferred}), unless this is its last attempt.
|
|
104
101
|
*/
|
|
105
|
-
|
|
102
|
+
process(data: ScopeJob, run: ScopeJobRun): Promise<void>;
|
|
106
103
|
/**
|
|
107
|
-
* Owes
|
|
108
|
-
*
|
|
104
|
+
* Owes one chunk job per {@link chunkSize} live orgs of the item job `jobId`, in one
|
|
105
|
+
* transaction (a redelivered item job owes the same ids again: deduped).
|
|
109
106
|
*/
|
|
110
|
-
private
|
|
107
|
+
private fanOut;
|
|
111
108
|
/**
|
|
112
109
|
* Whether the install of the item's `version` may go ahead on this replica (P3-38): its
|
|
113
110
|
* extension is loaded here, or it is not enabled on the deployment (the install reports
|
|
114
|
-
* `catalog.not_deployed` as before). Enabled but not loaded here
|
|
115
|
-
*
|
|
111
|
+
* `catalog.not_deployed` as before). Enabled but not loaded here (its deploy owed this sync, and
|
|
112
|
+
* this replica's reconcile has not caught up yet) -> false, unless this is the job's last try.
|
|
116
113
|
*/
|
|
117
114
|
private extensionReady;
|
|
118
115
|
/** Converges one (item, org), under the org's sync lock; `signal` ends the wait for it. */
|