@bastani/atomic 0.10.11-alpha.2 → 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 +99 -0
- package/README.md +5 -8
- package/dist/_shared/dist-KOELCESV.js +2 -2
- package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
- package/dist/_shared/lib-4PES5P4V.js +2 -2
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +6 -6
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +5 -5
- package/dist/_shared/mode-shared-2QJSCUM6.js +6 -6
- package/dist/_shared/p0-cli-BB45ZQY6.js +46 -67
- package/dist/_shared/p0-cli-BB45ZQY6.js.map +1 -1
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +7 -8
- package/dist/_shared/p1a-prewarm-XIU57JHF.js.map +1 -1
- package/dist/_shared/{p1b-elig-ENCUPKKJ.js → p1b-elig-TVB5CBLL.js} +14 -2
- package/dist/_shared/{p1b-elig-ENCUPKKJ.js.map → p1b-elig-TVB5CBLL.js.map} +1 -1
- package/dist/_shared/runtime-O4KCSG4C.js +3 -3
- package/dist/_shared/{sdk-IQMULKFU.js → sdk-B5LEWGGI.js} +340 -163
- package/dist/_shared/sdk-B5LEWGGI.js.map +1 -0
- package/dist/_shared/session-data-AHTU7IS6.js +2 -2
- package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
- package/dist/_shared/{startup-0-0-3IXNMFM2.js → startup-0-0-EZUKEP4Q.js} +48 -40
- package/dist/_shared/startup-0-0-EZUKEP4Q.js.map +1 -0
- package/dist/_shared/{startup-0-1-7T2IAE7J.js → startup-0-1-RTOHJFDJ.js} +195 -42
- package/dist/_shared/startup-0-1-RTOHJFDJ.js.map +1 -0
- package/dist/_shared/startup-0-2-5QHPCEON.js +33 -43
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -1
- package/dist/_shared/startup-0-3-4ZYBYQNM.js +5 -5
- package/dist/_shared/startup-0-4-ZMJV547D.js +12 -7
- package/dist/_shared/startup-0-4-ZMJV547D.js.map +1 -1
- package/dist/_shared/startup-0-5-YDW47QX6.js +7 -7
- package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -1
- package/dist/_shared/startup-10-0-TDQNBDDL.js +6 -6
- package/dist/_shared/startup-12-0-55AAXBJZ.js +2 -2
- package/dist/_shared/startup-14-0-MLX36RBG.js +4 -5
- package/dist/_shared/startup-14-0-MLX36RBG.js.map +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +4 -4
- package/dist/_shared/startup-15-1-4S7FLMNG.js +19 -27
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +39 -23
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/{startup-8-1-X32CYSXB.js → startup-8-1-LZFXSD3Z.js} +90 -1176
- package/dist/_shared/startup-8-1-LZFXSD3Z.js.map +1 -0
- package/dist/_shared/storage-command-7MGXLJGZ.js +186 -35
- package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
- package/dist/_shared/storage-status-K7PX2RXA.js +557 -0
- package/dist/_shared/storage-status-K7PX2RXA.js.map +1 -0
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/team-DOQKICG2.js +376 -0
- package/dist/_shared/team-DOQKICG2.js.map +1 -0
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +23 -0
- package/dist/builtin/intercom/README.md +2 -2
- package/dist/builtin/intercom/broker/broker.bundle.mjs +913 -289
- 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 +170 -74
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +298 -47
- 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 +136 -19
- 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/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 +4 -4
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +3 -3
- package/dist/cli/blueprint-command.impl.js +3 -3
- package/dist/cli/blueprint-command.js +3 -3
- package/dist/cli/intercom-command.code.js +3 -3
- package/dist/cli/intercom-command.code.js.map +1 -1
- package/dist/cli/intercom-command.impl.js +3 -3
- package/dist/cli/intercom-command.js +3 -3
- package/dist/cli/list-models.code.js +2 -2
- package/dist/cli/list-models.impl.js +3 -3
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/session-picker.code.js +1 -1
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +1 -1
- package/dist/cli/startup-ui.impl.js +3 -3
- package/dist/cli/startup-ui.js +3 -3
- package/dist/cli/storage-command.impl.js +3 -3
- package/dist/cli/storage-command.js +3 -3
- package/dist/cli/storage-search-session.code.js +3 -3
- package/dist/cli/storage-search-session.impl.js +3 -3
- package/dist/cli/storage-search-session.js +3 -3
- package/dist/cli/team-command.code.js +19 -113
- package/dist/cli/team-command.code.js.map +1 -1
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +5 -18
- package/dist/cli.js.map +1 -1
- package/dist/core/agent-rehydrate-errors.d.ts +4 -9
- package/dist/core/compaction/compactor.d.ts +3 -3
- package/dist/core/debug.code.js +1 -1
- package/dist/core/debug.impl.js +3 -3
- package/dist/core/debug.js +3 -3
- package/dist/core/export-html/card-projection.impl.js +3 -3
- package/dist/core/export-html/card-projection.js +3 -3
- package/dist/core/export-html/index.code.js +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.impl.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.js +3 -3
- package/dist/core/export-html/tool-renderer.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/extensions/jiti-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-loader.js +3 -3
- package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-static-loader.js +3 -3
- package/dist/core/extensions/loader-host-modules.code.js +1 -1
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/extensions/loader-virtual-modules.js +1 -1
- package/dist/core/extensions/runner-context.js +2 -2
- package/dist/core/intercom-broker-control-host.code.js +2 -2
- package/dist/core/intercom-broker-control-host.impl.js +3 -3
- package/dist/core/intercom-broker-control-host.js +3 -3
- package/dist/core/intercom-broker-control.code.js +3 -3
- package/dist/core/intercom-broker-control.impl.js +3 -3
- package/dist/core/intercom-broker-control.js +3 -3
- package/dist/core/package-manager-storage-adapters.code.js +1 -1
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/process-start-token.d.ts +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 +3 -3
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +5 -5
- package/dist/core/session-manager-list.impl.js +3 -3
- package/dist/core/session-manager-list.js +3 -3
- package/dist/core/session-manager.code.js +1 -1
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-storage.code.js +1 -1
- package/dist/core/session-storage.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/settings-schema.d.ts +0 -3
- package/dist/core/storage/added-exports-0-10-11.js +19 -0
- package/dist/core/storage/added-exports-0-10-11.js.map +1 -0
- package/dist/core/storage/creation-time.js +105 -0
- package/dist/core/storage/creation-time.js.map +1 -0
- package/dist/core/storage/database.d.ts +19 -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 +3 -2
- package/dist/core/storage/index.js +5 -3
- package/dist/core/storage/index.js.map +1 -1
- package/dist/core/storage/libsql-removed.d.ts +71 -0
- package/dist/core/storage/libsql-removed.js +123 -0
- package/dist/core/storage/libsql-removed.js.map +1 -0
- package/dist/core/storage/migrations.d.ts +78 -14
- package/dist/core/storage/migrations.js +375 -49
- package/dist/core/storage/migrations.js.map +1 -1
- package/dist/core/storage/node-sqlite-file-gate.js +0 -15
- package/dist/core/storage/node-sqlite-file-gate.js.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +8 -13
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.js +51 -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 +9 -2
- package/dist/core/storage/prefix.js.map +1 -1
- package/dist/core/storage/process-selection.d.ts +5 -5
- package/dist/core/storage/provider.js +2 -2
- package/dist/core/storage/schema-catalog.d.ts +7 -8
- package/dist/core/storage/schema-catalog.js +8 -8
- package/dist/core/storage/schema-catalog.js.map +1 -1
- package/dist/core/storage/selection.d.ts +7 -82
- package/dist/core/storage/selection.js +20 -235
- package/dist/core/storage/selection.js.map +1 -1
- package/dist/core/storage/session/branch-fork-source.code.js +2 -2
- package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
- package/dist/core/storage/session/branch-fork-source.js +3 -3
- package/dist/core/storage/session/card-view.impl.js +3 -3
- package/dist/core/storage/session/card-view.js +3 -3
- package/dist/core/storage/session/child-reader.code.js +3 -3
- package/dist/core/storage/session/child-reader.impl.js +3 -3
- package/dist/core/storage/session/child-reader.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.js +3 -3
- package/dist/core/storage/session/expanded-child-details.code.js +2 -2
- package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
- package/dist/core/storage/session/expanded-child-details.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.js +3 -3
- package/dist/core/storage/session/fork-row-index.impl.js +3 -3
- package/dist/core/storage/session/fork-row-index.js +3 -3
- package/dist/core/storage/session/fork-staging.code.js +4 -7
- package/dist/core/storage/session/fork-staging.code.js.map +1 -1
- package/dist/core/storage/session/fork-staging.impl.js +3 -3
- package/dist/core/storage/session/fork-staging.js +3 -3
- package/dist/core/storage/session/fork-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.d.ts +5 -1
- package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.js +3 -3
- package/dist/core/storage/session/memory-session-store.impl.js +3 -3
- package/dist/core/storage/session/memory-session-store.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.js +3 -3
- package/dist/core/storage/session/released-history-files.code.js +3 -3
- package/dist/core/storage/session/released-history-files.impl.js +3 -3
- package/dist/core/storage/session/released-history-files.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.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 +3 -3
- package/dist/core/storage/session/snapshot-history.impl.js +3 -3
- package/dist/core/storage/session/snapshot-history.js +3 -3
- package/dist/core/storage/session/sql-session-store.code.js +1 -1
- package/dist/core/storage/session/sql-session-store.d.ts +48 -11
- package/dist/core/storage/session/sql-session-store.impl.js +3 -3
- package/dist/core/storage/session/sql-session-store.js +3 -3
- package/dist/core/storage/session/tree-outline.impl.js +3 -3
- package/dist/core/storage/session/tree-outline.js +3 -3
- package/dist/core/storage/session/tree-presentation.impl.js +3 -3
- package/dist/core/storage/session/tree-presentation.js +3 -3
- package/dist/core/storage/sqlite-facade.d.ts +6 -1
- package/dist/core/storage/sqlite-facade.js +1 -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 +3 -3
- package/dist/core/tasks/task-file-history.impl.js +3 -3
- package/dist/core/tasks/task-file-history.js +3 -3
- package/dist/core/tasks/task-reference-archive.code.js +4 -4
- package/dist/core/tasks/task-reference-archive.js +3 -3
- package/dist/core/tasks/task-reference-identity.js +3 -3
- package/dist/core/tasks/task-reference-stream.impl.js +3 -3
- package/dist/core/tasks/task-reference-stream.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.js +3 -3
- package/dist/core/tasks/task-view-source.code.js +1 -1
- package/dist/core/tasks/task-view-source.impl.js +3 -3
- package/dist/core/tasks/task-view-source.js +3 -3
- package/dist/core/tools/history-tasks.d.ts +3 -2
- package/dist/core/tools/read-url.code.js +4 -4
- package/dist/core/tools/read-url.impl.js +3 -3
- package/dist/core/tools/read-url.js +3 -3
- package/dist/core/worktree-snapshot/blob-store.d.ts +40 -3
- package/dist/core/worktree-snapshot/blob-store.js +414 -21
- package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
- package/dist/core/worktree-snapshot/errors.code.js +2 -2
- package/dist/core/worktree-snapshot/errors.impl.js +3 -3
- package/dist/core/worktree-snapshot/errors.js +3 -3
- package/dist/core/worktree-snapshot/fork-blob-guard.js +81 -0
- package/dist/core/worktree-snapshot/fork-blob-guard.js.map +1 -0
- package/dist/core/worktree-snapshot/fork-snapshot-index.js +79 -38
- package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -1
- package/dist/core/worktree-snapshot/session-index-reset.code.js +4 -0
- package/dist/core/worktree-snapshot/session-index-reset.code.js.map +1 -1
- package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
- package/dist/extensions/codemode/execute.code.js +1 -1
- package/dist/extensions/codemode/execute.impl.js +3 -3
- package/dist/extensions/codemode/execute.js +3 -3
- package/dist/extensions/codemode/renderer.code.js +2 -2
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +3 -3
- package/dist/extensions/mcp/cli.impl.js +3 -3
- package/dist/extensions/mcp/cli.js +3 -3
- package/dist/extensions/mcp/cli.lazy.code.js +2 -2
- package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
- package/dist/extensions/mcp/cli.lazy.js +3 -3
- package/dist/extensions/mcp/runtime.code.js +1 -1
- package/dist/extensions/mcp/runtime.impl.js +3 -3
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -5
- package/dist/main-first-time-setup.code.js +1 -1
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/main.js +1 -1
- package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
- package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
- package/dist/modes/interactive/startup-shell-eligibility.js +1 -1
- package/dist/modes/interactive-engine/engine-prewarm.d.ts +1 -1
- package/dist/modes/print-mode.js +1 -1
- package/dist/package-manager-cli.code.js +6 -6
- package/dist/package-manager-cli.impl.js +3 -3
- package/dist/package-manager-cli.js +3 -3
- package/dist/rpc-entry.js +1 -1
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/10.js +1 -1
- package/dist/startup-stages/11.js +1 -1
- package/dist/startup-stages/12.js +1 -1
- package/dist/startup-stages/2.js +2 -4
- package/dist/startup-stages/3.js +1 -3
- package/dist/startup-stages/4.js +1 -2
- package/dist/startup-stages/5.js +1 -1
- package/dist/startup-stages/6.js +5 -7
- package/dist/startup-stages/7.js +3 -10
- package/dist/startup-stages/8.js +7 -2
- package/dist/startup-stages/9.js +1 -7
- package/dist/startup-stages/stages.json +1 -1
- package/dist/utils/compile-cache-deferral.js +8 -13
- package/dist/utils/compile-cache-deferral.js.map +1 -1
- package/dist/utils/compile-cache-warmup-host.js +3 -4
- package/dist/utils/compile-cache-warmup-host.js.map +1 -1
- package/dist/utils/compile-cache.js +12 -100
- package/dist/utils/compile-cache.js.map +1 -1
- package/dist/utils/startup-database-spare.code.js +2 -2
- package/dist/utils/startup-database-spare.impl.js +3 -3
- package/dist/utils/startup-database-spare.js +3 -3
- package/dist/utils/tools-manager.code.js +1 -1
- package/dist/utils/tools-manager.impl.js +3 -3
- package/dist/utils/tools-manager.js +3 -3
- package/dist/utils/worker-threads.js +2 -15
- package/dist/utils/worker-threads.js.map +1 -1
- package/docs/build.md +3 -3
- package/docs/changelog.mdx +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 +29 -49
- package/docs/settings.md +7 -8
- package/docs/storage/custom-adapters.md +255 -0
- package/docs/storage/jsonl.md +117 -0
- package/docs/{guides/postgres-pgbouncer.md → storage/postgres/pgbouncer.md} +66 -68
- package/docs/storage/postgres/tuning.md +337 -0
- package/docs/storage/postgres.md +556 -0
- package/docs/storage/sqlite.md +99 -0
- package/docs/storage.md +326 -990
- package/docs/subagents/authoring.md +1 -1
- package/docs/subagents.md +2 -2
- package/docs/tools.md +1 -1
- package/docs/worktree-snapshots.md +2 -2
- package/package.json +9 -9
- package/schemas/models.schema.json +2 -2
- package/schemas/settings.schema.json +0 -14
- package/dist/_shared/sdk-IQMULKFU.js.map +0 -1
- package/dist/_shared/startup-0-0-3IXNMFM2.js.map +0 -1
- package/dist/_shared/startup-0-1-7T2IAE7J.js.map +0 -1
- package/dist/_shared/startup-8-1-X32CYSXB.js.map +0 -1
- package/dist/core/intercom-broker-control.d.ts +0 -129
- package/dist/startup-stages/13.js +0 -1
- package/docs/guides/postgres-tuning.md +0 -311
- package/docs/libraries/storage-libsql.md +0 -97
|
@@ -46,6 +46,9 @@ import {
|
|
|
46
46
|
type LeaseRenewalRequest,
|
|
47
47
|
type LeaseRenewResult,
|
|
48
48
|
type LeaseState,
|
|
49
|
+
MAINTENANCE_INTERVAL_MS,
|
|
50
|
+
MAINTENANCE_STALE_AFTER_MS,
|
|
51
|
+
type MaintenanceSubject,
|
|
49
52
|
OUTBOX_BACKUP_POLL_INTERVAL_MS,
|
|
50
53
|
OUTBOX_CLAIM_STALE_AFTER_MS,
|
|
51
54
|
type OutboxClaim,
|
|
@@ -150,6 +153,9 @@ const ROUTE_HOLDER_DOWN_WINDOW_MS = 10 * 60_000;
|
|
|
150
153
|
const BROKER_UNRESPONSIVE_AFTER_MS = (3 * BROKER_LEASE_RENEW_INTERVAL_MS) / 2;
|
|
151
154
|
export const SHARED_STORAGE_UNAVAILABLE_REASON =
|
|
152
155
|
"Session not found on this node, and Intercom could not reach the shared storage database to look for it on other nodes. Try again once the database is available.";
|
|
156
|
+
/** #6637: a send that would overtake its sender's earlier messages to the session, still undelivered at the save cap. */
|
|
157
|
+
export const EARLIER_SENDS_UNDELIVERED_REASON =
|
|
158
|
+
"Your earlier messages to this session are still waiting in the shared storage database, and this one may not overtake them. Try again once the database is available.";
|
|
153
159
|
const MAX_HELD_SENDS = 256;
|
|
154
160
|
/**
|
|
155
161
|
* #3983: how long the decision to keep a sender waiting may take before the sender is told to keep waiting while it
|
|
@@ -563,6 +569,11 @@ interface Waiter {
|
|
|
563
569
|
* wait as uncertain (#4443).
|
|
564
570
|
*/
|
|
565
571
|
missedSavingReport?: boolean;
|
|
572
|
+
/**
|
|
573
|
+
* #6637: its send was answered and its routing is over, so a later local send to its recipient goes after it
|
|
574
|
+
* (`waitForEarlierOutboxSends`); one still routing is ordered by the send-order gate, within its bounds.
|
|
575
|
+
*/
|
|
576
|
+
routed?: true;
|
|
566
577
|
}
|
|
567
578
|
|
|
568
579
|
interface SendProgress {
|
|
@@ -1085,6 +1096,8 @@ export class MultiNodeRouter {
|
|
|
1085
1096
|
private readonly processStartedAt: (pid: number) => number | null | undefined | Promise<number | null | undefined>;
|
|
1086
1097
|
private readonly lostBounds: LostRecipientBounds;
|
|
1087
1098
|
private membership: Lease | undefined;
|
|
1099
|
+
/** The maintenance lease while this broker is the swarm's maintainer (`maintain`). */
|
|
1100
|
+
private maintenance: Lease | undefined;
|
|
1088
1101
|
private subscription: WakeUpSubscription | undefined;
|
|
1089
1102
|
private readonly presence = new Map<BrokerConnectedSession, PresenceEntry>();
|
|
1090
1103
|
private readonly inflight = new Map<string, Inflight>();
|
|
@@ -1114,6 +1127,8 @@ export class MultiNodeRouter {
|
|
|
1114
1127
|
private readonly initialScans = new Map<string, { readonly promise: Promise<void>; readonly resolve: () => void }>();
|
|
1115
1128
|
/** Refcount of unsettled outbox waiters per `(senderKey, targetIdentity)` pair, maintained by `setWaiter`/`dropWaiter`. */
|
|
1116
1129
|
private readonly unsettledOutboxPairs = new Map<string, number>();
|
|
1130
|
+
/** #6637: local sends waiting for their sender's earlier outbox sends to their recipient (`waitForEarlierOutboxSends`). */
|
|
1131
|
+
private readonly outboxSendWatchers = new Set<() => void>();
|
|
1117
1132
|
private readonly sendOrder = new SendOrderGate();
|
|
1118
1133
|
private activeLocalCommit:
|
|
1119
1134
|
| { readonly clientMessage: SendClientMessage; reentrant?: RemoteSendRequest }
|
|
@@ -1307,6 +1322,7 @@ export class MultiNodeRouter {
|
|
|
1307
1322
|
if (subscribed.status === "subscribed") router.subscription = subscribed.subscription;
|
|
1308
1323
|
router.every(BROKER_LEASE_RENEW_INTERVAL_MS, () => router.renew());
|
|
1309
1324
|
router.every(OUTBOX_BACKUP_POLL_INTERVAL_MS, () => router.backupPoll());
|
|
1325
|
+
router.every(MAINTENANCE_INTERVAL_MS, () => router.maintain());
|
|
1310
1326
|
// #4992: what a broker that stopped mid-departure left is finished now, and at every backup poll.
|
|
1311
1327
|
// #5154: and the asks to recipients lost long enough.
|
|
1312
1328
|
void router
|
|
@@ -2873,7 +2889,12 @@ export class MultiNodeRouter {
|
|
|
2873
2889
|
});
|
|
2874
2890
|
if (enqueued.status === "invalid" || enqueued.status === "full") continue;
|
|
2875
2891
|
if (enqueued.status === "inserted" && owner.hostBrokerId !== undefined) {
|
|
2876
|
-
await this.bus.publish({
|
|
2892
|
+
await this.bus.publish({
|
|
2893
|
+
brokerId: owner.hostBrokerId,
|
|
2894
|
+
reason: "outbox",
|
|
2895
|
+
version: enqueued.row.sequence,
|
|
2896
|
+
targetIdentity: owner.identity,
|
|
2897
|
+
});
|
|
2877
2898
|
}
|
|
2878
2899
|
await this.state.releasedAsks.claim({
|
|
2879
2900
|
questionId: ask.questionId,
|
|
@@ -2991,7 +3012,12 @@ export class MultiNodeRouter {
|
|
|
2991
3012
|
});
|
|
2992
3013
|
}
|
|
2993
3014
|
if (enqueued.status === "inserted" && hosted !== undefined) {
|
|
2994
|
-
await this.bus.publish({
|
|
3015
|
+
await this.bus.publish({
|
|
3016
|
+
brokerId: hosted.holderId,
|
|
3017
|
+
reason: "outbox",
|
|
3018
|
+
version: enqueued.row.sequence,
|
|
3019
|
+
targetIdentity: asker.targetIdentity,
|
|
3020
|
+
});
|
|
2995
3021
|
}
|
|
2996
3022
|
}
|
|
2997
3023
|
}
|
|
@@ -3027,6 +3053,7 @@ export class MultiNodeRouter {
|
|
|
3027
3053
|
for (const [release, owner] of [...this.activeOpenings]) {
|
|
3028
3054
|
if (owner === session) release();
|
|
3029
3055
|
}
|
|
3056
|
+
this.outboxSendsChanged();
|
|
3030
3057
|
for (const waiter of [...this.waiters.values()]) {
|
|
3031
3058
|
// #4642: a hosted session shares its host's socket; only its own sends end with it.
|
|
3032
3059
|
const sentBySession =
|
|
@@ -3719,7 +3746,11 @@ export class MultiNodeRouter {
|
|
|
3719
3746
|
} finally {
|
|
3720
3747
|
const progress = this.sendProgress.get(request.clientMessage);
|
|
3721
3748
|
if (progress !== undefined) this.stopProgress(progress);
|
|
3722
|
-
if (ownsTicket)
|
|
3749
|
+
if (ownsTicket) {
|
|
3750
|
+
this.sendOrder.finish(ticket);
|
|
3751
|
+
const waiter = this.waiters.get(request.message.id);
|
|
3752
|
+
if (waiter !== undefined) waiter.routed = true;
|
|
3753
|
+
}
|
|
3723
3754
|
}
|
|
3724
3755
|
}
|
|
3725
3756
|
|
|
@@ -4013,21 +4044,79 @@ export class MultiNodeRouter {
|
|
|
4013
4044
|
}
|
|
4014
4045
|
|
|
4015
4046
|
/**
|
|
4016
|
-
*
|
|
4017
|
-
*
|
|
4018
|
-
*
|
|
4047
|
+
* #6637: a send to a session here goes after its sender's earlier sends to that session still in the shared outbox
|
|
4048
|
+
* (sent while it was offline or on another broker, and answered): it waits until this broker has written each of them
|
|
4049
|
+
* to the session, or each settled otherwise. A wait bounded by the local lookup's bound let it overtake them whenever the
|
|
4050
|
+
* session's registration and first claim took longer, as on a far-away database, or the claim found the rows still
|
|
4051
|
+
* held by the broker the session left. Only a sender with an unsettled outbox send to the session ever waits. The
|
|
4052
|
+
* sender is held meanwhile, and refused as retryable at the save cap. True to take the local path; false when the
|
|
4053
|
+
* send was answered or the router closed.
|
|
4019
4054
|
*/
|
|
4020
|
-
private async
|
|
4055
|
+
private async waitForEarlierOutboxSends(
|
|
4056
|
+
request: RemoteSendRequest,
|
|
4021
4057
|
senderKey: string,
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4058
|
+
target: BrokerConnectedSession,
|
|
4059
|
+
): Promise<boolean> {
|
|
4060
|
+
const identity = deliveryTargetIdentity(target);
|
|
4061
|
+
const pair = outboxPairKey(senderKey, identity);
|
|
4062
|
+
if (!this.unsettledOutboxPairs.has(pair)) return true;
|
|
4063
|
+
const earlier = new Set<string>();
|
|
4064
|
+
for (const waiter of this.waiters.values())
|
|
4065
|
+
if (
|
|
4066
|
+
waiter.routed === true &&
|
|
4067
|
+
waiter.messageId !== request.message.id &&
|
|
4068
|
+
outboxPairKey(waiter.senderKey, waiter.targetIdentity) === pair
|
|
4069
|
+
)
|
|
4070
|
+
earlier.add(waiter.messageId);
|
|
4071
|
+
const written = (): boolean => {
|
|
4072
|
+
for (const messageId of earlier)
|
|
4073
|
+
if (!this.waiters.has(messageId) || this.inflight.get(messageId)?.session === target) earlier.delete(messageId);
|
|
4074
|
+
return earlier.size === 0;
|
|
4075
|
+
};
|
|
4076
|
+
if (written()) return true;
|
|
4077
|
+
// A registration's first scan is still to come; otherwise a scan that ended without them looks again now.
|
|
4078
|
+
if (!this.initialScans.has(identity)) void this.scanIdentity(identity);
|
|
4079
|
+
const progress = this.sendProgress.get(request.clientMessage);
|
|
4080
|
+
const startedAt = progress?.startedAt ?? performance.now();
|
|
4081
|
+
const deadline = { clientDeadlineAt: progress?.clientDeadlineAt ?? startedAt + SEND_RESPONSE_TIMEOUT_MS };
|
|
4082
|
+
const capAt = startedAt + RECIPIENT_SAVE_MAX_WAIT_MS;
|
|
4083
|
+
while (!this.closed && !written()) {
|
|
4084
|
+
// A session that left takes the local path's fallback, which routes the send through the outbox behind them.
|
|
4085
|
+
if (this.host.sessions.get(target.info.id) !== target) return true;
|
|
4086
|
+
const now = performance.now();
|
|
4087
|
+
if (now >= capAt) {
|
|
4088
|
+
this.fail(request, EARLIER_SENDS_UNDELIVERED_REASON);
|
|
4089
|
+
return false;
|
|
4090
|
+
}
|
|
4091
|
+
const guardAt = deadline.clientDeadlineAt - MIN_WAIT_CLIENT_MARGIN_MS;
|
|
4092
|
+
if (now >= guardAt) {
|
|
4093
|
+
this.sendHoldFrame(
|
|
4094
|
+
request.socket,
|
|
4095
|
+
request.message.id,
|
|
4096
|
+
request.attemptId,
|
|
4097
|
+
Math.min(RECIPIENT_RECEIPT_TIMEOUT_MS, capAt - now),
|
|
4098
|
+
deadline,
|
|
4099
|
+
);
|
|
4100
|
+
if (progress !== undefined) progress.clientDeadlineAt = deadline.clientDeadlineAt;
|
|
4101
|
+
continue;
|
|
4102
|
+
}
|
|
4103
|
+
await new Promise<void>((resolve) => {
|
|
4104
|
+
const wake = (): void => {
|
|
4105
|
+
clearTimeout(timer);
|
|
4106
|
+
this.outboxSendWatchers.delete(wake);
|
|
4107
|
+
resolve();
|
|
4108
|
+
};
|
|
4109
|
+
const timer = setTimeout(wake, Math.min(capAt, guardAt) - now);
|
|
4110
|
+
timer.unref?.();
|
|
4111
|
+
this.outboxSendWatchers.add(wake);
|
|
4112
|
+
});
|
|
4113
|
+
}
|
|
4114
|
+
return !this.closed;
|
|
4115
|
+
}
|
|
4116
|
+
|
|
4117
|
+
/** #6637: an outbox send was written to its recipient here or settled, or a recipient left: waits look again. */
|
|
4118
|
+
private outboxSendsChanged(): void {
|
|
4119
|
+
for (const wake of [...this.outboxSendWatchers]) wake();
|
|
4031
4120
|
}
|
|
4032
4121
|
|
|
4033
4122
|
/**
|
|
@@ -4884,7 +4973,6 @@ export class MultiNodeRouter {
|
|
|
4884
4973
|
ticket: SendOrderTicket,
|
|
4885
4974
|
openingDeadlineAt: number,
|
|
4886
4975
|
): Promise<void> {
|
|
4887
|
-
const targetIdentity = deliveryTargetIdentity(target);
|
|
4888
4976
|
const lookup = this.state.outbox.read(request.message.id);
|
|
4889
4977
|
// #5607: a lookup that fails while an owner check is still answering is reported when it is awaited below, not
|
|
4890
4978
|
// left unobserved meanwhile. The checks are waited for within the lookup's own bound, counted from now.
|
|
@@ -4934,7 +5022,7 @@ export class MultiNodeRouter {
|
|
|
4934
5022
|
sending = adopted;
|
|
4935
5023
|
}
|
|
4936
5024
|
await this.waitForEarlierLocal(ticket, target, expired, boundExpired);
|
|
4937
|
-
await this.
|
|
5025
|
+
if (!(await this.waitForEarlierOutboxSends(sending, ticket.senderKey, target))) return;
|
|
4938
5026
|
this.extendBeforeLocalReceiptWait(sending, target);
|
|
4939
5027
|
await this.commitLocalNotFound(sending, ticket, openingDeadlineAt);
|
|
4940
5028
|
return;
|
|
@@ -4977,7 +5065,7 @@ export class MultiNodeRouter {
|
|
|
4977
5065
|
sending = adopted;
|
|
4978
5066
|
}
|
|
4979
5067
|
await this.waitForEarlierLocal(ticket, target, expired, boundExpired);
|
|
4980
|
-
await this.
|
|
5068
|
+
if (!(await this.waitForEarlierOutboxSends(sending, ticket.senderKey, target))) return;
|
|
4981
5069
|
this.extendBeforeLocalReceiptWait(sending, target);
|
|
4982
5070
|
await this.commitLocalNotFound(sending, ticket, openingDeadlineAt);
|
|
4983
5071
|
} finally {
|
|
@@ -5444,7 +5532,12 @@ export class MultiNodeRouter {
|
|
|
5444
5532
|
this.holdSender(waiter, receiptWaitMs);
|
|
5445
5533
|
}
|
|
5446
5534
|
if (asksTarget) await this.writeQuestionTarget(request.socket, message.id, request.attemptId, target);
|
|
5447
|
-
await this.bus.publish({
|
|
5535
|
+
await this.bus.publish({
|
|
5536
|
+
brokerId: target.hostBrokerId!,
|
|
5537
|
+
reason: "outbox",
|
|
5538
|
+
version: row.sequence,
|
|
5539
|
+
targetIdentity: row.targetIdentity,
|
|
5540
|
+
});
|
|
5448
5541
|
// A clean quit recorded before this send's row was written is seen here; one recorded after it wakes this
|
|
5449
5542
|
// broker (`wakeWaitingOrigins`), so a send racing its recipient's quit is queued either way. The waiter's own
|
|
5450
5543
|
// receipt wait keeps running meanwhile, so slow reads here never hold the sender past it.
|
|
@@ -5842,6 +5935,7 @@ export class MultiNodeRouter {
|
|
|
5842
5935
|
// A recipient that never confirms saves is delivered once the frame is written, as locally.
|
|
5843
5936
|
if (session.acknowledgesReceipt !== true) this.settleDelivered(inflight, session, frame);
|
|
5844
5937
|
});
|
|
5938
|
+
this.outboxSendsChanged();
|
|
5845
5939
|
}
|
|
5846
5940
|
}
|
|
5847
5941
|
|
|
@@ -6195,6 +6289,7 @@ export class MultiNodeRouter {
|
|
|
6195
6289
|
const next = (this.unsettledOutboxPairs.get(pair) ?? 0) - 1;
|
|
6196
6290
|
if (next <= 0) this.unsettledOutboxPairs.delete(pair);
|
|
6197
6291
|
else this.unsettledOutboxPairs.set(pair, next);
|
|
6292
|
+
this.outboxSendsChanged();
|
|
6198
6293
|
}
|
|
6199
6294
|
if (waiter.timer !== undefined) clearTimeout(waiter.timer);
|
|
6200
6295
|
if (waiter.capTimer !== undefined) clearTimeout(waiter.capTimer);
|
|
@@ -6212,8 +6307,12 @@ export class MultiNodeRouter {
|
|
|
6212
6307
|
void this.guard(this.deliverWakeRequests());
|
|
6213
6308
|
return;
|
|
6214
6309
|
}
|
|
6215
|
-
if (event.hint.reason === "outbox")
|
|
6216
|
-
|
|
6310
|
+
if (event.hint.reason === "outbox") {
|
|
6311
|
+
// A hint that names its recipient concerns that recipient's queue alone; one from an earlier release names none.
|
|
6312
|
+
const target = event.hint.targetIdentity;
|
|
6313
|
+
if (target === undefined) this.scanAll();
|
|
6314
|
+
else if (this.localSessionFor(target) !== undefined) void this.scanIdentity(target);
|
|
6315
|
+
} else {
|
|
6217
6316
|
void this.checkOutcomes();
|
|
6218
6317
|
void this.guard(this.checkHolds());
|
|
6219
6318
|
void this.guard(this.deliverWakeRequests());
|
|
@@ -6229,6 +6328,7 @@ export class MultiNodeRouter {
|
|
|
6229
6328
|
instanceKey: this.instanceKey,
|
|
6230
6329
|
pid: this.pid,
|
|
6231
6330
|
...(this.home === undefined ? {} : { home: this.home }),
|
|
6331
|
+
ownWakeUpChannel: true,
|
|
6232
6332
|
};
|
|
6233
6333
|
}
|
|
6234
6334
|
|
|
@@ -6401,6 +6501,33 @@ export class MultiNodeRouter {
|
|
|
6401
6501
|
this.wakeWaitingChild(reservationKey).finally(() => this.pendingWakeChecks.delete(reservationKey)),
|
|
6402
6502
|
);
|
|
6403
6503
|
}
|
|
6504
|
+
}
|
|
6505
|
+
|
|
6506
|
+
/**
|
|
6507
|
+
* The shared state's maintenance: the rows past their retention deleted, and outbox rows left queued past the
|
|
6508
|
+
* known-session retention expired. One broker of the swarm runs it each `MAINTENANCE_INTERVAL_MS`, the one holding
|
|
6509
|
+
* the maintenance lease, as Oban's pruner runs on its leader and River's on its maintenance leader: when every broker
|
|
6510
|
+
* ran it at every backup poll, a swarm of brokers sent the same deletes over and over. A broker that is not the
|
|
6511
|
+
* maintainer reads the lease and goes on while another holds it live; the maintainer takes it again, which renews
|
|
6512
|
+
* it, and so stays the maintainer while it runs. Once it stops, its lease goes stale after
|
|
6513
|
+
* `MAINTENANCE_STALE_AFTER_MS` (or is free at once, when it closed) and the next broker to check takes it over.
|
|
6514
|
+
* Nothing here is needed for delivery: a broker's own scans and the sweeps for a stopped broker's recipients stay in
|
|
6515
|
+
* `backupPoll`, on every broker.
|
|
6516
|
+
*/
|
|
6517
|
+
private async maintain(): Promise<void> {
|
|
6518
|
+
const { leases } = this.state;
|
|
6519
|
+
if (this.maintenance === undefined) {
|
|
6520
|
+
const found = await leases.read({ kind: "maintenance", task: RETENTION_MAINTENANCE.task });
|
|
6521
|
+
if (
|
|
6522
|
+
found.status === "found" &&
|
|
6523
|
+
found.lease.holderId !== this.brokerId &&
|
|
6524
|
+
found.lease.ageMs <= MAINTENANCE_STALE_AFTER_MS
|
|
6525
|
+
)
|
|
6526
|
+
return;
|
|
6527
|
+
}
|
|
6528
|
+
const acquired = await leases.acquire(RETENTION_MAINTENANCE, this.brokerId, MAINTENANCE_STALE_AFTER_MS);
|
|
6529
|
+
this.maintenance = acquired.status === "acquired" ? acquired.lease : undefined;
|
|
6530
|
+
if (this.maintenance === undefined || this.closed) return;
|
|
6404
6531
|
await this.state.outbox.prune(DELIVERED_MESSAGE_TTL_MS, KNOWN_SESSION_RETENTION_MS);
|
|
6405
6532
|
await this.state.sentMessages.prune(DELIVERED_MESSAGE_TTL_MS);
|
|
6406
6533
|
await this.state.reservations.prune(DELIVERED_MESSAGE_TTL_MS);
|
|
@@ -6550,6 +6677,8 @@ export class MultiNodeRouter {
|
|
|
6550
6677
|
// #5607: its sessions' ids are free for them to take again on another broker, as their presences are.
|
|
6551
6678
|
await this.state.knownSessions.owners?.retireBroker(this.brokerId);
|
|
6552
6679
|
if (this.membership !== undefined) await this.state.leases.release(this.membership);
|
|
6680
|
+
// Free for the next broker to check, rather than once it went stale.
|
|
6681
|
+
if (this.maintenance !== undefined) await this.state.leases.release(this.maintenance);
|
|
6553
6682
|
} catch (error) {
|
|
6554
6683
|
this.report(error);
|
|
6555
6684
|
}
|
|
@@ -6561,6 +6690,9 @@ export class MultiNodeRouter {
|
|
|
6561
6690
|
}
|
|
6562
6691
|
}
|
|
6563
6692
|
|
|
6693
|
+
/** The maintenance lease of the shared state's retention (`maintain`). */
|
|
6694
|
+
const RETENTION_MAINTENANCE: MaintenanceSubject = { kind: "maintenance", task: "retention" };
|
|
6695
|
+
|
|
6564
6696
|
/** A target identity a return path can bind: a registration's return address, never a reusable bare session id. */
|
|
6565
6697
|
function stableIdentity(targetIdentity: string): string | undefined {
|
|
6566
6698
|
return targetIdentity.startsWith('["return",') ? targetIdentity : undefined;
|
|
@@ -26,6 +26,17 @@ export const BROKER_LEASE_STALE_AFTER_MS = 30_000;
|
|
|
26
26
|
export const OUTBOX_CLAIM_STALE_AFTER_MS = 30_000;
|
|
27
27
|
/** Safety-net outbox scan interval for brokers whose wake-ups were lost. */
|
|
28
28
|
export const OUTBOX_BACKUP_POLL_INTERVAL_MS = 30_000;
|
|
29
|
+
/**
|
|
30
|
+
* How often the swarm's maintainer, one broker holding the maintenance lease, prunes the shared state past its retention
|
|
31
|
+
* and expires the outbox rows left queued too long; each other broker checks this often whether the lease went stale.
|
|
32
|
+
* Like Oban's leader-only pruner and River's maintenance leader, one broker does it, not every broker every backup poll.
|
|
33
|
+
*/
|
|
34
|
+
export const MAINTENANCE_INTERVAL_MS = 5 * 60_000;
|
|
35
|
+
/**
|
|
36
|
+
* Age after which another broker takes the maintenance lease over: the maintainer renews it by taking it again each
|
|
37
|
+
* `MAINTENANCE_INTERVAL_MS`, so it goes stale only once the maintainer stopped.
|
|
38
|
+
*/
|
|
39
|
+
export const MAINTENANCE_STALE_AFTER_MS = 2 * MAINTENANCE_INTERVAL_MS;
|
|
29
40
|
/** How long a session that left stays known, so a send to it is queued for its return (spec §14, S5 amendment). */
|
|
30
41
|
export const KNOWN_SESSION_RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
31
42
|
/**
|
|
@@ -68,6 +79,7 @@ export type StateStoreInvalidReason =
|
|
|
68
79
|
| "empty-child-name"
|
|
69
80
|
| "empty-target"
|
|
70
81
|
| "empty-group"
|
|
82
|
+
| "empty-task"
|
|
71
83
|
| "subject-key-mismatch";
|
|
72
84
|
|
|
73
85
|
export interface InvalidStateInput {
|
|
@@ -75,7 +87,7 @@ export interface InvalidStateInput {
|
|
|
75
87
|
readonly reason: StateStoreInvalidReason;
|
|
76
88
|
}
|
|
77
89
|
|
|
78
|
-
export type LeaseKind = "broker" | "presence";
|
|
90
|
+
export type LeaseKind = "broker" | "presence" | "maintenance";
|
|
79
91
|
|
|
80
92
|
/** Broker membership: one row per running broker process, keyed by its random `brokerId`. */
|
|
81
93
|
export interface BrokerMembershipSubject {
|
|
@@ -96,6 +108,11 @@ export interface BrokerMembershipSubject {
|
|
|
96
108
|
readonly instanceKey?: string;
|
|
97
109
|
/** #5038: the broker's process id, checked on its host before a later instance supersedes it. */
|
|
98
110
|
readonly pid?: number;
|
|
111
|
+
/**
|
|
112
|
+
* The broker listens for wake-up notifications on a channel of its own (`brokerWakeUpChannel`), so a sender need not
|
|
113
|
+
* notify the channel every broker of an earlier release listens on. Absent from older brokers.
|
|
114
|
+
*/
|
|
115
|
+
readonly ownWakeUpChannel?: true;
|
|
99
116
|
}
|
|
100
117
|
|
|
101
118
|
/** Recipient presence: which broker currently hosts the recipient's socket. */
|
|
@@ -117,11 +134,21 @@ export interface PresenceAlias {
|
|
|
117
134
|
readonly owner: string;
|
|
118
135
|
}
|
|
119
136
|
|
|
120
|
-
|
|
137
|
+
/**
|
|
138
|
+
* The swarm's maintainer: the broker that runs one kind of shared maintenance, `task`, such as `"retention"`. Older
|
|
139
|
+
* brokers never read this kind, and keep their own maintenance.
|
|
140
|
+
*/
|
|
141
|
+
export interface MaintenanceSubject {
|
|
142
|
+
readonly kind: "maintenance";
|
|
143
|
+
readonly task: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type LeaseSubject = BrokerMembershipSubject | RecipientPresenceSubject | MaintenanceSubject;
|
|
121
147
|
|
|
122
148
|
export type LeaseKey =
|
|
123
149
|
| { readonly kind: "broker"; readonly brokerId: string }
|
|
124
|
-
| { readonly kind: "presence"; readonly targetIdentity: string }
|
|
150
|
+
| { readonly kind: "presence"; readonly targetIdentity: string }
|
|
151
|
+
| { readonly kind: "maintenance"; readonly task: string };
|
|
125
152
|
|
|
126
153
|
export interface Lease {
|
|
127
154
|
readonly key: LeaseKey;
|
|
@@ -24,6 +24,7 @@ import { openSqlBrokerLeaseStore } from "./sql-lease-store.js";
|
|
|
24
24
|
import { openSqlOutboxStore, recipientTransaction, runLast, withoutFailedWake } from "./sql-outbox-store.js";
|
|
25
25
|
import { openSqlPendingAskStore } from "./sql-pending-ask-store.js";
|
|
26
26
|
import { openSqlReleasedAskStore } from "./sql-released-ask-store.js";
|
|
27
|
+
import { ensureRetentionIndexes } from "./sql-retention.js";
|
|
27
28
|
import { openSqlRestoringReservationStore } from "./sql-restoring-reservation-store.js";
|
|
28
29
|
import { withBrokerSchemaCatalog } from "./sql-schema.js";
|
|
29
30
|
import { openSqlSentMessageAuthority } from "./sql-sent-message-authority.js";
|
|
@@ -162,6 +163,7 @@ export async function openIntercomBrokerState(
|
|
|
162
163
|
const releasedAsks = await openSqlReleasedAskStore(options);
|
|
163
164
|
const sentMessages = await openSqlSentMessageAuthority(options);
|
|
164
165
|
const knownSessions = await openSqlKnownSessionStore(options);
|
|
166
|
+
await ensureRetentionIndexes(database, options.prefix);
|
|
165
167
|
const bus = await openDatabaseWakeUpBus({
|
|
166
168
|
openDatabase: async () => borrowed,
|
|
167
169
|
prefix: source.prefix,
|
|
@@ -187,6 +189,18 @@ export async function openIntercomBrokerState(
|
|
|
187
189
|
reserveAndEnqueue(reservation, request) {
|
|
188
190
|
// The recipient's domain: sends to it run one at a time, and sends to others beside them (#6560).
|
|
189
191
|
const send = recipientTransaction(database, source.prefix, request.targetIdentity);
|
|
192
|
+
// PostgreSQL: one round trip, decided by the database, so the recipient's domain is held for no round trip
|
|
193
|
+
// and sends to a busy recipient do not queue for its lock past the lock timeout.
|
|
194
|
+
// A send to a recipient its sender found offline too, whose wake-up hint the same round trip writes.
|
|
195
|
+
const reserved = sentMessages.reservationOf(reservation);
|
|
196
|
+
const enqueueAtOnce = outbox.enqueueAtOnce;
|
|
197
|
+
if (reserved !== undefined && enqueueAtOnce !== undefined) {
|
|
198
|
+
const first = enqueueAtOnce(request, reserved);
|
|
199
|
+
if (first !== undefined)
|
|
200
|
+
return withoutFailedWake(request, (attempt) =>
|
|
201
|
+
attempt === request ? first : enqueueAtOnce(attempt, reserved)!,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
190
204
|
// The reservation's read and the enqueue's go out with the transaction's start, the reservation's write
|
|
191
205
|
// and the row's insert together, then the commit, on a pipelined connection: three round trips (#6560).
|
|
192
206
|
const leading = (attempt: typeof request) => [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dialectOf, type SqliteDatabase } from "@bastani/atomic/storage";
|
|
2
|
-
import { catalogHasColumns } from "./sql-schema.js";
|
|
2
|
+
import { catalogHasColumns, foundInCatalogAgain, RETRY_UNAPPLIED, setUpBrokerSchemaOnce } from "./sql-schema.js";
|
|
3
3
|
|
|
4
4
|
function isLineTerminatorCode(code: number): boolean {
|
|
5
5
|
return code === 0x0a || code === 0x0d || code === 0x2028 || code === 0x2029;
|
|
@@ -114,8 +114,9 @@ export async function addOptionalColumn(
|
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
116
|
* Adds each missing column of `columns` (name → definition after the name) to `table`, in order. A table from an older
|
|
117
|
-
* broker gets the columns, and an older broker ignores them.
|
|
118
|
-
*
|
|
117
|
+
* broker gets the columns, and an older broker ignores them. The columns are probed and added in one transaction, which
|
|
118
|
+
* one of the brokers opening the store at once runs while the others wait for it without its lock (#5054, #6560); an
|
|
119
|
+
* older broker adding one meanwhile is not an error.
|
|
119
120
|
*/
|
|
120
121
|
export async function addMissingColumns(
|
|
121
122
|
database: SqliteDatabase,
|
|
@@ -124,8 +125,31 @@ export async function addMissingColumns(
|
|
|
124
125
|
withColumn?: string,
|
|
125
126
|
): Promise<void> {
|
|
126
127
|
const dialect = dialectOf(database);
|
|
128
|
+
const names = Object.keys(columns);
|
|
127
129
|
// An open that read the catalog and found every column there runs no transaction (#6560).
|
|
128
|
-
if (await catalogHasColumns(database, table,
|
|
130
|
+
if (await catalogHasColumns(database, table, names)) return;
|
|
131
|
+
const probes = names.map((column) => dialect.columnExists(table, column));
|
|
132
|
+
try {
|
|
133
|
+
await setUpBrokerSchemaOnce(
|
|
134
|
+
database,
|
|
135
|
+
`${table}:columns`,
|
|
136
|
+
() => foundInCatalogAgain(database, (catalog) => names.every((column) => catalog.hasColumn(table, column))),
|
|
137
|
+
async (tx) => {
|
|
138
|
+
// The probes go out together, then each column they found missing is added.
|
|
139
|
+
const found = await Promise.all(probes.map((probe) => tx.all(probe.sql, ...probe.params)));
|
|
140
|
+
for (const [index, [column, definition]] of Object.entries(columns).entries()) {
|
|
141
|
+
if (found[index]!.length > 0) continue;
|
|
142
|
+
await tx.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
|
|
143
|
+
if (withColumn !== undefined) await tx.exec(withColumn);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
probes,
|
|
147
|
+
);
|
|
148
|
+
return;
|
|
149
|
+
} catch (error) {
|
|
150
|
+
if (!isDuplicateColumn(error)) throw error;
|
|
151
|
+
}
|
|
152
|
+
// An older broker added one of them meanwhile: each of the others in a transaction of its own.
|
|
129
153
|
for (const [column, definition] of Object.entries(columns)) {
|
|
130
154
|
const probe = dialect.columnExists(table, column);
|
|
131
155
|
try {
|
|
@@ -133,7 +157,7 @@ export async function addMissingColumns(
|
|
|
133
157
|
if ((await tx.all(probe.sql, ...probe.params)).length > 0) return;
|
|
134
158
|
await tx.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
|
|
135
159
|
if (withColumn !== undefined) await tx.exec(withColumn);
|
|
136
|
-
});
|
|
160
|
+
}, RETRY_UNAPPLIED);
|
|
137
161
|
} catch (error) {
|
|
138
162
|
if (!isDuplicateColumn(error)) throw error;
|
|
139
163
|
}
|
|
@@ -919,11 +919,12 @@ export async function openSqlEndedChildQueueStore(
|
|
|
919
919
|
if (!counting && !ledger.holdsMessages()) recountSoon();
|
|
920
920
|
};
|
|
921
921
|
// A step that runs only while the database is idle and its lock free at once; a database that cannot say so runs it
|
|
922
|
-
// as a transaction of its own, apart from the message writes.
|
|
922
|
+
// as a transaction of its own, apart from the message writes. It touches the queue's own tables alone, so on a shared
|
|
923
|
+
// database it excludes the queue's writers, as they exclude one another, not every writer of the database.
|
|
923
924
|
const maintain: (callback: (tx: SqliteExecutor) => Promise<void>) => Promise<boolean> =
|
|
924
925
|
database.tryMaintenance?.bind(database) ??
|
|
925
926
|
((callback) =>
|
|
926
|
-
database.transaction(callback).then(
|
|
927
|
+
database.transaction(callback, { concurrency: { kind: "serial", domain: queue } }).then(
|
|
927
928
|
() => true,
|
|
928
929
|
() => false,
|
|
929
930
|
));
|
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
InvalidStateInput,
|
|
12
12
|
StateStoreInvalidReason,
|
|
13
13
|
} from "./multinode-state-store.js";
|
|
14
|
-
import { ensureBrokerSchema, withBrokerSchemaCatalog } from "./sql-schema.js";
|
|
14
|
+
import { ensureBrokerSchema, RETRY_UNAPPLIED, withBrokerSchemaCatalog } from "./sql-schema.js";
|
|
15
15
|
|
|
16
16
|
type HeldRow = SqliteRow & {
|
|
17
17
|
reservation_key: string;
|
|
@@ -45,7 +45,7 @@ async function openHeldSendStoreInCatalog({ database, prefix }: IntercomBrokerSt
|
|
|
45
45
|
const table = `${validateStoragePrefix(prefix, dialectOf(database).name)}intercom_held_sends`;
|
|
46
46
|
const { types, nowMs } = dialectOf(database);
|
|
47
47
|
/** `take` reads and writes this table alone, so it excludes other takes, not every writer (#6560). */
|
|
48
|
-
const serial = { concurrency: { kind: "serial", domain: table } } as const;
|
|
48
|
+
const serial = { ...RETRY_UNAPPLIED, concurrency: { kind: "serial", domain: table } } as const;
|
|
49
49
|
await ensureBrokerSchema(database, prefix, "held-sends", (tx) =>
|
|
50
50
|
tx.exec(`
|
|
51
51
|
CREATE TABLE IF NOT EXISTS ${table}(
|