@bastani/atomic 0.10.11-alpha.1 → 0.10.11-alpha.2
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/CHANGELOG.md +56 -0
- package/dist/_shared/dist-KOELCESV.js +2 -2
- package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
- package/dist/_shared/lib-4PES5P4V.js +2 -2
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +7 -7
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +7 -7
- package/dist/_shared/mode-shared-2QJSCUM6.js +7 -7
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
- package/dist/_shared/runtime-O4KCSG4C.js +5 -5
- package/dist/_shared/{sdk-AVFII7NK.js → sdk-IQMULKFU.js} +2438 -470
- package/dist/_shared/sdk-IQMULKFU.js.map +1 -0
- package/dist/_shared/session-data-AHTU7IS6.js +3 -3
- package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
- package/dist/_shared/settings-startup-8-DNZ2RIHM.js +1 -1
- package/dist/_shared/{settings-startup-4QCVCI53.js → settings-startup-HXQLSUWM.js} +8 -2
- package/dist/_shared/settings-startup-HXQLSUWM.js.map +1 -0
- package/dist/_shared/{startup-0-0-57KF6LZH.js → startup-0-0-3IXNMFM2.js} +392 -15
- package/dist/_shared/startup-0-0-3IXNMFM2.js.map +1 -0
- package/dist/_shared/{startup-0-1-GIY75K46.js → startup-0-1-7T2IAE7J.js} +51 -243
- package/dist/_shared/startup-0-1-7T2IAE7J.js.map +1 -0
- package/dist/_shared/{startup-0-2-27OWFHV6.js → startup-0-2-5QHPCEON.js} +225 -7
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -0
- package/dist/_shared/{startup-0-3-T4DVFYWX.js → startup-0-3-4ZYBYQNM.js} +273 -14
- package/dist/_shared/startup-0-3-4ZYBYQNM.js.map +1 -0
- package/dist/_shared/startup-0-4-ZMJV547D.js +6 -6
- package/dist/_shared/startup-0-5-YDW47QX6.js +7 -7
- package/dist/_shared/startup-10-0-TDQNBDDL.js +7 -7
- package/dist/_shared/startup-12-0-55AAXBJZ.js +2 -2
- package/dist/_shared/startup-14-0-MLX36RBG.js +4 -4
- package/dist/_shared/startup-15-0-YUKGAC63.js +5 -5
- package/dist/_shared/startup-15-1-4S7FLMNG.js +7 -7
- package/dist/_shared/startup-8-0-34CBHPZH.js +421 -84
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/startup-8-1-X32CYSXB.js +77 -13
- package/dist/_shared/startup-8-1-X32CYSXB.js.map +1 -1
- package/dist/_shared/storage-command-7MGXLJGZ.js +7 -5
- package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/tree-outline-MUEPK5B7.js +3 -3
- package/dist/builtin/intercom/CHANGELOG.md +11 -0
- package/dist/builtin/intercom/broker/broker.bundle.mjs +205 -82
- package/dist/builtin/intercom/broker/sql-lease-store.ts +38 -27
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +228 -65
- package/dist/builtin/intercom/broker/sql-schema.ts +82 -27
- package/dist/builtin/intercom/index.bundle.mjs +1 -1
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +6 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/cli/args.js +2 -2
- package/dist/cli/auth-cli.code.js +4 -4
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +2 -2
- package/dist/cli/blueprint-command.impl.js +3 -3
- package/dist/cli/blueprint-command.js +3 -3
- package/dist/cli/intercom-command.code.js +3 -3
- package/dist/cli/intercom-command.impl.js +3 -3
- package/dist/cli/intercom-command.js +3 -3
- package/dist/cli/list-models.code.js +2 -2
- package/dist/cli/list-models.impl.js +3 -3
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/session-picker.code.js +2 -2
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +2 -2
- package/dist/cli/startup-ui.impl.js +3 -3
- package/dist/cli/startup-ui.js +3 -3
- package/dist/cli/storage-command.impl.js +3 -3
- package/dist/cli/storage-command.js +3 -3
- package/dist/cli/storage-search-session.code.js +2 -2
- package/dist/cli/storage-search-session.impl.js +3 -3
- package/dist/cli/storage-search-session.js +3 -3
- package/dist/cli/team-command.code.js +2 -2
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +2 -2
- package/dist/core/debug.impl.js +3 -3
- package/dist/core/debug.js +3 -3
- package/dist/core/export-html/card-projection.impl.js +3 -3
- package/dist/core/export-html/card-projection.js +3 -3
- package/dist/core/export-html/index.code.js +2 -2
- package/dist/core/export-html/index.impl.js +3 -3
- package/dist/core/export-html/index.js +3 -3
- package/dist/core/export-html/json-spans.impl.js +3 -3
- package/dist/core/export-html/json-spans.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.code.js +1 -1
- package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.js +3 -3
- package/dist/core/export-html/tool-renderer.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/extensions/jiti-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-loader.js +3 -3
- package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-static-loader.js +3 -3
- package/dist/core/extensions/loader-host-modules.code.js +1 -1
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/extensions/loader-virtual-modules.js +1 -1
- package/dist/core/extensions/runner-context.js +2 -2
- package/dist/core/intercom-broker-control-host.code.js +1 -1
- package/dist/core/intercom-broker-control-host.impl.js +3 -3
- package/dist/core/intercom-broker-control-host.js +3 -3
- package/dist/core/intercom-broker-control.code.js +3 -3
- package/dist/core/intercom-broker-control.impl.js +3 -3
- package/dist/core/intercom-broker-control.js +3 -3
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/sdk.code.js +3 -3
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +26 -14
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-list.impl.js +3 -3
- package/dist/core/session-manager-list.js +3 -3
- package/dist/core/session-manager.code.js +3 -3
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-open-markers.js +3 -0
- package/dist/core/session-open-markers.js.map +1 -0
- package/dist/core/session-storage.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/storage/added-exports.js +3 -0
- package/dist/core/storage/added-exports.js.map +1 -1
- package/dist/core/storage/database.d.ts +37 -0
- package/dist/core/storage/database.js.map +1 -1
- package/dist/core/storage/index.d.ts +1 -1
- package/dist/core/storage/index.js +2 -2
- package/dist/core/storage/index.js.map +1 -1
- package/dist/core/storage/migrations.d.ts +12 -3
- package/dist/core/storage/migrations.js +24 -11
- package/dist/core/storage/migrations.js.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +31 -2
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.js +86 -2
- package/dist/core/storage/node-sqlite.js.map +1 -1
- package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
- package/dist/core/storage/offline-snapshot-file.js +3 -3
- package/dist/core/storage/prefix.js +5 -0
- package/dist/core/storage/prefix.js.map +1 -1
- package/dist/core/storage/provider.js +2 -2
- package/dist/core/storage/schema-catalog.d.ts +82 -4
- package/dist/core/storage/schema-catalog.js +242 -32
- package/dist/core/storage/schema-catalog.js.map +1 -1
- package/dist/core/storage/selection.js +2 -2
- package/dist/core/storage/session/branch-fork-source.code.js +9 -8
- package/dist/core/storage/session/branch-fork-source.code.js.map +1 -1
- package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
- package/dist/core/storage/session/branch-fork-source.js +3 -3
- package/dist/core/storage/session/card-view.impl.js +3 -3
- package/dist/core/storage/session/card-view.js +3 -3
- package/dist/core/storage/session/child-reader.code.js +4 -4
- package/dist/core/storage/session/child-reader.impl.js +3 -3
- package/dist/core/storage/session/child-reader.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.js +3 -3
- package/dist/core/storage/session/errors.js +1 -1
- package/dist/core/storage/session/expanded-child-details.code.js +3 -3
- package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
- package/dist/core/storage/session/expanded-child-details.js +3 -3
- package/dist/core/storage/session/fork-detach.d.ts +118 -0
- package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.js +3 -3
- package/dist/core/storage/session/fork-row-index.impl.js +3 -3
- package/dist/core/storage/session/fork-row-index.js +3 -3
- package/dist/core/storage/session/fork-schema.js +53 -0
- package/dist/core/storage/session/fork-schema.js.map +1 -0
- package/dist/core/storage/session/fork-segments.d.ts +58 -0
- package/dist/core/storage/session/fork-staging.code.js +3 -3
- package/dist/core/storage/session/fork-staging.impl.js +3 -3
- package/dist/core/storage/session/fork-staging.js +3 -3
- package/dist/core/storage/session/fork-sweep.js +61 -0
- package/dist/core/storage/session/fork-sweep.js.map +1 -0
- package/dist/core/storage/session/fork-window.code.js +4 -4
- package/dist/core/storage/session/fork-window.impl.js +3 -3
- package/dist/core/storage/session/fork-window.js +3 -3
- package/dist/core/storage/session/history-pages.impl.js +3 -3
- package/dist/core/storage/session/history-pages.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.d.ts +37 -1
- package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.js +3 -3
- package/dist/core/storage/session/memory-session-store.impl.js +3 -3
- package/dist/core/storage/session/memory-session-store.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.js +3 -3
- package/dist/core/storage/session/released-history-files.code.js +3 -3
- package/dist/core/storage/session/released-history-files.impl.js +3 -3
- package/dist/core/storage/session/released-history-files.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.code.js +1 -1
- package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.js +3 -3
- package/dist/core/storage/session/session-resume.impl.js +3 -3
- package/dist/core/storage/session/session-resume.js +3 -3
- package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
- package/dist/core/storage/session/snapshot-cut.js +3 -3
- package/dist/core/storage/session/snapshot-history.code.js +4 -4
- package/dist/core/storage/session/snapshot-history.impl.js +3 -3
- package/dist/core/storage/session/snapshot-history.js +3 -3
- package/dist/core/storage/session/sql-session-store.code.js +1 -1
- package/dist/core/storage/session/sql-session-store.d.ts +349 -12
- package/dist/core/storage/session/sql-session-store.impl.js +4 -4
- package/dist/core/storage/session/sql-session-store.js +4 -4
- package/dist/core/storage/session/tree-outline.impl.js +3 -3
- package/dist/core/storage/session/tree-outline.js +3 -3
- package/dist/core/storage/session/tree-presentation.impl.js +3 -3
- package/dist/core/storage/session/tree-presentation.js +3 -3
- package/dist/core/storage/session/types.d.ts +22 -0
- package/dist/core/storage/sqlite-facade.d.ts +17 -1
- package/dist/core/storage/sqlite-facade.js +33 -0
- package/dist/core/storage/sqlite-facade.js.map +1 -1
- package/dist/core/storage/storage-status.impl.js +3 -3
- package/dist/core/storage/storage-status.js +3 -3
- package/dist/core/storage/team.impl.js +3 -3
- package/dist/core/storage/team.js +3 -3
- package/dist/core/structured-output/index.code.js +1 -1
- package/dist/core/structured-output/index.impl.js +3 -3
- package/dist/core/structured-output/index.js +3 -3
- package/dist/core/tasks/task-completion-entry.impl.js +3 -3
- package/dist/core/tasks/task-completion-entry.js +3 -3
- package/dist/core/tasks/task-file-history.code.js +4 -4
- package/dist/core/tasks/task-file-history.impl.js +3 -3
- package/dist/core/tasks/task-file-history.js +3 -3
- package/dist/core/tasks/task-reference-archive.code.js +4 -4
- package/dist/core/tasks/task-reference-archive.js +3 -3
- package/dist/core/tasks/task-reference-identity.js +3 -3
- package/dist/core/tasks/task-reference-stream.impl.js +3 -3
- package/dist/core/tasks/task-reference-stream.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.js +3 -3
- package/dist/core/tasks/task-view-source.impl.js +3 -3
- package/dist/core/tasks/task-view-source.js +3 -3
- package/dist/core/tools/history-session.d.ts +2 -0
- package/dist/core/tools/read-url.code.js +2 -2
- package/dist/core/tools/read-url.impl.js +3 -3
- package/dist/core/tools/read-url.js +3 -3
- package/dist/core/worktree-snapshot/blob-store.d.ts +31 -0
- package/dist/core/worktree-snapshot/blob-store.js +164 -49
- package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
- package/dist/core/worktree-snapshot/errors.code.js +3 -3
- package/dist/core/worktree-snapshot/errors.impl.js +3 -3
- package/dist/core/worktree-snapshot/errors.js +3 -3
- package/dist/core/worktree-snapshot/fork-snapshot-index.js +121 -0
- package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -0
- package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
- package/dist/extensions/codemode/execute.code.js +2 -2
- package/dist/extensions/codemode/execute.impl.js +3 -3
- package/dist/extensions/codemode/execute.js +3 -3
- package/dist/extensions/codemode/renderer.code.js +1 -1
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +2 -2
- package/dist/extensions/mcp/cli.impl.js +3 -3
- package/dist/extensions/mcp/cli.js +3 -3
- package/dist/extensions/mcp/cli.lazy.code.js +2 -2
- package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
- package/dist/extensions/mcp/cli.lazy.js +3 -3
- package/dist/extensions/mcp/runtime.code.js +1 -1
- package/dist/extensions/mcp/runtime.impl.js +3 -3
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/index.js +6 -6
- package/dist/main-first-time-setup.code.js +2 -2
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.code.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
- package/dist/modes/print-mode.js +1 -1
- package/dist/package-manager-cli.code.js +5 -5
- package/dist/package-manager-cli.impl.js +3 -3
- package/dist/package-manager-cli.js +3 -3
- package/dist/rpc-entry.js +1 -1
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/2.js +1 -0
- package/dist/startup-stages/5.js +1 -1
- package/dist/startup-stages/7.js +5 -1
- package/dist/startup-stages/8.js +2 -2
- package/dist/utils/startup-database-spare.code.js +3 -3
- package/dist/utils/startup-database-spare.impl.js +3 -3
- package/dist/utils/startup-database-spare.js +3 -3
- package/dist/utils/tools-manager.code.js +1 -1
- package/dist/utils/tools-manager.impl.js +3 -3
- package/dist/utils/tools-manager.js +3 -3
- package/docs/guides/postgres-pgbouncer.md +14 -7
- package/docs/guides/postgres-tuning.md +9 -9
- package/docs/sessions.md +9 -0
- package/docs/storage.md +47 -6
- package/package.json +8 -8
- package/dist/_shared/sdk-AVFII7NK.js.map +0 -1
- package/dist/_shared/settings-startup-4QCVCI53.js.map +0 -1
- package/dist/_shared/startup-0-0-57KF6LZH.js.map +0 -1
- package/dist/_shared/startup-0-1-GIY75K46.js.map +0 -1
- package/dist/_shared/startup-0-2-27OWFHV6.js.map +0 -1
- package/dist/_shared/startup-0-3-T4DVFYWX.js.map +0 -1
|
@@ -16,11 +16,12 @@ import {
|
|
|
16
16
|
OUTBOX_EXPIRED_REASON,
|
|
17
17
|
OUTBOX_TARGET_MAX_BYTES,
|
|
18
18
|
OUTBOX_TARGET_MAX_ROWS,
|
|
19
|
-
type ClaimedOutboxRow,
|
|
20
19
|
type InvalidStateInput,
|
|
21
20
|
type IntercomBrokerStateOptions,
|
|
22
21
|
type OutboxClaim,
|
|
22
|
+
type OutboxClaimResult,
|
|
23
23
|
type OutboxClaimWriteRejection,
|
|
24
|
+
type OutboxDeliveredResult,
|
|
24
25
|
type OutboxEnqueueRequest,
|
|
25
26
|
type OutboxEnqueueResult,
|
|
26
27
|
type OutboxFrame,
|
|
@@ -33,6 +34,10 @@ import { addMissingColumns } from "./sql-add-column.js";
|
|
|
33
34
|
import { ensureBrokerSchema, withBrokerSchemaCatalog } from "./sql-schema.js";
|
|
34
35
|
|
|
35
36
|
const UNDELIVERED = "state IN ('queued', 'claimed')";
|
|
37
|
+
/** The setting a PostgreSQL claim transaction records in that its recipient has undelivered rows, and its locks are held. */
|
|
38
|
+
const CLAIM_GATE = "atomic.intercom_outbox_claim";
|
|
39
|
+
/** The most `markDelivered` calls one transaction settles together (#6560). */
|
|
40
|
+
const MARK_DELIVERED_BATCH_MAX = 100;
|
|
36
41
|
|
|
37
42
|
interface OutboxRecord extends SqliteRow {
|
|
38
43
|
readonly sequence: SqliteValue;
|
|
@@ -175,9 +180,9 @@ export function rowTransaction(): SqliteTransactionOptions {
|
|
|
175
180
|
/**
|
|
176
181
|
* S2 outbox on the shared storage adapter's database, in `<prefix>intercom_outbox`. Every read-modify-write runs in
|
|
177
182
|
* one `BEGIN IMMEDIATE` transaction, and every age is measured on the database clock. On a database whose transactions
|
|
178
|
-
* run concurrently (PostgreSQL), an enqueue holds its recipient's domain (`recipientTransaction`); a claim
|
|
179
|
-
* recipient's rows in sequence order and every write of a claimed row is one
|
|
180
|
-
* (`rowTransaction`), so no write waits for another recipient's (#6560).
|
|
183
|
+
* run concurrently (PostgreSQL), an enqueue holds its recipient's domain (`recipientTransaction`); a claim holds its
|
|
184
|
+
* recipient's claim domain and locks the recipient's rows in sequence order, and every write of a claimed row is one
|
|
185
|
+
* statement guarded by its claim token (`rowTransaction`), so no write waits for another recipient's (#6560).
|
|
181
186
|
*/
|
|
182
187
|
export function openSqlOutboxStore(options: IntercomBrokerStateOptions): Promise<SqlOutboxStore> {
|
|
183
188
|
// Its schema checks answer from one read of the catalog, shared with an open around it: a current schema costs
|
|
@@ -189,7 +194,7 @@ async function openOutboxStoreInCatalog(options: IntercomBrokerStateOptions): Pr
|
|
|
189
194
|
const { database } = options;
|
|
190
195
|
const table = `${validateStoragePrefix(options.prefix, dialectOf(database).name)}intercom_outbox`;
|
|
191
196
|
const { types, nowMs, greatest, lockClause, name: dialect } = dialectOf(database);
|
|
192
|
-
/**
|
|
197
|
+
/** Claim writes and expiry: each decides on the rows it locks (#6560). */
|
|
193
198
|
const fenced = rowTransaction();
|
|
194
199
|
const ageSince = (column: string) => greatest("0", `${nowMs} - ${column}`);
|
|
195
200
|
// In a serial transaction, so brokers opening a new store at once take turns creating it (#5054).
|
|
@@ -253,8 +258,6 @@ async function openOutboxStoreInCatalog(options: IntercomBrokerStateOptions): Pr
|
|
|
253
258
|
limit,
|
|
254
259
|
);
|
|
255
260
|
};
|
|
256
|
-
const isLive = (record: OutboxRecord, staleAfterMs: number): boolean =>
|
|
257
|
-
record.claim_age !== null && Number(record.claim_age) <= staleAfterMs;
|
|
258
261
|
|
|
259
262
|
/**
|
|
260
263
|
* Applies `assignments` (with their parameters) to the row only while `claim` is its current claim: one UPDATE whose
|
|
@@ -292,6 +295,89 @@ async function openOutboxStoreInCatalog(options: IntercomBrokerStateOptions): Pr
|
|
|
292
295
|
const settled = `failure_reason = ?, settled_at = ${nowMs},
|
|
293
296
|
claimant_id = NULL, claim_token = NULL, claim_renewed_at = NULL, saving_at = NULL`;
|
|
294
297
|
|
|
298
|
+
/**
|
|
299
|
+
* Settles each of `claims`, of distinct rows, as delivered, in one transaction: one UPDATE, sent with its start, that
|
|
300
|
+
* locks their rows in sequence order, as a claim locks a recipient's rows, and changes those whose claim is still
|
|
301
|
+
* current. Only when it changed fewer rows than it was given are the others read, to report why (#6560).
|
|
302
|
+
*/
|
|
303
|
+
const markDeliveredTogether = (claims: readonly OutboxClaim[]): Promise<OutboxDeliveredResult[]> => {
|
|
304
|
+
const current = claims.map(() => "(message_id = ? AND claim_token = ? AND claimant_id = ?)").join(" OR ");
|
|
305
|
+
const keys = claims.flatMap((claim) => [claim.messageId, claim.token, claim.claimantId]);
|
|
306
|
+
const write: SqliteStatement = {
|
|
307
|
+
sql: `UPDATE ${table} SET state = 'delivered', ${settled}
|
|
308
|
+
WHERE message_id IN (
|
|
309
|
+
SELECT message_id FROM ${table} WHERE state = 'claimed' AND (${current})
|
|
310
|
+
ORDER BY sequence${lockClause("update")}
|
|
311
|
+
) AND state = 'claimed' AND (${current})
|
|
312
|
+
RETURNING ${columns}`,
|
|
313
|
+
params: [null, ...keys, ...keys],
|
|
314
|
+
};
|
|
315
|
+
return database.transaction(
|
|
316
|
+
async (executor) => {
|
|
317
|
+
const written = new Map(
|
|
318
|
+
(await executor.all<OutboxRecord>(write.sql, ...write.params)).map((record) => [record.message_id, record]),
|
|
319
|
+
);
|
|
320
|
+
const others = claims.filter((claim) => !written.has(claim.messageId));
|
|
321
|
+
const found =
|
|
322
|
+
others.length === 0
|
|
323
|
+
? new Map<string, OutboxRecord>()
|
|
324
|
+
: new Map(
|
|
325
|
+
(
|
|
326
|
+
await executor.all<OutboxRecord>(
|
|
327
|
+
`SELECT ${columns} FROM ${table} WHERE message_id IN (${others.map(() => "?").join(", ")})`,
|
|
328
|
+
...others.map((claim) => claim.messageId),
|
|
329
|
+
)
|
|
330
|
+
).map((record) => [record.message_id, record]),
|
|
331
|
+
);
|
|
332
|
+
return claims.map((claim): OutboxDeliveredResult => {
|
|
333
|
+
const delivered = written.get(claim.messageId);
|
|
334
|
+
if (delivered !== undefined) return { status: "delivered", row: toRow(delivered) };
|
|
335
|
+
const record = found.get(claim.messageId);
|
|
336
|
+
if (record === undefined) return { status: "unknown" };
|
|
337
|
+
if (isSettled(record)) return { status: "settled", row: toRow(record) };
|
|
338
|
+
return { status: "stale" };
|
|
339
|
+
});
|
|
340
|
+
},
|
|
341
|
+
{ ...fenced, leading: [write] },
|
|
342
|
+
);
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* The `markDelivered` calls waiting for the transaction that settles them, in the order they were made. On PostgreSQL
|
|
347
|
+
* the calls made while one transaction settles others go together in the next, whose round trips they share, rather
|
|
348
|
+
* than two round trips each: one transaction at a time, so each commits after every call made before it (#6560).
|
|
349
|
+
*/
|
|
350
|
+
const deliveries: {
|
|
351
|
+
readonly claim: OutboxClaim;
|
|
352
|
+
readonly resolve: (result: OutboxDeliveredResult) => void;
|
|
353
|
+
readonly reject: (error: unknown) => void;
|
|
354
|
+
}[] = [];
|
|
355
|
+
let delivering = false;
|
|
356
|
+
const deliverQueued = async () => {
|
|
357
|
+
// Calls made in the same turn as the first go with it.
|
|
358
|
+
await undefined;
|
|
359
|
+
while (deliveries.length > 0) {
|
|
360
|
+
// The calls in order, up to one that names a row already in the batch: it goes in the next, so it finds the row as
|
|
361
|
+
// the call before it left it.
|
|
362
|
+
const rows = new Set<string>();
|
|
363
|
+
let count = 0;
|
|
364
|
+
while (
|
|
365
|
+
count < deliveries.length &&
|
|
366
|
+
count < MARK_DELIVERED_BATCH_MAX &&
|
|
367
|
+
!rows.has(deliveries[count]!.claim.messageId)
|
|
368
|
+
)
|
|
369
|
+
rows.add(deliveries[count++]!.claim.messageId);
|
|
370
|
+
const batch = deliveries.splice(0, count);
|
|
371
|
+
try {
|
|
372
|
+
const results = await markDeliveredTogether(batch.map(({ claim }) => claim));
|
|
373
|
+
batch.forEach(({ resolve }, index) => resolve(results[index]!));
|
|
374
|
+
} catch (error) {
|
|
375
|
+
for (const { reject } of batch) reject(error);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
delivering = false;
|
|
379
|
+
};
|
|
380
|
+
|
|
295
381
|
/**
|
|
296
382
|
* #4896: the recipient's undelivered rows and their frame bytes, read from `<table>_target_bytes` alone. Only rows an
|
|
297
383
|
* older broker wrote, without `frame_bytes`, are measured from their frames.
|
|
@@ -451,61 +537,131 @@ async function openOutboxStoreInCatalog(options: IntercomBrokerStateOptions): Pr
|
|
|
451
537
|
async claim(request) {
|
|
452
538
|
if (request.claimantId.length === 0) return invalid("empty-claimant-id");
|
|
453
539
|
if (request.targetIdentity.length === 0) return invalid("empty-target-identity");
|
|
454
|
-
|
|
455
|
-
//
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
540
|
+
const { claimantId, targetIdentity, staleAfterMs } = request;
|
|
541
|
+
// Each row's token: this claim's, with the row's sequence, so every claimed row has a token of its own.
|
|
542
|
+
const token = randomUUID();
|
|
543
|
+
const claimed = (records: readonly OutboxRecord[]): OutboxClaimResult => ({
|
|
544
|
+
status: "claimed",
|
|
545
|
+
rows: [...records]
|
|
546
|
+
.sort((first, second) => Number(first.sequence) - Number(second.sequence))
|
|
547
|
+
.map((record) => {
|
|
548
|
+
const row = toRow(record);
|
|
549
|
+
const claim = { messageId: row.messageId, claimantId, token: String(record.claim_token), attempt: row.claimAttempts };
|
|
550
|
+
return { row, claim };
|
|
551
|
+
}),
|
|
552
|
+
});
|
|
553
|
+
const claiming = `state = 'claimed', claim_attempts = claim_attempts + 1, claimant_id = ?,
|
|
554
|
+
claim_token = ? || ':' || CAST(sequence AS TEXT), claim_renewed_at = ${nowMs}, saving_at = NULL`;
|
|
555
|
+
if (dialect === "postgres") {
|
|
556
|
+
// A read and one claim statement, sent with the transaction's start and its commit: one round trip whether or not
|
|
557
|
+
// there is anything to claim (#6560). The claim statement locks the recipient's undelivered rows in sequence order, as every write of several rows
|
|
558
|
+
// locks them, and reads them in their newest versions, so a renewal or settlement of one waits for this claim, or
|
|
559
|
+
// this claim for it. It does not skip a locked row (SKIP LOCKED): an earlier row passed over could be handed out
|
|
560
|
+
// after a later one, and another claimant's live claim would go unseen. Another claimant's live claim holds
|
|
561
|
+
// every row; otherwise each row not live is claimed, and the claimant's own live claims stay in flight.
|
|
562
|
+
// The recipient's claims take turns: the lock domain `<outbox>_claims:<recipient>` is taken before the statement
|
|
563
|
+
// takes its snapshot. The statement sees only rows its snapshot holds, so without it a claim made meanwhile of a
|
|
564
|
+
// row queued meanwhile went unseen: this claim could take over a claimant's older row it was late to renew while
|
|
565
|
+
// that claimant held a newer one, and two brokers would hand out one recipient's messages at once, the newer
|
|
566
|
+
// possibly first. Sends, settlements and other recipients' claims do not take it.
|
|
567
|
+
// Only a recipient with undelivered rows needs the lock. A read sent first, `waiting`, takes it, with the
|
|
568
|
+
// database's lock shared, only when it finds such a row, so the common empty poll takes no lock at all. The read
|
|
569
|
+
// records what it found in a setting of the transaction, and the claim statement locks and claims rows only when
|
|
570
|
+
// the read found some: every claim acts under the lock, with a snapshot taken after it. A row queued after the
|
|
571
|
+
// read waits for the next claim, which its send's wake-up hint brings. An older driver takes the locks with the
|
|
572
|
+
// transaction's start instead, which is just as correct.
|
|
573
|
+
// While it waits for the locks, `waiting` holds the table's share lock. A broker that adds a column to the table
|
|
574
|
+
// under the database's lock at that moment ends one of the two with a deadlock error; a claim that fails so is
|
|
575
|
+
// taken again at the next scan, as after any failed claim.
|
|
576
|
+
const waiting: SqliteStatement = {
|
|
577
|
+
sql: `SELECT set_config('${CLAIM_GATE}', 'locked', true) AS waiting
|
|
578
|
+
WHERE EXISTS (SELECT 1 FROM ${table} WHERE target_identity = ? AND ${UNDELIVERED})`,
|
|
579
|
+
params: [targetIdentity],
|
|
580
|
+
};
|
|
581
|
+
const statement: SqliteStatement = {
|
|
582
|
+
sql: `WITH locked AS MATERIALIZED (
|
|
583
|
+
SELECT message_id, sequence, state, claimant_id, claim_renewed_at FROM ${table}
|
|
584
|
+
WHERE target_identity = ? AND ${UNDELIVERED}
|
|
585
|
+
AND current_setting('${CLAIM_GATE}', true) = 'locked'
|
|
586
|
+
ORDER BY sequence${lockClause("update")}
|
|
587
|
+
), live AS MATERIALIZED (
|
|
588
|
+
SELECT message_id, sequence, claimant_id FROM locked
|
|
589
|
+
WHERE state = 'claimed' AND claim_renewed_at IS NOT NULL AND ${ageSince("claim_renewed_at")} <= ?
|
|
590
|
+
), holder AS MATERIALIZED (
|
|
591
|
+
SELECT claimant_id FROM live WHERE claimant_id <> ? ORDER BY sequence LIMIT 1
|
|
592
|
+
), claimed AS (
|
|
593
|
+
UPDATE ${table} SET ${claiming}
|
|
594
|
+
WHERE message_id IN (SELECT message_id FROM locked)
|
|
595
|
+
AND message_id NOT IN (SELECT message_id FROM live)
|
|
596
|
+
AND NOT EXISTS (SELECT 1 FROM holder)
|
|
597
|
+
RETURNING ${columns}
|
|
598
|
+
)
|
|
599
|
+
SELECT claimed.*, (SELECT claimant_id FROM holder) AS holder
|
|
600
|
+
FROM (SELECT 1) AS answer LEFT JOIN claimed ON TRUE`,
|
|
601
|
+
params: [targetIdentity, staleAfterMs, claimantId, claimantId, token],
|
|
602
|
+
};
|
|
603
|
+
return database.transaction(
|
|
604
|
+
async (executor) => {
|
|
605
|
+
await executor.all(waiting.sql, ...waiting.params);
|
|
606
|
+
const records = await executor.all<OutboxRecord & { readonly holder: string | null }>(
|
|
607
|
+
statement.sql,
|
|
608
|
+
...statement.params,
|
|
609
|
+
);
|
|
610
|
+
const holder = records[0]?.holder ?? null;
|
|
611
|
+
if (holder !== null) return { status: "held", claimantId: holder } as const;
|
|
612
|
+
return claimed(records.filter((record) => record.message_id !== null));
|
|
613
|
+
},
|
|
614
|
+
{
|
|
615
|
+
concurrency: { kind: "serial", domain: `${table}_claims:${targetIdentity}` },
|
|
616
|
+
leading: [waiting, statement],
|
|
617
|
+
leadingOnly: true,
|
|
618
|
+
lockIfLeadingFinds: true,
|
|
619
|
+
},
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
// SQLite and libSQL: a write statement takes the database's write lock even when it changes nothing, so a read
|
|
623
|
+
// decides first, without it, whether there is anything to claim: empty scans (such as fan-out wake-up polls across
|
|
624
|
+
// idle sessions) cost one read. Linearizable: if a row commits after this snapshot, its enqueue writes a new
|
|
625
|
+
// wake-up hint. The same read answers a claim another claimant holds, or one of only the claimant's own rows in
|
|
626
|
+
// flight. Otherwise one statement claims the rows, deciding again on what it changes (#6560).
|
|
627
|
+
const live = (alias: string) =>
|
|
628
|
+
`${alias}.state = 'claimed' AND ${alias}.claim_renewed_at IS NOT NULL
|
|
629
|
+
AND ${ageSince(`${alias}.claim_renewed_at`)} <= ?`;
|
|
630
|
+
const heldBy = `SELECT live.claimant_id FROM ${table} live
|
|
631
|
+
WHERE live.target_identity = ? AND ${live("live")} AND live.claimant_id <> ?`;
|
|
632
|
+
const probe = () =>
|
|
633
|
+
database.get<{ holder: string | null; claimable: SqliteValue }>(
|
|
634
|
+
`SELECT (${heldBy} ORDER BY live.sequence LIMIT 1) AS holder, EXISTS (
|
|
635
|
+
SELECT 1 FROM ${table} pending WHERE pending.target_identity = ?
|
|
636
|
+
AND pending.${UNDELIVERED} AND NOT (${live("pending")})
|
|
637
|
+
) AS claimable`,
|
|
638
|
+
targetIdentity,
|
|
639
|
+
staleAfterMs,
|
|
640
|
+
claimantId,
|
|
641
|
+
targetIdentity,
|
|
642
|
+
staleAfterMs,
|
|
477
643
|
);
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
});
|
|
500
|
-
rows.push({
|
|
501
|
-
row,
|
|
502
|
-
claim: { messageId: row.messageId, claimantId: request.claimantId, token, attempt: row.claimAttempts },
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
// Sent with the commit: one round trip for the claim's reads, one for its writes (#6560).
|
|
506
|
-
await runLast(executor, ...claims);
|
|
507
|
-
return { status: "claimed", rows } as const;
|
|
508
|
-
}, { ...fenced, leading: [locking] });
|
|
644
|
+
const found = await probe();
|
|
645
|
+
if (found !== undefined && found.holder !== null) return { status: "held", claimantId: found.holder } as const;
|
|
646
|
+
if (Number(found?.claimable ?? 0) === 0) return { status: "claimed", rows: [] } as const;
|
|
647
|
+
const records = await database.all<OutboxRecord>(
|
|
648
|
+
`UPDATE ${table} SET ${claiming}
|
|
649
|
+
WHERE target_identity = ? AND ${UNDELIVERED} AND NOT (${live(table)}) AND NOT EXISTS (${heldBy})
|
|
650
|
+
RETURNING ${columns}`,
|
|
651
|
+
claimantId,
|
|
652
|
+
token,
|
|
653
|
+
targetIdentity,
|
|
654
|
+
staleAfterMs,
|
|
655
|
+
targetIdentity,
|
|
656
|
+
staleAfterMs,
|
|
657
|
+
claimantId,
|
|
658
|
+
);
|
|
659
|
+
if (records.length > 0) return claimed(records);
|
|
660
|
+
// Another claimant took the rows since the read, or they were settled: only then is the holder read again.
|
|
661
|
+
const again = await probe();
|
|
662
|
+
return again !== undefined && again.holder !== null
|
|
663
|
+
? ({ status: "held", claimantId: again.holder } as const)
|
|
664
|
+
: ({ status: "claimed", rows: [] } as const);
|
|
509
665
|
},
|
|
510
666
|
|
|
511
667
|
renewClaim(claim) {
|
|
@@ -541,10 +697,17 @@ async function openOutboxStoreInCatalog(options: IntercomBrokerStateOptions): Pr
|
|
|
541
697
|
},
|
|
542
698
|
|
|
543
699
|
markDelivered(claim) {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
700
|
+
if (dialect !== "postgres" || claim.messageId.length === 0 || claim.claimantId.length === 0)
|
|
701
|
+
return withClaim(claim, `state = 'delivered', ${settled}`, [null], (written) => ({
|
|
702
|
+
status: "delivered" as const,
|
|
703
|
+
row: toRow(written),
|
|
704
|
+
}));
|
|
705
|
+
return new Promise<OutboxDeliveredResult>((resolve, reject) => {
|
|
706
|
+
deliveries.push({ claim, resolve, reject });
|
|
707
|
+
if (delivering) return;
|
|
708
|
+
delivering = true;
|
|
709
|
+
void deliverQueued();
|
|
710
|
+
});
|
|
548
711
|
},
|
|
549
712
|
|
|
550
713
|
markFailed(claim, reason) {
|
|
@@ -7,7 +7,10 @@ import { dialectOf, ensureStorageSchema, type SqliteDatabase, type SqliteExecuto
|
|
|
7
7
|
* namespace, and without them every open checks its schema in a transaction, as before.
|
|
8
8
|
*/
|
|
9
9
|
const catalogApi: Partial<
|
|
10
|
-
Pick<
|
|
10
|
+
Pick<
|
|
11
|
+
typeof storage,
|
|
12
|
+
"storageSchemaCurrent" | "schemaCatalogOf" | "withStorageSchemaCatalog" | "restampStorageSchemaAtOpenEnd"
|
|
13
|
+
>
|
|
11
14
|
> = storage;
|
|
12
15
|
|
|
13
16
|
/**
|
|
@@ -30,7 +33,12 @@ export async function withBrokerSchemaCatalog<T>(
|
|
|
30
33
|
* Runs `setup`, a broker store's idempotent schema statements, in a transaction of its own, unless the prefix's ledger
|
|
31
34
|
* records `revision` for `store` already (#5218): on PostgreSQL a current schema runs no DDL, so a role with only DML
|
|
32
35
|
* privileges opens the store. Raise `revision` whenever `setup` creates or alters anything new. Inside an open that read
|
|
33
|
-
* the catalog (`withStorageSchemaCatalog`), a revision it found recorded skips the transaction too (#6560).
|
|
36
|
+
* the catalog (`withStorageSchemaCatalog`), a revision it found recorded skips the transaction too (#6560). On SQLite and
|
|
37
|
+
* libSQL the store's stamp records it. A setup that runs stamps nothing: later setups of the same open would leave its
|
|
38
|
+
* stamp behind, and stamping costs a new database's first open statements and a transaction. The next open finds the
|
|
39
|
+
* store in the catalog instead; there a setup whose objects the catalog holds is checked again, and a counter it seeds
|
|
40
|
+
* seeded, in the one transaction the open's end stamps every such store in, so later opens of a current schema take no
|
|
41
|
+
* write lock and answer every store from its stamp.
|
|
34
42
|
*/
|
|
35
43
|
export async function ensureBrokerSchema(
|
|
36
44
|
database: SqliteDatabase,
|
|
@@ -41,30 +49,70 @@ export async function ensureBrokerSchema(
|
|
|
41
49
|
): Promise<void> {
|
|
42
50
|
const schema = { ledger: storageMigrationTable(prefix), domain: `intercom-${store}`, revision };
|
|
43
51
|
if (await catalogApi.storageSchemaCurrent?.(database, schema)) return;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
const found = await foundInCatalog(database, setup);
|
|
53
|
+
if (found?.present === true) {
|
|
54
|
+
const options = { verify: found.verify, deferred: found.seeds };
|
|
55
|
+
if (catalogApi.restampStorageSchemaAtOpenEnd?.(database, schema, setup, options) === true) return;
|
|
56
|
+
if (!found.seeds) return;
|
|
57
|
+
}
|
|
58
|
+
const dialect = dialectOf(database);
|
|
59
|
+
await database.transaction(async (tx) => {
|
|
60
|
+
if (!dialect.versionedMigrations) {
|
|
61
|
+
await setup(tx);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
await ensureStorageSchema(tx, dialect, schema, async () => {
|
|
47
65
|
await setup(tx);
|
|
48
|
-
})
|
|
49
|
-
);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
// Stamped where the end of the open takes a transaction for other stores anyway, as after a repair or an upgrade.
|
|
69
|
+
if (!dialect.versionedMigrations)
|
|
70
|
+
catalogApi.restampStorageSchemaAtOpenEnd?.(database, schema, setup, { verify: found?.verify, alongside: true });
|
|
50
71
|
}
|
|
51
72
|
|
|
52
73
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* Statements on an existing object of that kind do nothing, so skipping them is the same. The setup runs against a
|
|
58
|
-
* handle that only collects the SQL it would run; any other call, or a statement of another form, and it runs as
|
|
59
|
-
* before. False outside such an open, and on PostgreSQL, whose ledger decides.
|
|
74
|
+
* Asks the open of `database` in progress to stamp `store`'s `setup` at its end, on SQLite and libSQL, where the open
|
|
75
|
+
* found the store current in the catalog, `verify` says, rather than by its stamp, which a schema change since left
|
|
76
|
+
* behind: the next open then answers from the stamp (#6560). Does nothing where the stamp is current, elsewhere, and
|
|
77
|
+
* outside an open.
|
|
60
78
|
*/
|
|
61
|
-
async function
|
|
79
|
+
export async function stampBrokerSchemaAtOpenEnd(
|
|
62
80
|
database: SqliteDatabase,
|
|
81
|
+
prefix: string | undefined,
|
|
82
|
+
store: string,
|
|
63
83
|
setup: (tx: SqliteExecutor) => Promise<unknown>,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
84
|
+
verify: (catalog: storage.StorageSchemaCatalog) => boolean,
|
|
85
|
+
revision = 1,
|
|
86
|
+
): Promise<void> {
|
|
87
|
+
const schema = { ledger: storageMigrationTable(prefix), domain: `intercom-${store}`, revision };
|
|
88
|
+
if (await catalogApi.storageSchemaCurrent?.(database, schema)) return;
|
|
89
|
+
catalogApi.restampStorageSchemaAtOpenEnd?.(database, schema, setup, { verify });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* What `setup` creates on a SQLite or libSQL database, where it only runs `CREATE TABLE` and `CREATE INDEX` statements
|
|
94
|
+
* with `IF NOT EXISTS` and seeds rows with `INSERT … ON CONFLICT … DO NOTHING`: `present`, whether the catalog an open
|
|
95
|
+
* in progress read found each object, as a table or an index as the statement names it; `verify`, the same check
|
|
96
|
+
* against another catalog; and `seeds`, whether it seeds rows, which still have to be written. SQLite records no
|
|
97
|
+
* versions, so such a setup ran at every open in a write transaction of its own, which took the database's write lock
|
|
98
|
+
* and, on a server, three round trips (#6560); statements on an existing object of that kind do nothing. The setup runs
|
|
99
|
+
* against a handle that only collects the SQL it would run. Undefined for any other call or statement, outside such an
|
|
100
|
+
* open, and on PostgreSQL, whose ledger decides.
|
|
101
|
+
*/
|
|
102
|
+
async function foundInCatalog(
|
|
103
|
+
database: SqliteDatabase,
|
|
104
|
+
setup: (tx: SqliteExecutor) => Promise<unknown>,
|
|
105
|
+
): Promise<
|
|
106
|
+
| {
|
|
107
|
+
readonly verify: (catalog: storage.StorageSchemaCatalog) => boolean;
|
|
108
|
+
readonly seeds: boolean;
|
|
109
|
+
readonly present: boolean;
|
|
110
|
+
}
|
|
111
|
+
| undefined
|
|
112
|
+
> {
|
|
113
|
+
if (dialectOf(database).versionedMigrations) return undefined;
|
|
114
|
+
const catalog = await openCatalogOf(database);
|
|
115
|
+
if (catalog?.sqliteObjectType === undefined) return undefined;
|
|
68
116
|
const scripts: string[] = [];
|
|
69
117
|
let other = false;
|
|
70
118
|
const refuse = () => {
|
|
@@ -83,22 +131,29 @@ async function createsNothingNew(
|
|
|
83
131
|
try {
|
|
84
132
|
await setup(collecting);
|
|
85
133
|
} catch {
|
|
86
|
-
return
|
|
134
|
+
return undefined;
|
|
87
135
|
}
|
|
88
|
-
if (other) return
|
|
136
|
+
if (other) return undefined;
|
|
137
|
+
const created: { readonly name: string; readonly type: string }[] = [];
|
|
138
|
+
let seeds = false;
|
|
89
139
|
for (const script of scripts) {
|
|
90
140
|
const statements = splitStatements(script);
|
|
91
|
-
if (statements === undefined) return
|
|
141
|
+
if (statements === undefined) return undefined;
|
|
92
142
|
for (const statement of statements) {
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
143
|
+
const create = CREATE_IF_NOT_EXISTS.exec(statement);
|
|
144
|
+
if (create !== null) created.push({ name: create[3] ?? create[4]!, type: create[2]!.toLowerCase() });
|
|
145
|
+
else if (SEED.test(statement)) seeds = true;
|
|
146
|
+
else return undefined;
|
|
97
147
|
}
|
|
98
148
|
}
|
|
99
|
-
|
|
149
|
+
const verify = (found: storage.StorageSchemaCatalog) =>
|
|
150
|
+
created.every(({ name, type }) => found.sqliteObjectType?.(name) === type);
|
|
151
|
+
return { verify, seeds, present: verify(catalog) };
|
|
100
152
|
}
|
|
101
153
|
|
|
154
|
+
/** `INSERT INTO … ON CONFLICT … DO NOTHING`: rows a setup seeds once, which writing again leaves as they are. */
|
|
155
|
+
const SEED = /^INSERT\s+INTO\s[\s\S]*\sON\s+CONFLICT\b[\s\S]*\sDO\s+NOTHING$/i;
|
|
156
|
+
|
|
102
157
|
/** `CREATE [UNIQUE] TABLE|INDEX IF NOT EXISTS <name>`, the name plain or double-quoted and never schema-qualified. */
|
|
103
158
|
const CREATE_IF_NOT_EXISTS =
|
|
104
159
|
/^CREATE\s+(UNIQUE\s+)?(TABLE|INDEX)\s+IF\s+NOT\s+EXISTS\s+(?:"([^"]+)"|([A-Za-z_][A-Za-z0-9_]*))(?![A-Za-z0-9_$."])/i;
|
|
@@ -7,7 +7,7 @@ import * as __atomicHostImport1 from "@bastani/atomic-ai";
|
|
|
7
7
|
if (!(name in namespace)) missing.push(`The requested module '${specifier}' does not provide an export named '${name}'`);
|
|
8
8
|
if (missing.length > 0) {
|
|
9
9
|
const application = typeof __atomicHostImport0.APP_NAME === "string" ? __atomicHostImport0.APP_NAME : "atomic";
|
|
10
|
-
if (__atomicHostImport0.VERSION !== "0.10.11-alpha.
|
|
10
|
+
if (__atomicHostImport0.VERSION !== "0.10.11-alpha.2") missing.unshift(application + " was updated to 0.10.11-alpha.2 while this session was running; restart it to keep using the intercom extension.");
|
|
11
11
|
throw new Error(missing.join("\n"));
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -6,7 +6,7 @@ import * as __atomicHostImport0 from "@bastani/atomic";
|
|
|
6
6
|
if (!(name in namespace)) missing.push(`The requested module '${specifier}' does not provide an export named '${name}'`);
|
|
7
7
|
if (missing.length > 0) {
|
|
8
8
|
const application = typeof __atomicHostImport0.APP_NAME === "string" ? __atomicHostImport0.APP_NAME : "atomic";
|
|
9
|
-
if (__atomicHostImport0.VERSION !== "0.10.11-alpha.
|
|
9
|
+
if (__atomicHostImport0.VERSION !== "0.10.11-alpha.2") missing.unshift(application + " was updated to 0.10.11-alpha.2 while this session was running; restart it to keep using the mcp extension.");
|
|
10
10
|
throw new Error(missing.join("\n"));
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.10.11-alpha.2] - 2026-11-26
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- A subagent started with `context: "fork"` now shares its parent's history in the session store instead of copying it, so it starts about as fast from a long conversation as from a short one. It reads, resumes and exports as before. See [Shared-history forks](../coding-agent/docs/storage.md#shared-history-forks) in Atomic's storage guide ([#6608](https://github.com/bastani-inc/atomic/pull/6608), [#6560](https://github.com/bastani-inc/atomic/issues/6560)).
|
|
10
|
+
|
|
5
11
|
## [0.10.11-alpha.1] - 2026-11-25
|
|
6
12
|
|
|
7
13
|
### Changed
|
|
@@ -10,7 +10,7 @@ import * as __atomicHostImport4 from "@bastani/atomic-ai";
|
|
|
10
10
|
if (!(name in namespace)) missing.push(`The requested module '${specifier}' does not provide an export named '${name}'`);
|
|
11
11
|
if (missing.length > 0) {
|
|
12
12
|
const application = typeof __atomicHostImport0.APP_NAME === "string" ? __atomicHostImport0.APP_NAME : "atomic";
|
|
13
|
-
if (__atomicHostImport0.VERSION !== "0.10.11-alpha.
|
|
13
|
+
if (__atomicHostImport0.VERSION !== "0.10.11-alpha.2") missing.unshift(application + " was updated to 0.10.11-alpha.2 while this session was running; restart it to keep using the subagents extension.");
|
|
14
14
|
throw new Error(missing.join("\n"));
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -8,7 +8,7 @@ import * as __atomicHostImport2 from "@bastani/atomic-ai/compat";
|
|
|
8
8
|
if (!(name in namespace)) missing.push(`The requested module '${specifier}' does not provide an export named '${name}'`);
|
|
9
9
|
if (missing.length > 0) {
|
|
10
10
|
const application = typeof __atomicHostImport0.APP_NAME === "string" ? __atomicHostImport0.APP_NAME : "atomic";
|
|
11
|
-
if (__atomicHostImport0.VERSION !== "0.10.11-alpha.
|
|
11
|
+
if (__atomicHostImport0.VERSION !== "0.10.11-alpha.2") missing.unshift(application + " was updated to 0.10.11-alpha.2 while this session was running; restart it to keep using the web-access extension.");
|
|
12
12
|
throw new Error(missing.join("\n"));
|
|
13
13
|
}
|
|
14
14
|
}
|
package/dist/cli/args.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../_shared/rolldown-runtime-BGM3D5V3.js";
|
|
2
|
-
import { isValidThinkingLevel } from "../_shared/startup-0-0-
|
|
3
|
-
import { insertForcedOptionsBeforeTerminator, parseArgs, printHelp } from "../_shared/startup-0-1-
|
|
2
|
+
import { isValidThinkingLevel } from "../_shared/startup-0-0-3IXNMFM2.js";
|
|
3
|
+
import { insertForcedOptionsBeforeTerminator, parseArgs, printHelp } from "../_shared/startup-0-1-7T2IAE7J.js";
|
|
4
4
|
export { insertForcedOptionsBeforeTerminator, isValidThinkingLevel, parseArgs, printHelp };
|
|
5
5
|
//# sourceMappingURL=args.js.map
|
|
@@ -3,12 +3,12 @@ import chalk from "chalk";
|
|
|
3
3
|
import { APP_NAME, ENV_DEBUG, getAgentDir, getAuthPath, setEnvValue } from "../_shared/p0-cli-BB45ZQY6.js";
|
|
4
4
|
import { AuthStorage, ReadOnlyAuthStorage } from "../_shared/startup-0-4-ZMJV547D.js";
|
|
5
5
|
import { CredentialSynchronizationError, ModelRuntime, isOAuthLoginCancelled } from "../_shared/startup-0-5-YDW47QX6.js";
|
|
6
|
-
import { RawStdoutWriteError, flushRawStdout, restoreStdout, takeOverStdout, writeRawStdout, writeRawStdoutOnce } from "../_shared/startup-0-0-
|
|
7
|
-
import { findExactModelReferenceMatch, resolveModelReference } from "../_shared/startup-0-2-
|
|
6
|
+
import { RawStdoutWriteError, flushRawStdout, restoreStdout, takeOverStdout, writeRawStdout, writeRawStdoutOnce } from "../_shared/startup-0-0-3IXNMFM2.js";
|
|
7
|
+
import { findExactModelReferenceMatch, resolveModelReference } from "../_shared/startup-0-2-5QHPCEON.js";
|
|
8
8
|
import { SettingsManager } from "../_shared/startup-8-1-X32CYSXB.js";
|
|
9
|
-
import { parseArgs } from "../_shared/startup-0-1-
|
|
9
|
+
import { parseArgs } from "../_shared/startup-0-1-7T2IAE7J.js";
|
|
10
10
|
import { ModelsError } from "@bastani/atomic-ai";
|
|
11
|
-
import { InMemoryCodingAgentModelsStore, resolveCliModel } from "../_shared/startup-0-3-
|
|
11
|
+
import { InMemoryCodingAgentModelsStore, resolveCliModel } from "../_shared/startup-0-3-4ZYBYQNM.js";
|
|
12
12
|
import { extractBearerToken, redactCredentialShapes } from "../_shared/p1b-elig-ENCUPKKJ.js";
|
|
13
13
|
import { inspect } from "node:util";
|
|
14
14
|
import { replaceControlCharacters } from "@bastani/atomic-tui";
|