@bastani/atomic 0.10.11-alpha.1 → 0.10.11-alpha.3
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 +155 -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 +9 -9
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +8 -8
- package/dist/_shared/mode-shared-2QJSCUM6.js +9 -9
- 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} +14 -2
- package/dist/_shared/{p1b-elig-ENCUPKKJ.js.map → p1b-elig-TVB5CBLL.js.map} +1 -1
- package/dist/_shared/runtime-O4KCSG4C.js +5 -5
- package/dist/_shared/{sdk-AVFII7NK.js → sdk-B5LEWGGI.js} +2633 -488
- package/dist/_shared/sdk-B5LEWGGI.js.map +1 -0
- package/dist/_shared/session-data-AHTU7IS6.js +3 -3
- package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
- package/dist/_shared/settings-startup-8-DNZ2RIHM.js +1 -1
- package/dist/_shared/{settings-startup-4QCVCI53.js → settings-startup-HXQLSUWM.js} +8 -2
- package/dist/_shared/settings-startup-HXQLSUWM.js.map +1 -0
- package/dist/_shared/{startup-0-0-57KF6LZH.js → startup-0-0-EZUKEP4Q.js} +436 -51
- package/dist/_shared/startup-0-0-EZUKEP4Q.js.map +1 -0
- package/dist/_shared/{startup-0-1-GIY75K46.js → startup-0-1-RTOHJFDJ.js} +240 -279
- package/dist/_shared/startup-0-1-RTOHJFDJ.js.map +1 -0
- package/dist/_shared/{startup-0-2-27OWFHV6.js → startup-0-2-5QHPCEON.js} +254 -46
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -0
- package/dist/_shared/{startup-0-3-T4DVFYWX.js → startup-0-3-4ZYBYQNM.js} +273 -14
- package/dist/_shared/startup-0-3-4ZYBYQNM.js.map +1 -0
- package/dist/_shared/startup-0-4-ZMJV547D.js +14 -9
- package/dist/_shared/startup-0-4-ZMJV547D.js.map +1 -1
- package/dist/_shared/startup-0-5-YDW47QX6.js +10 -10
- package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -1
- package/dist/_shared/startup-10-0-TDQNBDDL.js +9 -9
- package/dist/_shared/startup-12-0-55AAXBJZ.js +3 -3
- package/dist/_shared/startup-14-0-MLX36RBG.js +6 -7
- package/dist/_shared/startup-14-0-MLX36RBG.js.map +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +7 -7
- package/dist/_shared/startup-15-1-4S7FLMNG.js +22 -30
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +455 -102
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/{startup-8-1-X32CYSXB.js → startup-8-1-LZFXSD3Z.js} +162 -1184
- package/dist/_shared/startup-8-1-LZFXSD3Z.js.map +1 -0
- package/dist/_shared/storage-command-7MGXLJGZ.js +189 -36
- 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 +3 -3
- package/dist/builtin/intercom/CHANGELOG.md +34 -0
- package/dist/builtin/intercom/README.md +2 -2
- package/dist/builtin/intercom/broker/broker.bundle.mjs +1091 -344
- package/dist/builtin/intercom/broker/database-wake-up-bus.ts +243 -64
- package/dist/builtin/intercom/broker/multinode-router.ts +154 -22
- package/dist/builtin/intercom/broker/multinode-state-store.ts +30 -3
- package/dist/builtin/intercom/broker/open-broker-state.ts +14 -0
- package/dist/builtin/intercom/broker/sql-add-column.ts +29 -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 +208 -101
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +516 -102
- 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 +24 -7
- package/dist/builtin/intercom/broker/sql-retention.ts +141 -0
- package/dist/builtin/intercom/broker/sql-schema.ts +199 -27
- 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 +2 -3
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +6 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/index.bundle.mjs +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 +6 -6
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +4 -4
- package/dist/cli/blueprint-command.impl.js +3 -3
- package/dist/cli/blueprint-command.js +3 -3
- package/dist/cli/intercom-command.code.js +4 -4
- 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 +2 -2
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +2 -2
- package/dist/cli/startup-ui.impl.js +3 -3
- package/dist/cli/startup-ui.js +3 -3
- package/dist/cli/storage-command.impl.js +3 -3
- package/dist/cli/storage-command.js +3 -3
- package/dist/cli/storage-search-session.code.js +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 +20 -114
- 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 +2 -2
- package/dist/core/export-html/index.impl.js +3 -3
- package/dist/core/export-html/index.js +3 -3
- package/dist/core/export-html/json-spans.impl.js +3 -3
- package/dist/core/export-html/json-spans.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.code.js +1 -1
- package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.js +3 -3
- package/dist/core/export-html/tool-renderer.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/extensions/jiti-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-loader.js +3 -3
- package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-static-loader.js +3 -3
- package/dist/core/extensions/loader-host-modules.code.js +1 -1
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/extensions/loader-virtual-modules.js +1 -1
- package/dist/core/extensions/runner-context.js +3 -3
- 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 +8 -0
- 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 +4 -4
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +27 -15
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-list.impl.js +3 -3
- package/dist/core/session-manager-list.js +3 -3
- package/dist/core/session-manager.code.js +3 -3
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-open-markers.js +3 -0
- package/dist/core/session-open-markers.js.map +1 -0
- package/dist/core/session-storage.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/added-exports.js +3 -0
- package/dist/core/storage/added-exports.js.map +1 -1
- 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 +56 -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 +11 -0
- package/dist/core/storage/fenced-paths.js +11 -0
- 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 +4 -3
- 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 +81 -8
- package/dist/core/storage/migrations.js +386 -47
- 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 +36 -12
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.js +135 -3
- 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 +14 -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 +82 -5
- package/dist/core/storage/schema-catalog.js +244 -34
- 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 +9 -8
- package/dist/core/storage/session/branch-fork-source.code.js.map +1 -1
- package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
- package/dist/core/storage/session/branch-fork-source.js +3 -3
- package/dist/core/storage/session/card-view.impl.js +3 -3
- package/dist/core/storage/session/card-view.js +3 -3
- package/dist/core/storage/session/child-reader.code.js +4 -4
- package/dist/core/storage/session/child-reader.impl.js +3 -3
- package/dist/core/storage/session/child-reader.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.js +3 -3
- package/dist/core/storage/session/errors.js +1 -1
- package/dist/core/storage/session/expanded-child-details.code.js +3 -3
- package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
- package/dist/core/storage/session/expanded-child-details.js +3 -3
- package/dist/core/storage/session/fork-detach.d.ts +118 -0
- package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.js +3 -3
- package/dist/core/storage/session/fork-row-index.impl.js +3 -3
- package/dist/core/storage/session/fork-row-index.js +3 -3
- package/dist/core/storage/session/fork-schema.js +53 -0
- package/dist/core/storage/session/fork-schema.js.map +1 -0
- package/dist/core/storage/session/fork-segments.d.ts +58 -0
- package/dist/core/storage/session/fork-staging.code.js +5 -8
- 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 +61 -0
- package/dist/core/storage/session/fork-sweep.js.map +1 -0
- package/dist/core/storage/session/fork-window.code.js +4 -4
- package/dist/core/storage/session/fork-window.impl.js +3 -3
- package/dist/core/storage/session/fork-window.js +3 -3
- package/dist/core/storage/session/history-pages.impl.js +3 -3
- package/dist/core/storage/session/history-pages.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.d.ts +42 -2
- 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 +4 -4
- package/dist/core/storage/session/released-history-files.impl.js +3 -3
- package/dist/core/storage/session/released-history-files.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.code.js +1 -1
- package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.js +3 -3
- package/dist/core/storage/session/session-resume.impl.js +3 -3
- package/dist/core/storage/session/session-resume.js +3 -3
- package/dist/core/storage/session/session-search-index.d.ts +43 -4
- package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
- package/dist/core/storage/session/snapshot-cut.js +3 -3
- package/dist/core/storage/session/snapshot-history.code.js +4 -4
- package/dist/core/storage/session/snapshot-history.impl.js +3 -3
- package/dist/core/storage/session/snapshot-history.js +3 -3
- package/dist/core/storage/session/sql-session-store.code.js +1 -1
- package/dist/core/storage/session/sql-session-store.d.ts +394 -20
- package/dist/core/storage/session/sql-session-store.impl.js +4 -4
- package/dist/core/storage/session/sql-session-store.js +4 -4
- package/dist/core/storage/session/tree-outline.impl.js +3 -3
- package/dist/core/storage/session/tree-outline.js +3 -3
- package/dist/core/storage/session/tree-presentation.impl.js +3 -3
- package/dist/core/storage/session/tree-presentation.js +3 -3
- package/dist/core/storage/session/types.d.ts +22 -0
- package/dist/core/storage/sqlite-facade.d.ts +23 -2
- package/dist/core/storage/sqlite-facade.js +34 -0
- package/dist/core/storage/sqlite-facade.js.map +1 -1
- 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 +4 -4
- package/dist/core/tasks/task-file-history.impl.js +3 -3
- package/dist/core/tasks/task-file-history.js +3 -3
- package/dist/core/tasks/task-reference-archive.code.js +5 -5
- 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-session.d.ts +2 -0
- 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 +71 -3
- package/dist/core/worktree-snapshot/blob-store.js +575 -67
- package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
- package/dist/core/worktree-snapshot/errors.code.js +3 -3
- package/dist/core/worktree-snapshot/errors.impl.js +3 -3
- package/dist/core/worktree-snapshot/errors.js +3 -3
- package/dist/core/worktree-snapshot/fork-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 +162 -0
- package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -0
- 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 +2 -2
- package/dist/extensions/codemode/execute.impl.js +3 -3
- package/dist/extensions/codemode/execute.js +3 -3
- package/dist/extensions/codemode/renderer.code.js +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 +8 -8
- package/dist/main-first-time-setup.code.js +2 -2
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/main.js +1 -1
- package/dist/modes/interactive/components/stored-tree-view.code.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
- package/dist/modes/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 +7 -7
- 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 -3
- 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 -6
- 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 +3 -3
- package/dist/utils/startup-database-spare.impl.js +3 -3
- package/dist/utils/startup-database-spare.js +3 -3
- package/dist/utils/tools-manager.code.js +1 -1
- package/dist/utils/tools-manager.impl.js +3 -3
- package/dist/utils/tools-manager.js +3 -3
- package/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 +1421 -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 +31 -42
- 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} +73 -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 +333 -956
- 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/sdk-AVFII7NK.js.map +0 -1
- package/dist/_shared/settings-startup-4QCVCI53.js.map +0 -1
- package/dist/_shared/startup-0-0-57KF6LZH.js.map +0 -1
- package/dist/_shared/startup-0-1-GIY75K46.js.map +0 -1
- package/dist/_shared/startup-0-2-27OWFHV6.js.map +0 -1
- package/dist/_shared/startup-0-3-T4DVFYWX.js.map +0 -1
- 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
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import * as storage from "@bastani/atomic/storage";
|
|
1
3
|
import {
|
|
2
4
|
dialectOf,
|
|
5
|
+
ensureStorageSchema,
|
|
3
6
|
fencedPath,
|
|
4
7
|
type SqliteDatabase,
|
|
5
8
|
type SqliteExecutor,
|
|
6
9
|
type SqliteRow,
|
|
10
|
+
type SqliteStatement,
|
|
11
|
+
type StorageNotificationEvent,
|
|
12
|
+
type StorageNotifications,
|
|
7
13
|
type StorageNotificationSubscription,
|
|
14
|
+
storageMigrationTable,
|
|
8
15
|
validateStoragePrefix,
|
|
9
16
|
} from "@bastani/atomic/storage";
|
|
10
17
|
import { OUTBOX_BACKUP_POLL_INTERVAL_MS } from "./multinode-state-store.js";
|
|
@@ -17,7 +24,8 @@ import type {
|
|
|
17
24
|
WakeUpSubscribeResult,
|
|
18
25
|
WakeUpSubscription,
|
|
19
26
|
} from "./wake-up-bus.js";
|
|
20
|
-
import {
|
|
27
|
+
import { addMissingColumns } from "./sql-add-column.js";
|
|
28
|
+
import { ensureBrokerSchema, openCatalogOf, RETRY_UNAPPLIED, withBrokerSchemaCatalog } from "./sql-schema.js";
|
|
21
29
|
|
|
22
30
|
/**
|
|
23
31
|
* S4 wake-up bus (specs/2026-10-19-intercom-multi-node.md §5.6): a hint log in the shared storage database. Each
|
|
@@ -26,12 +34,15 @@ import { ensureBrokerSchema, withBrokerSchemaCatalog } from "./sql-schema.js";
|
|
|
26
34
|
* hints written meanwhile may have been pruned or missed. While the database stays unavailable, reopening backs off
|
|
27
35
|
* exponentially from the poll interval up to `WAKE_UP_RECONNECT_MAX_DELAY_MS`.
|
|
28
36
|
*
|
|
29
|
-
* On a database that delivers notifications (Postgres), a publish also notifies the
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
37
|
+
* On a database that delivers notifications (Postgres), a publish also notifies the hint's broker once the hint
|
|
38
|
+
* commits, and a subscribed connection polls as soon as a notification for one of its brokers arrives (#5103). Each
|
|
39
|
+
* broker has a channel of its own (`brokerWakeUpChannel`), so a notification reaches only the connection that hosts it;
|
|
40
|
+
* brokers of earlier releases listen on the channel named like the table instead, which is notified too while the
|
|
41
|
+
* broker's membership does not say it listens on its own (`wakeUpNotices`). A connection listens on both. The interval
|
|
42
|
+
* poll stays: notifications are lost while the listening connection is down, and none arrive through a transaction
|
|
43
|
+
* pooler. While the database reports its listening connection live, the poll only backs the notifications up and runs
|
|
44
|
+
* at `WAKE_UP_LISTENING_POLL_INTERVAL_MS`; the listener's `listening` event, sent when it listens again after an
|
|
45
|
+
* outage, polls at once (#6560).
|
|
35
46
|
*/
|
|
36
47
|
|
|
37
48
|
/** How often a connection with subscriptions reads its hints when no notification would announce them. */
|
|
@@ -41,21 +52,62 @@ export const WAKE_UP_POLL_INTERVAL_MS = 500;
|
|
|
41
52
|
* in an outage the listener has not noticed yet waits for this poll.
|
|
42
53
|
*/
|
|
43
54
|
export const WAKE_UP_LISTENING_POLL_INTERVAL_MS = 5_000;
|
|
44
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* The longest a hint nobody consumed (its broker exited) stays in the table, while brokers publish: by then the backup
|
|
57
|
+
* poll has covered it. The prune runs at most every {@link WAKE_UP_PRUNE_INTERVAL_MS}, so it deletes the hints older
|
|
58
|
+
* than the retention less that interval: one that just missed a prune is gone by the next, at most the retention old.
|
|
59
|
+
*/
|
|
45
60
|
export const WAKE_UP_HINT_RETENTION_MS = OUTBOX_BACKUP_POLL_INTERVAL_MS;
|
|
46
61
|
/**
|
|
47
|
-
* How often at most one connection deletes
|
|
48
|
-
*
|
|
62
|
+
* How often at most one connection deletes old hints, at a publish (#6560): each prune is a write every broker would
|
|
63
|
+
* otherwise send at every publish.
|
|
49
64
|
*/
|
|
50
65
|
export const WAKE_UP_PRUNE_INTERVAL_MS = 10_000;
|
|
66
|
+
/** The age past which a prune deletes a hint, so that no hint outlives {@link WAKE_UP_HINT_RETENTION_MS}. */
|
|
67
|
+
const WAKE_UP_PRUNE_AGE_MS = WAKE_UP_HINT_RETENTION_MS - WAKE_UP_PRUNE_INTERVAL_MS;
|
|
51
68
|
/**
|
|
52
|
-
* Hints read and deleted per statement; a poll repeats until a batch comes back short
|
|
53
|
-
*
|
|
69
|
+
* Hints read and deleted per statement; a poll repeats until a batch comes back short, so a backlog is taken in
|
|
70
|
+
* statements of bounded size.
|
|
54
71
|
*/
|
|
55
72
|
export const WAKE_UP_POLL_BATCH_SIZE = 500;
|
|
56
73
|
/** Longest wait between attempts to reopen an unavailable database; the backup poll covers the gap. */
|
|
57
74
|
export const WAKE_UP_RECONNECT_MAX_DELAY_MS = OUTBOX_BACKUP_POLL_INTERVAL_MS;
|
|
58
75
|
|
|
76
|
+
/**
|
|
77
|
+
* What a broker's membership subject holds, as the lease table stores it, when the broker listens on its own wake-up
|
|
78
|
+
* channel (`BrokerMembershipSubject.ownWakeUpChannel`). A JSON string escapes its quotes, so only that field matches.
|
|
79
|
+
*/
|
|
80
|
+
export const OWN_WAKE_UP_CHANNEL_MARK = '"ownWakeUpChannel":true';
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The channel only `brokerId`'s connections listen on: the hint table's name and 64 bits of a hash of the broker id, so
|
|
84
|
+
* it stays a short identifier whatever the id, as Que's `que_listener_<pid>`. A notification on it reaches that broker's
|
|
85
|
+
* connection alone, where one on the table's channel reaches every broker's.
|
|
86
|
+
*/
|
|
87
|
+
export function brokerWakeUpChannel(table: string, brokerId: string): string {
|
|
88
|
+
return `${table}_${createHash("sha256").update(brokerId).digest("hex").slice(0, 16)}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The notifications that wake `brokerId` once the transaction that runs them commits: one on its own channel, and one on
|
|
93
|
+
* the table's channel, where brokers of earlier releases listen, unless `brokerId`'s membership lease, in `leases`, says
|
|
94
|
+
* it listens on its own. Both carry the broker id, which a listener checks.
|
|
95
|
+
*/
|
|
96
|
+
export function wakeUpNotices(
|
|
97
|
+
notifications: StorageNotifications,
|
|
98
|
+
table: string,
|
|
99
|
+
leases: string,
|
|
100
|
+
brokerId: string,
|
|
101
|
+
): SqliteStatement[] {
|
|
102
|
+
return [
|
|
103
|
+
notifications.notify(brokerWakeUpChannel(table, brokerId), brokerId),
|
|
104
|
+
notifications.notify(table, brokerId, {
|
|
105
|
+
sql: `SELECT 1 FROM ${leases} WHERE kind = 'broker' AND key = ? AND strpos(subject_json, ?) > 0`,
|
|
106
|
+
params: [brokerId, OWN_WAKE_UP_CHANNEL_MARK],
|
|
107
|
+
}),
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
|
|
59
111
|
/** Runs `callback` once after `delayMs` and returns a function that cancels it. */
|
|
60
112
|
export type WakeUpPollScheduler = (callback: () => void, delayMs: number) => () => void;
|
|
61
113
|
|
|
@@ -69,9 +121,9 @@ export interface DatabaseWakeUpBusOptions {
|
|
|
69
121
|
readonly schedule?: WakeUpPollScheduler;
|
|
70
122
|
/**
|
|
71
123
|
* A separate handle on the same database that the poll reads its hints through, so a poll never queues behind the
|
|
72
|
-
* database's writes (#6560); the bus does not close it. On PostgreSQL the poll
|
|
73
|
-
* it in one statement (`DELETE … RETURNING`)
|
|
74
|
-
* opened.
|
|
124
|
+
* database's writes (#6560); the bus does not close it, and writes nothing through it. On PostgreSQL the poll reads
|
|
125
|
+
* nothing through it: it takes and deletes its hints in one statement (`DELETE … RETURNING`) on the database it
|
|
126
|
+
* opened. Absent: the poll runs on the database it opened.
|
|
75
127
|
*/
|
|
76
128
|
readonly reader?: SqliteExecutor;
|
|
77
129
|
}
|
|
@@ -81,6 +133,15 @@ interface HintRow extends SqliteRow {
|
|
|
81
133
|
readonly broker_id: string;
|
|
82
134
|
readonly reason: string;
|
|
83
135
|
readonly version: number;
|
|
136
|
+
readonly target_identity: string | null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The channels a connection listens on, each with its subscription, and the database it listens through. */
|
|
140
|
+
interface Listening {
|
|
141
|
+
readonly database: SqliteDatabase;
|
|
142
|
+
readonly channels: Map<string, StorageNotificationSubscription>;
|
|
143
|
+
/** The database reported its listening connection live, as of the latest check. */
|
|
144
|
+
live: boolean;
|
|
84
145
|
}
|
|
85
146
|
|
|
86
147
|
interface DatabaseSubscription {
|
|
@@ -95,19 +156,94 @@ const scheduleTimeout: WakeUpPollScheduler = (callback, delayMs) => {
|
|
|
95
156
|
return () => clearTimeout(timer);
|
|
96
157
|
};
|
|
97
158
|
|
|
159
|
+
/**
|
|
160
|
+
* `storageSchemaCurrent` of the storage API, which an Atomic installation older than #6560 lacks: a named import would
|
|
161
|
+
* fail to link there, so it is taken from the module namespace, and without it the hint log's persistence is read from
|
|
162
|
+
* the catalog at every open.
|
|
163
|
+
*/
|
|
164
|
+
const schemaApi: Partial<Pick<typeof storage, "storageSchemaCurrent" | "ensureStorageSchemaOnce">> = storage;
|
|
165
|
+
|
|
166
|
+
/** The ledger step, `schema:intercom-wakeups-unlogged`, that makes a hint log created as a logged table unlogged. */
|
|
167
|
+
const UNLOGGED_HINTS_DOMAIN = "intercom-wakeups-unlogged";
|
|
168
|
+
|
|
98
169
|
async function createSchema(database: SqliteDatabase, table: string, prefix: string | undefined): Promise<void> {
|
|
99
|
-
const { types } = dialectOf(database);
|
|
100
|
-
//
|
|
101
|
-
|
|
170
|
+
const { types, name } = dialectOf(database);
|
|
171
|
+
// On PostgreSQL the hint log is unlogged: its rows skip the write-ahead log, so a hint costs no log write and its
|
|
172
|
+
// commit no flush to disk. A crash of the server empties it, which loses only hints, and the backup poll finds
|
|
173
|
+
// every message they announced. In a serial transaction, so brokers opening a new bus at once take turns creating
|
|
174
|
+
// it (#5054).
|
|
175
|
+
const schema = `CREATE ${name === "postgres" ? "UNLOGGED " : ""}TABLE IF NOT EXISTS ${table} (
|
|
102
176
|
id ${types.serialKey},
|
|
103
177
|
broker_id TEXT NOT NULL,
|
|
104
178
|
reason TEXT NOT NULL CHECK (reason IN ('outbox', 'outcome')),
|
|
105
179
|
version ${types.int} NOT NULL,
|
|
106
|
-
created_at ${types.int} NOT NULL
|
|
180
|
+
created_at ${types.int} NOT NULL,
|
|
181
|
+
target_identity TEXT
|
|
107
182
|
);
|
|
108
183
|
CREATE INDEX IF NOT EXISTS ${table}_broker ON ${table} (broker_id, id);
|
|
109
184
|
CREATE INDEX IF NOT EXISTS ${table}_created ON ${table} (created_at);`;
|
|
185
|
+
// `target_identity`, the recipient a hint is about (`WakeUpHint.targetIdentity`), came later: a table an earlier
|
|
186
|
+
// release created gets it here, and an earlier broker's hints leave it null. A table this open creates has it, so a
|
|
187
|
+
// new database's first open spends nothing on it.
|
|
188
|
+
const catalog = await openCatalogOf(database);
|
|
189
|
+
const existed = catalog === undefined || catalog.hasTable(table);
|
|
110
190
|
await ensureBrokerSchema(database, prefix, "wakeups", (tx) => tx.exec(schema));
|
|
191
|
+
if (existed) await addMissingColumns(database, table, { target_identity: "TEXT" });
|
|
192
|
+
await ensureUnloggedHints(database, table, prefix);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Makes a hint log that an earlier Atomic created as a logged table unlogged on PostgreSQL, once per database, recorded
|
|
197
|
+
* in the ledger as `schema:intercom-wakeups-unlogged`. `ALTER TABLE … SET UNLOGGED` needs the table's owner, so a
|
|
198
|
+
* runtime role without DDL leaves it logged, as before, until `atomic storage migrate` runs as the owner. Earlier
|
|
199
|
+
* Atomic releases use the unlogged table unchanged. The rewrite locks the table, which holds only hints younger than
|
|
200
|
+
* the retention: when another broker holds it longer than the schema lock wait, the next open tries again. A table
|
|
201
|
+
* that is unlogged already, as every table this build creates, needs only the step recorded: the statement that reads
|
|
202
|
+
* the table's persistence records it too, so a new database's open pays one round trip for it and no transaction
|
|
203
|
+
* (#6560).
|
|
204
|
+
*/
|
|
205
|
+
async function ensureUnloggedHints(database: SqliteDatabase, table: string, prefix: string | undefined): Promise<void> {
|
|
206
|
+
const dialect = dialectOf(database);
|
|
207
|
+
if (dialect.name !== "postgres" || database.readOnly === true) return;
|
|
208
|
+
const schema = { ledger: storageMigrationTable(prefix), domain: UNLOGGED_HINTS_DOMAIN, revision: 1 };
|
|
209
|
+
if (await schemaApi.storageSchemaCurrent?.(database, schema)) return;
|
|
210
|
+
const yes = (value: boolean | number | undefined) => value === true || Number(value) === 1;
|
|
211
|
+
let found: (SqliteRow & { owned: boolean | number; unlogged: boolean | number }) | undefined;
|
|
212
|
+
try {
|
|
213
|
+
// The ledger exists: the hint log's own setup recorded itself there. Recording a step that holds, whoever else
|
|
214
|
+
// records it at once, needs no lock.
|
|
215
|
+
found = await database.get(
|
|
216
|
+
`WITH found AS (
|
|
217
|
+
SELECT pg_catalog.pg_has_role(current_user, c.relowner, 'USAGE') AS owned, c.relpersistence = 'u' AS unlogged
|
|
218
|
+
FROM pg_catalog.pg_class c WHERE c.relnamespace = current_schema()::regnamespace AND c.relname = ?
|
|
219
|
+
), recorded AS (
|
|
220
|
+
INSERT INTO ${schema.ledger} (domain, version, applied_at)
|
|
221
|
+
SELECT ?, ?, ${dialect.nowMs} FROM found WHERE found.unlogged ON CONFLICT DO NOTHING RETURNING 1
|
|
222
|
+
)
|
|
223
|
+
SELECT owned, unlogged FROM found`,
|
|
224
|
+
dialect.identifier(table),
|
|
225
|
+
`schema:${schema.domain}`,
|
|
226
|
+
schema.revision,
|
|
227
|
+
);
|
|
228
|
+
} catch {
|
|
229
|
+
// A role that may not write the ledger leaves the step to `atomic storage migrate`.
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (found === undefined || yes(found.unlogged) || !yes(found.owned)) return;
|
|
233
|
+
const setup = async (tx: SqliteExecutor) => {
|
|
234
|
+
await tx.exec(`ALTER TABLE ${table} SET UNLOGGED`);
|
|
235
|
+
};
|
|
236
|
+
try {
|
|
237
|
+
// Brokers that open the database at once make it unlogged once: the others wait for it without its lock (#6560).
|
|
238
|
+
const ensureOnce = schemaApi.ensureStorageSchemaOnce;
|
|
239
|
+
if (ensureOnce !== undefined) await ensureOnce(database, schema, setup);
|
|
240
|
+
else
|
|
241
|
+
await database.transaction((tx) => ensureStorageSchema(tx, dialect, schema, () => setup(tx)), {
|
|
242
|
+
concurrency: { kind: "serial", domain: schema.ledger },
|
|
243
|
+
});
|
|
244
|
+
} catch {
|
|
245
|
+
// The table stays as it was: hints work the same in a logged table.
|
|
246
|
+
}
|
|
111
247
|
}
|
|
112
248
|
|
|
113
249
|
/**
|
|
@@ -137,6 +273,8 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
137
273
|
private readonly subscriptions = new Set<DatabaseSubscription>();
|
|
138
274
|
private readonly options: DatabaseWakeUpBusOptions;
|
|
139
275
|
private readonly table: string;
|
|
276
|
+
/** The lease table, whose membership leases say which brokers listen on their own channels. */
|
|
277
|
+
private readonly leases: string;
|
|
140
278
|
private readonly pollIntervalMs: number;
|
|
141
279
|
private readonly listeningPollIntervalMs: number;
|
|
142
280
|
private readonly schedule: WakeUpPollScheduler;
|
|
@@ -149,15 +287,11 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
149
287
|
/** Consecutive failed attempts to reopen the database; each doubles the wait before the next. */
|
|
150
288
|
private reconnectFailures = 0;
|
|
151
289
|
private reconnectNotBefore = 0;
|
|
152
|
-
/**
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
/** The database reported its listening connection live, as of the latest check. */
|
|
158
|
-
live: boolean;
|
|
159
|
-
}
|
|
160
|
-
| undefined;
|
|
290
|
+
/**
|
|
291
|
+
* The notification channels this connection listens on, each with its subscription: the table's and each subscribed
|
|
292
|
+
* broker's own (`brokerWakeUpChannel`). And the database it listens through.
|
|
293
|
+
*/
|
|
294
|
+
private listening: Listening | undefined;
|
|
161
295
|
/** A notification arrived during a poll: the next poll runs as soon as that one ends. */
|
|
162
296
|
private pollAgain = false;
|
|
163
297
|
/** When a publish last deleted the hints past the retention, by this process's clock. */
|
|
@@ -166,6 +300,7 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
166
300
|
constructor(options: DatabaseWakeUpBusOptions, table: string, database: SqliteDatabase) {
|
|
167
301
|
this.options = options;
|
|
168
302
|
this.table = table;
|
|
303
|
+
this.leases = `${validateStoragePrefix(options.prefix)}intercom_leases`;
|
|
169
304
|
this.database = database;
|
|
170
305
|
this.pollIntervalMs = options.pollIntervalMs ?? WAKE_UP_POLL_INTERVAL_MS;
|
|
171
306
|
this.listeningPollIntervalMs = options.listeningPollIntervalMs ?? WAKE_UP_LISTENING_POLL_INTERVAL_MS;
|
|
@@ -177,29 +312,37 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
177
312
|
const database = await this.connection(false);
|
|
178
313
|
if (database === undefined) return { status: "unavailable" };
|
|
179
314
|
const { nowMs } = dialectOf(database);
|
|
180
|
-
const insert =
|
|
315
|
+
const insert: SqliteStatement = {
|
|
316
|
+
sql: `INSERT INTO ${this.table} (broker_id, reason, version, created_at, target_identity) VALUES (?, ?, ?, ${nowMs}, ?)`,
|
|
317
|
+
params: [hint.brokerId, hint.reason, hint.version, hint.targetIdentity ?? null],
|
|
318
|
+
};
|
|
181
319
|
const notifications = database.notifications;
|
|
182
320
|
try {
|
|
183
|
-
if (notifications === undefined) await database.run(insert
|
|
321
|
+
if (notifications === undefined) await database.run(insert.sql, ...insert.params);
|
|
184
322
|
else {
|
|
185
|
-
// The
|
|
186
|
-
//
|
|
323
|
+
// The notifications go out once the hint commits, so the poll they start finds the hint: on Postgres right
|
|
324
|
+
// behind its commit, in the same round trip, and the insert goes with the transaction's start (#6560). A hint
|
|
325
|
+
// is a new row that no write checks first, so its writers take no lock domain: see
|
|
187
326
|
// `fencedPath("intercom-wakeup-hint")`.
|
|
188
|
-
const
|
|
327
|
+
const notices = wakeUpNotices(notifications, this.table, this.leases, hint.brokerId);
|
|
189
328
|
await database.transaction(
|
|
190
329
|
async (tx) => {
|
|
191
|
-
await
|
|
192
|
-
|
|
330
|
+
await Promise.all([insert, ...notices].map(({ sql, params }) => tx.run(sql, ...params)));
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
...RETRY_UNAPPLIED,
|
|
334
|
+
concurrency: { kind: "fenced", audit: fencedPath("intercom-wakeup-hint") },
|
|
335
|
+
leading: [insert],
|
|
193
336
|
},
|
|
194
|
-
{ concurrency: { kind: "fenced", audit: fencedPath("intercom-wakeup-hint") } },
|
|
195
337
|
);
|
|
196
338
|
}
|
|
197
339
|
// #6560: at most once per interval, not at every publish: each prune is a write every broker would send.
|
|
198
340
|
if (this.prunedAt === undefined || Date.now() - this.prunedAt >= WAKE_UP_PRUNE_INTERVAL_MS) {
|
|
199
341
|
this.prunedAt = Date.now();
|
|
342
|
+
// The clock is read once, in a subquery: PostgreSQL's is volatile, and a volatile bound uses no index.
|
|
200
343
|
await database.run(
|
|
201
|
-
`DELETE FROM ${this.table} WHERE created_at < ${nowMs} - ?`,
|
|
202
|
-
|
|
344
|
+
`DELETE FROM ${this.table} WHERE created_at < (SELECT ${nowMs}) - ?`,
|
|
345
|
+
WAKE_UP_PRUNE_AGE_MS,
|
|
203
346
|
);
|
|
204
347
|
}
|
|
205
348
|
} catch {
|
|
@@ -222,6 +365,7 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
222
365
|
close: async () => {
|
|
223
366
|
subscription.open = false;
|
|
224
367
|
this.subscriptions.delete(subscription);
|
|
368
|
+
this.listen();
|
|
225
369
|
},
|
|
226
370
|
};
|
|
227
371
|
return { status: "subscribed", subscription: handle };
|
|
@@ -236,8 +380,7 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
236
380
|
this.closed = true;
|
|
237
381
|
this.cancelPoll?.();
|
|
238
382
|
this.cancelPoll = undefined;
|
|
239
|
-
this.
|
|
240
|
-
this.listening = undefined;
|
|
383
|
+
this.stopListening();
|
|
241
384
|
for (const subscription of this.subscriptions) subscription.open = false;
|
|
242
385
|
this.subscriptions.clear();
|
|
243
386
|
await this.polling;
|
|
@@ -253,22 +396,45 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
253
396
|
});
|
|
254
397
|
}
|
|
255
398
|
|
|
256
|
-
/**
|
|
399
|
+
/**
|
|
400
|
+
* Listens for notifications through the current database, when it delivers them: on each subscribed broker's own
|
|
401
|
+
* channel, and on the table's, where brokers of earlier releases send them. A channel no subscription needs any more
|
|
402
|
+
* is left.
|
|
403
|
+
*/
|
|
257
404
|
private listen(): void {
|
|
258
405
|
const database = this.database;
|
|
259
|
-
if (this.closed || database === undefined
|
|
260
|
-
this.listening
|
|
261
|
-
this.listening = undefined;
|
|
406
|
+
if (this.closed || database === undefined) return;
|
|
407
|
+
if (this.listening !== undefined && this.listening.database !== database) this.stopListening();
|
|
262
408
|
const notifications = database.notifications;
|
|
263
409
|
if (notifications === undefined) return;
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
410
|
+
const fresh = this.listening === undefined;
|
|
411
|
+
const listening = (this.listening ??= { database, channels: new Map(), live: false });
|
|
412
|
+
const wanted = new Set([
|
|
413
|
+
this.table,
|
|
414
|
+
...[...this.subscriptions].map((subscription) => brokerWakeUpChannel(this.table, subscription.brokerId)),
|
|
415
|
+
]);
|
|
416
|
+
for (const [channel, subscription] of listening.channels) {
|
|
417
|
+
if (wanted.has(channel)) continue;
|
|
418
|
+
subscription.close();
|
|
419
|
+
listening.channels.delete(channel);
|
|
420
|
+
}
|
|
421
|
+
for (const channel of wanted) {
|
|
422
|
+
if (!listening.channels.has(channel))
|
|
423
|
+
listening.channels.set(channel, notifications.listen(channel, (event) => this.notified(listening, event)));
|
|
424
|
+
}
|
|
425
|
+
if (fresh) void this.checkListening();
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
private notified(listening: Listening, event: StorageNotificationEvent): void {
|
|
429
|
+
if (event.kind === "listening") {
|
|
430
|
+
if (this.listening === listening) listening.live = true;
|
|
431
|
+
this.pollNow();
|
|
432
|
+
} else if ([...this.subscriptions].some((open) => open.brokerId === event.payload)) this.pollNow();
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
private stopListening(): void {
|
|
436
|
+
for (const subscription of this.listening?.channels.values() ?? []) subscription.close();
|
|
437
|
+
this.listening = undefined;
|
|
272
438
|
}
|
|
273
439
|
|
|
274
440
|
/** Asks the database whether its listening connection is live, for the interval of the next poll. */
|
|
@@ -321,26 +487,38 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
321
487
|
const database = await this.connection(true);
|
|
322
488
|
const brokerIds = [...new Set([...this.subscriptions].map((subscription) => subscription.brokerId))];
|
|
323
489
|
if (database === undefined || brokerIds.length === 0) return;
|
|
324
|
-
const
|
|
325
|
-
|
|
490
|
+
const dialect = dialectOf(database);
|
|
491
|
+
// One statement text whatever the number of brokers, so the server plans it once: their ids go as one JSON array.
|
|
492
|
+
const batch = `FROM ${this.table} WHERE broker_id IN (SELECT value FROM ${dialect.jsonValues("?")}) ORDER BY id LIMIT ${WAKE_UP_POLL_BATCH_SIZE}`;
|
|
493
|
+
const ids = JSON.stringify(brokerIds);
|
|
326
494
|
const reader = this.options.reader ?? database;
|
|
327
495
|
for (;;) {
|
|
328
496
|
let rows: HintRow[];
|
|
329
497
|
try {
|
|
330
|
-
if (
|
|
331
|
-
// #6560: one statement takes the batch and deletes it
|
|
332
|
-
//
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
498
|
+
if (dialect.name === "postgres") {
|
|
499
|
+
// #6560: one statement takes the batch and deletes it. It is a write, so it goes through the database,
|
|
500
|
+
// never the reader, as a statement of its own in the wake-up table's domain: one round trip, queued
|
|
501
|
+
// behind neither other domains' writes nor read-only transactions. It returns the hints in no
|
|
502
|
+
// particular order.
|
|
503
|
+
const take = {
|
|
504
|
+
sql: `DELETE FROM ${this.table} WHERE id IN (SELECT id ${batch}) RETURNING id, broker_id, reason, version, target_identity`,
|
|
505
|
+
params: [ids],
|
|
506
|
+
};
|
|
507
|
+
rows = (
|
|
508
|
+
database.autocommit === undefined
|
|
509
|
+
? await database.all(take.sql, ...take.params)
|
|
510
|
+
: await database.autocommit(take, { kind: "serial", domain: this.table })
|
|
511
|
+
) as HintRow[];
|
|
337
512
|
rows.sort((left, right) => Number(left.id) - Number(right.id));
|
|
338
513
|
} else {
|
|
339
|
-
rows = await reader.all<HintRow>(
|
|
514
|
+
rows = await reader.all<HintRow>(
|
|
515
|
+
`SELECT id, broker_id, reason, version, target_identity ${batch}`,
|
|
516
|
+
ids,
|
|
517
|
+
);
|
|
340
518
|
if (rows.length > 0) {
|
|
341
519
|
await database.run(
|
|
342
|
-
`DELETE FROM ${this.table} WHERE id IN (${
|
|
343
|
-
|
|
520
|
+
`DELETE FROM ${this.table} WHERE id IN (SELECT value FROM ${dialect.jsonValues("?")})`,
|
|
521
|
+
JSON.stringify(rows.map((row) => Number(row.id))),
|
|
344
522
|
);
|
|
345
523
|
}
|
|
346
524
|
}
|
|
@@ -353,6 +531,7 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
353
531
|
brokerId: row.broker_id,
|
|
354
532
|
reason: row.reason === "outcome" ? "outcome" : "outbox",
|
|
355
533
|
version: row.version,
|
|
534
|
+
...(row.target_identity === null ? {} : { targetIdentity: row.target_identity }),
|
|
356
535
|
};
|
|
357
536
|
for (const subscription of this.subscriptions) {
|
|
358
537
|
if (subscription.brokerId === hint.brokerId) this.deliver(subscription, { kind: "hint", hint });
|