@bastani/atomic 0.10.11-alpha.3 → 0.10.11-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- 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 +4 -4
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +4 -4
- package/dist/_shared/mode-shared-2QJSCUM6.js +4 -4
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
- package/dist/_shared/p1b-elig-TVB5CBLL.js +22 -6
- package/dist/_shared/p1b-elig-TVB5CBLL.js.map +1 -1
- package/dist/_shared/p2-shell-main-B2WIALFD.js +6 -3
- package/dist/_shared/p2-shell-main-B2WIALFD.js.map +1 -1
- package/dist/_shared/runtime-O4KCSG4C.js +2 -2
- package/dist/_shared/sdk-B5LEWGGI.js +899 -515
- package/dist/_shared/sdk-B5LEWGGI.js.map +1 -1
- 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-EZUKEP4Q.js → startup-0-0-XJJDOIEC.js} +6 -12
- package/dist/_shared/{startup-0-0-EZUKEP4Q.js.map → startup-0-0-XJJDOIEC.js.map} +1 -1
- package/dist/_shared/{startup-0-1-RTOHJFDJ.js → startup-0-1-M6OWAYHH.js} +354 -103
- package/dist/_shared/startup-0-1-M6OWAYHH.js.map +1 -0
- package/dist/_shared/startup-0-2-5QHPCEON.js +18 -9
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -1
- package/dist/_shared/startup-0-3-4ZYBYQNM.js +4 -4
- package/dist/_shared/startup-0-4-ZMJV547D.js +4 -4
- package/dist/_shared/startup-0-5-YDW47QX6.js +4 -4
- package/dist/_shared/startup-10-0-TDQNBDDL.js +4 -4
- package/dist/_shared/startup-12-0-55AAXBJZ.js +1 -1
- package/dist/_shared/startup-14-0-MLX36RBG.js +2 -2
- package/dist/_shared/startup-15-0-YUKGAC63.js +2 -2
- package/dist/_shared/startup-15-1-4S7FLMNG.js +4 -4
- package/dist/_shared/startup-8-0-34CBHPZH.js +2114 -235
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/startup-8-1-LZFXSD3Z.js +12 -12
- package/dist/_shared/storage-command-7MGXLJGZ.js +6 -6
- package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
- package/dist/_shared/storage-status-K7PX2RXA.js +2 -2
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/team-DOQKICG2.js +1 -1
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +19 -0
- package/dist/builtin/intercom/broker/broker.bundle.mjs +1020 -108
- package/dist/builtin/intercom/broker/client.ts +8 -0
- package/dist/builtin/intercom/broker/database-wake-up-bus.ts +91 -14
- package/dist/builtin/intercom/broker/multinode-router.ts +102 -17
- package/dist/builtin/intercom/broker/multinode-state-store.ts +41 -2
- package/dist/builtin/intercom/broker/send-order-gate.ts +5 -2
- package/dist/builtin/intercom/broker/sql-add-column.ts +22 -1
- package/dist/builtin/intercom/broker/sql-lease-store.ts +304 -48
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +541 -50
- package/dist/builtin/intercom/broker/sql-restoring-reservation-store.ts +239 -8
- package/dist/builtin/intercom/broker/sql-retention.ts +11 -2
- package/dist/builtin/intercom/broker/sql-schema.ts +42 -8
- package/dist/builtin/intercom/index.bundle.mjs +13 -2
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +6 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/skill-creator/eval-viewer/generate_review.py +8 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/index.bundle.mjs +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 +2 -2
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +1 -1
- 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 +1 -1
- 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 +1 -1
- 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/debug.impl.js +3 -3
- package/dist/core/debug.js +3 -3
- package/dist/core/export-html/card-projection.impl.js +3 -3
- package/dist/core/export-html/card-projection.js +3 -3
- package/dist/core/export-html/index.code.js +4 -4
- package/dist/core/export-html/index.code.js.map +1 -1
- package/dist/core/export-html/index.impl.js +3 -3
- package/dist/core/export-html/index.js +3 -3
- package/dist/core/export-html/json-spans.impl.js +3 -3
- package/dist/core/export-html/json-spans.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.js +3 -3
- package/dist/core/export-html/tool-renderer.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/extensions/jiti-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-loader.js +3 -3
- package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-static-loader.js +3 -3
- package/dist/core/extensions/loader-host-modules.code.js +1 -1
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/extensions/loader-virtual-modules.js +1 -1
- package/dist/core/extensions/runner-context.js +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/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 +5 -4
- package/dist/core/sdk.code.js +2 -2
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +4 -4
- 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.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/storage/database.d.ts +6 -0
- package/dist/core/storage/database.js.map +1 -1
- package/dist/core/storage/fenced-paths.d.ts +7 -6
- package/dist/core/storage/fenced-paths.js +7 -6
- package/dist/core/storage/fenced-paths.js.map +1 -1
- package/dist/core/storage/index.js +2 -2
- package/dist/core/storage/node-sqlite-thread.js +209 -19
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.js +435 -71
- 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/provider.js +2 -2
- package/dist/core/storage/schema-catalog.d.ts +69 -7
- package/dist/core/storage/schema-catalog.js +352 -61
- package/dist/core/storage/schema-catalog.js.map +1 -1
- package/dist/core/storage/selection.js +2 -2
- package/dist/core/storage/session/branch-fork-source.code.js +2 -2
- package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
- package/dist/core/storage/session/branch-fork-source.js +3 -3
- package/dist/core/storage/session/card-view.impl.js +3 -3
- package/dist/core/storage/session/card-view.js +3 -3
- package/dist/core/storage/session/child-reader.code.js +3 -3
- package/dist/core/storage/session/child-reader.impl.js +3 -3
- package/dist/core/storage/session/child-reader.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.js +3 -3
- package/dist/core/storage/session/expanded-child-details.code.js +2 -2
- package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
- package/dist/core/storage/session/expanded-child-details.js +3 -3
- package/dist/core/storage/session/fork-detach.d.ts +11 -1
- package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.js +3 -3
- package/dist/core/storage/session/fork-row-index.impl.js +3 -3
- package/dist/core/storage/session/fork-row-index.js +3 -3
- package/dist/core/storage/session/fork-staging.code.js +1 -1
- package/dist/core/storage/session/fork-staging.impl.js +3 -3
- package/dist/core/storage/session/fork-staging.js +3 -3
- package/dist/core/storage/session/fork-sweep.js +31 -7
- package/dist/core/storage/session/fork-sweep.js.map +1 -1
- package/dist/core/storage/session/fork-window.code.js +3 -3
- package/dist/core/storage/session/fork-window.impl.js +3 -3
- package/dist/core/storage/session/fork-window.js +3 -3
- package/dist/core/storage/session/history-pages.impl.js +3 -3
- package/dist/core/storage/session/history-pages.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
- package/dist/core/storage/session/jsonl-session-lock.d.ts +100 -0
- package/dist/core/storage/session/jsonl-session-store.d.ts +41 -23
- 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 +8 -8
- package/dist/core/storage/session/released-history-files.code.js.map +1 -1
- package/dist/core/storage/session/released-history-files.impl.js +3 -3
- package/dist/core/storage/session/released-history-files.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.js +3 -3
- package/dist/core/storage/session/session-resume.impl.js +3 -3
- package/dist/core/storage/session/session-resume.js +3 -3
- package/dist/core/storage/session/session-search-index.d.ts +9 -1
- 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.d.ts +51 -7
- 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 -0
- package/dist/core/storage/sqlite-facade.js +309 -33
- package/dist/core/storage/sqlite-facade.js.map +1 -1
- package/dist/core/storage/sqlite-open-batch.js +10 -0
- package/dist/core/storage/sqlite-open-batch.js.map +1 -0
- package/dist/core/storage/storage-status.impl.js +3 -3
- package/dist/core/storage/storage-status.js +3 -3
- package/dist/core/storage/team.impl.js +3 -3
- package/dist/core/storage/team.js +3 -3
- 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 +3 -3
- 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.impl.js +3 -3
- package/dist/core/tasks/task-view-source.js +3 -3
- package/dist/core/tools/read-url.code.js +2 -2
- 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 +5 -3
- package/dist/core/worktree-snapshot/blob-store.js +151 -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-snapshot-index.js +158 -41
- package/dist/core/worktree-snapshot/fork-snapshot-index.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 +1 -1
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +1 -1
- 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.impl.js +3 -3
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/index.js +2 -2
- 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/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/package-manager-cli.code.js +4 -4
- 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/3.js +1 -1
- package/dist/startup-stages/5.js +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/docs/changelog.mdx +49 -0
- package/docs/storage/jsonl.md +3 -3
- package/package.json +8 -8
- package/dist/_shared/startup-0-1-RTOHJFDJ.js.map +0 -1
|
@@ -2126,6 +2126,14 @@ export class IntercomClient extends EventEmitter {
|
|
|
2126
2126
|
writeMessage(this.requireActiveSocket(), { type: "received", messageId, ...(paused ? { paused: true as const } : {}) });
|
|
2127
2127
|
}
|
|
2128
2128
|
|
|
2129
|
+
/**
|
|
2130
|
+
* #5145, #6712: clears an outcome that was heard on this registration but not saved, so a redelivery on the same
|
|
2131
|
+
* connection is heard and saved again instead of dropped. Already-saved outcomes stay recorded.
|
|
2132
|
+
*/
|
|
2133
|
+
forgetUnsavedOutcome(messageId: string): void {
|
|
2134
|
+
if (this.heardOutcomes.get(messageId) === "heard") this.heardOutcomes.delete(messageId);
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2129
2137
|
/**
|
|
2130
2138
|
* #5145: whether `message` is an outcome this client already heard, so it is not heard twice. A copy of one already
|
|
2131
2139
|
* saved is confirmed again, so the broker that sent it stops holding it.
|
|
@@ -25,7 +25,13 @@ import type {
|
|
|
25
25
|
WakeUpSubscription,
|
|
26
26
|
} from "./wake-up-bus.js";
|
|
27
27
|
import { addMissingColumns } from "./sql-add-column.js";
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
ensureBrokerSchema,
|
|
30
|
+
openCatalogOf,
|
|
31
|
+
queueBrokerSqliteSetup,
|
|
32
|
+
RETRY_UNAPPLIED,
|
|
33
|
+
withBrokerSchemaCatalog,
|
|
34
|
+
} from "./sql-schema.js";
|
|
29
35
|
|
|
30
36
|
/**
|
|
31
37
|
* S4 wake-up bus (specs/2026-10-19-intercom-multi-node.md §5.6): a hint log in the shared storage database. Each
|
|
@@ -70,6 +76,8 @@ const WAKE_UP_PRUNE_AGE_MS = WAKE_UP_HINT_RETENTION_MS - WAKE_UP_PRUNE_INTERVAL_
|
|
|
70
76
|
* statements of bounded size.
|
|
71
77
|
*/
|
|
72
78
|
export const WAKE_UP_POLL_BATCH_SIZE = 500;
|
|
79
|
+
/** The most hints one publish transaction writes together (#6715). */
|
|
80
|
+
const WAKE_UP_PUBLISH_BATCH_MAX = 500;
|
|
73
81
|
/** Longest wait between attempts to reopen an unavailable database; the backup poll covers the gap. */
|
|
74
82
|
export const WAKE_UP_RECONNECT_MAX_DELAY_MS = OUTBOX_BACKUP_POLL_INTERVAL_MS;
|
|
75
83
|
|
|
@@ -188,7 +196,25 @@ async function createSchema(database: SqliteDatabase, table: string, prefix: str
|
|
|
188
196
|
const catalog = await openCatalogOf(database);
|
|
189
197
|
const existed = catalog === undefined || catalog.hasTable(table);
|
|
190
198
|
await ensureBrokerSchema(database, prefix, "wakeups", (tx) => tx.exec(schema));
|
|
191
|
-
if (
|
|
199
|
+
if (dialectOf(database).name === "sqlite") {
|
|
200
|
+
if (
|
|
201
|
+
!(catalog !== undefined && catalog.hasColumn(table, "target_identity")) &&
|
|
202
|
+
!queueBrokerSqliteSetup(database, prefix ?? "", {
|
|
203
|
+
verify: (found) => found.hasColumn(table, "target_identity"),
|
|
204
|
+
run(ctx) {
|
|
205
|
+
// Add target_identity only when an older build created the table before this transaction without it.
|
|
206
|
+
if (ctx.tableExisted(table) && !ctx.hasColumn(table, "target_identity")) {
|
|
207
|
+
ctx.enqueue(`ALTER TABLE ${table} ADD COLUMN target_identity TEXT`);
|
|
208
|
+
ctx.noteColumnAdded(table, "target_identity");
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
})
|
|
212
|
+
) {
|
|
213
|
+
if (existed) await addMissingColumns(database, table, { target_identity: "TEXT" });
|
|
214
|
+
}
|
|
215
|
+
} else if (existed) {
|
|
216
|
+
await addMissingColumns(database, table, { target_identity: "TEXT" });
|
|
217
|
+
}
|
|
192
218
|
await ensureUnloggedHints(database, table, prefix);
|
|
193
219
|
}
|
|
194
220
|
|
|
@@ -296,6 +322,13 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
296
322
|
private pollAgain = false;
|
|
297
323
|
/** When a publish last deleted the hints past the retention, by this process's clock. */
|
|
298
324
|
private prunedAt: number | undefined;
|
|
325
|
+
/** Publishes waiting for the next batch transaction, in the order they were made (#6715). */
|
|
326
|
+
private readonly pendingPublishes: {
|
|
327
|
+
readonly hint: WakeUpHint;
|
|
328
|
+
readonly resolve: (result: WakeUpPublishResult) => void;
|
|
329
|
+
}[] = [];
|
|
330
|
+
/** The drain loop currently writing batches of queued publishes, if any. */
|
|
331
|
+
private publishing: Promise<void> | undefined;
|
|
299
332
|
|
|
300
333
|
constructor(options: DatabaseWakeUpBusOptions, table: string, database: SqliteDatabase) {
|
|
301
334
|
this.options = options;
|
|
@@ -307,24 +340,67 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
307
340
|
this.schedule = options.schedule ?? scheduleTimeout;
|
|
308
341
|
}
|
|
309
342
|
|
|
310
|
-
|
|
311
|
-
if (hint.brokerId.length === 0) return { status: "invalid", reason: "empty-broker-id" };
|
|
343
|
+
publish(hint: WakeUpHint): Promise<WakeUpPublishResult> {
|
|
344
|
+
if (hint.brokerId.length === 0) return Promise.resolve({ status: "invalid", reason: "empty-broker-id" });
|
|
345
|
+
if (this.closed) return Promise.resolve({ status: "unavailable" });
|
|
346
|
+
return new Promise<WakeUpPublishResult>((resolve) => {
|
|
347
|
+
this.pendingPublishes.push({ hint, resolve });
|
|
348
|
+
if (this.publishing === undefined) this.publishing = this.drainPublishes();
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
private async drainPublishes(): Promise<void> {
|
|
353
|
+
try {
|
|
354
|
+
// Publishes made in the same turn as the first go with it.
|
|
355
|
+
await undefined;
|
|
356
|
+
while (this.pendingPublishes.length > 0) {
|
|
357
|
+
if (this.closed) {
|
|
358
|
+
for (const { resolve } of this.pendingPublishes.splice(0)) resolve({ status: "unavailable" });
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const batch = this.pendingPublishes.splice(0, WAKE_UP_PUBLISH_BATCH_MAX);
|
|
362
|
+
const result = await this.publishBatch(batch.map(({ hint }) => hint));
|
|
363
|
+
for (const { resolve } of batch) resolve(result);
|
|
364
|
+
}
|
|
365
|
+
} finally {
|
|
366
|
+
this.publishing = undefined;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
private async publishBatch(hints: readonly WakeUpHint[]): Promise<WakeUpPublishResult> {
|
|
312
371
|
const database = await this.connection(false);
|
|
313
372
|
if (database === undefined) return { status: "unavailable" };
|
|
314
|
-
const { nowMs } = dialectOf(database);
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
373
|
+
const { name: dialect, nowMs, types } = dialectOf(database);
|
|
374
|
+
const payload = JSON.stringify(
|
|
375
|
+
hints.map((hint) => [hint.brokerId, hint.reason, hint.version, hint.targetIdentity ?? null]),
|
|
376
|
+
);
|
|
377
|
+
const insert: SqliteStatement =
|
|
378
|
+
dialect === "postgres"
|
|
379
|
+
? {
|
|
380
|
+
sql: `INSERT INTO ${this.table} (broker_id, reason, version, created_at, target_identity)
|
|
381
|
+
SELECT h ->> 0, h ->> 1, CAST(h ->> 2 AS ${types.int}), ${nowMs}, h ->> 3
|
|
382
|
+
FROM jsonb_array_elements(?::jsonb) WITH ORDINALITY AS t(h, ord)
|
|
383
|
+
ORDER BY ord`,
|
|
384
|
+
params: [payload],
|
|
385
|
+
}
|
|
386
|
+
: {
|
|
387
|
+
sql: `INSERT INTO ${this.table} (broker_id, reason, version, created_at, target_identity)
|
|
388
|
+
SELECT json_extract(value, '$[0]'), json_extract(value, '$[1]'),
|
|
389
|
+
CAST(json_extract(value, '$[2]') AS ${types.int}), ${nowMs}, json_extract(value, '$[3]')
|
|
390
|
+
FROM json_each(?)
|
|
391
|
+
ORDER BY key`,
|
|
392
|
+
params: [payload],
|
|
393
|
+
};
|
|
319
394
|
const notifications = database.notifications;
|
|
320
395
|
try {
|
|
321
396
|
if (notifications === undefined) await database.run(insert.sql, ...insert.params);
|
|
322
397
|
else {
|
|
323
|
-
// The notifications go out once the
|
|
324
|
-
// behind
|
|
325
|
-
//
|
|
326
|
-
// `fencedPath("intercom-wakeup-hint")`.
|
|
327
|
-
const
|
|
398
|
+
// The notifications go out once the hints commit, one per distinct broker, so the poll they start finds
|
|
399
|
+
// them: on Postgres right behind the commit, in the same round trip, and the batch insert goes with the
|
|
400
|
+
// transaction's start (#6560, #6715). Hints are new rows that no write checks first, so their writers take
|
|
401
|
+
// no lock domain: see `fencedPath("intercom-wakeup-hint")`.
|
|
402
|
+
const brokers = [...new Set(hints.map((hint) => hint.brokerId))];
|
|
403
|
+
const notices = brokers.flatMap((brokerId) => wakeUpNotices(notifications, this.table, this.leases, brokerId));
|
|
328
404
|
await database.transaction(
|
|
329
405
|
async (tx) => {
|
|
330
406
|
await Promise.all([insert, ...notices].map(({ sql, params }) => tx.run(sql, ...params)));
|
|
@@ -383,6 +459,7 @@ class DatabaseWakeUpBus implements WakeUpBus {
|
|
|
383
459
|
this.stopListening();
|
|
384
460
|
for (const subscription of this.subscriptions) subscription.open = false;
|
|
385
461
|
this.subscriptions.clear();
|
|
462
|
+
await this.publishing;
|
|
386
463
|
await this.polling;
|
|
387
464
|
await this.opening;
|
|
388
465
|
const database = this.database;
|
|
@@ -52,6 +52,8 @@ import {
|
|
|
52
52
|
OUTBOX_BACKUP_POLL_INTERVAL_MS,
|
|
53
53
|
OUTBOX_CLAIM_STALE_AFTER_MS,
|
|
54
54
|
type OutboxClaim,
|
|
55
|
+
type OutboxReleaseClaimResult,
|
|
56
|
+
type OutboxRenewClaimResult,
|
|
55
57
|
type OutboxEnqueueRequest,
|
|
56
58
|
type OutboxEnqueueResult,
|
|
57
59
|
type OutboxRow,
|
|
@@ -62,6 +64,7 @@ import {
|
|
|
62
64
|
type ReleasedAskRecord,
|
|
63
65
|
type RestoringReservation,
|
|
64
66
|
type RestoringReservationLease,
|
|
67
|
+
type RestoringReservationRenewResult,
|
|
65
68
|
reservationKeyFor,
|
|
66
69
|
returnAddressOf,
|
|
67
70
|
type SentMessageReservation,
|
|
@@ -586,6 +589,7 @@ interface SendProgress {
|
|
|
586
589
|
readonly messageId: string;
|
|
587
590
|
readonly attemptId?: string;
|
|
588
591
|
readonly ticket?: SendOrderTicket;
|
|
592
|
+
readonly requirePendingReplyLocal?: true;
|
|
589
593
|
waitingOnReplyKey?: string;
|
|
590
594
|
scheduledFireAt?: number;
|
|
591
595
|
stopReporting?: () => void;
|
|
@@ -3072,7 +3076,7 @@ export class MultiNodeRouter {
|
|
|
3072
3076
|
// this registration held itself is given back.
|
|
3073
3077
|
if (alias !== undefined) await this.releaseOwner(alias);
|
|
3074
3078
|
if (entry.fenced === true) {
|
|
3075
|
-
|
|
3079
|
+
await this.releaseClaims(claims.map((inflight) => inflight.claim));
|
|
3076
3080
|
const stillHere = [...this.presence.keys()].some((other) => deliveryTargetIdentity(other) === identity);
|
|
3077
3081
|
if (entry.lease !== undefined && !stillHere) {
|
|
3078
3082
|
await this.state.leases.release(entry.lease);
|
|
@@ -3113,7 +3117,7 @@ export class MultiNodeRouter {
|
|
|
3113
3117
|
// a reply never finds it offline with only its pending asks. A failed write loses them, as a lost local route
|
|
3114
3118
|
// does: the subagent then wakes at its reply deadline.
|
|
3115
3119
|
await keepReleasedAsks(this.state, session).catch((error: Error) => this.report(error));
|
|
3116
|
-
|
|
3120
|
+
await this.releaseClaims(claims.map((inflight) => inflight.claim));
|
|
3117
3121
|
// #4842: an ask that ends with its recipient fails for its asker on any node.
|
|
3118
3122
|
await (away ? Promise.resolve() : this.state.pendingAsks.pruneSender(sessionId).then(() => undefined))
|
|
3119
3123
|
.then(async () => {
|
|
@@ -3673,6 +3677,7 @@ export class MultiNodeRouter {
|
|
|
3673
3677
|
messageId: request.message.id,
|
|
3674
3678
|
...(request.attemptId === undefined ? {} : { attemptId: request.attemptId }),
|
|
3675
3679
|
ticket,
|
|
3680
|
+
...(request.localTarget !== undefined && request.requirePendingReply ? { requirePendingReplyLocal: true as const } : {}),
|
|
3676
3681
|
};
|
|
3677
3682
|
this.sendProgress.set(request.clientMessage, progress);
|
|
3678
3683
|
this.ticketProgress.set(ticket, progress);
|
|
@@ -3996,9 +4001,31 @@ export class MultiNodeRouter {
|
|
|
3996
4001
|
if (upstream !== undefined && upstream.hadProgress) {
|
|
3997
4002
|
latest = latest === undefined ? upstream.lastProgressAt : Math.max(latest, upstream.lastProgressAt);
|
|
3998
4003
|
}
|
|
4004
|
+
const active = upstream ?? own;
|
|
4005
|
+
if (
|
|
4006
|
+
latest === undefined &&
|
|
4007
|
+
active.requirePendingReplyLocal === true &&
|
|
4008
|
+
active.waitingOnReplyKey === undefined &&
|
|
4009
|
+
this.storeAnsweredAt >= active.startedAt
|
|
4010
|
+
) {
|
|
4011
|
+
latest = this.storeAnsweredAt;
|
|
4012
|
+
}
|
|
3999
4013
|
return latest;
|
|
4000
4014
|
}
|
|
4001
4015
|
|
|
4016
|
+
/**
|
|
4017
|
+
* Store-silence window for a plain local send waiting on `earlier`. A local `requirePendingReply` reply has a
|
|
4018
|
+
* `PRESENCE_REGISTRATION_BOUND_MS` shared-route adoption budget, so once the shared store is proven responsive a
|
|
4019
|
+
* single contended write (> 300 ms) must not let later plain sends overtake it; soft replies and unsettled outbox
|
|
4020
|
+
* retries keep `LOCAL_RETRY_LOOKUP_BOUND_MS`.
|
|
4021
|
+
*/
|
|
4022
|
+
private localBlockerSilenceMs(earlier: SendOrderTicket): number {
|
|
4023
|
+
const own = this.ticketProgress.get(earlier);
|
|
4024
|
+
if (own === undefined) return LOCAL_RETRY_LOOKUP_BOUND_MS;
|
|
4025
|
+
const active = this.resolveBlockerProgress(own, earlier) ?? own;
|
|
4026
|
+
return active.requirePendingReplyLocal === true ? PRESENCE_REGISTRATION_BOUND_MS : LOCAL_RETRY_LOOKUP_BOUND_MS;
|
|
4027
|
+
}
|
|
4028
|
+
|
|
4002
4029
|
/** Wait for strictly earlier sends from the same sender to `target` before performing a local commit. */
|
|
4003
4030
|
private async waitForEarlierLocal(
|
|
4004
4031
|
ticket: SendOrderTicket,
|
|
@@ -4035,7 +4062,7 @@ export class MultiNodeRouter {
|
|
|
4035
4062
|
...(hasBound
|
|
4036
4063
|
? {
|
|
4037
4064
|
blockerProgressAt: (earlier) => this.blockerProgressAt(earlier),
|
|
4038
|
-
progressSilenceMs:
|
|
4065
|
+
progressSilenceMs: (earlier) => this.localBlockerSilenceMs(earlier),
|
|
4039
4066
|
maxLocalWaitUntil: (ownProgress?.startedAt ?? performance.now()) + PRESENCE_REGISTRATION_BOUND_MS,
|
|
4040
4067
|
}
|
|
4041
4068
|
: {}),
|
|
@@ -5832,10 +5859,28 @@ export class MultiNodeRouter {
|
|
|
5832
5859
|
return done;
|
|
5833
5860
|
}
|
|
5834
5861
|
|
|
5862
|
+
/**
|
|
5863
|
+
* Scans every recipient this broker hosts. With several, one read first finds those with undelivered rows, and only
|
|
5864
|
+
* they are claimed for: a backup poll or resync across idle recipients costs one statement, not a claim each (#6560).
|
|
5865
|
+
* A row queued after the read is claimed when its send's wake-up hint arrives, or at the next scan, as one queued
|
|
5866
|
+
* right after a claim's own read is. When the read fails, every recipient is claimed for, as without it.
|
|
5867
|
+
*/
|
|
5835
5868
|
private scanAll(): void {
|
|
5836
|
-
|
|
5837
|
-
|
|
5869
|
+
const identities = [...new Set([...this.host.sessions.values()].map(deliveryTargetIdentity))];
|
|
5870
|
+
const outbox = this.state.outbox;
|
|
5871
|
+
if (identities.length < 2 || outbox.withUndelivered === undefined) {
|
|
5872
|
+
for (const identity of identities) this.scanIdentity(identity);
|
|
5873
|
+
return;
|
|
5838
5874
|
}
|
|
5875
|
+
void outbox.withUndelivered(identities).then(
|
|
5876
|
+
(found) => {
|
|
5877
|
+
for (const identity of identities) if (found.has(identity)) this.scanIdentity(identity);
|
|
5878
|
+
},
|
|
5879
|
+
(error: unknown) => {
|
|
5880
|
+
this.report(error);
|
|
5881
|
+
for (const identity of identities) this.scanIdentity(identity);
|
|
5882
|
+
},
|
|
5883
|
+
);
|
|
5839
5884
|
}
|
|
5840
5885
|
|
|
5841
5886
|
private localSessionFor(identity: string): BrokerConnectedSession | undefined {
|
|
@@ -5870,10 +5915,13 @@ export class MultiNodeRouter {
|
|
|
5870
5915
|
// The recipient left or was replaced while this batch was being delivered: release this row and every
|
|
5871
5916
|
// later row in the batch unwritten so a reconnected session never receives a later row ahead of an earlier
|
|
5872
5917
|
// released row.
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5918
|
+
const tail = claimed.rows.slice(index);
|
|
5919
|
+
const released = await this.releaseClaims(
|
|
5920
|
+
tail.map((pending) => pending.claim),
|
|
5921
|
+
{ unwritten: true },
|
|
5922
|
+
);
|
|
5923
|
+
for (let remaining = 0; remaining < tail.length; remaining++) {
|
|
5924
|
+
if (released[remaining]?.status === "released") await this.wakeOrigin(tail[remaining]!.row);
|
|
5877
5925
|
}
|
|
5878
5926
|
if (this.localSessionFor(identity) !== undefined) void this.scanIdentity(identity);
|
|
5879
5927
|
return;
|
|
@@ -6021,7 +6069,12 @@ export class MultiNodeRouter {
|
|
|
6021
6069
|
});
|
|
6022
6070
|
}
|
|
6023
6071
|
}
|
|
6024
|
-
|
|
6072
|
+
// Replies clear their shared pending-ask route after `markDelivered` commits; keeping `wakeOrigin` after
|
|
6073
|
+
// `clearReply` prevents the replier from hearing `delivered` and sending a second reply before the route
|
|
6074
|
+
// is cleared (#6715). Non-reply deliveries write the outcome hint atomically inside the settlement.
|
|
6075
|
+
const delivered = await this.state.outbox.markDelivered(inflight.claim, {
|
|
6076
|
+
wakeOrigin: frame.message.replyTo === undefined,
|
|
6077
|
+
});
|
|
6025
6078
|
this.storeAnswered();
|
|
6026
6079
|
marked = true;
|
|
6027
6080
|
this.firstHandedOverAt.delete(messageId);
|
|
@@ -6046,7 +6099,7 @@ export class MultiNodeRouter {
|
|
|
6046
6099
|
inflight.handedOverAt,
|
|
6047
6100
|
);
|
|
6048
6101
|
finishOpening?.();
|
|
6049
|
-
await this.wakeOrigin(inflight.row);
|
|
6102
|
+
if (delivered.woke !== inflight.row.originBrokerId) await this.wakeOrigin(inflight.row);
|
|
6050
6103
|
} finally {
|
|
6051
6104
|
finishOpening?.();
|
|
6052
6105
|
}
|
|
@@ -6074,6 +6127,20 @@ export class MultiNodeRouter {
|
|
|
6074
6127
|
}
|
|
6075
6128
|
}
|
|
6076
6129
|
|
|
6130
|
+
private async releaseClaims(
|
|
6131
|
+
claims: readonly OutboxClaim[],
|
|
6132
|
+
options?: { readonly unwritten?: boolean },
|
|
6133
|
+
): Promise<OutboxReleaseClaimResult[]> {
|
|
6134
|
+
if (claims.length === 0) return [];
|
|
6135
|
+
const outbox = this.state.outbox;
|
|
6136
|
+
if (claims.length > 1 && outbox.releaseClaims !== undefined) {
|
|
6137
|
+
return outbox.releaseClaims(claims, options);
|
|
6138
|
+
}
|
|
6139
|
+
const results: OutboxReleaseClaimResult[] = [];
|
|
6140
|
+
for (const claim of claims) results.push(await outbox.releaseClaim(claim, options));
|
|
6141
|
+
return results;
|
|
6142
|
+
}
|
|
6143
|
+
|
|
6077
6144
|
private async wakeOrigin(row: OutboxRow): Promise<void> {
|
|
6078
6145
|
if (row.originBrokerId === this.brokerId) void this.checkOutcomes();
|
|
6079
6146
|
else await this.bus.publish({ brokerId: row.originBrokerId, reason: "outcome", version: row.sequence });
|
|
@@ -6466,16 +6533,34 @@ export class MultiNodeRouter {
|
|
|
6466
6533
|
}
|
|
6467
6534
|
});
|
|
6468
6535
|
}
|
|
6469
|
-
|
|
6470
|
-
|
|
6536
|
+
const inflights = [...this.inflight.values()];
|
|
6537
|
+
const dropUnrenewed = (inflight: Inflight, renewed: OutboxRenewClaimResult) => {
|
|
6471
6538
|
if (renewed.status !== "renewed" && this.inflight.get(inflight.row.messageId) === inflight) {
|
|
6472
6539
|
this.inflight.delete(inflight.row.messageId);
|
|
6473
6540
|
inflight.finishOpening?.();
|
|
6474
6541
|
}
|
|
6475
|
-
}
|
|
6476
|
-
|
|
6477
|
-
|
|
6542
|
+
};
|
|
6543
|
+
// #6560: every claim in flight renewed in one statement, not a transaction each.
|
|
6544
|
+
const outbox = this.state.outbox;
|
|
6545
|
+
if (inflights.length > 1 && outbox.renewClaims !== undefined) {
|
|
6546
|
+
const renewed = await outbox.renewClaims(inflights.map((inflight) => inflight.claim));
|
|
6547
|
+
inflights.forEach((inflight, index) => dropUnrenewed(inflight, renewed[index]!));
|
|
6548
|
+
} else for (const inflight of inflights) dropUnrenewed(inflight, await outbox.renewClaim(inflight.claim));
|
|
6549
|
+
const mirrors = [...this.mirrored];
|
|
6550
|
+
const dropUnrenewedMirror = (
|
|
6551
|
+
key: string,
|
|
6552
|
+
mirror: MirroredReservation,
|
|
6553
|
+
renewed: RestoringReservationRenewResult,
|
|
6554
|
+
) => {
|
|
6478
6555
|
if (renewed.status !== "renewed" && this.mirrored.get(key) === mirror) this.mirrored.delete(key);
|
|
6556
|
+
};
|
|
6557
|
+
const reservations = this.state.reservations;
|
|
6558
|
+
if (mirrors.length > 0 && reservations.renewMany !== undefined) {
|
|
6559
|
+
const renewed = await reservations.renewMany(mirrors.map(([, mirror]) => mirror.lease));
|
|
6560
|
+
mirrors.forEach(([key, mirror], index) => dropUnrenewedMirror(key, mirror, renewed[index]!));
|
|
6561
|
+
} else {
|
|
6562
|
+
for (const [key, mirror] of mirrors)
|
|
6563
|
+
dropUnrenewedMirror(key, mirror, await reservations.renew(mirror.lease));
|
|
6479
6564
|
}
|
|
6480
6565
|
// #5352: a reservation whose write failed or did not answer is written again, in order behind its key's steps.
|
|
6481
6566
|
for (const [key, pending] of this.unpublished) {
|
|
@@ -6670,7 +6755,7 @@ export class MultiNodeRouter {
|
|
|
6670
6755
|
this.holds.clear();
|
|
6671
6756
|
await Promise.all([...this.serials.values()]);
|
|
6672
6757
|
try {
|
|
6673
|
-
|
|
6758
|
+
await this.releaseClaims([...this.inflight.values()].map((inflight) => inflight.claim));
|
|
6674
6759
|
for (const entry of this.presence.values()) {
|
|
6675
6760
|
if (entry.lease !== undefined) await this.state.leases.release(entry.lease);
|
|
6676
6761
|
}
|
|
@@ -328,8 +328,23 @@ export type OutboxClaimWriteRejection =
|
|
|
328
328
|
|
|
329
329
|
export type OutboxRenewClaimResult = { readonly status: "renewed" } | OutboxClaimWriteRejection;
|
|
330
330
|
export type OutboxReleaseClaimResult = { readonly status: "released" } | OutboxClaimWriteRejection;
|
|
331
|
+
export interface OutboxMarkDeliveredOptions {
|
|
332
|
+
/**
|
|
333
|
+
* Write the database wake-up bus's `outcome` hint for a settled row whose `originBrokerId` differs from
|
|
334
|
+
* `claim.claimantId` inside the settlement itself, so settling and waking its origin commit together in one round
|
|
335
|
+
* trip (#6715). A store that ignores it (or could not take the hint log's lock without waiting) omits `woke`, and
|
|
336
|
+
* the caller wakes the origin itself.
|
|
337
|
+
*/
|
|
338
|
+
readonly wakeOrigin?: boolean;
|
|
339
|
+
}
|
|
340
|
+
|
|
331
341
|
export type OutboxDeliveredResult =
|
|
332
|
-
| {
|
|
342
|
+
| {
|
|
343
|
+
readonly status: "delivered";
|
|
344
|
+
readonly row: OutboxRow;
|
|
345
|
+
/** With `wakeOrigin`, the origin broker the settlement sent an `outcome` wake-up hint to (#6715). */
|
|
346
|
+
readonly woke?: string;
|
|
347
|
+
}
|
|
333
348
|
| OutboxClaimWriteRejection;
|
|
334
349
|
export type OutboxFailedResult = { readonly status: "failed"; readonly row: OutboxRow } | OutboxClaimWriteRejection;
|
|
335
350
|
export type OutboxReadResult =
|
|
@@ -351,6 +366,11 @@ export interface OutboxStore {
|
|
|
351
366
|
*/
|
|
352
367
|
claim(request: OutboxClaimRequest): Promise<OutboxClaimResult>;
|
|
353
368
|
renewClaim(claim: OutboxClaim): Promise<OutboxRenewClaimResult>;
|
|
369
|
+
/**
|
|
370
|
+
* `renewClaim` for each of `claims`, of distinct rows, in one transaction whose one statement renews every claim still
|
|
371
|
+
* current, answered in the order given (#6560). Optional: without it, a broker renews its claims one at a time.
|
|
372
|
+
*/
|
|
373
|
+
renewClaims?(claims: readonly OutboxClaim[]): Promise<OutboxRenewClaimResult[]>;
|
|
354
374
|
/**
|
|
355
375
|
* #3983: the claim's recipient reports it is still saving the row, so the sender's broker keeps its sender
|
|
356
376
|
* waiting. Optional: a store without it never extends a sender's wait.
|
|
@@ -362,6 +382,14 @@ export interface OutboxStore {
|
|
|
362
382
|
* never claimed, as it was before this claim.
|
|
363
383
|
*/
|
|
364
384
|
releaseClaim(claim: OutboxClaim, options?: { readonly unwritten?: boolean }): Promise<OutboxReleaseClaimResult>;
|
|
385
|
+
/**
|
|
386
|
+
* `releaseClaim` for each of `claims`, in one transaction whose statement releases every claim still current,
|
|
387
|
+
* answered in the order given (#6713). Optional: without it, a broker releases its claims one at a time.
|
|
388
|
+
*/
|
|
389
|
+
releaseClaims?(
|
|
390
|
+
claims: readonly OutboxClaim[],
|
|
391
|
+
options?: { readonly unwritten?: boolean },
|
|
392
|
+
): Promise<OutboxReleaseClaimResult[]>;
|
|
365
393
|
/**
|
|
366
394
|
* #5038: return every row `claimantId` holds to `queued`, as its own `releaseClaim` would, so a dead broker's
|
|
367
395
|
* claims stop holding its recipients' queues until they go stale. Resolves to the number of rows released.
|
|
@@ -372,7 +400,7 @@ export interface OutboxStore {
|
|
|
372
400
|
* route with `PendingAskStore.record` first: a settled row is never claimed again, so a route written after it
|
|
373
401
|
* would be lost if the broker stopped between the two writes.
|
|
374
402
|
*/
|
|
375
|
-
markDelivered(claim: OutboxClaim): Promise<OutboxDeliveredResult>;
|
|
403
|
+
markDelivered(claim: OutboxClaim, options?: OutboxMarkDeliveredOptions): Promise<OutboxDeliveredResult>;
|
|
376
404
|
/** The recipient's broker refused the row; `reason` is reported to the sender verbatim. */
|
|
377
405
|
markFailed(claim: OutboxClaim, reason: string): Promise<OutboxFailedResult>;
|
|
378
406
|
read(messageId: string): Promise<OutboxReadResult>;
|
|
@@ -381,6 +409,12 @@ export interface OutboxStore {
|
|
|
381
409
|
* first `limit` of them.
|
|
382
410
|
*/
|
|
383
411
|
listUndelivered(targetIdentity: string, limit?: number): Promise<OutboxListResult>;
|
|
412
|
+
/**
|
|
413
|
+
* Which of `targetIdentities` have `queued` or `claimed` rows, read in one statement, so a broker that scans every
|
|
414
|
+
* recipient it hosts claims only for those (#6560). A row queued after the read is found by the claim its send's
|
|
415
|
+
* wake-up hint starts, or by the next scan. Optional: without it, the broker claims for each recipient.
|
|
416
|
+
*/
|
|
417
|
+
withUndelivered?(targetIdentities: readonly string[]): Promise<ReadonlySet<string>>;
|
|
384
418
|
/**
|
|
385
419
|
* #4896: where `messageId` stands in its recipient's undelivered rows, from 1 for the oldest, counted without
|
|
386
420
|
* reading any row: `missing` when it is not one of them.
|
|
@@ -581,6 +615,11 @@ export interface RestoringReservationStore {
|
|
|
581
615
|
): Promise<RestoringReservationLookupResult>;
|
|
582
616
|
/** Reset the age, also of a gone marker. A superseded token or an ended reservation is `stale`. */
|
|
583
617
|
renew(lease: RestoringReservationLease): Promise<RestoringReservationRenewResult>;
|
|
618
|
+
/**
|
|
619
|
+
* Reset the age of multiple reservations, also of gone markers, in a single shared-store transaction, returning one
|
|
620
|
+
* result per entry in input order (#6714). Absent on custom stores that only implement `renew`.
|
|
621
|
+
*/
|
|
622
|
+
renewMany?(leases: readonly RestoringReservationLease[]): Promise<RestoringReservationRenewResult[]>;
|
|
584
623
|
/** Owner only: mark the reservation gone, or end it as `released`. */
|
|
585
624
|
release(
|
|
586
625
|
lease: RestoringReservationLease,
|
|
@@ -99,7 +99,7 @@ export interface WaitForEarlierOptions {
|
|
|
99
99
|
*/
|
|
100
100
|
readonly blockerProgressAt?: (earlier: SendOrderTicket) => number | undefined;
|
|
101
101
|
/** Silence window (ms) to wait past a progressing blocker's latest store answer; 0 disables extension. */
|
|
102
|
-
readonly progressSilenceMs?: number;
|
|
102
|
+
readonly progressSilenceMs?: number | ((earlier: SendOrderTicket) => number);
|
|
103
103
|
/** Hard monotonic deadline (`performance.now()`) past which progress extensions stop. */
|
|
104
104
|
readonly maxLocalWaitUntil?: number;
|
|
105
105
|
}
|
|
@@ -307,7 +307,10 @@ export class SendOrderGate {
|
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
private extensionRemainingMs(earlier: InternalTicket, options: WaitForEarlierOptions): number {
|
|
310
|
-
const silenceMs =
|
|
310
|
+
const silenceMs =
|
|
311
|
+
typeof options.progressSilenceMs === "function"
|
|
312
|
+
? options.progressSilenceMs(earlier)
|
|
313
|
+
: (options.progressSilenceMs ?? 0);
|
|
311
314
|
if (silenceMs <= 0 || options.blockerProgressAt === undefined) return 0;
|
|
312
315
|
const progressAt = options.blockerProgressAt(earlier);
|
|
313
316
|
if (progressAt === undefined) return 0;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { dialectOf, type SqliteDatabase } from "@bastani/atomic/storage";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
catalogHasColumns,
|
|
4
|
+
foundInCatalogAgain,
|
|
5
|
+
queueBrokerSqliteSetup,
|
|
6
|
+
RETRY_UNAPPLIED,
|
|
7
|
+
setUpBrokerSchemaOnce,
|
|
8
|
+
} from "./sql-schema.js";
|
|
3
9
|
|
|
4
10
|
function isLineTerminatorCode(code: number): boolean {
|
|
5
11
|
return code === 0x0a || code === 0x0d || code === 0x2028 || code === 0x2029;
|
|
@@ -128,6 +134,21 @@ export async function addMissingColumns(
|
|
|
128
134
|
const names = Object.keys(columns);
|
|
129
135
|
// An open that read the catalog and found every column there runs no transaction (#6560).
|
|
130
136
|
if (await catalogHasColumns(database, table, names)) return;
|
|
137
|
+
// Inside a SQLite open scope, queue missing column additions into the open's single write transaction (#6709).
|
|
138
|
+
if (
|
|
139
|
+
queueBrokerSqliteSetup(database, undefined, {
|
|
140
|
+
verify: (catalog) => names.every((column) => catalog.hasColumn(table, column)),
|
|
141
|
+
run(ctx) {
|
|
142
|
+
for (const [column, definition] of Object.entries(columns)) {
|
|
143
|
+
if (ctx.hasColumn(table, column)) continue;
|
|
144
|
+
ctx.enqueue(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`, { ignoreError: isDuplicateColumn });
|
|
145
|
+
ctx.noteColumnAdded(table, column);
|
|
146
|
+
if (withColumn !== undefined) ctx.enqueue(withColumn);
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
})
|
|
150
|
+
)
|
|
151
|
+
return;
|
|
131
152
|
const probes = names.map((column) => dialect.columnExists(table, column));
|
|
132
153
|
try {
|
|
133
154
|
await setUpBrokerSchemaOnce(
|