@bastani/atomic 0.10.11-alpha.2 → 0.10.11
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 +307 -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 +88 -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 +20 -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 +1498 -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
|
@@ -26,6 +26,17 @@ export const BROKER_LEASE_STALE_AFTER_MS = 30_000;
|
|
|
26
26
|
export const OUTBOX_CLAIM_STALE_AFTER_MS = 30_000;
|
|
27
27
|
/** Safety-net outbox scan interval for brokers whose wake-ups were lost. */
|
|
28
28
|
export const OUTBOX_BACKUP_POLL_INTERVAL_MS = 30_000;
|
|
29
|
+
/**
|
|
30
|
+
* How often the swarm's maintainer, one broker holding the maintenance lease, prunes the shared state past its retention
|
|
31
|
+
* and expires the outbox rows left queued too long; each other broker checks this often whether the lease went stale.
|
|
32
|
+
* Like Oban's leader-only pruner and River's maintenance leader, one broker does it, not every broker every backup poll.
|
|
33
|
+
*/
|
|
34
|
+
export const MAINTENANCE_INTERVAL_MS = 5 * 60_000;
|
|
35
|
+
/**
|
|
36
|
+
* Age after which another broker takes the maintenance lease over: the maintainer renews it by taking it again each
|
|
37
|
+
* `MAINTENANCE_INTERVAL_MS`, so it goes stale only once the maintainer stopped.
|
|
38
|
+
*/
|
|
39
|
+
export const MAINTENANCE_STALE_AFTER_MS = 2 * MAINTENANCE_INTERVAL_MS;
|
|
29
40
|
/** How long a session that left stays known, so a send to it is queued for its return (spec §14, S5 amendment). */
|
|
30
41
|
export const KNOWN_SESSION_RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
31
42
|
/**
|
|
@@ -68,6 +79,7 @@ export type StateStoreInvalidReason =
|
|
|
68
79
|
| "empty-child-name"
|
|
69
80
|
| "empty-target"
|
|
70
81
|
| "empty-group"
|
|
82
|
+
| "empty-task"
|
|
71
83
|
| "subject-key-mismatch";
|
|
72
84
|
|
|
73
85
|
export interface InvalidStateInput {
|
|
@@ -75,7 +87,7 @@ export interface InvalidStateInput {
|
|
|
75
87
|
readonly reason: StateStoreInvalidReason;
|
|
76
88
|
}
|
|
77
89
|
|
|
78
|
-
export type LeaseKind = "broker" | "presence";
|
|
90
|
+
export type LeaseKind = "broker" | "presence" | "maintenance";
|
|
79
91
|
|
|
80
92
|
/** Broker membership: one row per running broker process, keyed by its random `brokerId`. */
|
|
81
93
|
export interface BrokerMembershipSubject {
|
|
@@ -96,6 +108,11 @@ export interface BrokerMembershipSubject {
|
|
|
96
108
|
readonly instanceKey?: string;
|
|
97
109
|
/** #5038: the broker's process id, checked on its host before a later instance supersedes it. */
|
|
98
110
|
readonly pid?: number;
|
|
111
|
+
/**
|
|
112
|
+
* The broker listens for wake-up notifications on a channel of its own (`brokerWakeUpChannel`), so a sender need not
|
|
113
|
+
* notify the channel every broker of an earlier release listens on. Absent from older brokers.
|
|
114
|
+
*/
|
|
115
|
+
readonly ownWakeUpChannel?: true;
|
|
99
116
|
}
|
|
100
117
|
|
|
101
118
|
/** Recipient presence: which broker currently hosts the recipient's socket. */
|
|
@@ -117,11 +134,21 @@ export interface PresenceAlias {
|
|
|
117
134
|
readonly owner: string;
|
|
118
135
|
}
|
|
119
136
|
|
|
120
|
-
|
|
137
|
+
/**
|
|
138
|
+
* The swarm's maintainer: the broker that runs one kind of shared maintenance, `task`, such as `"retention"`. Older
|
|
139
|
+
* brokers never read this kind, and keep their own maintenance.
|
|
140
|
+
*/
|
|
141
|
+
export interface MaintenanceSubject {
|
|
142
|
+
readonly kind: "maintenance";
|
|
143
|
+
readonly task: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type LeaseSubject = BrokerMembershipSubject | RecipientPresenceSubject | MaintenanceSubject;
|
|
121
147
|
|
|
122
148
|
export type LeaseKey =
|
|
123
149
|
| { readonly kind: "broker"; readonly brokerId: string }
|
|
124
|
-
| { readonly kind: "presence"; readonly targetIdentity: string }
|
|
150
|
+
| { readonly kind: "presence"; readonly targetIdentity: string }
|
|
151
|
+
| { readonly kind: "maintenance"; readonly task: string };
|
|
125
152
|
|
|
126
153
|
export interface Lease {
|
|
127
154
|
readonly key: LeaseKey;
|
|
@@ -301,8 +328,23 @@ export type OutboxClaimWriteRejection =
|
|
|
301
328
|
|
|
302
329
|
export type OutboxRenewClaimResult = { readonly status: "renewed" } | OutboxClaimWriteRejection;
|
|
303
330
|
export type OutboxReleaseClaimResult = { readonly status: "released" } | OutboxClaimWriteRejection;
|
|
331
|
+
export interface OutboxMarkDeliveredOptions {
|
|
332
|
+
/**
|
|
333
|
+
* Write the database wake-up bus's `outcome` hint for a settled row whose `originBrokerId` differs from
|
|
334
|
+
* `claim.claimantId` inside the settlement itself, so settling and waking its origin commit together in one round
|
|
335
|
+
* trip (#6715). A store that ignores it (or could not take the hint log's lock without waiting) omits `woke`, and
|
|
336
|
+
* the caller wakes the origin itself.
|
|
337
|
+
*/
|
|
338
|
+
readonly wakeOrigin?: boolean;
|
|
339
|
+
}
|
|
340
|
+
|
|
304
341
|
export type OutboxDeliveredResult =
|
|
305
|
-
| {
|
|
342
|
+
| {
|
|
343
|
+
readonly status: "delivered";
|
|
344
|
+
readonly row: OutboxRow;
|
|
345
|
+
/** With `wakeOrigin`, the origin broker the settlement sent an `outcome` wake-up hint to (#6715). */
|
|
346
|
+
readonly woke?: string;
|
|
347
|
+
}
|
|
306
348
|
| OutboxClaimWriteRejection;
|
|
307
349
|
export type OutboxFailedResult = { readonly status: "failed"; readonly row: OutboxRow } | OutboxClaimWriteRejection;
|
|
308
350
|
export type OutboxReadResult =
|
|
@@ -324,6 +366,11 @@ export interface OutboxStore {
|
|
|
324
366
|
*/
|
|
325
367
|
claim(request: OutboxClaimRequest): Promise<OutboxClaimResult>;
|
|
326
368
|
renewClaim(claim: OutboxClaim): Promise<OutboxRenewClaimResult>;
|
|
369
|
+
/**
|
|
370
|
+
* `renewClaim` for each of `claims`, of distinct rows, in one transaction whose one statement renews every claim still
|
|
371
|
+
* current, answered in the order given (#6560). Optional: without it, a broker renews its claims one at a time.
|
|
372
|
+
*/
|
|
373
|
+
renewClaims?(claims: readonly OutboxClaim[]): Promise<OutboxRenewClaimResult[]>;
|
|
327
374
|
/**
|
|
328
375
|
* #3983: the claim's recipient reports it is still saving the row, so the sender's broker keeps its sender
|
|
329
376
|
* waiting. Optional: a store without it never extends a sender's wait.
|
|
@@ -335,6 +382,14 @@ export interface OutboxStore {
|
|
|
335
382
|
* never claimed, as it was before this claim.
|
|
336
383
|
*/
|
|
337
384
|
releaseClaim(claim: OutboxClaim, options?: { readonly unwritten?: boolean }): Promise<OutboxReleaseClaimResult>;
|
|
385
|
+
/**
|
|
386
|
+
* `releaseClaim` for each of `claims`, in one transaction whose statement releases every claim still current,
|
|
387
|
+
* answered in the order given (#6713). Optional: without it, a broker releases its claims one at a time.
|
|
388
|
+
*/
|
|
389
|
+
releaseClaims?(
|
|
390
|
+
claims: readonly OutboxClaim[],
|
|
391
|
+
options?: { readonly unwritten?: boolean },
|
|
392
|
+
): Promise<OutboxReleaseClaimResult[]>;
|
|
338
393
|
/**
|
|
339
394
|
* #5038: return every row `claimantId` holds to `queued`, as its own `releaseClaim` would, so a dead broker's
|
|
340
395
|
* claims stop holding its recipients' queues until they go stale. Resolves to the number of rows released.
|
|
@@ -345,7 +400,7 @@ export interface OutboxStore {
|
|
|
345
400
|
* route with `PendingAskStore.record` first: a settled row is never claimed again, so a route written after it
|
|
346
401
|
* would be lost if the broker stopped between the two writes.
|
|
347
402
|
*/
|
|
348
|
-
markDelivered(claim: OutboxClaim): Promise<OutboxDeliveredResult>;
|
|
403
|
+
markDelivered(claim: OutboxClaim, options?: OutboxMarkDeliveredOptions): Promise<OutboxDeliveredResult>;
|
|
349
404
|
/** The recipient's broker refused the row; `reason` is reported to the sender verbatim. */
|
|
350
405
|
markFailed(claim: OutboxClaim, reason: string): Promise<OutboxFailedResult>;
|
|
351
406
|
read(messageId: string): Promise<OutboxReadResult>;
|
|
@@ -354,6 +409,12 @@ export interface OutboxStore {
|
|
|
354
409
|
* first `limit` of them.
|
|
355
410
|
*/
|
|
356
411
|
listUndelivered(targetIdentity: string, limit?: number): Promise<OutboxListResult>;
|
|
412
|
+
/**
|
|
413
|
+
* Which of `targetIdentities` have `queued` or `claimed` rows, read in one statement, so a broker that scans every
|
|
414
|
+
* recipient it hosts claims only for those (#6560). A row queued after the read is found by the claim its send's
|
|
415
|
+
* wake-up hint starts, or by the next scan. Optional: without it, the broker claims for each recipient.
|
|
416
|
+
*/
|
|
417
|
+
withUndelivered?(targetIdentities: readonly string[]): Promise<ReadonlySet<string>>;
|
|
357
418
|
/**
|
|
358
419
|
* #4896: where `messageId` stands in its recipient's undelivered rows, from 1 for the oldest, counted without
|
|
359
420
|
* reading any row: `missing` when it is not one of them.
|
|
@@ -554,6 +615,11 @@ export interface RestoringReservationStore {
|
|
|
554
615
|
): Promise<RestoringReservationLookupResult>;
|
|
555
616
|
/** Reset the age, also of a gone marker. A superseded token or an ended reservation is `stale`. */
|
|
556
617
|
renew(lease: RestoringReservationLease): Promise<RestoringReservationRenewResult>;
|
|
618
|
+
/**
|
|
619
|
+
* Reset the age of multiple reservations, also of gone markers, in a single shared-store transaction, returning one
|
|
620
|
+
* result per entry in input order (#6714). Absent on custom stores that only implement `renew`.
|
|
621
|
+
*/
|
|
622
|
+
renewMany?(leases: readonly RestoringReservationLease[]): Promise<RestoringReservationRenewResult[]>;
|
|
557
623
|
/** Owner only: mark the reservation gone, or end it as `released`. */
|
|
558
624
|
release(
|
|
559
625
|
lease: RestoringReservationLease,
|
|
@@ -24,6 +24,7 @@ import { openSqlBrokerLeaseStore } from "./sql-lease-store.js";
|
|
|
24
24
|
import { openSqlOutboxStore, recipientTransaction, runLast, withoutFailedWake } from "./sql-outbox-store.js";
|
|
25
25
|
import { openSqlPendingAskStore } from "./sql-pending-ask-store.js";
|
|
26
26
|
import { openSqlReleasedAskStore } from "./sql-released-ask-store.js";
|
|
27
|
+
import { ensureRetentionIndexes } from "./sql-retention.js";
|
|
27
28
|
import { openSqlRestoringReservationStore } from "./sql-restoring-reservation-store.js";
|
|
28
29
|
import { withBrokerSchemaCatalog } from "./sql-schema.js";
|
|
29
30
|
import { openSqlSentMessageAuthority } from "./sql-sent-message-authority.js";
|
|
@@ -162,6 +163,7 @@ export async function openIntercomBrokerState(
|
|
|
162
163
|
const releasedAsks = await openSqlReleasedAskStore(options);
|
|
163
164
|
const sentMessages = await openSqlSentMessageAuthority(options);
|
|
164
165
|
const knownSessions = await openSqlKnownSessionStore(options);
|
|
166
|
+
await ensureRetentionIndexes(database, options.prefix);
|
|
165
167
|
const bus = await openDatabaseWakeUpBus({
|
|
166
168
|
openDatabase: async () => borrowed,
|
|
167
169
|
prefix: source.prefix,
|
|
@@ -187,6 +189,18 @@ export async function openIntercomBrokerState(
|
|
|
187
189
|
reserveAndEnqueue(reservation, request) {
|
|
188
190
|
// The recipient's domain: sends to it run one at a time, and sends to others beside them (#6560).
|
|
189
191
|
const send = recipientTransaction(database, source.prefix, request.targetIdentity);
|
|
192
|
+
// PostgreSQL: one round trip, decided by the database, so the recipient's domain is held for no round trip
|
|
193
|
+
// and sends to a busy recipient do not queue for its lock past the lock timeout.
|
|
194
|
+
// A send to a recipient its sender found offline too, whose wake-up hint the same round trip writes.
|
|
195
|
+
const reserved = sentMessages.reservationOf(reservation);
|
|
196
|
+
const enqueueAtOnce = outbox.enqueueAtOnce;
|
|
197
|
+
if (reserved !== undefined && enqueueAtOnce !== undefined) {
|
|
198
|
+
const first = enqueueAtOnce(request, reserved);
|
|
199
|
+
if (first !== undefined)
|
|
200
|
+
return withoutFailedWake(request, (attempt) =>
|
|
201
|
+
attempt === request ? first : enqueueAtOnce(attempt, reserved)!,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
190
204
|
// The reservation's read and the enqueue's go out with the transaction's start, the reservation's write
|
|
191
205
|
// and the row's insert together, then the commit, on a pipelined connection: three round trips (#6560).
|
|
192
206
|
const leading = (attempt: typeof request) => [
|
|
@@ -99,7 +99,7 @@ export interface WaitForEarlierOptions {
|
|
|
99
99
|
*/
|
|
100
100
|
readonly blockerProgressAt?: (earlier: SendOrderTicket) => number | undefined;
|
|
101
101
|
/** Silence window (ms) to wait past a progressing blocker's latest store answer; 0 disables extension. */
|
|
102
|
-
readonly progressSilenceMs?: number;
|
|
102
|
+
readonly progressSilenceMs?: number | ((earlier: SendOrderTicket) => number);
|
|
103
103
|
/** Hard monotonic deadline (`performance.now()`) past which progress extensions stop. */
|
|
104
104
|
readonly maxLocalWaitUntil?: number;
|
|
105
105
|
}
|
|
@@ -307,7 +307,10 @@ export class SendOrderGate {
|
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
private extensionRemainingMs(earlier: InternalTicket, options: WaitForEarlierOptions): number {
|
|
310
|
-
const silenceMs =
|
|
310
|
+
const silenceMs =
|
|
311
|
+
typeof options.progressSilenceMs === "function"
|
|
312
|
+
? options.progressSilenceMs(earlier)
|
|
313
|
+
: (options.progressSilenceMs ?? 0);
|
|
311
314
|
if (silenceMs <= 0 || options.blockerProgressAt === undefined) return 0;
|
|
312
315
|
const progressAt = options.blockerProgressAt(earlier);
|
|
313
316
|
if (progressAt === undefined) return 0;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { dialectOf, type SqliteDatabase } from "@bastani/atomic/storage";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
catalogHasColumns,
|
|
4
|
+
foundInCatalogAgain,
|
|
5
|
+
queueBrokerSqliteSetup,
|
|
6
|
+
RETRY_UNAPPLIED,
|
|
7
|
+
setUpBrokerSchemaOnce,
|
|
8
|
+
} from "./sql-schema.js";
|
|
3
9
|
|
|
4
10
|
function isLineTerminatorCode(code: number): boolean {
|
|
5
11
|
return code === 0x0a || code === 0x0d || code === 0x2028 || code === 0x2029;
|
|
@@ -114,8 +120,9 @@ export async function addOptionalColumn(
|
|
|
114
120
|
|
|
115
121
|
/**
|
|
116
122
|
* Adds each missing column of `columns` (name → definition after the name) to `table`, in order. A table from an older
|
|
117
|
-
* broker gets the columns, and an older broker ignores them.
|
|
118
|
-
*
|
|
123
|
+
* broker gets the columns, and an older broker ignores them. The columns are probed and added in one transaction, which
|
|
124
|
+
* one of the brokers opening the store at once runs while the others wait for it without its lock (#5054, #6560); an
|
|
125
|
+
* older broker adding one meanwhile is not an error.
|
|
119
126
|
*/
|
|
120
127
|
export async function addMissingColumns(
|
|
121
128
|
database: SqliteDatabase,
|
|
@@ -124,8 +131,46 @@ export async function addMissingColumns(
|
|
|
124
131
|
withColumn?: string,
|
|
125
132
|
): Promise<void> {
|
|
126
133
|
const dialect = dialectOf(database);
|
|
134
|
+
const names = Object.keys(columns);
|
|
127
135
|
// An open that read the catalog and found every column there runs no transaction (#6560).
|
|
128
|
-
if (await catalogHasColumns(database, table,
|
|
136
|
+
if (await catalogHasColumns(database, table, names)) return;
|
|
137
|
+
// Inside a SQLite open scope, queue missing column additions into the open's single write transaction (#6709).
|
|
138
|
+
if (
|
|
139
|
+
queueBrokerSqliteSetup(database, undefined, {
|
|
140
|
+
verify: (catalog) => names.every((column) => catalog.hasColumn(table, column)),
|
|
141
|
+
run(ctx) {
|
|
142
|
+
for (const [column, definition] of Object.entries(columns)) {
|
|
143
|
+
if (ctx.hasColumn(table, column)) continue;
|
|
144
|
+
ctx.enqueue(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`, { ignoreError: isDuplicateColumn });
|
|
145
|
+
ctx.noteColumnAdded(table, column);
|
|
146
|
+
if (withColumn !== undefined) ctx.enqueue(withColumn);
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
})
|
|
150
|
+
)
|
|
151
|
+
return;
|
|
152
|
+
const probes = names.map((column) => dialect.columnExists(table, column));
|
|
153
|
+
try {
|
|
154
|
+
await setUpBrokerSchemaOnce(
|
|
155
|
+
database,
|
|
156
|
+
`${table}:columns`,
|
|
157
|
+
() => foundInCatalogAgain(database, (catalog) => names.every((column) => catalog.hasColumn(table, column))),
|
|
158
|
+
async (tx) => {
|
|
159
|
+
// The probes go out together, then each column they found missing is added.
|
|
160
|
+
const found = await Promise.all(probes.map((probe) => tx.all(probe.sql, ...probe.params)));
|
|
161
|
+
for (const [index, [column, definition]] of Object.entries(columns).entries()) {
|
|
162
|
+
if (found[index]!.length > 0) continue;
|
|
163
|
+
await tx.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
|
|
164
|
+
if (withColumn !== undefined) await tx.exec(withColumn);
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
probes,
|
|
168
|
+
);
|
|
169
|
+
return;
|
|
170
|
+
} catch (error) {
|
|
171
|
+
if (!isDuplicateColumn(error)) throw error;
|
|
172
|
+
}
|
|
173
|
+
// An older broker added one of them meanwhile: each of the others in a transaction of its own.
|
|
129
174
|
for (const [column, definition] of Object.entries(columns)) {
|
|
130
175
|
const probe = dialect.columnExists(table, column);
|
|
131
176
|
try {
|
|
@@ -133,7 +178,7 @@ export async function addMissingColumns(
|
|
|
133
178
|
if ((await tx.all(probe.sql, ...probe.params)).length > 0) return;
|
|
134
179
|
await tx.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
|
|
135
180
|
if (withColumn !== undefined) await tx.exec(withColumn);
|
|
136
|
-
});
|
|
181
|
+
}, RETRY_UNAPPLIED);
|
|
137
182
|
} catch (error) {
|
|
138
183
|
if (!isDuplicateColumn(error)) throw error;
|
|
139
184
|
}
|
|
@@ -919,11 +919,12 @@ export async function openSqlEndedChildQueueStore(
|
|
|
919
919
|
if (!counting && !ledger.holdsMessages()) recountSoon();
|
|
920
920
|
};
|
|
921
921
|
// A step that runs only while the database is idle and its lock free at once; a database that cannot say so runs it
|
|
922
|
-
// as a transaction of its own, apart from the message writes.
|
|
922
|
+
// as a transaction of its own, apart from the message writes. It touches the queue's own tables alone, so on a shared
|
|
923
|
+
// database it excludes the queue's writers, as they exclude one another, not every writer of the database.
|
|
923
924
|
const maintain: (callback: (tx: SqliteExecutor) => Promise<void>) => Promise<boolean> =
|
|
924
925
|
database.tryMaintenance?.bind(database) ??
|
|
925
926
|
((callback) =>
|
|
926
|
-
database.transaction(callback).then(
|
|
927
|
+
database.transaction(callback, { concurrency: { kind: "serial", domain: queue } }).then(
|
|
927
928
|
() => true,
|
|
928
929
|
() => false,
|
|
929
930
|
));
|
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
InvalidStateInput,
|
|
12
12
|
StateStoreInvalidReason,
|
|
13
13
|
} from "./multinode-state-store.js";
|
|
14
|
-
import { ensureBrokerSchema, withBrokerSchemaCatalog } from "./sql-schema.js";
|
|
14
|
+
import { ensureBrokerSchema, RETRY_UNAPPLIED, withBrokerSchemaCatalog } from "./sql-schema.js";
|
|
15
15
|
|
|
16
16
|
type HeldRow = SqliteRow & {
|
|
17
17
|
reservation_key: string;
|
|
@@ -45,7 +45,7 @@ async function openHeldSendStoreInCatalog({ database, prefix }: IntercomBrokerSt
|
|
|
45
45
|
const table = `${validateStoragePrefix(prefix, dialectOf(database).name)}intercom_held_sends`;
|
|
46
46
|
const { types, nowMs } = dialectOf(database);
|
|
47
47
|
/** `take` reads and writes this table alone, so it excludes other takes, not every writer (#6560). */
|
|
48
|
-
const serial = { concurrency: { kind: "serial", domain: table } } as const;
|
|
48
|
+
const serial = { ...RETRY_UNAPPLIED, concurrency: { kind: "serial", domain: table } } as const;
|
|
49
49
|
await ensureBrokerSchema(database, prefix, "held-sends", (tx) =>
|
|
50
50
|
tx.exec(`
|
|
51
51
|
CREATE TABLE IF NOT EXISTS ${table}(
|
|
@@ -13,7 +13,8 @@ import type {
|
|
|
13
13
|
SessionIdReclaim,
|
|
14
14
|
SessionIdReclaimResult,
|
|
15
15
|
} from "./multinode-state-store.js";
|
|
16
|
-
import {
|
|
16
|
+
import { deleteInBatches, storeNow } from "./sql-retention.js";
|
|
17
|
+
import { ensureBrokerSchema, RETRY_UNAPPLIED, withBrokerSchemaCatalog } from "./sql-schema.js";
|
|
17
18
|
|
|
18
19
|
type BindingRow = SqliteRow & { return_address: string; owner_token?: string | null; owner_broker?: string | null };
|
|
19
20
|
|
|
@@ -83,6 +84,8 @@ async function openKnownSessionStoreInCatalog({
|
|
|
83
84
|
const leases = `${validateStoragePrefix(prefix, dialectOf(database).name)}intercom_leases`;
|
|
84
85
|
const { types, nowMs, greatest } = dialectOf(database);
|
|
85
86
|
const age = greatest("0", `${nowMs} - recorded_at`);
|
|
87
|
+
/** The database clock, read once per statement: `recorded_at` compared with it is answered by its index. */
|
|
88
|
+
const now = storeNow(database);
|
|
86
89
|
/** `age` at the statement's one reading of the clock, from `WITH clock`. */
|
|
87
90
|
const clockAge = greatest("0", "(SELECT now FROM clock) - recorded_at");
|
|
88
91
|
await ensureBrokerSchema(database, prefix, "known-sessions", (tx) =>
|
|
@@ -196,7 +199,7 @@ async function openKnownSessionStoreInCatalog({
|
|
|
196
199
|
owner: KnownSessionOwner | undefined,
|
|
197
200
|
): Promise<KnownSessionBindResult> => {
|
|
198
201
|
await tx.run(
|
|
199
|
-
`DELETE FROM ${bindings} WHERE intercom_session_id = ? AND ${
|
|
202
|
+
`DELETE FROM ${bindings} WHERE intercom_session_id = ? AND recorded_at < ${now} - ?`,
|
|
200
203
|
intercomSessionId,
|
|
201
204
|
retentionMs,
|
|
202
205
|
);
|
|
@@ -255,11 +258,27 @@ async function openKnownSessionStoreInCatalog({
|
|
|
255
258
|
return { status: "bound" };
|
|
256
259
|
};
|
|
257
260
|
|
|
261
|
+
/**
|
|
262
|
+
* The writes of this store that `lookup` and `binding` read, started and not finished. Those reads go through the
|
|
263
|
+
* reader, which no write of this store is queued on, so they first wait for these: a caller that starts a write and
|
|
264
|
+
* then reads, without awaiting the write, reads it. With none unfinished they wait for nothing.
|
|
265
|
+
*/
|
|
266
|
+
const unfinished = new Set<Promise<void>>();
|
|
267
|
+
const writing = <T>(write: Promise<T>): Promise<T> => {
|
|
268
|
+
const settled = write.then(
|
|
269
|
+
() => {},
|
|
270
|
+
() => {},
|
|
271
|
+
);
|
|
272
|
+
unfinished.add(settled);
|
|
273
|
+
void settled.then(() => unfinished.delete(settled));
|
|
274
|
+
return write;
|
|
275
|
+
};
|
|
276
|
+
|
|
258
277
|
const reclaim = async (request: SessionIdReclaim): Promise<SessionIdReclaimResult> => {
|
|
259
278
|
if (request.intercomSessionId.length === 0 || request.freshId.length === 0)
|
|
260
279
|
return { status: "invalid", reason: "empty-session-id" };
|
|
261
280
|
const owning = owned ? request.owner : undefined;
|
|
262
|
-
|
|
281
|
+
const reclaiming = database.transaction(
|
|
263
282
|
async (tx) => {
|
|
264
283
|
// A session of this return address that another broker presents, in any group, holds the id there.
|
|
265
284
|
const identities = returnIdentityPrefix(request.returnAddress);
|
|
@@ -267,7 +286,7 @@ async function openKnownSessionStoreInCatalog({
|
|
|
267
286
|
`UPDATE ${bindings} SET recorded_at = ${nowMs}${
|
|
268
287
|
owning === undefined ? "" : `, owner_token = ?, owner_broker = ?, owner_renewed_at = ${nowMs}`
|
|
269
288
|
}
|
|
270
|
-
WHERE intercom_session_id = ? AND return_address = ? AND latest_claim = ? AND ${
|
|
289
|
+
WHERE intercom_session_id = ? AND return_address = ? AND latest_claim = ? AND recorded_at >= ${now} - ?
|
|
271
290
|
AND NOT EXISTS (
|
|
272
291
|
SELECT 1 FROM ${leases} presence
|
|
273
292
|
WHERE presence.kind = 'presence' AND substr(presence.key, 1, length(?)) = ? AND presence.holder_id IS NOT NULL
|
|
@@ -315,8 +334,9 @@ async function openKnownSessionStoreInCatalog({
|
|
|
315
334
|
: await bindIn(tx, request.freshId, request.returnAddress, request.retentionMs, undefined, owning);
|
|
316
335
|
return { status: "fresh", binding } as const;
|
|
317
336
|
},
|
|
318
|
-
{ concurrency: { kind: "serial", domain: bindings } },
|
|
337
|
+
{ ...RETRY_UNAPPLIED, concurrency: { kind: "serial", domain: bindings } },
|
|
319
338
|
);
|
|
339
|
+
return writing(reclaiming);
|
|
320
340
|
};
|
|
321
341
|
|
|
322
342
|
return {
|
|
@@ -325,7 +345,7 @@ async function openKnownSessionStoreInCatalog({
|
|
|
325
345
|
if (session.targetIdentity.length === 0) return { status: "invalid", reason: "empty-target-identity" };
|
|
326
346
|
if (session.intercomSessionId.length === 0) return { status: "invalid", reason: "empty-session-id" };
|
|
327
347
|
if (session.group.length === 0) return { status: "invalid", reason: "empty-group" };
|
|
328
|
-
|
|
348
|
+
const recording = database.run(
|
|
329
349
|
`INSERT INTO ${table}(target_identity, intercom_session_id, name_json, name_key, atomic_session_id,
|
|
330
350
|
group_name, groups_json, recipient_purpose, reply_capability, recorded_at${aliasColumn})
|
|
331
351
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ${nowMs}${aliased ? ", ?" : ""})
|
|
@@ -352,11 +372,13 @@ async function openKnownSessionStoreInCatalog({
|
|
|
352
372
|
// #5607: last, so every earlier value keeps its place.
|
|
353
373
|
...(aliased ? [session.aliasSessionId ?? null] : []),
|
|
354
374
|
);
|
|
375
|
+
await writing(recording);
|
|
355
376
|
return { status: "recorded" };
|
|
356
377
|
},
|
|
357
378
|
async lookup(target, retentionMs): Promise<KnownSessionLookupResult> {
|
|
358
379
|
if (target.length === 0) return { status: "invalid", reason: "empty-target" };
|
|
359
|
-
// Through the reader, which never waits behind this database's writes (#6560).
|
|
380
|
+
// Through the reader, which never waits behind this database's writes (#6560), only for this store's own.
|
|
381
|
+
if (unfinished.size > 0) await Promise.all(unfinished);
|
|
360
382
|
const rows = await reader.all<KnownRow>(
|
|
361
383
|
// One reading of the clock, so a session found within the retention reports an age within it too.
|
|
362
384
|
`WITH clock AS (SELECT ${nowMs} AS now)
|
|
@@ -376,27 +398,29 @@ async function openKnownSessionStoreInCatalog({
|
|
|
376
398
|
},
|
|
377
399
|
async bind(intercomSessionId, returnAddress, retentionMs, claim, owner): Promise<KnownSessionBindResult> {
|
|
378
400
|
if (intercomSessionId.length === 0) return { status: "invalid", reason: "empty-session-id" };
|
|
379
|
-
return
|
|
380
|
-
|
|
381
|
-
|
|
401
|
+
return writing(
|
|
402
|
+
database.transaction((tx) => bindIn(tx, intercomSessionId, returnAddress, retentionMs, claim, owner), {
|
|
403
|
+
...RETRY_UNAPPLIED,
|
|
404
|
+
concurrency: { kind: "serial", domain: bindings },
|
|
405
|
+
}),
|
|
406
|
+
);
|
|
382
407
|
},
|
|
383
408
|
...(owned ? { owners } : {}),
|
|
384
409
|
async binding(intercomSessionId, retentionMs): Promise<KnownSessionBindingResult> {
|
|
385
410
|
if (intercomSessionId.length === 0) return { status: "invalid", reason: "empty-session-id" };
|
|
411
|
+
if (unfinished.size > 0) await Promise.all(unfinished);
|
|
386
412
|
const bound = await reader.get<BindingRow>(
|
|
387
|
-
`SELECT return_address FROM ${bindings} WHERE intercom_session_id = ? AND ${
|
|
413
|
+
`SELECT return_address FROM ${bindings} WHERE intercom_session_id = ? AND recorded_at >= ${now} - ?`,
|
|
388
414
|
intercomSessionId,
|
|
389
415
|
retentionMs,
|
|
390
416
|
);
|
|
391
417
|
return bound === undefined ? { status: "unbound" } : { status: "bound", returnAddress: bound.return_address };
|
|
392
418
|
},
|
|
393
419
|
async prune(olderThanMs): Promise<number> {
|
|
394
|
-
|
|
395
|
-
const {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
);
|
|
399
|
-
return changes;
|
|
420
|
+
// Oldest first, from each table's `_recorded` index, in batches.
|
|
421
|
+
const older = { where: `recorded_at < ${now} - ?`, params: [olderThanMs], orderBy: "recorded_at" };
|
|
422
|
+
await deleteInBatches(database, { table: bindings, key: "intercom_session_id", ...older });
|
|
423
|
+
return deleteInBatches(database, { table, key: "record_order", ...older });
|
|
400
424
|
},
|
|
401
425
|
async markLost(targetIdentities): Promise<void> {
|
|
402
426
|
if (targetIdentities.length === 0) return;
|
|
@@ -410,13 +434,13 @@ async function openKnownSessionStoreInCatalog({
|
|
|
410
434
|
);
|
|
411
435
|
}
|
|
412
436
|
},
|
|
413
|
-
{ concurrency: { kind: "serial", domain: table } },
|
|
437
|
+
{ ...RETRY_UNAPPLIED, concurrency: { kind: "serial", domain: table } },
|
|
414
438
|
);
|
|
415
439
|
},
|
|
416
440
|
async listLost(olderThanMs): Promise<KnownSessionState[]> {
|
|
417
441
|
const rows = await database.all<KnownRow>(
|
|
418
442
|
`SELECT ${columns} FROM ${table}
|
|
419
|
-
WHERE lost_at IS NOT NULL AND ${
|
|
443
|
+
WHERE lost_at IS NOT NULL AND lost_at <= ${now} - ?
|
|
420
444
|
ORDER BY record_order`,
|
|
421
445
|
olderThanMs,
|
|
422
446
|
);
|