@bastani/atomic 0.10.11-alpha.2 → 0.10.11-alpha.4
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 +150 -0
- package/README.md +5 -8
- 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 +6 -6
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +5 -5
- package/dist/_shared/mode-shared-2QJSCUM6.js +6 -6
- package/dist/_shared/p0-cli-BB45ZQY6.js +46 -67
- package/dist/_shared/p0-cli-BB45ZQY6.js.map +1 -1
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +7 -8
- package/dist/_shared/p1a-prewarm-XIU57JHF.js.map +1 -1
- package/dist/_shared/{p1b-elig-ENCUPKKJ.js → p1b-elig-TVB5CBLL.js} +36 -8
- package/dist/_shared/p1b-elig-TVB5CBLL.js.map +1 -0
- package/dist/_shared/p2-shell-main-B2WIALFD.js +6 -3
- package/dist/_shared/p2-shell-main-B2WIALFD.js.map +1 -1
- package/dist/_shared/runtime-O4KCSG4C.js +3 -3
- package/dist/_shared/{sdk-IQMULKFU.js → sdk-B5LEWGGI.js} +1218 -657
- package/dist/_shared/sdk-B5LEWGGI.js.map +1 -0
- package/dist/_shared/session-data-AHTU7IS6.js +2 -2
- package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
- package/dist/_shared/{startup-0-0-3IXNMFM2.js → startup-0-0-XJJDOIEC.js} +50 -48
- package/dist/_shared/startup-0-0-XJJDOIEC.js.map +1 -0
- package/dist/_shared/{startup-0-1-7T2IAE7J.js → startup-0-1-M6OWAYHH.js} +540 -136
- package/dist/_shared/startup-0-1-M6OWAYHH.js.map +1 -0
- package/dist/_shared/startup-0-2-5QHPCEON.js +47 -48
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -1
- package/dist/_shared/startup-0-3-4ZYBYQNM.js +5 -5
- package/dist/_shared/startup-0-4-ZMJV547D.js +12 -7
- package/dist/_shared/startup-0-4-ZMJV547D.js.map +1 -1
- package/dist/_shared/startup-0-5-YDW47QX6.js +7 -7
- package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -1
- package/dist/_shared/startup-10-0-TDQNBDDL.js +6 -6
- package/dist/_shared/startup-12-0-55AAXBJZ.js +2 -2
- package/dist/_shared/startup-14-0-MLX36RBG.js +4 -5
- package/dist/_shared/startup-14-0-MLX36RBG.js.map +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +4 -4
- package/dist/_shared/startup-15-1-4S7FLMNG.js +19 -27
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +2144 -249
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/{startup-8-1-X32CYSXB.js → startup-8-1-LZFXSD3Z.js} +98 -1184
- package/dist/_shared/startup-8-1-LZFXSD3Z.js.map +1 -0
- package/dist/_shared/storage-command-7MGXLJGZ.js +188 -37
- package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
- package/dist/_shared/storage-status-K7PX2RXA.js +557 -0
- package/dist/_shared/storage-status-K7PX2RXA.js.map +1 -0
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/team-DOQKICG2.js +376 -0
- package/dist/_shared/team-DOQKICG2.js.map +1 -0
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +42 -0
- package/dist/builtin/intercom/README.md +2 -2
- package/dist/builtin/intercom/broker/broker.bundle.mjs +1917 -381
- package/dist/builtin/intercom/broker/client.ts +8 -0
- package/dist/builtin/intercom/broker/database-wake-up-bus.ts +324 -68
- package/dist/builtin/intercom/broker/multinode-router.ts +256 -39
- package/dist/builtin/intercom/broker/multinode-state-store.ts +71 -5
- package/dist/builtin/intercom/broker/open-broker-state.ts +14 -0
- package/dist/builtin/intercom/broker/send-order-gate.ts +5 -2
- package/dist/builtin/intercom/broker/sql-add-column.ts +50 -5
- package/dist/builtin/intercom/broker/sql-ended-child-queue-store.ts +3 -2
- package/dist/builtin/intercom/broker/sql-held-send-store.ts +2 -2
- package/dist/builtin/intercom/broker/sql-known-session-store.ts +43 -19
- package/dist/builtin/intercom/broker/sql-lease-store.ts +473 -121
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +821 -79
- package/dist/builtin/intercom/broker/sql-pending-ask-store.ts +8 -5
- package/dist/builtin/intercom/broker/sql-released-ask-store.ts +12 -5
- package/dist/builtin/intercom/broker/sql-restoring-reservation-store.ts +256 -8
- package/dist/builtin/intercom/broker/sql-retention.ts +150 -0
- package/dist/builtin/intercom/broker/sql-schema.ts +175 -24
- package/dist/builtin/intercom/broker/sql-sent-message-authority.ts +74 -19
- package/dist/builtin/intercom/broker/wake-up-bus.ts +6 -0
- package/dist/builtin/intercom/index.bundle.mjs +14 -4
- 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/skills/skill-creator/eval-viewer/generate_review.py +8 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/index.bundle.mjs +2 -10
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/bun/bundled-sqlite.js +41 -0
- package/dist/bun/bundled-sqlite.js.map +1 -0
- 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 +3 -3
- 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.code.js.map +1 -1
- 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 +1 -1
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +1 -1
- 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 +3 -3
- 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 +19 -113
- package/dist/cli/team-command.code.js.map +1 -1
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +5 -18
- package/dist/cli.js.map +1 -1
- package/dist/core/agent-rehydrate-errors.d.ts +4 -9
- package/dist/core/compaction/compactor.d.ts +3 -3
- package/dist/core/debug.code.js +1 -1
- 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 +4 -4
- package/dist/core/export-html/index.code.js.map +1 -1
- 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.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 +2 -2
- 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.code.js +1 -1
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/process-start-token.d.ts +12 -3
- package/dist/core/process-tree-containment.d.ts +16 -0
- package/dist/core/sdk-types.d.ts +1 -2
- package/dist/core/sdk-types.js.map +1 -1
- 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 +5 -5
- 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 +1 -1
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-storage.code.js +1 -1
- package/dist/core/session-storage.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/settings-schema.d.ts +0 -3
- package/dist/core/storage/added-exports-0-10-11.js +19 -0
- package/dist/core/storage/added-exports-0-10-11.js.map +1 -0
- package/dist/core/storage/creation-time.js +105 -0
- package/dist/core/storage/creation-time.js.map +1 -0
- package/dist/core/storage/database.d.ts +25 -5
- package/dist/core/storage/database.js.map +1 -1
- package/dist/core/storage/dialect.d.ts +1 -1
- package/dist/core/storage/dialect.js +1 -1
- package/dist/core/storage/dialect.js.map +1 -1
- package/dist/core/storage/errors.d.ts +13 -13
- package/dist/core/storage/errors.js +10 -16
- package/dist/core/storage/errors.js.map +1 -1
- package/dist/core/storage/fenced-paths.d.ts +18 -6
- package/dist/core/storage/fenced-paths.js +18 -6
- package/dist/core/storage/fenced-paths.js.map +1 -1
- package/dist/core/storage/file-identity.d.ts +2 -0
- package/dist/core/storage/file-identity.js +24 -8
- package/dist/core/storage/file-identity.js.map +1 -1
- package/dist/core/storage/index.d.ts +3 -2
- package/dist/core/storage/index.js +5 -3
- package/dist/core/storage/index.js.map +1 -1
- package/dist/core/storage/libsql-removed.d.ts +71 -0
- package/dist/core/storage/libsql-removed.js +123 -0
- package/dist/core/storage/libsql-removed.js.map +1 -0
- package/dist/core/storage/migrations.d.ts +78 -14
- package/dist/core/storage/migrations.js +375 -49
- package/dist/core/storage/migrations.js.map +1 -1
- package/dist/core/storage/node-sqlite-file-gate.js +0 -15
- package/dist/core/storage/node-sqlite-file-gate.js.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +215 -30
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.js +484 -72
- 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.d.ts +1 -1
- package/dist/core/storage/prefix.js +9 -2
- package/dist/core/storage/prefix.js.map +1 -1
- package/dist/core/storage/process-selection.d.ts +5 -5
- package/dist/core/storage/provider.js +2 -2
- package/dist/core/storage/schema-catalog.d.ts +76 -15
- package/dist/core/storage/schema-catalog.js +359 -68
- package/dist/core/storage/schema-catalog.js.map +1 -1
- package/dist/core/storage/selection.d.ts +7 -82
- package/dist/core/storage/selection.js +20 -235
- package/dist/core/storage/selection.js.map +1 -1
- package/dist/core/storage/session/branch-fork-source.code.js +2 -2
- 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 +3 -3
- 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/expanded-child-details.code.js +2 -2
- 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 +11 -1
- 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-staging.code.js +4 -7
- package/dist/core/storage/session/fork-staging.code.js.map +1 -1
- 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 +31 -7
- package/dist/core/storage/session/fork-sweep.js.map +1 -1
- package/dist/core/storage/session/fork-window.code.js +3 -3
- 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-lock.d.ts +100 -0
- package/dist/core/storage/session/jsonl-session-store.d.ts +46 -24
- 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 +9 -9
- package/dist/core/storage/session/released-history-files.code.js.map +1 -1
- 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.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/session-search-index.d.ts +52 -5
- 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 +3 -3
- 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 +99 -18
- package/dist/core/storage/session/sql-session-store.impl.js +3 -3
- package/dist/core/storage/session/sql-session-store.js +3 -3
- 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/sqlite-facade.d.ts +12 -1
- package/dist/core/storage/sqlite-facade.js +310 -33
- package/dist/core/storage/sqlite-facade.js.map +1 -1
- package/dist/core/storage/sqlite-open-batch.js +10 -0
- package/dist/core/storage/sqlite-open-batch.js.map +1 -0
- package/dist/core/storage/storage-status.code.js +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.code.js +1 -1
- package/dist/core/storage/team.d.ts +26 -115
- 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 +3 -3
- 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.code.js +1 -1
- 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-tasks.d.ts +3 -2
- package/dist/core/tools/read-url.code.js +4 -4
- 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 +44 -5
- package/dist/core/worktree-snapshot/blob-store.js +553 -30
- package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
- package/dist/core/worktree-snapshot/errors.code.js +2 -2
- 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-blob-guard.js +81 -0
- package/dist/core/worktree-snapshot/fork-blob-guard.js.map +1 -0
- package/dist/core/worktree-snapshot/fork-snapshot-index.js +208 -50
- package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -1
- package/dist/core/worktree-snapshot/session-index-reset.code.js +4 -0
- package/dist/core/worktree-snapshot/session-index-reset.code.js.map +1 -1
- 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 +1 -1
- package/dist/extensions/codemode/execute.impl.js +3 -3
- package/dist/extensions/codemode/execute.js +3 -3
- package/dist/extensions/codemode/renderer.code.js +2 -2
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +3 -3
- 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.d.ts +3 -1
- package/dist/index.js +5 -5
- package/dist/main-first-time-setup.code.js +1 -1
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/main.js +1 -1
- package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
- 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/interactive/startup-shell-eligibility.js +1 -1
- package/dist/modes/interactive-engine/engine-prewarm.d.ts +1 -1
- package/dist/modes/print-mode.js +1 -1
- package/dist/package-manager-cli.code.js +6 -6
- 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/10.js +1 -1
- package/dist/startup-stages/11.js +1 -1
- package/dist/startup-stages/12.js +1 -1
- package/dist/startup-stages/2.js +2 -4
- package/dist/startup-stages/3.js +1 -3
- package/dist/startup-stages/4.js +1 -2
- package/dist/startup-stages/5.js +1 -1
- package/dist/startup-stages/6.js +5 -7
- package/dist/startup-stages/7.js +3 -10
- package/dist/startup-stages/8.js +7 -2
- package/dist/startup-stages/9.js +1 -7
- package/dist/startup-stages/stages.json +1 -1
- package/dist/utils/compile-cache-deferral.js +8 -13
- package/dist/utils/compile-cache-deferral.js.map +1 -1
- package/dist/utils/compile-cache-warmup-host.js +3 -4
- package/dist/utils/compile-cache-warmup-host.js.map +1 -1
- package/dist/utils/compile-cache.js +12 -100
- package/dist/utils/compile-cache.js.map +1 -1
- package/dist/utils/startup-database-spare.code.js +2 -2
- 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/dist/utils/worker-threads.js +2 -15
- package/dist/utils/worker-threads.js.map +1 -1
- package/docs/build.md +3 -3
- package/docs/changelog.mdx +1470 -69
- package/docs/compaction/reference.md +5 -5
- package/docs/compaction.md +7 -9
- package/docs/containerization.md +2 -2
- package/docs/custom-provider/api-reference.md +1 -1
- package/docs/docs.json +37 -10
- package/docs/environment-variables.md +0 -2
- package/docs/extensions/api-reference.md +4 -4
- package/docs/getting-started/installation.md +3 -0
- package/docs/guides/configuration.md +1 -1
- package/docs/guides/non-interactive.md +1 -1
- package/docs/guides/resume-on-any-machine.md +14 -22
- package/docs/guides/team-setup.md +56 -83
- package/docs/guides.md +2 -4
- package/docs/herdr.md +1 -1
- package/docs/index.md +1 -1
- package/docs/intercom/operations.md +26 -21
- package/docs/intercom/reference.md +2 -2
- package/docs/intercom.md +1 -1
- package/docs/libraries/storage-postgres.md +9 -9
- package/docs/libraries.md +2 -3
- package/docs/models-configuration.md +2 -2
- package/docs/models.md +2 -3
- package/docs/packages/authoring.md +7 -7
- package/docs/packages.md +1 -1
- package/docs/programmatic.md +2 -2
- package/docs/quickstart.md +1 -1
- package/docs/reference/cli.md +6 -11
- package/docs/reference.md +2 -2
- package/docs/rpc/extension-ui.md +2 -2
- package/docs/sdk/reference.md +5 -4
- package/docs/sdk/storage.md +8 -92
- package/docs/sdk/structured-decisions.md +1 -1
- package/docs/sdk/web-server.md +3 -3
- package/docs/sdk.md +14 -4
- package/docs/security.md +1 -1
- package/docs/session-format.md +5 -5
- package/docs/sessions.md +29 -49
- package/docs/settings.md +7 -8
- package/docs/storage/custom-adapters.md +255 -0
- package/docs/storage/jsonl.md +117 -0
- package/docs/{guides/postgres-pgbouncer.md → storage/postgres/pgbouncer.md} +66 -68
- package/docs/storage/postgres/tuning.md +337 -0
- package/docs/storage/postgres.md +556 -0
- package/docs/storage/sqlite.md +99 -0
- package/docs/storage.md +326 -990
- package/docs/subagents/authoring.md +1 -1
- package/docs/subagents.md +2 -2
- package/docs/tools.md +1 -1
- package/docs/worktree-snapshots.md +2 -2
- package/package.json +9 -9
- package/schemas/models.schema.json +2 -2
- package/schemas/settings.schema.json +0 -14
- package/dist/_shared/p1b-elig-ENCUPKKJ.js.map +0 -1
- package/dist/_shared/sdk-IQMULKFU.js.map +0 -1
- package/dist/_shared/startup-0-0-3IXNMFM2.js.map +0 -1
- package/dist/_shared/startup-0-1-7T2IAE7J.js.map +0 -1
- package/dist/_shared/startup-8-1-X32CYSXB.js.map +0 -1
- package/dist/core/intercom-broker-control.d.ts +0 -129
- package/dist/startup-stages/13.js +0 -1
- package/docs/guides/postgres-tuning.md +0 -311
- package/docs/libraries/storage-libsql.md +0 -97
|
@@ -19,7 +19,8 @@ import type {
|
|
|
19
19
|
} from "./multinode-state-store.js";
|
|
20
20
|
import { SETTLED_ASK_RETENTION_MS } from "./multinode-state-store.js";
|
|
21
21
|
import { addMissingColumns } from "./sql-add-column.js";
|
|
22
|
-
import {
|
|
22
|
+
import { storeNow } from "./sql-retention.js";
|
|
23
|
+
import { ensureBrokerSchema, RETRY_UNAPPLIED, withBrokerSchemaCatalog } from "./sql-schema.js";
|
|
23
24
|
|
|
24
25
|
type AskRow = SqliteRow & { sender_session_id: string; target_session_id: string; message_id: string };
|
|
25
26
|
|
|
@@ -60,12 +61,12 @@ async function openPendingAskStoreInCatalog({
|
|
|
60
61
|
prefix,
|
|
61
62
|
}: IntercomBrokerStateOptions): Promise<PendingAskStore> {
|
|
62
63
|
const table = `${validateStoragePrefix(prefix, dialectOf(database).name)}intercom_pending_asks`;
|
|
63
|
-
const { types, nowMs
|
|
64
|
+
const { types, nowMs } = dialectOf(database);
|
|
64
65
|
/**
|
|
65
66
|
* Its transactions read and write this table and the settled asks alone, which no other store touches, so they
|
|
66
67
|
* exclude one another, not every writer of the database (#6560).
|
|
67
68
|
*/
|
|
68
|
-
const serial = { concurrency: { kind: "serial", domain: table } } as const;
|
|
69
|
+
const serial = { ...RETRY_UNAPPLIED, concurrency: { kind: "serial", domain: table } } as const;
|
|
69
70
|
await ensureBrokerSchema(database, prefix, "pending-asks", (tx) =>
|
|
70
71
|
tx.exec(`
|
|
71
72
|
CREATE TABLE IF NOT EXISTS ${table}(
|
|
@@ -87,6 +88,8 @@ async function openPendingAskStoreInCatalog({
|
|
|
87
88
|
replied: types.int,
|
|
88
89
|
ended_at: types.int,
|
|
89
90
|
});
|
|
91
|
+
/** The database clock, read once per statement: a column compared with it is answered by its index. */
|
|
92
|
+
const now = storeNow(database);
|
|
90
93
|
// #4997: asks answered or failed, remembered so a stopped broker's copy of one is not recorded again.
|
|
91
94
|
const settled = `${validateStoragePrefix(prefix)}intercom_settled_asks`;
|
|
92
95
|
await ensureBrokerSchema(database, prefix, "settled-asks", (tx) =>
|
|
@@ -141,7 +144,7 @@ async function openPendingAskStoreInCatalog({
|
|
|
141
144
|
ON CONFLICT DO NOTHING`,
|
|
142
145
|
...reverseParams(route),
|
|
143
146
|
);
|
|
144
|
-
await tx.run(`DELETE FROM ${settled} WHERE settled_at < ${
|
|
147
|
+
await tx.run(`DELETE FROM ${settled} WHERE settled_at < ${now} - ?`, SETTLED_ASK_RETENTION_MS);
|
|
145
148
|
return changes === 0 ? ({ status: "no-match" } as const) : ({ status: "cleared" } as const);
|
|
146
149
|
}, serial);
|
|
147
150
|
},
|
|
@@ -279,7 +282,7 @@ async function openPendingAskStoreInCatalog({
|
|
|
279
282
|
async listEnded(olderThanMs): Promise<PendingAskListResult> {
|
|
280
283
|
const rows = await database.all<AskRow>(
|
|
281
284
|
`SELECT sender_session_id, target_session_id, message_id FROM ${table}
|
|
282
|
-
WHERE ended_at IS NOT NULL AND replied IS NULL AND ${
|
|
285
|
+
WHERE ended_at IS NOT NULL AND replied IS NULL AND ended_at <= ${now} - ?
|
|
283
286
|
ORDER BY ended_at, "order"`,
|
|
284
287
|
olderThanMs,
|
|
285
288
|
);
|
|
@@ -17,7 +17,8 @@ import type {
|
|
|
17
17
|
ReleasedAskSupersede,
|
|
18
18
|
StateStoreInvalidReason,
|
|
19
19
|
} from "./multinode-state-store.js";
|
|
20
|
-
import {
|
|
20
|
+
import { deleteInBatches, storeNow } from "./sql-retention.js";
|
|
21
|
+
import { ensureBrokerSchema, RETRY_UNAPPLIED, withBrokerSchemaCatalog } from "./sql-schema.js";
|
|
21
22
|
|
|
22
23
|
interface ReleasedAskRow extends SqliteRow {
|
|
23
24
|
readonly question_id: string;
|
|
@@ -79,7 +80,7 @@ async function openReleasedAskStoreInCatalog({ database, prefix }: IntercomBroke
|
|
|
79
80
|
const table = `${validateStoragePrefix(prefix, dialectOf(database).name)}intercom_released_asks`;
|
|
80
81
|
const { types, nowMs, greatest } = dialectOf(database);
|
|
81
82
|
/** Its transactions read and write this table alone, so they exclude one another, not every writer (#6560). */
|
|
82
|
-
const serial = { concurrency: { kind: "serial", domain: table } } as const;
|
|
83
|
+
const serial = { ...RETRY_UNAPPLIED, concurrency: { kind: "serial", domain: table } } as const;
|
|
83
84
|
await ensureBrokerSchema(database, prefix, "released-asks", (tx) =>
|
|
84
85
|
tx.exec(`
|
|
85
86
|
CREATE TABLE IF NOT EXISTS ${table}(
|
|
@@ -189,9 +190,15 @@ async function openReleasedAskStoreInCatalog({ database, prefix }: IntercomBroke
|
|
|
189
190
|
if (bad !== undefined) return bad;
|
|
190
191
|
return settle(claim, "open", ["claimed"]);
|
|
191
192
|
},
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return
|
|
193
|
+
prune(olderThanMs) {
|
|
194
|
+
// Oldest first, from `<table>_expires`, in batches.
|
|
195
|
+
return deleteInBatches(database, {
|
|
196
|
+
table,
|
|
197
|
+
key: '"order"',
|
|
198
|
+
where: `expires_at < ${storeNow(database)} - ?`,
|
|
199
|
+
params: [olderThanMs],
|
|
200
|
+
orderBy: "expires_at",
|
|
201
|
+
});
|
|
195
202
|
},
|
|
196
203
|
};
|
|
197
204
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
dialectOf,
|
|
3
3
|
type StorageDialect,
|
|
4
|
+
type StorageSchemaCatalog,
|
|
4
5
|
type SqliteExecutor,
|
|
5
6
|
type SqliteRow,
|
|
7
|
+
type SqliteStatement,
|
|
6
8
|
validateStoragePrefix,
|
|
7
9
|
} from "@bastani/atomic/storage";
|
|
8
10
|
import type {
|
|
@@ -27,7 +29,15 @@ import type {
|
|
|
27
29
|
import { reservationAdmitsSender } from "./group-membership.js";
|
|
28
30
|
import { isReleasedReservationKey } from "./released-children.js";
|
|
29
31
|
import { addMissingColumns } from "./sql-add-column.js";
|
|
30
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
ensureBrokerSchema,
|
|
34
|
+
foundInCatalogAgain,
|
|
35
|
+
openCatalogOf,
|
|
36
|
+
queueBrokerSqliteSetup,
|
|
37
|
+
RETRY_UNAPPLIED,
|
|
38
|
+
setUpBrokerSchemaOnce,
|
|
39
|
+
withBrokerSchemaCatalog,
|
|
40
|
+
} from "./sql-schema.js";
|
|
31
41
|
|
|
32
42
|
type ReservationRow = SqliteRow & {
|
|
33
43
|
reservation_key: string;
|
|
@@ -49,6 +59,27 @@ type ReservationRow = SqliteRow & {
|
|
|
49
59
|
|
|
50
60
|
type Counter = "order" | "token";
|
|
51
61
|
|
|
62
|
+
type RenewedReservationRow = SqliteRow & {
|
|
63
|
+
reservation_key: string | null;
|
|
64
|
+
owner_session_id: string | null;
|
|
65
|
+
fencing_token: number | bigint | null;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
type MissedReservationRow = SqliteRow & {
|
|
69
|
+
reservation_key: string;
|
|
70
|
+
end_json: string | null;
|
|
71
|
+
fencing_token: number | bigint;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** The setting a PostgreSQL batched reservation renewal sets when any reservation missed, so its follow-up read runs. */
|
|
75
|
+
const RESERVATION_RENEW_MISSES = "atomic.intercom_reservation_renew_misses";
|
|
76
|
+
|
|
77
|
+
const compare = (a: string, b: string) => (a < b ? -1 : a > b ? 1 : 0);
|
|
78
|
+
|
|
79
|
+
function wellFormed(_key: string, value: unknown): unknown {
|
|
80
|
+
return typeof value === "string" ? value.toWellFormed() : value;
|
|
81
|
+
}
|
|
82
|
+
|
|
52
83
|
const invalid = (reason: StateStoreInvalidReason): InvalidStateInput => ({ status: "invalid", reason });
|
|
53
84
|
|
|
54
85
|
function reservationOf(row: ReservationRow): RestoringReservation {
|
|
@@ -137,12 +168,12 @@ async function openRestoringReservationStoreInCatalog({
|
|
|
137
168
|
const table = `${validPrefix}intercom_restoring_reservations`;
|
|
138
169
|
const counters = `${validPrefix}intercom_restoring_reservation_counters`;
|
|
139
170
|
const wakeClaims = `${validPrefix}intercom_restoring_wake_claims`;
|
|
140
|
-
const { types, nowMs, greatest } = dialectOf(database);
|
|
171
|
+
const { types, nowMs, greatest, jsonValues, name: dialect } = dialectOf(database);
|
|
141
172
|
/**
|
|
142
173
|
* Its transactions read and write this table, its counters and its wake claims alone, which no other store
|
|
143
174
|
* touches, so they exclude one another, not every writer of the database (#6560).
|
|
144
175
|
*/
|
|
145
|
-
const serial = { concurrency: { kind: "serial", domain: table } } as const;
|
|
176
|
+
const serial = { ...RETRY_UNAPPLIED, concurrency: { kind: "serial", domain: table } } as const;
|
|
146
177
|
await ensureBrokerSchema(database, prefix, "restoring-reservations", (tx) =>
|
|
147
178
|
tx.exec(`
|
|
148
179
|
CREATE TABLE IF NOT EXISTS ${table}(
|
|
@@ -185,11 +216,32 @@ async function openRestoringReservationStoreInCatalog({
|
|
|
185
216
|
);
|
|
186
217
|
// Probed every time, as an earlier broker may recreate its index meanwhile; a current one runs no DDL (#5218). The
|
|
187
218
|
// catalog an open read answers that probe, so a current index costs no transaction (#6560).
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
catalog?.hasObject(`${table}_wake`) === true &&
|
|
219
|
+
const wakeIndexCurrent = (catalog: StorageSchemaCatalog) =>
|
|
220
|
+
catalog.hasObject(`${table}_wake`) &&
|
|
191
221
|
!catalog.hasObject(`${table}_wake_requested`.slice(0, dialectOf(database).name === "postgres" ? 63 : undefined));
|
|
192
|
-
|
|
222
|
+
const catalog = await openCatalogOf(database);
|
|
223
|
+
// Brokers that open a new database at once create it once; the others wait for it without its lock (#6560).
|
|
224
|
+
// On SQLite inside an open scope, queue the wake index update into the open's single write transaction (#6709).
|
|
225
|
+
if (catalog === undefined || !wakeIndexCurrent(catalog)) {
|
|
226
|
+
const index = `${table}_wake`;
|
|
227
|
+
const earlier = `${table}_wake_requested`;
|
|
228
|
+
if (
|
|
229
|
+
!queueBrokerSqliteSetup(database, prefix ?? "", {
|
|
230
|
+
verify: wakeIndexCurrent,
|
|
231
|
+
run(ctx) {
|
|
232
|
+
if (ctx.catalog?.hasObject(earlier) === true) ctx.enqueue(`DROP INDEX IF EXISTS ${earlier}`);
|
|
233
|
+
if (ctx.catalog?.hasObject(index) !== true)
|
|
234
|
+
ctx.enqueue(`CREATE INDEX IF NOT EXISTS ${index} ON ${table}(owner_broker_id) WHERE wake_requested = 1`);
|
|
235
|
+
},
|
|
236
|
+
})
|
|
237
|
+
)
|
|
238
|
+
await setUpBrokerSchemaOnce(
|
|
239
|
+
database,
|
|
240
|
+
`${table}:wake-index`,
|
|
241
|
+
() => foundInCatalogAgain(database, wakeIndexCurrent),
|
|
242
|
+
(tx) => renameWakeIndex(tx, dialectOf(database), table),
|
|
243
|
+
);
|
|
244
|
+
}
|
|
193
245
|
const columns = `reservation_key, owner_session_id, owner_broker_id, child_name AS child_name_json, child_target,
|
|
194
246
|
targets_json, "group" AS reservation_group, dormant, wake, wake_generation, fencing_token, "order" AS reservation_order,
|
|
195
247
|
gone AS gone_json, end_json,
|
|
@@ -395,6 +447,8 @@ async function openRestoringReservationStoreInCatalog({
|
|
|
395
447
|
async renew(lease): Promise<RestoringReservationRenewResult> {
|
|
396
448
|
const bad = invalidLease(lease);
|
|
397
449
|
if (bad !== undefined) return bad;
|
|
450
|
+
// Renewed again within the renewal interval, far inside the staleness limit: a renewal lost in a crash of the
|
|
451
|
+
// database server leaves the reservation a renewal older and still held, so its commit does not wait for the disk.
|
|
398
452
|
return database.transaction(async (tx) => {
|
|
399
453
|
const stale = await owned(tx, lease);
|
|
400
454
|
if (stale !== undefined) return stale;
|
|
@@ -403,7 +457,201 @@ async function openRestoringReservationStoreInCatalog({
|
|
|
403
457
|
lease.reservationKey,
|
|
404
458
|
);
|
|
405
459
|
return { status: "renewed" };
|
|
406
|
-
}, serial);
|
|
460
|
+
}, { ...serial, relaxedDurability: true });
|
|
461
|
+
},
|
|
462
|
+
async renewMany(leases): Promise<RestoringReservationRenewResult[]> {
|
|
463
|
+
if (leases.length === 0) return [];
|
|
464
|
+
const invalidResults: Array<InvalidStateInput | undefined> = new Array(leases.length);
|
|
465
|
+
let validCount = 0;
|
|
466
|
+
for (let i = 0; i < leases.length; i++) {
|
|
467
|
+
const bad = invalidLease(leases[i]!);
|
|
468
|
+
if (bad !== undefined) invalidResults[i] = bad;
|
|
469
|
+
else validCount++;
|
|
470
|
+
}
|
|
471
|
+
if (validCount === 0) return invalidResults as RestoringReservationRenewResult[];
|
|
472
|
+
const tupleKey = (reservationKey: string, ownerSessionId: string, fencingToken: number) =>
|
|
473
|
+
JSON.stringify([reservationKey.toWellFormed(), ownerSessionId.toWellFormed(), fencingToken]);
|
|
474
|
+
const byTuple = new Map<string, RestoringReservationLease>();
|
|
475
|
+
const validKeys = new Set<string>();
|
|
476
|
+
let hasNonSafeIntToken = false;
|
|
477
|
+
for (let i = 0; i < leases.length; i++) {
|
|
478
|
+
if (invalidResults[i] !== undefined) continue;
|
|
479
|
+
const lease = leases[i]!;
|
|
480
|
+
validKeys.add(lease.reservationKey.toWellFormed());
|
|
481
|
+
if (!Number.isSafeInteger(lease.fencingToken)) {
|
|
482
|
+
hasNonSafeIntToken = true;
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
const tKey = tupleKey(lease.reservationKey, lease.ownerSessionId, lease.fencingToken);
|
|
486
|
+
if (!byTuple.has(tKey)) byTuple.set(tKey, lease);
|
|
487
|
+
}
|
|
488
|
+
const entries = [...byTuple.values()].sort((a, b) => compare(a.reservationKey, b.reservationKey));
|
|
489
|
+
const answer = (
|
|
490
|
+
renewed: ReadonlySet<string>,
|
|
491
|
+
found: ReadonlyMap<string, MissedReservationRow>,
|
|
492
|
+
): RestoringReservationRenewResult[] =>
|
|
493
|
+
leases.map((lease, index): RestoringReservationRenewResult => {
|
|
494
|
+
const bad = invalidResults[index];
|
|
495
|
+
if (bad !== undefined) return bad;
|
|
496
|
+
if (
|
|
497
|
+
Number.isSafeInteger(lease.fencingToken) &&
|
|
498
|
+
renewed.has(tupleKey(lease.reservationKey, lease.ownerSessionId, lease.fencingToken))
|
|
499
|
+
)
|
|
500
|
+
return { status: "renewed" };
|
|
501
|
+
const row = found.get(lease.reservationKey.toWellFormed());
|
|
502
|
+
if (row === undefined || row.end_json !== null) return { status: "stale" };
|
|
503
|
+
return { status: "stale", currentFencingToken: Number(row.fencing_token) };
|
|
504
|
+
});
|
|
505
|
+
if (dialect === "postgres") {
|
|
506
|
+
const keysParam = JSON.stringify([...validKeys], wellFormed);
|
|
507
|
+
if (entries.length === 0) {
|
|
508
|
+
const readAll: SqliteStatement = {
|
|
509
|
+
sql: `SELECT reservation_key, end_json, fencing_token FROM ${table}
|
|
510
|
+
WHERE reservation_key = ANY(ARRAY(SELECT value FROM ${jsonValues("?")}))`,
|
|
511
|
+
params: [keysParam],
|
|
512
|
+
};
|
|
513
|
+
return database.transaction(
|
|
514
|
+
async (tx) => {
|
|
515
|
+
const found = new Map<string, MissedReservationRow>();
|
|
516
|
+
for (const row of await tx.all<MissedReservationRow>(readAll.sql, ...readAll.params))
|
|
517
|
+
found.set(row.reservation_key, row);
|
|
518
|
+
return answer(new Set(), found);
|
|
519
|
+
},
|
|
520
|
+
{ ...serial, leading: [readAll], leadingOnly: true, relaxedDurability: true },
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
const write: SqliteStatement = {
|
|
524
|
+
sql: `WITH requested AS MATERIALIZED (
|
|
525
|
+
SELECT
|
|
526
|
+
entry ->> 0 AS reservation_key,
|
|
527
|
+
entry ->> 1 AS owner_session_id,
|
|
528
|
+
(entry ->> 2)::bigint AS fencing_token
|
|
529
|
+
FROM jsonb_array_elements((?)::jsonb) AS entry
|
|
530
|
+
),
|
|
531
|
+
locked AS MATERIALIZED (
|
|
532
|
+
SELECT t.reservation_key, requested.owner_session_id, requested.fencing_token
|
|
533
|
+
FROM ${table} AS t
|
|
534
|
+
JOIN requested
|
|
535
|
+
ON t.reservation_key = requested.reservation_key
|
|
536
|
+
AND t.owner_session_id = requested.owner_session_id
|
|
537
|
+
AND t.fencing_token = requested.fencing_token
|
|
538
|
+
WHERE t.reservation_key = ANY(ARRAY(SELECT DISTINCT reservation_key FROM requested))
|
|
539
|
+
AND t.end_json IS NULL
|
|
540
|
+
ORDER BY t.reservation_key
|
|
541
|
+
FOR UPDATE OF t
|
|
542
|
+
),
|
|
543
|
+
renewed AS (
|
|
544
|
+
UPDATE ${table} AS t
|
|
545
|
+
SET renewed_at = ${nowMs}
|
|
546
|
+
FROM locked
|
|
547
|
+
WHERE t.reservation_key = locked.reservation_key
|
|
548
|
+
AND t.owner_session_id = locked.owner_session_id
|
|
549
|
+
AND t.fencing_token = locked.fencing_token
|
|
550
|
+
AND t.end_json IS NULL
|
|
551
|
+
RETURNING t.reservation_key, t.owner_session_id, t.fencing_token
|
|
552
|
+
),
|
|
553
|
+
gate AS MATERIALIZED (
|
|
554
|
+
SELECT set_config('${RESERVATION_RENEW_MISSES}',
|
|
555
|
+
CASE WHEN (SELECT COUNT(*) FROM renewed) < CAST(? AS ${types.int}) THEN '1' ELSE '' END,
|
|
556
|
+
true) AS misses
|
|
557
|
+
)
|
|
558
|
+
SELECT renewed.reservation_key, renewed.owner_session_id, renewed.fencing_token
|
|
559
|
+
FROM gate LEFT JOIN renewed ON TRUE`,
|
|
560
|
+
params: [
|
|
561
|
+
JSON.stringify(
|
|
562
|
+
entries.map((lease) => [lease.reservationKey, lease.ownerSessionId, lease.fencingToken]),
|
|
563
|
+
wellFormed,
|
|
564
|
+
),
|
|
565
|
+
entries.length + (hasNonSafeIntToken ? 1 : 0),
|
|
566
|
+
],
|
|
567
|
+
};
|
|
568
|
+
const readMisses: SqliteStatement = {
|
|
569
|
+
sql: `SELECT reservation_key, end_json, fencing_token FROM ${table}
|
|
570
|
+
WHERE current_setting('${RESERVATION_RENEW_MISSES}', true) = '1'
|
|
571
|
+
AND reservation_key = ANY(ARRAY(SELECT value FROM ${jsonValues("?")}))`,
|
|
572
|
+
params: [keysParam],
|
|
573
|
+
};
|
|
574
|
+
return database.transaction(
|
|
575
|
+
async (tx) => {
|
|
576
|
+
const renewed = new Set<string>();
|
|
577
|
+
for (const row of await tx.all<RenewedReservationRow>(write.sql, ...write.params))
|
|
578
|
+
if (
|
|
579
|
+
row.reservation_key !== null &&
|
|
580
|
+
row.owner_session_id !== null &&
|
|
581
|
+
row.fencing_token !== null
|
|
582
|
+
)
|
|
583
|
+
renewed.add(tupleKey(row.reservation_key, row.owner_session_id, Number(row.fencing_token)));
|
|
584
|
+
const found = new Map<string, MissedReservationRow>();
|
|
585
|
+
for (const row of await tx.all<MissedReservationRow>(readMisses.sql, ...readMisses.params))
|
|
586
|
+
found.set(row.reservation_key, row);
|
|
587
|
+
return answer(renewed, found);
|
|
588
|
+
},
|
|
589
|
+
{ ...serial, leading: [write, readMisses], leadingOnly: true, relaxedDurability: true },
|
|
590
|
+
);
|
|
591
|
+
}
|
|
592
|
+
const write: SqliteStatement | undefined =
|
|
593
|
+
entries.length === 0
|
|
594
|
+
? undefined
|
|
595
|
+
: {
|
|
596
|
+
sql: `WITH requested AS (
|
|
597
|
+
SELECT
|
|
598
|
+
json_extract(value, '$[0]') AS req_reservation_key,
|
|
599
|
+
json_extract(value, '$[1]') AS req_owner_session_id,
|
|
600
|
+
json_extract(value, '$[2]') AS req_fencing_token
|
|
601
|
+
FROM json_each(?)
|
|
602
|
+
)
|
|
603
|
+
UPDATE ${table}
|
|
604
|
+
SET renewed_at = ${nowMs}
|
|
605
|
+
FROM requested
|
|
606
|
+
WHERE ${table}.reservation_key = requested.req_reservation_key
|
|
607
|
+
AND ${table}.owner_session_id = requested.req_owner_session_id
|
|
608
|
+
AND ${table}.fencing_token = requested.req_fencing_token
|
|
609
|
+
AND ${table}.end_json IS NULL
|
|
610
|
+
RETURNING reservation_key, owner_session_id, fencing_token`,
|
|
611
|
+
params: [
|
|
612
|
+
JSON.stringify(
|
|
613
|
+
entries.map((lease) => [lease.reservationKey, lease.ownerSessionId, lease.fencingToken]),
|
|
614
|
+
wellFormed,
|
|
615
|
+
),
|
|
616
|
+
],
|
|
617
|
+
};
|
|
618
|
+
const readMissedSql = `SELECT reservation_key, end_json, fencing_token FROM ${table}
|
|
619
|
+
WHERE reservation_key IN (SELECT value FROM ${jsonValues("?")})`;
|
|
620
|
+
return database.transaction(
|
|
621
|
+
async (tx) => {
|
|
622
|
+
const renewed = new Set<string>();
|
|
623
|
+
if (write !== undefined) {
|
|
624
|
+
for (const row of await tx.all<RenewedReservationRow>(write.sql, ...write.params))
|
|
625
|
+
if (
|
|
626
|
+
row.reservation_key !== null &&
|
|
627
|
+
row.owner_session_id !== null &&
|
|
628
|
+
row.fencing_token !== null
|
|
629
|
+
)
|
|
630
|
+
renewed.add(tupleKey(row.reservation_key, row.owner_session_id, Number(row.fencing_token)));
|
|
631
|
+
}
|
|
632
|
+
const missedKeys = new Set<string>();
|
|
633
|
+
for (let i = 0; i < leases.length; i++) {
|
|
634
|
+
if (invalidResults[i] !== undefined) continue;
|
|
635
|
+
const lease = leases[i]!;
|
|
636
|
+
if (
|
|
637
|
+
Number.isSafeInteger(lease.fencingToken) &&
|
|
638
|
+
renewed.has(tupleKey(lease.reservationKey, lease.ownerSessionId, lease.fencingToken))
|
|
639
|
+
)
|
|
640
|
+
continue;
|
|
641
|
+
missedKeys.add(lease.reservationKey.toWellFormed());
|
|
642
|
+
}
|
|
643
|
+
const found = new Map<string, MissedReservationRow>();
|
|
644
|
+
if (missedKeys.size > 0) {
|
|
645
|
+
const rows = await tx.all<MissedReservationRow>(
|
|
646
|
+
readMissedSql,
|
|
647
|
+
JSON.stringify([...missedKeys], wellFormed),
|
|
648
|
+
);
|
|
649
|
+
for (const row of rows) found.set(row.reservation_key, row);
|
|
650
|
+
}
|
|
651
|
+
return answer(renewed, found);
|
|
652
|
+
},
|
|
653
|
+
{ ...serial, relaxedDurability: true },
|
|
654
|
+
);
|
|
407
655
|
},
|
|
408
656
|
async release(lease, outcome): Promise<RestoringReservationReleaseResult> {
|
|
409
657
|
const bad = invalidLease(lease);
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dialectOf,
|
|
3
|
+
type SqliteDatabase,
|
|
4
|
+
type SqliteRow,
|
|
5
|
+
type SqliteValue,
|
|
6
|
+
type StorageDialect,
|
|
7
|
+
validateStoragePrefix,
|
|
8
|
+
} from "@bastani/atomic/storage";
|
|
9
|
+
import { isMissingPrivilege } from "./sql-add-column.js";
|
|
10
|
+
import { brokerSchemaCurrent, ensureBrokerSchema, openCatalogOf, queueBrokerSqliteSetup } from "./sql-schema.js";
|
|
11
|
+
|
|
12
|
+
/** The most rows one retention statement deletes, as River's job cleaner and Oban's pruner bound theirs. */
|
|
13
|
+
export const RETENTION_DELETE_BATCH = 1_000;
|
|
14
|
+
/** The most batches one prune of a table deletes; older rows left over wait for the next maintenance. */
|
|
15
|
+
const RETENTION_DELETE_BATCHES = 100;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The database clock in milliseconds, read once for the whole statement. A retention filter compares a column to it,
|
|
19
|
+
* `column < ${storeNow} - ?`, so the column's index answers the filter: PostgreSQL's clock (`clock_timestamp()`) is
|
|
20
|
+
* volatile, and a comparison with a volatile expression is never an index condition, while a subquery's value is.
|
|
21
|
+
*/
|
|
22
|
+
export function storeNow(database: SqliteDatabase): string {
|
|
23
|
+
return `(SELECT ${dialectOf(database).nowMs})`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The rows of `table` that one retention prune deletes. */
|
|
27
|
+
export interface RetentionDelete {
|
|
28
|
+
readonly table: string;
|
|
29
|
+
/** A column that names each row on its own, such as the primary key. */
|
|
30
|
+
readonly key: string;
|
|
31
|
+
/** The rows to delete: `where`, with `params`, in which `orderBy` is the column an index orders them by. */
|
|
32
|
+
readonly where: string;
|
|
33
|
+
readonly params: readonly SqliteValue[];
|
|
34
|
+
readonly orderBy: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Deletes the rows `request` names, at most `RETENTION_DELETE_BATCH` per statement, until a batch finds fewer, as River's
|
|
39
|
+
* `JobDeleteBefore` and Oban's `prune_jobs` do: each statement reads its rows from the index `orderBy` is the column of
|
|
40
|
+
* and holds their locks only while it runs, so a large backlog never becomes one long statement. Resolves to the number
|
|
41
|
+
* of rows deleted.
|
|
42
|
+
*/
|
|
43
|
+
export async function deleteInBatches(database: SqliteDatabase, request: RetentionDelete): Promise<number> {
|
|
44
|
+
const { table, key, where, params, orderBy } = request;
|
|
45
|
+
const batch = `SELECT ${key} FROM ${table} WHERE ${where} ORDER BY ${orderBy} LIMIT ?`;
|
|
46
|
+
// PostgreSQL: the keys as one array, so the delete finds each row by its key's index; `IN (SELECT …)` can join the
|
|
47
|
+
// whole table instead.
|
|
48
|
+
const sql =
|
|
49
|
+
dialectOf(database).name === "postgres"
|
|
50
|
+
? `DELETE FROM ${table} WHERE ${key} = ANY(ARRAY(${batch}))`
|
|
51
|
+
: `DELETE FROM ${table} WHERE ${key} IN (${batch})`;
|
|
52
|
+
let deleted = 0;
|
|
53
|
+
for (let round = 0; round < RETENTION_DELETE_BATCHES; round++) {
|
|
54
|
+
const { changes } = await database.run(sql, ...params, RETENTION_DELETE_BATCH);
|
|
55
|
+
deleted += changes;
|
|
56
|
+
if (changes < RETENTION_DELETE_BATCH) break;
|
|
57
|
+
}
|
|
58
|
+
return deleted;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The rows still to deliver: every query of a recipient's undelivered rows names them with this text exactly. */
|
|
62
|
+
export const UNDELIVERED = "state IN ('queued', 'claimed')";
|
|
63
|
+
/** The settled outbox rows, which retention deletes. */
|
|
64
|
+
export const SETTLED = "state IN ('delivered', 'failed')";
|
|
65
|
+
/**
|
|
66
|
+
* The outbox's fillfactor on PostgreSQL: each page keeps room for new versions of its rows, so a claim's renewal or a
|
|
67
|
+
* save report, which changes no indexed column, stays on its page as a HOT update.
|
|
68
|
+
*/
|
|
69
|
+
const OUTBOX_FILLFACTOR = 85;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The indexes that keep the broker state's maintenance and sweeps off full scans, created once per database at the end
|
|
73
|
+
* of a broker's open, when every table and column they need is there, as one schema step: `intercom-outbox-indexes`,
|
|
74
|
+
* revision 2, so an older broker, which recorded revision 1 of it, creates nothing of its own again. On a new database
|
|
75
|
+
* it is the one schema transaction the outbox's indexes always took.
|
|
76
|
+
* - `<outbox>_undelivered`, `(target_identity, sequence)` over the undelivered rows only, with `frame_bytes` alongside:
|
|
77
|
+
* every claim, scan and send reads a recipient's undelivered rows in sequence order and sums their sizes from it. It
|
|
78
|
+
* holds no settled row, so it stays the size of what is still to deliver. SQLite has no `INCLUDE`: there `frame_bytes`
|
|
79
|
+
* is its last column.
|
|
80
|
+
* - `<outbox>_settled`, `settled_at` over the settled rows, which retention deletes oldest first.
|
|
81
|
+
* - `<released asks>_expires`, by which retention finds the expired released asks.
|
|
82
|
+
* - `<known sessions>_lost` and `<pending asks>_ended`, partial: every broker's backup poll sweeps for the recipients
|
|
83
|
+
* and asks a stopped broker left, and reads only those, rather than every known session and pending ask.
|
|
84
|
+
* The outbox's earlier indexes, `<outbox>_target` and `<outbox>_target_bytes`, keyed by `(target_identity, state, …)`,
|
|
85
|
+
* are dropped: every claim and settlement changed a key of both. On PostgreSQL the outbox's fillfactor is set too.
|
|
86
|
+
* A role that does not own the tables (a runtime role with only DML privileges) leaves all of it to `atomic storage
|
|
87
|
+
* migrate`, run as the owner role, without trying; every query works without them.
|
|
88
|
+
*/
|
|
89
|
+
export async function ensureRetentionIndexes(database: SqliteDatabase, prefix: string | undefined): Promise<void> {
|
|
90
|
+
const dialect = dialectOf(database);
|
|
91
|
+
const named = validateStoragePrefix(prefix, dialect.name);
|
|
92
|
+
const outbox = `${named}intercom_outbox`;
|
|
93
|
+
const released = `${named}intercom_released_asks`;
|
|
94
|
+
const known = `${named}intercom_known_sessions`;
|
|
95
|
+
const pending = `${named}intercom_pending_asks`;
|
|
96
|
+
const postgres = dialect.name === "postgres";
|
|
97
|
+
if (await brokerSchemaCurrent(database, prefix, "outbox-indexes", 2)) return;
|
|
98
|
+
const catalog = await openCatalogOf(database);
|
|
99
|
+
// PostgreSQL: a table this open created is this role's; otherwise the role must own the outbox to change it.
|
|
100
|
+
if (postgres && (catalog === undefined || catalog.hasTable(outbox))) {
|
|
101
|
+
// A host whose storage API predates identifier hashing names every table as given.
|
|
102
|
+
const name = (dialect as Partial<StorageDialect>).identifier?.(outbox) ?? outbox;
|
|
103
|
+
const found = await database.get<SqliteRow & { owned: boolean | number }>(
|
|
104
|
+
`SELECT pg_catalog.pg_has_role(current_user, c.relowner, 'USAGE') AS owned FROM pg_catalog.pg_class c
|
|
105
|
+
WHERE c.relnamespace = current_schema()::regnamespace AND c.relname = ?`,
|
|
106
|
+
name,
|
|
107
|
+
);
|
|
108
|
+
if (found === undefined || !(found.owned === true || Number(found.owned) === 1)) return;
|
|
109
|
+
}
|
|
110
|
+
const retired = [`${outbox}_target`, `${outbox}_target_bytes`];
|
|
111
|
+
const undelivered = postgres
|
|
112
|
+
? "(target_identity, sequence) INCLUDE (frame_bytes)"
|
|
113
|
+
: "(target_identity, sequence, frame_bytes)";
|
|
114
|
+
const created = [
|
|
115
|
+
`CREATE INDEX IF NOT EXISTS ${outbox}_undelivered ON ${outbox}${undelivered} WHERE ${UNDELIVERED}`,
|
|
116
|
+
`CREATE INDEX IF NOT EXISTS ${outbox}_settled ON ${outbox}(settled_at) WHERE ${SETTLED}`,
|
|
117
|
+
`CREATE INDEX IF NOT EXISTS ${released}_expires ON ${released}(expires_at)`,
|
|
118
|
+
`CREATE INDEX IF NOT EXISTS ${known}_lost ON ${known}(lost_at) WHERE lost_at IS NOT NULL`,
|
|
119
|
+
`CREATE INDEX IF NOT EXISTS ${pending}_ended ON ${pending}(ended_at) WHERE ended_at IS NOT NULL AND replied IS NULL`,
|
|
120
|
+
];
|
|
121
|
+
const drops = retired.map((index) => `DROP INDEX IF EXISTS ${index}`);
|
|
122
|
+
// SQLite, which records no step, runs only the creations in it, so an open whose catalog finds every index takes no
|
|
123
|
+
// write transaction; the retired indexes are dropped apart.
|
|
124
|
+
const script = postgres
|
|
125
|
+
? [...created, ...drops, `ALTER TABLE ${outbox} SET (fillfactor = ${OUTBOX_FILLFACTOR})`]
|
|
126
|
+
: created;
|
|
127
|
+
try {
|
|
128
|
+
await ensureBrokerSchema(database, prefix, "outbox-indexes", (tx) => tx.exec(script.join(";\n")), 2);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
if (isMissingPrivilege(error)) return;
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
if (postgres) return;
|
|
134
|
+
// An older broker's open recreates them where it records no step.
|
|
135
|
+
const present =
|
|
136
|
+
catalog?.sqliteObjectType === undefined
|
|
137
|
+
? (await database.all("SELECT name FROM sqlite_master WHERE type = 'index' AND name IN (?, ?)", ...retired))
|
|
138
|
+
.length > 0
|
|
139
|
+
: retired.some((index) => catalog.sqliteObjectType?.(index) === "index");
|
|
140
|
+
if (present) {
|
|
141
|
+
const queued = queueBrokerSqliteSetup(database, prefix ?? "", {
|
|
142
|
+
verify: (found) => !retired.some((index) => found.sqliteObjectType?.(index) === "index"),
|
|
143
|
+
run(ctx) {
|
|
144
|
+
if (ctx.catalog === undefined || retired.some((index) => ctx.catalog?.sqliteObjectType?.(index) === "index"))
|
|
145
|
+
ctx.enqueue(drops.join(";\n"));
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
if (!queued) await database.transaction((tx) => tx.exec(drops.join(";\n")));
|
|
149
|
+
}
|
|
150
|
+
}
|