@bastani/atomic 0.10.10-alpha.2 → 0.10.11-alpha.1
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 +142 -0
- package/README.md +1 -1
- 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 +8 -10
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +6 -6
- package/dist/_shared/mode-shared-2QJSCUM6.js +52 -15
- package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -1
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
- package/dist/_shared/runtime-O4KCSG4C.js +3 -3
- package/dist/_shared/{sdk-RRLVN7ER.js → sdk-AVFII7NK.js} +757 -233
- package/dist/_shared/sdk-AVFII7NK.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/{startup-0-0-4VG2G44V.js → startup-0-0-57KF6LZH.js} +94 -42
- package/dist/_shared/startup-0-0-57KF6LZH.js.map +1 -0
- package/dist/_shared/{startup-0-1-XTIL65D4.js → startup-0-1-GIY75K46.js} +75 -13
- package/dist/_shared/startup-0-1-GIY75K46.js.map +1 -0
- package/dist/_shared/startup-0-2-27OWFHV6.js +72 -7
- package/dist/_shared/startup-0-2-27OWFHV6.js.map +1 -1
- package/dist/_shared/startup-0-3-T4DVFYWX.js +4 -4
- package/dist/_shared/startup-0-4-ZMJV547D.js +4 -4
- package/dist/_shared/{startup-0-5-FD2P735I.js → startup-0-5-YDW47QX6.js} +27 -69
- package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -0
- package/dist/_shared/startup-10-0-TDQNBDDL.js +6 -6
- package/dist/_shared/startup-12-0-55AAXBJZ.js +3 -3
- package/dist/_shared/startup-14-0-MLX36RBG.js +4 -4
- package/dist/_shared/startup-15-0-YUKGAC63.js +31 -7
- package/dist/_shared/startup-15-0-YUKGAC63.js.map +1 -1
- package/dist/_shared/startup-15-1-4S7FLMNG.js +7 -6
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +4 -4
- package/dist/_shared/{startup-8-1-4KANEHRA.js → startup-8-1-X32CYSXB.js} +1219 -714
- package/dist/_shared/startup-8-1-X32CYSXB.js.map +1 -0
- package/dist/_shared/storage-command-7MGXLJGZ.js +14 -8
- package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
- package/dist/_shared/task-reference-stream-JWMUZSJX.js +1 -1
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +24 -0
- package/dist/builtin/intercom/broker/broker.bundle.mjs +993 -362
- package/dist/builtin/intercom/broker/database-wake-up-bus.ts +103 -24
- package/dist/builtin/intercom/broker/multinode-router.ts +42 -21
- package/dist/builtin/intercom/broker/multinode-state-store.ts +22 -1
- package/dist/builtin/intercom/broker/open-broker-state.ts +82 -31
- package/dist/builtin/intercom/broker/paths.ts +8 -4
- package/dist/builtin/intercom/broker/released-asker-remote-replies.ts +18 -6
- package/dist/builtin/intercom/broker/sql-add-column.ts +4 -1
- package/dist/builtin/intercom/broker/sql-ended-child-queue-store.ts +65 -44
- package/dist/builtin/intercom/broker/sql-held-send-store.ts +11 -3
- package/dist/builtin/intercom/broker/sql-known-session-store.ts +24 -12
- package/dist/builtin/intercom/broker/sql-lease-store.ts +375 -65
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +270 -101
- package/dist/builtin/intercom/broker/sql-pending-ask-store.ts +20 -9
- package/dist/builtin/intercom/broker/sql-released-ask-store.ts +14 -6
- package/dist/builtin/intercom/broker/sql-restoring-reservation-store.ts +27 -11
- package/dist/builtin/intercom/broker/sql-schema.ts +139 -1
- package/dist/builtin/intercom/broker/sql-sent-message-authority.ts +97 -34
- package/dist/builtin/intercom/index.bundle.mjs +11 -8
- 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/SKILL.md +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +62 -23
- package/dist/builtin/web-access/CHANGELOG.md +9 -0
- package/dist/builtin/web-access/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/cli/args.js +2 -2
- package/dist/cli/auth-cli.code.js +4 -4
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +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 +2 -2
- 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 +2 -2
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +2 -2
- package/dist/core/agent-session-methods.d.ts +3 -0
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/compaction/compactor.d.ts +2 -0
- package/dist/core/debug.impl.js +3 -3
- package/dist/core/debug.js +3 -3
- package/dist/core/export-html/card-projection.code.js +1 -1
- 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 +2 -2
- package/dist/core/extensions/runner-context.js +3 -3
- package/dist/core/extensions/runner-context.js.map +1 -1
- package/dist/core/intercom-broker-control-host.code.js +1 -1
- package/dist/core/intercom-broker-control-host.impl.js +3 -3
- package/dist/core/intercom-broker-control-host.js +3 -3
- package/dist/core/intercom-broker-control.code.js +3 -3
- package/dist/core/intercom-broker-control.impl.js +3 -3
- package/dist/core/intercom-broker-control.js +3 -3
- package/dist/core/model-registry.js +1 -1
- package/dist/core/model-resolver-defaults.d.ts +3 -2
- 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/sdk.code.js +3 -4
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.d.ts +5 -2
- package/dist/core/session-manager-core.js +17 -13
- 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 +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/storage/added-exports.d.ts +6 -0
- package/dist/core/storage/added-exports.js +16 -0
- package/dist/core/storage/added-exports.js.map +1 -0
- package/dist/core/storage/database.d.ts +16 -0
- package/dist/core/storage/database.js.map +1 -1
- package/dist/core/storage/fenced-paths.d.ts +47 -0
- package/dist/core/storage/fenced-paths.js +53 -0
- package/dist/core/storage/fenced-paths.js.map +1 -1
- package/dist/core/storage/file-identity.js +31 -2
- package/dist/core/storage/file-identity.js.map +1 -1
- package/dist/core/storage/index.d.ts +3 -0
- package/dist/core/storage/index.js +5 -2
- package/dist/core/storage/index.js.map +1 -1
- package/dist/core/storage/migrations.d.ts +22 -0
- package/dist/core/storage/migrations.js +55 -0
- package/dist/core/storage/migrations.js.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +19 -6
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.js +53 -4
- 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 +3 -2
- package/dist/core/storage/prefix.js +18 -2
- package/dist/core/storage/prefix.js.map +1 -1
- package/dist/core/storage/provider.js +2 -2
- package/dist/core/storage/schema-catalog.d.ts +42 -0
- package/dist/core/storage/schema-catalog.js +141 -0
- package/dist/core/storage/schema-catalog.js.map +1 -0
- package/dist/core/storage/selection.js +2 -2
- package/dist/core/storage/session/branch-fork-source.code.js +41 -20
- 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 +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.code.js +1 -1
- 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 +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-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 +176 -36
- 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-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-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 +2 -2
- 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 +5 -0
- 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-chat-records.d.ts +15 -0
- package/dist/core/storage/session/sql-session-store.code.js +1 -1
- package/dist/core/storage/session/sql-session-store.d.ts +102 -5
- 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.code.js +1 -1
- 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 +14 -0
- package/dist/core/storage/sqlite-facade.d.ts +37 -5
- package/dist/core/storage/sqlite-facade.js +351 -18
- package/dist/core/storage/sqlite-facade.js.map +1 -1
- package/dist/core/storage/statement-sequence.d.ts +83 -0
- package/dist/core/storage/statement-sequence.js +21 -0
- package/dist/core/storage/statement-sequence.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.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.code.js +1 -1
- 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/bash.d.ts +8 -4
- package/dist/core/tools/history-session.d.ts +5 -0
- package/dist/core/tools/history-tasks.d.ts +123 -0
- package/dist/core/tools/kill.d.ts +5 -2
- package/dist/core/tools/powershell.d.ts +2 -2
- package/dist/core/tools/read-url.code.js +3 -3
- package/dist/core/tools/read-url.impl.js +3 -3
- package/dist/core/tools/read-url.js +3 -3
- package/dist/core/tools/read.d.ts +12 -2
- package/dist/core/tools/resource-selectors.d.ts +2 -0
- package/dist/core/tools/search.d.ts +12 -2
- package/dist/core/worktree-snapshot/blob-store.d.ts +14 -2
- package/dist/core/worktree-snapshot/blob-store.js +69 -16
- 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/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.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/agent-panel.d.ts +1 -0
- 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/task-inspector.d.ts +2 -0
- package/dist/modes/interactive/components/user-message-selector-archive.code.js +1 -1
- 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/interactive-mode-helpers.d.ts +2 -2
- package/dist/modes/print-mode.js +1 -1
- package/dist/modes/rpc/agent-panel-bridge.d.ts +5 -0
- 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/0.js +1 -1
- package/dist/startup-stages/1.js +1 -1
- package/dist/startup-stages/10.js +1 -1
- package/dist/startup-stages/12.js +1 -1
- package/dist/startup-stages/2.js +8 -1
- package/dist/startup-stages/3.js +1 -6
- package/dist/startup-stages/5.js +1 -1
- package/dist/startup-stages/7.js +1 -5
- 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/docs/background-tasks.md +123 -23
- package/docs/compaction.md +18 -0
- package/docs/docs.json +2 -0
- package/docs/environment-variables.md +1 -1
- package/docs/getting-started/installation.md +9 -2
- package/docs/guides/postgres-pgbouncer.md +339 -0
- package/docs/guides/postgres-tuning.md +311 -0
- package/docs/guides/resume-on-any-machine.md +2 -2
- package/docs/guides.md +2 -0
- package/docs/index.md +1 -1
- package/docs/libraries/agent-core.md +1 -1
- package/docs/libraries/ai.md +2 -2
- package/docs/libraries/codemode.md +1 -1
- package/docs/libraries/storage-libsql.md +6 -1
- package/docs/libraries/storage-postgres.md +11 -6
- package/docs/libraries/tui.md +1 -1
- package/docs/libraries.md +2 -2
- package/docs/programmatic.md +1 -1
- package/docs/quickstart.md +1 -1
- package/docs/sdk/storage.md +1 -1
- package/docs/sdk/web-server.md +1 -3
- package/docs/sdk.md +1 -7
- package/docs/sessions.md +58 -2
- package/docs/settings.md +20 -1
- package/docs/skills/authoring.md +1 -1
- package/docs/skills.md +79 -6
- package/docs/storage.md +262 -12
- package/docs/subagents/reference.md +2 -2
- package/docs/subagents.md +4 -3
- package/docs/tools.md +44 -10
- package/docs/windows.md +1 -1
- package/package.json +9 -9
- package/dist/_shared/sdk-RRLVN7ER.js.map +0 -1
- package/dist/_shared/startup-0-0-4VG2G44V.js.map +0 -1
- package/dist/_shared/startup-0-1-XTIL65D4.js.map +0 -1
- package/dist/_shared/startup-0-5-FD2P735I.js.map +0 -1
- package/dist/_shared/startup-8-1-4KANEHRA.js.map +0 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
dialectOf,
|
|
3
|
+
fencedPath,
|
|
3
4
|
type SqliteDatabase,
|
|
5
|
+
type SqliteExecutor,
|
|
4
6
|
type SqliteRow,
|
|
5
7
|
type StorageNotificationSubscription,
|
|
6
8
|
validateStoragePrefix,
|
|
@@ -15,7 +17,7 @@ import type {
|
|
|
15
17
|
WakeUpSubscribeResult,
|
|
16
18
|
WakeUpSubscription,
|
|
17
19
|
} from "./wake-up-bus.js";
|
|
18
|
-
import { ensureBrokerSchema } from "./sql-schema.js";
|
|
20
|
+
import { ensureBrokerSchema, withBrokerSchemaCatalog } from "./sql-schema.js";
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* S4 wake-up bus (specs/2026-10-19-intercom-multi-node.md §5.6): a hint log in the shared storage database. Each
|
|
@@ -27,13 +29,25 @@ import { ensureBrokerSchema } from "./sql-schema.js";
|
|
|
27
29
|
* On a database that delivers notifications (Postgres), a publish also notifies the channel named like the table, in
|
|
28
30
|
* the transaction that writes the hint, and a subscribed connection polls as soon as a notification for one of its
|
|
29
31
|
* brokers arrives (#5103). The interval poll stays: notifications are lost while the listening connection is down, and
|
|
30
|
-
* none arrive through a transaction pooler.
|
|
32
|
+
* none arrive through a transaction pooler. While the database reports its listening connection live, the poll only
|
|
33
|
+
* backs the notifications up and runs at `WAKE_UP_LISTENING_POLL_INTERVAL_MS`; the listener's `listening` event, sent
|
|
34
|
+
* when it listens again after an outage, polls at once (#6560).
|
|
31
35
|
*/
|
|
32
36
|
|
|
33
|
-
/** How often a connection with subscriptions reads its hints. */
|
|
37
|
+
/** How often a connection with subscriptions reads its hints when no notification would announce them. */
|
|
34
38
|
export const WAKE_UP_POLL_INTERVAL_MS = 500;
|
|
39
|
+
/**
|
|
40
|
+
* How often a connection with subscriptions reads its hints while its notifications are live: only a notification lost
|
|
41
|
+
* in an outage the listener has not noticed yet waits for this poll.
|
|
42
|
+
*/
|
|
43
|
+
export const WAKE_UP_LISTENING_POLL_INTERVAL_MS = 5_000;
|
|
35
44
|
/** Hints nobody consumed (their broker exited) are deleted after this age; the backup poll has covered them. */
|
|
36
45
|
export const WAKE_UP_HINT_RETENTION_MS = OUTBOX_BACKUP_POLL_INTERVAL_MS;
|
|
46
|
+
/**
|
|
47
|
+
* How often at most one connection deletes the hints past the retention, at a publish (#6560): a hint nobody consumed
|
|
48
|
+
* then stays at most this much longer than the retention.
|
|
49
|
+
*/
|
|
50
|
+
export const WAKE_UP_PRUNE_INTERVAL_MS = 10_000;
|
|
37
51
|
/**
|
|
38
52
|
* Hints read and deleted per statement; a poll repeats until a batch comes back short. Each batch's delete binds one
|
|
39
53
|
* parameter per hint, so a backlog never exceeds SQLite's bound-parameter limit (999 on old builds).
|
|
@@ -51,7 +65,15 @@ export interface DatabaseWakeUpBusOptions {
|
|
|
51
65
|
/** The validated storage prefix; the table is `<prefix>intercom_wakeups`. */
|
|
52
66
|
readonly prefix?: string;
|
|
53
67
|
readonly pollIntervalMs?: number;
|
|
68
|
+
readonly listeningPollIntervalMs?: number;
|
|
54
69
|
readonly schedule?: WakeUpPollScheduler;
|
|
70
|
+
/**
|
|
71
|
+
* 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 takes and deletes its hints through
|
|
73
|
+
* it in one statement (`DELETE … RETURNING`), so it must accept writes. Absent: the poll runs on the database it
|
|
74
|
+
* opened.
|
|
75
|
+
*/
|
|
76
|
+
readonly reader?: SqliteExecutor;
|
|
55
77
|
}
|
|
56
78
|
|
|
57
79
|
interface HintRow extends SqliteRow {
|
|
@@ -88,12 +110,22 @@ async function createSchema(database: SqliteDatabase, table: string, prefix: str
|
|
|
88
110
|
await ensureBrokerSchema(database, prefix, "wakeups", (tx) => tx.exec(schema));
|
|
89
111
|
}
|
|
90
112
|
|
|
91
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Opens a connection to the bus's database and sets up its table, checked against one read of the schema catalog, so a
|
|
115
|
+
* current table costs no transaction or lock (#6560). With `schemaSetUp`, this bus set the table up already, on an
|
|
116
|
+
* earlier connection: a schema only moves forward, so the connection runs no schema statement at all.
|
|
117
|
+
*/
|
|
118
|
+
async function openSchemaConnection(
|
|
119
|
+
options: DatabaseWakeUpBusOptions,
|
|
120
|
+
table: string,
|
|
121
|
+
schemaSetUp = false,
|
|
122
|
+
): Promise<SqliteDatabase> {
|
|
92
123
|
const database = await options.openDatabase();
|
|
93
124
|
try {
|
|
94
125
|
// Refused before anything is created when the prefix is too long for this backend's identifiers (#5067).
|
|
95
126
|
validateStoragePrefix(options.prefix, dialectOf(database).name);
|
|
96
|
-
|
|
127
|
+
if (!schemaSetUp)
|
|
128
|
+
await withBrokerSchemaCatalog(database, options.prefix, () => createSchema(database, table, options.prefix));
|
|
97
129
|
} catch (cause) {
|
|
98
130
|
await database.close().catch(() => {});
|
|
99
131
|
throw cause;
|
|
@@ -106,6 +138,7 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
106
138
|
private readonly options: DatabaseWakeUpBusOptions;
|
|
107
139
|
private readonly table: string;
|
|
108
140
|
private readonly pollIntervalMs: number;
|
|
141
|
+
private readonly listeningPollIntervalMs: number;
|
|
109
142
|
private readonly schedule: WakeUpPollScheduler;
|
|
110
143
|
private database: SqliteDatabase | undefined;
|
|
111
144
|
private opening: Promise<SqliteDatabase | undefined> | undefined;
|
|
@@ -117,15 +150,25 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
117
150
|
private reconnectFailures = 0;
|
|
118
151
|
private reconnectNotBefore = 0;
|
|
119
152
|
/** The notification channel this connection listens on, and the database it listens through. */
|
|
120
|
-
private listening:
|
|
153
|
+
private listening:
|
|
154
|
+
| {
|
|
155
|
+
readonly database: SqliteDatabase;
|
|
156
|
+
readonly subscription: StorageNotificationSubscription;
|
|
157
|
+
/** The database reported its listening connection live, as of the latest check. */
|
|
158
|
+
live: boolean;
|
|
159
|
+
}
|
|
160
|
+
| undefined;
|
|
121
161
|
/** A notification arrived during a poll: the next poll runs as soon as that one ends. */
|
|
122
162
|
private pollAgain = false;
|
|
163
|
+
/** When a publish last deleted the hints past the retention, by this process's clock. */
|
|
164
|
+
private prunedAt: number | undefined;
|
|
123
165
|
|
|
124
166
|
constructor(options: DatabaseWakeUpBusOptions, table: string, database: SqliteDatabase) {
|
|
125
167
|
this.options = options;
|
|
126
168
|
this.table = table;
|
|
127
169
|
this.database = database;
|
|
128
170
|
this.pollIntervalMs = options.pollIntervalMs ?? WAKE_UP_POLL_INTERVAL_MS;
|
|
171
|
+
this.listeningPollIntervalMs = options.listeningPollIntervalMs ?? WAKE_UP_LISTENING_POLL_INTERVAL_MS;
|
|
129
172
|
this.schedule = options.schedule ?? scheduleTimeout;
|
|
130
173
|
}
|
|
131
174
|
|
|
@@ -139,20 +182,26 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
139
182
|
try {
|
|
140
183
|
if (notifications === undefined) await database.run(insert, hint.brokerId, hint.reason, hint.version);
|
|
141
184
|
else {
|
|
142
|
-
// The notification goes out when the hint commits, so the poll it starts finds the hint.
|
|
185
|
+
// The notification goes out when the hint commits, so the poll it starts finds the hint. A hint is a new
|
|
186
|
+
// row that no write checks first, so its writers take no lock domain (#6560): see
|
|
187
|
+
// `fencedPath("intercom-wakeup-hint")`.
|
|
143
188
|
const notify = notifications.notify(this.table, hint.brokerId);
|
|
144
189
|
await database.transaction(
|
|
145
190
|
async (tx) => {
|
|
146
191
|
await tx.run(insert, hint.brokerId, hint.reason, hint.version);
|
|
147
192
|
await tx.run(notify.sql, ...notify.params);
|
|
148
193
|
},
|
|
149
|
-
{ concurrency: { kind: "
|
|
194
|
+
{ concurrency: { kind: "fenced", audit: fencedPath("intercom-wakeup-hint") } },
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
// #6560: at most once per interval, not at every publish: each prune is a write every broker would send.
|
|
198
|
+
if (this.prunedAt === undefined || Date.now() - this.prunedAt >= WAKE_UP_PRUNE_INTERVAL_MS) {
|
|
199
|
+
this.prunedAt = Date.now();
|
|
200
|
+
await database.run(
|
|
201
|
+
`DELETE FROM ${this.table} WHERE created_at < ${nowMs} - ?`,
|
|
202
|
+
WAKE_UP_HINT_RETENTION_MS,
|
|
150
203
|
);
|
|
151
204
|
}
|
|
152
|
-
await database.run(
|
|
153
|
-
`DELETE FROM ${this.table} WHERE created_at < ${nowMs} - ?`,
|
|
154
|
-
WAKE_UP_HINT_RETENTION_MS,
|
|
155
|
-
);
|
|
156
205
|
} catch {
|
|
157
206
|
this.drop(database);
|
|
158
207
|
return { status: "unavailable" };
|
|
@@ -213,10 +262,25 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
213
262
|
const notifications = database.notifications;
|
|
214
263
|
if (notifications === undefined) return;
|
|
215
264
|
const subscription = notifications.listen(this.table, (event) => {
|
|
216
|
-
if (event.kind === "listening"
|
|
265
|
+
if (event.kind === "listening") {
|
|
266
|
+
if (this.listening?.subscription === subscription) this.listening.live = true;
|
|
217
267
|
this.pollNow();
|
|
268
|
+
} else if ([...this.subscriptions].some((open) => open.brokerId === event.payload)) this.pollNow();
|
|
218
269
|
});
|
|
219
|
-
this.listening = { database, subscription };
|
|
270
|
+
this.listening = { database, subscription, live: false };
|
|
271
|
+
void this.checkListening();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** Asks the database whether its listening connection is live, for the interval of the next poll. */
|
|
275
|
+
private async checkListening(): Promise<void> {
|
|
276
|
+
const listening = this.listening;
|
|
277
|
+
const notifications = listening?.database.notifications;
|
|
278
|
+
if (listening === undefined || notifications === undefined) return;
|
|
279
|
+
const live = await notifications.state().then(
|
|
280
|
+
(state) => state.status === "listening",
|
|
281
|
+
() => false,
|
|
282
|
+
);
|
|
283
|
+
if (this.listening === listening) listening.live = live;
|
|
220
284
|
}
|
|
221
285
|
|
|
222
286
|
/** Polls at once, or as soon as the poll in progress ends, instead of at the next interval. */
|
|
@@ -237,7 +301,9 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
237
301
|
this.cancelPoll = this.schedule(() => {
|
|
238
302
|
this.cancelPoll = undefined;
|
|
239
303
|
this.pollAgain = false;
|
|
240
|
-
this.polling = this.poll()
|
|
304
|
+
this.polling = this.poll()
|
|
305
|
+
.then(() => this.checkListening())
|
|
306
|
+
.finally(() => {
|
|
241
307
|
this.polling = undefined;
|
|
242
308
|
this.armPoll(this.pollAgain ? 0 : this.nextPollDelayMs());
|
|
243
309
|
});
|
|
@@ -245,6 +311,8 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
245
311
|
}
|
|
246
312
|
|
|
247
313
|
private nextPollDelayMs(): number {
|
|
314
|
+
if (this.database !== undefined && this.listening?.database === this.database && this.listening.live)
|
|
315
|
+
return this.listeningPollIntervalMs;
|
|
248
316
|
if (this.database !== undefined || this.reconnectFailures === 0) return this.pollIntervalMs;
|
|
249
317
|
return Math.min(this.pollIntervalMs * 2 ** this.reconnectFailures, WAKE_UP_RECONNECT_MAX_DELAY_MS);
|
|
250
318
|
}
|
|
@@ -254,18 +322,27 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
254
322
|
const brokerIds = [...new Set([...this.subscriptions].map((subscription) => subscription.brokerId))];
|
|
255
323
|
if (database === undefined || brokerIds.length === 0) return;
|
|
256
324
|
const placeholders = brokerIds.map(() => "?").join(", ");
|
|
325
|
+
const batch = `FROM ${this.table} WHERE broker_id IN (${placeholders}) ORDER BY id LIMIT ${WAKE_UP_POLL_BATCH_SIZE}`;
|
|
326
|
+
const reader = this.options.reader ?? database;
|
|
257
327
|
for (;;) {
|
|
258
328
|
let rows: HintRow[];
|
|
259
329
|
try {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
`DELETE FROM ${this.table} WHERE id IN (${rows.map(() => "?").join(", ")})`,
|
|
267
|
-
...rows.map((row) => row.id),
|
|
330
|
+
if (dialectOf(database).name === "postgres") {
|
|
331
|
+
// #6560: one statement takes the batch and deletes it, through the reader, whose calls never queue
|
|
332
|
+
// behind this database's writes. It returns the hints in no particular order.
|
|
333
|
+
rows = await reader.all<HintRow>(
|
|
334
|
+
`DELETE FROM ${this.table} WHERE id IN (SELECT id ${batch}) RETURNING id, broker_id, reason, version`,
|
|
335
|
+
...brokerIds,
|
|
268
336
|
);
|
|
337
|
+
rows.sort((left, right) => Number(left.id) - Number(right.id));
|
|
338
|
+
} else {
|
|
339
|
+
rows = await reader.all<HintRow>(`SELECT id, broker_id, reason, version ${batch}`, ...brokerIds);
|
|
340
|
+
if (rows.length > 0) {
|
|
341
|
+
await database.run(
|
|
342
|
+
`DELETE FROM ${this.table} WHERE id IN (${rows.map(() => "?").join(", ")})`,
|
|
343
|
+
...rows.map((row) => row.id),
|
|
344
|
+
);
|
|
345
|
+
}
|
|
269
346
|
}
|
|
270
347
|
} catch {
|
|
271
348
|
this.drop(database);
|
|
@@ -299,7 +376,9 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
299
376
|
private async reconnect(): Promise<SqliteDatabase | undefined> {
|
|
300
377
|
let database: SqliteDatabase;
|
|
301
378
|
try {
|
|
302
|
-
|
|
379
|
+
// The bus set its table up when it opened: replacing a dropped connection runs no schema statement, so it never
|
|
380
|
+
// takes the database's write lock, however many brokers lose their connections at once (#6560).
|
|
381
|
+
database = await openSchemaConnection(this.options, this.table, true);
|
|
303
382
|
} catch {
|
|
304
383
|
this.reconnectFailures++;
|
|
305
384
|
this.reconnectNotBefore = Date.now() + this.nextPollDelayMs();
|
|
@@ -2775,21 +2775,22 @@ export class MultiNodeRouter {
|
|
|
2775
2775
|
*/
|
|
2776
2776
|
private async sweepLostRecipients(): Promise<void> {
|
|
2777
2777
|
const { afterRestartMs, afterStaleLeaseMs } = this.lostBounds;
|
|
2778
|
-
const
|
|
2779
|
-
const
|
|
2778
|
+
const { leases } = this.state;
|
|
2779
|
+
const lostAfterMs = BROKER_LEASE_STALE_AFTER_MS + afterStaleLeaseMs;
|
|
2780
|
+
// #6560: only the leases stale past the bound, which while every broker renews its sessions' is none: every
|
|
2781
|
+
// broker sweeps every backup poll, and reading every lease each time grew with the square of the swarm.
|
|
2782
|
+
const aged =
|
|
2783
|
+
leases.listAged === undefined
|
|
2784
|
+
? (await leases.listLive("presence", Number.MAX_SAFE_INTEGER)).filter((lease) => lease.ageMs >= lostAfterMs)
|
|
2785
|
+
: await leases.listAged("presence", lostAfterMs);
|
|
2780
2786
|
const lost = new Map<string, { from: SessionInfo; targetIdentity: string; boundMs: number }>();
|
|
2781
|
-
for (const lease of
|
|
2787
|
+
for (const lease of aged) {
|
|
2782
2788
|
const subject = lease.subject as RecipientPresenceSubject;
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
from: subject.session,
|
|
2789
|
-
targetIdentity: subject.targetIdentity,
|
|
2790
|
-
boundMs: afterStaleLeaseMs,
|
|
2791
|
-
});
|
|
2792
|
-
}
|
|
2789
|
+
lost.set(subject.session.id, {
|
|
2790
|
+
from: subject.session,
|
|
2791
|
+
targetIdentity: subject.targetIdentity,
|
|
2792
|
+
boundMs: afterStaleLeaseMs,
|
|
2793
|
+
});
|
|
2793
2794
|
}
|
|
2794
2795
|
for (const known of await this.state.knownSessions.listLost(afterRestartMs)) {
|
|
2795
2796
|
const from: SessionInfo = {
|
|
@@ -2805,6 +2806,14 @@ export class MultiNodeRouter {
|
|
|
2805
2806
|
};
|
|
2806
2807
|
lost.set(known.intercomSessionId, { from, targetIdentity: known.targetIdentity, boundMs: afterRestartMs });
|
|
2807
2808
|
}
|
|
2809
|
+
if (lost.size === 0) return;
|
|
2810
|
+
// A session lost under one identity may be present under another: the live leases, read only when one is lost.
|
|
2811
|
+
const live = new Set<string>();
|
|
2812
|
+
for (const lease of await leases.listLive("presence", BROKER_LEASE_STALE_AFTER_MS)) {
|
|
2813
|
+
const subject = lease.subject as RecipientPresenceSubject;
|
|
2814
|
+
live.add(subject.session.id);
|
|
2815
|
+
live.add(subject.targetIdentity);
|
|
2816
|
+
}
|
|
2808
2817
|
for (const [sessionId, { from, targetIdentity, boundMs }] of lost) {
|
|
2809
2818
|
if (live.has(sessionId) || live.has(targetIdentity) || this.host.sessions.has(sessionId)) continue;
|
|
2810
2819
|
if (await this.reservedForReturn(sessionId, targetIdentity, from)) continue;
|
|
@@ -4221,8 +4230,18 @@ export class MultiNodeRouter {
|
|
|
4221
4230
|
if (await this.routeReleasedReply(request, undefined, ticket)) return;
|
|
4222
4231
|
if (this.closed) return;
|
|
4223
4232
|
const from = request.from;
|
|
4233
|
+
const leases = this.state.leases;
|
|
4234
|
+
// Presences are stored with every string well formed (#6560): a target ending in half a surrogate pair names them
|
|
4235
|
+
// as their stored strings do.
|
|
4236
|
+
const target = request.target.toWellFormed();
|
|
4224
4237
|
for (;;) {
|
|
4225
|
-
|
|
4238
|
+
// Only the presences the target may name, by index, where the store can (#6560): what follows resolves the
|
|
4239
|
+
// target among those alone, as it would among every live presence.
|
|
4240
|
+
const candidates =
|
|
4241
|
+
leases.listLiveFor === undefined
|
|
4242
|
+
? leases.listLive("presence", BROKER_LEASE_STALE_AFTER_MS)
|
|
4243
|
+
: leases.listLiveFor(target, BROKER_LEASE_STALE_AFTER_MS);
|
|
4244
|
+
const live = (await candidates).filter(
|
|
4226
4245
|
(lease) =>
|
|
4227
4246
|
lease.subject.kind === "presence" &&
|
|
4228
4247
|
lease.holderId !== this.brokerId &&
|
|
@@ -4234,8 +4253,8 @@ export class MultiNodeRouter {
|
|
|
4234
4253
|
// #5607: a plain send to an id a session holds as an alias reaches that session.
|
|
4235
4254
|
const plain = isPlainSend(request);
|
|
4236
4255
|
const exact =
|
|
4237
|
-
live.find((lease) => presenceOf(lease).session.id ===
|
|
4238
|
-
(plain ? await this.aliasHolder(live,
|
|
4256
|
+
live.find((lease) => presenceOf(lease).session.id === target) ??
|
|
4257
|
+
(plain ? await this.aliasHolder(live, target) : undefined);
|
|
4239
4258
|
if (this.closed) return;
|
|
4240
4259
|
let resolved: LeaseState | undefined = exact;
|
|
4241
4260
|
if (resolved === undefined) {
|
|
@@ -4255,15 +4274,17 @@ export class MultiNodeRouter {
|
|
|
4255
4274
|
const nonAgentNamed = visible.some(
|
|
4256
4275
|
(lease) =>
|
|
4257
4276
|
!isAgentRecipient(presenceOf(lease).session) &&
|
|
4258
|
-
presenceOf(lease).session.name?.toLowerCase() ===
|
|
4277
|
+
presenceOf(lease).session.name?.toLowerCase() === target.toLowerCase(),
|
|
4259
4278
|
);
|
|
4260
4279
|
const agents = visible.filter((lease) => isAgentRecipient(presenceOf(lease).session));
|
|
4261
4280
|
const infos = agents.map((lease) => presenceOf(lease).session);
|
|
4262
|
-
let resolution: SessionTargetResolution = resolveSessionTarget(infos,
|
|
4281
|
+
let resolution: SessionTargetResolution = resolveSessionTarget(infos, target);
|
|
4263
4282
|
if (resolution.kind === "not_found") {
|
|
4264
|
-
resolution = resolveSessionTargetByHostSessionId(infos,
|
|
4283
|
+
resolution = resolveSessionTargetByHostSessionId(infos, target, (info) => {
|
|
4265
4284
|
const lease = agents.find((candidate) => presenceOf(candidate).session === info);
|
|
4266
|
-
return lease === undefined
|
|
4285
|
+
return lease === undefined
|
|
4286
|
+
? undefined
|
|
4287
|
+
: returnAddressOf(presenceOf(lease).targetIdentity)?.toWellFormed();
|
|
4267
4288
|
});
|
|
4268
4289
|
}
|
|
4269
4290
|
// A sender this one holds a return path to answers to its name only when nothing visible does.
|
|
@@ -4282,7 +4303,7 @@ export class MultiNodeRouter {
|
|
|
4282
4303
|
if (answerable.length > 0) {
|
|
4283
4304
|
const answered = resolveSessionTarget(
|
|
4284
4305
|
answerable.map((lease) => presenceOf(lease).session),
|
|
4285
|
-
|
|
4306
|
+
target,
|
|
4286
4307
|
);
|
|
4287
4308
|
if (answered.kind !== "not_found") {
|
|
4288
4309
|
resolution = answered;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import type { SqliteDatabase } from "@bastani/atomic/storage";
|
|
2
|
+
import type { SqliteDatabase, SqliteExecutor } from "@bastani/atomic/storage";
|
|
3
3
|
import type { BrokerMessage, ClientMessage, ReachPolicyFrame, SessionInfo } from "../types.js";
|
|
4
4
|
import type { EndedChildQueueStore } from "./sql-ended-child-queue-store.js";
|
|
5
5
|
import { isReleasedReservationKey } from "./released-children.js";
|
|
@@ -180,6 +180,22 @@ export interface BrokerLeaseStore {
|
|
|
180
180
|
read(key: LeaseKey): Promise<LeaseReadResult>;
|
|
181
181
|
/** Live leases of one kind, in the order their keys were first acquired. */
|
|
182
182
|
listLive(kind: LeaseKind, staleAfterMs: number): Promise<LeaseState[]>;
|
|
183
|
+
/**
|
|
184
|
+
* The live presence leases a send to `target` may resolve to, in the order their keys were first acquired: every one
|
|
185
|
+
* whose session's id is `target` or `target` trimmed, whose session's name is either of them in any case, whose UUID
|
|
186
|
+
* id starts with `target` trimmed when that is an 8-digit hex prefix, whose identity's return address is `target`
|
|
187
|
+
* trimmed, or whose aliases include `target`. It may list others too, which the caller's own matching leaves out. Read
|
|
188
|
+
* by index, so a send's read does not grow with the presences of other sessions (#6560). Absent on custom stores and
|
|
189
|
+
* on a database whose role may not add the columns it reads, where `listLive("presence")` serves instead.
|
|
190
|
+
*/
|
|
191
|
+
listLiveFor?(target: string, staleAfterMs: number): Promise<LeaseState[]>;
|
|
192
|
+
/**
|
|
193
|
+
* Held leases of one kind at least `minAgeMs` old, in the order their keys were first acquired: what `listLive` with
|
|
194
|
+
* no bound lists past that age, without reading the younger ones. While every lease is renewed it reads no row, so a
|
|
195
|
+
* periodic check for leases left behind costs one empty read rather than every lease (#6560). Absent on custom
|
|
196
|
+
* stores, which `listLive` with no bound serves instead.
|
|
197
|
+
*/
|
|
198
|
+
listAged?(kind: LeaseKind, minAgeMs: number): Promise<LeaseState[]>;
|
|
183
199
|
/**
|
|
184
200
|
* #5038: give up every lease `holderId` holds, as its own `release` would, so their next acquisitions need not
|
|
185
201
|
* wait for them to go stale. Resolves to the number of leases retired.
|
|
@@ -1056,6 +1072,11 @@ export interface IntercomBrokerStateOptions {
|
|
|
1056
1072
|
readonly database: SqliteDatabase;
|
|
1057
1073
|
/** The adapter's validated table prefix. */
|
|
1058
1074
|
readonly prefix: string;
|
|
1075
|
+
/**
|
|
1076
|
+
* A separate handle on `database` for the reads that answer within a bound (live leases, known sessions), so they
|
|
1077
|
+
* never queue behind its writes (#6560); the store does not close it. Absent: they read through `database`.
|
|
1078
|
+
*/
|
|
1079
|
+
readonly reader?: SqliteExecutor;
|
|
1059
1080
|
}
|
|
1060
1081
|
|
|
1061
1082
|
export type OpenIntercomBrokerStateStore = (options: IntercomBrokerStateOptions) => Promise<IntercomBrokerStateStore>;
|
|
@@ -17,14 +17,15 @@ import {
|
|
|
17
17
|
} from "@bastani/atomic/storage";
|
|
18
18
|
import { type DatabaseWakeUpBusOptions, openDatabaseWakeUpBus } from "./database-wake-up-bus.js";
|
|
19
19
|
import type { IntercomBrokerStateStore } from "./multinode-state-store.js";
|
|
20
|
-
import { openSqlEndedChildQueueStore } from "./sql-ended-child-queue-store.js";
|
|
20
|
+
import { ensureEndedChildQueueSchema, openSqlEndedChildQueueStore } from "./sql-ended-child-queue-store.js";
|
|
21
21
|
import { openSqlHeldSendStore } from "./sql-held-send-store.js";
|
|
22
22
|
import { openSqlKnownSessionStore } from "./sql-known-session-store.js";
|
|
23
23
|
import { openSqlBrokerLeaseStore } from "./sql-lease-store.js";
|
|
24
|
-
import { openSqlOutboxStore, withoutFailedWake } from "./sql-outbox-store.js";
|
|
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
27
|
import { openSqlRestoringReservationStore } from "./sql-restoring-reservation-store.js";
|
|
28
|
+
import { withBrokerSchemaCatalog } from "./sql-schema.js";
|
|
28
29
|
import { openSqlSentMessageAuthority } from "./sql-sent-message-authority.js";
|
|
29
30
|
import type { WakeUpBus } from "./wake-up-bus.js";
|
|
30
31
|
|
|
@@ -124,29 +125,55 @@ export function borrowedDatabase(database: SqliteDatabase): SqliteDatabase {
|
|
|
124
125
|
return new Proxy(database, { get: (target, key) => (key === "close" ? close : Reflect.get(target, key)) });
|
|
125
126
|
}
|
|
126
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Creates the tables a broker creates only on first use, today the ended-child queue's, for `atomic storage migrate`:
|
|
130
|
+
* with `openIntercomBrokerState`, every table a broker needs, so a runtime role that may not create tables finds them
|
|
131
|
+
* (#6560).
|
|
132
|
+
*/
|
|
133
|
+
export async function ensureLazyIntercomSchemas(source: SharedDatabaseSource): Promise<void> {
|
|
134
|
+
const database = await source.openDatabase();
|
|
135
|
+
try {
|
|
136
|
+
await ensureEndedChildQueueSchema({ database, prefix: source.prefix ?? "" });
|
|
137
|
+
} finally {
|
|
138
|
+
await database.close();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
127
142
|
/** Compose S1–S4 and the S5 known-session store, and the wake-up bus, on one connection. */
|
|
128
143
|
export async function openIntercomBrokerState(
|
|
129
144
|
source: SharedDatabaseSource,
|
|
130
|
-
busOptions: Pick<DatabaseWakeUpBusOptions, "pollIntervalMs" | "schedule"> = {},
|
|
145
|
+
busOptions: Pick<DatabaseWakeUpBusOptions, "pollIntervalMs" | "listeningPollIntervalMs" | "schedule"> = {},
|
|
131
146
|
): Promise<OpenedBrokerState> {
|
|
132
147
|
const database = await source.openDatabase();
|
|
148
|
+
let reader: SqliteDatabase | undefined;
|
|
133
149
|
try {
|
|
134
150
|
// The backend is known once the database is open: refuse a prefix too long for it before creating anything (#5067).
|
|
135
151
|
validateStoragePrefix(source.prefix, dialectOf(database).name);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
152
|
+
// Reads that answer within a bound go through a handle of their own, never queued behind the writes (#6560).
|
|
153
|
+
reader = await database.openReader?.();
|
|
154
|
+
const options = { database, prefix: source.prefix ?? "", ...(reader === undefined ? {} : { reader }) };
|
|
155
|
+
const borrowed = borrowedDatabase(database);
|
|
156
|
+
const openStores = async () => {
|
|
157
|
+
const leases = await openSqlBrokerLeaseStore(options);
|
|
158
|
+
const outbox = await openSqlOutboxStore(options);
|
|
159
|
+
const heldSends = await openSqlHeldSendStore(options);
|
|
160
|
+
const reservations = await openSqlRestoringReservationStore(options);
|
|
161
|
+
const pendingAsks = await openSqlPendingAskStore(options);
|
|
162
|
+
const releasedAsks = await openSqlReleasedAskStore(options);
|
|
163
|
+
const sentMessages = await openSqlSentMessageAuthority(options);
|
|
164
|
+
const knownSessions = await openSqlKnownSessionStore(options);
|
|
165
|
+
const bus = await openDatabaseWakeUpBus({
|
|
166
|
+
openDatabase: async () => borrowed,
|
|
167
|
+
prefix: source.prefix,
|
|
168
|
+
...busOptions,
|
|
169
|
+
...(reader === undefined ? {} : { reader }),
|
|
170
|
+
});
|
|
171
|
+
return { leases, outbox, heldSends, reservations, pendingAsks, releasedAsks, sentMessages, knownSessions, bus };
|
|
172
|
+
};
|
|
173
|
+
// One read of the schema for every store: a broker whose stores are current opens without a schema transaction,
|
|
174
|
+
// so brokers starting together neither take nor wait for the database's write lock (#6560).
|
|
175
|
+
const { leases, outbox, heldSends, reservations, pendingAsks, releasedAsks, sentMessages, knownSessions, bus } =
|
|
176
|
+
await withBrokerSchemaCatalog(database, options.prefix, openStores, [borrowed]);
|
|
150
177
|
let closing: Promise<void> | undefined;
|
|
151
178
|
const state: IntercomBrokerStateStore = {
|
|
152
179
|
leases,
|
|
@@ -158,32 +185,56 @@ export async function openIntercomBrokerState(
|
|
|
158
185
|
sentMessages,
|
|
159
186
|
knownSessions,
|
|
160
187
|
reserveAndEnqueue(reservation, request) {
|
|
188
|
+
// The recipient's domain: sends to it run one at a time, and sends to others beside them (#6560).
|
|
189
|
+
const send = recipientTransaction(database, source.prefix, request.targetIdentity);
|
|
190
|
+
// The reservation's read and the enqueue's go out with the transaction's start, the reservation's write
|
|
191
|
+
// and the row's insert together, then the commit, on a pipelined connection: three round trips (#6560).
|
|
192
|
+
const leading = (attempt: typeof request) => [
|
|
193
|
+
sentMessages.lookupStatement(reservation.messageId),
|
|
194
|
+
...outbox.enqueueLeading(attempt),
|
|
195
|
+
];
|
|
161
196
|
// #5607: written again, without it, when only an offline recipient's wake-up hint failed.
|
|
162
|
-
return withoutFailedWake(request, (attempt) =>
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
//
|
|
169
|
-
|
|
197
|
+
return withoutFailedWake(request, (attempt) =>
|
|
198
|
+
database.transaction(async (tx) => {
|
|
199
|
+
const key = { messageId: reservation.messageId, digest: reservation.digest };
|
|
200
|
+
const earlier = await sentMessages.lookupIn(tx, key);
|
|
201
|
+
if (earlier.status === "conflict")
|
|
202
|
+
return { status: "conflict", messageId: reservation.messageId } as const;
|
|
203
|
+
// The reservation is written first and the row inserted only under it: a reservation of the message
|
|
204
|
+
// with another digest, on another connection and in no domain of this recipient, either commits first
|
|
205
|
+
// and the row is refused, or waits for this send and is refused itself (#6560).
|
|
206
|
+
const reserve = sentMessages.reserveStatement(reservation);
|
|
207
|
+
const enqueued = await outbox.enqueueIn(
|
|
208
|
+
tx,
|
|
209
|
+
attempt,
|
|
210
|
+
reserve === undefined
|
|
211
|
+
? undefined
|
|
212
|
+
: { first: reserve, condition: sentMessages.reservedCondition(key) },
|
|
213
|
+
);
|
|
214
|
+
if (enqueued.status === "full") {
|
|
215
|
+
// Refused before anything was written, so the transaction has no commit to sync.
|
|
216
|
+
if (earlier.status === "match") await sentMessages.forgetIn(tx, key);
|
|
217
|
+
return enqueued;
|
|
218
|
+
}
|
|
219
|
+
// Another send's row of the message, with another digest: the reservation this send wrote goes too.
|
|
220
|
+
if (enqueued.status === "conflict" && earlier.status === "miss") await sentMessages.forgetIn(tx, key);
|
|
221
|
+
// A duplicate the leading read found wrote nothing: its reservation is recorded again, as before.
|
|
222
|
+
else if (enqueued.status === "duplicate" && reserve !== undefined) await runLast(tx, reserve);
|
|
170
223
|
return enqueued;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
await sentMessages.reserveIn(tx, reservation);
|
|
174
|
-
return enqueued;
|
|
175
|
-
}));
|
|
224
|
+
}, { ...send, leading: leading(attempt) }),
|
|
225
|
+
);
|
|
176
226
|
},
|
|
177
227
|
openEndedChildQueue(owner) {
|
|
178
228
|
return openSqlEndedChildQueueStore(options, owner);
|
|
179
229
|
},
|
|
180
230
|
close() {
|
|
181
|
-
closing ??= database.close();
|
|
231
|
+
closing ??= Promise.all([reader?.close(), database.close()]).then(() => {});
|
|
182
232
|
return closing;
|
|
183
233
|
},
|
|
184
234
|
};
|
|
185
235
|
return { state, bus };
|
|
186
236
|
} catch (cause) {
|
|
237
|
+
await reader?.close().catch(() => {});
|
|
187
238
|
await database.close().catch(() => {});
|
|
188
239
|
throw cause;
|
|
189
240
|
}
|
|
@@ -2,7 +2,7 @@ import { createHash } from "crypto";
|
|
|
2
2
|
import { type BigIntStats, lstatSync, mkdirSync, readFileSync, renameSync, type Stats, writeFileSync } from "fs";
|
|
3
3
|
import { lstat, mkdir, readFile } from "node:fs/promises";
|
|
4
4
|
import { homedir, tmpdir } from "os";
|
|
5
|
-
import { basename, dirname, join, resolve } from "path";
|
|
5
|
+
import { basename, dirname, isAbsolute, join, resolve } from "path";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* The shared storage selection (`ATOMIC_STORAGE` JSON) the launching Atomic process hands its broker: its
|
|
@@ -251,6 +251,10 @@ function inDirectorySocketPath(agentDir: string): string {
|
|
|
251
251
|
return join(getIntercomDirPath(agentDir), "broker.sock");
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
function absoluteSocketPath(socketPath: string): string {
|
|
255
|
+
return isAbsolute(socketPath) ? socketPath : resolve(socketPath);
|
|
256
|
+
}
|
|
257
|
+
|
|
254
258
|
function fitsUnixSocketPath(socketPath: string, platform: NodeJS.Platform): boolean {
|
|
255
259
|
return Buffer.byteLength(socketPath) <= maxUnixSocketPathBytes(platform);
|
|
256
260
|
}
|
|
@@ -264,7 +268,7 @@ export function directBrokerSocketPath(
|
|
|
264
268
|
return pipe.length <= MAX_PIPE_NAME_LENGTH ? pipe : `${WINDOWS_PIPE_PREFIX}${agentDirDigest(agentDir)}`;
|
|
265
269
|
}
|
|
266
270
|
const socketPath = inDirectorySocketPath(agentDir);
|
|
267
|
-
return fitsUnixSocketPath(socketPath, platform) ? socketPath : undefined;
|
|
271
|
+
return fitsUnixSocketPath(absoluteSocketPath(socketPath), platform) ? socketPath : undefined;
|
|
268
272
|
}
|
|
269
273
|
|
|
270
274
|
/**
|
|
@@ -327,7 +331,7 @@ export function chooseBrokerSocketPath(
|
|
|
327
331
|
const direct = directBrokerSocketPath(platform, agentDir);
|
|
328
332
|
if (direct !== undefined) return direct;
|
|
329
333
|
|
|
330
|
-
const socketPath = inDirectorySocketPath(agentDir);
|
|
334
|
+
const socketPath = absoluteSocketPath(inDirectorySocketPath(agentDir));
|
|
331
335
|
const shortPath = join(privateSocketDirectory(), `${agentDirDigest(agentDir)}.sock`);
|
|
332
336
|
if (!fitsUnixSocketPath(shortPath, platform)) {
|
|
333
337
|
throw new Error(
|
|
@@ -344,7 +348,7 @@ export async function chooseBrokerSocketPathAsync(
|
|
|
344
348
|
const direct = directBrokerSocketPath(platform, agentDir);
|
|
345
349
|
if (direct !== undefined) return direct;
|
|
346
350
|
|
|
347
|
-
const socketPath = inDirectorySocketPath(agentDir);
|
|
351
|
+
const socketPath = absoluteSocketPath(inDirectorySocketPath(agentDir));
|
|
348
352
|
const shortPath = join(await privateSocketDirectoryAsync(), `${agentDirDigest(agentDir)}.sock`);
|
|
349
353
|
if (!fitsUnixSocketPath(shortPath, platform)) {
|
|
350
354
|
throw new Error(
|