@bastani/atomic 0.10.15 → 0.10.16-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/dist/__atomic_timers/index.js +112 -0
- package/dist/__atomic_timers/index.js.map +1 -0
- package/dist/_shared/dist-KOELCESV.js +2 -2
- package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
- package/dist/_shared/http-YFAPTIZD.js +20 -22
- package/dist/_shared/http-YFAPTIZD.js.map +1 -1
- package/dist/_shared/lib-4PES5P4V.js +2 -2
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +55 -25
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +13 -14
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js.map +1 -1
- package/dist/_shared/mode-shared-2QJSCUM6.js +16 -17
- package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -1
- package/dist/_shared/p0-cli-BB45ZQY6.js +23 -37
- package/dist/_shared/p0-cli-BB45ZQY6.js.map +1 -1
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +6 -5
- package/dist/_shared/p1a-prewarm-XIU57JHF.js.map +1 -1
- package/dist/_shared/{p1b-elig-TVB5CBLL.js → p1b-elig-BY2G5BUE.js} +28 -36
- package/dist/_shared/p1b-elig-BY2G5BUE.js.map +1 -0
- package/dist/_shared/runtime-O4KCSG4C.js +4 -4
- package/dist/_shared/sdk-OHKMDJ74.js +382 -45
- package/dist/_shared/sdk-OHKMDJ74.js.map +1 -1
- package/dist/_shared/session-data-AHTU7IS6.js +3 -3
- package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
- package/dist/_shared/settings-startup-HXQLSUWM.js.map +1 -1
- package/dist/_shared/{startup-0-0-Q3MWKUK4.js → startup-0-0-ERMIDHQT.js} +296 -382
- package/dist/_shared/startup-0-0-ERMIDHQT.js.map +1 -0
- package/dist/_shared/{startup-0-1-M6OWAYHH.js → startup-0-1-RTASI3HG.js} +430 -102
- package/dist/_shared/startup-0-1-RTASI3HG.js.map +1 -0
- package/dist/_shared/{startup-0-2-2HUMCPKX.js → startup-0-2-YZZOC22D.js} +8109 -7962
- package/dist/_shared/startup-0-2-YZZOC22D.js.map +1 -0
- package/dist/_shared/{startup-0-3-4ZYBYQNM.js → startup-0-3-DE2NCS6A.js} +130 -83
- package/dist/_shared/startup-0-3-DE2NCS6A.js.map +1 -0
- package/dist/_shared/startup-0-4-ZMJV547D.js +7 -7
- package/dist/_shared/{startup-0-5-YDW47QX6.js → startup-0-5-HZX3ZPTP.js} +411 -85
- package/dist/_shared/startup-0-5-HZX3ZPTP.js.map +1 -0
- package/dist/_shared/startup-10-0-TDQNBDDL.js +42 -29
- package/dist/_shared/startup-10-0-TDQNBDDL.js.map +1 -1
- package/dist/_shared/startup-12-0-55AAXBJZ.js +3 -3
- package/dist/_shared/startup-14-0-MLX36RBG.js +11 -10
- package/dist/_shared/startup-14-0-MLX36RBG.js.map +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +9 -8
- package/dist/_shared/startup-15-0-YUKGAC63.js.map +1 -1
- package/dist/_shared/startup-15-1-4S7FLMNG.js +24 -16
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +40 -19
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/startup-8-1-LZFXSD3Z.js +129 -92
- package/dist/_shared/startup-8-1-LZFXSD3Z.js.map +1 -1
- package/dist/_shared/storage-command-7MGXLJGZ.js +6 -4
- package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
- package/dist/_shared/storage-status-K7PX2RXA.js +7 -6
- package/dist/_shared/storage-status-K7PX2RXA.js.map +1 -1
- package/dist/_shared/task-reference-stream-JWMUZSJX.js +1 -1
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/team-DOQKICG2.js +4 -3
- package/dist/_shared/team-DOQKICG2.js.map +1 -1
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/index.bundle.mjs +1 -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/src/extension/index.bundle.mjs +102 -42
- package/dist/builtin/web-access/index.bundle.mjs +1 -2
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/cli/args.js +2 -2
- package/dist/cli/auth-cli.code.js +6 -6
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +7 -6
- package/dist/cli/blueprint-command.code.js.map +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 +3 -3
- package/dist/cli/intercom-command.impl.js +3 -3
- package/dist/cli/intercom-command.js +3 -3
- package/dist/cli/list-models.code.js +2 -2
- package/dist/cli/list-models.impl.js +3 -3
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/session-picker.code.js +2 -2
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +2 -2
- package/dist/cli/startup-ui.impl.js +3 -3
- package/dist/cli/startup-ui.js +3 -3
- package/dist/cli/storage-command.impl.js +3 -3
- package/dist/cli/storage-command.js +3 -3
- package/dist/cli/storage-search-session.code.js +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 +2 -2
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +2 -2
- package/dist/core/agent-session.d.ts +1 -0
- 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.code.js +1 -1
- package/dist/core/export-html/card-projection.impl.js +3 -3
- package/dist/core/export-html/card-projection.js +3 -3
- package/dist/core/export-html/index.code.js +2 -2
- package/dist/core/export-html/index.impl.js +3 -3
- package/dist/core/export-html/index.js +3 -3
- package/dist/core/export-html/json-spans.impl.js +3 -3
- package/dist/core/export-html/json-spans.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.code.js +1 -1
- package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.js +3 -3
- package/dist/core/export-html/tool-renderer.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/extensions/jiti-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-loader.js +3 -3
- package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-static-loader.js +3 -3
- package/dist/core/extensions/loader-host-modules.code.js +1 -1
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/extensions/loader-virtual-modules.js +2 -2
- package/dist/core/extensions/runner-context.js +1 -1
- package/dist/core/http-dispatcher.d.ts +2 -1
- package/dist/core/intercom-broker-control-host.code.js +1 -1
- package/dist/core/intercom-broker-control-host.impl.js +3 -3
- package/dist/core/intercom-broker-control-host.js +3 -3
- package/dist/core/intercom-broker-control.code.js +3 -3
- package/dist/core/intercom-broker-control.impl.js +3 -3
- package/dist/core/intercom-broker-control.js +3 -3
- package/dist/core/lock-takeover.d.ts +2 -0
- package/dist/core/model-config.d.ts +28 -0
- package/dist/core/model-registry.js +1 -1
- package/dist/core/model-runtime-streaming.d.ts +3 -2
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/provider-rate-limits.d.ts +17 -10
- package/dist/core/provider-request-admission.d.ts +16 -0
- package/dist/core/resume/blueprint/barrier.d.ts +6 -6
- package/dist/core/resume/blueprint/build.d.ts +3 -1
- package/dist/core/resume/blueprint/ledger.d.ts +3 -2
- package/dist/core/resume/blueprint/resume.d.ts +2 -1
- package/dist/core/retry-policy.d.ts +3 -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 +6 -6
- package/dist/core/session-manager-list.impl.js +3 -3
- package/dist/core/session-manager-list.js +3 -3
- package/dist/core/session-manager-types.d.ts +1 -1
- package/dist/core/session-manager.code.js +2 -2
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-open-markers.js +1 -1
- package/dist/core/session-storage.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/settings-duration.d.ts +3 -0
- package/dist/core/settings-manager-resource-accessors.d.ts +2 -1
- package/dist/core/settings-schema.d.ts +1 -0
- package/dist/core/storage/index.js +2 -2
- package/dist/core/storage/node-sqlite-file-gate.js +7 -6
- package/dist/core/storage/node-sqlite-file-gate.js.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +2 -2
- package/dist/core/storage/node-sqlite.js +2 -2
- 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.js +3 -0
- package/dist/core/storage/prefix.js.map +1 -1
- package/dist/core/storage/provider.js +2 -2
- 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 +24 -7
- package/dist/core/storage/session/child-reader.code.js.map +1 -1
- package/dist/core/storage/session/child-reader.impl.js +3 -3
- package/dist/core/storage/session/child-reader.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.code.js +1 -1
- package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.js +3 -3
- package/dist/core/storage/session/expanded-child-details.code.js +3 -3
- package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
- package/dist/core/storage/session/expanded-child-details.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.js +3 -3
- package/dist/core/storage/session/fork-row-index.impl.js +3 -3
- package/dist/core/storage/session/fork-row-index.js +3 -3
- package/dist/core/storage/session/fork-staging.code.js +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 +4 -4
- package/dist/core/storage/session/fork-window.impl.js +3 -3
- package/dist/core/storage/session/fork-window.js +3 -3
- package/dist/core/storage/session/history-pages.impl.js +3 -3
- package/dist/core/storage/session/history-pages.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.d.ts +2 -2
- package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.js +3 -3
- package/dist/core/storage/session/memory-session-store.d.ts +2 -2
- package/dist/core/storage/session/memory-session-store.impl.js +3 -3
- package/dist/core/storage/session/memory-session-store.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.js +3 -3
- package/dist/core/storage/session/released-history-files.code.js +4 -4
- package/dist/core/storage/session/released-history-files.impl.js +3 -3
- package/dist/core/storage/session/released-history-files.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.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/snapshot-cut.impl.js +3 -3
- package/dist/core/storage/session/snapshot-cut.js +3 -3
- package/dist/core/storage/session/snapshot-history.code.js +4 -4
- package/dist/core/storage/session/snapshot-history.impl.js +3 -3
- package/dist/core/storage/session/snapshot-history.js +3 -3
- package/dist/core/storage/session/sql-session-store.d.ts +13 -4
- 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.code.js +1 -1
- package/dist/core/storage/session/tree-presentation.impl.js +3 -3
- package/dist/core/storage/session/tree-presentation.js +3 -3
- package/dist/core/storage/session/types.d.ts +20 -2
- package/dist/core/storage/sqlite-facade.js +14 -13
- package/dist/core/storage/sqlite-facade.js.map +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.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/heartbeat.d.ts +1 -0
- package/dist/core/tasks/task-completion-entry.code.js +1 -1
- package/dist/core/tasks/task-completion-entry.impl.js +3 -3
- package/dist/core/tasks/task-completion-entry.js +3 -3
- package/dist/core/tasks/task-file-history.code.js +3 -3
- package/dist/core/tasks/task-file-history.impl.js +3 -3
- package/dist/core/tasks/task-file-history.js +3 -3
- package/dist/core/tasks/task-reference-archive.code.js +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/ask-user-question/ask-user-question.d.ts +1 -1
- package/dist/core/tools/history-session.d.ts +2 -0
- package/dist/core/tools/read-url.code.js +3 -3
- package/dist/core/tools/read-url.impl.js +3 -3
- package/dist/core/tools/read-url.js +3 -3
- package/dist/core/worktree-snapshot/blob-store.js +5 -6
- package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
- package/dist/core/worktree-snapshot/errors.code.js +3 -3
- package/dist/core/worktree-snapshot/errors.impl.js +3 -3
- package/dist/core/worktree-snapshot/errors.js +3 -3
- package/dist/core/worktree-snapshot/git.d.ts +2 -0
- 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 +6 -5
- package/dist/extensions/codemode/execute.code.js.map +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 +8 -4
- package/dist/extensions/mcp/cli.code.js.map +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 +6 -6
- package/dist/main-first-time-setup.code.js +2 -2
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.code.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.code.js +1 -1
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
- package/dist/modes/interactive/startup-shell-eligibility.js +1 -1
- package/dist/package-manager-cli.code.js +7 -7
- package/dist/package-manager-cli.impl.js +3 -3
- package/dist/package-manager-cli.js +3 -3
- package/dist/rpc-entry.js +1 -1
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/10.js +1 -1
- package/dist/startup-stages/11.js +1 -1
- package/dist/startup-stages/12.js +1 -1
- package/dist/startup-stages/13.js +1 -0
- package/dist/startup-stages/2.js +2 -6
- package/dist/startup-stages/3.js +6 -1
- package/dist/startup-stages/4.js +1 -1
- package/dist/startup-stages/5.js +12 -1
- package/dist/startup-stages/6.js +8 -4
- package/dist/startup-stages/7.js +4 -3
- package/dist/startup-stages/8.js +1 -5
- package/dist/startup-stages/9.js +5 -1
- package/dist/startup-stages/stages.json +1 -1
- package/dist/utils/startup-database-spare.code.js +3 -3
- package/dist/utils/startup-database-spare.impl.js +3 -3
- package/dist/utils/startup-database-spare.js +3 -3
- package/dist/utils/tools-manager.code.js +1 -1
- package/dist/utils/tools-manager.impl.js +3 -3
- package/dist/utils/tools-manager.js +3 -3
- package/dist/utils/windows-cwd.js +3 -3
- package/dist/utils/windows-cwd.js.map +1 -1
- package/docs/changelog.mdx +2 -10
- package/docs/codemode.md +5 -2
- package/docs/compaction/branch-summaries.md +1 -1
- package/docs/compaction/custom-compactors.md +1 -1
- package/docs/custom-provider/api-reference.md +1 -1
- package/docs/custom-provider/registration.md +3 -0
- package/docs/custom-provider/streaming.md +1 -1
- package/docs/environment-variables.md +2 -2
- package/docs/guides/resume-on-any-machine.md +1 -0
- package/docs/libraries/ai.md +4 -2
- package/docs/libraries/codemode.md +1 -1
- package/docs/models/choose-a-model.md +1 -1
- package/docs/models-configuration.md +5 -2
- package/docs/models.md +32 -0
- package/docs/providers.md +33 -1
- package/docs/sdk/structured-decisions.md +4 -2
- package/docs/sessions.md +1 -1
- package/docs/settings.md +78 -16
- package/docs/storage/postgres/tuning.md +1 -0
- package/docs/subagents/reference.md +2 -1
- package/docs/tools.md +4 -3
- package/docs/worktree-snapshots/reference.md +2 -0
- package/docs/worktree-snapshots.md +4 -0
- package/package.json +9 -9
- package/schemas/models.schema.json +21 -0
- package/schemas/settings.schema.json +14 -1
- package/dist/_shared/p1b-elig-TVB5CBLL.js.map +0 -1
- package/dist/_shared/startup-0-0-Q3MWKUK4.js.map +0 -1
- package/dist/_shared/startup-0-1-M6OWAYHH.js.map +0 -1
- package/dist/_shared/startup-0-2-2HUMCPKX.js.map +0 -1
- package/dist/_shared/startup-0-3-4ZYBYQNM.js.map +0 -1
- package/dist/_shared/startup-0-5-YDW47QX6.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob-store.js","sourceRoot":"","sources":["../../../src/core/worktree-snapshot/blob-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AACxF,OAAO,EAAE,+BAA+B,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAU/G,OAAO,EAAE,SAAS,EAAoE,MAAM,uBAAuB,CAAC;AACpH,OAAO,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAC3F,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACjH,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC9G,OAAO,EAA6B,eAAe,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACpH,OAAO,EAAE,sBAAsB,EAAiC,MAAM,iCAAiC,CAAC;AACxG,OAAO,EAAE,cAAc,EA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transactionFinisher } from \"../storage/added-exports.js\";\nimport { MAX_SEQUENCE_REQUEST_STATEMENTS, noteStorageSchemaTables } from \"../storage/added-exports-0-10-11.js\";\nimport type {\n\tSqliteDatabase,\n\tSqliteExecutor,\n\tSqliteRow,\n\tSqliteStatement,\n\tSqliteTransactionOptions,\n\tSqliteValue,\n\tStorageDescriptor,\n} from \"../storage/database.js\";\nimport { dialectOf, type StorageDialect, type StorageJsonSource, type StorageTrigger } from \"../storage/dialect.js\";\nimport { StorageTransientError, StorageWriteLockTimeoutError } from \"../storage/errors.js\";\nimport { applyStorageMigrations, ensureStorageSchema, withShortSchemaLockWaits } from \"../storage/migrations.js\";\nimport { renderStorageIdentifiers, storageMigrationTable, validateStoragePrefix } from \"../storage/prefix.js\";\nimport { type StorageSchemaCatalog, schemaCatalogOf, withStorageSchemaCatalog } from \"../storage/schema-catalog.js\";\nimport { queueSqliteSchemaSetup, type SqliteSchemaBatchContext } from \"../storage/sqlite-open-batch.js\";\nimport { statementBatch } from \"../storage/statement-batches.js\";\nimport type { BatchWrite } from \"../storage/statement-sequence.js\";\nimport type { WorkspaceCollectionError } from \"./errors.ts\";\nimport { forkInheritedBlobGuard, forkInheritedBlobGuardName } from \"./fork-blob-guard.ts\";\nimport {\n\tentriesIndexComplete,\n\tforkLinksCheck,\n\tforkSegmentsTable,\n\tforkSessionLink,\n\tlegacyForkLinksTriggerName,\n\tmaterializedForkLinks,\n\townDuplicate,\n\townParentSeq,\n\tparentColumns,\n\tsnapshotEntryCondition,\n} from \"./fork-snapshot-index.ts\";\nimport type { SnapshotBlob, SnapshotBlobStore, WorktreeSnapshot } from \"./types.ts\";\n\n/** A trigger or view, by its exact name. */\ninterface SchemaObject {\n\treadonly type: \"trigger\" | \"view\";\n\treadonly name: string;\n}\n\n/**\n * The key under which a failed rename's error carries the trigger or view that stopped it, once confirmed in the\n * database (#5622); `WorkspaceCollectionError` names it in its hint. A `Symbol.for` key, shared without an import.\n */\nconst RENAME_BLOCKER = Symbol.for(\"atomic-snapshots/rename-blocker@1\");\n\n/** What SQLite writes after an object's name when the object stops a schema change only once the change is made. */\nconst RENAME_BLOCKER_WHEN = [\" after rename\", \" after drop column\"];\n\n/**\n * Every trigger or view that `error`, a failed rename, or an error it wraps can name. SQLite names a trigger or view\n * that no longer compiles, such as one that refers to a dropped table, as `error in <type> <name>[ <when>]: <reason>`,\n * and drivers add their own prefix. The name is not quoted, so `error in view sales after rename: …` can name a view\n * `sales after rename` or a view `sales`, and a name can hold `: `. Only the database can tell which object it is.\n */\nfunction renameBlockerCandidates(error: unknown): SchemaObject[] {\n\tconst candidates: SchemaObject[] = [];\n\tlet current = error;\n\tfor (let depth = 0; depth < 8 && current instanceof Error; depth++, current = current.cause)\n\t\tfor (const match of current.message.matchAll(/\\berror in (trigger|view) /gu)) {\n\t\t\tconst type = match[1] as SchemaObject[\"type\"];\n\t\t\tconst rest = current.message.slice(match.index + match[0].length);\n\t\t\tfor (let end = rest.indexOf(\": \"); end !== -1; end = rest.indexOf(\": \", end + 1)) {\n\t\t\t\tconst name = rest.slice(0, end);\n\t\t\t\tcandidates.push({ type, name });\n\t\t\t\tfor (const when of RENAME_BLOCKER_WHEN)\n\t\t\t\t\tif (name.endsWith(when)) candidates.push({ type, name: name.slice(0, -when.length) });\n\t\t\t}\n\t\t}\n\treturn candidates;\n}\n\n/** Every blob hash a snapshot needs to be restored: its chain's patches and its bundle. */\nexport function snapshotBlobHashes(snapshot: WorktreeSnapshot): string[] {\n\tconst hashes = snapshot.chain.flatMap((link) => (link.patch === null ? [] : [link.patch]));\n\tif (snapshot.bundle) hashes.push(snapshot.bundle.blob);\n\treturn [...new Set(hashes)];\n}\n\n/**\n * Compares two blob hashes as `ORDER BY hash` with the dialect's `byteOrderCollation` does: the hashes are ASCII (hex\n * digests), whose UTF-16 code unit order is their byte order.\n */\nfunction byteOrder(first: string, second: string): number {\n\treturn first < second ? -1 : first > second ? 1 : 0;\n}\n\n/**\n * The blob hashes a recorded snapshot names, read as the reference index reads them: a write never fails on a record\n * whose chain or bundle is not well formed, which references nothing it cannot read.\n */\nfunction wellFormedBlobHashes(snapshot: WorktreeSnapshot): string[] {\n\tconst chain: readonly WorktreeSnapshot[\"chain\"][number][] = Array.isArray(snapshot?.chain) ? snapshot.chain : [];\n\tconst hashes = chain.flatMap((link) => (typeof link?.patch === \"string\" ? [link.patch] : []));\n\tif (typeof snapshot?.bundle?.blob === \"string\") hashes.push(snapshot.bundle.blob);\n\treturn hashes;\n}\n\nexport class MemorySnapshotBlobStore implements SnapshotBlobStore {\n\tprivate readonly blobs = new Map<string, Uint8Array>();\n\n\tasync putBlobs(blobs: readonly SnapshotBlob[]): Promise<void> {\n\t\tfor (const blob of blobs) if (!this.blobs.has(blob.hash)) this.blobs.set(blob.hash, Uint8Array.from(blob.data));\n\t}\n\tasync getBlob(hash: string): Promise<Uint8Array | undefined> {\n\t\tconst data = this.blobs.get(hash);\n\t\treturn data === undefined ? undefined : Uint8Array.from(data);\n\t}\n\tasync refreshBlobs(hashes: readonly string[]): Promise<boolean> {\n\t\treturn hashes.every((hash) => this.blobs.has(hash));\n\t}\n\tasync listBlobHashes(): Promise<readonly string[]> {\n\t\treturn [...this.blobs.keys()];\n\t}\n}\n\n/**\n * The tables of one blob table's reference index, all under the blob table's prefix. Triggers on the session store's\n * tables, and on the tables a workflow run journal of an earlier release left in the database, keep them current in the\n * same transaction as each write, so collection reads only these tables and never a journal or a session.\n */\nexport interface SnapshotIndexTables {\n\t/**\n\t * `(hash, bytes, data, created_at, chunks)`: one row per blob. A blob of at most {@link SNAPSHOT_BLOB_CHUNK_BYTES}\n\t * is in `data` (`chunks` 0, as every blob written before chunks was); a larger one has an empty `data` and its bytes\n\t * in `chunks` rows of {@link SnapshotIndexTables.blobChunks}.\n\t */\n\treadonly blobs: string;\n\t/**\n\t * `(hash, idx, data)`: the chunks of each blob larger than {@link SNAPSHOT_BLOB_CHUNK_BYTES}, in order (#4954). An\n\t * ordinary table whose primary key is an index of its own, never `WITHOUT ROWID` (#5541): see\n\t * {@link chunkTableDefinition}.\n\t */\n\treadonly blobChunks: string;\n\t/** `(run_id, hash)`: each blob a run's tool or stage checkpoints reference, once per run. */\n\treadonly runRefs: string;\n\t/** `(run_id, retained, seq)`: whether the run's latest status keeps its snapshots, from the event at `seq`. */\n\treadonly runState: string;\n\t/**\n\t * `(session_id, seq, root, snapshot_id, prev_seq, restore_from, restore_to, degraded_from, degraded_since)`: one row\n\t * per `worktree_snapshot` session entry, with the `seq` of the nearest snapshot entry before it on its branch and,\n\t * for the entry written when a snapshot was restored into a new worktree, the root it moved from and to. An entry of\n\t * a partly restored worktree names the snapshot it lacks in `degraded_from` (#4922), with `degraded_since`, on the\n\t * database clock, when the entries naming it began: the nearest snapshot entry before it's when that one names it\n\t * too, else when this entry was indexed.\n\t */\n\treadonly sessionRefs: string;\n\t/**\n\t * `(session_id, seq, entry_id, parent_id, anchor_seq, children, broken)`: one row per session entry, so that a\n\t * branch can be followed without reading entries: `anchor_seq` is the latest snapshot entry at or before the entry\n\t * on its branch, `children` counts its child entries (none: a leaf of the session tree), and `broken` marks an\n\t * entry whose parent the index could not follow, which makes the session keep every snapshot it records.\n\t */\n\treadonly sessionLinks: string;\n\t/** `(session_id, seq, snapshot_id, hash)`: the blobs of each snapshot record a session entry carries. */\n\treadonly sessionRecords: string;\n\t/**\n\t * `(owner, hash)`: the blobs of each snapshot that dispatched work carries (#4503), once per row that carries it: a\n\t * pool work row (owner `work:<id>`) or a root's pool binding (owner `root:<run id>`). A reference lasts as long as its\n\t * row, whatever any run's status.\n\t */\n\treadonly carriedRefs: string;\n\t/** One row: the last collection's claim on the database clock and its outcome. */\n\treadonly collection: string;\n\t/** `(source, watermark, backfilled_through)`: how far the index covers each table that holds references. */\n\treadonly sources: string;\n}\n\nexport function snapshotIndexTables(prefix = \"\"): SnapshotIndexTables {\n\tconst p = validateStoragePrefix(prefix);\n\treturn Object.freeze({\n\t\tblobs: `${p}snapshot_blobs`,\n\t\tblobChunks: `${p}snapshot_blob_chunks`,\n\t\trunRefs: `${p}snapshot_run_refs`,\n\t\trunState: `${p}snapshot_run_state`,\n\t\tsessionRefs: `${p}snapshot_session_refs`,\n\t\tsessionLinks: `${p}snapshot_session_links`,\n\t\tsessionRecords: `${p}snapshot_session_records`,\n\t\tcarriedRefs: `${p}snapshot_carried_refs`,\n\t\tcollection: `${p}snapshot_collection`,\n\t\tsources: `${p}snapshot_index_sources`,\n\t});\n}\n\n/**\n * The most bytes of a snapshot blob one row holds. A larger blob, such as the patch of a checkout with a large\n * untracked file, is stored as rows of at most this size, written in one transaction: a libSQL server refuses a value\n * or row over 5,000,000 bytes by default (sqld's `max_row_size`) and a response over 10 MB, so one row per blob failed\n * on it below the documented `maxFileBytes` (#4954). A different size needs a different table name, because a blob's\n * rows are addressed by their index.\n */\nexport const SNAPSHOT_BLOB_CHUNK_BYTES = 1024 * 1024;\n\n/** The schema domain of the blob table and its reference index, in the prefix's migration ledger. */\nexport const SNAPSHOT_BLOB_DOMAIN = \"snapshot-blobs\";\n\n/** Why collection left a legacy chunk table in place. Byte estimates are from the decision, before any partial copy was discarded. */\nexport type PendingChunkMove =\n\t| {\n\t\t\treadonly reason: \"free-space\";\n\t\t\treadonly remainingBytes: number;\n\t\t\treadonly requiredFreeBytes: number;\n\t\t\treadonly freeBytes: number;\n\t }\n\t| { readonly reason: \"space-unknown\"; readonly remainingBytes: number; readonly automaticLimitBytes: number };\n\nexport type SnapshotCollectionSkipReason = \"disabled\" | \"unsupported\" | \"in-progress\" | \"not-due\";\n\n/** How one automatic collection ended. Its promise never rejects: a failure is an outcome, reported once. */\nexport type SnapshotCollectionOutcome =\n\t| { readonly status: \"skipped\"; readonly reason: SnapshotCollectionSkipReason }\n\t| { readonly status: \"collected\"; readonly deleted: readonly string[]; readonly pendingChunkMove?: PendingChunkMove }\n\t/**\n\t * The storage closed, or its last store was released, before the collection finished; it stopped at its next batch\n\t * and what it deleted stays deleted.\n\t */\n\t| { readonly status: \"interrupted\"; readonly deleted: readonly string[] }\n\t| { readonly status: \"failed\"; readonly error: WorkspaceCollectionError };\n\n/** The prefix of every blob table identity in one database, for telling the tables of one database apart. */\nconst databaseIdentity = (descriptor: StorageDescriptor) => `${descriptor.adapter}\\0${descriptor.location}\\0`;\n\n/**\n * How an automatic collection waits, so that it never keeps its process alive: between batches, and before it tries\n * a write lock another connection holds again, on timers the process does not wait for. A process that has nothing\n * else to do exits at the next wait, which leaves only garbage, like a crash, and the next trigger after the claim\n * lease carries on. {@link keepProcessAlive} makes the process wait for the collection like any other work. A wait\n * ends at once when `signal` aborts, so an aborted collection stops without sleeping out its wait.\n */\nexport class BackgroundCollectionPace {\n\treadonly signal?: AbortSignal;\n\tprivate keepAlive = false;\n\tprivate pending?: ReturnType<typeof setTimeout>;\n\n\tconstructor(signal?: AbortSignal) {\n\t\tthis.signal = signal;\n\t}\n\n\t/**\n\t * Resolves after `milliseconds`, or as soon as the signal aborts, and unless the process exits first because it\n\t * has nothing else to do.\n\t */\n\twait(milliseconds: number): Promise<void> {\n\t\treturn new Promise((resolve) => {\n\t\t\tconst signal = this.signal;\n\t\t\tif (signal?.aborted) return resolve();\n\t\t\tconst done = () => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tsignal?.removeEventListener(\"abort\", done);\n\t\t\t\tthis.pending = undefined;\n\t\t\t\tresolve();\n\t\t\t};\n\t\t\tconst timer = setTimeout(done, milliseconds);\n\t\t\tsignal?.addEventListener(\"abort\", done, { once: true });\n\t\t\tif (!this.keepAlive) timer.unref();\n\t\t\tthis.pending = timer;\n\t\t});\n\t}\n\n\t/** Makes the process wait for the collection: the wait in progress and every later one. */\n\tkeepProcessAlive(): void {\n\t\tthis.keepAlive = true;\n\t\tthis.pending?.ref();\n\t}\n}\n\n/** An automatic collection this process is running, and how it waits. */\nexport interface RunningSnapshotCollection {\n\treadonly outcome: Promise<SnapshotCollectionOutcome>;\n\treadonly pace: BackgroundCollectionPace;\n\t/** Stops the collection at its next batch boundary, with `reason` as the abort reason. */\n\tabort(reason: Error): void;\n}\n\nconst collectionsRunning = new Map<string, RunningSnapshotCollection>();\n\n/** Records the automatic collection this process runs on `store`'s blob table, until it settles. */\nexport function trackSnapshotCollection(store: SqlSnapshotBlobStore, running: RunningSnapshotCollection): void {\n\tcollectionsRunning.set(store.identity, running);\n\tvoid running.outcome.then(() => collectionsRunning.delete(store.identity));\n}\n\n/** The automatic collection of `store`'s blob table that this process is running, if any. */\nexport function runningSnapshotCollectionOf(store: SqlSnapshotBlobStore): RunningSnapshotCollection | undefined {\n\treturn collectionsRunning.get(store.identity);\n}\n\n/**\n * Stops every automatic collection this process is running on a blob table of the database `descriptor` names, each at\n * its next batch boundary, with `reason` as the abort reason; a collection that stops this way ends `interrupted`.\n */\nexport function abortSnapshotCollectionsOn(descriptor: StorageDescriptor, reason: Error): void {\n\tconst prefix = databaseIdentity(descriptor);\n\tfor (const [identity, running] of collectionsRunning) if (identity.startsWith(prefix)) running.abort(reason);\n}\n\n/** Every automatic collection this process is running on a blob table of the database `descriptor` names. */\nexport function runningSnapshotCollectionsOn(descriptor: StorageDescriptor): Promise<SnapshotCollectionOutcome>[] {\n\tconst prefix = databaseIdentity(descriptor);\n\treturn [...collectionsRunning]\n\t\t.filter(([identity]) => identity.startsWith(prefix))\n\t\t.map(([, running]) => running.outcome);\n}\n\n/**\n * Resolves after the event loop has run its timers and I/O callbacks. The node:sqlite adapter commits an uncontended\n * transaction without ever returning to the loop, so a collection yields here between batches instead of holding\n * the host process for all of them.\n */\nconst yieldToEventLoop = () => new Promise<void>((resolve) => setImmediate(resolve));\n\n/**\n * How long the snapshot a resume restored only partly stays its checkout's restore target and is kept by collection\n * (#4922). Resume and capture count it from the partial restore; collection, on the database clock, from the first\n * session entry that names the snapshot, which never comes earlier.\n */\nexport const DEGRADED_RESTORE_RETENTION_DAYS = 30;\nconst DEGRADED_PIN_SECONDS = DEGRADED_RESTORE_RETENTION_DAYS * 24 * 60 * 60;\n\n/** Aged blobs one page of a collection examines, read from the age index in one statement. */\nexport const SNAPSHOT_COLLECTION_BATCH = 256;\n\n/**\n * The most blobs one delete batch of a collection deletes, in one write transaction (#5530). Deleting a blob also\n * deletes its chunks. On a chunk table an earlier release created `WITHOUT ROWID`, until collection moves it (#5541),\n * finding them reads whole chunks of the rows each seek compares: about 3.5 ms per blob on a large store with its\n * pages cached, so a batch of this many takes about 30 ms.\n * The transaction also checks again, in one statement, the sessions that reference the batch's blobs: at most\n * {@link SNAPSHOT_COLLECTION_SESSION_REFS} snapshot entries of them.\n */\nexport const SNAPSHOT_COLLECTION_DELETE_BATCH = 8;\n\n/**\n * The most snapshot entries of sessions one collection statement walks to find the snapshots those sessions retain\n * (#5530). Each session's retained snapshots are found by walking the snapshot entries on its open branches, about\n * 2 µs per entry with its pages cached, so a statement over this many takes a few milliseconds, and the event loop\n * gets a turn between statements. A session with more entries than this is walked in a statement of its own, and so\n * is a blob whose sessions hold more together when its delete batch checks them again.\n */\nexport const SNAPSHOT_COLLECTION_SESSION_REFS = 2_048;\n\n/**\n * The most bytes of legacy blobs one write transaction of a collection stamps or moves. A blob stored before blob ages\n * has an unknown age, which collection stamps; changing one column rewrites the whole row on SQLite, its\n * blob included, and holds the writer for as long as that takes, so a stamping transaction stops at this many bytes of\n * blobs. An in-row blob larger than {@link SNAPSHOT_BLOB_CHUNK_BYTES} is moved to chunks regardless of age,\n * at most this many bytes per transaction. Publishing frees its old value while holding the writer, with time\n * proportional to that value's size.\n */\nexport const SNAPSHOT_LEGACY_STAMP_BYTES = 16 * SNAPSHOT_BLOB_CHUNK_BYTES;\n\n/**\n * The most chunk rows one write transaction copies or frees while collection moves a chunk table an earlier release\n * created `WITHOUT ROWID` to the row layout (#5541). Each costs a read of its 1 MiB, cold on a first move, under the\n * write lock.\n */\nexport const SNAPSHOT_CHUNK_MOVE_ROWS = 4;\n\n/**\n * The free space a chunk table's move to the row layout leaves on the file system of a SQLite database file\n * beyond its copy, at least (#5694): the move starts only when the disk has room for the copy, its write-ahead log and\n * this much more, so other writes keep room on the disk.\n */\nexport const SNAPSHOT_CHUNK_MOVE_HEADROOM_BYTES = 64 * 1024 * 1024;\n\n// Four 1 MiB chunks per offline transaction, plus space for b-tree pages and WAL framing.\nconst OFFLINE_CHUNK_LOG_ALLOWANCE = 16 * SNAPSHOT_BLOB_CHUNK_BYTES;\n\n/**\n * Whether `error`, or a failure it wraps, says the database's disk is full or failed to read or write: SQLite's\n * `SQLITE_FULL` or `SQLITE_IOERR` and its extended codes (node:sqlite's `errcode`, libSQL's code or `rawCode`), as a\n * libSQL server answers when its disk fills, or PostgreSQL's `disk_full` (53100) or `io_error` (58030).\n */\nfunction isStorageSpaceFailure(error: unknown): boolean {\n\tconst seen = new Set<object>();\n\tfor (let cause = error; typeof cause === \"object\" && cause !== null && !seen.has(cause); ) {\n\t\tseen.add(cause);\n\t\tconst { code, errcode, rawCode } = cause as { code?: unknown; errcode?: unknown; rawCode?: unknown };\n\t\tif (typeof code === \"string\" && /^(?:SQLITE_FULL|SQLITE_IOERR(?:_\\w+)?|53100|58030)$/.test(code)) return true;\n\t\tconst number = errcode ?? rawCode;\n\t\tif (typeof number === \"number\" && ((number & 0xff) === 13 || (number & 0xff) === 10)) return true;\n\t\tcause = (cause as { cause?: unknown }).cause;\n\t}\n\treturn false;\n}\n\n/** Rows of one referencing table that one backfill transaction indexes. */\nexport const SNAPSHOT_INDEX_BACKFILL_BATCH = 500;\n\n/**\n * How long an unfinished collection's claim holds the database after its last batch, in seconds. Every batch renews\n * it, so a collection that stopped (killed, or its storage closed) is taken over after this lease, not after the\n * collection interval.\n */\nexport const SNAPSHOT_COLLECTION_LEASE_SECONDS = 120;\n\n/**\n * How long a background collection first waits before it tries a write lock another connection holds again, in\n * milliseconds. Each refusal doubles the wait, up to {@link SNAPSHOT_COLLECTION_LOCK_RETRY_MAX_MS}; once the waits add\n * up to the claim lease, the collection gives up with the lock's error, since another process may take over its claim.\n */\nexport const SNAPSHOT_COLLECTION_LOCK_RETRY_FIRST_MS = 10;\nexport const SNAPSHOT_COLLECTION_LOCK_RETRY_MAX_MS = 1_000;\n\nexport interface SnapshotIndexOptions {\n\treadonly signal?: AbortSignal;\n\t/** Renews this holder's claim in every batch, so a long collection keeps it. */\n\treadonly holder?: string;\n\t/**\n\t * Runs in the background: waits between batches, and for a write lock another connection holds, on `pace`, so the\n\t * process can exit meanwhile. Without it the collection waits like any other work of its caller.\n\t */\n\treadonly pace?: BackgroundCollectionPace;\n}\n\nexport interface SnapshotSweepOptions extends SnapshotIndexOptions {\n\treadonly graceSeconds: number;\n\t/** Called after each batch commits with the hashes it deleted. */\n\treadonly onBatch?: (deleted: readonly string[]) => void;\n\t/** The existing space check deferred layout maintenance; garbage collection itself succeeded. */\n\treadonly onPendingChunkMove?: (pending: PendingChunkMove) => void;\n}\n\ntype PageRow = SqliteRow & { created_at: number; hash: string };\n\n/**\n * How many whole seconds a blob's `created_at` must lie behind the database clock for the blob to be at least\n * `graceSeconds` old. Both count whole seconds, so a blob stored late in a second carries that second's start and can\n * be almost a second younger than the difference says; one second more keeps it for the whole window. 0 keeps none.\n */\nfunction collectableAge(graceSeconds: number): number {\n\treturn graceSeconds === 0 ? 0 : graceSeconds + 1;\n}\n\n/**\n * How long the light statements of a sweep, such as reading what walking a session costs, may hold the event loop\n * together before the sweep gives it a turn, in milliseconds. Counting a session's snapshot entries reads them: a few\n * milliseconds for a large session whose pages are not cached, so each session is counted in a statement of its own.\n */\nconst SWEEP_TURN_MS = 8;\n\n/**\n * How long a sweep goes without a write before it renews its claim in a transaction of its own: a quarter of the claim\n * lease, so pages with nothing to delete, which write nothing else, never let the lease run out.\n */\nconst SWEEP_CLAIM_RENEWAL_MS = (SNAPSHOT_COLLECTION_LEASE_SECONDS * 1_000) / 4;\n\n/** A blob a sweep may delete, with the sessions whose records reference it. */\ninterface SweepCandidate {\n\treadonly hash: string;\n\treadonly sessions: readonly string[];\n}\n\n/** Blobs a sweep deletes in one write transaction, with the sessions whose records referenced them when it walked them. */\ninterface SweepDeleteBatch {\n\treadonly hashes: readonly string[];\n\treadonly sessions: readonly string[];\n}\n\n/**\n * Groups `costs`' sessions, in order, into groups whose costs add up to at most {@link SNAPSHOT_COLLECTION_SESSION_REFS};\n * a session that costs more is a group of its own.\n */\nfunction sessionGroups(costs: ReadonlyMap<string, number>): string[][] {\n\tconst groups: string[][] = [];\n\tlet group: string[] = [];\n\tlet total = 0;\n\tfor (const [session, cost] of costs) {\n\t\tif (group.length > 0 && total + cost > SNAPSHOT_COLLECTION_SESSION_REFS) {\n\t\t\tgroups.push(group);\n\t\t\tgroup = [];\n\t\t\ttotal = 0;\n\t\t}\n\t\tgroup.push(session);\n\t\ttotal += cost;\n\t}\n\tif (group.length > 0) groups.push(group);\n\treturn groups;\n}\n\n/**\n * The turns of the event loop between the steps of a sweep that hold it, such as a statement that walks sessions, a\n * delete batch or a page: {@link next} gives the loop a turn when a step has held it since the last turn, then checks\n * the sweep's abort signal.\n */\nclass SweepTurns {\n\tprivate readonly signal?: AbortSignal;\n\tprivate readonly yieldTurn: () => Promise<void>;\n\tprivate holding = false;\n\tprivate turnedAt = performance.now();\n\n\tconstructor(options: { readonly signal?: AbortSignal }, yieldTurn: () => Promise<void>) {\n\t\tthis.signal = options.signal;\n\t\tthis.yieldTurn = yieldTurn;\n\t}\n\n\tasync next(): Promise<void> {\n\t\tif (this.holding) {\n\t\t\tthis.holding = false;\n\t\t\tawait this.yieldTurn();\n\t\t\tthis.turnedAt = performance.now();\n\t\t}\n\t\tthis.signal?.throwIfAborted();\n\t}\n\n\t/** Records that a step held the event loop since the last turn. */\n\theld(): void {\n\t\tthis.holding = true;\n\t}\n\n\t/** Gives the event loop a turn once the light steps since the last one have held it for {@link SWEEP_TURN_MS}. */\n\tasync light(): Promise<void> {\n\t\tif (performance.now() - this.turnedAt >= SWEEP_TURN_MS) this.holding = true;\n\t\tawait this.next();\n\t}\n}\n\n/**\n * What one sweep has read about the sessions that reference its candidates (#5530): how many snapshot entries walking\n * each costs, and the blobs the snapshots of those it walked retain. Only nominates candidates: each delete batch reads\n * its sessions again in its transaction.\n */\nclass SweepSessions {\n\tprivate readonly costs = new Map<string, number>();\n\tprivate readonly walked = new Set<string>();\n\tprivate readonly retained = new Set<string>();\n\n\t/** Which of `sessions` this sweep has not walked yet. */\n\tunwalked(sessions: Iterable<string>): string[] {\n\t\treturn [...new Set(sessions)].filter((session) => !this.walked.has(session));\n\t}\n\n\tcost(costs: ReadonlyMap<string, number>): void {\n\t\tfor (const [session, cost] of costs) this.costs.set(session, cost);\n\t}\n\n\t/** Records that `sessions` were walked and that their retained snapshots reference `hashes`. */\n\tretain(sessions: readonly string[], hashes: readonly string[]): void {\n\t\tfor (const session of sessions) this.walked.add(session);\n\t\tfor (const hash of hashes) this.retained.add(hash);\n\t}\n\n\tretains(hash: string): boolean {\n\t\treturn this.retained.has(hash);\n\t}\n\n\t/**\n\t * `candidates` in delete batches, in order, of at most {@link SNAPSHOT_COLLECTION_DELETE_BATCH} blobs whose sessions\n\t * cost at most {@link SNAPSHOT_COLLECTION_SESSION_REFS} to walk together; a candidate whose own sessions cost more\n\t * is a batch of its own.\n\t */\n\tbatches(candidates: readonly SweepCandidate[]): SweepDeleteBatch[] {\n\t\tconst batches: SweepDeleteBatch[] = [];\n\t\tlet batch: string[] = [];\n\t\tlet sessions = new Set<string>();\n\t\tlet total = 0;\n\t\tconst added = (candidate: SweepCandidate) =>\n\t\t\tcandidate.sessions.reduce(\n\t\t\t\t(sum, session) => (sessions.has(session) ? sum : sum + (this.costs.get(session) ?? 1)),\n\t\t\t\t0,\n\t\t\t);\n\t\tfor (const candidate of candidates) {\n\t\t\tif (\n\t\t\t\tbatch.length === SNAPSHOT_COLLECTION_DELETE_BATCH ||\n\t\t\t\t(batch.length > 0 && total + added(candidate) > SNAPSHOT_COLLECTION_SESSION_REFS)\n\t\t\t) {\n\t\t\t\tbatches.push({ hashes: batch, sessions: [...sessions] });\n\t\t\t\tbatch = [];\n\t\t\t\tsessions = new Set();\n\t\t\t\ttotal = 0;\n\t\t\t}\n\t\t\ttotal += added(candidate);\n\t\t\tbatch.push(candidate.hash);\n\t\t\tfor (const session of candidate.sessions) sessions.add(session);\n\t\t}\n\t\tif (batch.length > 0) batches.push({ hashes: batch, sessions: [...sessions] });\n\t\treturn batches;\n\t}\n}\n\n/**\n * A table whose rows reference snapshot blobs, with the triggers that index its future rows and the statements that\n * index the rows it already holds. Both are built from the same statements, so they cannot disagree.\n */\ninterface IndexSource {\n\treadonly name: string;\n\treadonly table: string;\n\t/** The triggers that index the table's future rows, in the order they are created. */\n\treadonly triggers: readonly StorageTrigger[];\n\t/** Each statement indexes the rows with `rowid > ? AND rowid <= ?`, bound in that order. */\n\treadonly backfill: readonly string[];\n\t/**\n\t * When set, rows are indexed one at a time in rowid order, each statement bound to the row's rowid, instead of by\n\t * `backfill`: a row's index depends on its parent's, which a statement over many rows cannot see.\n\t */\n\treadonly rowwise?: readonly string[];\n\t/** The fork segments table `rowwise` reads, where it links the entries of sessions with segments (#6560). */\n\treadonly segments?: string;\n\t/**\n\t * Of `rowwise`, what links a row linked already again (#6560): the statement that writes its link, the one that\n\t * writes it over for a session with fork segments, and the one that sets a snapshot entry's previous snapshot, its\n\t * parent's anchor. The children count, the snapshot's records and when a pin began stay.\n\t */\n\treadonly relink?: {\n\t\treadonly link: string;\n\t\treadonly fork?: string;\n\t\treadonly refs: string;\n\t\t/** `refs` for the rows session `?` stores from seq `?` on, in one statement. */\n\t\treadonly refsFrom: string;\n\t};\n\t/** The rows session `?` stores from seq `?` on, as `rowwise` yields one (#6560). */\n\treadonly entriesFrom?: string;\n\t/** Clears the source's index rows when its triggers are installed again, so no stale row outlives its entry. */\n\treadonly reset?: readonly string[];\n\t/**\n\t * The row that says the source's triggers index what this build's do, and that no build before 0.9.88 writes.\n\t * Without it, triggers of the source's names are an older build's, which index less, and this build installs its own\n\t * and indexes the table again (#5065). Builds 0.9.88 and 0.9.89 write it as `(0, 0)` when they install the triggers\n\t * and read only that it exists. This build writes it as {@link PUBLISHED_VERSION}, and on SQLite, which builds before\n\t * 0.9.88 also open, only once its own backfill of the source is done, so that builds 0.9.88 and 0.9.89 never trust\n\t * rows a build before 0.9.88 indexed during this build's backfill: they install their own triggers and index the\n\t * table again instead (#5558).\n\t */\n\treadonly version?: string;\n\t/**\n\t * The progress row of this build's own backfill of the source, which no older build writes (#5558). An older build\n\t * that takes this build's triggers for its own indexes the rows it backfills with statements that index less, and\n\t * advances only the source's row: the source is backfilled only once this row's progress reaches its watermark too,\n\t * and this build indexes those rows again. On SQLite, a source a build of 0.9.88 or 0.9.89 installed is trusted once\n\t * its backfill is done, as those builds index what this build does; one whose backfill is not done is indexed again\n\t * by this build from its first row, as a build before 0.9.88 may have indexed some of it.\n\t */\n\treadonly own?: string;\n\t/**\n\t * Text that the SQL of every trigger this build installs for the source holds, and no older build's does (#5558).\n\t * Builds 0.9.88 and 0.9.89 install triggers without it, and their pending trigger does not move {@link own} back. On\n\t * SQLite, which builds before 0.9.88 also open, an index this build installed is this build's only while every\n\t * trigger it has holds the text: such a build installs a lost trigger again, keeps the triggers it finds, some of\n\t * them the same SQL in every build, empties the index and indexes the table its way. Without the text everywhere,\n\t * this build indexes the table again. A takeover installs this build's triggers before its backfill relies on its\n\t * own progress.\n\t */\n\treadonly marker?: string;\n\t/**\n\t * Text that only this build's SQL of the trigger `trigger` holds. On SQLite, which older builds also open, a trigger\n\t * of that name without it is an older build's, installed after this build's went missing, so the source is indexed\n\t * again as an older build's (#5558).\n\t */\n\treadonly signature?: { readonly trigger: string; readonly text: string };\n}\n\ninterface SourceState {\n\treadonly source: IndexSource;\n\treadonly installed: boolean;\n\treadonly backfilled: boolean;\n\treadonly deferred: boolean;\n\t/** Installed by another build whose index this build does not trust: an upgrade, or an older build's again. */\n\treadonly foreign: boolean;\n\t/**\n\t * On SQLite, installed with {@link IndexSource.version} but not backfilled, as by a build of 0.9.88 or 0.9.89 whose\n\t * backfill is not done. This build's backfill removes the row, installs its own triggers and indexes the source again\n\t * from its first row (#5558).\n\t */\n\treadonly takeover: boolean;\n\treadonly retired?: readonly string[];\n}\n\n/**\n * The watermark and progress of a source's {@link IndexSource.version} row as this build writes it: on SQLite once its\n * own backfill of the source is done, on Postgres when it installs the source's triggers (#5558). Builds 0.9.88 and\n * 0.9.89 write the row as `(0, 0)`.\n */\nconst PUBLISHED_VERSION = 1;\n\n/** Receipts for physical session-index generations. Released builds read only their own source names. */\nexport const SESSION_INDEX_RETIRED_PREFIX = \"session-entries@retired:\";\ntype SessionIndexReset = (\n\ttx: SqliteExecutor,\n\ttables: SnapshotIndexTables,\n\ttriggers: readonly string[],\n) => Promise<boolean>;\n\n/**\n * A row that a development build marked a source with while it removed the source's index in batches. An index an\n * older build installed while it was there is never trusted as that build's finished index (#5558).\n */\nconst rebuildRow = (source: IndexSource) => `${source.name}@rebuild`;\n\nconst CHECKPOINT_EVENT = \"CheckpointRecorded\";\nconst STATUS_EVENTS = \"'RunStarted', 'StatusChanged'\";\nconst RELEASED_STATUSES = \"'completed', 'cancelled'\";\n/** The `seq` of a run state taken from the run's header status, which any start or status event replaces. */\nconst HEADER_SEQ = -1;\n\ntype Column = (name: string) => string;\nconst newRow: Column = (name) => `NEW.${name}`;\nconst oldRow: Column = (name) => `OLD.${name}`;\nconst storedRow: Column = (name) => name;\n\n/**\n * `test` on a payload that may not be JSON: SQLite does not promise to stop at the first false term of an AND, and\n * Postgres fails a cast of text that is not JSON.\n */\nconst whenValidJson = (d: StorageDialect, json: string, test: string) =>\n\t`CASE WHEN ${d.jsonValid(json)} THEN (${test}) ELSE ${d.literals.false} END`;\n\nconst triggerRows = (columns: readonly string[]) =>\n\t`(SELECT ${columns.map((name) => `NEW.${name} AS ${name}`).join(\", \")})`;\nconst storedRows = (d: StorageDialect, table: string, columns: readonly string[], condition: string) =>\n\t`(SELECT ${columns.join(\", \")} FROM ${table} WHERE ${d.rowOrder()} > ? AND ${d.rowOrder()} <= ? AND ${condition})`;\n\nfunction checkpointCondition(d: StorageDialect, column: Column): string {\n\tconst payload = column(\"payload\");\n\treturn `${column(\"type\")} = '${CHECKPOINT_EVENT}' AND ${d.contains(payload, `'\"worktreeSnapshots\"'`)} AND ${whenValidJson(\n\t\td,\n\t\tpayload,\n\t\t`${d.jsonText(payload, \"kind\")} IN ('tool', 'stage')`,\n\t)}`;\n}\n\nfunction statusCondition(d: StorageDialect, column: Column): string {\n\tconst payload = column(\"payload\");\n\treturn `${column(\"type\")} IN (${STATUS_EVENTS}) AND ${whenValidJson(\n\t\td,\n\t\tpayload,\n\t\t`${d.jsonHasType(\"text\", payload, \"workflowId\")} AND ${d.jsonHasType(\"text\", payload, \"status\")} AND ${d.jsonType(payload, \"completedCheckpoints\")} IN ('integer', 'real') AND ${d.jsonType(payload, \"pendingPrompts\")} IN ('integer', 'real')`,\n\t)}`;\n}\n\n/**\n * The SQL form of `isDurableWorkflowResumable` for the status payload `payload`, given that the run has a snapshot\n * reference and so at least one checkpoint: a root run keeps its snapshots while it is failed or blocked, or running or\n * paused, unless it was marked not resumable.\n */\nfunction retainedByStatus(d: StorageDialect, payload: string): string {\n\tconst root = d.jsonType(payload, \"rootWorkflowId\");\n\treturn `CASE\n\t\tWHEN ${root} IS NOT NULL AND (${root} <> 'text' OR ${d.jsonText(payload, \"rootWorkflowId\")} <> ${d.jsonText(payload, \"workflowId\")}) THEN 0\n\t\tWHEN ${d.jsonText(payload, \"status\")} IN ('failed', 'blocked', 'running', 'paused') THEN ${d.flag(d.isDistinct(d.jsonType(payload, \"resumable\"), \"'false'\"))}\n\t\tELSE 0\n\tEND`;\n}\n\n/** A trigger of the reference index: after `event` on `table`, when `when` holds for the row, it runs `statements`. */\nfunction createTrigger(\n\tname: string,\n\tevent: string,\n\ttable: string,\n\tstatements: readonly string[],\n\twhen?: string,\n): StorageTrigger {\n\tconst trigger = { name, table, timing: \"AFTER\", event, statements } as const;\n\treturn when === undefined ? trigger : { ...trigger, when };\n}\n\n/** A table whose rows each carry the snapshot that dispatched work restores its tree from (#4503). */\ninterface CarriedSnapshots {\n\treadonly name: string;\n\treadonly table: string;\n\t/** The prefix of each row's owner in {@link SnapshotIndexTables.carriedRefs}, before the row's `key`. */\n\treadonly owner: \"work\" | \"root\";\n\treadonly key: string;\n\t/** The JSON column that holds the snapshot, at the object keys `path` (none: the whole document). */\n\treadonly json: string;\n\treadonly path: readonly string[];\n\t/** Text `json` holds whenever its row carries a snapshot, so a row that carries none costs the index nothing. */\n\treadonly marker?: string;\n}\n\n/**\n * Indexes the blobs of the snapshot each row of `carried.table` carries as the row's references, from its insert until\n * its delete; an update of the snapshot replaces them. A row whose JSON the database cannot parse references nothing,\n * so a write never fails on the index. No statement inserts a reference that exists already: an upsert's update runs\n * its triggers under its own conflict policy, which overrides their `OR IGNORE`.\n */\nfunction carriedSource(d: StorageDialect, t: SnapshotIndexTables, carried: CarriedSnapshots): IndexSource {\n\tconst { table, key, json, path, marker } = carried;\n\tconst owner = (row: Column) => `'${carried.owner}:' || ${row(key)}`;\n\tconst carries = (row: Column) => (marker === undefined ? undefined : d.contains(row(json), `'${marker}'`));\n\tconst rowOf = (row: Column) =>\n\t\t`${owner(row)} AS owner, CASE WHEN ${d.jsonValid(row(json))} THEN ${row(json)} ELSE '{}' END AS snapshot`;\n\tconst snapshot = { column: \"r.snapshot\" };\n\tconst index = (rows: string) =>\n\t\t[\n\t\t\t{\n\t\t\t\tfrom: `, ${d.jsonEach(snapshot, \"link\", ...path, \"chain\")}`,\n\t\t\t\tlink: { ...snapshot, element: \"link\" },\n\t\t\t\tkeys: [\"patch\"],\n\t\t\t},\n\t\t\t{ from: \"\", link: snapshot, keys: [...path, \"bundle\", \"blob\"] },\n\t\t].map(({ from, link, keys }) => {\n\t\t\tconst hash = d.jsonAt(link, ...keys);\n\t\t\treturn d.insertOrIgnore(\n\t\t\t\tt.carriedRefs,\n\t\t\t\t[\"owner\", \"hash\"],\n\t\t\t\t`SELECT DISTINCT r.owner, ${hash} FROM ${rows} AS r${from} WHERE ${d.jsonAtIsText(link, ...keys)} AND NOT EXISTS (SELECT 1 FROM ${t.carriedRefs} AS held WHERE held.owner = r.owner AND held.hash = ${hash})`,\n\t\t\t);\n\t\t});\n\tconst inserted = `(SELECT ${rowOf(newRow)})`;\n\tconst release = `DELETE FROM ${t.carriedRefs} WHERE owner = ${owner(oldRow)}`;\n\tconst names = {\n\t\tinsert: `${table}_snapshot_carried_insert`,\n\t\tupdate: `${table}_snapshot_carried_update`,\n\t\tdelete: `${table}_snapshot_carried_delete`,\n\t};\n\treturn {\n\t\tname: carried.name,\n\t\ttable,\n\t\ttriggers: [\n\t\t\tcreateTrigger(names.insert, \"INSERT\", table, index(inserted), carries(newRow)),\n\t\t\tcreateTrigger(\n\t\t\t\tnames.update,\n\t\t\t\t`UPDATE OF ${json}`,\n\t\t\t\ttable,\n\t\t\t\t[release, ...index(inserted)],\n\t\t\t\tmarker === undefined ? undefined : `${carries(oldRow)} OR ${carries(newRow)}`,\n\t\t\t),\n\t\t\tcreateTrigger(names.delete, \"DELETE\", table, [release], carries(oldRow)),\n\t\t],\n\t\tbackfill: index(storedRows(d, table, [rowOf(storedRow)], carries(storedRow) ?? d.literals.true)),\n\t\treset: [`DELETE FROM ${t.carriedRefs} WHERE owner LIKE '${carried.owner}:%'`],\n\t};\n}\n\n/** The progress row of this build's own backfill of the session entries (#5558). */\nconst ENTRIES_OWN_PROGRESS = \"session-entries@own-progress\";\n\n/** `trigger`, its SQL holding `marker` in a comment that changes nothing it does (#5558). */\nfunction withMarker(trigger: StorageTrigger, marker: string): StorageTrigger {\n\tconst [first, ...rest] = trigger.statements;\n\treturn { ...trigger, statements: [`/* ${marker} */ ${first}`, ...rest] };\n}\n\n/**\n * The tables whose rows reference snapshot blobs, and how each is indexed. `forkSegments` names the sessions' fork\n * segments table when it exists (#6560): the backfill of the session entries then also links an entry whose parent\n * the session inherits, as the session store does when it writes one (`forkLinkWrites`).\n */\nfunction indexSources(\n\tprefix: string,\n\tt: SnapshotIndexTables,\n\td: StorageDialect,\n\tforkSegments?: string,\n): readonly IndexSource[] {\n\tconst { events, runs } = renderStorageIdentifiers(\"journal\", { events: \"events\", runs: \"runs\" }, prefix);\n\tconst { entries } = renderStorageIdentifiers(\"sessions\", { entries: \"entries\" }, prefix);\n\n\tconst payload = { column: \"r.payload\" };\n\tconst snapshot = { ...payload, element: \"snapshot\" };\n\tconst link = { ...payload, element: \"link\" };\n\tconst snapshots = d.jsonEach(payload, \"snapshot\", \"worktreeSnapshots\");\n\tconst runRefs = (rows: string) =>\n\t\t[\n\t\t\t{ from: `${snapshots}, ${d.jsonEach(snapshot, \"link\", \"chain\")}`, source: link, keys: [\"patch\"] },\n\t\t\t{ from: snapshots, source: snapshot, keys: [\"bundle\", \"blob\"] },\n\t\t].map(({ from, source, keys }) =>\n\t\t\td.insertOrIgnore(\n\t\t\t\tt.runRefs,\n\t\t\t\t[\"run_id\", \"hash\"],\n\t\t\t\t`SELECT r.run_id, ${d.jsonAt(source, ...keys)} FROM ${rows} AS r, ${from} WHERE ${d.jsonAtIsText(source, ...keys)}`,\n\t\t\t),\n\t\t);\n\tconst released = (status: string) => d.flag(`${status} NOT IN (${RELEASED_STATUSES})`);\n\tconst runState = (rows: string) =>\n\t\t`INSERT INTO ${t.runState} (run_id, retained, seq) SELECT r.run_id, ${retainedByStatus(d, \"r.payload\")}, r.seq FROM ${rows} AS r WHERE true ON CONFLICT (run_id) DO UPDATE SET retained = excluded.retained, seq = excluded.seq WHERE excluded.seq >= ${t.runState}.seq`;\n\tconst runHeader = (rows: string) =>\n\t\t`INSERT INTO ${t.runState} (run_id, retained, seq) SELECT r.run_id, ${released(\"r.status\")}, ${HEADER_SEQ} FROM ${rows} AS r WHERE true ON CONFLICT (run_id) DO NOTHING`;\n\tconst entryRow = (name: string) => `r.${name}`;\n\tconst entry = { column: \"r.entry_json\" };\n\tconst parentType = \"r.parent_type\";\n\tconst parentId = \"r.parent_id\";\n\tconst isSnapshot = snapshotEntryCondition(d, entryRow);\n\t// The parent is the first link before the entry with the parent's id, as `forkSessionLink` finds it (#6560).\n\tconst parentOf = (rows: string) =>\n\t\t`${rows} AS r LEFT JOIN ${t.sessionLinks} AS parent ON parent.session_id = r.session_id AND parent.seq = ${ownParentSeq(t.sessionLinks)}`;\n\t/**\n\t * Indexes one session entry's link in the session tree. `rows` yields that one entry as `r`. Only the links before\n\t * it count: its parent, an earlier entry of the same id, and the entries whose child it is, whose children it adds\n\t * to, once. A row linked again gets the same anchor and broken mark, so a session's rows linked in seq order end\n\t * the same whether a save or the index's rebuild linked them, and whatever links after them were there (#6560).\n\t */\n\tconst sessionLink = (rows: string) => [\n\t\t`UPDATE ${t.sessionLinks} SET children = children + 1 FROM ${rows} AS r WHERE ${t.sessionLinks}.session_id = r.session_id AND ${t.sessionLinks}.entry_id = ${parentId} AND ${parentType} = 'text' AND +${t.sessionLinks}.seq < r.seq AND NOT EXISTS (SELECT 1 FROM ${t.sessionLinks} AS own WHERE own.session_id = r.session_id AND own.seq = r.seq)`,\n\t\t`INSERT INTO ${t.sessionLinks} (session_id, seq, entry_id, parent_id, anchor_seq, children, broken)\n\t\t\tSELECT r.session_id, r.seq, r.entry_id, CASE WHEN ${parentType} = 'text' THEN ${parentId} END, CASE WHEN ${isSnapshot} THEN r.seq ELSE parent.anchor_seq END, 0, CASE WHEN ${ownDuplicate(t.sessionLinks)} THEN 1 WHEN ${parentType} IS NULL OR ${parentType} = 'null' THEN 0 WHEN parent.entry_id IS NOT NULL THEN parent.broken ELSE 1 END FROM ${parentOf(rows)} WHERE true\n\t\t\tON CONFLICT (session_id, seq) DO UPDATE SET anchor_seq = excluded.anchor_seq, broken = excluded.broken`,\n\t];\n\t/** Indexes a snapshot entry's reference and the blobs of its record; any other entry adds nothing. */\n\tconst sessionRecord = (rows: string) => {\n\t\tconst record = (source: StorageJsonSource, keys: readonly string[], from = \"\") =>\n\t\t\td.insertOrIgnore(\n\t\t\t\tt.sessionRecords,\n\t\t\t\t[\"session_id\", \"seq\", \"snapshot_id\", \"hash\"],\n\t\t\t\t`SELECT r.session_id, r.seq, ${d.jsonText(entry.column, \"snapshotId\")}, ${d.jsonAt(source, ...keys)} FROM ${rows} AS r${from} WHERE ${d.jsonAtIsText(source, ...keys)} AND ${isSnapshot}`,\n\t\t\t);\n\t\tconst restored = `${d.jsonHasType(\"text\", entry.column, \"restore\", \"from\")} AND ${d.jsonHasType(\"text\", entry.column, \"restore\", \"to\")}`;\n\t\tconst pinned = d.jsonHasType(\"text\", entry.column, \"degradedFrom\");\n\t\tconst degradedFrom = d.jsonText(entry.column, \"degradedFrom\");\n\t\t// A pin began with the first entry naming its snapshot; entries that go on naming it keep that start (#4922).\n\t\tconst degradedSince = `COALESCE((SELECT earlier.degraded_since FROM ${t.sessionRefs} AS earlier WHERE earlier.session_id = r.session_id AND earlier.seq = parent.anchor_seq AND earlier.degraded_from = ${degradedFrom}), ${d.nowSeconds})`;\n\t\treturn [\n\t\t\td.insertOrReplace(\n\t\t\t\tt.sessionRefs,\n\t\t\t\t[\n\t\t\t\t\t\"session_id\",\n\t\t\t\t\t\"seq\",\n\t\t\t\t\t\"root\",\n\t\t\t\t\t\"snapshot_id\",\n\t\t\t\t\t\"prev_seq\",\n\t\t\t\t\t\"restore_from\",\n\t\t\t\t\t\"restore_to\",\n\t\t\t\t\t\"degraded_from\",\n\t\t\t\t\t\"degraded_since\",\n\t\t\t\t],\n\t\t\t\t[\"session_id\", \"seq\"],\n\t\t\t\t`SELECT r.session_id, r.seq, ${d.jsonText(entry.column, \"root\")}, ${d.jsonText(entry.column, \"snapshotId\")}, parent.anchor_seq, CASE WHEN ${restored} THEN ${d.jsonText(entry.column, \"restore\", \"from\")} END, CASE WHEN ${restored} THEN ${d.jsonText(entry.column, \"restore\", \"to\")} END, CASE WHEN ${pinned} THEN ${degradedFrom} END, CASE WHEN ${pinned} THEN ${degradedSince} END FROM ${parentOf(rows)} WHERE ${isSnapshot}`,\n\t\t\t),\n\t\t\trecord({ ...entry, element: \"link\" }, [\"patch\"], `, ${d.jsonEach(entry, \"link\", \"snapshot\", \"chain\")}`),\n\t\t\trecord(entry, [\"snapshot\", \"bundle\", \"blob\"]),\n\t\t];\n\t};\n\n\tconst eventColumns = [\"run_id\", \"seq\", \"payload\"];\n\tconst eventsSource = {\n\t\tname: \"journal-events\",\n\t\ttable: events,\n\t\ttriggers: [\n\t\t\tcreateTrigger(\n\t\t\t\t`${events}_snapshot_refs`,\n\t\t\t\t\"INSERT\",\n\t\t\t\tevents,\n\t\t\t\trunRefs(triggerRows(eventColumns)),\n\t\t\t\tcheckpointCondition(d, newRow),\n\t\t\t),\n\t\t\tcreateTrigger(\n\t\t\t\t`${events}_snapshot_state`,\n\t\t\t\t\"INSERT\",\n\t\t\t\tevents,\n\t\t\t\t[runState(triggerRows(eventColumns))],\n\t\t\t\tstatusCondition(d, newRow),\n\t\t\t),\n\t\t],\n\t\tbackfill: [\n\t\t\t...runRefs(storedRows(d, events, eventColumns, checkpointCondition(d, storedRow))),\n\t\t\trunState(storedRows(d, events, eventColumns, statusCondition(d, storedRow))),\n\t\t],\n\t};\n\tconst headerColumns = [\"run_id\", \"status\"];\n\tconst runsSource = {\n\t\tname: \"journal-runs\",\n\t\ttable: runs,\n\t\ttriggers: [\n\t\t\tcreateTrigger(`${runs}_snapshot_state_insert`, \"INSERT\", runs, [runHeader(triggerRows(headerColumns))]),\n\t\t\tcreateTrigger(`${runs}_snapshot_state_status`, \"UPDATE OF status\", runs, [\n\t\t\t\t`UPDATE ${t.runState} SET retained = ${released(\"NEW.status\")} WHERE run_id = NEW.run_id AND seq = ${HEADER_SEQ}`,\n\t\t\t]),\n\t\t\tcreateTrigger(`${runs}_snapshot_refs_delete`, \"DELETE\", runs, [\n\t\t\t\t`DELETE FROM ${t.runRefs} WHERE run_id = OLD.run_id`,\n\t\t\t\t`DELETE FROM ${t.runState} WHERE run_id = OLD.run_id`,\n\t\t\t]),\n\t\t],\n\t\tbackfill: [runHeader(storedRows(d, runs, headerColumns, d.literals.true))],\n\t};\n\tconst entryColumns = [\"session_id\", \"seq\", \"entry_id\", \"entry_json\"];\n\t/** One entry as `r`, with its parent named once, so that each statement parses the entry's JSON for it only once. */\n\tconst triggerEntry = `(SELECT ${entryColumns.map((name) => `NEW.${name} AS ${name}`).join(\", \")}, ${parentColumns(d, \"NEW.entry_json\")})`;\n\tconst storedEntry = `(SELECT ${entryColumns.join(\", \")}, ${parentColumns(d, \"entry_json\")} FROM ${entries} WHERE ${d.rowOrder()} = ?)`;\n\t/** The rows session `?` stores from seq `?` on, as `storedEntry` yields one. */\n\tconst entriesFrom = `(SELECT ${entryColumns.join(\", \")}, ${parentColumns(d, \"entry_json\")} FROM ${entries} WHERE session_id = ? AND seq >= ?)`;\n\t/** Sets the previous snapshot of the references of `rows` to their parent's anchor: when a pin began stays. */\n\tconst refsAgain = (rows: string) =>\n\t\t`UPDATE ${t.sessionRefs} SET prev_seq = linked.anchor_seq FROM (SELECT r.session_id, r.seq, parent.anchor_seq FROM ${parentOf(rows)} WHERE ${isSnapshot}) AS linked WHERE ${t.sessionRefs}.session_id = linked.session_id AND ${t.sessionRefs}.seq = linked.seq`;\n\tconst indexComplete = entriesIndexComplete(t.sources);\n\tconst newRowOrder = d.rowOrder(\"NEW\");\n\tconst forkLink = (rows: string) =>\n\t\tforkSegments === undefined ? [] : [forkSessionLink(t.sessionLinks, forkSegments, rows, isSnapshot)];\n\tconst entriesSource = {\n\t\tname: \"session-entries\",\n\t\ttable: entries,\n\t\ttriggers: [\n\t\t\t// While the rows that existed first are indexed, new rows wait for that pass, which keeps parents ahead of\n\t\t\t// their children: the pass reaches them by extending its watermark. A row written at a rowid the pass has\n\t\t\t// already gone by, which SQLite reuses once the newest rows are deleted, moves the pass back to it; indexing\n\t\t\t// a row twice changes nothing.\n\t\t\tcreateTrigger(`${entries}_snapshot_links`, \"INSERT\", entries, sessionLink(triggerEntry), indexComplete),\n\t\t\tcreateTrigger(\n\t\t\t\t`${entries}_snapshot_refs`,\n\t\t\t\t\"INSERT\",\n\t\t\t\tentries,\n\t\t\t\tsessionRecord(triggerEntry),\n\t\t\t\t`${d.contains(\"NEW.entry_json\", `'\"worktree_snapshot\"'`)} AND ${indexComplete}`,\n\t\t\t),\n\t\t\tcreateTrigger(\n\t\t\t\t`${entries}_snapshot_pending`,\n\t\t\t\t\"INSERT\",\n\t\t\t\tentries,\n\t\t\t\t[\n\t\t\t\t\t`UPDATE ${t.sources} SET watermark = ${newRowOrder} WHERE source = 'session-entries' AND watermark < ${newRowOrder}`,\n\t\t\t\t\t`UPDATE ${t.sources} SET backfilled_through = ${newRowOrder} - 1 WHERE source = 'session-entries' AND backfilled_through >= ${newRowOrder}`,\n\t\t\t\t\t// This build's own progress follows, so an older build's backfill of these rows is never trusted (#5558).\n\t\t\t\t\t`UPDATE ${t.sources} SET watermark = ${newRowOrder} WHERE source = '${ENTRIES_OWN_PROGRESS}' AND watermark < ${newRowOrder}`,\n\t\t\t\t\t`UPDATE ${t.sources} SET backfilled_through = ${newRowOrder} - 1 WHERE source = '${ENTRIES_OWN_PROGRESS}' AND backfilled_through >= ${newRowOrder}`,\n\t\t\t\t],\n\t\t\t\t`NOT COALESCE(${indexComplete}, ${d.literals.true})`,\n\t\t\t),\n\t\t\tcreateTrigger(`${entries}_snapshot_refs_delete`, \"DELETE\", entries, [\n\t\t\t\t`UPDATE ${t.sessionLinks} SET children = children - 1 WHERE session_id = OLD.session_id AND children > 0 AND entry_id = (SELECT parent_id FROM ${t.sessionLinks} WHERE session_id = OLD.session_id AND seq = OLD.seq)`,\n\t\t\t\t`DELETE FROM ${t.sessionLinks} WHERE session_id = OLD.session_id AND seq = OLD.seq`,\n\t\t\t\t`DELETE FROM ${t.sessionRefs} WHERE session_id = OLD.session_id AND seq = OLD.seq`,\n\t\t\t\t`DELETE FROM ${t.sessionRecords} WHERE session_id = OLD.session_id AND seq = OLD.seq`,\n\t\t\t]),\n\t\t].map((trigger) => withMarker(trigger, ENTRIES_OWN_PROGRESS)),\n\t\tbackfill: [],\n\t\trowwise: [...sessionLink(storedEntry), ...forkLink(storedEntry), ...sessionRecord(storedEntry)],\n\t\t...(forkSegments === undefined ? {} : { segments: forkSegments }),\n\t\tentriesFrom,\n\t\trelink: {\n\t\t\tlink: sessionLink(storedEntry)[1]!,\n\t\t\t...(forkSegments === undefined ? {} : { fork: forkLink(storedEntry)[0]! }),\n\t\t\t// The reference's previous snapshot only: when a pin began stays as its first indexing recorded it.\n\t\t\trefs: refsAgain(storedEntry),\n\t\t\trefsFrom: refsAgain(entriesFrom),\n\t\t},\n\t\t// The triggers that index degraded pins (#4922). Older builds install theirs under the same names (#5065).\n\t\tversion: \"session-entries@degraded-pins\",\n\t\town: ENTRIES_OWN_PROGRESS,\n\t\tmarker: ENTRIES_OWN_PROGRESS,\n\t\tsignature: { trigger: `${entries}_snapshot_refs`, text: \"degraded_from\" },\n\t\treset: [`DELETE FROM ${t.sessionLinks}`, `DELETE FROM ${t.sessionRefs}`, `DELETE FROM ${t.sessionRecords}`],\n\t};\n\t// What a shared-placement root carries to its children (#4503): the snapshot each queued pool work row carries, and\n\t// the one of the root's own binding, which its pool records while it is prepared, children queued or not.\n\tconst workSource = carriedSource(d, t, {\n\t\tname: \"journal-pool-work\",\n\t\ttable: `${runs}_work`,\n\t\towner: \"work\",\n\t\tkey: \"id\",\n\t\tjson: \"descriptor\",\n\t\tpath: [\"execution\", \"workspaceSnapshot\"],\n\t\tmarker: '\"workspaceSnapshot\"',\n\t});\n\tconst rootSource = carriedSource(d, t, {\n\t\tname: \"journal-pool-root-snapshot\",\n\t\ttable: `${runs}_pool_root_snapshot`,\n\t\towner: \"root\",\n\t\tkey: \"root\",\n\t\tjson: \"snapshot\",\n\t\tpath: [],\n\t});\n\treturn [eventsSource, runsSource, entriesSource, workSource, rootSource];\n}\n\n/** What {@link relinkSessionEntries} and {@link linkStoredEntry} read and run. */\ninterface EntryLinking {\n\treadonly dialect: StorageDialect;\n\treadonly links: string;\n\treadonly entries: string;\n\t/** The sessions' fork segments table, where the statements link the entries of sessions with segments. */\n\treadonly segments: string | undefined;\n\t/** The statements that index one stored entry, bound to its row order: the session entries' `rowwise`. */\n\treadonly statements: readonly string[];\n\t/** Those that link a row linked already again: the session entries' `relink`. */\n\treadonly relink: NonNullable<IndexSource[\"relink\"]>;\n}\n\n/** The session entries' {@link EntryLinking} of `source`, with the dialect and links table it runs on. */\nfunction entryLinking(source: IndexSource, dialect: StorageDialect, links: string): EntryLinking {\n\treturn {\n\t\tdialect,\n\t\tlinks,\n\t\tentries: source.table,\n\t\tsegments: source.segments,\n\t\tstatements: source.rowwise!,\n\t\trelink: source.relink!,\n\t};\n}\n\n/**\n * Runs `statements` in order, each sent without waiting for the answer to the one before: a database runs a\n * connection's calls in the order they are made, and a pipelined connection sends them together.\n */\nasync function runInOrder(executor: SqliteExecutor, statements: readonly SqliteStatement[]): Promise<void> {\n\tawait Promise.all(statements.map(({ sql, params }) => executor.run(sql, ...params)));\n}\n\n/**\n * Links the rows session `sessionId` stores from seq `fromSeq` on again, in seq order, each behind the rows before it\n * (#6560), then counts their children again: an entry's children are the rows after it in the session whose parent\n * has its id. A materialization runs it once it copied rows in below the rows a fork appended, and the index's rebuild\n * when it meets a row stored before rows below it: both link every row as a save in seq order did.\n */\nasync function relinkSessionEntries(\n\texecutor: SqliteExecutor,\n\tlinking: EntryLinking,\n\tsessionId: string,\n\tfromSeq: number,\n): Promise<void> {\n\tconst { dialect, links, entries, segments, statements, relink } = linking;\n\tconst rows = await executor.all<SqliteRow & { id: number; linked: number; snapshot: number }>(\n\t\t`SELECT ${dialect.rowOrder(\"e\")} AS id,\n\t\t\tCASE WHEN EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = e.session_id AND l.seq = e.seq) THEN 1 ELSE 0 END AS linked,\n\t\t\tCASE WHEN ${dialect.contains(\"e.entry_json\", `'\"worktree_snapshot\"'`)} THEN 1 ELSE 0 END AS snapshot\n\t\tFROM ${entries} AS e WHERE e.session_id = ? AND e.seq >= ? ORDER BY e.seq`,\n\t\tsessionId,\n\t\tfromSeq,\n\t);\n\tconst forked =\n\t\tsegments !== undefined &&\n\t\trelink.fork !== undefined &&\n\t\t(await executor.get(`SELECT 1 AS found FROM ${segments} WHERE session_id = ? LIMIT 1`, sessionId)) !== undefined;\n\t// A row not linked yet gets every statement; one linked already only those that write its link and reference again.\n\tconst again = (snapshot: boolean) => [\n\t\trelink.link,\n\t\t...(forked ? [relink.fork!] : []),\n\t\t...(snapshot ? [relink.refs] : []),\n\t];\n\tawait runInOrder(\n\t\texecutor,\n\t\trows.flatMap(({ id, linked, snapshot }) =>\n\t\t\t(Number(linked) === 1 ? again(Number(snapshot) === 1) : statements).map((sql) => ({ sql, params: [id] })),\n\t\t),\n\t);\n\tconst linked = await executor.all<\n\t\tSqliteRow & { seq: number; entry_id: string; parent_id: string | null; children: number }\n\t>(\n\t\t`SELECT seq, entry_id, parent_id, children FROM ${links} WHERE session_id = ? AND seq >= ? ORDER BY seq DESC`,\n\t\tsessionId,\n\t\tfromSeq,\n\t);\n\tconst later = new Map<string, number>();\n\tconst counts: SqliteStatement[] = [];\n\tfor (const link of linked) {\n\t\tconst children = later.get(link.entry_id) ?? 0;\n\t\tif (Number(link.children) !== children)\n\t\t\tcounts.push({\n\t\t\t\tsql: `UPDATE ${links} SET children = ? WHERE session_id = ? AND seq = ?`,\n\t\t\t\tparams: [children, sessionId, Number(link.seq)],\n\t\t\t});\n\t\tif (link.parent_id !== null) later.set(link.parent_id, (later.get(link.parent_id) ?? 0) + 1);\n\t}\n\tawait runInOrder(executor, counts);\n}\n\n/**\n * Links, in seq order, every row session `sessionId` stores up to seq `seq` that is not linked yet, behind the rows of\n * its sources that its segments before `seq` name, which are linked first, the same way. Where the session has a row\n * linked already after the first row this links, the rows after it are linked again with it (see\n * {@link relinkSessionEntries}). A session linked this way has every row before a linked row linked, so the link of a\n * segment's last row tells that its source is linked through it.\n */\nasync function linkThrough(\n\texecutor: SqliteExecutor,\n\tlinking: EntryLinking,\n\tsessionId: string,\n\tseq: number,\n): Promise<void> {\n\tconst { dialect, links, entries, segments, statements } = linking;\n\tconst sources = async (through: number) => {\n\t\tif (segments === undefined) return;\n\t\tconst pending = await executor.all<SqliteRow & { source_id: string; to_seq: number }>(\n\t\t\t`SELECT seg.source_id, seg.to_seq FROM ${segments} AS seg WHERE seg.session_id = ? AND seg.base_seq < ? AND NOT EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = seg.source_id AND l.seq = seg.to_seq) ORDER BY seg.base_seq`,\n\t\t\tsessionId,\n\t\t\tthrough,\n\t\t);\n\t\tfor (const segment of pending) await linkThrough(executor, linking, segment.source_id, Number(segment.to_seq));\n\t};\n\tawait sources(seq);\n\tconst first = await executor.get<SqliteRow & { seq: number | null; later: number }>(\n\t\t`SELECT f.seq, CASE WHEN EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = ? AND l.seq > f.seq) THEN 1 ELSE 0 END AS later\n\t\tFROM (SELECT min(e.seq) AS seq FROM ${entries} AS e WHERE e.session_id = ? AND e.seq <= ? AND NOT EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = e.session_id AND l.seq = e.seq)) AS f`,\n\t\tsessionId,\n\t\tsessionId,\n\t\tseq,\n\t);\n\tif (first?.seq === null || first?.seq === undefined) return;\n\tif (Number(first.later) === 1) {\n\t\t// The rows after it were linked before it: they are linked again, behind it.\n\t\tawait relinkFrom(executor, linking, sessionId, Number(first.seq));\n\t\treturn;\n\t}\n\tconst rows = await executor.all<SqliteRow & { id: number }>(\n\t\t`SELECT ${dialect.rowOrder()} AS id FROM ${entries} WHERE session_id = ? AND seq >= ? AND seq <= ? ORDER BY seq`,\n\t\tsessionId,\n\t\tNumber(first.seq),\n\t\tseq,\n\t);\n\tawait runInOrder(\n\t\texecutor,\n\t\trows.flatMap(({ id }) => statements.map((sql) => ({ sql, params: [id] }))),\n\t);\n}\n\n/**\n * Links the rows session `sessionId` stores from seq `fromSeq` on again, behind the rows of the sources its segments\n * name, and then the rows of every session that reads them through a segment and has a row linked after them: such a\n * row took its parent's link, or its anchor, from the rows linked again (#6560).\n */\nasync function relinkFrom(\n\texecutor: SqliteExecutor,\n\tlinking: EntryLinking,\n\tsessionId: string,\n\tfromSeq: number,\n): Promise<void> {\n\tconst { links, segments } = linking;\n\tif (segments !== undefined) {\n\t\tconst pending = await executor.all<SqliteRow & { source_id: string; to_seq: number }>(\n\t\t\t`SELECT seg.source_id, seg.to_seq FROM ${segments} AS seg WHERE seg.session_id = ? AND NOT EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = seg.source_id AND l.seq = seg.to_seq) ORDER BY seg.base_seq`,\n\t\t\tsessionId,\n\t\t);\n\t\tfor (const segment of pending) await linkThrough(executor, linking, segment.source_id, Number(segment.to_seq));\n\t}\n\tawait relinkSessionEntries(executor, linking, sessionId, fromSeq);\n\tif (segments === undefined) return;\n\tconst readers = await executor.all<SqliteRow & { session_id: string; first: number }>(\n\t\t`SELECT seg.session_id, min(seg.base_seq + 1 + CASE WHEN seg.from_seq < ? THEN ? - seg.from_seq ELSE 0 END) AS first\n\t\tFROM ${segments} AS seg WHERE seg.source_id = ? AND seg.to_seq >= ? GROUP BY seg.session_id ORDER BY seg.session_id`,\n\t\tfromSeq,\n\t\tfromSeq,\n\t\tsessionId,\n\t\tfromSeq,\n\t);\n\tfor (const reader of readers) {\n\t\tconst linked = await executor.get(\n\t\t\t`SELECT 1 AS found FROM ${links} WHERE session_id = ? AND seq >= ? LIMIT 1`,\n\t\t\treader.session_id,\n\t\t\tNumber(reader.first),\n\t\t);\n\t\tif (linked !== undefined) await relinkFrom(executor, linking, reader.session_id, Number(reader.first));\n\t}\n}\n\n/**\n * Indexes the stored entry at row order `id`, as the index's backfill meets it. The backfill goes in row order, but a\n * fork that copied in the rows it read stores them after the entries it appended, and a fork moved onto another\n * session's copy reads rows stored after its own (#6560): a row with a row before it, of its session or of a source\n * its segments name, not linked yet, or with a row after it linked already, is linked by {@link linkThrough}, so every\n * row is linked behind the rows before it in its view, as a save links it.\n */\nasync function linkStoredEntry(executor: SqliteExecutor, linking: EntryLinking, id: number): Promise<void> {\n\tconst { dialect, links, entries, segments, statements } = linking;\n\tconst pendingSource =\n\t\tsegments === undefined\n\t\t\t? \"0\"\n\t\t\t: `CASE WHEN EXISTS (SELECT 1 FROM ${segments} AS seg WHERE seg.session_id = e.session_id AND seg.base_seq < e.seq AND NOT EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = seg.source_id AND l.seq = seg.to_seq)) THEN 1 ELSE 0 END`;\n\tconst row = await executor.get<\n\t\tSqliteRow & {\n\t\t\tsession_id: string;\n\t\t\tseq: number;\n\t\t\tlinked: number;\n\t\t\tlater: number;\n\t\t\tprevious: number | null;\n\t\t\tlinked_before: number | null;\n\t\t\tpending_source: number;\n\t\t}\n\t>(\n\t\t`SELECT e.session_id, e.seq,\n\t\t\tCASE WHEN EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = e.session_id AND l.seq = e.seq) THEN 1 ELSE 0 END AS linked,\n\t\t\tCASE WHEN EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = e.session_id AND l.seq > e.seq) THEN 1 ELSE 0 END AS later,\n\t\t\t(SELECT max(p.seq) FROM ${entries} AS p WHERE p.session_id = e.session_id AND p.seq < e.seq) AS previous,\n\t\t\t(SELECT max(l.seq) FROM ${links} AS l WHERE l.session_id = e.session_id AND l.seq < e.seq) AS linked_before,\n\t\t\t${pendingSource} AS pending_source\n\t\tFROM ${entries} AS e WHERE ${dialect.rowOrder(\"e\")} = ?`,\n\t\tid,\n\t);\n\tconst inOrder =\n\t\trow === undefined ||\n\t\tNumber(row.linked) === 1 ||\n\t\t(Number(row.later) === 0 &&\n\t\t\tNumber(row.pending_source) === 0 &&\n\t\t\t(row.previous === null || (row.linked_before !== null && Number(row.linked_before) === Number(row.previous))));\n\tif (inOrder) for (const sql of statements) await executor.run(sql, id);\n\telse await linkThrough(executor, linking, row.session_id, Number(row.seq));\n}\n\n/**\n * How a session store links the rows a materialization copies into a fork, and the forks it moves onto another\n * session's copy (#6560): see {@link sessionEntryLinks}.\n */\nexport interface SessionEntryLinks {\n\t/** The statement that links one piece of the rows a materialization copied: see `materializedForkLinks`. */\n\treadonly materialized: string;\n\t/**\n\t * Runs `before`, the writes of session `sessionId`'s new segments, and in the same request reads whether its links\n\t * from seq `fromSeq` on are what a save in seq order writes ({@link forkLinksCheck}). They are but in a few\n\t * histories, with entries that share an ID or name a parent after them: the session is then linked again from the\n\t * first row that is not, row by row, with the sessions that read it.\n\t */\n\tsettle(\n\t\texecutor: SqliteExecutor,\n\t\tsessionId: string,\n\t\tfromSeq: number,\n\t\tbefore: readonly SqliteStatement[],\n\t\thasSegments?: boolean,\n\t): Promise<void>;\n}\n\n/**\n * The {@link SessionEntryLinks} of a session store under `prefix` whose fork segments table is `forkSegments` (#6560).\n * Until the index's backfill of the session entries is done, which links the rows in seq order itself, `settle` only\n * writes the segments.\n */\nexport function sessionEntryLinks(prefix: string, dialect: StorageDialect, forkSegments: string): SessionEntryLinks {\n\tconst t = snapshotIndexTables(prefix);\n\tconst source = indexSources(prefix, t, dialect, forkSegments).find((source) => source.name === \"session-entries\")!;\n\tconst linking = entryLinking(source, dialect, t.sessionLinks);\n\tconst complete = entriesIndexComplete(t.sources);\n\tconst tables = { links: t.sessionLinks, segments: forkSegments, refs: t.sessionRefs };\n\tconst materializePlain = dialect.name === \"postgres\";\n\tconst checkWithSegments = forkLinksCheck(tables, complete, { hasSegments: true });\n\tconst checkWithoutSegments = forkLinksCheck(tables, complete, {\n\t\thasSegments: false,\n\t\tmaterialize: materializePlain,\n\t});\n\treturn {\n\t\tmaterialized: materializedForkLinks(t.sessionLinks, forkSegments, complete, dialect.types.int, dialect.name),\n\t\tasync settle(executor, sessionId, fromSeq, before, hasSegments = true) {\n\t\t\ttype Verdict = SqliteRow & { seq: number | null; children: number; refs: number };\n\t\t\tconst [, verdict] = await Promise.all([\n\t\t\t\trunInOrder(executor, before),\n\t\t\t\thasSegments\n\t\t\t\t\t? executor.get<Verdict>(checkWithSegments, sessionId, sessionId, fromSeq, sessionId, fromSeq)\n\t\t\t\t\t: materializePlain\n\t\t\t\t\t\t? executor.get<Verdict>(checkWithoutSegments, sessionId, fromSeq, sessionId, fromSeq)\n\t\t\t\t\t\t: executor.get<Verdict>(\n\t\t\t\t\t\t\t\tcheckWithoutSegments,\n\t\t\t\t\t\t\t\tsessionId,\n\t\t\t\t\t\t\t\tfromSeq,\n\t\t\t\t\t\t\t\tsessionId,\n\t\t\t\t\t\t\t\tfromSeq,\n\t\t\t\t\t\t\t\tsessionId,\n\t\t\t\t\t\t\t\tfromSeq,\n\t\t\t\t\t\t\t),\n\t\t\t]);\n\t\t\tif (verdict === undefined) return;\n\t\t\tconst children = Number(verdict.children) === 1;\n\t\t\tif (verdict.seq !== null || children)\n\t\t\t\tawait relinkFrom(executor, linking, sessionId, children ? fromSeq : Number(verdict.seq));\n\t\t\tif (verdict.seq !== null || children || Number(verdict.refs) === 1)\n\t\t\t\tawait executor.run(linking.relink.refsFrom, sessionId, fromSeq);\n\t\t},\n\t};\n}\n\n/**\n * Creates a chunk table named `table` unless it exists. An ordinary table, whose primary key is an index of its own:\n * a lookup reads that small index, then only the row it finds. A `WITHOUT ROWID` table, as earlier releases created,\n * keeps each row in its key's b-tree, so a seek reads the whole record of every 1 MiB row it compares on its way, and\n * every lookup, a delete's of a blob without chunks included, read several chunks (#5541). On Postgres both are the\n * same heap table.\n */\nfunction chunkTableDefinition(table: string, dialect: StorageDialect): string {\n\tconst { int, text, blob } = dialect.types;\n\treturn `CREATE TABLE IF NOT EXISTS ${table} (hash ${text} NOT NULL, idx ${int} NOT NULL, data ${blob} NOT NULL, PRIMARY KEY (hash, idx))${dialect.tableOptions}`;\n}\n\n/** The trigger that deletes a blob's chunks with it, in the statement that deletes it, whoever deletes it. */\nconst chunksDeleteTrigger = (t: SnapshotIndexTables) =>\n\tcreateTrigger(`${t.blobs}_chunks_delete_all`, \"DELETE\", t.blobs, [\n\t\t`DELETE FROM ${t.blobChunks} WHERE hash = OLD.hash`,\n\t]);\n\n/**\n * The tables of a chunk table's move to the row layout (#5541): `next`, the new table it fills, which then takes the\n * chunk table's name, and `retired`, the old table under its new name until it is emptied and dropped.\n */\nconst chunkMoveTables = (t: SnapshotIndexTables) =>\n\t({ next: `${t.blobChunks}_next`, retired: `${t.blobChunks}_retired` }) as const;\n\n/**\n * What {@link blobChunkWrites} reads once the chunk table exists: whether the blob table has its `chunks` column, and\n * whether the trigger that deletes a blob's chunks with it is there.\n */\nfunction blobChunkProbes(transaction: SqliteExecutor, t: SnapshotIndexTables, dialect: StorageDialect) {\n\tconst column = dialect.columnExists(t.blobs, \"chunks\");\n\tconst trigger = dialect.schemaObjects([`${t.blobs}_chunks_delete_all`]);\n\treturn [\n\t\tasync () => (await transaction.get(column.sql, ...column.params)) !== undefined,\n\t\tasync () => (await transaction.get(trigger.sql, ...trigger.params)) !== undefined,\n\t] as const;\n}\n\n/** The blob table's `chunks` column and the chunks' delete trigger, those of them that {@link blobChunkProbes} missed. */\nfunction blobChunkWrites(\n\tt: SnapshotIndexTables,\n\tdialect: StorageDialect,\n\t[column, trigger]: readonly [boolean, boolean],\n): BatchWrite[] {\n\treturn [\n\t\t!column && `ALTER TABLE ${t.blobs} ADD COLUMN chunks ${dialect.types.int} NOT NULL DEFAULT 0`,\n\t\t!trigger && dialect.dropTrigger(`${t.blobs}_chunks_delete`, t.blobs, true),\n\t\t!trigger && dialect.renderTrigger(chunksDeleteTrigger(t)),\n\t];\n}\n\n/**\n * Chunked blobs (#4954): the chunk table, the blob table's `chunks` column, 0 for a blob whose bytes are in its own row,\n * as every blob written before it was, and the trigger that deletes a blob's chunks with it. Idempotent.\n */\nasync function addBlobChunks(\n\ttransaction: SqliteExecutor,\n\tt: SnapshotIndexTables,\n\tdialect: StorageDialect,\n): Promise<void> {\n\tconst found = await statementBatch(\n\t\ttransaction,\n\t\t[chunkTableDefinition(t.blobChunks, dialect)],\n\t\tblobChunkProbes(transaction, t, dialect),\n\t);\n\tawait statementBatch(transaction, blobChunkWrites(t, dialect, found), []);\n}\n\n/**\n * Creates the blob table and the tables of its reference index that are missing, reading what each step needs\n * together, so on a SQLite file connection the setup waits for the connection's thread three times.\n */\nasync function createSnapshotIndexTables(\n\ttransaction: SqliteExecutor,\n\tt: SnapshotIndexTables,\n\tprefix: string,\n\tdialect: StorageDialect,\n\t/** Statements that run with the tables' own, in the same request: such as a ledger record of what they create. */\n\tafter: readonly string[] = [],\n): Promise<void> {\n\tconst { int, text, blob } = dialect.types;\n\tconst strict = dialect.tableOptions;\n\tconst keyed = dialect.withoutRowidTableOptions;\n\tconst ageColumn = dialect.columnExists(t.blobs, \"created_at\");\n\tconst [age] = await statementBatch(\n\t\ttransaction,\n\t\t[\n\t\t\t`CREATE TABLE IF NOT EXISTS ${t.blobs} (hash ${text} PRIMARY KEY, bytes ${int} NOT NULL, data ${blob} NOT NULL, created_at ${int} NOT NULL DEFAULT (${dialect.nowSeconds}))${strict}`,\n\t\t],\n\t\t[() => transaction.get<SqliteRow & { default_value: SqliteValue }>(ageColumn.sql, ...ageColumn.params)],\n\t);\n\tconst [column, trigger, ...refColumns] = await statementBatch(\n\t\ttransaction,\n\t\t[\n\t\t\t// Unknown ages are stamped in short collection batches, never by rewriting the table at open.\n\t\t\t!age && `ALTER TABLE ${t.blobs} ADD COLUMN created_at ${int} NOT NULL DEFAULT 0`,\n\t\t\t`\n\t\tCREATE TABLE IF NOT EXISTS ${t.runRefs} (run_id ${text} NOT NULL, hash ${text} NOT NULL, PRIMARY KEY (run_id, hash))${keyed};\n\t\tCREATE INDEX IF NOT EXISTS ${t.runRefs}_hash ON ${t.runRefs} (hash);\n\t\tCREATE TABLE IF NOT EXISTS ${t.runState} (run_id ${text} PRIMARY KEY, retained ${int} NOT NULL, seq ${int} NOT NULL)${keyed};\n\t\tCREATE TABLE IF NOT EXISTS ${t.sessionRefs} (session_id ${text} NOT NULL, seq ${int} NOT NULL, root ${text} NOT NULL, snapshot_id ${text} NOT NULL, prev_seq ${int}, restore_from ${text}, restore_to ${text}, degraded_from ${text}, degraded_since ${int}, PRIMARY KEY (session_id, seq))${keyed};\n\t\tCREATE TABLE IF NOT EXISTS ${t.sessionLinks} (session_id ${text} NOT NULL, seq ${int} NOT NULL, entry_id ${text} NOT NULL, parent_id ${text}, anchor_seq ${int}, children ${int} NOT NULL, broken ${int} NOT NULL, PRIMARY KEY (session_id, seq))${strict};\n\t\tCREATE INDEX IF NOT EXISTS ${t.sessionLinks}_entry ON ${t.sessionLinks} (session_id, entry_id);\n\t\t${sessionLinksLeafIndex(t, dialect)};\n\t\tCREATE INDEX IF NOT EXISTS ${t.sessionLinks}_broken ON ${t.sessionLinks} (session_id) WHERE broken = 1;\n\t\tCREATE TABLE IF NOT EXISTS ${t.sessionRecords} (session_id ${text} NOT NULL, seq ${int} NOT NULL, snapshot_id ${text} NOT NULL, hash ${text} NOT NULL, PRIMARY KEY (session_id, seq, hash))${keyed};\n\t\tCREATE INDEX IF NOT EXISTS ${t.sessionRecords}_hash ON ${t.sessionRecords} (hash);\n\t\tCREATE TABLE IF NOT EXISTS ${t.carriedRefs} (owner ${text} NOT NULL, hash ${text} NOT NULL, PRIMARY KEY (owner, hash))${keyed};\n\t\tCREATE INDEX IF NOT EXISTS ${t.carriedRefs}_hash ON ${t.carriedRefs} (hash);\n\t\tCREATE TABLE IF NOT EXISTS ${t.collection} (id ${int} PRIMARY KEY CHECK (id = 1), claimed_at ${int}, holder ${text}, finished_at ${int}, deleted ${int}, error_code ${text})${strict};\n\t\tINSERT INTO ${t.collection} (id) VALUES (1) ON CONFLICT DO NOTHING;\n\t\tCREATE TABLE IF NOT EXISTS ${t.sources} (source ${text} PRIMARY KEY, watermark ${int} NOT NULL, backfilled_through ${int} NOT NULL)${keyed};\n\t\t${after.map((statement) => `${statement};`).join(\"\\n\")}\n\t`,\n\t\t\tchunkTableDefinition(t.blobChunks, dialect),\n\t\t],\n\t\t[...blobChunkProbes(transaction, t, dialect), ...sessionRefColumnProbes(transaction, t, dialect)],\n\t);\n\tawait statementBatch(\n\t\ttransaction,\n\t\t[\n\t\t\t...blobChunkWrites(t, dialect, [column, trigger]),\n\t\t\t...(age && String(age.default_value) !== \"0\" ? blobMaintenanceIndexes(t) : []),\n\t\t\t...sessionRefColumnWrites(t, prefix, dialect, refColumns),\n\t\t],\n\t\t[],\n\t);\n}\n\n/** The indexes collection and the chunk-layout move look blobs up by. */\nfunction blobMaintenanceIndexes(t: SnapshotIndexTables): string[] {\n\treturn [\n\t\t`CREATE INDEX IF NOT EXISTS ${t.blobs}_age ON ${t.blobs} (created_at, hash)`,\n\t\t`CREATE INDEX IF NOT EXISTS ${t.blobs}_inline_size ON ${t.blobs} (chunks, hash) WHERE chunks = 0 AND length(data) > ${SNAPSHOT_BLOB_CHUNK_BYTES}`,\n\t];\n}\n\nasync function addBlobMaintenanceIndexes(transaction: SqliteExecutor, t: SnapshotIndexTables): Promise<void> {\n\tawait statementBatch(transaction, blobMaintenanceIndexes(t), []);\n}\n\n/**\n * The ledger step, `schema:snapshot-links-hot`, after which the session links table has no index that names\n * `children` on PostgreSQL ({@link hotSessionLinks}).\n */\nconst SESSION_LINKS_HOT_DOMAIN = \"snapshot-links-hot\";\n\nfunction sessionLinksHotSchema(prefix: string) {\n\treturn { ledger: storageMigrationTable(prefix), domain: SESSION_LINKS_HOT_DOMAIN, revision: 1 };\n}\n\n/**\n * The index the queries for the session tree's leaves read: on PostgreSQL every link with an anchor, whose leaves they\n * pick by `children = 0` ({@link hotSessionLinks}); elsewhere only the leaves with an anchor.\n */\nfunction sessionLinksLeafIndex(t: SnapshotIndexTables, dialect: StorageDialect): string {\n\treturn dialect.name === \"postgres\"\n\t\t? `CREATE INDEX IF NOT EXISTS ${t.sessionLinks}_anchored ON ${t.sessionLinks} (session_id, anchor_seq) WHERE anchor_seq IS NOT NULL`\n\t\t: `CREATE INDEX IF NOT EXISTS ${t.sessionLinks}_leaves ON ${t.sessionLinks} (session_id, anchor_seq) WHERE children = 0 AND anchor_seq IS NOT NULL`;\n}\n\n/** The ledger record of {@link hotSessionLinks}, for a database whose links table this transaction created with it. */\nfunction hotSessionLinksRecord(prefix: string, dialect: StorageDialect): string {\n\tconst { ledger, domain, revision } = sessionLinksHotSchema(prefix);\n\treturn `INSERT INTO ${ledger} (domain, version, applied_at) VALUES ('schema:${domain}', ${revision}, ${dialect.nowMs}) ON CONFLICT DO NOTHING`;\n}\n\n/**\n * Makes the update each append writes to its parent's session link a HOT update on PostgreSQL: one that stays on its\n * page and writes no index entry. Each append raises its parent link's `children`, and PostgreSQL updates a row in\n * place only when no index names a changed column, its condition included, which `_leaves` (`WHERE children = 0`)\n * did. So every append wrote the parent link's new version into each of the table's indexes. `_anchored` indexes the\n * same rows without that condition, and the queries for leaves, which only collection runs, check `children = 0` on\n * the rows it finds. Older builds read and write the table as before, and none of them creates `_leaves` again: on\n * PostgreSQL the step that creates it runs once per database. Recorded in the ledger, so it runs once. SQLite keeps\n * `_leaves`, as it updates rows in place whatever their indexes.\n */\nasync function hotSessionLinks(\n\ttransaction: SqliteExecutor,\n\tt: SnapshotIndexTables,\n\tprefix: string,\n\tdialect: StorageDialect,\n): Promise<void> {\n\tawait ensureStorageSchema(transaction, dialect, sessionLinksHotSchema(prefix), async () => {\n\t\tawait transaction.exec(sessionLinksLeafIndex(t, dialect));\n\t\tawait transaction.exec(`DROP INDEX IF EXISTS ${t.sessionLinks}_leaves`);\n\t});\n}\n\n/** This process's check of {@link hotSessionLinks} for each database, ledger and links table, while it holds. */\nconst hotSessionLinksChecks = new Map<string, Promise<boolean>>();\n\n/**\n * Runs {@link hotSessionLinks} on a PostgreSQL database whose ledger lacks it, in a transaction of its own. Nothing runs\n * where the catalog the open read records it, or where this role does not own the links table: a runtime role without\n * DDL opens as before, and `atomic storage migrate`, run as the owner, makes the change. A role that does not own the\n * table finds that out once per process, as for the fillfactor steps.\n */\nasync function ensureHotSessionLinks(database: SqliteDatabase, t: SnapshotIndexTables, prefix: string): Promise<void> {\n\tconst dialect = dialectOf(database);\n\tif (dialect.name !== \"postgres\" || database.readOnly === true) return;\n\tconst schema = sessionLinksHotSchema(prefix);\n\tif (await storageSchemaCurrent(database, schema)) return;\n\tconst identity = database.databaseIdentity?.();\n\tif (identity === undefined) {\n\t\tawait checkHotSessionLinks(database, t, prefix);\n\t\treturn;\n\t}\n\tconst key = JSON.stringify([identity, schema.ledger, t.sessionLinks]);\n\tlet check = hotSessionLinksChecks.get(key);\n\tif (check === undefined) {\n\t\tconst made = checkHotSessionLinks(database, t, prefix);\n\t\tcheck = made;\n\t\thotSessionLinksChecks.set(key, made);\n\t\tconst forget = () => {\n\t\t\tif (hotSessionLinksChecks.get(key) === made) hotSessionLinksChecks.delete(key);\n\t\t};\n\t\tmade.then((settled) => {\n\t\t\tif (!settled) forget();\n\t\t}, forget);\n\t}\n\tawait check;\n}\n\n/**\n * The largest links table, in bytes, an open builds {@link hotSessionLinks}'s index for in its own transaction, which\n * holds the table's writes for the build: about 150,000 links, a fraction of a second. A larger one is left to `atomic\n * storage migrate`, which builds the index without holding them ({@link SqlSnapshotBlobStore.buildHotSessionLinksIndex}).\n */\nconst HOT_SESSION_LINKS_OPEN_BUILD_BYTES = 16 * 1024 * 1024;\n/** How often {@link SqlSnapshotBlobStore.buildHotSessionLinksIndex} looks again at an index build another process runs. */\nconst HOT_SESSION_LINKS_BUILD_POLL_MS = 500;\n\n/** What {@link sessionLinksState} finds of the links table. */\ninterface SessionLinksState {\n\treadonly owned: boolean;\n\treadonly bytes: number;\n\t/** Whether `_anchored` exists and is valid; `false` for one a build that did not finish left. */\n\treadonly anchored: boolean | undefined;\n\t/** Whether an index of the table is being built right now. */\n\treadonly building: boolean;\n}\n\n/** The links table's owner, size and `_anchored` index, in one read; `undefined` when the table does not exist. */\nasync function sessionLinksState(\n\tdatabase: SqliteExecutor,\n\tt: SnapshotIndexTables,\n\tdialect: StorageDialect,\n): Promise<SessionLinksState | undefined> {\n\tconst row = await database.get<\n\t\tSqliteRow & {\n\t\t\towned: boolean | number;\n\t\t\tbytes: number | string;\n\t\t\tanchored: boolean | number | null;\n\t\t\tbuilding: boolean | number;\n\t\t}\n\t>(\n\t\t`SELECT pg_catalog.pg_has_role(current_user, c.relowner, 'USAGE') AS owned, pg_catalog.pg_relation_size(c.oid) AS bytes,\n\t\t\t(SELECT x.indisvalid FROM pg_catalog.pg_index x JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid\n\t\t\t\tWHERE x.indrelid = c.oid AND i.relname = ?) AS anchored,\n\t\t\tEXISTS (SELECT 1 FROM pg_catalog.pg_stat_progress_create_index p WHERE p.relid = c.oid) AS building\n\t\tFROM pg_catalog.pg_class c WHERE c.relnamespace = current_schema()::regnamespace AND c.relname = ?`,\n\t\tdialect.identifier(`${t.sessionLinks}_anchored`),\n\t\tdialect.identifier(t.sessionLinks),\n\t);\n\tif (row === undefined) return undefined;\n\tconst yes = (value: boolean | number | null) => value === true || Number(value) === 1;\n\treturn {\n\t\towned: yes(row.owned),\n\t\tbytes: Number(row.bytes),\n\t\tanchored: row.anchored === null ? undefined : yes(row.anchored),\n\t\tbuilding: yes(row.building),\n\t};\n}\n\n/**\n * Runs {@link hotSessionLinks} where this role owns a small links table; true when this process need not check again.\n * A large table, or one whose `_anchored` index a build of `atomic storage migrate` left unfinished or is making now,\n * is left to `atomic storage migrate`.\n */\nasync function checkHotSessionLinks(\n\tdatabase: SqliteDatabase,\n\tt: SnapshotIndexTables,\n\tprefix: string,\n): Promise<boolean> {\n\tconst dialect = dialectOf(database);\n\tconst found = await sessionLinksState(database, t, dialect);\n\tif (found === undefined) return false;\n\tif (!found.owned || found.bytes > HOT_SESSION_LINKS_OPEN_BUILD_BYTES || found.anchored === false || found.building)\n\t\treturn true;\n\tawait database.transaction((transaction) => hotSessionLinks(transaction, t, prefix, dialect), {\n\t\tretryTransientFailures: true,\n\t\tconcurrency: { kind: \"serial\", domain: sessionLinksHotSchema(prefix).ledger },\n\t});\n\treturn false;\n}\n\n/** The columns of {@link SnapshotIndexTables.sessionRefs} that later builds added, with their types. */\nconst SESSION_REF_COLUMNS = [\"prev_seq\", \"restore_from\", \"restore_to\", \"degraded_from\", \"degraded_since\"] as const;\n\n/** Whether the session references have each of {@link SESSION_REF_COLUMNS}, in its order. */\nfunction sessionRefColumnProbes(transaction: SqliteExecutor, t: SnapshotIndexTables, dialect: StorageDialect) {\n\treturn SESSION_REF_COLUMNS.map((name) => {\n\t\tconst column = dialect.columnExists(t.sessionRefs, name);\n\t\treturn async () => (await transaction.get(column.sql, ...column.params)) !== undefined;\n\t});\n}\n\n/**\n * Adds the columns of the session references that an index written by an earlier build lacks, as\n * {@link sessionRefColumnProbes} found them. Adding any drops the session entries' triggers and marks their index for\n * a rebuild, which collection runs before it deletes anything.\n */\nfunction sessionRefColumnWrites(\n\tt: SnapshotIndexTables,\n\tprefix: string,\n\tdialect: StorageDialect,\n\tfound: readonly boolean[],\n): BatchWrite[] {\n\tconst { int, text } = dialect.types;\n\tconst types: Record<(typeof SESSION_REF_COLUMNS)[number], string> = {\n\t\tprev_seq: int,\n\t\trestore_from: text,\n\t\trestore_to: text,\n\t\tdegraded_from: text,\n\t\tdegraded_since: int,\n\t};\n\tconst missing = SESSION_REF_COLUMNS.filter((_, index) => found[index] !== true);\n\tif (missing.length === 0) return [];\n\t// Mark the tree-aware rebuild durably, but leave its old rows untouched until completeIndex runs.\n\tconst source = indexSources(prefix, t, dialect).find((source) => source.name === \"session-entries\")!;\n\treturn [\n\t\t...missing.map((name) => `ALTER TABLE ${t.sessionRefs} ADD COLUMN ${name} ${types[name]}`),\n\t\t...source.triggers.map((trigger) => dialect.dropTrigger(trigger.name, trigger.table)),\n\t\t{\n\t\t\tsql: `INSERT INTO ${t.sources} (source, watermark, backfilled_through) VALUES (?, -1, -1) ${REPLACE_PROGRESS}`,\n\t\t\tparams: [source.name],\n\t\t},\n\t];\n}\n\n/** Adds the columns of the session references that an index written by an earlier build lacks; see above. */\nasync function addSessionRefColumns(\n\ttransaction: SqliteExecutor,\n\tt: SnapshotIndexTables,\n\tprefix: string,\n\tdialect: StorageDialect,\n): Promise<void> {\n\tconst found = await statementBatch(transaction, [], sessionRefColumnProbes(transaction, t, dialect));\n\tawait statementBatch(transaction, sessionRefColumnWrites(t, prefix, dialect, found), []);\n}\n\n/** Replaces a source's progress row: `sources` has no triggers or references, so this upsert is what a REPLACE did. */\nconst REPLACE_PROGRESS =\n\t\"ON CONFLICT (source) DO UPDATE SET watermark = excluded.watermark, backfilled_through = excluded.backfilled_through\";\n\n/** Installs `source`'s index triggers and records that rows above its current last row are indexed by them. */\nasync function installSource(\n\ttransaction: SqliteExecutor,\n\tdialect: StorageDialect,\n\tt: SnapshotIndexTables,\n\tsource: IndexSource,\n\treset?: SessionIndexReset,\n): Promise<void> {\n\tconst detached =\n\t\tsource.name === \"session-entries\" &&\n\t\t(await reset?.(\n\t\t\ttransaction,\n\t\t\tt,\n\t\t\tsource.triggers.map((trigger) => trigger.name),\n\t\t));\n\tconst withholds = withholdsVersion(dialect, source);\n\tconst [installed] = await statementBatch(\n\t\ttransaction,\n\t\t[\n\t\t\t...(detached\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t...(source.reset ?? []).map((sql) => ({ sql, params: [] })),\n\t\t\t\t\t\t// Triggers of these names that an older build installed are replaced, not kept (#5065): dropped in one\n\t\t\t\t\t\t// script, as they are created, so a source with more triggers costs a driver no more calls.\n\t\t\t\t\t\tsource.triggers.length > 0 &&\n\t\t\t\t\t\t\tsource.triggers\n\t\t\t\t\t\t\t\t.map((trigger) => `${dialect.dropTrigger(trigger.name, trigger.table)};`)\n\t\t\t\t\t\t\t\t.join(\"\\n\"),\n\t\t\t\t\t]),\n\t\t\tsource.triggers.map((trigger) => dialect.renderTrigger(trigger)).join(\"\\n\"),\n\t\t\t{\n\t\t\t\tsql: `INSERT INTO ${t.sources} (source, watermark, backfilled_through) SELECT ?, COALESCE(MAX(${dialect.rowOrder()}), 0), 0 FROM ${source.table} WHERE true ${REPLACE_PROGRESS}`,\n\t\t\t\tparams: [source.name],\n\t\t\t},\n\t\t\tsource.own !== undefined && {\n\t\t\t\tsql: `INSERT INTO ${t.sources} (source, watermark, backfilled_through) SELECT ?, watermark, 0 FROM ${t.sources} WHERE source = ? ${REPLACE_PROGRESS}`,\n\t\t\t\tparams: [source.own, source.name],\n\t\t\t},\n\t\t\t{ sql: `DELETE FROM ${t.sources} WHERE source = ?`, params: [rebuildRow(source)] },\n\t\t\tsource.version !== undefined && !withholds && publishVersion(t, source),\n\t\t],\n\t\t// A table with no row yet is backfilled as it is installed; any other is published once its backfill is done.\n\t\tsource.version !== undefined && withholds\n\t\t\t? [\n\t\t\t\t\t() =>\n\t\t\t\t\t\ttransaction.get<SqliteRow & { watermark: number }>(\n\t\t\t\t\t\t\t`SELECT watermark FROM ${t.sources} WHERE source = ?`,\n\t\t\t\t\t\t\tsource.name,\n\t\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t: [],\n\t);\n\tif (source.version === undefined || !withholds) return;\n\tawait statementBatch(\n\t\ttransaction,\n\t\t[\n\t\t\tNumber(installed?.watermark) === 0\n\t\t\t\t? publishVersion(t, source)\n\t\t\t\t: { sql: `DELETE FROM ${t.sources} WHERE source = ?`, params: [source.version] },\n\t\t],\n\t\t[],\n\t);\n}\n\n/**\n * Whether this build writes `source`'s {@link IndexSource.version} row only once its own backfill of the source is done:\n * on SQLite, which builds before 0.9.88 also open (#5558).\n */\nfunction withholdsVersion(dialect: StorageDialect, source: IndexSource): boolean {\n\treturn dialect.name === \"sqlite\" && source.version !== undefined && source.own !== undefined;\n}\n\n/** The statement that writes `source`'s version row as this build's, its own backfill of the source being done (#5558). */\nfunction publishVersion(t: SnapshotIndexTables, source: IndexSource): SqliteStatement {\n\treturn {\n\t\tsql: `INSERT INTO ${t.sources} (source, watermark, backfilled_through) VALUES (?, ?, ?) ${REPLACE_PROGRESS}`,\n\t\tparams: [source.version!, PUBLISHED_VERSION, PUBLISHED_VERSION],\n\t};\n}\n\n/**\n * Installs the index triggers of every referencing table that exists and lacks them, except a source whose rebuild is\n * deferred to collection. Installing again replaces nothing, so the step can run any number of times.\n */\nasync function installMissingSources(\n\ttransaction: SqliteExecutor,\n\tt: SnapshotIndexTables,\n\tprefix: string,\n\tdialect: StorageDialect,\n\treset?: SessionIndexReset,\n): Promise<void> {\n\tfor (const { source, installed, deferred } of await readSourceStates(\n\t\ttransaction,\n\t\tdialect,\n\t\tt,\n\t\tindexSources(prefix, t, dialect),\n\t)) {\n\t\tif (!installed && !deferred) await installSource(transaction, dialect, t, source, reset);\n\t}\n}\n\n/** The names of `sources`' tables and triggers, whose presence `readSourceStates` reads. */\nfunction sourceObjectNames(sources: readonly IndexSource[]): string[] {\n\treturn sources.flatMap((source) => [source.table, ...source.triggers.map((trigger) => trigger.name)]);\n}\n\n/** The read of every source's progress rows. */\nfunction sourceProgressRead(t: SnapshotIndexTables): SqliteStatement {\n\treturn { sql: `SELECT source, watermark, backfilled_through FROM ${t.sources}`, params: [] };\n}\n\n/**\n * Which referencing tables exist, whether each has all its triggers and a source row, and whether its backfill is done.\n * `present`, when given, holds every table and trigger of `sources`, as an open's catalog found them: the objects are\n * not read then (#6560).\n */\nasync function readSourceStates(\n\texecutor: SqliteExecutor,\n\tdialect: StorageDialect,\n\tt: SnapshotIndexTables,\n\tsources: readonly IndexSource[],\n\tlistRetired = false,\n\tpresent?: ReadonlySet<string>,\n\talso?: { readonly names: readonly string[]; readonly found: Set<string> },\n): Promise<SourceState[]> {\n\t// `also` asks, in the same statement, which of other objects exist, as `also.found` tells.\n\tconst names = [...sourceObjectNames(sources), ...(also?.names ?? [])];\n\t// Builds before 0.9.88 open SQLite databases only, so only there can a trigger of this build's name be\n\t// one that indexes less.\n\tconst sqlite = dialect.name === \"sqlite\";\n\tconst signatures = sqlite ? sources.flatMap((source) => source.signature ?? []) : [];\n\tconst markers = sqlite\n\t\t? sources.flatMap((source) =>\n\t\t\t\tsource.marker === undefined\n\t\t\t\t\t? []\n\t\t\t\t\t: source.triggers.map((trigger) => ({ trigger: trigger.name, text: source.marker! })),\n\t\t\t)\n\t\t: [];\n\tconst holds = (checks: readonly { readonly trigger: string; readonly text: string }[]) =>\n\t\tchecks.length === 0 ? \"NULL\" : `CASE ${checks.map(() => \"WHEN name = ? THEN instr(sql, ?) > 0\").join(\" \")} END`;\n\tconst objects =\n\t\tsignatures.length + markers.length === 0\n\t\t\t? dialect.schemaObjects(names)\n\t\t\t: {\n\t\t\t\t\tsql: `SELECT name, ${holds(signatures)} AS signed, ${holds(markers)} AS marked FROM sqlite_schema WHERE name IN (${names.map(() => \"?\").join(\", \")})`,\n\t\t\t\t\tparams: [...signatures, ...markers].flatMap((check) => [check.trigger, check.text]).concat(names),\n\t\t\t\t};\n\tconst progressRead = sourceProgressRead(t);\n\ttype ObjectRow = SqliteRow & { name: string; signed?: number | null; marked?: number | null };\n\t// Read together: the progress rows do not depend on the objects.\n\tconst [objectRows, progressRows] = await statementBatch(\n\t\texecutor,\n\t\t[],\n\t\t[\n\t\t\t() =>\n\t\t\t\tpresent === undefined\n\t\t\t\t\t? executor.all<ObjectRow>(objects.sql, ...objects.params)\n\t\t\t\t\t: Promise.resolve(names.filter((name) => present.has(name)).map((name): ObjectRow => ({ name }))),\n\t\t\t() =>\n\t\t\t\texecutor.all<SqliteRow & { source: string; watermark: number; backfilled_through: number }>(\n\t\t\t\t\tprogressRead.sql,\n\t\t\t\t\t...progressRead.params,\n\t\t\t\t),\n\t\t],\n\t);\n\tconst found = new Set(objectRows.map((row) => row.name));\n\tfor (const name of also?.names ?? []) if (found.has(name)) also?.found.add(name);\n\t// Whether each checked trigger's SQL holds this build's text; every other object reads null.\n\tconst checked = (column: \"signed\" | \"marked\") =>\n\t\tnew Map(\n\t\t\tobjectRows\n\t\t\t\t.filter((row) => row[column] !== null && row[column] !== undefined)\n\t\t\t\t.map((row) => [row.name, Number(row[column]) === 1]),\n\t\t);\n\tconst signed = checked(\"signed\");\n\tconst marked = checked(\"marked\");\n\tlet retired: string[] | undefined;\n\tconst progress = new Map(\n\t\tprogressRows.map((row) => {\n\t\t\tif (\n\t\t\t\tlistRetired &&\n\t\t\t\tsqlite &&\n\t\t\t\trow.source.startsWith(SESSION_INDEX_RETIRED_PREFIX) &&\n\t\t\t\tNumber(row.backfilled_through) === 0\n\t\t\t) {\n\t\t\t\tretired ??= [];\n\t\t\t\tretired.push(row.source);\n\t\t\t}\n\t\t\treturn [row.source, row] as const;\n\t\t}),\n\t);\n\treturn sources\n\t\t.filter((source) => found.has(source.table))\n\t\t.map((source) => {\n\t\t\tconst row = progress.get(source.name);\n\t\t\tconst version = source.version === undefined ? undefined : progress.get(source.version);\n\t\t\tconst own = source.own === undefined ? undefined : progress.get(source.own);\n\t\t\tconst ownDone =\n\t\t\t\town !== undefined && row !== undefined && Number(own.backfilled_through) >= Number(row.watermark);\n\t\t\t// An index an older build installed while a rebuild row was there, which 0.9.87 may have indexed since (#5558).\n\t\t\tconst reinstalled = row !== undefined && progress.has(rebuildRow(source));\n\t\t\t// On SQLite, a reference trigger without this build's text is a build's before 0.9.88, installed after this\n\t\t\t// build's went missing (#5558).\n\t\t\tconst unsigned = source.signature !== undefined && signed.get(source.signature.trigger) === false;\n\t\t\t// Every trigger the source has is this build's. One a build before 0.9.88 installed again after it went\n\t\t\t// missing is not, even when its SQL is the same in every build otherwise (#5558).\n\t\t\tconst mine =\n\t\t\t\tsource.marker !== undefined &&\n\t\t\t\tsource.triggers.every((trigger) => !found.has(trigger.name) || marked.get(trigger.name) === true);\n\t\t\tlet foreign: boolean;\n\t\t\t// Whether the backfill is done for this build, besides the source's own progress row.\n\t\t\tlet trusted: boolean;\n\t\t\tif (withholdsVersion(dialect, source)) {\n\t\t\t\t// This build's install whose backfill is not done yet, which holds back the version row (#5558).\n\t\t\t\tconst pending = version === undefined && own !== undefined && mine;\n\t\t\t\t// A row of 0 is a build of 0.9.88 or 0.9.89's, whose finished backfill indexed what this build's does, unless\n\t\t\t\t// it installed the index while a rebuild row was there: this build takes it over then. This build publishes\n\t\t\t\t// its own once its own progress reaches the watermark, which it must still hold.\n\t\t\t\tconst published = version !== undefined && Number(version.watermark) === PUBLISHED_VERSION;\n\t\t\t\tforeign = unsigned || (version === undefined && !pending) || (published && !mine);\n\t\t\t\ttrusted = published ? ownDone : version !== undefined && !reinstalled;\n\t\t\t} else {\n\t\t\t\t// A source whose triggers an older build installed is indexed again by collection, as after an upgrade.\n\t\t\t\tforeign = unsigned || (source.version !== undefined && version === undefined) || reinstalled;\n\t\t\t\t// Rows an older build indexed with its statements past this build's own progress are not backfilled.\n\t\t\t\ttrusted = own === undefined || ownDone;\n\t\t\t}\n\t\t\tconst installed =\n\t\t\t\trow !== undefined &&\n\t\t\t\t!foreign &&\n\t\t\t\tNumber(row.watermark) >= 0 &&\n\t\t\t\tsource.triggers.every((trigger) => found.has(trigger.name));\n\t\t\tconst backfilled =\n\t\t\t\trow !== undefined &&\n\t\t\t\t!foreign &&\n\t\t\t\ttrusted &&\n\t\t\t\tNumber(row.watermark) >= 0 &&\n\t\t\t\tNumber(row.backfilled_through) >= Number(row.watermark);\n\t\t\treturn {\n\t\t\t\tsource,\n\t\t\t\tinstalled,\n\t\t\t\tbackfilled,\n\t\t\t\tdeferred: row !== undefined && (foreign || Number(row.watermark) === -1),\n\t\t\t\tforeign,\n\t\t\t\ttakeover: withholdsVersion(dialect, source) && installed && version !== undefined && !backfilled,\n\t\t\t\t...(retired && source.name === \"session-entries\" ? { retired } : {}),\n\t\t\t};\n\t\t});\n}\n\n/**\n * The `<prefix>snapshot_blobs` table and its reference index, shared by the session stores of one database. The index\n * also counts the references a workflow run journal of an earlier release holds in the same database, so collection\n * never deletes a blob such a run still needs.\n */\nexport class SqlSnapshotBlobStore implements SnapshotBlobStore {\n\tprivate readonly database: SqliteDatabase;\n\tprivate readonly tables: SnapshotIndexTables;\n\tprivate sources: readonly IndexSource[];\n\tprivate readonly dialect: StorageDialect;\n\t/** The sessions' fork segments table (#6560), which exists once shared-history forks are on. */\n\tprivate readonly forkSegments: string;\n\treadonly table: string;\n\n\tprivate constructor(\n\t\tdatabase: SqliteDatabase,\n\t\tdialect: StorageDialect,\n\t\ttables: SnapshotIndexTables,\n\t\tsources: readonly IndexSource[],\n\t\tforkSegments = forkSegmentsTable(),\n\t) {\n\t\tthis.database = database;\n\t\tthis.dialect = dialect;\n\t\tthis.tables = tables;\n\t\tthis.sources = sources;\n\t\tthis.forkSegments = forkSegments;\n\t\tthis.table = tables.blobs;\n\t}\n\n\t/** Which table this store collects, for telling stores of one database and prefix apart from others. */\n\tget identity(): string {\n\t\treturn `${databaseIdentity(this.database.descriptor)}${this.table}`;\n\t}\n\n\t/**\n\t * Opens the blob table and its reference index, creating the tables that are missing in their own transaction, such\n\t * as those an index written by an earlier build lacks, and indexes referencing tables created since. A store whose\n\t * tables and index exist opens without the write lock. On SQLite inside an open scope (`withStorageSchemaCatalog`),\n\t * table creation and index installation queue into the open's single write transaction (#6709).\n\t */\n\tstatic open(database: SqliteDatabase, prefix = \"\"): Promise<SqlSnapshotBlobStore> {\n\t\treturn withStorageSchemaCatalog(database, storageMigrationTable(prefix), () =>\n\t\t\tSqlSnapshotBlobStore.openWithCatalog(database, prefix),\n\t\t);\n\t}\n\n\tprivate static async openWithCatalog(database: SqliteDatabase, prefix: string): Promise<SqlSnapshotBlobStore> {\n\t\tconst t = snapshotIndexTables(prefix);\n\t\tconst dialect = dialectOf(database);\n\t\tconst ledger = storageMigrationTable(prefix);\n\t\tconst columns = [\n\t\t\t[t.blobs, \"created_at\"],\n\t\t\t[t.blobs, \"chunks\"],\n\t\t\t...SESSION_REF_COLUMNS.map((column) => [t.sessionRefs, column] as const),\n\t\t] as const;\n\t\tconst triggers = [`${t.blobs}_chunks_delete_all`, `${t.blobs}_chunks_delete`];\n\t\tconst probes = [\n\t\t\t...Object.values(t).map((table) => dialect.tableExists(table)),\n\t\t\t...columns.map(([table, column]) => dialect.columnExists(table, column)),\n\t\t\tdialect.schemaObjects(triggers),\n\t\t];\n\t\tconst tablesPresent = (found: StorageSchemaCatalog) =>\n\t\t\tObject.values(t).every((table) => found.hasTable(table)) &&\n\t\t\tcolumns.every(([table, column]) => found.hasColumn(table, column)) &&\n\t\t\ttriggers.some((trigger) => found.hasObject(trigger));\n\t\t// One catalog read answers the schema questions where an open read it (#6560): always on Postgres, at the first\n\t\t// question on SQLite.\n\t\tconst catalog = await schemaCatalogOf(database);\n\t\t// Whether shared-history forks are on (#6560), from that catalog or asked beside the probes.\n\t\tconst segments = forkSegmentsTable(prefix);\n\t\tconst segmentsProbe = dialect.tableExists(segments);\n\t\tconst shared =\n\t\t\tcatalog !== undefined\n\t\t\t\t? Promise.resolve(catalog.hasTable(segments))\n\t\t\t\t: database.get(segmentsProbe.sql, ...segmentsProbe.params).then((row) => row !== undefined);\n\t\tshared.catch(() => {});\n\t\t// A versioned database checks its ledger whatever the probes find, so it does not ask them. Elsewhere the catalog\n\t\t// answers them all, in one read instead of a read each.\n\t\tconst current = dialect.versionedMigrations\n\t\t\t? false\n\t\t\t: catalog !== undefined\n\t\t\t\t? tablesPresent(catalog)\n\t\t\t\t: (await Promise.all(probes.map((probe) => database.get(probe.sql, ...probe.params)))).every(\n\t\t\t\t\t\t(row) => row !== undefined,\n\t\t\t\t\t);\n\n\t\t// On SQLite inside an open scope, when the snapshot tables are missing or incomplete, queue both table creation\n\t\t// and source index trigger installation into the open's single write transaction without reading uncommitted tables\n\t\t// beforehand (#6709).\n\t\tif (!current && !dialect.versionedMigrations && catalog !== undefined) {\n\t\t\tconst needsReset =\n\t\t\t\tcatalog.hasTable(t.sessionLinks) || catalog.hasTable(t.sessionRefs) || catalog.hasTable(t.sessionRecords);\n\t\t\tconst reset = needsReset ? await SqlSnapshotBlobStore.prepareSessionIndexReset(database) : undefined;\n\t\t\tconst store = new SqlSnapshotBlobStore(\n\t\t\t\tdatabase,\n\t\t\t\tdialect,\n\t\t\t\tt,\n\t\t\t\tindexSources(prefix, t, dialect, (await shared) ? segments : undefined),\n\t\t\t\tsegments,\n\t\t\t);\n\t\t\tconst enqueueFreshTables = (ctx: SqliteSchemaBatchContext, sharedNow: boolean) => {\n\t\t\t\tconst { int, text, blob } = dialect.types;\n\t\t\t\tconst strict = dialect.tableOptions;\n\t\t\t\tconst keyed = dialect.withoutRowidTableOptions;\n\t\t\t\tconst guard = sharedNow ? [forkInheritedBlobGuard(dialect, t, segments).replace(/;\\s*$/, \"\")] : [];\n\t\t\t\tctx.enqueue(\n\t\t\t\t\t`CREATE TABLE IF NOT EXISTS ${t.blobs} (hash ${text} PRIMARY KEY, bytes ${int} NOT NULL, data ${blob} NOT NULL, created_at ${int} NOT NULL DEFAULT (${dialect.nowSeconds}))${strict}`,\n\t\t\t\t);\n\t\t\t\tctx.enqueue(`\n\t\tCREATE TABLE IF NOT EXISTS ${t.runRefs} (run_id ${text} NOT NULL, hash ${text} NOT NULL, PRIMARY KEY (run_id, hash))${keyed};\n\t\tCREATE INDEX IF NOT EXISTS ${t.runRefs}_hash ON ${t.runRefs} (hash);\n\t\tCREATE TABLE IF NOT EXISTS ${t.runState} (run_id ${text} PRIMARY KEY, retained ${int} NOT NULL, seq ${int} NOT NULL)${keyed};\n\t\tCREATE TABLE IF NOT EXISTS ${t.sessionRefs} (session_id ${text} NOT NULL, seq ${int} NOT NULL, root ${text} NOT NULL, snapshot_id ${text} NOT NULL, prev_seq ${int}, restore_from ${text}, restore_to ${text}, degraded_from ${text}, degraded_since ${int}, PRIMARY KEY (session_id, seq))${keyed};\n\t\tCREATE TABLE IF NOT EXISTS ${t.sessionLinks} (session_id ${text} NOT NULL, seq ${int} NOT NULL, entry_id ${text} NOT NULL, parent_id ${text}, anchor_seq ${int}, children ${int} NOT NULL, broken ${int} NOT NULL, PRIMARY KEY (session_id, seq))${strict};\n\t\tCREATE INDEX IF NOT EXISTS ${t.sessionLinks}_entry ON ${t.sessionLinks} (session_id, entry_id);\n\t\t${sessionLinksLeafIndex(t, dialect)};\n\t\tCREATE INDEX IF NOT EXISTS ${t.sessionLinks}_broken ON ${t.sessionLinks} (session_id) WHERE broken = 1;\n\t\tCREATE TABLE IF NOT EXISTS ${t.sessionRecords} (session_id ${text} NOT NULL, seq ${int} NOT NULL, snapshot_id ${text} NOT NULL, hash ${text} NOT NULL, PRIMARY KEY (session_id, seq, hash))${keyed};\n\t\tCREATE INDEX IF NOT EXISTS ${t.sessionRecords}_hash ON ${t.sessionRecords} (hash);\n\t\tCREATE TABLE IF NOT EXISTS ${t.carriedRefs} (owner ${text} NOT NULL, hash ${text} NOT NULL, PRIMARY KEY (owner, hash))${keyed};\n\t\tCREATE INDEX IF NOT EXISTS ${t.carriedRefs}_hash ON ${t.carriedRefs} (hash);\n\t\tCREATE TABLE IF NOT EXISTS ${t.collection} (id ${int} PRIMARY KEY CHECK (id = 1), claimed_at ${int}, holder ${text}, finished_at ${int}, deleted ${int}, error_code ${text})${strict};\n\t\tINSERT INTO ${t.collection} (id) VALUES (1) ON CONFLICT DO NOTHING;\n\t\tCREATE TABLE IF NOT EXISTS ${t.sources} (source ${text} PRIMARY KEY, watermark ${int} NOT NULL, backfilled_through ${int} NOT NULL)${keyed};\n\t\t${guard.map((statement) => `${statement};`).join(\"\\n\")}\n\t`);\n\t\t\t\tctx.enqueue(chunkTableDefinition(t.blobChunks, dialect));\n\t\t\t\tfor (const write of [...blobChunkWrites(t, dialect, [false, false]), ...blobMaintenanceIndexes(t)]) {\n\t\t\t\t\tif (write !== false && write !== undefined) ctx.enqueue(write);\n\t\t\t\t}\n\t\t\t\tfor (const table of Object.values(t)) ctx.noteTableCreated(table);\n\t\t\t};\n\t\t\tconst queued = queueSqliteSchemaSetup(database, ledger, {\n\t\t\t\tdone: async (freshCatalog) => {\n\t\t\t\t\tif (!tablesPresent(freshCatalog)) return false;\n\t\t\t\t\tconst sharedNow = freshCatalog.hasTable(segments);\n\t\t\t\t\tif (sharedNow && !freshCatalog.hasObject(forkInheritedBlobGuardName(t.blobs))) return false;\n\t\t\t\t\tconst sourcesNow = indexSources(prefix, t, dialect, sharedNow ? segments : undefined);\n\t\t\t\t\tconst legacy = store.legacyForkLinks();\n\t\t\t\t\tconst foundLegacy = new Set<string>();\n\t\t\t\t\tconst states = await readSourceStates(\n\t\t\t\t\t\tdatabase,\n\t\t\t\t\t\tdialect,\n\t\t\t\t\t\tt,\n\t\t\t\t\t\tsourcesNow,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tlegacy && { names: [legacy.name], found: foundLegacy },\n\t\t\t\t\t);\n\t\t\t\t\tif (legacy !== undefined && foundLegacy.has(legacy.name)) return false;\n\t\t\t\t\tif (states.some((state) => !state.installed && !state.deferred)) return false;\n\t\t\t\t\tstore.sources = sourcesNow;\n\t\t\t\t\treturn true;\n\t\t\t\t},\n\t\t\t\trun: async (ctx) => {\n\t\t\t\t\tconst sharedNow = ctx.tableExisted(segments) || ctx.createdTable(segments);\n\t\t\t\t\tstore.sources = indexSources(prefix, t, dialect, sharedNow ? segments : undefined);\n\t\t\t\t\tconst anyTableExisted = Object.values(t).some((table) => ctx.tableExisted(table));\n\t\t\t\t\tconst tablesAlreadyCurrent = ctx.catalog !== undefined && tablesPresent(ctx.catalog);\n\t\t\t\t\tconst guardName = forkInheritedBlobGuardName(t.blobs);\n\t\t\t\t\tif (!tablesAlreadyCurrent) {\n\t\t\t\t\t\tif (ctx.catalog !== undefined && !anyTableExisted) {\n\t\t\t\t\t\t\tenqueueFreshTables(ctx, sharedNow);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tawait ctx.flushWrites();\n\t\t\t\t\t\t\tawait createSnapshotIndexTables(\n\t\t\t\t\t\t\t\tctx.tx,\n\t\t\t\t\t\t\t\tt,\n\t\t\t\t\t\t\t\tprefix,\n\t\t\t\t\t\t\t\tdialect,\n\t\t\t\t\t\t\t\tsharedNow ? [forkInheritedBlobGuard(dialect, t, segments).replace(/;\\s*$/, \"\")] : [],\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tfor (const table of Object.values(t)) ctx.noteTableCreated(table);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (sharedNow && ctx.catalog?.hasObject(guardName) !== true) {\n\t\t\t\t\t\tctx.enqueue(forkInheritedBlobGuard(dialect, t, segments));\n\t\t\t\t\t}\n\t\t\t\t\t// Install snapshot index triggers in the same transaction. When no referencing table or progress table\n\t\t\t\t\t// existed before this transaction, only newly created tables (empty, watermark 0) need triggers.\n\t\t\t\t\tconst existingSources = store.sources.filter((source) => ctx.tableExisted(source.table));\n\t\t\t\t\tif (!ctx.tableExisted(t.sources) && existingSources.length === 0) {\n\t\t\t\t\t\tfor (const source of store.sources) {\n\t\t\t\t\t\t\tif (!ctx.createdTable(source.table)) continue;\n\t\t\t\t\t\t\tctx.enqueue(source.triggers.map((trigger) => dialect.renderTrigger(trigger)).join(\"\\n\"));\n\t\t\t\t\t\t\tctx.enqueue({\n\t\t\t\t\t\t\t\tsql: `INSERT INTO ${t.sources} (source, watermark, backfilled_through) VALUES (?, 0, 0) ${REPLACE_PROGRESS}`,\n\t\t\t\t\t\t\t\tparams: [source.name],\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (source.own !== undefined)\n\t\t\t\t\t\t\t\tctx.enqueue({\n\t\t\t\t\t\t\t\t\tsql: `INSERT INTO ${t.sources} (source, watermark, backfilled_through) VALUES (?, 0, 0) ${REPLACE_PROGRESS}`,\n\t\t\t\t\t\t\t\t\tparams: [source.own],\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (source.version !== undefined) ctx.enqueue(publishVersion(t, source));\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tawait ctx.flushWrites();\n\t\t\t\t\tconst legacy = store.legacyForkLinks();\n\t\t\t\t\tconst foundLegacy = new Set<string>();\n\t\t\t\t\tconst states = await readSourceStates(\n\t\t\t\t\t\tctx.tx,\n\t\t\t\t\t\tdialect,\n\t\t\t\t\t\tt,\n\t\t\t\t\t\tstore.sources,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tlegacy && { names: [legacy.name], found: foundLegacy },\n\t\t\t\t\t);\n\t\t\t\t\tif (legacy !== undefined && foundLegacy.has(legacy.name))\n\t\t\t\t\t\tawait ctx.tx.exec(dialect.dropTrigger(legacy.name, legacy.table, true));\n\t\t\t\t\tfor (const { source, installed, deferred } of states) {\n\t\t\t\t\t\tif (!installed && !deferred) await installSource(ctx.tx, dialect, t, source, reset);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t});\n\t\t\tif (queued) return store;\n\t\t}\n\n\t\t// A versioned database always checks its ledger: a newer schema with the same tables is refused, and a step it\n\t\t// lacks, such as the index triggers, runs even when every table exists.\n\t\t// Whether this open created the tables on PostgreSQL, and with them the links indexes of {@link hotSessionLinks}.\n\t\tlet linksHot = false;\n\t\tif (!current) {\n\t\t\tconst migrated = await applyStorageMigrations(\n\t\t\t\tdatabase,\n\t\t\t\tSNAPSHOT_BLOB_DOMAIN,\n\t\t\t\t[\n\t\t\t\t\t{\n\t\t\t\t\t\tversion: 1,\n\t\t\t\t\t\tup: async (transaction, dialect) => {\n\t\t\t\t\t\t\t// On PostgreSQL the tables come with the links index of {@link hotSessionLinks}, without one an\n\t\t\t\t\t\t\t// earlier build made, recorded in the ledger in the same request: a new database takes no extra\n\t\t\t\t\t\t\t// round trip for it. Where forks share history, as a new database's do from its first open, the\n\t\t\t\t\t\t\t// guard that keeps what they inherit comes with them in that request too (fork-blob-guard.ts).\n\t\t\t\t\t\t\tconst hot = dialect.name === \"postgres\";\n\t\t\t\t\t\t\tawait createSnapshotIndexTables(transaction, t, prefix, dialect, [\n\t\t\t\t\t\t\t\t...(hot\n\t\t\t\t\t\t\t\t\t? [`DROP INDEX IF EXISTS ${t.sessionLinks}_leaves`, hotSessionLinksRecord(prefix, dialect)]\n\t\t\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t\t\t...((await shared) ? [forkInheritedBlobGuard(dialect, t, segments).replace(/;\\s*$/, \"\")] : []),\n\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t\tlinksHot = hot;\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t// Where a ledger records the steps, it records the index triggers too, installed under the migration lock.\n\t\t\t\t\t// Without one, installIndex below installs each source in a transaction of its own, as it always has.\n\t\t\t\t\t...(dialect.versionedMigrations\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tversion: 2,\n\t\t\t\t\t\t\t\t\tup: (transaction: SqliteExecutor, dialect: StorageDialect) =>\n\t\t\t\t\t\t\t\t\t\tinstallMissingSources(transaction, t, prefix, dialect),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t// The pins of partly restored worktrees (#4922); SQLite adds them in step 1, which runs every time.\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tversion: 3,\n\t\t\t\t\t\t\t\t\tup: (transaction: SqliteExecutor, dialect: StorageDialect) =>\n\t\t\t\t\t\t\t\t\t\taddSessionRefColumns(transaction, t, prefix, dialect),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t// Chunked blobs (#4954); SQLite adds them in step 1, which runs every time.\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tversion: 4,\n\t\t\t\t\t\t\t\t\tup: (transaction: SqliteExecutor, dialect: StorageDialect) =>\n\t\t\t\t\t\t\t\t\t\taddBlobChunks(transaction, t, dialect),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tversion: 5,\n\t\t\t\t\t\t\t\t\tup: async (transaction: SqliteExecutor, dialect: StorageDialect) => {\n\t\t\t\t\t\t\t\t\t\tawait addBlobChunks(transaction, t, dialect);\n\t\t\t\t\t\t\t\t\t\tawait addBlobMaintenanceIndexes(transaction, t);\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: []),\n\t\t\t\t],\n\t\t\t\t{ table: ledger },\n\t\t\t);\n\t\t\t// The session store's open, which asks the catalog for the guard next, finds it without reading the schema again.\n\t\t\tif (migrated.applied.includes(1) && (await shared))\n\t\t\t\tnoteStorageSchemaTables(database, [forkInheritedBlobGuardName(t.blobs)]);\n\t\t}\n\t\tif (!linksHot) await ensureHotSessionLinks(database, t, prefix);\n\t\tconst store = new SqlSnapshotBlobStore(\n\t\t\tdatabase,\n\t\t\tdialect,\n\t\t\tt,\n\t\t\tindexSources(prefix, t, dialect, (await shared) ? segments : undefined),\n\t\t\tsegments,\n\t\t);\n\t\tawait store.installIndex(undefined, false, await schemaCatalogOf(database));\n\t\treturn store;\n\t}\n\n\t/**\n\t * Gives a PostgreSQL database's session links the index of {@link hotSessionLinks} without holding the table's writes,\n\t * as `atomic storage migrate` does where an open would not ({@link HOT_SESSION_LINKS_OPEN_BUILD_BYTES}). Each step\n\t * runs on its own, outside a transaction: `CREATE INDEX CONCURRENTLY` builds `_anchored`, `DROP INDEX CONCURRENTLY`\n\t * removes `_leaves`, and only then does the ledger record the step. A build that stopped part way, which leaves an\n\t * invalid `_anchored`, is dropped and made again; one another process is making is waited for. Nothing runs where the\n\t * ledger records the step, where the table does not exist yet (its first open creates it with the index), or where\n\t * this role does not own it. `database` should allow a statement as long as the build takes.\n\t */\n\tstatic async buildHotSessionLinksIndex(\n\t\tdatabase: SqliteDatabase,\n\t\tprefix = \"\",\n\t): Promise<\"built\" | \"current\" | \"absent\" | \"not-owner\"> {\n\t\tconst dialect = dialectOf(database);\n\t\tif (dialect.name !== \"postgres\") return \"current\";\n\t\tconst t = snapshotIndexTables(prefix);\n\t\tconst schema = sessionLinksHotSchema(prefix);\n\t\tconst recorded = async () => {\n\t\t\tconst ledger = dialect.tableExists(schema.ledger);\n\t\t\tif ((await database.get(ledger.sql, ...ledger.params)) === undefined) return false;\n\t\t\treturn (\n\t\t\t\t(await database.get(\n\t\t\t\t\t`SELECT 1 AS found FROM ${schema.ledger} WHERE domain = ? AND version >= ?`,\n\t\t\t\t\t`schema:${schema.domain}`,\n\t\t\t\t\tschema.revision,\n\t\t\t\t)) !== undefined\n\t\t\t);\n\t\t};\n\t\tif (await recorded()) return \"current\";\n\t\tfor (;;) {\n\t\t\tconst found = await sessionLinksState(database, t, dialect);\n\t\t\tif (found === undefined) return \"absent\";\n\t\t\tif (!found.owned) return \"not-owner\";\n\t\t\tif (found.building) {\n\t\t\t\t// Another process builds an index of the table, perhaps this one: its outcome decides what is left to do.\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, HOT_SESSION_LINKS_BUILD_POLL_MS));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (found.anchored === false)\n\t\t\t\tawait database.exec(`DROP INDEX CONCURRENTLY IF EXISTS ${t.sessionLinks}_anchored`);\n\t\t\tif (found.anchored !== true)\n\t\t\t\tawait database.exec(sessionLinksLeafIndex(t, dialect).replace(\"CREATE INDEX\", \"CREATE INDEX CONCURRENTLY\"));\n\t\t\tbreak;\n\t\t}\n\t\tawait database.exec(`DROP INDEX CONCURRENTLY IF EXISTS ${t.sessionLinks}_leaves`);\n\t\t// The index is in place, so the record runs no DDL, which would wait for the table's writes.\n\t\tawait database.transaction((transaction) => ensureStorageSchema(transaction, dialect, schema, async () => {}), {\n\t\t\tretryTransientFailures: true,\n\t\t\tconcurrency: { kind: \"serial\", domain: schema.ledger },\n\t\t});\n\t\treturn \"built\";\n\t}\n\n\t/** Runs only layout maintenance on the offline command's dedicated, exclusively locked SQLite file connection. */\n\tstatic async moveChunksOffline(file: string, prefix = \"\"): Promise<void> {\n\t\tconst tables = snapshotIndexTables(prefix);\n\t\tconst { withOfflineSnapshotFile } = await import(\"../storage/offline-snapshot-file.js\");\n\t\tawait withOfflineSnapshotFile(file, async (database) => {\n\t\t\tconst store = new SqlSnapshotBlobStore(database, dialectOf(database), tables, []);\n\t\t\tawait store.checkOfflineLayout();\n\t\t\tawait store.moveChunksToRowTable({ graceSeconds: 0 }, true);\n\t\t});\n\t}\n\n\t/** Don't rename away a custom index or view, or run extra triggers outside the offline batch's space budget. */\n\tprivate async checkOfflineLayout(): Promise<void> {\n\t\tconst t = this.tables;\n\t\tconst { next, retired } = chunkMoveTables(t);\n\t\tconst erase = chunksDeleteTrigger(t);\n\t\tconst conditional = { ...erase, name: `${t.blobs}_chunks_delete`, when: \"OLD.chunks > 0\" };\n\t\t// sqlite_schema elides IF NOT EXISTS and the final semicolon; RENAME quotes the new table name.\n\t\tconst stored = (sql: string) => sql.replace(\" IF NOT EXISTS\", \"\").replace(/;$/, \"\");\n\t\tconst layouts = [t.blobChunks, next, retired].flatMap((name) => {\n\t\t\tconst row = stored(chunkTableDefinition(name, this.dialect));\n\t\t\treturn [row, row.replace(`TABLE ${name} `, `TABLE \"${name}\" `)].flatMap((definition) => {\n\t\t\t\tconst legacy = `${definition}, WITHOUT ROWID`;\n\t\t\t\treturn name === next ? [definition] : name === retired ? [legacy] : [definition, legacy];\n\t\t\t});\n\t\t});\n\t\tconst current = stored(this.dialect.renderTrigger(erase));\n\t\tconst expected = new Set([...layouts, current, stored(this.dialect.renderTrigger(conditional))]);\n\t\tconst objects = await this.database.all<SqliteRow & { name: string; sql: string }>(\n\t\t\t\"SELECT name, sql FROM sqlite_schema WHERE sql IS NOT NULL AND (instr(lower(sql), lower(?)) > 0 OR name IN (?, ?))\",\n\t\t\tt.blobChunks,\n\t\t\terase.name,\n\t\t\tconditional.name,\n\t\t);\n\t\tif (!objects.some((row) => row.name === t.blobChunks) || !objects.some((row) => row.sql === current))\n\t\t\tthrow new Error(`No standard Atomic snapshot chunk store found for table ${t.blobs}.`);\n\t\tfor (const row of objects)\n\t\t\tif (!expected.has(row.sql))\n\t\t\t\tthrow new Error(`Cannot move a customized snapshot chunk layout offline (${row.name}).`);\n\t}\n\n\t/** Another file on this volume may have grown since admission. Check outside the write transaction, including during retirement. */\n\tprivate async requireOfflineBatchSpace(): Promise<void> {\n\t\tconst free = await this.database.freeBytes?.();\n\t\tif (free === undefined || free < SNAPSHOT_CHUNK_MOVE_HEADROOM_BYTES + OFFLINE_CHUNK_LOG_ALLOWANCE)\n\t\t\tthrow new Error(\"Not enough free space for another offline chunk batch and the 64 MiB reserve.\");\n\t}\n\n\t/** The exclusive connection is the only WAL writer. Never start a second batch on a nonempty log. */\n\tprivate async checkpointChunkMove(): Promise<void> {\n\t\tconst row = await this.database.get(\"PRAGMA wal_checkpoint(TRUNCATE)\");\n\t\tif (row?.busy !== 0 || row.log !== 0)\n\t\t\tthrow new Error(\"Could not truncate the offline chunk move's write-ahead log.\");\n\t}\n\n\t/** A transcript-only handle has no snapshot sources to index. Binding it must not even inspect their tables. */\n\tstatic forTranscriptReader(database: SqliteDatabase & { readonly readOnly: true }): SqlSnapshotBlobStore {\n\t\treturn new SqlSnapshotBlobStore(database, dialectOf(database), snapshotIndexTables(), []);\n\t}\n\n\t/**\n\t * Creates the blob table and its reference index inside the caller's transaction, and indexes the referencing tables\n\t * that exist, so a store that creates its own tables takes the write lock once for all of them.\n\t */\n\tstatic async initialize(\n\t\ttransaction: SqliteExecutor,\n\t\tprefix = \"\",\n\t\tdialect: StorageDialect,\n\t\treset?: SessionIndexReset,\n\t): Promise<void> {\n\t\tconst t = snapshotIndexTables(prefix);\n\t\tawait createSnapshotIndexTables(transaction, t, prefix, dialect);\n\t\tawait installMissingSources(transaction, t, prefix, dialect, reset);\n\t}\n\n\t/** @internal Resolve the space reading and load migration code before taking SQLite's writer lock. */\n\tstatic async prepareSessionIndexReset(database: SqliteDatabase): Promise<SessionIndexReset | undefined> {\n\t\tif (dialectOf(database).name !== \"sqlite\") return undefined;\n\t\tconst available = await database.freeBytes?.().catch(() => undefined);\n\t\tif (available === undefined) return undefined;\n\t\tconst { detachSessionIndex } = await import(\"./session-index-reset.js\");\n\t\treturn (tx, tables, triggers) => detachSessionIndex(tx, tables, triggers, available);\n\t}\n\n\t/**\n\t * Stores every blob, in one transaction, or restarts the age of one stored already. A blob larger than\n\t * {@link SNAPSHOT_BLOB_CHUNK_BYTES} is stored as chunk rows and a header row that names how many, so no statement\n\t * binds more than one chunk (#4954); the chunks of a blob stored already are not written again. Unknown ages\n\t * remain protected until collection stamps them.\n\t */\n\tasync putBlobs(unordered: readonly SnapshotBlob[]): Promise<void> {\n\t\tif (unordered.length === 0) return;\n\t\t// In hash order, so the rows it locks are taken in the order every other write of them takes them.\n\t\tconst blobs = [...unordered].sort((first, second) => byteOrder(first.hash, second.hash));\n\t\tconst now = this.dialect.nowSeconds;\n\t\tconst header = `INSERT INTO ${this.table} (hash, bytes, data, created_at, chunks) VALUES (?, ?, ?, ${now}, ?) ON CONFLICT(hash) DO UPDATE SET created_at = ${now} WHERE ${this.table}.created_at > 0`;\n\t\tconst chunk = `INSERT INTO ${this.tables.blobChunks} (hash, idx, data) SELECT ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM ${this.table} WHERE hash = ?) ON CONFLICT DO NOTHING`;\n\t\tconst statements: { sql: string; params: SqliteValue[] }[] = [];\n\t\tlet chunked = false;\n\t\tlet totalBytes = 0;\n\t\tfor (const blob of blobs) {\n\t\t\tconst { hash, data } = blob;\n\t\t\ttotalBytes += data.byteLength;\n\t\t\tif (data.byteLength <= SNAPSHOT_BLOB_CHUNK_BYTES) {\n\t\t\t\tstatements.push({ sql: header, params: [hash, data.byteLength, data, 0] });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst chunks = Math.ceil(data.byteLength / SNAPSHOT_BLOB_CHUNK_BYTES);\n\t\t\tchunked = true;\n\t\t\tfor (let index = 0; index < chunks; index++) {\n\t\t\t\tconst bytes = data.subarray(index * SNAPSHOT_BLOB_CHUNK_BYTES, (index + 1) * SNAPSHOT_BLOB_CHUNK_BYTES);\n\t\t\t\tstatements.push({ sql: chunk, params: [hash, index, bytes, hash] });\n\t\t\t}\n\t\t\tstatements.push({ sql: header, params: [hash, data.byteLength, new Uint8Array(), chunks] });\n\t\t}\n\t\tif (!chunked && this.database.batch) {\n\t\t\tawait this.database.batch(statements);\n\t\t\treturn;\n\t\t}\n\t\tconst lead = statements.length < MAX_SEQUENCE_REQUEST_STATEMENTS && totalBytes <= SNAPSHOT_BLOB_CHUNK_BYTES;\n\t\tawait this.database.transaction(\n\t\t\tasync (transaction) => {\n\t\t\t\t// On a pipelined connection the statements go out with the commit: one round trip after the locks.\n\t\t\t\tif (transactionFinisher(transaction)?.(statements) === true) return;\n\t\t\t\tfor (const statement of statements) await transaction.run(statement.sql, ...statement.params);\n\t\t\t},\n\t\t\tthis.blobWrite(lead ? statements : undefined, lead),\n\t\t);\n\t}\n\n\t/**\n\t * How a put or a refresh of this table's blobs runs: a serial transaction of the blob table's own domain (#6560). On\n\t * PostgreSQL it holds the database-wide lock shared, so it waits for and excludes collection, whose writes hold that\n\t * lock exclusively, and the blob writers of this table exclude one another, but session writes, which hold the\n\t * database-wide lock shared with their session's domain, run beside it. Rows it writes again (`created_at`) are locked\n\t * in hash order, as an append's check of the blobs it records locks them (`missingBlob`), so neither waits on the\n\t * other in a cycle. Its callback only uses the transaction, so a transient failure runs it again.\n\t */\n\tprivate blobWrite(leading?: readonly SqliteStatement[], leadingOnly = false): SqliteTransactionOptions {\n\t\treturn {\n\t\t\tretryTransientFailures: true,\n\t\t\tconcurrency: { kind: \"serial\", domain: this.table },\n\t\t\t...(leading === undefined ? {} : { leading }),\n\t\t\t...(leading !== undefined && leadingOnly ? { leadingOnly: true } : {}),\n\t\t};\n\t}\n\t/**\n\t * The blob's bytes, read a chunk per statement when it has chunks, so no response holds more than one chunk. A\n\t * chunked blob whose chunks are not all there, as when a collection deleted it during the read, is not returned.\n\t */\n\tasync getBlob(hash: string): Promise<Uint8Array | undefined> {\n\t\tconst row = await this.database.get<SqliteRow & { data: Uint8Array; bytes: number; chunks: number }>(\n\t\t\t`SELECT data, bytes, chunks FROM ${this.table} WHERE hash = ?`,\n\t\t\thash,\n\t\t);\n\t\tif (row === undefined) return undefined;\n\t\tconst chunks = Number(row.chunks);\n\t\tif (chunks === 0) return row.data;\n\t\tconst data = new Uint8Array(Number(row.bytes));\n\t\tlet offset = 0;\n\t\tfor (let index = 0; index < chunks; index++) {\n\t\t\tconst chunk = await this.database.get<SqliteRow & { data: Uint8Array }>(\n\t\t\t\t`SELECT data FROM ${this.tables.blobChunks} WHERE hash = ? AND idx = ?`,\n\t\t\t\thash,\n\t\t\t\tindex,\n\t\t\t);\n\t\t\tif (chunk === undefined || offset + chunk.data.byteLength > data.byteLength) return undefined;\n\t\t\tdata.set(chunk.data, offset);\n\t\t\toffset += chunk.data.byteLength;\n\t\t}\n\t\treturn offset === data.byteLength ? data : undefined;\n\t}\n\t/** Refreshes stored hashes; unknown ages stay protected until collection stamps them. False when any is missing. */\n\tasync refreshBlobs(hashes: readonly string[]): Promise<boolean> {\n\t\tconst unique = [...new Set(hashes)];\n\t\tif (unique.length === 0) return true;\n\t\tconst requested = `hash IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")})`;\n\t\tconst params = [JSON.stringify(unique)];\n\t\tconst update = `UPDATE ${this.table} SET created_at = ${this.dialect.nowSeconds} WHERE ${requested} AND created_at > 0`;\n\t\tconst present = `SELECT hash FROM ${this.table} WHERE ${requested}`;\n\t\tif (this.database.batch) {\n\t\t\tconst [, rows] = await this.database.batch([\n\t\t\t\t{ sql: update, params },\n\t\t\t\t{ sql: present, params },\n\t\t\t]);\n\t\t\treturn rows!.length === unique.length;\n\t\t}\n\t\t// The rows present, locked in hash order before the update writes them (see `blobWrite`). On a pipelined connection\n\t\t// this read goes out with the transaction's start and the update with its commit.\n\t\tconst locked = {\n\t\t\tsql: `${present} ORDER BY hash${this.dialect.byteOrderCollation}${this.dialect.lockClause(\"update\")}`,\n\t\t\tparams,\n\t\t};\n\t\treturn this.database.transaction(\n\t\t\tasync (transaction) => {\n\t\t\t\tconst rows = await transaction.all(locked.sql, ...locked.params);\n\t\t\t\tif (transactionFinisher(transaction)?.([{ sql: update, params }]) !== true)\n\t\t\t\t\tawait transaction.run(update, ...params);\n\t\t\t\treturn rows.length === unique.length;\n\t\t\t},\n\t\t\tthis.blobWrite([locked]),\n\t\t);\n\t}\n\tasync listBlobHashes(): Promise<readonly string[]> {\n\t\tconst rows = await this.database.all<{ hash: string }>(`SELECT hash FROM ${this.table}`);\n\t\treturn rows.map((row) => row.hash);\n\t}\n\n\t/**\n\t * Rejects with a `blobs-collected` {@link WorkspaceSnapshotError} naming the first of `snapshots`' blobs this table\n\t * does not hold in full, a chunked blob's chunks included (#5077). Run in the write transaction that records the\n\t * snapshots, it keeps a collection that ran after their capture stored the blobs from leaving a recorded snapshot\n\t * that cannot be restored: the blobs it finds stay until that transaction ends, and the references it writes keep\n\t * them after.\n\t */\n\tasync assertStored(transaction: SqliteExecutor, snapshots: readonly WorktreeSnapshot[]): Promise<void> {\n\t\tconst missing = await this.missingBlob(transaction, snapshots);\n\t\tif (missing !== undefined) await this.refuseCollected(missing);\n\t}\n\n\t/** The `blobs-collected` {@link WorkspaceSnapshotError} `assertStored` rejects with for `hash`. */\n\tasync refuseCollected(hash: string): Promise<never> {\n\t\t// Loaded only when a write is refused, so the storage entry does not load the workspace error family.\n\t\tconst { WorkspaceSnapshotError } = await import(\"./errors.ts\");\n\t\tthrow new WorkspaceSnapshotError(\"blobs-collected\", hash);\n\t}\n\n\t/** The blobs of `snapshots` that `assertStored` checks, each once, in the order it reports the first missing one. */\n\tstoredHashes(snapshots: readonly WorktreeSnapshot[]): string[] {\n\t\treturn [...new Set(snapshots.flatMap(wellFormedBlobHashes))];\n\t}\n\n\t/**\n\t * The query `missingBlob` reads, for the blobs named by `source`, an SQL expression of a JSON array of hashes: the\n\t * hashes this table holds in full, locked FOR SHARE in hash order. A statement that checks the blobs on the server,\n\t * such as the session append function, runs it as it is (#6599).\n\t */\n\tstoredBlobsQuery(source: string): string {\n\t\treturn `SELECT hash FROM ${this.table} AS b WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues(source)}) AND (chunks = 0 OR chunks = (SELECT COUNT(*) FROM ${this.tables.blobChunks} AS c WHERE c.hash = b.hash)) ORDER BY hash${this.dialect.byteOrderCollation}${this.dialect.lockClause(\"share\")}`;\n\t}\n\n\t/**\n\t * A query that returns a row only while this table holds every blob of `snapshots` in full, for a write planned\n\t * outside a transaction to check in the request that writes it (#5077); undefined when they name no blob.\n\t */\n\tstoredFence(snapshots: readonly WorktreeSnapshot[]): SqliteStatement | undefined {\n\t\tconst hashes = [...new Set(snapshots.flatMap(wellFormedBlobHashes))];\n\t\tif (hashes.length === 0) return undefined;\n\t\treturn {\n\t\t\tsql: `SELECT 1 AS stored WHERE (SELECT COUNT(*) FROM ${this.table} AS b WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")}) AND (chunks = 0 OR chunks = (SELECT COUNT(*) FROM ${this.tables.blobChunks} AS c WHERE c.hash = b.hash))) = ?`,\n\t\t\tparams: [JSON.stringify(hashes), hashes.length],\n\t\t};\n\t}\n\n\t/**\n\t * The first of `snapshots`' blobs this table does not hold in full, read in `transaction`; undefined when none. The\n\t * rows it finds stay locked FOR SHARE until the transaction ends, taken in hash order as a blob write takes them.\n\t */\n\tasync missingBlob(transaction: SqliteExecutor, snapshots: readonly WorktreeSnapshot[]): Promise<string | undefined> {\n\t\tconst hashes = this.storedHashes(snapshots);\n\t\tif (hashes.length === 0) return undefined;\n\t\tconst rows = await transaction.all<SqliteRow & { hash: string }>(\n\t\t\tthis.storedBlobsQuery(\"?\"),\n\t\t\tJSON.stringify(hashes),\n\t\t);\n\t\tconst stored = new Set(rows.map((row) => row.hash));\n\t\treturn hashes.find((hash) => !stored.has(hash));\n\t}\n\n\t/**\n\t * Installs the index triggers of every referencing table that lacks them, each with a watermark, the highest rowid\n\t * the table holds in the same transaction, so every row is either at or below the watermark, to be backfilled, or\n\t * above it, indexed by the triggers. A table that has none yet, an empty one included, costs one watermark of 0.\n\t * Resolves with the state of every referencing table.\n\t */\n\tprivate async installIndex(\n\t\tpace?: BackgroundCollectionPace,\n\t\tincludeDeferred = false,\n\t\tcatalog?: StorageSchemaCatalog,\n\t): Promise<SourceState[]> {\n\t\t// The fork links trigger earlier builds of #6560 installed, asked for in the same read: dropped where found, in the\n\t\t// first write below, so a database that has it runs it no longer once a store of this build opened it.\n\t\tconst legacy = this.legacyForkLinks();\n\t\tconst found = new Set<string>();\n\t\tconst states = await this.readStates(includeDeferred, catalog, legacy && { names: [legacy.name], found });\n\t\tlet drop = legacy !== undefined && found.has(legacy.name) ? legacy : undefined;\n\t\tconst dropLegacy = async (transaction: SqliteExecutor) => {\n\t\t\tif (drop === undefined) return;\n\t\t\tconst { name, table } = drop;\n\t\t\tawait withShortSchemaLockWaits(transaction, this.dialect, () =>\n\t\t\t\ttransaction.exec(this.dialect.dropTrigger(name, table, true)),\n\t\t\t);\n\t\t\tdrop = undefined;\n\t\t};\n\t\tconst missing = states.filter((state) => !state.installed && (includeDeferred || !state.deferred));\n\t\tfor (const { source } of missing) {\n\t\t\tconst reset =\n\t\t\t\tsource.name === \"session-entries\"\n\t\t\t\t\t? await SqlSnapshotBlobStore.prepareSessionIndexReset(this.database)\n\t\t\t\t\t: undefined;\n\t\t\tawait this.write(pace, async (transaction) => {\n\t\t\t\tawait dropLegacy(transaction);\n\t\t\t\tconst [current] = await readSourceStates(transaction, this.dialect, this.tables, [source]);\n\t\t\t\tif (current === undefined || current.installed || (current.deferred && !includeDeferred)) return;\n\t\t\t\t// Its triggers lock the table: under short lock waits, so a stalled transaction never queues writers (#5218).\n\t\t\t\tawait withShortSchemaLockWaits(transaction, this.dialect, () =>\n\t\t\t\t\tinstallSource(transaction, this.dialect, this.tables, source, reset),\n\t\t\t\t);\n\t\t\t});\n\t\t}\n\t\tif (drop !== undefined) await this.write(pace, dropLegacy);\n\t\treturn missing.length === 0 ? states : this.readStates(includeDeferred);\n\t}\n\n\t/** The fork links trigger earlier builds of #6560 installed on the session entries, and its table. */\n\tprivate legacyForkLinks(): { readonly name: string; readonly table: string } | undefined {\n\t\tconst entries = this.sources.find((source) => source.name === \"session-entries\");\n\t\treturn entries && { name: legacyForkLinksTriggerName(entries.table), table: entries.table };\n\t}\n\n\t/**\n\t * The state of every source, read outside a transaction. On PostgreSQL the objects and the progress rows are read in\n\t * one read-only transaction whose start carries both, so they cost one round trip, not one each. An open's\n\t * `catalog` answers which objects exist only when it found every one: only its positive answers are final, and a\n\t * source table it lacks may have been created since (#6560). `also` asks which of other objects exist in the same\n\t * read, as `readSourceStates` does.\n\t */\n\tprivate readStates(\n\t\tincludeDeferred: boolean,\n\t\tcatalog?: StorageSchemaCatalog,\n\t\talso?: { readonly names: readonly string[]; readonly found: Set<string> },\n\t): Promise<SourceState[]> {\n\t\tif (this.dialect.name !== \"postgres\")\n\t\t\treturn readSourceStates(\n\t\t\t\tthis.database,\n\t\t\t\tthis.dialect,\n\t\t\t\tthis.tables,\n\t\t\t\tthis.sources,\n\t\t\t\tincludeDeferred,\n\t\t\t\tundefined,\n\t\t\t\talso,\n\t\t\t);\n\t\tconst names = sourceObjectNames(this.sources);\n\t\tconst present =\n\t\t\tcatalog !== undefined && names.every((name) => catalog.hasObject(name))\n\t\t\t\t? new Set([...names, ...(also?.names ?? []).filter((name) => catalog.hasObject(name))])\n\t\t\t\t: undefined;\n\t\treturn this.database.transaction(\n\t\t\t(transaction) =>\n\t\t\t\treadSourceStates(transaction, this.dialect, this.tables, this.sources, includeDeferred, present, also),\n\t\t\t{\n\t\t\t\treadOnly: true,\n\t\t\t\tretryTransientFailures: true,\n\t\t\t\tleading: [\n\t\t\t\t\t...(present === undefined ? [this.dialect.schemaObjects([...names, ...(also?.names ?? [])])] : []),\n\t\t\t\t\tsourceProgressRead(this.tables),\n\t\t\t\t],\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * Indexes the rows that referencing tables held before their triggers were installed, in transactions of\n\t * {@link SNAPSHOT_INDEX_BACKFILL_BATCH} rows, so that the index covers every reference. A one-time cost in the number\n\t * of existing rows, paid in the background by the first collection; resumes where it stopped. Does nothing once the\n\t * index is complete. Yields to the event loop after every batch, so the next batch, of the same table or another,\n\t * or what follows the index, such as a sweep's first batch, starts on a turn of its own (#5530). Checks `signal`\n\t * before each batch and rejects with its reason.\n\t */\n\tasync completeIndex(options: SnapshotIndexOptions = {}): Promise<void> {\n\t\tconst states = await this.installIndex(options.pace, true);\n\t\tfor (const { source, backfilled } of states) {\n\t\t\tif (backfilled) continue;\n\t\t\tconst reset =\n\t\t\t\tsource.name === \"session-entries\"\n\t\t\t\t\t? await SqlSnapshotBlobStore.prepareSessionIndexReset(this.database)\n\t\t\t\t\t: undefined;\n\t\t\tfor (let done = false; !done; ) {\n\t\t\t\toptions.signal?.throwIfAborted();\n\t\t\t\tdone = await this.backfillBatch(source, options, reset);\n\t\t\t\tawait this.betweenBatches(options.pace);\n\t\t\t}\n\t\t}\n\t\t// Reclamation must not delay publication: released collectors see exactly the same install and backfill as\n\t\t// before, even when either version exits at a batch boundary. Only unreferenced physical rows remain here.\n\t\tfor (const { retired } of states)\n\t\t\tfor (const receipt of retired ?? []) {\n\t\t\t\tconst { drainRetiredSessionIndex } = await import(\"./session-index-reset.js\");\n\t\t\t\tfor (;;) {\n\t\t\t\t\tawait this.betweenBatches(options.pace);\n\t\t\t\t\toptions.signal?.throwIfAborted();\n\t\t\t\t\tconst done = await this.write(options.pace, async (tx) => {\n\t\t\t\t\t\tconst finished = await drainRetiredSessionIndex(tx, this.tables, receipt);\n\t\t\t\t\t\tif (options.holder !== undefined) await this.renewClaim(tx, options.holder);\n\t\t\t\t\t\treturn finished;\n\t\t\t\t\t});\n\t\t\t\t\tif (done) break;\n\t\t\t\t}\n\t\t\t}\n\t}\n\n\t/** Indexes the next rows of `source`, and resolves true once every row at or below its watermark is indexed. */\n\tprivate backfillBatch(\n\t\tsource: IndexSource,\n\t\t{ holder, pace, signal }: SnapshotIndexOptions,\n\t\treset?: SessionIndexReset,\n\t): Promise<boolean> {\n\t\tconst t = this.tables;\n\t\tconst row = this.dialect.rowOrder();\n\t\tconst withholds = withholdsVersion(this.dialect, source);\n\t\treturn this.write(pace, async (transaction) => {\n\t\t\tconst [state] = await readSourceStates(transaction, this.dialect, t, [source]);\n\t\t\tif (state === undefined || state.backfilled) return true;\n\t\t\tif (state.foreign) {\n\t\t\t\t// A build before 0.9.88 installed its own triggers since the loop read the states: the source is installed again\n\t\t\t\t// in this transaction, its old rows removed, as at the start of a collection. Left as it is, that build could\n\t\t\t\t// index it its way, and builds 0.9.88 and 0.9.89 trust their version row (#5558).\n\t\t\t\tawait withShortSchemaLockWaits(transaction, this.dialect, () =>\n\t\t\t\t\tinstallSource(transaction, this.dialect, t, source, reset),\n\t\t\t\t);\n\t\t\t\tif (holder !== undefined) await this.renewClaim(transaction, holder);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t// A source that lost triggers meanwhile is indexed on, as its rows still need this build's statements; the sweep\n\t\t\t// installs its triggers again before it deletes anything.\n\t\t\tconst progress = await transaction.get<SqliteRow & { watermark: number; backfilled_through: number }>(\n\t\t\t\t`SELECT watermark, backfilled_through FROM ${t.sources} WHERE source = ?`,\n\t\t\t\tsource.name,\n\t\t\t);\n\t\t\tif (progress === undefined || progress.watermark < 0) return true;\n\t\t\tif (state.takeover) {\n\t\t\t\t// Installed by a build of 0.9.88 or 0.9.89 whose backfill is not done, which a build before 0.9.88 may have\n\t\t\t\t// indexed some of its way: this build indexes it again from its first row, with its own triggers, whose\n\t\t\t\t// pending trigger moves its own progress back, and holds the version row back until it is done, so that\n\t\t\t\t// builds 0.9.88 and 0.9.89 do not trust it meanwhile (#5558).\n\t\t\t\tawait transaction.run(\n\t\t\t\t\t`INSERT INTO ${t.sources} (source, watermark, backfilled_through) VALUES (?, ?, 0) ${REPLACE_PROGRESS}`,\n\t\t\t\t\tsource.own!,\n\t\t\t\t\tprogress.watermark,\n\t\t\t\t);\n\t\t\t\tfor (const name of [source.version!, rebuildRow(source)])\n\t\t\t\t\tawait transaction.run(`DELETE FROM ${t.sources} WHERE source = ?`, name);\n\t\t\t\tfor (const trigger of source.triggers)\n\t\t\t\t\tawait transaction.exec(this.dialect.dropTrigger(trigger.name, trigger.table));\n\t\t\t\tawait transaction.exec(source.triggers.map((trigger) => this.dialect.renderTrigger(trigger)).join(\"\\n\"));\n\t\t\t}\n\t\t\t// This build's own progress (#5558): rows an older build indexed past it are indexed again. On Postgres, which\n\t\t\t// no build before 0.9.88 opens, a source a build of 0.9.88 or 0.9.89 installed has none: its backfill, which\n\t\t\t// indexes what this one does, is trusted as far as it got.\n\t\t\tlet own =\n\t\t\t\tsource.own === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: await transaction.get<SqliteRow & { backfilled_through: number }>(\n\t\t\t\t\t\t\t`SELECT backfilled_through FROM ${t.sources} WHERE source = ?`,\n\t\t\t\t\t\t\tsource.own,\n\t\t\t\t\t\t);\n\t\t\tif (source.own !== undefined && own === undefined && progress.backfilled_through < progress.watermark) {\n\t\t\t\tawait transaction.run(\n\t\t\t\t\t`INSERT INTO ${t.sources} (source, watermark, backfilled_through) VALUES (?, ?, ?) ${REPLACE_PROGRESS}`,\n\t\t\t\t\tsource.own,\n\t\t\t\t\tprogress.watermark,\n\t\t\t\t\tprogress.backfilled_through,\n\t\t\t\t);\n\t\t\t\town = { backfilled_through: progress.backfilled_through };\n\t\t\t}\n\t\t\tconst from =\n\t\t\t\town !== undefined && own.backfilled_through < progress.backfilled_through\n\t\t\t\t\t? own.backfilled_through\n\t\t\t\t\t: progress.backfilled_through;\n\t\t\t// The version row says the index is this build's and complete: never while a trigger is missing, which a build\n\t\t\t// before 0.9.88 would install again its way under it (#5558).\n\t\t\tconst publish = withholds && state.installed;\n\t\t\tif (from >= progress.watermark) {\n\t\t\t\tif (publish) await statementBatch(transaction, [publishVersion(t, source)], []);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tconst { upper: lastRow } = (await transaction.get<SqliteRow & { upper: number | null }>(\n\t\t\t\t`SELECT MAX(${row}) AS upper FROM (SELECT ${row} FROM ${source.table} WHERE ${row} > ? AND ${row} <= ? ORDER BY ${row} LIMIT ?)`,\n\t\t\t\tfrom,\n\t\t\t\tprogress.watermark,\n\t\t\t\tSNAPSHOT_INDEX_BACKFILL_BATCH,\n\t\t\t))!;\n\t\t\tconst upper = lastRow ?? progress.watermark;\n\t\t\tfor (const sql of source.backfill) await transaction.run(sql, from, upper);\n\t\t\tif (source.rowwise !== undefined) {\n\t\t\t\tconst rows = await transaction.all<SqliteRow & { id: number }>(\n\t\t\t\t\t`SELECT ${row} AS id FROM ${source.table} WHERE ${row} > ? AND ${row} <= ? ORDER BY ${row}`,\n\t\t\t\t\tfrom,\n\t\t\t\t\tupper,\n\t\t\t\t);\n\t\t\t\t// The session entries are linked in each session's seq order, whatever order their rows are stored in (#6560).\n\t\t\t\tconst linking =\n\t\t\t\t\tsource.name === \"session-entries\" ? entryLinking(source, this.dialect, t.sessionLinks) : undefined;\n\t\t\t\tfor (const { id } of rows) {\n\t\t\t\t\t// Stopping between rows rolls the whole batch back, progress included, so the pass stays resumable.\n\t\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\t\tif (linking !== undefined) await linkStoredEntry(transaction, linking, id);\n\t\t\t\t\telse for (const sql of source.rowwise) await transaction.run(sql, id);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Indexing rows again behind the source's progress, for this build's own, never moves the progress back.\n\t\t\tawait transaction.run(\n\t\t\t\t`UPDATE ${t.sources} SET backfilled_through = ? WHERE source = ? AND backfilled_through < ?`,\n\t\t\t\tupper,\n\t\t\t\tsource.name,\n\t\t\t\tupper,\n\t\t\t);\n\t\t\tif (own !== undefined)\n\t\t\t\tawait transaction.run(\n\t\t\t\t\t`UPDATE ${t.sources} SET watermark = ?, backfilled_through = ? WHERE source = ?`,\n\t\t\t\t\tprogress.watermark,\n\t\t\t\t\tupper,\n\t\t\t\t\tsource.own!,\n\t\t\t\t);\n\t\t\tif (holder !== undefined) await this.renewClaim(transaction, holder);\n\t\t\tconst done = upper >= progress.watermark;\n\t\t\t// Both progress rows reach the watermark: builds 0.9.88 and 0.9.89 may trust the index now (#5558).\n\t\t\tif (done && publish) await statementBatch(transaction, [publishVersion(t, source)], []);\n\t\t\treturn done;\n\t\t});\n\t}\n\n\t/**\n\t * Deletes every blob stored or re-stored at least `graceSeconds` ago on the database clock that no retained snapshot\n\t * and no snapshot dispatched work carries references, and resolves with the hashes deleted. Reads the reference index\n\t * and the blob table's age index, never a journal or a session. Ages are counted in whole seconds, so a blob can stay\n\t * up to a second past `graceSeconds`, never less.\n\t *\n\t * Pages through the aged blobs, oldest first, {@link SNAPSHOT_COLLECTION_BATCH} at a time, and keeps as candidates\n\t * those no retaining run, no carried work and no session retains. A session's retained snapshots are found by walking\n\t * its snapshot entries, at most {@link SNAPSHOT_COLLECTION_SESSION_REFS} of them per statement, once per sweep\n\t * (#5530). The candidates are deleted in batches, each one write transaction that finds the retained snapshots of the\n\t * sessions it walked for its blobs again, in one statement, and deletes only the blobs none of them retains, no other\n\t * session records, and that are still old and unreferenced by runs and carried work. So a reference published before\n\t * the batch commits keeps its blob, and a process killed mid-collection leaves only garbage. The event loop never\n\t * gets a turn inside a write transaction: another connection of this process that wrote then would wait for the\n\t * write lock while holding the event loop, and the transaction could not end until it gave up.\n\t *\n\t * Every batch first checks, in its transaction, that every referencing table has its triggers and a finished\n\t * backfill, as {@link completeIndex} leaves them. When one does not, because a table appeared or lost its triggers\n\t * since, nothing is deleted until the index has been completed again. A sweep repairs the index once; when it is\n\t * incomplete again after that, because the schema keeps changing under it, the sweep stops without deleting\n\t * anything more and the next collection tries again. Gives the event loop a turn between statements that walk\n\t * sessions, between batches and between pages, and checks `signal` before each and rejects with its reason.\n\t */\n\tasync sweep(options: SnapshotSweepOptions): Promise<readonly string[]> {\n\t\tconst t = this.tables;\n\t\toptions.signal?.throwIfAborted();\n\t\tconst trigger = `${t.blobs}_chunks_delete_all`;\n\t\tconst required = [trigger, `${t.blobs}_age`, `${t.blobs}_inline_size`];\n\t\t// Asked with them: whether forks share their parents' histories, whose inherited snapshots the sweep keeps (#6560).\n\t\tconst schema = this.dialect.schemaObjects([...required, this.forkSegments]);\n\t\tconst present = new Set(\n\t\t\t(await this.database.all<SqliteRow & { name: string }>(schema.sql, ...schema.params)).map((row) => row.name),\n\t\t);\n\t\tconst forks = present.has(this.forkSegments);\n\t\tif (!required.every((name) => present.has(name))) {\n\t\t\toptions.signal?.throwIfAborted();\n\t\t\tawait this.write(options.pace, async (transaction) => {\n\t\t\t\tif (options.holder !== undefined) await this.renewClaim(transaction, options.holder);\n\t\t\t\tawait withShortSchemaLockWaits(transaction, this.dialect, async () => {\n\t\t\t\t\tif (!present.has(trigger)) await addBlobChunks(transaction, t, this.dialect);\n\t\t\t\t\tawait addBlobMaintenanceIndexes(transaction, t);\n\t\t\t\t});\n\t\t\t});\n\t\t\tawait this.betweenBatches(options.pace);\n\t\t}\n\t\tconst minimumAge = collectableAge(options.graceSeconds);\n\t\tconst deleted: string[] = [];\n\t\tconst turns = new SweepTurns(options, () => this.betweenBatches(options.pace));\n\t\tlet sessions = new SweepSessions();\n\t\tlet cursor: PageRow | undefined;\n\t\tlet repaired = false;\n\t\tlet renewedAt = Number.NEGATIVE_INFINITY;\n\t\tfor (;;) {\n\t\t\tawait turns.next();\n\t\t\tif (options.holder !== undefined && performance.now() - renewedAt >= SWEEP_CLAIM_RENEWAL_MS) {\n\t\t\t\t// Pages that hold nothing to delete write nothing else; the claim is renewed when the sweep starts and then\n\t\t\t\t// at least once per quarter lease.\n\t\t\t\tconst holder = options.holder;\n\t\t\t\tawait this.write(options.pace, (transaction) => this.renewClaim(transaction, holder));\n\t\t\t\trenewedAt = performance.now();\n\t\t\t}\n\t\t\tconst page = await this.page(minimumAge, cursor);\n\t\t\tconst candidates = await this.unretainedOf(\n\t\t\t\tpage.map((row) => row.hash),\n\t\t\t\tsessions,\n\t\t\t\tturns,\n\t\t\t\tforks,\n\t\t\t);\n\t\t\tlet incomplete = false;\n\t\t\tfor (const batch of sessions.batches(candidates)) {\n\t\t\t\t// Every delete batch starts on a turn of its own and ends with one: never a turn while it holds the write lock.\n\t\t\t\tawait turns.next();\n\t\t\t\tconst removed = await this.deleteUnretained(batch, minimumAge, options);\n\t\t\t\tturns.held();\n\t\t\t\tif (removed === undefined) {\n\t\t\t\t\tincomplete = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\trenewedAt = performance.now();\n\t\t\t\tdeleted.push(...removed);\n\t\t\t\toptions.onBatch?.(removed);\n\t\t\t}\n\t\t\tif (incomplete) {\n\t\t\t\tif (repaired) return deleted;\n\t\t\t\trepaired = true;\n\t\t\t\tawait this.completeIndex(options);\n\t\t\t\tsessions = new SweepSessions();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (page.length < SNAPSHOT_COLLECTION_BATCH) {\n\t\t\t\tawait this.stampLegacyAges(options);\n\t\t\t\tawait this.moveChunksToRowTable(options);\n\t\t\t\treturn deleted;\n\t\t\t}\n\t\t\tcursor = page.at(-1);\n\t\t\t// Every page holds the event loop, also one whose blobs runs, carried work or sessions this sweep walked\n\t\t\t// already retain, which walks no session and deletes nothing: the next page starts after a turn (#5530).\n\t\t\tturns.held();\n\t\t}\n\t}\n\n\t/**\n\t * Which of `hashes` no retaining run, no carried work and no session retains, as far as these reads see: the sweep's\n\t * candidates, which a delete batch checks again in its transaction. Finds the retained blobs of each session that\n\t * references one of them and that `sessions` has not walked yet, in statements of at most\n\t * {@link SNAPSHOT_COLLECTION_SESSION_REFS} snapshot entries, with a turn between them.\n\t */\n\tprivate async unretainedOf(\n\t\thashes: readonly string[],\n\t\tsessions: SweepSessions,\n\t\tturns: SweepTurns,\n\t\tforks: boolean,\n\t): Promise<SweepCandidate[]> {\n\t\tif (hashes.length === 0) return [];\n\t\tconst t = this.tables;\n\t\tconst free = await this.database.all<SqliteRow & { hash: string }>(\n\t\t\t`SELECT value AS hash FROM ${this.dialect.jsonValues(\"?\")} WHERE ${this.unreferencedByRuns(\"value\")}`,\n\t\t\tJSON.stringify(hashes),\n\t\t);\n\t\tif (free.length === 0) return [];\n\t\tconst referencing = new Map<string, string[]>(free.map((row) => [row.hash, []]));\n\t\tfor (const { hash, session_id } of await this.database.all<SqliteRow & { hash: string; session_id: string }>(\n\t\t\t`SELECT DISTINCT hash, session_id FROM ${t.sessionRecords} WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")})`,\n\t\t\tJSON.stringify([...referencing.keys()]),\n\t\t))\n\t\t\treferencing.get(hash)?.push(session_id);\n\t\tconst unwalked = sessions.unwalked([...referencing.values()].flat());\n\t\tif (unwalked.length > 0) {\n\t\t\tconst costs = await this.sessionCosts(unwalked, () => turns.light());\n\t\t\tsessions.cost(costs);\n\t\t\tfor (const group of sessionGroups(costs)) {\n\t\t\t\tawait turns.next();\n\t\t\t\tsessions.retain(group, await this.retainedBySessions(group, forks));\n\t\t\t\tturns.held();\n\t\t\t}\n\t\t}\n\t\treturn [...referencing]\n\t\t\t.filter(([hash]) => !sessions.retains(hash))\n\t\t\t.map(([hash, referencedBy]) => ({ hash, sessions: referencedBy }));\n\t}\n\n\t/**\n\t * Deletes the blobs of `batch` that are still old and that no retaining run, no carried work and no session retains,\n\t * in one write transaction, and resolves with the hashes deleted; undefined, deleting nothing, when the reference\n\t * index is incomplete. The transaction checks the batch's blobs again in one statement, so what it sees is what\n\t * holds when the batch commits: the snapshots the batch's sessions, those the sweep walked for its blobs, retain now,\n\t * and the sessions that record its blobs now. A blob a session the sweep did not walk records, such as one created\n\t * since, is kept; the next collection walks that session. Nothing in the transaction waits for a turn of the event\n\t * loop (#5530).\n\t *\n\t * It runs as a whole-database transaction on purpose, so no other write runs beside it. With only the blob table's\n\t * lock it would not be safe: it decides which blobs sessions still use in one statement and deletes in the next. A\n\t * session write that records a blob meanwhile holds the blob's row only until it commits its reference; the delete\n\t * waits for it, then goes ahead without looking at the references again, and removes a blob a session has just\n\t * recorded. The same goes for the references retaining runs and carried work write.\n\t */\n\tprivate deleteUnretained(\n\t\tbatch: SweepDeleteBatch,\n\t\tminimumAge: number,\n\t\toptions: SnapshotSweepOptions,\n\t): Promise<string[] | undefined> {\n\t\tconst t = this.tables;\n\t\treturn this.write(options.pace, async (transaction) => {\n\t\t\tconst found = new Set<string>();\n\t\t\tconst states = await readSourceStates(transaction, this.dialect, this.tables, this.sources, false, undefined, {\n\t\t\t\tnames: [this.forkSegments],\n\t\t\t\tfound,\n\t\t\t});\n\t\t\tif (!states.every((state) => state.installed && state.backfilled)) return undefined;\n\t\t\tif (options.holder !== undefined) await this.renewClaim(transaction, options.holder);\n\t\t\tconst kept = new Set(await this.keptBySessions(transaction, batch, found.has(this.forkSegments)));\n\t\t\tconst unretained = batch.hashes.filter((hash) => !kept.has(hash));\n\t\t\tif (unretained.length === 0) return [];\n\t\t\tconst rows = await transaction.all<SqliteRow & { hash: string }>(\n\t\t\t\t`DELETE FROM ${t.blobs} WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")}) AND created_at > 0 AND created_at <= ${this.dialect.nowSeconds} - ? AND ${this.unreferencedByRuns(`${t.blobs}.hash`)} RETURNING hash`,\n\t\t\t\tJSON.stringify(unretained),\n\t\t\t\tminimumAge,\n\t\t\t);\n\t\t\treturn rows.map((row) => row.hash);\n\t\t});\n\t}\n\n\t/** A condition that no retaining run and no carried work references the blob `hash` names. */\n\tprivate unreferencedByRuns(hash: string): string {\n\t\tconst t = this.tables;\n\t\treturn `NOT EXISTS (\n\t\t\t\tSELECT 1 FROM ${t.runRefs} AS ref WHERE ref.hash = ${hash}\n\t\t\t\tAND NOT EXISTS (SELECT 1 FROM ${t.runState} AS state WHERE state.run_id = ref.run_id AND state.retained = 0)\n\t\t\t) AND NOT EXISTS (SELECT 1 FROM ${t.carriedRefs} AS carried WHERE carried.hash = ${hash})`;\n\t}\n\n\t/**\n\t * How many snapshot entries finding the retained snapshots of each of `sessions` walks: the entries of the session,\n\t * once for each distinct latest snapshot entry of its open leaves, which bounds the entries on those leaves'\n\t * branches. Reads one session per statement, waiting for `turn` between statements.\n\t */\n\tprivate async sessionCosts(sessions: readonly string[], turn: () => Promise<void>): Promise<Map<string, number>> {\n\t\tconst t = this.tables;\n\t\tconst costs = new Map<string, number>();\n\t\tfor (const [index, session] of sessions.entries()) {\n\t\t\tif (index > 0) await turn();\n\t\t\tconst row = await this.database.get<SqliteRow & { refs: number; anchors: number }>(\n\t\t\t\t`SELECT count(*) AS refs,\n\t\t\t\t\t(SELECT count(DISTINCT anchor_seq) FROM ${t.sessionLinks} WHERE session_id = ? AND children = 0 AND anchor_seq IS NOT NULL) AS anchors\n\t\t\t\tFROM ${t.sessionRefs} WHERE session_id = ?`,\n\t\t\t\tsession,\n\t\t\t\tsession,\n\t\t\t);\n\t\t\tcosts.set(session, Math.max(1, Number(row?.refs ?? 0) * Number(row?.anchors ?? 0)));\n\t\t}\n\t\treturn costs;\n\t}\n\n\t/**\n\t * The blobs that the snapshots `sessions` retain reference, in one statement. A session whose tree the index could\n\t * not follow retains every snapshot it records.\n\t */\n\tprivate async retainedBySessions(sessions: readonly string[], forks: boolean): Promise<string[]> {\n\t\tconst t = this.tables;\n\t\tconst ids = JSON.stringify(sessions);\n\t\tconst inherited = this.inheritedRecord(forks);\n\t\tconst rows = await this.database.all<SqliteRow & { hash: string }>(\n\t\t\t`SELECT DISTINCT record.hash FROM ${t.sessionRecords} AS record\n\t\t\tWHERE record.session_id IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")})\n\t\t\tAND (\n\t\t\t\t(record.session_id, record.snapshot_id) IN (${this.sessionHeads(`session_id IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")})`)})\n\t\t\t\tOR EXISTS (SELECT 1 FROM ${t.sessionLinks} AS broken WHERE broken.session_id = record.session_id AND broken.broken = 1)${inherited}\n\t\t\t)`,\n\t\t\tids,\n\t\t\tids,\n\t\t);\n\t\treturn rows.map((row) => row.hash);\n\t}\n\n\t/**\n\t * A condition, after `OR`, that another session inherits the session record `record` through a fork segment\n\t * (#6560); empty when `forks` says the fork segments table is not there, as while shared-history forks are off. A\n\t * fork that shares its parent's history stores none of the entries it inherits, so its own references never name\n\t * their snapshots: a record a segment names is kept whatever its session retains, as long as the segment lasts. A\n\t * delete batch reads whether the table exists in its own transaction, so it sees the segments that hold when it\n\t * commits.\n\t */\n\tprivate inheritedRecord(forks: boolean): string {\n\t\tif (!forks) return \"\";\n\t\treturn `\n\t\t\t\tOR EXISTS (SELECT 1 FROM ${this.forkSegments} AS segment WHERE segment.source_id = record.session_id AND record.seq BETWEEN segment.from_seq AND segment.to_seq)`;\n\t}\n\n\t/**\n\t * The blobs of `batch` that a session records and that the delete must keep, in one statement: those the snapshots\n\t * of `batch.sessions` retain, and those a session not among them records, whose snapshots the sweep did not walk.\n\t * Walks only `batch.sessions`, whose snapshot entries the sweep bounded when it made the batch (#5530).\n\t */\n\tprivate async keptBySessions(executor: SqliteExecutor, batch: SweepDeleteBatch, forks: boolean): Promise<string[]> {\n\t\tconst t = this.tables;\n\t\tconst ids = JSON.stringify(batch.sessions);\n\t\tconst walked = `(SELECT value FROM ${this.dialect.jsonValues(\"?\")})`;\n\t\tconst inherited = this.inheritedRecord(forks);\n\t\tconst rows = await executor.all<SqliteRow & { hash: string }>(\n\t\t\t`SELECT DISTINCT record.hash FROM ${t.sessionRecords} AS record\n\t\t\tWHERE record.hash IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")})\n\t\t\tAND (\n\t\t\t\trecord.session_id NOT IN ${walked}\n\t\t\t\tOR (record.session_id, record.snapshot_id) IN (${this.sessionHeads(`session_id IN ${walked}`)})\n\t\t\t\tOR EXISTS (SELECT 1 FROM ${t.sessionLinks} AS broken WHERE broken.session_id = record.session_id AND broken.broken = 1)${inherited}\n\t\t\t)`,\n\t\t\tJSON.stringify(batch.hashes),\n\t\t\tids,\n\t\t\tids,\n\t\t);\n\t\treturn rows.map((row) => row.hash);\n\t}\n\n\t/**\n\t * Stamps every blob of unknown age with the database clock, in hash order, in write transactions of at most\n\t * {@link SNAPSHOT_LEGACY_STAMP_BYTES} of blobs. Moves every in-row blob larger than\n\t * {@link SNAPSHOT_BLOB_CHUNK_BYTES} to chunks regardless of age. Chunk writes have the same byte bound;\n\t * publishing also frees the old in-row value, whose cost grows with its size. Starts with a turn of the event loop\n\t * when there is anything to do, so its first write does not share the turn of the sweep's last batch, and every\n\t * stamp and every statement of a move ends with a turn, whatever it found, so every page does too (#5530).\n\t */\n\tprivate async stampLegacyAges(options: SnapshotIndexOptions): Promise<void> {\n\t\tconst oversized = `chunks = 0 AND length(data) > ${SNAPSHOT_BLOB_CHUNK_BYTES}`;\n\t\tif (\n\t\t\t!(await this.database.get(\n\t\t\t\t`SELECT 1 FROM ${this.table} WHERE created_at = 0 UNION ALL SELECT 1 FROM ${this.table} WHERE ${oversized} LIMIT 1`,\n\t\t\t))\n\t\t)\n\t\t\treturn;\n\t\tawait this.betweenBatches(options.pace);\n\t\tlet after = \"\";\n\t\tfor (;;) {\n\t\t\toptions.signal?.throwIfAborted();\n\t\t\tconst page = await this.database.all<SqliteRow & { hash: string; size: number }>(\n\t\t\t\t`SELECT hash, length(data) AS size FROM ${this.table} WHERE created_at = 0 AND hash > ? UNION ALL SELECT hash, length(data) AS size FROM ${this.table} WHERE ${oversized} AND created_at > 0 AND hash > ? ORDER BY hash LIMIT ?`,\n\t\t\t\tafter,\n\t\t\t\tafter,\n\t\t\t\tSNAPSHOT_COLLECTION_BATCH,\n\t\t\t);\n\t\t\tlet batch: string[] = [];\n\t\t\tlet bytes = 0;\n\t\t\tfor (const { hash, size } of page) {\n\t\t\t\tconst oversized = Number(size) > SNAPSHOT_BLOB_CHUNK_BYTES;\n\t\t\t\tif (batch.length > 0 && (oversized || bytes + Number(size) > SNAPSHOT_LEGACY_STAMP_BYTES)) {\n\t\t\t\t\tawait this.stampInRows(batch, options);\n\t\t\t\t\tbatch = [];\n\t\t\t\t\tbytes = 0;\n\t\t\t\t}\n\t\t\t\tif (oversized) {\n\t\t\t\t\tawait this.moveLegacyBlobToChunks(hash, options);\n\t\t\t\t} else {\n\t\t\t\t\tbatch.push(hash);\n\t\t\t\t\tbytes += Number(size);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (batch.length > 0) await this.stampInRows(batch, options);\n\t\t\tif (page.length < SNAPSHOT_COLLECTION_BATCH) return;\n\t\t\tafter = page.at(-1)!.hash;\n\t\t}\n\t}\n\n\t/** Stamps the blobs `hashes` name that still have an unknown age, in their rows, in one write transaction. */\n\tprivate async stampInRows(hashes: readonly string[], options: SnapshotIndexOptions): Promise<void> {\n\t\toptions.signal?.throwIfAborted();\n\t\tawait this.write(options.pace, async (transaction) => {\n\t\t\tif (options.holder !== undefined) await this.renewClaim(transaction, options.holder);\n\t\t\tawait transaction.run(\n\t\t\t\t`UPDATE ${this.table} SET created_at = ${this.dialect.nowSeconds} WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")}) AND created_at = 0`,\n\t\t\t\tJSON.stringify(hashes),\n\t\t\t);\n\t\t});\n\t\tawait this.betweenBatches(options.pace);\n\t}\n\n\t/**\n\t * Moves an in-row legacy blob to chunks regardless of age. Reads its bytes without the writer and writes at most\n\t * {@link SNAPSHOT_LEGACY_STAMP_BYTES} per transaction while readers retain the in-row value. Publishing stamps\n\t * only an unknown age and frees the old value under the writer, with time proportional to the freed size. A stopped\n\t * move leaves chunks the next move reuses.\n\t * Gives the event loop a turn after reading the blob's bytes and after every transaction, also when another host\n\t * moved or deleted the blob first (#5530).\n\t */\n\tprivate async moveLegacyBlobToChunks(hash: string, options: SnapshotIndexOptions): Promise<void> {\n\t\tconst t = this.tables;\n\t\tconst unmoved = `hash = ? AND chunks = 0 AND length(data) > ${SNAPSHOT_BLOB_CHUNK_BYTES}`;\n\t\tconst legacy = await this.database.get<SqliteRow & { data: Uint8Array }>(\n\t\t\t`SELECT data FROM ${t.blobs} WHERE ${unmoved}`,\n\t\t\thash,\n\t\t);\n\t\tawait this.betweenBatches(options.pace);\n\t\tif (legacy === undefined) return;\n\t\tconst { data } = legacy;\n\t\tconst chunks = Math.ceil(data.byteLength / SNAPSHOT_BLOB_CHUNK_BYTES);\n\t\tconst perTransaction = SNAPSHOT_LEGACY_STAMP_BYTES / SNAPSHOT_BLOB_CHUNK_BYTES;\n\t\tfor (let first = 0; first < chunks; first += perTransaction) {\n\t\t\toptions.signal?.throwIfAborted();\n\t\t\tconst pending = await this.write(options.pace, async (transaction) => {\n\t\t\t\tif (options.holder !== undefined) await this.renewClaim(transaction, options.holder);\n\t\t\t\tif (!(await transaction.get(`SELECT 1 FROM ${t.blobs} WHERE ${unmoved}`, hash))) {\n\t\t\t\t\tawait this.dropStrayChunks(transaction, [hash]);\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tfor (let index = first; index < Math.min(first + perTransaction, chunks); index++) {\n\t\t\t\t\tawait transaction.run(\n\t\t\t\t\t\t`INSERT INTO ${t.blobChunks} (hash, idx, data) VALUES (?, ?, ?) ON CONFLICT DO NOTHING`,\n\t\t\t\t\t\thash,\n\t\t\t\t\t\tindex,\n\t\t\t\t\t\tdata.subarray(index * SNAPSHOT_BLOB_CHUNK_BYTES, (index + 1) * SNAPSHOT_BLOB_CHUNK_BYTES),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t});\n\t\t\tawait this.betweenBatches(options.pace);\n\t\t\tif (!pending) return;\n\t\t}\n\t\toptions.signal?.throwIfAborted();\n\t\tawait this.write(options.pace, async (transaction) => {\n\t\t\tif (options.holder !== undefined) await this.renewClaim(transaction, options.holder);\n\t\t\tconst { changes } = await transaction.run(\n\t\t\t\t`UPDATE ${t.blobs} SET data = ?, chunks = ?, created_at = CASE WHEN created_at = 0 THEN ${this.dialect.nowSeconds} ELSE created_at END WHERE ${unmoved} AND (SELECT count(*) FROM ${t.blobChunks} WHERE hash = ?) = ?`,\n\t\t\t\tnew Uint8Array(),\n\t\t\t\tchunks,\n\t\t\t\thash,\n\t\t\t\thash,\n\t\t\t\tchunks,\n\t\t\t);\n\t\t\tif (changes === 0) await this.dropStrayChunks(transaction, [hash]);\n\t\t});\n\t\tawait this.betweenBatches(options.pace);\n\t}\n\n\t/**\n\t * Deletes the chunks of the blobs `hashes` names whose rows hold their bytes themselves or are gone: chunks that a\n\t * move wrote before another writer deleted or replaced its row. Completed chunked blobs retain their chunks.\n\t */\n\tprivate async dropStrayChunks(transaction: SqliteExecutor, hashes: readonly string[]): Promise<void> {\n\t\tconst t = this.tables;\n\t\tawait transaction.run(\n\t\t\t`DELETE FROM ${t.blobChunks} WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")}) AND NOT EXISTS (SELECT 1 FROM ${t.blobs} AS stored WHERE stored.hash = ${t.blobChunks}.hash AND stored.chunks > 0)`,\n\t\t\tJSON.stringify(hashes),\n\t\t);\n\t}\n\n\t/**\n\t * Moves a chunk table that an earlier release created `WITHOUT ROWID` to the row layout of\n\t * {@link chunkTableDefinition} (#5541), in write transactions that each copy or free at most\n\t * {@link SNAPSHOT_CHUNK_MOVE_ROWS} chunks in all. It copies the rows, in key order, to a new table in that layout;\n\t * later transactions copy the rows written since and drop the copies of rows deleted since, and the one that leaves\n\t * the new table holding exactly the chunk table's rows gives it the chunk table's name, under which the old one is\n\t * kept until later transactions empty and drop it. The chunk table keeps its name, columns and key throughout, so\n\t * a process of an earlier release reads and writes it unchanged, and a chunk is copied with its bytes: its key, a\n\t * blob's hash and an index, names them. A stopped move resumes from what the tables hold. Does nothing on a chunk\n\t * table in the row layout, which every Postgres table is.\n\t */\n\tprivate async moveChunksToRowTable(options: SnapshotSweepOptions, offline = false): Promise<void> {\n\t\tconst t = this.tables;\n\t\tconst { next, retired } = chunkMoveTables(t);\n\t\t// The old table is `WITHOUT ROWID` under either name, so one statement tells a store with nothing to move, as\n\t\t// every store is once its move is over.\n\t\tconst probe = this.dialect.withoutRowidTables([t.blobChunks, retired]);\n\t\tconst clustered = async (executor: SqliteExecutor) =>\n\t\t\t(await executor.all<SqliteRow & { name: string }>(probe.sql, ...probe.params)).map((row) => row.name);\n\t\tconst rows = SNAPSHOT_CHUNK_MOVE_ROWS;\n\t\tconst pending = await clustered(this.database);\n\t\tif (pending.includes(retired)) await this.dropChunkTable(retired, options, offline);\n\t\tif (!pending.includes(t.blobChunks)) return;\n\t\t// A copy the disk has no room for would fill it (#5694): the table stays as it is, read and written as before, and a\n\t\t// partial copy an earlier collection left is dropped, its pages back on the database's free list.\n\t\tconst pendingMove = await this.chunkCopySpace(next, offline);\n\t\tif (pendingMove) {\n\t\t\tif (offline)\n\t\t\t\tthrow new Error(\n\t\t\t\t\tpendingMove.reason === \"free-space\"\n\t\t\t\t\t\t? `The chunk move needs ${pendingMove.requiredFreeBytes} free bytes; ${pendingMove.freeBytes} are available.`\n\t\t\t\t\t\t: \"Cannot measure free disk space for the offline chunk move.\",\n\t\t\t\t);\n\t\t\toptions.onPendingChunkMove?.(pendingMove);\n\t\t\treturn this.dropChunkTable(next, options);\n\t\t}\n\t\t// Copies the rows after the last one copied: no other statement writes the new table before it is renamed.\n\t\tconst copyNext = async (transaction: SqliteExecutor) => {\n\t\t\tconst last = await transaction.get<SqliteRow & { hash: string; idx: number }>(\n\t\t\t\t`SELECT hash, idx FROM ${next} ORDER BY hash DESC, idx DESC LIMIT 1`,\n\t\t\t);\n\t\t\tconst { changes } = await transaction.run(\n\t\t\t\t`INSERT INTO ${next} (hash, idx, data) SELECT hash, idx, data FROM ${t.blobChunks} WHERE (hash, idx) > (?, ?) ORDER BY hash, idx LIMIT ? ON CONFLICT DO NOTHING`,\n\t\t\t\tlast?.hash ?? \"\",\n\t\t\t\tlast?.idx ?? -1,\n\t\t\t\trows,\n\t\t\t);\n\t\t\treturn changes;\n\t\t};\n\t\t// Copies the first rows the new table lacks, wherever they are: rows written behind the copy.\n\t\tconst copyMissing = async (transaction: SqliteExecutor) => {\n\t\t\tconst { changes } = await transaction.run(\n\t\t\t\t`INSERT INTO ${next} (hash, idx, data) SELECT old.hash, old.idx, old.data FROM ${t.blobChunks} AS old WHERE NOT EXISTS (SELECT 1 FROM ${next} AS copy WHERE copy.hash = old.hash AND copy.idx = old.idx) ORDER BY old.hash, old.idx LIMIT ?`,\n\t\t\t\trows,\n\t\t\t);\n\t\t\treturn changes;\n\t\t};\n\t\t// The rows the new table holds and the chunk table no longer does: copies of rows deleted since they were copied.\n\t\tconst stale = `SELECT hash, idx FROM ${next} EXCEPT SELECT hash, idx FROM ${t.blobChunks}`;\n\t\tfor (let copying = true; ; ) {\n\t\t\toptions.signal?.throwIfAborted();\n\t\t\tif (offline) await this.requireOfflineBatchSpace();\n\t\t\tlet moved: boolean;\n\t\t\ttry {\n\t\t\t\tmoved = await this.write(options.pace, async (transaction) => {\n\t\t\t\t\tif (options.holder !== undefined) await this.renewClaim(transaction, options.holder);\n\t\t\t\t\tif (!(await clustered(transaction)).includes(t.blobChunks)) return true;\n\t\t\t\t\tawait transaction.exec(chunkTableDefinition(next, this.dialect));\n\t\t\t\t\tif (copying) {\n\t\t\t\t\t\tcopying = (await copyNext(transaction)) === rows;\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\t// Rows copied and stale copies dropped share the transaction's rows. The tables are renamed only by a transaction\n\t\t\t\t\t// that leaves the new table holding exactly the chunk table's rows; otherwise the next transaction continues.\n\t\t\t\t\tconst copied = await copyMissing(transaction);\n\t\t\t\t\tif (copied === rows) return false;\n\t\t\t\t\tconst room = rows - copied;\n\t\t\t\t\tconst { changes: dropped } = await transaction.run(\n\t\t\t\t\t\t`DELETE FROM ${next} WHERE (hash, idx) IN (${stale} LIMIT ?)`,\n\t\t\t\t\t\troom,\n\t\t\t\t\t);\n\t\t\t\t\tif (dropped === room && (await transaction.get(`${stale} LIMIT 1`)) !== undefined) return false;\n\t\t\t\t\t// Renaming the table would point a trigger that names it at the old table: both of the delete triggers releases\n\t\t\t\t\t// installed are dropped, and the current one is installed again on the new table.\n\t\t\t\t\tawait transaction.exec(this.dialect.dropTrigger(`${t.blobs}_chunks_delete`, t.blobs));\n\t\t\t\t\tawait transaction.exec(this.dialect.dropTrigger(`${t.blobs}_chunks_delete_all`, t.blobs));\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait transaction.exec(`ALTER TABLE ${t.blobChunks} RENAME TO ${retired}`);\n\t\t\t\t\t\tawait transaction.exec(`ALTER TABLE ${next} RENAME TO ${t.blobChunks}`);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tawait this.confirmRenameBlocker(transaction, error);\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t\tawait transaction.exec(this.dialect.renderTrigger(chunksDeleteTrigger(t)));\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\t// A disk that fills up ends the move, not the collection (#5694): the partial copy is dropped, its pages back on\n\t\t\t\t// the database's free list, and a later collection tries again.\n\t\t\t\tif (offline || !isStorageSpaceFailure(error)) throw error;\n\t\t\t\tawait this.betweenBatches(options.pace);\n\t\t\t\treturn this.dropChunkTable(next, options);\n\t\t\t}\n\t\t\tif (offline) await this.checkpointChunkMove();\n\t\t\tawait this.betweenBatches(options.pace);\n\t\t\tif (moved) break;\n\t\t}\n\t\tawait this.dropChunkTable(retired, options, offline);\n\t}\n\n\t/**\n\t * Records on `error`, a rename that failed in `transaction`, the trigger or view SQLite named in it, when the schema\n\t * holds exactly one trigger or view that the error's words can name (#5622). The failed statement left the\n\t * transaction open on the schema SQLite checked, so that object is the one SQLite named. Otherwise, or when the schema\n\t * cannot be read, nothing is recorded and the collection warning names no object.\n\t */\n\tprivate async confirmRenameBlocker(transaction: SqliteExecutor, error: unknown): Promise<void> {\n\t\tconst candidates = renameBlockerCandidates(error);\n\t\tif (candidates.length === 0) return;\n\t\tconst names = JSON.stringify([...new Set(candidates.map((candidate) => candidate.name))]);\n\t\tconst objects = (schema: string) =>\n\t\t\t`SELECT type, name FROM ${schema} WHERE type IN ('trigger', 'view') AND name IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")})`;\n\t\tconst rows = await transaction\n\t\t\t.all<SqliteRow & SchemaObject>(\n\t\t\t\t`${objects(\"sqlite_master\")} UNION ALL ${objects(\"sqlite_temp_master\")}`,\n\t\t\t\tnames,\n\t\t\t\tnames,\n\t\t\t)\n\t\t\t.catch(() => undefined);\n\t\tif (rows === undefined) return;\n\t\tconst named = rows.filter((row) =>\n\t\t\tcandidates.some((candidate) => candidate.type === row.type && candidate.name === row.name),\n\t\t);\n\t\tconst [only] = named;\n\t\tif (named.length === 1 && only !== undefined && typeof error === \"object\" && error !== null)\n\t\t\tReflect.defineProperty(error, RENAME_BLOCKER, { value: { type: only.type, name: only.name } });\n\t}\n\n\t/**\n\t * Whether the file system of a SQLite database file has room to copy what is left of the chunk table to the\n\t * row layout (#5694): the copy grows the file by the bytes its free pages do not hold, and the write-ahead log can\n\t * hold every page the copy writes until a checkpoint moves them into the file, with\n\t * {@link SNAPSHOT_CHUNK_MOVE_HEADROOM_BYTES} left over; the database's own `freeBytes` says how much the file system\n\t * holds. A database whose disk this process cannot see, such as a libSQL server, moves only what is left of a table\n\t * no larger than that headroom: the move must never be what fills a disk, and the old layout works as before.\n\t */\n\tprivate async chunkCopySpace(next: string, offline: boolean): Promise<PendingChunkMove | undefined> {\n\t\tconst rowsOf = async (table: string) =>\n\t\t\tNumber(\n\t\t\t\t(await this.database.get<SqliteRow & { rows: number }>(`SELECT count(*) AS rows FROM ${table}`))?.rows ?? 0,\n\t\t\t);\n\t\tconst copy = this.dialect.tableExists(next);\n\t\tconst copyExists = async () => (await this.database.get(copy.sql, ...copy.params)) !== undefined;\n\t\t// The chunks the copy lacks, counted in one statement against what it holds: a copy may also hold copies of chunks\n\t\t// deleted since, which take no more room, and chunks stored since that it lacks.\n\t\tconst lacking = async () =>\n\t\t\tNumber(\n\t\t\t\t(\n\t\t\t\t\tawait this.database.get<SqliteRow & { rows: number }>(\n\t\t\t\t\t\t`SELECT count(*) AS rows FROM ${this.tables.blobChunks} AS old WHERE NOT EXISTS (SELECT 1 FROM ${next} AS copy WHERE copy.hash = old.hash AND copy.idx = old.idx)`,\n\t\t\t\t\t)\n\t\t\t\t)?.rows ?? 0,\n\t\t\t);\n\t\tconst rows = !(await copyExists())\n\t\t\t? await rowsOf(this.tables.blobChunks)\n\t\t\t: await lacking().catch(async (error: unknown) => {\n\t\t\t\t\t// Another collector finished the move, which took the copy's name, or dropped the copy, since it was found:\n\t\t\t\t\t// none of it is left to count on. The move's own transactions see which.\n\t\t\t\t\tif (!(await copyExists())) return rowsOf(this.tables.blobChunks);\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\tconst left = rows * SNAPSHOT_BLOB_CHUNK_BYTES;\n\t\tlet free: number | undefined;\n\t\ttry {\n\t\t\tfree = await this.database.freeBytes?.();\n\t\t} catch {\n\t\t\t// A reading that fails is no reading: the collection goes on as for a disk this process cannot see.\n\t\t\tfree = undefined;\n\t\t}\n\t\tif (free === undefined)\n\t\t\treturn !offline && left <= SNAPSHOT_CHUNK_MOVE_HEADROOM_BYTES\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\treason: \"space-unknown\",\n\t\t\t\t\t\tremainingBytes: left,\n\t\t\t\t\t\tautomaticLimitBytes: SNAPSHOT_CHUNK_MOVE_HEADROOM_BYTES,\n\t\t\t\t\t};\n\t\tconst freePages = await this.database.get<SqliteRow & { bytes: number }>(\n\t\t\t\"SELECT (SELECT freelist_count FROM pragma_freelist_count()) * (SELECT page_size FROM pragma_page_size()) AS bytes\",\n\t\t);\n\t\tconst reused = Math.min(left, Number(freePages?.bytes ?? 0));\n\t\tconst requiredFreeBytes =\n\t\t\tleft - reused + (offline ? OFFLINE_CHUNK_LOG_ALLOWANCE : left) + SNAPSHOT_CHUNK_MOVE_HEADROOM_BYTES;\n\t\treturn free >= requiredFreeBytes\n\t\t\t? undefined\n\t\t\t: { reason: \"free-space\", remainingBytes: left, requiredFreeBytes, freeBytes: free };\n\t}\n\n\t/**\n\t * Empties `table`, the chunk table a move to the row layout retired or a partial copy of the move (#5694), in write\n\t * transactions of at most {@link SNAPSHOT_CHUNK_MOVE_ROWS} rows, from its first key on, then drops it; its pages go\n\t * to the database's free list. A full disk stops it without a failure: a later collection goes on.\n\t */\n\tprivate async dropChunkTable(table: string, options: SnapshotIndexOptions, offline = false): Promise<void> {\n\t\tconst probe = this.dialect.tableExists(table);\n\t\tif ((await this.database.get(probe.sql, ...probe.params)) === undefined) return;\n\t\tfor (;;) {\n\t\t\toptions.signal?.throwIfAborted();\n\t\t\tif (offline) await this.requireOfflineBatchSpace();\n\t\t\tlet dropped: boolean;\n\t\t\ttry {\n\t\t\t\tdropped = await this.write(options.pace, async (transaction) => {\n\t\t\t\t\tif (options.holder !== undefined) await this.renewClaim(transaction, options.holder);\n\t\t\t\t\tif ((await transaction.get(probe.sql, ...probe.params)) === undefined) return true;\n\t\t\t\t\tconst last = await transaction.get<SqliteRow & { hash: string; idx: number }>(\n\t\t\t\t\t\t`SELECT hash, idx FROM ${table} ORDER BY hash, idx LIMIT 1 OFFSET ?`,\n\t\t\t\t\t\tSNAPSHOT_CHUNK_MOVE_ROWS - 1,\n\t\t\t\t\t);\n\t\t\t\t\tif (last === undefined) {\n\t\t\t\t\t\tawait transaction.exec(`DROP TABLE IF EXISTS ${table}`);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tawait transaction.run(`DELETE FROM ${table} WHERE (hash, idx) <= (?, ?)`, last.hash, last.idx);\n\t\t\t\t\treturn false;\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tif (!offline && isStorageSpaceFailure(error)) return;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tif (offline) await this.checkpointChunkMove();\n\t\t\tawait this.betweenBatches(options.pace);\n\t\t\tif (dropped) return;\n\t\t}\n\t}\n\n\t/** {@link completeIndex}, then {@link sweep}: what a manual collection does. */\n\tasync collectGarbage(options: SnapshotSweepOptions): Promise<readonly string[]> {\n\t\tawait this.completeIndex(options);\n\t\treturn this.sweep(options);\n\t}\n\n\t/**\n\t * The snapshots the sessions that `sessions` selects keep, a condition on `session_id` (#5530), as a subquery of\n\t * `(session_id, snapshot_id)`: for every leaf of their session trees,\n\t * the latest snapshot entry of each checkout on the leaf's branch, followed through each entry's link to the\n\t * nearest snapshot entry before it. A leaf costs the snapshot entries on its branch and never a message, and leaves\n\t * that share their latest snapshot are followed once. Roots are grouped into checkouts the way resume does: a root\n\t * a restore moved to is the root it moved from, taking the branch's restores from the newest back. Resume compares\n\t * canonical paths where this compares the recorded ones, so a checkout reached through a symbolic link can keep one\n\t * snapshot more than resume needs and never fewer. A head that records a partly restored worktree also keeps the\n\t * snapshot it lacks, named in `degraded_from`, for {@link DEGRADED_RESTORE_RETENTION_DAYS} (#4922).\n\t */\n\tprivate sessionHeads(sessions: string): string {\n\t\tconst t = this.tables;\n\t\treturn `WITH RECURSIVE\n\t\t\topen_anchors(session_id, seq) AS (SELECT DISTINCT session_id, anchor_seq FROM ${t.sessionLinks} WHERE ${sessions} AND children = 0 AND anchor_seq IS NOT NULL),\n\t\t\tbranch(session_id, start_seq, root, snapshot_id, restore_from, restore_to, degraded_from, degraded_since, prev_seq, depth) AS (\n\t\t\t\tSELECT ref.session_id, ref.seq, ref.root, ref.snapshot_id, ref.restore_from, ref.restore_to, ref.degraded_from, ref.degraded_since, ref.prev_seq, 0 FROM open_anchors AS anchor JOIN ${t.sessionRefs} AS ref ON ref.session_id = anchor.session_id AND ref.seq = anchor.seq\n\t\t\t\tUNION ALL\n\t\t\t\tSELECT branch.session_id, branch.start_seq, ref.root, ref.snapshot_id, ref.restore_from, ref.restore_to, ref.degraded_from, ref.degraded_since, ref.prev_seq, branch.depth + 1 FROM branch JOIN ${t.sessionRefs} AS ref ON ref.session_id = branch.session_id AND ref.seq = branch.prev_seq\n\t\t\t),\n\t\t\twalk(session_id, start_seq, root, current, position) AS (\n\t\t\t\tSELECT DISTINCT session_id, start_seq, root, root, -1 FROM branch\n\t\t\t\tUNION ALL\n\t\t\t\tSELECT walk.session_id, walk.start_seq, walk.root, CASE WHEN restore.restore_to = walk.current THEN restore.restore_from ELSE walk.current END, restore.depth\n\t\t\t\tFROM walk JOIN branch AS restore ON restore.session_id = walk.session_id AND restore.start_seq = walk.start_seq AND restore.restore_to IS NOT NULL\n\t\t\t\t\tAND restore.depth = (SELECT min(later.depth) FROM branch AS later WHERE later.session_id = walk.session_id AND later.start_seq = walk.start_seq AND later.restore_to IS NOT NULL AND later.depth > walk.position)\n\t\t\t),\n\t\t\tcheckout(session_id, start_seq, root, original) AS (\n\t\t\t\tSELECT session_id, start_seq, root, current FROM walk AS last WHERE position = (SELECT max(other.position) FROM walk AS other WHERE other.session_id = last.session_id AND other.start_seq = last.start_seq AND other.root = last.root)\n\t\t\t),\n\t\t\tsession_heads(session_id, start_seq, original, depth) AS (\n\t\t\t\tSELECT branch.session_id, branch.start_seq, checkout.original, min(branch.depth) FROM branch JOIN checkout ON checkout.session_id = branch.session_id AND checkout.start_seq = branch.start_seq AND checkout.root = branch.root GROUP BY branch.session_id, branch.start_seq, checkout.original\n\t\t\t),\n\t\t\thead_records(session_id, snapshot_id, degraded_from, degraded_since) AS (\n\t\t\t\tSELECT branch.session_id, branch.snapshot_id, branch.degraded_from, branch.degraded_since FROM session_heads JOIN checkout ON checkout.session_id = session_heads.session_id AND checkout.start_seq = session_heads.start_seq AND checkout.original = session_heads.original JOIN branch ON branch.session_id = checkout.session_id AND branch.start_seq = checkout.start_seq AND branch.root = checkout.root AND branch.depth = session_heads.depth\n\t\t\t)\n\t\t\tSELECT session_id, snapshot_id FROM head_records\n\t\t\tUNION SELECT session_id, degraded_from FROM head_records WHERE degraded_from IS NOT NULL AND (degraded_since IS NULL OR degraded_since > ${this.dialect.nowSeconds} - ${DEGRADED_PIN_SECONDS})`;\n\t}\n\n\t/**\n\t * The next {@link SNAPSHOT_COLLECTION_BATCH} blobs whose `created_at` is at least `minimumAge` whole seconds behind\n\t * the database clock, oldest first, after `after`: a range of the age index, whatever references them. A page after\n\t * `after` searches the index from `after`, which already excludes an unknown age (0): with `created_at > 0` as a\n\t * second lower bound, SQLite searched from the oldest blob instead, so each page cost more than the one before (#5530).\n\t */\n\tprivate page(minimumAge: number, after: PageRow | undefined): Promise<PageRow[]> {\n\t\tconst t = this.tables;\n\t\treturn after === undefined\n\t\t\t? this.database.all<PageRow>(\n\t\t\t\t\t`SELECT created_at, hash FROM ${t.blobs} WHERE created_at > 0 AND created_at <= ${this.dialect.nowSeconds} - ? ORDER BY created_at, hash LIMIT ?`,\n\t\t\t\t\tminimumAge,\n\t\t\t\t\tSNAPSHOT_COLLECTION_BATCH,\n\t\t\t\t)\n\t\t\t: this.database.all<PageRow>(\n\t\t\t\t\t`SELECT created_at, hash FROM ${t.blobs} WHERE created_at <= ${this.dialect.nowSeconds} - ? AND (created_at, hash) > (?, ?) ORDER BY created_at, hash LIMIT ?`,\n\t\t\t\t\tminimumAge,\n\t\t\t\t\tafter.created_at,\n\t\t\t\t\tafter.hash,\n\t\t\t\t\tSNAPSHOT_COLLECTION_BATCH,\n\t\t\t\t);\n\t}\n\n\t/**\n\t * Claims this table's next collection for `holder` when it is due on the database clock: none was ever claimed, or\n\t * the last one finished at least `intervalSeconds` ago, or an unfinished one has renewed its claim in no batch for\n\t * {@link SNAPSHOT_COLLECTION_LEASE_SECONDS}, so it stopped. A failed collection finishes with its error code, so it\n\t * backs off for the whole interval. A read without the write lock answers \"not due\" first; only a due claim takes\n\t * the lock, waiting for it on `pace` when one is given.\n\t */\n\tasync claimCollection(intervalSeconds: number, holder: string, pace?: BackgroundCollectionPace): Promise<boolean> {\n\t\tconst due = `id = 1 AND (claimed_at IS NULL OR (finished_at IS NULL AND claimed_at <= ${this.dialect.nowSeconds} - ?) OR (finished_at IS NOT NULL AND finished_at <= ${this.dialect.nowSeconds} - ?))`;\n\t\tconst lease = SNAPSHOT_COLLECTION_LEASE_SECONDS;\n\t\tif (!(await this.database.get(`SELECT id FROM ${this.tables.collection} WHERE ${due}`, lease, intervalSeconds)))\n\t\t\treturn false;\n\t\tconst { changes } = await this.write(pace, (transaction) =>\n\t\t\ttransaction.run(\n\t\t\t\t`UPDATE ${this.tables.collection} SET claimed_at = ${this.dialect.nowSeconds}, holder = ?, finished_at = NULL, deleted = NULL, error_code = NULL WHERE ${due}`,\n\t\t\t\tholder,\n\t\t\t\tlease,\n\t\t\t\tintervalSeconds,\n\t\t\t),\n\t\t);\n\t\treturn changes === 1;\n\t}\n\n\tprivate renewClaim(transaction: SqliteExecutor, holder: string): Promise<unknown> {\n\t\treturn transaction.run(\n\t\t\t`UPDATE ${this.tables.collection} SET claimed_at = ${this.dialect.nowSeconds} WHERE id = 1 AND holder = ?`,\n\t\t\tholder,\n\t\t);\n\t}\n\n\t/**\n\t * Records how `holder`'s claimed collection ended; a later claim by another holder is left alone. Waits for the\n\t * write lock on `pace` when one is given.\n\t */\n\tasync recordCollection(\n\t\tholder: string,\n\t\toutcome: { readonly deleted: number; readonly errorCode: string | null },\n\t\tpace?: BackgroundCollectionPace,\n\t): Promise<void> {\n\t\tawait this.write(pace, (transaction) =>\n\t\t\ttransaction.run(\n\t\t\t\t`UPDATE ${this.tables.collection} SET finished_at = ${this.dialect.nowSeconds}, deleted = ?, error_code = ? WHERE id = 1 AND holder = ?`,\n\t\t\t\toutcome.deleted,\n\t\t\t\toutcome.errorCode,\n\t\t\t\tholder,\n\t\t\t),\n\t\t);\n\t}\n\n\t/** Waits between two batches: on `pace` in the background, otherwise until the event loop has run once. */\n\tprivate betweenBatches(pace: BackgroundCollectionPace | undefined): Promise<void> {\n\t\treturn pace === undefined ? yieldToEventLoop() : pace.wait(0);\n\t}\n\n\t/**\n\t * Runs `body` in a write transaction. With `pace`, the transaction never waits for a write lock another connection\n\t * holds: it is refused at once (SQLite `StorageWriteLockTimeoutError` or PostgreSQL not-applied `lock-conflict`) and\n\t * tried again after a wait on `pace` that doubles each time, so the process can exit meanwhile; once the waits add\n\t * up to {@link SNAPSHOT_COLLECTION_LEASE_SECONDS}, it rejects with the refusal.\n\t */\n\tprivate async write<T>(\n\t\tpace: BackgroundCollectionPace | undefined,\n\t\tbody: (transaction: SqliteExecutor) => Promise<T>,\n\t): Promise<T> {\n\t\tif (pace === undefined) return this.database.transaction(body);\n\t\tlet waited = 0;\n\t\tfor (let delay = SNAPSHOT_COLLECTION_LOCK_RETRY_FIRST_MS; ; ) {\n\t\t\ttry {\n\t\t\t\treturn await this.database.transaction(body, { lockWaitMs: 0 });\n\t\t\t} catch (error) {\n\t\t\t\tconst lockRefused =\n\t\t\t\t\terror instanceof StorageWriteLockTimeoutError ||\n\t\t\t\t\t(error instanceof StorageTransientError &&\n\t\t\t\t\t\terror.code === \"lock-conflict\" &&\n\t\t\t\t\t\terror.outcome === \"not-applied\");\n\t\t\t\tif (!lockRefused || waited >= SNAPSHOT_COLLECTION_LEASE_SECONDS * 1_000) throw error;\n\t\t\t}\n\t\t\tawait pace.wait(delay);\n\t\t\tpace.signal?.throwIfAborted();\n\t\t\twaited += delay;\n\t\t\tdelay = Math.min(delay * 2, SNAPSHOT_COLLECTION_LOCK_RETRY_MAX_MS);\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"blob-store.js","sourceRoot":"","sources":["../../../src/core/worktree-snapshot/blob-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AACxF,OAAO,EAAE,+BAA+B,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAU/G,OAAO,EAAE,SAAS,EAAoE,MAAM,uBAAuB,CAAC;AACpH,OAAO,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAC3F,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACjH,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,qBAAqB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K,CAAC;YAChB,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,qCAAqC,CAAC,CAAC;QACpE,CAAC;IACF,CAAC;CACD","sourcesContent":["import { type LongTimeout, setLongTimeout } from \"@bastani/atomic-timers\";\nimport { storageSchemaCurrent, transactionFinisher } from \"../storage/added-exports.js\";\nimport { MAX_SEQUENCE_REQUEST_STATEMENTS, noteStorageSchemaTables } from \"../storage/added-exports-0-10-11.js\";\nimport type {\n\tSqliteDatabase,\n\tSqliteExecutor,\n\tSqliteRow,\n\tSqliteStatement,\n\tSqliteTransactionOptions,\n\tSqliteValue,\n\tStorageDescriptor,\n} from \"../storage/database.js\";\nimport { dialectOf, type StorageDialect, type StorageJsonSource, type StorageTrigger } from \"../storage/dialect.js\";\nimport { StorageTransientError, StorageWriteLockTimeoutError } from \"../storage/errors.js\";\nimport { applyStorageMigrations, ensureStorageSchema, withShortSchemaLockWaits } from \"../storage/migrations.js\";\nimport { renderStorageIdentifiers, storageMigrationTable, validateStoragePrefix } from \"../storage/prefix.js\";\nimport { type StorageSchemaCatalog, schemaCatalogOf, withStorageSchemaCatalog } from \"../storage/schema-catalog.js\";\nimport { queueSqliteSchemaSetup, type SqliteSchemaBatchContext } from \"../storage/sqlite-open-batch.js\";\nimport { statementBatch } from \"../storage/statement-batches.js\";\nimport type { BatchWrite } from \"../storage/statement-sequence.js\";\nimport type { WorkspaceCollectionError } from \"./errors.ts\";\nimport { forkInheritedBlobGuard, forkInheritedBlobGuardName } from \"./fork-blob-guard.ts\";\nimport {\n\tentriesIndexComplete,\n\tforkLinksCheck,\n\tforkSegmentsTable,\n\tforkSessionLink,\n\tlegacyForkLinksTriggerName,\n\tmaterializedForkLinks,\n\townDuplicate,\n\townParentSeq,\n\tparentColumns,\n\tsnapshotEntryCondition,\n} from \"./fork-snapshot-index.ts\";\nimport type { SnapshotBlob, SnapshotBlobStore, WorktreeSnapshot } from \"./types.ts\";\n\n/** A trigger or view, by its exact name. */\ninterface SchemaObject {\n\treadonly type: \"trigger\" | \"view\";\n\treadonly name: string;\n}\n\n/**\n * The key under which a failed rename's error carries the trigger or view that stopped it, once confirmed in the\n * database (#5622); `WorkspaceCollectionError` names it in its hint. A `Symbol.for` key, shared without an import.\n */\nconst RENAME_BLOCKER = Symbol.for(\"atomic-snapshots/rename-blocker@1\");\n\n/** What SQLite writes after an object's name when the object stops a schema change only once the change is made. */\nconst RENAME_BLOCKER_WHEN = [\" after rename\", \" after drop column\"];\n\n/**\n * Every trigger or view that `error`, a failed rename, or an error it wraps can name. SQLite names a trigger or view\n * that no longer compiles, such as one that refers to a dropped table, as `error in <type> <name>[ <when>]: <reason>`,\n * and drivers add their own prefix. The name is not quoted, so `error in view sales after rename: …` can name a view\n * `sales after rename` or a view `sales`, and a name can hold `: `. Only the database can tell which object it is.\n */\nfunction renameBlockerCandidates(error: unknown): SchemaObject[] {\n\tconst candidates: SchemaObject[] = [];\n\tlet current = error;\n\tfor (let depth = 0; depth < 8 && current instanceof Error; depth++, current = current.cause)\n\t\tfor (const match of current.message.matchAll(/\\berror in (trigger|view) /gu)) {\n\t\t\tconst type = match[1] as SchemaObject[\"type\"];\n\t\t\tconst rest = current.message.slice(match.index + match[0].length);\n\t\t\tfor (let end = rest.indexOf(\": \"); end !== -1; end = rest.indexOf(\": \", end + 1)) {\n\t\t\t\tconst name = rest.slice(0, end);\n\t\t\t\tcandidates.push({ type, name });\n\t\t\t\tfor (const when of RENAME_BLOCKER_WHEN)\n\t\t\t\t\tif (name.endsWith(when)) candidates.push({ type, name: name.slice(0, -when.length) });\n\t\t\t}\n\t\t}\n\treturn candidates;\n}\n\n/** Every blob hash a snapshot needs to be restored: its chain's patches and its bundle. */\nexport function snapshotBlobHashes(snapshot: WorktreeSnapshot): string[] {\n\tconst hashes = snapshot.chain.flatMap((link) => (link.patch === null ? [] : [link.patch]));\n\tif (snapshot.bundle) hashes.push(snapshot.bundle.blob);\n\treturn [...new Set(hashes)];\n}\n\n/**\n * Compares two blob hashes as `ORDER BY hash` with the dialect's `byteOrderCollation` does: the hashes are ASCII (hex\n * digests), whose UTF-16 code unit order is their byte order.\n */\nfunction byteOrder(first: string, second: string): number {\n\treturn first < second ? -1 : first > second ? 1 : 0;\n}\n\n/**\n * The blob hashes a recorded snapshot names, read as the reference index reads them: a write never fails on a record\n * whose chain or bundle is not well formed, which references nothing it cannot read.\n */\nfunction wellFormedBlobHashes(snapshot: WorktreeSnapshot): string[] {\n\tconst chain: readonly WorktreeSnapshot[\"chain\"][number][] = Array.isArray(snapshot?.chain) ? snapshot.chain : [];\n\tconst hashes = chain.flatMap((link) => (typeof link?.patch === \"string\" ? [link.patch] : []));\n\tif (typeof snapshot?.bundle?.blob === \"string\") hashes.push(snapshot.bundle.blob);\n\treturn hashes;\n}\n\nexport class MemorySnapshotBlobStore implements SnapshotBlobStore {\n\tprivate readonly blobs = new Map<string, Uint8Array>();\n\n\tasync putBlobs(blobs: readonly SnapshotBlob[]): Promise<void> {\n\t\tfor (const blob of blobs) if (!this.blobs.has(blob.hash)) this.blobs.set(blob.hash, Uint8Array.from(blob.data));\n\t}\n\tasync getBlob(hash: string): Promise<Uint8Array | undefined> {\n\t\tconst data = this.blobs.get(hash);\n\t\treturn data === undefined ? undefined : Uint8Array.from(data);\n\t}\n\tasync refreshBlobs(hashes: readonly string[]): Promise<boolean> {\n\t\treturn hashes.every((hash) => this.blobs.has(hash));\n\t}\n\tasync listBlobHashes(): Promise<readonly string[]> {\n\t\treturn [...this.blobs.keys()];\n\t}\n}\n\n/**\n * The tables of one blob table's reference index, all under the blob table's prefix. Triggers on the session store's\n * tables, and on the tables a workflow run journal of an earlier release left in the database, keep them current in the\n * same transaction as each write, so collection reads only these tables and never a journal or a session.\n */\nexport interface SnapshotIndexTables {\n\t/**\n\t * `(hash, bytes, data, created_at, chunks)`: one row per blob. A blob of at most {@link SNAPSHOT_BLOB_CHUNK_BYTES}\n\t * is in `data` (`chunks` 0, as every blob written before chunks was); a larger one has an empty `data` and its bytes\n\t * in `chunks` rows of {@link SnapshotIndexTables.blobChunks}.\n\t */\n\treadonly blobs: string;\n\t/**\n\t * `(hash, idx, data)`: the chunks of each blob larger than {@link SNAPSHOT_BLOB_CHUNK_BYTES}, in order (#4954). An\n\t * ordinary table whose primary key is an index of its own, never `WITHOUT ROWID` (#5541): see\n\t * {@link chunkTableDefinition}.\n\t */\n\treadonly blobChunks: string;\n\t/** `(run_id, hash)`: each blob a run's tool or stage checkpoints reference, once per run. */\n\treadonly runRefs: string;\n\t/** `(run_id, retained, seq)`: whether the run's latest status keeps its snapshots, from the event at `seq`. */\n\treadonly runState: string;\n\t/**\n\t * `(session_id, seq, root, snapshot_id, prev_seq, restore_from, restore_to, degraded_from, degraded_since)`: one row\n\t * per `worktree_snapshot` session entry, with the `seq` of the nearest snapshot entry before it on its branch and,\n\t * for the entry written when a snapshot was restored into a new worktree, the root it moved from and to. An entry of\n\t * a partly restored worktree names the snapshot it lacks in `degraded_from` (#4922), with `degraded_since`, on the\n\t * database clock, when the entries naming it began: the nearest snapshot entry before it's when that one names it\n\t * too, else when this entry was indexed.\n\t */\n\treadonly sessionRefs: string;\n\t/**\n\t * `(session_id, seq, entry_id, parent_id, anchor_seq, children, broken)`: one row per session entry, so that a\n\t * branch can be followed without reading entries: `anchor_seq` is the latest snapshot entry at or before the entry\n\t * on its branch, `children` counts its child entries (none: a leaf of the session tree), and `broken` marks an\n\t * entry whose parent the index could not follow, which makes the session keep every snapshot it records.\n\t */\n\treadonly sessionLinks: string;\n\t/** `(session_id, seq, snapshot_id, hash)`: the blobs of each snapshot record a session entry carries. */\n\treadonly sessionRecords: string;\n\t/**\n\t * `(owner, hash)`: the blobs of each snapshot that dispatched work carries (#4503), once per row that carries it: a\n\t * pool work row (owner `work:<id>`) or a root's pool binding (owner `root:<run id>`). A reference lasts as long as its\n\t * row, whatever any run's status.\n\t */\n\treadonly carriedRefs: string;\n\t/** One row: the last collection's claim on the database clock and its outcome. */\n\treadonly collection: string;\n\t/** `(source, watermark, backfilled_through)`: how far the index covers each table that holds references. */\n\treadonly sources: string;\n}\n\nexport function snapshotIndexTables(prefix = \"\"): SnapshotIndexTables {\n\tconst p = validateStoragePrefix(prefix);\n\treturn Object.freeze({\n\t\tblobs: `${p}snapshot_blobs`,\n\t\tblobChunks: `${p}snapshot_blob_chunks`,\n\t\trunRefs: `${p}snapshot_run_refs`,\n\t\trunState: `${p}snapshot_run_state`,\n\t\tsessionRefs: `${p}snapshot_session_refs`,\n\t\tsessionLinks: `${p}snapshot_session_links`,\n\t\tsessionRecords: `${p}snapshot_session_records`,\n\t\tcarriedRefs: `${p}snapshot_carried_refs`,\n\t\tcollection: `${p}snapshot_collection`,\n\t\tsources: `${p}snapshot_index_sources`,\n\t});\n}\n\n/**\n * The most bytes of a snapshot blob one row holds. A larger blob, such as the patch of a checkout with a large\n * untracked file, is stored as rows of at most this size, written in one transaction: a libSQL server refuses a value\n * or row over 5,000,000 bytes by default (sqld's `max_row_size`) and a response over 10 MB, so one row per blob failed\n * on it below the documented `maxFileBytes` (#4954). A different size needs a different table name, because a blob's\n * rows are addressed by their index.\n */\nexport const SNAPSHOT_BLOB_CHUNK_BYTES = 1024 * 1024;\n\n/** The schema domain of the blob table and its reference index, in the prefix's migration ledger. */\nexport const SNAPSHOT_BLOB_DOMAIN = \"snapshot-blobs\";\n\n/** Why collection left a legacy chunk table in place. Byte estimates are from the decision, before any partial copy was discarded. */\nexport type PendingChunkMove =\n\t| {\n\t\t\treadonly reason: \"free-space\";\n\t\t\treadonly remainingBytes: number;\n\t\t\treadonly requiredFreeBytes: number;\n\t\t\treadonly freeBytes: number;\n\t }\n\t| { readonly reason: \"space-unknown\"; readonly remainingBytes: number; readonly automaticLimitBytes: number };\n\nexport type SnapshotCollectionSkipReason = \"disabled\" | \"unsupported\" | \"in-progress\" | \"not-due\";\n\n/** How one automatic collection ended. Its promise never rejects: a failure is an outcome, reported once. */\nexport type SnapshotCollectionOutcome =\n\t| { readonly status: \"skipped\"; readonly reason: SnapshotCollectionSkipReason }\n\t| { readonly status: \"collected\"; readonly deleted: readonly string[]; readonly pendingChunkMove?: PendingChunkMove }\n\t/**\n\t * The storage closed, or its last store was released, before the collection finished; it stopped at its next batch\n\t * and what it deleted stays deleted.\n\t */\n\t| { readonly status: \"interrupted\"; readonly deleted: readonly string[] }\n\t| { readonly status: \"failed\"; readonly error: WorkspaceCollectionError };\n\n/** The prefix of every blob table identity in one database, for telling the tables of one database apart. */\nconst databaseIdentity = (descriptor: StorageDescriptor) => `${descriptor.adapter}\\0${descriptor.location}\\0`;\n\n/**\n * How an automatic collection waits, so that it never keeps its process alive: between batches, and before it tries\n * a write lock another connection holds again, on timers the process does not wait for. A process that has nothing\n * else to do exits at the next wait, which leaves only garbage, like a crash, and the next trigger after the claim\n * lease carries on. {@link keepProcessAlive} makes the process wait for the collection like any other work. A wait\n * ends at once when `signal` aborts, so an aborted collection stops without sleeping out its wait.\n */\nexport class BackgroundCollectionPace {\n\treadonly signal?: AbortSignal;\n\tprivate keepAlive = false;\n\tprivate pending?: LongTimeout;\n\n\tconstructor(signal?: AbortSignal) {\n\t\tthis.signal = signal;\n\t}\n\n\t/**\n\t * Resolves after `milliseconds`, or as soon as the signal aborts, and unless the process exits first because it\n\t * has nothing else to do.\n\t */\n\twait(milliseconds: number): Promise<void> {\n\t\treturn new Promise((resolve) => {\n\t\t\tconst signal = this.signal;\n\t\t\tif (signal?.aborted) return resolve();\n\t\t\tconst done = () => {\n\t\t\t\ttimer.clear();\n\t\t\t\tsignal?.removeEventListener(\"abort\", done);\n\t\t\t\tthis.pending = undefined;\n\t\t\t\tresolve();\n\t\t\t};\n\t\t\tconst timer = setLongTimeout(done, milliseconds, { ref: this.keepAlive });\n\t\t\tsignal?.addEventListener(\"abort\", done, { once: true });\n\t\t\tthis.pending = timer;\n\t\t});\n\t}\n\n\t/** Makes the process wait for the collection: the wait in progress and every later one. */\n\tkeepProcessAlive(): void {\n\t\tthis.keepAlive = true;\n\t\tthis.pending?.ref();\n\t}\n}\n\n/** An automatic collection this process is running, and how it waits. */\nexport interface RunningSnapshotCollection {\n\treadonly outcome: Promise<SnapshotCollectionOutcome>;\n\treadonly pace: BackgroundCollectionPace;\n\t/** Stops the collection at its next batch boundary, with `reason` as the abort reason. */\n\tabort(reason: Error): void;\n}\n\nconst collectionsRunning = new Map<string, RunningSnapshotCollection>();\n\n/** Records the automatic collection this process runs on `store`'s blob table, until it settles. */\nexport function trackSnapshotCollection(store: SqlSnapshotBlobStore, running: RunningSnapshotCollection): void {\n\tcollectionsRunning.set(store.identity, running);\n\tvoid running.outcome.then(() => collectionsRunning.delete(store.identity));\n}\n\n/** The automatic collection of `store`'s blob table that this process is running, if any. */\nexport function runningSnapshotCollectionOf(store: SqlSnapshotBlobStore): RunningSnapshotCollection | undefined {\n\treturn collectionsRunning.get(store.identity);\n}\n\n/**\n * Stops every automatic collection this process is running on a blob table of the database `descriptor` names, each at\n * its next batch boundary, with `reason` as the abort reason; a collection that stops this way ends `interrupted`.\n */\nexport function abortSnapshotCollectionsOn(descriptor: StorageDescriptor, reason: Error): void {\n\tconst prefix = databaseIdentity(descriptor);\n\tfor (const [identity, running] of collectionsRunning) if (identity.startsWith(prefix)) running.abort(reason);\n}\n\n/** Every automatic collection this process is running on a blob table of the database `descriptor` names. */\nexport function runningSnapshotCollectionsOn(descriptor: StorageDescriptor): Promise<SnapshotCollectionOutcome>[] {\n\tconst prefix = databaseIdentity(descriptor);\n\treturn [...collectionsRunning]\n\t\t.filter(([identity]) => identity.startsWith(prefix))\n\t\t.map(([, running]) => running.outcome);\n}\n\n/**\n * Resolves after the event loop has run its timers and I/O callbacks. The node:sqlite adapter commits an uncontended\n * transaction without ever returning to the loop, so a collection yields here between batches instead of holding\n * the host process for all of them.\n */\nconst yieldToEventLoop = () => new Promise<void>((resolve) => setImmediate(resolve));\n\n/**\n * How long the snapshot a resume restored only partly stays its checkout's restore target and is kept by collection\n * (#4922). Resume and capture count it from the partial restore; collection, on the database clock, from the first\n * session entry that names the snapshot, which never comes earlier.\n */\nexport const DEGRADED_RESTORE_RETENTION_DAYS = 30;\nconst DEGRADED_PIN_SECONDS = DEGRADED_RESTORE_RETENTION_DAYS * 24 * 60 * 60;\n\n/** Aged blobs one page of a collection examines, read from the age index in one statement. */\nexport const SNAPSHOT_COLLECTION_BATCH = 256;\n\n/**\n * The most blobs one delete batch of a collection deletes, in one write transaction (#5530). Deleting a blob also\n * deletes its chunks. On a chunk table an earlier release created `WITHOUT ROWID`, until collection moves it (#5541),\n * finding them reads whole chunks of the rows each seek compares: about 3.5 ms per blob on a large store with its\n * pages cached, so a batch of this many takes about 30 ms.\n * The transaction also checks again, in one statement, the sessions that reference the batch's blobs: at most\n * {@link SNAPSHOT_COLLECTION_SESSION_REFS} snapshot entries of them.\n */\nexport const SNAPSHOT_COLLECTION_DELETE_BATCH = 8;\n\n/**\n * The most snapshot entries of sessions one collection statement walks to find the snapshots those sessions retain\n * (#5530). Each session's retained snapshots are found by walking the snapshot entries on its open branches, about\n * 2 µs per entry with its pages cached, so a statement over this many takes a few milliseconds, and the event loop\n * gets a turn between statements. A session with more entries than this is walked in a statement of its own, and so\n * is a blob whose sessions hold more together when its delete batch checks them again.\n */\nexport const SNAPSHOT_COLLECTION_SESSION_REFS = 2_048;\n\n/**\n * The most bytes of legacy blobs one write transaction of a collection stamps or moves. A blob stored before blob ages\n * has an unknown age, which collection stamps; changing one column rewrites the whole row on SQLite, its\n * blob included, and holds the writer for as long as that takes, so a stamping transaction stops at this many bytes of\n * blobs. An in-row blob larger than {@link SNAPSHOT_BLOB_CHUNK_BYTES} is moved to chunks regardless of age,\n * at most this many bytes per transaction. Publishing frees its old value while holding the writer, with time\n * proportional to that value's size.\n */\nexport const SNAPSHOT_LEGACY_STAMP_BYTES = 16 * SNAPSHOT_BLOB_CHUNK_BYTES;\n\n/**\n * The most chunk rows one write transaction copies or frees while collection moves a chunk table an earlier release\n * created `WITHOUT ROWID` to the row layout (#5541). Each costs a read of its 1 MiB, cold on a first move, under the\n * write lock.\n */\nexport const SNAPSHOT_CHUNK_MOVE_ROWS = 4;\n\n/**\n * The free space a chunk table's move to the row layout leaves on the file system of a SQLite database file\n * beyond its copy, at least (#5694): the move starts only when the disk has room for the copy, its write-ahead log and\n * this much more, so other writes keep room on the disk.\n */\nexport const SNAPSHOT_CHUNK_MOVE_HEADROOM_BYTES = 64 * 1024 * 1024;\n\n// Four 1 MiB chunks per offline transaction, plus space for b-tree pages and WAL framing.\nconst OFFLINE_CHUNK_LOG_ALLOWANCE = 16 * SNAPSHOT_BLOB_CHUNK_BYTES;\n\n/**\n * Whether `error`, or a failure it wraps, says the database's disk is full or failed to read or write: SQLite's\n * `SQLITE_FULL` or `SQLITE_IOERR` and its extended codes (node:sqlite's `errcode`, libSQL's code or `rawCode`), as a\n * libSQL server answers when its disk fills, or PostgreSQL's `disk_full` (53100) or `io_error` (58030).\n */\nfunction isStorageSpaceFailure(error: unknown): boolean {\n\tconst seen = new Set<object>();\n\tfor (let cause = error; typeof cause === \"object\" && cause !== null && !seen.has(cause); ) {\n\t\tseen.add(cause);\n\t\tconst { code, errcode, rawCode } = cause as { code?: unknown; errcode?: unknown; rawCode?: unknown };\n\t\tif (typeof code === \"string\" && /^(?:SQLITE_FULL|SQLITE_IOERR(?:_\\w+)?|53100|58030)$/.test(code)) return true;\n\t\tconst number = errcode ?? rawCode;\n\t\tif (typeof number === \"number\" && ((number & 0xff) === 13 || (number & 0xff) === 10)) return true;\n\t\tcause = (cause as { cause?: unknown }).cause;\n\t}\n\treturn false;\n}\n\n/** Rows of one referencing table that one backfill transaction indexes. */\nexport const SNAPSHOT_INDEX_BACKFILL_BATCH = 500;\n\n/**\n * How long an unfinished collection's claim holds the database after its last batch, in seconds. Every batch renews\n * it, so a collection that stopped (killed, or its storage closed) is taken over after this lease, not after the\n * collection interval.\n */\nexport const SNAPSHOT_COLLECTION_LEASE_SECONDS = 120;\n\n/**\n * How long a background collection first waits before it tries a write lock another connection holds again, in\n * milliseconds. Each refusal doubles the wait, up to {@link SNAPSHOT_COLLECTION_LOCK_RETRY_MAX_MS}; once the waits add\n * up to the claim lease, the collection gives up with the lock's error, since another process may take over its claim.\n */\nexport const SNAPSHOT_COLLECTION_LOCK_RETRY_FIRST_MS = 10;\nexport const SNAPSHOT_COLLECTION_LOCK_RETRY_MAX_MS = 1_000;\n\nexport interface SnapshotIndexOptions {\n\treadonly signal?: AbortSignal;\n\t/** Renews this holder's claim in every batch, so a long collection keeps it. */\n\treadonly holder?: string;\n\t/**\n\t * Runs in the background: waits between batches, and for a write lock another connection holds, on `pace`, so the\n\t * process can exit meanwhile. Without it the collection waits like any other work of its caller.\n\t */\n\treadonly pace?: BackgroundCollectionPace;\n}\n\nexport interface SnapshotSweepOptions extends SnapshotIndexOptions {\n\treadonly graceSeconds: number;\n\t/** Called after each batch commits with the hashes it deleted. */\n\treadonly onBatch?: (deleted: readonly string[]) => void;\n\t/** The existing space check deferred layout maintenance; garbage collection itself succeeded. */\n\treadonly onPendingChunkMove?: (pending: PendingChunkMove) => void;\n}\n\ntype PageRow = SqliteRow & { created_at: number; hash: string };\n\n/**\n * How many whole seconds a blob's `created_at` must lie behind the database clock for the blob to be at least\n * `graceSeconds` old. Both count whole seconds, so a blob stored late in a second carries that second's start and can\n * be almost a second younger than the difference says; one second more keeps it for the whole window. 0 keeps none.\n */\nfunction collectableAge(graceSeconds: number): number {\n\treturn graceSeconds === 0 ? 0 : graceSeconds + 1;\n}\n\n/**\n * How long the light statements of a sweep, such as reading what walking a session costs, may hold the event loop\n * together before the sweep gives it a turn, in milliseconds. Counting a session's snapshot entries reads them: a few\n * milliseconds for a large session whose pages are not cached, so each session is counted in a statement of its own.\n */\nconst SWEEP_TURN_MS = 8;\n\n/**\n * How long a sweep goes without a write before it renews its claim in a transaction of its own: a quarter of the claim\n * lease, so pages with nothing to delete, which write nothing else, never let the lease run out.\n */\nconst SWEEP_CLAIM_RENEWAL_MS = (SNAPSHOT_COLLECTION_LEASE_SECONDS * 1_000) / 4;\n\n/** A blob a sweep may delete, with the sessions whose records reference it. */\ninterface SweepCandidate {\n\treadonly hash: string;\n\treadonly sessions: readonly string[];\n}\n\n/** Blobs a sweep deletes in one write transaction, with the sessions whose records referenced them when it walked them. */\ninterface SweepDeleteBatch {\n\treadonly hashes: readonly string[];\n\treadonly sessions: readonly string[];\n}\n\n/**\n * Groups `costs`' sessions, in order, into groups whose costs add up to at most {@link SNAPSHOT_COLLECTION_SESSION_REFS};\n * a session that costs more is a group of its own.\n */\nfunction sessionGroups(costs: ReadonlyMap<string, number>): string[][] {\n\tconst groups: string[][] = [];\n\tlet group: string[] = [];\n\tlet total = 0;\n\tfor (const [session, cost] of costs) {\n\t\tif (group.length > 0 && total + cost > SNAPSHOT_COLLECTION_SESSION_REFS) {\n\t\t\tgroups.push(group);\n\t\t\tgroup = [];\n\t\t\ttotal = 0;\n\t\t}\n\t\tgroup.push(session);\n\t\ttotal += cost;\n\t}\n\tif (group.length > 0) groups.push(group);\n\treturn groups;\n}\n\n/**\n * The turns of the event loop between the steps of a sweep that hold it, such as a statement that walks sessions, a\n * delete batch or a page: {@link next} gives the loop a turn when a step has held it since the last turn, then checks\n * the sweep's abort signal.\n */\nclass SweepTurns {\n\tprivate readonly signal?: AbortSignal;\n\tprivate readonly yieldTurn: () => Promise<void>;\n\tprivate holding = false;\n\tprivate turnedAt = performance.now();\n\n\tconstructor(options: { readonly signal?: AbortSignal }, yieldTurn: () => Promise<void>) {\n\t\tthis.signal = options.signal;\n\t\tthis.yieldTurn = yieldTurn;\n\t}\n\n\tasync next(): Promise<void> {\n\t\tif (this.holding) {\n\t\t\tthis.holding = false;\n\t\t\tawait this.yieldTurn();\n\t\t\tthis.turnedAt = performance.now();\n\t\t}\n\t\tthis.signal?.throwIfAborted();\n\t}\n\n\t/** Records that a step held the event loop since the last turn. */\n\theld(): void {\n\t\tthis.holding = true;\n\t}\n\n\t/** Gives the event loop a turn once the light steps since the last one have held it for {@link SWEEP_TURN_MS}. */\n\tasync light(): Promise<void> {\n\t\tif (performance.now() - this.turnedAt >= SWEEP_TURN_MS) this.holding = true;\n\t\tawait this.next();\n\t}\n}\n\n/**\n * What one sweep has read about the sessions that reference its candidates (#5530): how many snapshot entries walking\n * each costs, and the blobs the snapshots of those it walked retain. Only nominates candidates: each delete batch reads\n * its sessions again in its transaction.\n */\nclass SweepSessions {\n\tprivate readonly costs = new Map<string, number>();\n\tprivate readonly walked = new Set<string>();\n\tprivate readonly retained = new Set<string>();\n\n\t/** Which of `sessions` this sweep has not walked yet. */\n\tunwalked(sessions: Iterable<string>): string[] {\n\t\treturn [...new Set(sessions)].filter((session) => !this.walked.has(session));\n\t}\n\n\tcost(costs: ReadonlyMap<string, number>): void {\n\t\tfor (const [session, cost] of costs) this.costs.set(session, cost);\n\t}\n\n\t/** Records that `sessions` were walked and that their retained snapshots reference `hashes`. */\n\tretain(sessions: readonly string[], hashes: readonly string[]): void {\n\t\tfor (const session of sessions) this.walked.add(session);\n\t\tfor (const hash of hashes) this.retained.add(hash);\n\t}\n\n\tretains(hash: string): boolean {\n\t\treturn this.retained.has(hash);\n\t}\n\n\t/**\n\t * `candidates` in delete batches, in order, of at most {@link SNAPSHOT_COLLECTION_DELETE_BATCH} blobs whose sessions\n\t * cost at most {@link SNAPSHOT_COLLECTION_SESSION_REFS} to walk together; a candidate whose own sessions cost more\n\t * is a batch of its own.\n\t */\n\tbatches(candidates: readonly SweepCandidate[]): SweepDeleteBatch[] {\n\t\tconst batches: SweepDeleteBatch[] = [];\n\t\tlet batch: string[] = [];\n\t\tlet sessions = new Set<string>();\n\t\tlet total = 0;\n\t\tconst added = (candidate: SweepCandidate) =>\n\t\t\tcandidate.sessions.reduce(\n\t\t\t\t(sum, session) => (sessions.has(session) ? sum : sum + (this.costs.get(session) ?? 1)),\n\t\t\t\t0,\n\t\t\t);\n\t\tfor (const candidate of candidates) {\n\t\t\tif (\n\t\t\t\tbatch.length === SNAPSHOT_COLLECTION_DELETE_BATCH ||\n\t\t\t\t(batch.length > 0 && total + added(candidate) > SNAPSHOT_COLLECTION_SESSION_REFS)\n\t\t\t) {\n\t\t\t\tbatches.push({ hashes: batch, sessions: [...sessions] });\n\t\t\t\tbatch = [];\n\t\t\t\tsessions = new Set();\n\t\t\t\ttotal = 0;\n\t\t\t}\n\t\t\ttotal += added(candidate);\n\t\t\tbatch.push(candidate.hash);\n\t\t\tfor (const session of candidate.sessions) sessions.add(session);\n\t\t}\n\t\tif (batch.length > 0) batches.push({ hashes: batch, sessions: [...sessions] });\n\t\treturn batches;\n\t}\n}\n\n/**\n * A table whose rows reference snapshot blobs, with the triggers that index its future rows and the statements that\n * index the rows it already holds. Both are built from the same statements, so they cannot disagree.\n */\ninterface IndexSource {\n\treadonly name: string;\n\treadonly table: string;\n\t/** The triggers that index the table's future rows, in the order they are created. */\n\treadonly triggers: readonly StorageTrigger[];\n\t/** Each statement indexes the rows with `rowid > ? AND rowid <= ?`, bound in that order. */\n\treadonly backfill: readonly string[];\n\t/**\n\t * When set, rows are indexed one at a time in rowid order, each statement bound to the row's rowid, instead of by\n\t * `backfill`: a row's index depends on its parent's, which a statement over many rows cannot see.\n\t */\n\treadonly rowwise?: readonly string[];\n\t/** The fork segments table `rowwise` reads, where it links the entries of sessions with segments (#6560). */\n\treadonly segments?: string;\n\t/**\n\t * Of `rowwise`, what links a row linked already again (#6560): the statement that writes its link, the one that\n\t * writes it over for a session with fork segments, and the one that sets a snapshot entry's previous snapshot, its\n\t * parent's anchor. The children count, the snapshot's records and when a pin began stay.\n\t */\n\treadonly relink?: {\n\t\treadonly link: string;\n\t\treadonly fork?: string;\n\t\treadonly refs: string;\n\t\t/** `refs` for the rows session `?` stores from seq `?` on, in one statement. */\n\t\treadonly refsFrom: string;\n\t};\n\t/** The rows session `?` stores from seq `?` on, as `rowwise` yields one (#6560). */\n\treadonly entriesFrom?: string;\n\t/** Clears the source's index rows when its triggers are installed again, so no stale row outlives its entry. */\n\treadonly reset?: readonly string[];\n\t/**\n\t * The row that says the source's triggers index what this build's do, and that no build before 0.9.88 writes.\n\t * Without it, triggers of the source's names are an older build's, which index less, and this build installs its own\n\t * and indexes the table again (#5065). Builds 0.9.88 and 0.9.89 write it as `(0, 0)` when they install the triggers\n\t * and read only that it exists. This build writes it as {@link PUBLISHED_VERSION}, and on SQLite, which builds before\n\t * 0.9.88 also open, only once its own backfill of the source is done, so that builds 0.9.88 and 0.9.89 never trust\n\t * rows a build before 0.9.88 indexed during this build's backfill: they install their own triggers and index the\n\t * table again instead (#5558).\n\t */\n\treadonly version?: string;\n\t/**\n\t * The progress row of this build's own backfill of the source, which no older build writes (#5558). An older build\n\t * that takes this build's triggers for its own indexes the rows it backfills with statements that index less, and\n\t * advances only the source's row: the source is backfilled only once this row's progress reaches its watermark too,\n\t * and this build indexes those rows again. On SQLite, a source a build of 0.9.88 or 0.9.89 installed is trusted once\n\t * its backfill is done, as those builds index what this build does; one whose backfill is not done is indexed again\n\t * by this build from its first row, as a build before 0.9.88 may have indexed some of it.\n\t */\n\treadonly own?: string;\n\t/**\n\t * Text that the SQL of every trigger this build installs for the source holds, and no older build's does (#5558).\n\t * Builds 0.9.88 and 0.9.89 install triggers without it, and their pending trigger does not move {@link own} back. On\n\t * SQLite, which builds before 0.9.88 also open, an index this build installed is this build's only while every\n\t * trigger it has holds the text: such a build installs a lost trigger again, keeps the triggers it finds, some of\n\t * them the same SQL in every build, empties the index and indexes the table its way. Without the text everywhere,\n\t * this build indexes the table again. A takeover installs this build's triggers before its backfill relies on its\n\t * own progress.\n\t */\n\treadonly marker?: string;\n\t/**\n\t * Text that only this build's SQL of the trigger `trigger` holds. On SQLite, which older builds also open, a trigger\n\t * of that name without it is an older build's, installed after this build's went missing, so the source is indexed\n\t * again as an older build's (#5558).\n\t */\n\treadonly signature?: { readonly trigger: string; readonly text: string };\n}\n\ninterface SourceState {\n\treadonly source: IndexSource;\n\treadonly installed: boolean;\n\treadonly backfilled: boolean;\n\treadonly deferred: boolean;\n\t/** Installed by another build whose index this build does not trust: an upgrade, or an older build's again. */\n\treadonly foreign: boolean;\n\t/**\n\t * On SQLite, installed with {@link IndexSource.version} but not backfilled, as by a build of 0.9.88 or 0.9.89 whose\n\t * backfill is not done. This build's backfill removes the row, installs its own triggers and indexes the source again\n\t * from its first row (#5558).\n\t */\n\treadonly takeover: boolean;\n\treadonly retired?: readonly string[];\n}\n\n/**\n * The watermark and progress of a source's {@link IndexSource.version} row as this build writes it: on SQLite once its\n * own backfill of the source is done, on Postgres when it installs the source's triggers (#5558). Builds 0.9.88 and\n * 0.9.89 write the row as `(0, 0)`.\n */\nconst PUBLISHED_VERSION = 1;\n\n/** Receipts for physical session-index generations. Released builds read only their own source names. */\nexport const SESSION_INDEX_RETIRED_PREFIX = \"session-entries@retired:\";\ntype SessionIndexReset = (\n\ttx: SqliteExecutor,\n\ttables: SnapshotIndexTables,\n\ttriggers: readonly string[],\n) => Promise<boolean>;\n\n/**\n * A row that a development build marked a source with while it removed the source's index in batches. An index an\n * older build installed while it was there is never trusted as that build's finished index (#5558).\n */\nconst rebuildRow = (source: IndexSource) => `${source.name}@rebuild`;\n\nconst CHECKPOINT_EVENT = \"CheckpointRecorded\";\nconst STATUS_EVENTS = \"'RunStarted', 'StatusChanged'\";\nconst RELEASED_STATUSES = \"'completed', 'cancelled'\";\n/** The `seq` of a run state taken from the run's header status, which any start or status event replaces. */\nconst HEADER_SEQ = -1;\n\ntype Column = (name: string) => string;\nconst newRow: Column = (name) => `NEW.${name}`;\nconst oldRow: Column = (name) => `OLD.${name}`;\nconst storedRow: Column = (name) => name;\n\n/**\n * `test` on a payload that may not be JSON: SQLite does not promise to stop at the first false term of an AND, and\n * Postgres fails a cast of text that is not JSON.\n */\nconst whenValidJson = (d: StorageDialect, json: string, test: string) =>\n\t`CASE WHEN ${d.jsonValid(json)} THEN (${test}) ELSE ${d.literals.false} END`;\n\nconst triggerRows = (columns: readonly string[]) =>\n\t`(SELECT ${columns.map((name) => `NEW.${name} AS ${name}`).join(\", \")})`;\nconst storedRows = (d: StorageDialect, table: string, columns: readonly string[], condition: string) =>\n\t`(SELECT ${columns.join(\", \")} FROM ${table} WHERE ${d.rowOrder()} > ? AND ${d.rowOrder()} <= ? AND ${condition})`;\n\nfunction checkpointCondition(d: StorageDialect, column: Column): string {\n\tconst payload = column(\"payload\");\n\treturn `${column(\"type\")} = '${CHECKPOINT_EVENT}' AND ${d.contains(payload, `'\"worktreeSnapshots\"'`)} AND ${whenValidJson(\n\t\td,\n\t\tpayload,\n\t\t`${d.jsonText(payload, \"kind\")} IN ('tool', 'stage')`,\n\t)}`;\n}\n\nfunction statusCondition(d: StorageDialect, column: Column): string {\n\tconst payload = column(\"payload\");\n\treturn `${column(\"type\")} IN (${STATUS_EVENTS}) AND ${whenValidJson(\n\t\td,\n\t\tpayload,\n\t\t`${d.jsonHasType(\"text\", payload, \"workflowId\")} AND ${d.jsonHasType(\"text\", payload, \"status\")} AND ${d.jsonType(payload, \"completedCheckpoints\")} IN ('integer', 'real') AND ${d.jsonType(payload, \"pendingPrompts\")} IN ('integer', 'real')`,\n\t)}`;\n}\n\n/**\n * The SQL form of `isDurableWorkflowResumable` for the status payload `payload`, given that the run has a snapshot\n * reference and so at least one checkpoint: a root run keeps its snapshots while it is failed or blocked, or running or\n * paused, unless it was marked not resumable.\n */\nfunction retainedByStatus(d: StorageDialect, payload: string): string {\n\tconst root = d.jsonType(payload, \"rootWorkflowId\");\n\treturn `CASE\n\t\tWHEN ${root} IS NOT NULL AND (${root} <> 'text' OR ${d.jsonText(payload, \"rootWorkflowId\")} <> ${d.jsonText(payload, \"workflowId\")}) THEN 0\n\t\tWHEN ${d.jsonText(payload, \"status\")} IN ('failed', 'blocked', 'running', 'paused') THEN ${d.flag(d.isDistinct(d.jsonType(payload, \"resumable\"), \"'false'\"))}\n\t\tELSE 0\n\tEND`;\n}\n\n/** A trigger of the reference index: after `event` on `table`, when `when` holds for the row, it runs `statements`. */\nfunction createTrigger(\n\tname: string,\n\tevent: string,\n\ttable: string,\n\tstatements: readonly string[],\n\twhen?: string,\n): StorageTrigger {\n\tconst trigger = { name, table, timing: \"AFTER\", event, statements } as const;\n\treturn when === undefined ? trigger : { ...trigger, when };\n}\n\n/** A table whose rows each carry the snapshot that dispatched work restores its tree from (#4503). */\ninterface CarriedSnapshots {\n\treadonly name: string;\n\treadonly table: string;\n\t/** The prefix of each row's owner in {@link SnapshotIndexTables.carriedRefs}, before the row's `key`. */\n\treadonly owner: \"work\" | \"root\";\n\treadonly key: string;\n\t/** The JSON column that holds the snapshot, at the object keys `path` (none: the whole document). */\n\treadonly json: string;\n\treadonly path: readonly string[];\n\t/** Text `json` holds whenever its row carries a snapshot, so a row that carries none costs the index nothing. */\n\treadonly marker?: string;\n}\n\n/**\n * Indexes the blobs of the snapshot each row of `carried.table` carries as the row's references, from its insert until\n * its delete; an update of the snapshot replaces them. A row whose JSON the database cannot parse references nothing,\n * so a write never fails on the index. No statement inserts a reference that exists already: an upsert's update runs\n * its triggers under its own conflict policy, which overrides their `OR IGNORE`.\n */\nfunction carriedSource(d: StorageDialect, t: SnapshotIndexTables, carried: CarriedSnapshots): IndexSource {\n\tconst { table, key, json, path, marker } = carried;\n\tconst owner = (row: Column) => `'${carried.owner}:' || ${row(key)}`;\n\tconst carries = (row: Column) => (marker === undefined ? undefined : d.contains(row(json), `'${marker}'`));\n\tconst rowOf = (row: Column) =>\n\t\t`${owner(row)} AS owner, CASE WHEN ${d.jsonValid(row(json))} THEN ${row(json)} ELSE '{}' END AS snapshot`;\n\tconst snapshot = { column: \"r.snapshot\" };\n\tconst index = (rows: string) =>\n\t\t[\n\t\t\t{\n\t\t\t\tfrom: `, ${d.jsonEach(snapshot, \"link\", ...path, \"chain\")}`,\n\t\t\t\tlink: { ...snapshot, element: \"link\" },\n\t\t\t\tkeys: [\"patch\"],\n\t\t\t},\n\t\t\t{ from: \"\", link: snapshot, keys: [...path, \"bundle\", \"blob\"] },\n\t\t].map(({ from, link, keys }) => {\n\t\t\tconst hash = d.jsonAt(link, ...keys);\n\t\t\treturn d.insertOrIgnore(\n\t\t\t\tt.carriedRefs,\n\t\t\t\t[\"owner\", \"hash\"],\n\t\t\t\t`SELECT DISTINCT r.owner, ${hash} FROM ${rows} AS r${from} WHERE ${d.jsonAtIsText(link, ...keys)} AND NOT EXISTS (SELECT 1 FROM ${t.carriedRefs} AS held WHERE held.owner = r.owner AND held.hash = ${hash})`,\n\t\t\t);\n\t\t});\n\tconst inserted = `(SELECT ${rowOf(newRow)})`;\n\tconst release = `DELETE FROM ${t.carriedRefs} WHERE owner = ${owner(oldRow)}`;\n\tconst names = {\n\t\tinsert: `${table}_snapshot_carried_insert`,\n\t\tupdate: `${table}_snapshot_carried_update`,\n\t\tdelete: `${table}_snapshot_carried_delete`,\n\t};\n\treturn {\n\t\tname: carried.name,\n\t\ttable,\n\t\ttriggers: [\n\t\t\tcreateTrigger(names.insert, \"INSERT\", table, index(inserted), carries(newRow)),\n\t\t\tcreateTrigger(\n\t\t\t\tnames.update,\n\t\t\t\t`UPDATE OF ${json}`,\n\t\t\t\ttable,\n\t\t\t\t[release, ...index(inserted)],\n\t\t\t\tmarker === undefined ? undefined : `${carries(oldRow)} OR ${carries(newRow)}`,\n\t\t\t),\n\t\t\tcreateTrigger(names.delete, \"DELETE\", table, [release], carries(oldRow)),\n\t\t],\n\t\tbackfill: index(storedRows(d, table, [rowOf(storedRow)], carries(storedRow) ?? d.literals.true)),\n\t\treset: [`DELETE FROM ${t.carriedRefs} WHERE owner LIKE '${carried.owner}:%'`],\n\t};\n}\n\n/** The progress row of this build's own backfill of the session entries (#5558). */\nconst ENTRIES_OWN_PROGRESS = \"session-entries@own-progress\";\n\n/** `trigger`, its SQL holding `marker` in a comment that changes nothing it does (#5558). */\nfunction withMarker(trigger: StorageTrigger, marker: string): StorageTrigger {\n\tconst [first, ...rest] = trigger.statements;\n\treturn { ...trigger, statements: [`/* ${marker} */ ${first}`, ...rest] };\n}\n\n/**\n * The tables whose rows reference snapshot blobs, and how each is indexed. `forkSegments` names the sessions' fork\n * segments table when it exists (#6560): the backfill of the session entries then also links an entry whose parent\n * the session inherits, as the session store does when it writes one (`forkLinkWrites`).\n */\nfunction indexSources(\n\tprefix: string,\n\tt: SnapshotIndexTables,\n\td: StorageDialect,\n\tforkSegments?: string,\n): readonly IndexSource[] {\n\tconst { events, runs } = renderStorageIdentifiers(\"journal\", { events: \"events\", runs: \"runs\" }, prefix);\n\tconst { entries } = renderStorageIdentifiers(\"sessions\", { entries: \"entries\" }, prefix);\n\n\tconst payload = { column: \"r.payload\" };\n\tconst snapshot = { ...payload, element: \"snapshot\" };\n\tconst link = { ...payload, element: \"link\" };\n\tconst snapshots = d.jsonEach(payload, \"snapshot\", \"worktreeSnapshots\");\n\tconst runRefs = (rows: string) =>\n\t\t[\n\t\t\t{ from: `${snapshots}, ${d.jsonEach(snapshot, \"link\", \"chain\")}`, source: link, keys: [\"patch\"] },\n\t\t\t{ from: snapshots, source: snapshot, keys: [\"bundle\", \"blob\"] },\n\t\t].map(({ from, source, keys }) =>\n\t\t\td.insertOrIgnore(\n\t\t\t\tt.runRefs,\n\t\t\t\t[\"run_id\", \"hash\"],\n\t\t\t\t`SELECT r.run_id, ${d.jsonAt(source, ...keys)} FROM ${rows} AS r, ${from} WHERE ${d.jsonAtIsText(source, ...keys)}`,\n\t\t\t),\n\t\t);\n\tconst released = (status: string) => d.flag(`${status} NOT IN (${RELEASED_STATUSES})`);\n\tconst runState = (rows: string) =>\n\t\t`INSERT INTO ${t.runState} (run_id, retained, seq) SELECT r.run_id, ${retainedByStatus(d, \"r.payload\")}, r.seq FROM ${rows} AS r WHERE true ON CONFLICT (run_id) DO UPDATE SET retained = excluded.retained, seq = excluded.seq WHERE excluded.seq >= ${t.runState}.seq`;\n\tconst runHeader = (rows: string) =>\n\t\t`INSERT INTO ${t.runState} (run_id, retained, seq) SELECT r.run_id, ${released(\"r.status\")}, ${HEADER_SEQ} FROM ${rows} AS r WHERE true ON CONFLICT (run_id) DO NOTHING`;\n\tconst entryRow = (name: string) => `r.${name}`;\n\tconst entry = { column: \"r.entry_json\" };\n\tconst parentType = \"r.parent_type\";\n\tconst parentId = \"r.parent_id\";\n\tconst isSnapshot = snapshotEntryCondition(d, entryRow);\n\t// The parent is the first link before the entry with the parent's id, as `forkSessionLink` finds it (#6560).\n\tconst parentOf = (rows: string) =>\n\t\t`${rows} AS r LEFT JOIN ${t.sessionLinks} AS parent ON parent.session_id = r.session_id AND parent.seq = ${ownParentSeq(t.sessionLinks)}`;\n\t/**\n\t * Indexes one session entry's link in the session tree. `rows` yields that one entry as `r`. Only the links before\n\t * it count: its parent, an earlier entry of the same id, and the entries whose child it is, whose children it adds\n\t * to, once. A row linked again gets the same anchor and broken mark, so a session's rows linked in seq order end\n\t * the same whether a save or the index's rebuild linked them, and whatever links after them were there (#6560).\n\t */\n\tconst sessionLink = (rows: string) => [\n\t\t`UPDATE ${t.sessionLinks} SET children = children + 1 FROM ${rows} AS r WHERE ${t.sessionLinks}.session_id = r.session_id AND ${t.sessionLinks}.entry_id = ${parentId} AND ${parentType} = 'text' AND +${t.sessionLinks}.seq < r.seq AND NOT EXISTS (SELECT 1 FROM ${t.sessionLinks} AS own WHERE own.session_id = r.session_id AND own.seq = r.seq)`,\n\t\t`INSERT INTO ${t.sessionLinks} (session_id, seq, entry_id, parent_id, anchor_seq, children, broken)\n\t\t\tSELECT r.session_id, r.seq, r.entry_id, CASE WHEN ${parentType} = 'text' THEN ${parentId} END, CASE WHEN ${isSnapshot} THEN r.seq ELSE parent.anchor_seq END, 0, CASE WHEN ${ownDuplicate(t.sessionLinks)} THEN 1 WHEN ${parentType} IS NULL OR ${parentType} = 'null' THEN 0 WHEN parent.entry_id IS NOT NULL THEN parent.broken ELSE 1 END FROM ${parentOf(rows)} WHERE true\n\t\t\tON CONFLICT (session_id, seq) DO UPDATE SET anchor_seq = excluded.anchor_seq, broken = excluded.broken`,\n\t];\n\t/** Indexes a snapshot entry's reference and the blobs of its record; any other entry adds nothing. */\n\tconst sessionRecord = (rows: string) => {\n\t\tconst record = (source: StorageJsonSource, keys: readonly string[], from = \"\") =>\n\t\t\td.insertOrIgnore(\n\t\t\t\tt.sessionRecords,\n\t\t\t\t[\"session_id\", \"seq\", \"snapshot_id\", \"hash\"],\n\t\t\t\t`SELECT r.session_id, r.seq, ${d.jsonText(entry.column, \"snapshotId\")}, ${d.jsonAt(source, ...keys)} FROM ${rows} AS r${from} WHERE ${d.jsonAtIsText(source, ...keys)} AND ${isSnapshot}`,\n\t\t\t);\n\t\tconst restored = `${d.jsonHasType(\"text\", entry.column, \"restore\", \"from\")} AND ${d.jsonHasType(\"text\", entry.column, \"restore\", \"to\")}`;\n\t\tconst pinned = d.jsonHasType(\"text\", entry.column, \"degradedFrom\");\n\t\tconst degradedFrom = d.jsonText(entry.column, \"degradedFrom\");\n\t\t// A pin began with the first entry naming its snapshot; entries that go on naming it keep that start (#4922).\n\t\tconst degradedSince = `COALESCE((SELECT earlier.degraded_since FROM ${t.sessionRefs} AS earlier WHERE earlier.session_id = r.session_id AND earlier.seq = parent.anchor_seq AND earlier.degraded_from = ${degradedFrom}), ${d.nowSeconds})`;\n\t\treturn [\n\t\t\td.insertOrReplace(\n\t\t\t\tt.sessionRefs,\n\t\t\t\t[\n\t\t\t\t\t\"session_id\",\n\t\t\t\t\t\"seq\",\n\t\t\t\t\t\"root\",\n\t\t\t\t\t\"snapshot_id\",\n\t\t\t\t\t\"prev_seq\",\n\t\t\t\t\t\"restore_from\",\n\t\t\t\t\t\"restore_to\",\n\t\t\t\t\t\"degraded_from\",\n\t\t\t\t\t\"degraded_since\",\n\t\t\t\t],\n\t\t\t\t[\"session_id\", \"seq\"],\n\t\t\t\t`SELECT r.session_id, r.seq, ${d.jsonText(entry.column, \"root\")}, ${d.jsonText(entry.column, \"snapshotId\")}, parent.anchor_seq, CASE WHEN ${restored} THEN ${d.jsonText(entry.column, \"restore\", \"from\")} END, CASE WHEN ${restored} THEN ${d.jsonText(entry.column, \"restore\", \"to\")} END, CASE WHEN ${pinned} THEN ${degradedFrom} END, CASE WHEN ${pinned} THEN ${degradedSince} END FROM ${parentOf(rows)} WHERE ${isSnapshot}`,\n\t\t\t),\n\t\t\trecord({ ...entry, element: \"link\" }, [\"patch\"], `, ${d.jsonEach(entry, \"link\", \"snapshot\", \"chain\")}`),\n\t\t\trecord(entry, [\"snapshot\", \"bundle\", \"blob\"]),\n\t\t];\n\t};\n\n\tconst eventColumns = [\"run_id\", \"seq\", \"payload\"];\n\tconst eventsSource = {\n\t\tname: \"journal-events\",\n\t\ttable: events,\n\t\ttriggers: [\n\t\t\tcreateTrigger(\n\t\t\t\t`${events}_snapshot_refs`,\n\t\t\t\t\"INSERT\",\n\t\t\t\tevents,\n\t\t\t\trunRefs(triggerRows(eventColumns)),\n\t\t\t\tcheckpointCondition(d, newRow),\n\t\t\t),\n\t\t\tcreateTrigger(\n\t\t\t\t`${events}_snapshot_state`,\n\t\t\t\t\"INSERT\",\n\t\t\t\tevents,\n\t\t\t\t[runState(triggerRows(eventColumns))],\n\t\t\t\tstatusCondition(d, newRow),\n\t\t\t),\n\t\t],\n\t\tbackfill: [\n\t\t\t...runRefs(storedRows(d, events, eventColumns, checkpointCondition(d, storedRow))),\n\t\t\trunState(storedRows(d, events, eventColumns, statusCondition(d, storedRow))),\n\t\t],\n\t};\n\tconst headerColumns = [\"run_id\", \"status\"];\n\tconst runsSource = {\n\t\tname: \"journal-runs\",\n\t\ttable: runs,\n\t\ttriggers: [\n\t\t\tcreateTrigger(`${runs}_snapshot_state_insert`, \"INSERT\", runs, [runHeader(triggerRows(headerColumns))]),\n\t\t\tcreateTrigger(`${runs}_snapshot_state_status`, \"UPDATE OF status\", runs, [\n\t\t\t\t`UPDATE ${t.runState} SET retained = ${released(\"NEW.status\")} WHERE run_id = NEW.run_id AND seq = ${HEADER_SEQ}`,\n\t\t\t]),\n\t\t\tcreateTrigger(`${runs}_snapshot_refs_delete`, \"DELETE\", runs, [\n\t\t\t\t`DELETE FROM ${t.runRefs} WHERE run_id = OLD.run_id`,\n\t\t\t\t`DELETE FROM ${t.runState} WHERE run_id = OLD.run_id`,\n\t\t\t]),\n\t\t],\n\t\tbackfill: [runHeader(storedRows(d, runs, headerColumns, d.literals.true))],\n\t};\n\tconst entryColumns = [\"session_id\", \"seq\", \"entry_id\", \"entry_json\"];\n\t/** One entry as `r`, with its parent named once, so that each statement parses the entry's JSON for it only once. */\n\tconst triggerEntry = `(SELECT ${entryColumns.map((name) => `NEW.${name} AS ${name}`).join(\", \")}, ${parentColumns(d, \"NEW.entry_json\")})`;\n\tconst storedEntry = `(SELECT ${entryColumns.join(\", \")}, ${parentColumns(d, \"entry_json\")} FROM ${entries} WHERE ${d.rowOrder()} = ?)`;\n\t/** The rows session `?` stores from seq `?` on, as `storedEntry` yields one. */\n\tconst entriesFrom = `(SELECT ${entryColumns.join(\", \")}, ${parentColumns(d, \"entry_json\")} FROM ${entries} WHERE session_id = ? AND seq >= ?)`;\n\t/** Sets the previous snapshot of the references of `rows` to their parent's anchor: when a pin began stays. */\n\tconst refsAgain = (rows: string) =>\n\t\t`UPDATE ${t.sessionRefs} SET prev_seq = linked.anchor_seq FROM (SELECT r.session_id, r.seq, parent.anchor_seq FROM ${parentOf(rows)} WHERE ${isSnapshot}) AS linked WHERE ${t.sessionRefs}.session_id = linked.session_id AND ${t.sessionRefs}.seq = linked.seq`;\n\tconst indexComplete = entriesIndexComplete(t.sources);\n\tconst newRowOrder = d.rowOrder(\"NEW\");\n\tconst forkLink = (rows: string) =>\n\t\tforkSegments === undefined ? [] : [forkSessionLink(t.sessionLinks, forkSegments, rows, isSnapshot)];\n\tconst entriesSource = {\n\t\tname: \"session-entries\",\n\t\ttable: entries,\n\t\ttriggers: [\n\t\t\t// While the rows that existed first are indexed, new rows wait for that pass, which keeps parents ahead of\n\t\t\t// their children: the pass reaches them by extending its watermark. A row written at a rowid the pass has\n\t\t\t// already gone by, which SQLite reuses once the newest rows are deleted, moves the pass back to it; indexing\n\t\t\t// a row twice changes nothing.\n\t\t\tcreateTrigger(`${entries}_snapshot_links`, \"INSERT\", entries, sessionLink(triggerEntry), indexComplete),\n\t\t\tcreateTrigger(\n\t\t\t\t`${entries}_snapshot_refs`,\n\t\t\t\t\"INSERT\",\n\t\t\t\tentries,\n\t\t\t\tsessionRecord(triggerEntry),\n\t\t\t\t`${d.contains(\"NEW.entry_json\", `'\"worktree_snapshot\"'`)} AND ${indexComplete}`,\n\t\t\t),\n\t\t\tcreateTrigger(\n\t\t\t\t`${entries}_snapshot_pending`,\n\t\t\t\t\"INSERT\",\n\t\t\t\tentries,\n\t\t\t\t[\n\t\t\t\t\t`UPDATE ${t.sources} SET watermark = ${newRowOrder} WHERE source = 'session-entries' AND watermark < ${newRowOrder}`,\n\t\t\t\t\t`UPDATE ${t.sources} SET backfilled_through = ${newRowOrder} - 1 WHERE source = 'session-entries' AND backfilled_through >= ${newRowOrder}`,\n\t\t\t\t\t// This build's own progress follows, so an older build's backfill of these rows is never trusted (#5558).\n\t\t\t\t\t`UPDATE ${t.sources} SET watermark = ${newRowOrder} WHERE source = '${ENTRIES_OWN_PROGRESS}' AND watermark < ${newRowOrder}`,\n\t\t\t\t\t`UPDATE ${t.sources} SET backfilled_through = ${newRowOrder} - 1 WHERE source = '${ENTRIES_OWN_PROGRESS}' AND backfilled_through >= ${newRowOrder}`,\n\t\t\t\t],\n\t\t\t\t`NOT COALESCE(${indexComplete}, ${d.literals.true})`,\n\t\t\t),\n\t\t\tcreateTrigger(`${entries}_snapshot_refs_delete`, \"DELETE\", entries, [\n\t\t\t\t`UPDATE ${t.sessionLinks} SET children = children - 1 WHERE session_id = OLD.session_id AND children > 0 AND entry_id = (SELECT parent_id FROM ${t.sessionLinks} WHERE session_id = OLD.session_id AND seq = OLD.seq)`,\n\t\t\t\t`DELETE FROM ${t.sessionLinks} WHERE session_id = OLD.session_id AND seq = OLD.seq`,\n\t\t\t\t`DELETE FROM ${t.sessionRefs} WHERE session_id = OLD.session_id AND seq = OLD.seq`,\n\t\t\t\t`DELETE FROM ${t.sessionRecords} WHERE session_id = OLD.session_id AND seq = OLD.seq`,\n\t\t\t]),\n\t\t].map((trigger) => withMarker(trigger, ENTRIES_OWN_PROGRESS)),\n\t\tbackfill: [],\n\t\trowwise: [...sessionLink(storedEntry), ...forkLink(storedEntry), ...sessionRecord(storedEntry)],\n\t\t...(forkSegments === undefined ? {} : { segments: forkSegments }),\n\t\tentriesFrom,\n\t\trelink: {\n\t\t\tlink: sessionLink(storedEntry)[1]!,\n\t\t\t...(forkSegments === undefined ? {} : { fork: forkLink(storedEntry)[0]! }),\n\t\t\t// The reference's previous snapshot only: when a pin began stays as its first indexing recorded it.\n\t\t\trefs: refsAgain(storedEntry),\n\t\t\trefsFrom: refsAgain(entriesFrom),\n\t\t},\n\t\t// The triggers that index degraded pins (#4922). Older builds install theirs under the same names (#5065).\n\t\tversion: \"session-entries@degraded-pins\",\n\t\town: ENTRIES_OWN_PROGRESS,\n\t\tmarker: ENTRIES_OWN_PROGRESS,\n\t\tsignature: { trigger: `${entries}_snapshot_refs`, text: \"degraded_from\" },\n\t\treset: [`DELETE FROM ${t.sessionLinks}`, `DELETE FROM ${t.sessionRefs}`, `DELETE FROM ${t.sessionRecords}`],\n\t};\n\t// What a shared-placement root carries to its children (#4503): the snapshot each queued pool work row carries, and\n\t// the one of the root's own binding, which its pool records while it is prepared, children queued or not.\n\tconst workSource = carriedSource(d, t, {\n\t\tname: \"journal-pool-work\",\n\t\ttable: `${runs}_work`,\n\t\towner: \"work\",\n\t\tkey: \"id\",\n\t\tjson: \"descriptor\",\n\t\tpath: [\"execution\", \"workspaceSnapshot\"],\n\t\tmarker: '\"workspaceSnapshot\"',\n\t});\n\tconst rootSource = carriedSource(d, t, {\n\t\tname: \"journal-pool-root-snapshot\",\n\t\ttable: `${runs}_pool_root_snapshot`,\n\t\towner: \"root\",\n\t\tkey: \"root\",\n\t\tjson: \"snapshot\",\n\t\tpath: [],\n\t});\n\treturn [eventsSource, runsSource, entriesSource, workSource, rootSource];\n}\n\n/** What {@link relinkSessionEntries} and {@link linkStoredEntry} read and run. */\ninterface EntryLinking {\n\treadonly dialect: StorageDialect;\n\treadonly links: string;\n\treadonly entries: string;\n\t/** The sessions' fork segments table, where the statements link the entries of sessions with segments. */\n\treadonly segments: string | undefined;\n\t/** The statements that index one stored entry, bound to its row order: the session entries' `rowwise`. */\n\treadonly statements: readonly string[];\n\t/** Those that link a row linked already again: the session entries' `relink`. */\n\treadonly relink: NonNullable<IndexSource[\"relink\"]>;\n}\n\n/** The session entries' {@link EntryLinking} of `source`, with the dialect and links table it runs on. */\nfunction entryLinking(source: IndexSource, dialect: StorageDialect, links: string): EntryLinking {\n\treturn {\n\t\tdialect,\n\t\tlinks,\n\t\tentries: source.table,\n\t\tsegments: source.segments,\n\t\tstatements: source.rowwise!,\n\t\trelink: source.relink!,\n\t};\n}\n\n/**\n * Runs `statements` in order, each sent without waiting for the answer to the one before: a database runs a\n * connection's calls in the order they are made, and a pipelined connection sends them together.\n */\nasync function runInOrder(executor: SqliteExecutor, statements: readonly SqliteStatement[]): Promise<void> {\n\tawait Promise.all(statements.map(({ sql, params }) => executor.run(sql, ...params)));\n}\n\n/**\n * Links the rows session `sessionId` stores from seq `fromSeq` on again, in seq order, each behind the rows before it\n * (#6560), then counts their children again: an entry's children are the rows after it in the session whose parent\n * has its id. A materialization runs it once it copied rows in below the rows a fork appended, and the index's rebuild\n * when it meets a row stored before rows below it: both link every row as a save in seq order did.\n */\nasync function relinkSessionEntries(\n\texecutor: SqliteExecutor,\n\tlinking: EntryLinking,\n\tsessionId: string,\n\tfromSeq: number,\n): Promise<void> {\n\tconst { dialect, links, entries, segments, statements, relink } = linking;\n\tconst rows = await executor.all<SqliteRow & { id: number; linked: number; snapshot: number }>(\n\t\t`SELECT ${dialect.rowOrder(\"e\")} AS id,\n\t\t\tCASE WHEN EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = e.session_id AND l.seq = e.seq) THEN 1 ELSE 0 END AS linked,\n\t\t\tCASE WHEN ${dialect.contains(\"e.entry_json\", `'\"worktree_snapshot\"'`)} THEN 1 ELSE 0 END AS snapshot\n\t\tFROM ${entries} AS e WHERE e.session_id = ? AND e.seq >= ? ORDER BY e.seq`,\n\t\tsessionId,\n\t\tfromSeq,\n\t);\n\tconst forked =\n\t\tsegments !== undefined &&\n\t\trelink.fork !== undefined &&\n\t\t(await executor.get(`SELECT 1 AS found FROM ${segments} WHERE session_id = ? LIMIT 1`, sessionId)) !== undefined;\n\t// A row not linked yet gets every statement; one linked already only those that write its link and reference again.\n\tconst again = (snapshot: boolean) => [\n\t\trelink.link,\n\t\t...(forked ? [relink.fork!] : []),\n\t\t...(snapshot ? [relink.refs] : []),\n\t];\n\tawait runInOrder(\n\t\texecutor,\n\t\trows.flatMap(({ id, linked, snapshot }) =>\n\t\t\t(Number(linked) === 1 ? again(Number(snapshot) === 1) : statements).map((sql) => ({ sql, params: [id] })),\n\t\t),\n\t);\n\tconst linked = await executor.all<\n\t\tSqliteRow & { seq: number; entry_id: string; parent_id: string | null; children: number }\n\t>(\n\t\t`SELECT seq, entry_id, parent_id, children FROM ${links} WHERE session_id = ? AND seq >= ? ORDER BY seq DESC`,\n\t\tsessionId,\n\t\tfromSeq,\n\t);\n\tconst later = new Map<string, number>();\n\tconst counts: SqliteStatement[] = [];\n\tfor (const link of linked) {\n\t\tconst children = later.get(link.entry_id) ?? 0;\n\t\tif (Number(link.children) !== children)\n\t\t\tcounts.push({\n\t\t\t\tsql: `UPDATE ${links} SET children = ? WHERE session_id = ? AND seq = ?`,\n\t\t\t\tparams: [children, sessionId, Number(link.seq)],\n\t\t\t});\n\t\tif (link.parent_id !== null) later.set(link.parent_id, (later.get(link.parent_id) ?? 0) + 1);\n\t}\n\tawait runInOrder(executor, counts);\n}\n\n/**\n * Links, in seq order, every row session `sessionId` stores up to seq `seq` that is not linked yet, behind the rows of\n * its sources that its segments before `seq` name, which are linked first, the same way. Where the session has a row\n * linked already after the first row this links, the rows after it are linked again with it (see\n * {@link relinkSessionEntries}). A session linked this way has every row before a linked row linked, so the link of a\n * segment's last row tells that its source is linked through it.\n */\nasync function linkThrough(\n\texecutor: SqliteExecutor,\n\tlinking: EntryLinking,\n\tsessionId: string,\n\tseq: number,\n): Promise<void> {\n\tconst { dialect, links, entries, segments, statements } = linking;\n\tconst sources = async (through: number) => {\n\t\tif (segments === undefined) return;\n\t\tconst pending = await executor.all<SqliteRow & { source_id: string; to_seq: number }>(\n\t\t\t`SELECT seg.source_id, seg.to_seq FROM ${segments} AS seg WHERE seg.session_id = ? AND seg.base_seq < ? AND NOT EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = seg.source_id AND l.seq = seg.to_seq) ORDER BY seg.base_seq`,\n\t\t\tsessionId,\n\t\t\tthrough,\n\t\t);\n\t\tfor (const segment of pending) await linkThrough(executor, linking, segment.source_id, Number(segment.to_seq));\n\t};\n\tawait sources(seq);\n\tconst first = await executor.get<SqliteRow & { seq: number | null; later: number }>(\n\t\t`SELECT f.seq, CASE WHEN EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = ? AND l.seq > f.seq) THEN 1 ELSE 0 END AS later\n\t\tFROM (SELECT min(e.seq) AS seq FROM ${entries} AS e WHERE e.session_id = ? AND e.seq <= ? AND NOT EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = e.session_id AND l.seq = e.seq)) AS f`,\n\t\tsessionId,\n\t\tsessionId,\n\t\tseq,\n\t);\n\tif (first?.seq === null || first?.seq === undefined) return;\n\tif (Number(first.later) === 1) {\n\t\t// The rows after it were linked before it: they are linked again, behind it.\n\t\tawait relinkFrom(executor, linking, sessionId, Number(first.seq));\n\t\treturn;\n\t}\n\tconst rows = await executor.all<SqliteRow & { id: number }>(\n\t\t`SELECT ${dialect.rowOrder()} AS id FROM ${entries} WHERE session_id = ? AND seq >= ? AND seq <= ? ORDER BY seq`,\n\t\tsessionId,\n\t\tNumber(first.seq),\n\t\tseq,\n\t);\n\tawait runInOrder(\n\t\texecutor,\n\t\trows.flatMap(({ id }) => statements.map((sql) => ({ sql, params: [id] }))),\n\t);\n}\n\n/**\n * Links the rows session `sessionId` stores from seq `fromSeq` on again, behind the rows of the sources its segments\n * name, and then the rows of every session that reads them through a segment and has a row linked after them: such a\n * row took its parent's link, or its anchor, from the rows linked again (#6560).\n */\nasync function relinkFrom(\n\texecutor: SqliteExecutor,\n\tlinking: EntryLinking,\n\tsessionId: string,\n\tfromSeq: number,\n): Promise<void> {\n\tconst { links, segments } = linking;\n\tif (segments !== undefined) {\n\t\tconst pending = await executor.all<SqliteRow & { source_id: string; to_seq: number }>(\n\t\t\t`SELECT seg.source_id, seg.to_seq FROM ${segments} AS seg WHERE seg.session_id = ? AND NOT EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = seg.source_id AND l.seq = seg.to_seq) ORDER BY seg.base_seq`,\n\t\t\tsessionId,\n\t\t);\n\t\tfor (const segment of pending) await linkThrough(executor, linking, segment.source_id, Number(segment.to_seq));\n\t}\n\tawait relinkSessionEntries(executor, linking, sessionId, fromSeq);\n\tif (segments === undefined) return;\n\tconst readers = await executor.all<SqliteRow & { session_id: string; first: number }>(\n\t\t`SELECT seg.session_id, min(seg.base_seq + 1 + CASE WHEN seg.from_seq < ? THEN ? - seg.from_seq ELSE 0 END) AS first\n\t\tFROM ${segments} AS seg WHERE seg.source_id = ? AND seg.to_seq >= ? GROUP BY seg.session_id ORDER BY seg.session_id`,\n\t\tfromSeq,\n\t\tfromSeq,\n\t\tsessionId,\n\t\tfromSeq,\n\t);\n\tfor (const reader of readers) {\n\t\tconst linked = await executor.get(\n\t\t\t`SELECT 1 AS found FROM ${links} WHERE session_id = ? AND seq >= ? LIMIT 1`,\n\t\t\treader.session_id,\n\t\t\tNumber(reader.first),\n\t\t);\n\t\tif (linked !== undefined) await relinkFrom(executor, linking, reader.session_id, Number(reader.first));\n\t}\n}\n\n/**\n * Indexes the stored entry at row order `id`, as the index's backfill meets it. The backfill goes in row order, but a\n * fork that copied in the rows it read stores them after the entries it appended, and a fork moved onto another\n * session's copy reads rows stored after its own (#6560): a row with a row before it, of its session or of a source\n * its segments name, not linked yet, or with a row after it linked already, is linked by {@link linkThrough}, so every\n * row is linked behind the rows before it in its view, as a save links it.\n */\nasync function linkStoredEntry(executor: SqliteExecutor, linking: EntryLinking, id: number): Promise<void> {\n\tconst { dialect, links, entries, segments, statements } = linking;\n\tconst pendingSource =\n\t\tsegments === undefined\n\t\t\t? \"0\"\n\t\t\t: `CASE WHEN EXISTS (SELECT 1 FROM ${segments} AS seg WHERE seg.session_id = e.session_id AND seg.base_seq < e.seq AND NOT EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = seg.source_id AND l.seq = seg.to_seq)) THEN 1 ELSE 0 END`;\n\tconst row = await executor.get<\n\t\tSqliteRow & {\n\t\t\tsession_id: string;\n\t\t\tseq: number;\n\t\t\tlinked: number;\n\t\t\tlater: number;\n\t\t\tprevious: number | null;\n\t\t\tlinked_before: number | null;\n\t\t\tpending_source: number;\n\t\t}\n\t>(\n\t\t`SELECT e.session_id, e.seq,\n\t\t\tCASE WHEN EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = e.session_id AND l.seq = e.seq) THEN 1 ELSE 0 END AS linked,\n\t\t\tCASE WHEN EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = e.session_id AND l.seq > e.seq) THEN 1 ELSE 0 END AS later,\n\t\t\t(SELECT max(p.seq) FROM ${entries} AS p WHERE p.session_id = e.session_id AND p.seq < e.seq) AS previous,\n\t\t\t(SELECT max(l.seq) FROM ${links} AS l WHERE l.session_id = e.session_id AND l.seq < e.seq) AS linked_before,\n\t\t\t${pendingSource} AS pending_source\n\t\tFROM ${entries} AS e WHERE ${dialect.rowOrder(\"e\")} = ?`,\n\t\tid,\n\t);\n\tconst inOrder =\n\t\trow === undefined ||\n\t\tNumber(row.linked) === 1 ||\n\t\t(Number(row.later) === 0 &&\n\t\t\tNumber(row.pending_source) === 0 &&\n\t\t\t(row.previous === null || (row.linked_before !== null && Number(row.linked_before) === Number(row.previous))));\n\tif (inOrder) for (const sql of statements) await executor.run(sql, id);\n\telse await linkThrough(executor, linking, row.session_id, Number(row.seq));\n}\n\n/**\n * How a session store links the rows a materialization copies into a fork, and the forks it moves onto another\n * session's copy (#6560): see {@link sessionEntryLinks}.\n */\nexport interface SessionEntryLinks {\n\t/** The statement that links one piece of the rows a materialization copied: see `materializedForkLinks`. */\n\treadonly materialized: string;\n\t/**\n\t * Runs `before`, the writes of session `sessionId`'s new segments, and in the same request reads whether its links\n\t * from seq `fromSeq` on are what a save in seq order writes ({@link forkLinksCheck}). They are but in a few\n\t * histories, with entries that share an ID or name a parent after them: the session is then linked again from the\n\t * first row that is not, row by row, with the sessions that read it.\n\t */\n\tsettle(\n\t\texecutor: SqliteExecutor,\n\t\tsessionId: string,\n\t\tfromSeq: number,\n\t\tbefore: readonly SqliteStatement[],\n\t\thasSegments?: boolean,\n\t): Promise<void>;\n}\n\n/**\n * The {@link SessionEntryLinks} of a session store under `prefix` whose fork segments table is `forkSegments` (#6560).\n * Until the index's backfill of the session entries is done, which links the rows in seq order itself, `settle` only\n * writes the segments.\n */\nexport function sessionEntryLinks(prefix: string, dialect: StorageDialect, forkSegments: string): SessionEntryLinks {\n\tconst t = snapshotIndexTables(prefix);\n\tconst source = indexSources(prefix, t, dialect, forkSegments).find((source) => source.name === \"session-entries\")!;\n\tconst linking = entryLinking(source, dialect, t.sessionLinks);\n\tconst complete = entriesIndexComplete(t.sources);\n\tconst tables = { links: t.sessionLinks, segments: forkSegments, refs: t.sessionRefs };\n\tconst materializePlain = dialect.name === \"postgres\";\n\tconst checkWithSegments = forkLinksCheck(tables, complete, { hasSegments: true });\n\tconst checkWithoutSegments = forkLinksCheck(tables, complete, {\n\t\thasSegments: false,\n\t\tmaterialize: materializePlain,\n\t});\n\treturn {\n\t\tmaterialized: materializedForkLinks(t.sessionLinks, forkSegments, complete, dialect.types.int, dialect.name),\n\t\tasync settle(executor, sessionId, fromSeq, before, hasSegments = true) {\n\t\t\ttype Verdict = SqliteRow & { seq: number | null; children: number; refs: number };\n\t\t\tconst [, verdict] = await Promise.all([\n\t\t\t\trunInOrder(executor, before),\n\t\t\t\thasSegments\n\t\t\t\t\t? executor.get<Verdict>(checkWithSegments, sessionId, sessionId, fromSeq, sessionId, fromSeq)\n\t\t\t\t\t: materializePlain\n\t\t\t\t\t\t? executor.get<Verdict>(checkWithoutSegments, sessionId, fromSeq, sessionId, fromSeq)\n\t\t\t\t\t\t: executor.get<Verdict>(\n\t\t\t\t\t\t\t\tcheckWithoutSegments,\n\t\t\t\t\t\t\t\tsessionId,\n\t\t\t\t\t\t\t\tfromSeq,\n\t\t\t\t\t\t\t\tsessionId,\n\t\t\t\t\t\t\t\tfromSeq,\n\t\t\t\t\t\t\t\tsessionId,\n\t\t\t\t\t\t\t\tfromSeq,\n\t\t\t\t\t\t\t),\n\t\t\t]);\n\t\t\tif (verdict === undefined) return;\n\t\t\tconst children = Number(verdict.children) === 1;\n\t\t\tif (verdict.seq !== null || children)\n\t\t\t\tawait relinkFrom(executor, linking, sessionId, children ? fromSeq : Number(verdict.seq));\n\t\t\tif (verdict.seq !== null || children || Number(verdict.refs) === 1)\n\t\t\t\tawait executor.run(linking.relink.refsFrom, sessionId, fromSeq);\n\t\t},\n\t};\n}\n\n/**\n * Creates a chunk table named `table` unless it exists. An ordinary table, whose primary key is an index of its own:\n * a lookup reads that small index, then only the row it finds. A `WITHOUT ROWID` table, as earlier releases created,\n * keeps each row in its key's b-tree, so a seek reads the whole record of every 1 MiB row it compares on its way, and\n * every lookup, a delete's of a blob without chunks included, read several chunks (#5541). On Postgres both are the\n * same heap table.\n */\nfunction chunkTableDefinition(table: string, dialect: StorageDialect): string {\n\tconst { int, text, blob } = dialect.types;\n\treturn `CREATE TABLE IF NOT EXISTS ${table} (hash ${text} NOT NULL, idx ${int} NOT NULL, data ${blob} NOT NULL, PRIMARY KEY (hash, idx))${dialect.tableOptions}`;\n}\n\n/** The trigger that deletes a blob's chunks with it, in the statement that deletes it, whoever deletes it. */\nconst chunksDeleteTrigger = (t: SnapshotIndexTables) =>\n\tcreateTrigger(`${t.blobs}_chunks_delete_all`, \"DELETE\", t.blobs, [\n\t\t`DELETE FROM ${t.blobChunks} WHERE hash = OLD.hash`,\n\t]);\n\n/**\n * The tables of a chunk table's move to the row layout (#5541): `next`, the new table it fills, which then takes the\n * chunk table's name, and `retired`, the old table under its new name until it is emptied and dropped.\n */\nconst chunkMoveTables = (t: SnapshotIndexTables) =>\n\t({ next: `${t.blobChunks}_next`, retired: `${t.blobChunks}_retired` }) as const;\n\n/**\n * What {@link blobChunkWrites} reads once the chunk table exists: whether the blob table has its `chunks` column, and\n * whether the trigger that deletes a blob's chunks with it is there.\n */\nfunction blobChunkProbes(transaction: SqliteExecutor, t: SnapshotIndexTables, dialect: StorageDialect) {\n\tconst column = dialect.columnExists(t.blobs, \"chunks\");\n\tconst trigger = dialect.schemaObjects([`${t.blobs}_chunks_delete_all`]);\n\treturn [\n\t\tasync () => (await transaction.get(column.sql, ...column.params)) !== undefined,\n\t\tasync () => (await transaction.get(trigger.sql, ...trigger.params)) !== undefined,\n\t] as const;\n}\n\n/** The blob table's `chunks` column and the chunks' delete trigger, those of them that {@link blobChunkProbes} missed. */\nfunction blobChunkWrites(\n\tt: SnapshotIndexTables,\n\tdialect: StorageDialect,\n\t[column, trigger]: readonly [boolean, boolean],\n): BatchWrite[] {\n\treturn [\n\t\t!column && `ALTER TABLE ${t.blobs} ADD COLUMN chunks ${dialect.types.int} NOT NULL DEFAULT 0`,\n\t\t!trigger && dialect.dropTrigger(`${t.blobs}_chunks_delete`, t.blobs, true),\n\t\t!trigger && dialect.renderTrigger(chunksDeleteTrigger(t)),\n\t];\n}\n\n/**\n * Chunked blobs (#4954): the chunk table, the blob table's `chunks` column, 0 for a blob whose bytes are in its own row,\n * as every blob written before it was, and the trigger that deletes a blob's chunks with it. Idempotent.\n */\nasync function addBlobChunks(\n\ttransaction: SqliteExecutor,\n\tt: SnapshotIndexTables,\n\tdialect: StorageDialect,\n): Promise<void> {\n\tconst found = await statementBatch(\n\t\ttransaction,\n\t\t[chunkTableDefinition(t.blobChunks, dialect)],\n\t\tblobChunkProbes(transaction, t, dialect),\n\t);\n\tawait statementBatch(transaction, blobChunkWrites(t, dialect, found), []);\n}\n\n/**\n * Creates the blob table and the tables of its reference index that are missing, reading what each step needs\n * together, so on a SQLite file connection the setup waits for the connection's thread three times.\n */\nasync function createSnapshotIndexTables(\n\ttransaction: SqliteExecutor,\n\tt: SnapshotIndexTables,\n\tprefix: string,\n\tdialect: StorageDialect,\n\t/** Statements that run with the tables' own, in the same request: such as a ledger record of what they create. */\n\tafter: readonly string[] = [],\n): Promise<void> {\n\tconst { int, text, blob } = dialect.types;\n\tconst strict = dialect.tableOptions;\n\tconst keyed = dialect.withoutRowidTableOptions;\n\tconst ageColumn = dialect.columnExists(t.blobs, \"created_at\");\n\tconst [age] = await statementBatch(\n\t\ttransaction,\n\t\t[\n\t\t\t`CREATE TABLE IF NOT EXISTS ${t.blobs} (hash ${text} PRIMARY KEY, bytes ${int} NOT NULL, data ${blob} NOT NULL, created_at ${int} NOT NULL DEFAULT (${dialect.nowSeconds}))${strict}`,\n\t\t],\n\t\t[() => transaction.get<SqliteRow & { default_value: SqliteValue }>(ageColumn.sql, ...ageColumn.params)],\n\t);\n\tconst [column, trigger, ...refColumns] = await statementBatch(\n\t\ttransaction,\n\t\t[\n\t\t\t// Unknown ages are stamped in short collection batches, never by rewriting the table at open.\n\t\t\t!age && `ALTER TABLE ${t.blobs} ADD COLUMN created_at ${int} NOT NULL DEFAULT 0`,\n\t\t\t`\n\t\tCREATE TABLE IF NOT EXISTS ${t.runRefs} (run_id ${text} NOT NULL, hash ${text} NOT NULL, PRIMARY KEY (run_id, hash))${keyed};\n\t\tCREATE INDEX IF NOT EXISTS ${t.runRefs}_hash ON ${t.runRefs} (hash);\n\t\tCREATE TABLE IF NOT EXISTS ${t.runState} (run_id ${text} PRIMARY KEY, retained ${int} NOT NULL, seq ${int} NOT NULL)${keyed};\n\t\tCREATE TABLE IF NOT EXISTS ${t.sessionRefs} (session_id ${text} NOT NULL, seq ${int} NOT NULL, root ${text} NOT NULL, snapshot_id ${text} NOT NULL, prev_seq ${int}, restore_from ${text}, restore_to ${text}, degraded_from ${text}, degraded_since ${int}, PRIMARY KEY (session_id, seq))${keyed};\n\t\tCREATE TABLE IF NOT EXISTS ${t.sessionLinks} (session_id ${text} NOT NULL, seq ${int} NOT NULL, entry_id ${text} NOT NULL, parent_id ${text}, anchor_seq ${int}, children ${int} NOT NULL, broken ${int} NOT NULL, PRIMARY KEY (session_id, seq))${strict};\n\t\tCREATE INDEX IF NOT EXISTS ${t.sessionLinks}_entry ON ${t.sessionLinks} (session_id, entry_id);\n\t\t${sessionLinksLeafIndex(t, dialect)};\n\t\tCREATE INDEX IF NOT EXISTS ${t.sessionLinks}_broken ON ${t.sessionLinks} (session_id) WHERE broken = 1;\n\t\tCREATE TABLE IF NOT EXISTS ${t.sessionRecords} (session_id ${text} NOT NULL, seq ${int} NOT NULL, snapshot_id ${text} NOT NULL, hash ${text} NOT NULL, PRIMARY KEY (session_id, seq, hash))${keyed};\n\t\tCREATE INDEX IF NOT EXISTS ${t.sessionRecords}_hash ON ${t.sessionRecords} (hash);\n\t\tCREATE TABLE IF NOT EXISTS ${t.carriedRefs} (owner ${text} NOT NULL, hash ${text} NOT NULL, PRIMARY KEY (owner, hash))${keyed};\n\t\tCREATE INDEX IF NOT EXISTS ${t.carriedRefs}_hash ON ${t.carriedRefs} (hash);\n\t\tCREATE TABLE IF NOT EXISTS ${t.collection} (id ${int} PRIMARY KEY CHECK (id = 1), claimed_at ${int}, holder ${text}, finished_at ${int}, deleted ${int}, error_code ${text})${strict};\n\t\tINSERT INTO ${t.collection} (id) VALUES (1) ON CONFLICT DO NOTHING;\n\t\tCREATE TABLE IF NOT EXISTS ${t.sources} (source ${text} PRIMARY KEY, watermark ${int} NOT NULL, backfilled_through ${int} NOT NULL)${keyed};\n\t\t${after.map((statement) => `${statement};`).join(\"\\n\")}\n\t`,\n\t\t\tchunkTableDefinition(t.blobChunks, dialect),\n\t\t],\n\t\t[...blobChunkProbes(transaction, t, dialect), ...sessionRefColumnProbes(transaction, t, dialect)],\n\t);\n\tawait statementBatch(\n\t\ttransaction,\n\t\t[\n\t\t\t...blobChunkWrites(t, dialect, [column, trigger]),\n\t\t\t...(age && String(age.default_value) !== \"0\" ? blobMaintenanceIndexes(t) : []),\n\t\t\t...sessionRefColumnWrites(t, prefix, dialect, refColumns),\n\t\t],\n\t\t[],\n\t);\n}\n\n/** The indexes collection and the chunk-layout move look blobs up by. */\nfunction blobMaintenanceIndexes(t: SnapshotIndexTables): string[] {\n\treturn [\n\t\t`CREATE INDEX IF NOT EXISTS ${t.blobs}_age ON ${t.blobs} (created_at, hash)`,\n\t\t`CREATE INDEX IF NOT EXISTS ${t.blobs}_inline_size ON ${t.blobs} (chunks, hash) WHERE chunks = 0 AND length(data) > ${SNAPSHOT_BLOB_CHUNK_BYTES}`,\n\t];\n}\n\nasync function addBlobMaintenanceIndexes(transaction: SqliteExecutor, t: SnapshotIndexTables): Promise<void> {\n\tawait statementBatch(transaction, blobMaintenanceIndexes(t), []);\n}\n\n/**\n * The ledger step, `schema:snapshot-links-hot`, after which the session links table has no index that names\n * `children` on PostgreSQL ({@link hotSessionLinks}).\n */\nconst SESSION_LINKS_HOT_DOMAIN = \"snapshot-links-hot\";\n\nfunction sessionLinksHotSchema(prefix: string) {\n\treturn { ledger: storageMigrationTable(prefix), domain: SESSION_LINKS_HOT_DOMAIN, revision: 1 };\n}\n\n/**\n * The index the queries for the session tree's leaves read: on PostgreSQL every link with an anchor, whose leaves they\n * pick by `children = 0` ({@link hotSessionLinks}); elsewhere only the leaves with an anchor.\n */\nfunction sessionLinksLeafIndex(t: SnapshotIndexTables, dialect: StorageDialect): string {\n\treturn dialect.name === \"postgres\"\n\t\t? `CREATE INDEX IF NOT EXISTS ${t.sessionLinks}_anchored ON ${t.sessionLinks} (session_id, anchor_seq) WHERE anchor_seq IS NOT NULL`\n\t\t: `CREATE INDEX IF NOT EXISTS ${t.sessionLinks}_leaves ON ${t.sessionLinks} (session_id, anchor_seq) WHERE children = 0 AND anchor_seq IS NOT NULL`;\n}\n\n/** The ledger record of {@link hotSessionLinks}, for a database whose links table this transaction created with it. */\nfunction hotSessionLinksRecord(prefix: string, dialect: StorageDialect): string {\n\tconst { ledger, domain, revision } = sessionLinksHotSchema(prefix);\n\treturn `INSERT INTO ${ledger} (domain, version, applied_at) VALUES ('schema:${domain}', ${revision}, ${dialect.nowMs}) ON CONFLICT DO NOTHING`;\n}\n\n/**\n * Makes the update each append writes to its parent's session link a HOT update on PostgreSQL: one that stays on its\n * page and writes no index entry. Each append raises its parent link's `children`, and PostgreSQL updates a row in\n * place only when no index names a changed column, its condition included, which `_leaves` (`WHERE children = 0`)\n * did. So every append wrote the parent link's new version into each of the table's indexes. `_anchored` indexes the\n * same rows without that condition, and the queries for leaves, which only collection runs, check `children = 0` on\n * the rows it finds. Older builds read and write the table as before, and none of them creates `_leaves` again: on\n * PostgreSQL the step that creates it runs once per database. Recorded in the ledger, so it runs once. SQLite keeps\n * `_leaves`, as it updates rows in place whatever their indexes.\n */\nasync function hotSessionLinks(\n\ttransaction: SqliteExecutor,\n\tt: SnapshotIndexTables,\n\tprefix: string,\n\tdialect: StorageDialect,\n): Promise<void> {\n\tawait ensureStorageSchema(transaction, dialect, sessionLinksHotSchema(prefix), async () => {\n\t\tawait transaction.exec(sessionLinksLeafIndex(t, dialect));\n\t\tawait transaction.exec(`DROP INDEX IF EXISTS ${t.sessionLinks}_leaves`);\n\t});\n}\n\n/** This process's check of {@link hotSessionLinks} for each database, ledger and links table, while it holds. */\nconst hotSessionLinksChecks = new Map<string, Promise<boolean>>();\n\n/**\n * Runs {@link hotSessionLinks} on a PostgreSQL database whose ledger lacks it, in a transaction of its own. Nothing runs\n * where the catalog the open read records it, or where this role does not own the links table: a runtime role without\n * DDL opens as before, and `atomic storage migrate`, run as the owner, makes the change. A role that does not own the\n * table finds that out once per process, as for the fillfactor steps.\n */\nasync function ensureHotSessionLinks(database: SqliteDatabase, t: SnapshotIndexTables, prefix: string): Promise<void> {\n\tconst dialect = dialectOf(database);\n\tif (dialect.name !== \"postgres\" || database.readOnly === true) return;\n\tconst schema = sessionLinksHotSchema(prefix);\n\tif (await storageSchemaCurrent(database, schema)) return;\n\tconst identity = database.databaseIdentity?.();\n\tif (identity === undefined) {\n\t\tawait checkHotSessionLinks(database, t, prefix);\n\t\treturn;\n\t}\n\tconst key = JSON.stringify([identity, schema.ledger, t.sessionLinks]);\n\tlet check = hotSessionLinksChecks.get(key);\n\tif (check === undefined) {\n\t\tconst made = checkHotSessionLinks(database, t, prefix);\n\t\tcheck = made;\n\t\thotSessionLinksChecks.set(key, made);\n\t\tconst forget = () => {\n\t\t\tif (hotSessionLinksChecks.get(key) === made) hotSessionLinksChecks.delete(key);\n\t\t};\n\t\tmade.then((settled) => {\n\t\t\tif (!settled) forget();\n\t\t}, forget);\n\t}\n\tawait check;\n}\n\n/**\n * The largest links table, in bytes, an open builds {@link hotSessionLinks}'s index for in its own transaction, which\n * holds the table's writes for the build: about 150,000 links, a fraction of a second. A larger one is left to `atomic\n * storage migrate`, which builds the index without holding them ({@link SqlSnapshotBlobStore.buildHotSessionLinksIndex}).\n */\nconst HOT_SESSION_LINKS_OPEN_BUILD_BYTES = 16 * 1024 * 1024;\n/** How often {@link SqlSnapshotBlobStore.buildHotSessionLinksIndex} looks again at an index build another process runs. */\nconst HOT_SESSION_LINKS_BUILD_POLL_MS = 500;\n\n/** What {@link sessionLinksState} finds of the links table. */\ninterface SessionLinksState {\n\treadonly owned: boolean;\n\treadonly bytes: number;\n\t/** Whether `_anchored` exists and is valid; `false` for one a build that did not finish left. */\n\treadonly anchored: boolean | undefined;\n\t/** Whether an index of the table is being built right now. */\n\treadonly building: boolean;\n}\n\n/** The links table's owner, size and `_anchored` index, in one read; `undefined` when the table does not exist. */\nasync function sessionLinksState(\n\tdatabase: SqliteExecutor,\n\tt: SnapshotIndexTables,\n\tdialect: StorageDialect,\n): Promise<SessionLinksState | undefined> {\n\tconst row = await database.get<\n\t\tSqliteRow & {\n\t\t\towned: boolean | number;\n\t\t\tbytes: number | string;\n\t\t\tanchored: boolean | number | null;\n\t\t\tbuilding: boolean | number;\n\t\t}\n\t>(\n\t\t`SELECT pg_catalog.pg_has_role(current_user, c.relowner, 'USAGE') AS owned, pg_catalog.pg_relation_size(c.oid) AS bytes,\n\t\t\t(SELECT x.indisvalid FROM pg_catalog.pg_index x JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid\n\t\t\t\tWHERE x.indrelid = c.oid AND i.relname = ?) AS anchored,\n\t\t\tEXISTS (SELECT 1 FROM pg_catalog.pg_stat_progress_create_index p WHERE p.relid = c.oid) AS building\n\t\tFROM pg_catalog.pg_class c WHERE c.relnamespace = current_schema()::regnamespace AND c.relname = ?`,\n\t\tdialect.identifier(`${t.sessionLinks}_anchored`),\n\t\tdialect.identifier(t.sessionLinks),\n\t);\n\tif (row === undefined) return undefined;\n\tconst yes = (value: boolean | number | null) => value === true || Number(value) === 1;\n\treturn {\n\t\towned: yes(row.owned),\n\t\tbytes: Number(row.bytes),\n\t\tanchored: row.anchored === null ? undefined : yes(row.anchored),\n\t\tbuilding: yes(row.building),\n\t};\n}\n\n/**\n * Runs {@link hotSessionLinks} where this role owns a small links table; true when this process need not check again.\n * A large table, or one whose `_anchored` index a build of `atomic storage migrate` left unfinished or is making now,\n * is left to `atomic storage migrate`.\n */\nasync function checkHotSessionLinks(\n\tdatabase: SqliteDatabase,\n\tt: SnapshotIndexTables,\n\tprefix: string,\n): Promise<boolean> {\n\tconst dialect = dialectOf(database);\n\tconst found = await sessionLinksState(database, t, dialect);\n\tif (found === undefined) return false;\n\tif (!found.owned || found.bytes > HOT_SESSION_LINKS_OPEN_BUILD_BYTES || found.anchored === false || found.building)\n\t\treturn true;\n\tawait database.transaction((transaction) => hotSessionLinks(transaction, t, prefix, dialect), {\n\t\tretryTransientFailures: true,\n\t\tconcurrency: { kind: \"serial\", domain: sessionLinksHotSchema(prefix).ledger },\n\t});\n\treturn false;\n}\n\n/** The columns of {@link SnapshotIndexTables.sessionRefs} that later builds added, with their types. */\nconst SESSION_REF_COLUMNS = [\"prev_seq\", \"restore_from\", \"restore_to\", \"degraded_from\", \"degraded_since\"] as const;\n\n/** Whether the session references have each of {@link SESSION_REF_COLUMNS}, in its order. */\nfunction sessionRefColumnProbes(transaction: SqliteExecutor, t: SnapshotIndexTables, dialect: StorageDialect) {\n\treturn SESSION_REF_COLUMNS.map((name) => {\n\t\tconst column = dialect.columnExists(t.sessionRefs, name);\n\t\treturn async () => (await transaction.get(column.sql, ...column.params)) !== undefined;\n\t});\n}\n\n/**\n * Adds the columns of the session references that an index written by an earlier build lacks, as\n * {@link sessionRefColumnProbes} found them. Adding any drops the session entries' triggers and marks their index for\n * a rebuild, which collection runs before it deletes anything.\n */\nfunction sessionRefColumnWrites(\n\tt: SnapshotIndexTables,\n\tprefix: string,\n\tdialect: StorageDialect,\n\tfound: readonly boolean[],\n): BatchWrite[] {\n\tconst { int, text } = dialect.types;\n\tconst types: Record<(typeof SESSION_REF_COLUMNS)[number], string> = {\n\t\tprev_seq: int,\n\t\trestore_from: text,\n\t\trestore_to: text,\n\t\tdegraded_from: text,\n\t\tdegraded_since: int,\n\t};\n\tconst missing = SESSION_REF_COLUMNS.filter((_, index) => found[index] !== true);\n\tif (missing.length === 0) return [];\n\t// Mark the tree-aware rebuild durably, but leave its old rows untouched until completeIndex runs.\n\tconst source = indexSources(prefix, t, dialect).find((source) => source.name === \"session-entries\")!;\n\treturn [\n\t\t...missing.map((name) => `ALTER TABLE ${t.sessionRefs} ADD COLUMN ${name} ${types[name]}`),\n\t\t...source.triggers.map((trigger) => dialect.dropTrigger(trigger.name, trigger.table)),\n\t\t{\n\t\t\tsql: `INSERT INTO ${t.sources} (source, watermark, backfilled_through) VALUES (?, -1, -1) ${REPLACE_PROGRESS}`,\n\t\t\tparams: [source.name],\n\t\t},\n\t];\n}\n\n/** Adds the columns of the session references that an index written by an earlier build lacks; see above. */\nasync function addSessionRefColumns(\n\ttransaction: SqliteExecutor,\n\tt: SnapshotIndexTables,\n\tprefix: string,\n\tdialect: StorageDialect,\n): Promise<void> {\n\tconst found = await statementBatch(transaction, [], sessionRefColumnProbes(transaction, t, dialect));\n\tawait statementBatch(transaction, sessionRefColumnWrites(t, prefix, dialect, found), []);\n}\n\n/** Replaces a source's progress row: `sources` has no triggers or references, so this upsert is what a REPLACE did. */\nconst REPLACE_PROGRESS =\n\t\"ON CONFLICT (source) DO UPDATE SET watermark = excluded.watermark, backfilled_through = excluded.backfilled_through\";\n\n/** Installs `source`'s index triggers and records that rows above its current last row are indexed by them. */\nasync function installSource(\n\ttransaction: SqliteExecutor,\n\tdialect: StorageDialect,\n\tt: SnapshotIndexTables,\n\tsource: IndexSource,\n\treset?: SessionIndexReset,\n): Promise<void> {\n\tconst detached =\n\t\tsource.name === \"session-entries\" &&\n\t\t(await reset?.(\n\t\t\ttransaction,\n\t\t\tt,\n\t\t\tsource.triggers.map((trigger) => trigger.name),\n\t\t));\n\tconst withholds = withholdsVersion(dialect, source);\n\tconst [installed] = await statementBatch(\n\t\ttransaction,\n\t\t[\n\t\t\t...(detached\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t...(source.reset ?? []).map((sql) => ({ sql, params: [] })),\n\t\t\t\t\t\t// Triggers of these names that an older build installed are replaced, not kept (#5065): dropped in one\n\t\t\t\t\t\t// script, as they are created, so a source with more triggers costs a driver no more calls.\n\t\t\t\t\t\tsource.triggers.length > 0 &&\n\t\t\t\t\t\t\tsource.triggers\n\t\t\t\t\t\t\t\t.map((trigger) => `${dialect.dropTrigger(trigger.name, trigger.table)};`)\n\t\t\t\t\t\t\t\t.join(\"\\n\"),\n\t\t\t\t\t]),\n\t\t\tsource.triggers.map((trigger) => dialect.renderTrigger(trigger)).join(\"\\n\"),\n\t\t\t{\n\t\t\t\tsql: `INSERT INTO ${t.sources} (source, watermark, backfilled_through) SELECT ?, COALESCE(MAX(${dialect.rowOrder()}), 0), 0 FROM ${source.table} WHERE true ${REPLACE_PROGRESS}`,\n\t\t\t\tparams: [source.name],\n\t\t\t},\n\t\t\tsource.own !== undefined && {\n\t\t\t\tsql: `INSERT INTO ${t.sources} (source, watermark, backfilled_through) SELECT ?, watermark, 0 FROM ${t.sources} WHERE source = ? ${REPLACE_PROGRESS}`,\n\t\t\t\tparams: [source.own, source.name],\n\t\t\t},\n\t\t\t{ sql: `DELETE FROM ${t.sources} WHERE source = ?`, params: [rebuildRow(source)] },\n\t\t\tsource.version !== undefined && !withholds && publishVersion(t, source),\n\t\t],\n\t\t// A table with no row yet is backfilled as it is installed; any other is published once its backfill is done.\n\t\tsource.version !== undefined && withholds\n\t\t\t? [\n\t\t\t\t\t() =>\n\t\t\t\t\t\ttransaction.get<SqliteRow & { watermark: number }>(\n\t\t\t\t\t\t\t`SELECT watermark FROM ${t.sources} WHERE source = ?`,\n\t\t\t\t\t\t\tsource.name,\n\t\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t: [],\n\t);\n\tif (source.version === undefined || !withholds) return;\n\tawait statementBatch(\n\t\ttransaction,\n\t\t[\n\t\t\tNumber(installed?.watermark) === 0\n\t\t\t\t? publishVersion(t, source)\n\t\t\t\t: { sql: `DELETE FROM ${t.sources} WHERE source = ?`, params: [source.version] },\n\t\t],\n\t\t[],\n\t);\n}\n\n/**\n * Whether this build writes `source`'s {@link IndexSource.version} row only once its own backfill of the source is done:\n * on SQLite, which builds before 0.9.88 also open (#5558).\n */\nfunction withholdsVersion(dialect: StorageDialect, source: IndexSource): boolean {\n\treturn dialect.name === \"sqlite\" && source.version !== undefined && source.own !== undefined;\n}\n\n/** The statement that writes `source`'s version row as this build's, its own backfill of the source being done (#5558). */\nfunction publishVersion(t: SnapshotIndexTables, source: IndexSource): SqliteStatement {\n\treturn {\n\t\tsql: `INSERT INTO ${t.sources} (source, watermark, backfilled_through) VALUES (?, ?, ?) ${REPLACE_PROGRESS}`,\n\t\tparams: [source.version!, PUBLISHED_VERSION, PUBLISHED_VERSION],\n\t};\n}\n\n/**\n * Installs the index triggers of every referencing table that exists and lacks them, except a source whose rebuild is\n * deferred to collection. Installing again replaces nothing, so the step can run any number of times.\n */\nasync function installMissingSources(\n\ttransaction: SqliteExecutor,\n\tt: SnapshotIndexTables,\n\tprefix: string,\n\tdialect: StorageDialect,\n\treset?: SessionIndexReset,\n): Promise<void> {\n\tfor (const { source, installed, deferred } of await readSourceStates(\n\t\ttransaction,\n\t\tdialect,\n\t\tt,\n\t\tindexSources(prefix, t, dialect),\n\t)) {\n\t\tif (!installed && !deferred) await installSource(transaction, dialect, t, source, reset);\n\t}\n}\n\n/** The names of `sources`' tables and triggers, whose presence `readSourceStates` reads. */\nfunction sourceObjectNames(sources: readonly IndexSource[]): string[] {\n\treturn sources.flatMap((source) => [source.table, ...source.triggers.map((trigger) => trigger.name)]);\n}\n\n/** The read of every source's progress rows. */\nfunction sourceProgressRead(t: SnapshotIndexTables): SqliteStatement {\n\treturn { sql: `SELECT source, watermark, backfilled_through FROM ${t.sources}`, params: [] };\n}\n\n/**\n * Which referencing tables exist, whether each has all its triggers and a source row, and whether its backfill is done.\n * `present`, when given, holds every table and trigger of `sources`, as an open's catalog found them: the objects are\n * not read then (#6560).\n */\nasync function readSourceStates(\n\texecutor: SqliteExecutor,\n\tdialect: StorageDialect,\n\tt: SnapshotIndexTables,\n\tsources: readonly IndexSource[],\n\tlistRetired = false,\n\tpresent?: ReadonlySet<string>,\n\talso?: { readonly names: readonly string[]; readonly found: Set<string> },\n): Promise<SourceState[]> {\n\t// `also` asks, in the same statement, which of other objects exist, as `also.found` tells.\n\tconst names = [...sourceObjectNames(sources), ...(also?.names ?? [])];\n\t// Builds before 0.9.88 open SQLite databases only, so only there can a trigger of this build's name be\n\t// one that indexes less.\n\tconst sqlite = dialect.name === \"sqlite\";\n\tconst signatures = sqlite ? sources.flatMap((source) => source.signature ?? []) : [];\n\tconst markers = sqlite\n\t\t? sources.flatMap((source) =>\n\t\t\t\tsource.marker === undefined\n\t\t\t\t\t? []\n\t\t\t\t\t: source.triggers.map((trigger) => ({ trigger: trigger.name, text: source.marker! })),\n\t\t\t)\n\t\t: [];\n\tconst holds = (checks: readonly { readonly trigger: string; readonly text: string }[]) =>\n\t\tchecks.length === 0 ? \"NULL\" : `CASE ${checks.map(() => \"WHEN name = ? THEN instr(sql, ?) > 0\").join(\" \")} END`;\n\tconst objects =\n\t\tsignatures.length + markers.length === 0\n\t\t\t? dialect.schemaObjects(names)\n\t\t\t: {\n\t\t\t\t\tsql: `SELECT name, ${holds(signatures)} AS signed, ${holds(markers)} AS marked FROM sqlite_schema WHERE name IN (${names.map(() => \"?\").join(\", \")})`,\n\t\t\t\t\tparams: [...signatures, ...markers].flatMap((check) => [check.trigger, check.text]).concat(names),\n\t\t\t\t};\n\tconst progressRead = sourceProgressRead(t);\n\ttype ObjectRow = SqliteRow & { name: string; signed?: number | null; marked?: number | null };\n\t// Read together: the progress rows do not depend on the objects.\n\tconst [objectRows, progressRows] = await statementBatch(\n\t\texecutor,\n\t\t[],\n\t\t[\n\t\t\t() =>\n\t\t\t\tpresent === undefined\n\t\t\t\t\t? executor.all<ObjectRow>(objects.sql, ...objects.params)\n\t\t\t\t\t: Promise.resolve(names.filter((name) => present.has(name)).map((name): ObjectRow => ({ name }))),\n\t\t\t() =>\n\t\t\t\texecutor.all<SqliteRow & { source: string; watermark: number; backfilled_through: number }>(\n\t\t\t\t\tprogressRead.sql,\n\t\t\t\t\t...progressRead.params,\n\t\t\t\t),\n\t\t],\n\t);\n\tconst found = new Set(objectRows.map((row) => row.name));\n\tfor (const name of also?.names ?? []) if (found.has(name)) also?.found.add(name);\n\t// Whether each checked trigger's SQL holds this build's text; every other object reads null.\n\tconst checked = (column: \"signed\" | \"marked\") =>\n\t\tnew Map(\n\t\t\tobjectRows\n\t\t\t\t.filter((row) => row[column] !== null && row[column] !== undefined)\n\t\t\t\t.map((row) => [row.name, Number(row[column]) === 1]),\n\t\t);\n\tconst signed = checked(\"signed\");\n\tconst marked = checked(\"marked\");\n\tlet retired: string[] | undefined;\n\tconst progress = new Map(\n\t\tprogressRows.map((row) => {\n\t\t\tif (\n\t\t\t\tlistRetired &&\n\t\t\t\tsqlite &&\n\t\t\t\trow.source.startsWith(SESSION_INDEX_RETIRED_PREFIX) &&\n\t\t\t\tNumber(row.backfilled_through) === 0\n\t\t\t) {\n\t\t\t\tretired ??= [];\n\t\t\t\tretired.push(row.source);\n\t\t\t}\n\t\t\treturn [row.source, row] as const;\n\t\t}),\n\t);\n\treturn sources\n\t\t.filter((source) => found.has(source.table))\n\t\t.map((source) => {\n\t\t\tconst row = progress.get(source.name);\n\t\t\tconst version = source.version === undefined ? undefined : progress.get(source.version);\n\t\t\tconst own = source.own === undefined ? undefined : progress.get(source.own);\n\t\t\tconst ownDone =\n\t\t\t\town !== undefined && row !== undefined && Number(own.backfilled_through) >= Number(row.watermark);\n\t\t\t// An index an older build installed while a rebuild row was there, which 0.9.87 may have indexed since (#5558).\n\t\t\tconst reinstalled = row !== undefined && progress.has(rebuildRow(source));\n\t\t\t// On SQLite, a reference trigger without this build's text is a build's before 0.9.88, installed after this\n\t\t\t// build's went missing (#5558).\n\t\t\tconst unsigned = source.signature !== undefined && signed.get(source.signature.trigger) === false;\n\t\t\t// Every trigger the source has is this build's. One a build before 0.9.88 installed again after it went\n\t\t\t// missing is not, even when its SQL is the same in every build otherwise (#5558).\n\t\t\tconst mine =\n\t\t\t\tsource.marker !== undefined &&\n\t\t\t\tsource.triggers.every((trigger) => !found.has(trigger.name) || marked.get(trigger.name) === true);\n\t\t\tlet foreign: boolean;\n\t\t\t// Whether the backfill is done for this build, besides the source's own progress row.\n\t\t\tlet trusted: boolean;\n\t\t\tif (withholdsVersion(dialect, source)) {\n\t\t\t\t// This build's install whose backfill is not done yet, which holds back the version row (#5558).\n\t\t\t\tconst pending = version === undefined && own !== undefined && mine;\n\t\t\t\t// A row of 0 is a build of 0.9.88 or 0.9.89's, whose finished backfill indexed what this build's does, unless\n\t\t\t\t// it installed the index while a rebuild row was there: this build takes it over then. This build publishes\n\t\t\t\t// its own once its own progress reaches the watermark, which it must still hold.\n\t\t\t\tconst published = version !== undefined && Number(version.watermark) === PUBLISHED_VERSION;\n\t\t\t\tforeign = unsigned || (version === undefined && !pending) || (published && !mine);\n\t\t\t\ttrusted = published ? ownDone : version !== undefined && !reinstalled;\n\t\t\t} else {\n\t\t\t\t// A source whose triggers an older build installed is indexed again by collection, as after an upgrade.\n\t\t\t\tforeign = unsigned || (source.version !== undefined && version === undefined) || reinstalled;\n\t\t\t\t// Rows an older build indexed with its statements past this build's own progress are not backfilled.\n\t\t\t\ttrusted = own === undefined || ownDone;\n\t\t\t}\n\t\t\tconst installed =\n\t\t\t\trow !== undefined &&\n\t\t\t\t!foreign &&\n\t\t\t\tNumber(row.watermark) >= 0 &&\n\t\t\t\tsource.triggers.every((trigger) => found.has(trigger.name));\n\t\t\tconst backfilled =\n\t\t\t\trow !== undefined &&\n\t\t\t\t!foreign &&\n\t\t\t\ttrusted &&\n\t\t\t\tNumber(row.watermark) >= 0 &&\n\t\t\t\tNumber(row.backfilled_through) >= Number(row.watermark);\n\t\t\treturn {\n\t\t\t\tsource,\n\t\t\t\tinstalled,\n\t\t\t\tbackfilled,\n\t\t\t\tdeferred: row !== undefined && (foreign || Number(row.watermark) === -1),\n\t\t\t\tforeign,\n\t\t\t\ttakeover: withholdsVersion(dialect, source) && installed && version !== undefined && !backfilled,\n\t\t\t\t...(retired && source.name === \"session-entries\" ? { retired } : {}),\n\t\t\t};\n\t\t});\n}\n\n/**\n * The `<prefix>snapshot_blobs` table and its reference index, shared by the session stores of one database. The index\n * also counts the references a workflow run journal of an earlier release holds in the same database, so collection\n * never deletes a blob such a run still needs.\n */\nexport class SqlSnapshotBlobStore implements SnapshotBlobStore {\n\tprivate readonly database: SqliteDatabase;\n\tprivate readonly tables: SnapshotIndexTables;\n\tprivate sources: readonly IndexSource[];\n\tprivate readonly dialect: StorageDialect;\n\t/** The sessions' fork segments table (#6560), which exists once shared-history forks are on. */\n\tprivate readonly forkSegments: string;\n\treadonly table: string;\n\n\tprivate constructor(\n\t\tdatabase: SqliteDatabase,\n\t\tdialect: StorageDialect,\n\t\ttables: SnapshotIndexTables,\n\t\tsources: readonly IndexSource[],\n\t\tforkSegments = forkSegmentsTable(),\n\t) {\n\t\tthis.database = database;\n\t\tthis.dialect = dialect;\n\t\tthis.tables = tables;\n\t\tthis.sources = sources;\n\t\tthis.forkSegments = forkSegments;\n\t\tthis.table = tables.blobs;\n\t}\n\n\t/** Which table this store collects, for telling stores of one database and prefix apart from others. */\n\tget identity(): string {\n\t\treturn `${databaseIdentity(this.database.descriptor)}${this.table}`;\n\t}\n\n\t/**\n\t * Opens the blob table and its reference index, creating the tables that are missing in their own transaction, such\n\t * as those an index written by an earlier build lacks, and indexes referencing tables created since. A store whose\n\t * tables and index exist opens without the write lock. On SQLite inside an open scope (`withStorageSchemaCatalog`),\n\t * table creation and index installation queue into the open's single write transaction (#6709).\n\t */\n\tstatic open(database: SqliteDatabase, prefix = \"\"): Promise<SqlSnapshotBlobStore> {\n\t\treturn withStorageSchemaCatalog(database, storageMigrationTable(prefix), () =>\n\t\t\tSqlSnapshotBlobStore.openWithCatalog(database, prefix),\n\t\t);\n\t}\n\n\tprivate static async openWithCatalog(database: SqliteDatabase, prefix: string): Promise<SqlSnapshotBlobStore> {\n\t\tconst t = snapshotIndexTables(prefix);\n\t\tconst dialect = dialectOf(database);\n\t\tconst ledger = storageMigrationTable(prefix);\n\t\tconst columns = [\n\t\t\t[t.blobs, \"created_at\"],\n\t\t\t[t.blobs, \"chunks\"],\n\t\t\t...SESSION_REF_COLUMNS.map((column) => [t.sessionRefs, column] as const),\n\t\t] as const;\n\t\tconst triggers = [`${t.blobs}_chunks_delete_all`, `${t.blobs}_chunks_delete`];\n\t\tconst probes = [\n\t\t\t...Object.values(t).map((table) => dialect.tableExists(table)),\n\t\t\t...columns.map(([table, column]) => dialect.columnExists(table, column)),\n\t\t\tdialect.schemaObjects(triggers),\n\t\t];\n\t\tconst tablesPresent = (found: StorageSchemaCatalog) =>\n\t\t\tObject.values(t).every((table) => found.hasTable(table)) &&\n\t\t\tcolumns.every(([table, column]) => found.hasColumn(table, column)) &&\n\t\t\ttriggers.some((trigger) => found.hasObject(trigger));\n\t\t// One catalog read answers the schema questions where an open read it (#6560): always on Postgres, at the first\n\t\t// question on SQLite.\n\t\tconst catalog = await schemaCatalogOf(database);\n\t\t// Whether shared-history forks are on (#6560), from that catalog or asked beside the probes.\n\t\tconst segments = forkSegmentsTable(prefix);\n\t\tconst segmentsProbe = dialect.tableExists(segments);\n\t\tconst shared =\n\t\t\tcatalog !== undefined\n\t\t\t\t? Promise.resolve(catalog.hasTable(segments))\n\t\t\t\t: database.get(segmentsProbe.sql, ...segmentsProbe.params).then((row) => row !== undefined);\n\t\tshared.catch(() => {});\n\t\t// A versioned database checks its ledger whatever the probes find, so it does not ask them. Elsewhere the catalog\n\t\t// answers them all, in one read instead of a read each.\n\t\tconst current = dialect.versionedMigrations\n\t\t\t? false\n\t\t\t: catalog !== undefined\n\t\t\t\t? tablesPresent(catalog)\n\t\t\t\t: (await Promise.all(probes.map((probe) => database.get(probe.sql, ...probe.params)))).every(\n\t\t\t\t\t\t(row) => row !== undefined,\n\t\t\t\t\t);\n\n\t\t// On SQLite inside an open scope, when the snapshot tables are missing or incomplete, queue both table creation\n\t\t// and source index trigger installation into the open's single write transaction without reading uncommitted tables\n\t\t// beforehand (#6709).\n\t\tif (!current && !dialect.versionedMigrations && catalog !== undefined) {\n\t\t\tconst needsReset =\n\t\t\t\tcatalog.hasTable(t.sessionLinks) || catalog.hasTable(t.sessionRefs) || catalog.hasTable(t.sessionRecords);\n\t\t\tconst reset = needsReset ? await SqlSnapshotBlobStore.prepareSessionIndexReset(database) : undefined;\n\t\t\tconst store = new SqlSnapshotBlobStore(\n\t\t\t\tdatabase,\n\t\t\t\tdialect,\n\t\t\t\tt,\n\t\t\t\tindexSources(prefix, t, dialect, (await shared) ? segments : undefined),\n\t\t\t\tsegments,\n\t\t\t);\n\t\t\tconst enqueueFreshTables = (ctx: SqliteSchemaBatchContext, sharedNow: boolean) => {\n\t\t\t\tconst { int, text, blob } = dialect.types;\n\t\t\t\tconst strict = dialect.tableOptions;\n\t\t\t\tconst keyed = dialect.withoutRowidTableOptions;\n\t\t\t\tconst guard = sharedNow ? [forkInheritedBlobGuard(dialect, t, segments).replace(/;\\s*$/, \"\")] : [];\n\t\t\t\tctx.enqueue(\n\t\t\t\t\t`CREATE TABLE IF NOT EXISTS ${t.blobs} (hash ${text} PRIMARY KEY, bytes ${int} NOT NULL, data ${blob} NOT NULL, created_at ${int} NOT NULL DEFAULT (${dialect.nowSeconds}))${strict}`,\n\t\t\t\t);\n\t\t\t\tctx.enqueue(`\n\t\tCREATE TABLE IF NOT EXISTS ${t.runRefs} (run_id ${text} NOT NULL, hash ${text} NOT NULL, PRIMARY KEY (run_id, hash))${keyed};\n\t\tCREATE INDEX IF NOT EXISTS ${t.runRefs}_hash ON ${t.runRefs} (hash);\n\t\tCREATE TABLE IF NOT EXISTS ${t.runState} (run_id ${text} PRIMARY KEY, retained ${int} NOT NULL, seq ${int} NOT NULL)${keyed};\n\t\tCREATE TABLE IF NOT EXISTS ${t.sessionRefs} (session_id ${text} NOT NULL, seq ${int} NOT NULL, root ${text} NOT NULL, snapshot_id ${text} NOT NULL, prev_seq ${int}, restore_from ${text}, restore_to ${text}, degraded_from ${text}, degraded_since ${int}, PRIMARY KEY (session_id, seq))${keyed};\n\t\tCREATE TABLE IF NOT EXISTS ${t.sessionLinks} (session_id ${text} NOT NULL, seq ${int} NOT NULL, entry_id ${text} NOT NULL, parent_id ${text}, anchor_seq ${int}, children ${int} NOT NULL, broken ${int} NOT NULL, PRIMARY KEY (session_id, seq))${strict};\n\t\tCREATE INDEX IF NOT EXISTS ${t.sessionLinks}_entry ON ${t.sessionLinks} (session_id, entry_id);\n\t\t${sessionLinksLeafIndex(t, dialect)};\n\t\tCREATE INDEX IF NOT EXISTS ${t.sessionLinks}_broken ON ${t.sessionLinks} (session_id) WHERE broken = 1;\n\t\tCREATE TABLE IF NOT EXISTS ${t.sessionRecords} (session_id ${text} NOT NULL, seq ${int} NOT NULL, snapshot_id ${text} NOT NULL, hash ${text} NOT NULL, PRIMARY KEY (session_id, seq, hash))${keyed};\n\t\tCREATE INDEX IF NOT EXISTS ${t.sessionRecords}_hash ON ${t.sessionRecords} (hash);\n\t\tCREATE TABLE IF NOT EXISTS ${t.carriedRefs} (owner ${text} NOT NULL, hash ${text} NOT NULL, PRIMARY KEY (owner, hash))${keyed};\n\t\tCREATE INDEX IF NOT EXISTS ${t.carriedRefs}_hash ON ${t.carriedRefs} (hash);\n\t\tCREATE TABLE IF NOT EXISTS ${t.collection} (id ${int} PRIMARY KEY CHECK (id = 1), claimed_at ${int}, holder ${text}, finished_at ${int}, deleted ${int}, error_code ${text})${strict};\n\t\tINSERT INTO ${t.collection} (id) VALUES (1) ON CONFLICT DO NOTHING;\n\t\tCREATE TABLE IF NOT EXISTS ${t.sources} (source ${text} PRIMARY KEY, watermark ${int} NOT NULL, backfilled_through ${int} NOT NULL)${keyed};\n\t\t${guard.map((statement) => `${statement};`).join(\"\\n\")}\n\t`);\n\t\t\t\tctx.enqueue(chunkTableDefinition(t.blobChunks, dialect));\n\t\t\t\tfor (const write of [...blobChunkWrites(t, dialect, [false, false]), ...blobMaintenanceIndexes(t)]) {\n\t\t\t\t\tif (write !== false && write !== undefined) ctx.enqueue(write);\n\t\t\t\t}\n\t\t\t\tfor (const table of Object.values(t)) ctx.noteTableCreated(table);\n\t\t\t};\n\t\t\tconst queued = queueSqliteSchemaSetup(database, ledger, {\n\t\t\t\tdone: async (freshCatalog) => {\n\t\t\t\t\tif (!tablesPresent(freshCatalog)) return false;\n\t\t\t\t\tconst sharedNow = freshCatalog.hasTable(segments);\n\t\t\t\t\tif (sharedNow && !freshCatalog.hasObject(forkInheritedBlobGuardName(t.blobs))) return false;\n\t\t\t\t\tconst sourcesNow = indexSources(prefix, t, dialect, sharedNow ? segments : undefined);\n\t\t\t\t\tconst legacy = store.legacyForkLinks();\n\t\t\t\t\tconst foundLegacy = new Set<string>();\n\t\t\t\t\tconst states = await readSourceStates(\n\t\t\t\t\t\tdatabase,\n\t\t\t\t\t\tdialect,\n\t\t\t\t\t\tt,\n\t\t\t\t\t\tsourcesNow,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tlegacy && { names: [legacy.name], found: foundLegacy },\n\t\t\t\t\t);\n\t\t\t\t\tif (legacy !== undefined && foundLegacy.has(legacy.name)) return false;\n\t\t\t\t\tif (states.some((state) => !state.installed && !state.deferred)) return false;\n\t\t\t\t\tstore.sources = sourcesNow;\n\t\t\t\t\treturn true;\n\t\t\t\t},\n\t\t\t\trun: async (ctx) => {\n\t\t\t\t\tconst sharedNow = ctx.tableExisted(segments) || ctx.createdTable(segments);\n\t\t\t\t\tstore.sources = indexSources(prefix, t, dialect, sharedNow ? segments : undefined);\n\t\t\t\t\tconst anyTableExisted = Object.values(t).some((table) => ctx.tableExisted(table));\n\t\t\t\t\tconst tablesAlreadyCurrent = ctx.catalog !== undefined && tablesPresent(ctx.catalog);\n\t\t\t\t\tconst guardName = forkInheritedBlobGuardName(t.blobs);\n\t\t\t\t\tif (!tablesAlreadyCurrent) {\n\t\t\t\t\t\tif (ctx.catalog !== undefined && !anyTableExisted) {\n\t\t\t\t\t\t\tenqueueFreshTables(ctx, sharedNow);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tawait ctx.flushWrites();\n\t\t\t\t\t\t\tawait createSnapshotIndexTables(\n\t\t\t\t\t\t\t\tctx.tx,\n\t\t\t\t\t\t\t\tt,\n\t\t\t\t\t\t\t\tprefix,\n\t\t\t\t\t\t\t\tdialect,\n\t\t\t\t\t\t\t\tsharedNow ? [forkInheritedBlobGuard(dialect, t, segments).replace(/;\\s*$/, \"\")] : [],\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tfor (const table of Object.values(t)) ctx.noteTableCreated(table);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (sharedNow && ctx.catalog?.hasObject(guardName) !== true) {\n\t\t\t\t\t\tctx.enqueue(forkInheritedBlobGuard(dialect, t, segments));\n\t\t\t\t\t}\n\t\t\t\t\t// Install snapshot index triggers in the same transaction. When no referencing table or progress table\n\t\t\t\t\t// existed before this transaction, only newly created tables (empty, watermark 0) need triggers.\n\t\t\t\t\tconst existingSources = store.sources.filter((source) => ctx.tableExisted(source.table));\n\t\t\t\t\tif (!ctx.tableExisted(t.sources) && existingSources.length === 0) {\n\t\t\t\t\t\tfor (const source of store.sources) {\n\t\t\t\t\t\t\tif (!ctx.createdTable(source.table)) continue;\n\t\t\t\t\t\t\tctx.enqueue(source.triggers.map((trigger) => dialect.renderTrigger(trigger)).join(\"\\n\"));\n\t\t\t\t\t\t\tctx.enqueue({\n\t\t\t\t\t\t\t\tsql: `INSERT INTO ${t.sources} (source, watermark, backfilled_through) VALUES (?, 0, 0) ${REPLACE_PROGRESS}`,\n\t\t\t\t\t\t\t\tparams: [source.name],\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (source.own !== undefined)\n\t\t\t\t\t\t\t\tctx.enqueue({\n\t\t\t\t\t\t\t\t\tsql: `INSERT INTO ${t.sources} (source, watermark, backfilled_through) VALUES (?, 0, 0) ${REPLACE_PROGRESS}`,\n\t\t\t\t\t\t\t\t\tparams: [source.own],\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (source.version !== undefined) ctx.enqueue(publishVersion(t, source));\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tawait ctx.flushWrites();\n\t\t\t\t\tconst legacy = store.legacyForkLinks();\n\t\t\t\t\tconst foundLegacy = new Set<string>();\n\t\t\t\t\tconst states = await readSourceStates(\n\t\t\t\t\t\tctx.tx,\n\t\t\t\t\t\tdialect,\n\t\t\t\t\t\tt,\n\t\t\t\t\t\tstore.sources,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tlegacy && { names: [legacy.name], found: foundLegacy },\n\t\t\t\t\t);\n\t\t\t\t\tif (legacy !== undefined && foundLegacy.has(legacy.name))\n\t\t\t\t\t\tawait ctx.tx.exec(dialect.dropTrigger(legacy.name, legacy.table, true));\n\t\t\t\t\tfor (const { source, installed, deferred } of states) {\n\t\t\t\t\t\tif (!installed && !deferred) await installSource(ctx.tx, dialect, t, source, reset);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t});\n\t\t\tif (queued) return store;\n\t\t}\n\n\t\t// A versioned database always checks its ledger: a newer schema with the same tables is refused, and a step it\n\t\t// lacks, such as the index triggers, runs even when every table exists.\n\t\t// Whether this open created the tables on PostgreSQL, and with them the links indexes of {@link hotSessionLinks}.\n\t\tlet linksHot = false;\n\t\tif (!current) {\n\t\t\tconst migrated = await applyStorageMigrations(\n\t\t\t\tdatabase,\n\t\t\t\tSNAPSHOT_BLOB_DOMAIN,\n\t\t\t\t[\n\t\t\t\t\t{\n\t\t\t\t\t\tversion: 1,\n\t\t\t\t\t\tup: async (transaction, dialect) => {\n\t\t\t\t\t\t\t// On PostgreSQL the tables come with the links index of {@link hotSessionLinks}, without one an\n\t\t\t\t\t\t\t// earlier build made, recorded in the ledger in the same request: a new database takes no extra\n\t\t\t\t\t\t\t// round trip for it. Where forks share history, as a new database's do from its first open, the\n\t\t\t\t\t\t\t// guard that keeps what they inherit comes with them in that request too (fork-blob-guard.ts).\n\t\t\t\t\t\t\tconst hot = dialect.name === \"postgres\";\n\t\t\t\t\t\t\tawait createSnapshotIndexTables(transaction, t, prefix, dialect, [\n\t\t\t\t\t\t\t\t...(hot\n\t\t\t\t\t\t\t\t\t? [`DROP INDEX IF EXISTS ${t.sessionLinks}_leaves`, hotSessionLinksRecord(prefix, dialect)]\n\t\t\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t\t\t...((await shared) ? [forkInheritedBlobGuard(dialect, t, segments).replace(/;\\s*$/, \"\")] : []),\n\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t\tlinksHot = hot;\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t// Where a ledger records the steps, it records the index triggers too, installed under the migration lock.\n\t\t\t\t\t// Without one, installIndex below installs each source in a transaction of its own, as it always has.\n\t\t\t\t\t...(dialect.versionedMigrations\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tversion: 2,\n\t\t\t\t\t\t\t\t\tup: (transaction: SqliteExecutor, dialect: StorageDialect) =>\n\t\t\t\t\t\t\t\t\t\tinstallMissingSources(transaction, t, prefix, dialect),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t// The pins of partly restored worktrees (#4922); SQLite adds them in step 1, which runs every time.\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tversion: 3,\n\t\t\t\t\t\t\t\t\tup: (transaction: SqliteExecutor, dialect: StorageDialect) =>\n\t\t\t\t\t\t\t\t\t\taddSessionRefColumns(transaction, t, prefix, dialect),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t// Chunked blobs (#4954); SQLite adds them in step 1, which runs every time.\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tversion: 4,\n\t\t\t\t\t\t\t\t\tup: (transaction: SqliteExecutor, dialect: StorageDialect) =>\n\t\t\t\t\t\t\t\t\t\taddBlobChunks(transaction, t, dialect),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tversion: 5,\n\t\t\t\t\t\t\t\t\tup: async (transaction: SqliteExecutor, dialect: StorageDialect) => {\n\t\t\t\t\t\t\t\t\t\tawait addBlobChunks(transaction, t, dialect);\n\t\t\t\t\t\t\t\t\t\tawait addBlobMaintenanceIndexes(transaction, t);\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: []),\n\t\t\t\t],\n\t\t\t\t{ table: ledger },\n\t\t\t);\n\t\t\t// The session store's open, which asks the catalog for the guard next, finds it without reading the schema again.\n\t\t\tif (migrated.applied.includes(1) && (await shared))\n\t\t\t\tnoteStorageSchemaTables(database, [forkInheritedBlobGuardName(t.blobs)]);\n\t\t}\n\t\tif (!linksHot) await ensureHotSessionLinks(database, t, prefix);\n\t\tconst store = new SqlSnapshotBlobStore(\n\t\t\tdatabase,\n\t\t\tdialect,\n\t\t\tt,\n\t\t\tindexSources(prefix, t, dialect, (await shared) ? segments : undefined),\n\t\t\tsegments,\n\t\t);\n\t\tawait store.installIndex(undefined, false, await schemaCatalogOf(database));\n\t\treturn store;\n\t}\n\n\t/**\n\t * Gives a PostgreSQL database's session links the index of {@link hotSessionLinks} without holding the table's writes,\n\t * as `atomic storage migrate` does where an open would not ({@link HOT_SESSION_LINKS_OPEN_BUILD_BYTES}). Each step\n\t * runs on its own, outside a transaction: `CREATE INDEX CONCURRENTLY` builds `_anchored`, `DROP INDEX CONCURRENTLY`\n\t * removes `_leaves`, and only then does the ledger record the step. A build that stopped part way, which leaves an\n\t * invalid `_anchored`, is dropped and made again; one another process is making is waited for. Nothing runs where the\n\t * ledger records the step, where the table does not exist yet (its first open creates it with the index), or where\n\t * this role does not own it. `database` should allow a statement as long as the build takes.\n\t */\n\tstatic async buildHotSessionLinksIndex(\n\t\tdatabase: SqliteDatabase,\n\t\tprefix = \"\",\n\t): Promise<\"built\" | \"current\" | \"absent\" | \"not-owner\"> {\n\t\tconst dialect = dialectOf(database);\n\t\tif (dialect.name !== \"postgres\") return \"current\";\n\t\tconst t = snapshotIndexTables(prefix);\n\t\tconst schema = sessionLinksHotSchema(prefix);\n\t\tconst recorded = async () => {\n\t\t\tconst ledger = dialect.tableExists(schema.ledger);\n\t\t\tif ((await database.get(ledger.sql, ...ledger.params)) === undefined) return false;\n\t\t\treturn (\n\t\t\t\t(await database.get(\n\t\t\t\t\t`SELECT 1 AS found FROM ${schema.ledger} WHERE domain = ? AND version >= ?`,\n\t\t\t\t\t`schema:${schema.domain}`,\n\t\t\t\t\tschema.revision,\n\t\t\t\t)) !== undefined\n\t\t\t);\n\t\t};\n\t\tif (await recorded()) return \"current\";\n\t\tfor (;;) {\n\t\t\tconst found = await sessionLinksState(database, t, dialect);\n\t\t\tif (found === undefined) return \"absent\";\n\t\t\tif (!found.owned) return \"not-owner\";\n\t\t\tif (found.building) {\n\t\t\t\t// Another process builds an index of the table, perhaps this one: its outcome decides what is left to do.\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, HOT_SESSION_LINKS_BUILD_POLL_MS));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (found.anchored === false)\n\t\t\t\tawait database.exec(`DROP INDEX CONCURRENTLY IF EXISTS ${t.sessionLinks}_anchored`);\n\t\t\tif (found.anchored !== true)\n\t\t\t\tawait database.exec(sessionLinksLeafIndex(t, dialect).replace(\"CREATE INDEX\", \"CREATE INDEX CONCURRENTLY\"));\n\t\t\tbreak;\n\t\t}\n\t\tawait database.exec(`DROP INDEX CONCURRENTLY IF EXISTS ${t.sessionLinks}_leaves`);\n\t\t// The index is in place, so the record runs no DDL, which would wait for the table's writes.\n\t\tawait database.transaction((transaction) => ensureStorageSchema(transaction, dialect, schema, async () => {}), {\n\t\t\tretryTransientFailures: true,\n\t\t\tconcurrency: { kind: \"serial\", domain: schema.ledger },\n\t\t});\n\t\treturn \"built\";\n\t}\n\n\t/** Runs only layout maintenance on the offline command's dedicated, exclusively locked SQLite file connection. */\n\tstatic async moveChunksOffline(file: string, prefix = \"\"): Promise<void> {\n\t\tconst tables = snapshotIndexTables(prefix);\n\t\tconst { withOfflineSnapshotFile } = await import(\"../storage/offline-snapshot-file.js\");\n\t\tawait withOfflineSnapshotFile(file, async (database) => {\n\t\t\tconst store = new SqlSnapshotBlobStore(database, dialectOf(database), tables, []);\n\t\t\tawait store.checkOfflineLayout();\n\t\t\tawait store.moveChunksToRowTable({ graceSeconds: 0 }, true);\n\t\t});\n\t}\n\n\t/** Don't rename away a custom index or view, or run extra triggers outside the offline batch's space budget. */\n\tprivate async checkOfflineLayout(): Promise<void> {\n\t\tconst t = this.tables;\n\t\tconst { next, retired } = chunkMoveTables(t);\n\t\tconst erase = chunksDeleteTrigger(t);\n\t\tconst conditional = { ...erase, name: `${t.blobs}_chunks_delete`, when: \"OLD.chunks > 0\" };\n\t\t// sqlite_schema elides IF NOT EXISTS and the final semicolon; RENAME quotes the new table name.\n\t\tconst stored = (sql: string) => sql.replace(\" IF NOT EXISTS\", \"\").replace(/;$/, \"\");\n\t\tconst layouts = [t.blobChunks, next, retired].flatMap((name) => {\n\t\t\tconst row = stored(chunkTableDefinition(name, this.dialect));\n\t\t\treturn [row, row.replace(`TABLE ${name} `, `TABLE \"${name}\" `)].flatMap((definition) => {\n\t\t\t\tconst legacy = `${definition}, WITHOUT ROWID`;\n\t\t\t\treturn name === next ? [definition] : name === retired ? [legacy] : [definition, legacy];\n\t\t\t});\n\t\t});\n\t\tconst current = stored(this.dialect.renderTrigger(erase));\n\t\tconst expected = new Set([...layouts, current, stored(this.dialect.renderTrigger(conditional))]);\n\t\tconst objects = await this.database.all<SqliteRow & { name: string; sql: string }>(\n\t\t\t\"SELECT name, sql FROM sqlite_schema WHERE sql IS NOT NULL AND (instr(lower(sql), lower(?)) > 0 OR name IN (?, ?))\",\n\t\t\tt.blobChunks,\n\t\t\terase.name,\n\t\t\tconditional.name,\n\t\t);\n\t\tif (!objects.some((row) => row.name === t.blobChunks) || !objects.some((row) => row.sql === current))\n\t\t\tthrow new Error(`No standard Atomic snapshot chunk store found for table ${t.blobs}.`);\n\t\tfor (const row of objects)\n\t\t\tif (!expected.has(row.sql))\n\t\t\t\tthrow new Error(`Cannot move a customized snapshot chunk layout offline (${row.name}).`);\n\t}\n\n\t/** Another file on this volume may have grown since admission. Check outside the write transaction, including during retirement. */\n\tprivate async requireOfflineBatchSpace(): Promise<void> {\n\t\tconst free = await this.database.freeBytes?.();\n\t\tif (free === undefined || free < SNAPSHOT_CHUNK_MOVE_HEADROOM_BYTES + OFFLINE_CHUNK_LOG_ALLOWANCE)\n\t\t\tthrow new Error(\"Not enough free space for another offline chunk batch and the 64 MiB reserve.\");\n\t}\n\n\t/** The exclusive connection is the only WAL writer. Never start a second batch on a nonempty log. */\n\tprivate async checkpointChunkMove(): Promise<void> {\n\t\tconst row = await this.database.get(\"PRAGMA wal_checkpoint(TRUNCATE)\");\n\t\tif (row?.busy !== 0 || row.log !== 0)\n\t\t\tthrow new Error(\"Could not truncate the offline chunk move's write-ahead log.\");\n\t}\n\n\t/** A transcript-only handle has no snapshot sources to index. Binding it must not even inspect their tables. */\n\tstatic forTranscriptReader(database: SqliteDatabase & { readonly readOnly: true }): SqlSnapshotBlobStore {\n\t\treturn new SqlSnapshotBlobStore(database, dialectOf(database), snapshotIndexTables(), []);\n\t}\n\n\t/**\n\t * Creates the blob table and its reference index inside the caller's transaction, and indexes the referencing tables\n\t * that exist, so a store that creates its own tables takes the write lock once for all of them.\n\t */\n\tstatic async initialize(\n\t\ttransaction: SqliteExecutor,\n\t\tprefix = \"\",\n\t\tdialect: StorageDialect,\n\t\treset?: SessionIndexReset,\n\t): Promise<void> {\n\t\tconst t = snapshotIndexTables(prefix);\n\t\tawait createSnapshotIndexTables(transaction, t, prefix, dialect);\n\t\tawait installMissingSources(transaction, t, prefix, dialect, reset);\n\t}\n\n\t/** @internal Resolve the space reading and load migration code before taking SQLite's writer lock. */\n\tstatic async prepareSessionIndexReset(database: SqliteDatabase): Promise<SessionIndexReset | undefined> {\n\t\tif (dialectOf(database).name !== \"sqlite\") return undefined;\n\t\tconst available = await database.freeBytes?.().catch(() => undefined);\n\t\tif (available === undefined) return undefined;\n\t\tconst { detachSessionIndex } = await import(\"./session-index-reset.js\");\n\t\treturn (tx, tables, triggers) => detachSessionIndex(tx, tables, triggers, available);\n\t}\n\n\t/**\n\t * Stores every blob, in one transaction, or restarts the age of one stored already. A blob larger than\n\t * {@link SNAPSHOT_BLOB_CHUNK_BYTES} is stored as chunk rows and a header row that names how many, so no statement\n\t * binds more than one chunk (#4954); the chunks of a blob stored already are not written again. Unknown ages\n\t * remain protected until collection stamps them.\n\t */\n\tasync putBlobs(unordered: readonly SnapshotBlob[]): Promise<void> {\n\t\tif (unordered.length === 0) return;\n\t\t// In hash order, so the rows it locks are taken in the order every other write of them takes them.\n\t\tconst blobs = [...unordered].sort((first, second) => byteOrder(first.hash, second.hash));\n\t\tconst now = this.dialect.nowSeconds;\n\t\tconst header = `INSERT INTO ${this.table} (hash, bytes, data, created_at, chunks) VALUES (?, ?, ?, ${now}, ?) ON CONFLICT(hash) DO UPDATE SET created_at = ${now} WHERE ${this.table}.created_at > 0`;\n\t\tconst chunk = `INSERT INTO ${this.tables.blobChunks} (hash, idx, data) SELECT ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM ${this.table} WHERE hash = ?) ON CONFLICT DO NOTHING`;\n\t\tconst statements: { sql: string; params: SqliteValue[] }[] = [];\n\t\tlet chunked = false;\n\t\tlet totalBytes = 0;\n\t\tfor (const blob of blobs) {\n\t\t\tconst { hash, data } = blob;\n\t\t\ttotalBytes += data.byteLength;\n\t\t\tif (data.byteLength <= SNAPSHOT_BLOB_CHUNK_BYTES) {\n\t\t\t\tstatements.push({ sql: header, params: [hash, data.byteLength, data, 0] });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst chunks = Math.ceil(data.byteLength / SNAPSHOT_BLOB_CHUNK_BYTES);\n\t\t\tchunked = true;\n\t\t\tfor (let index = 0; index < chunks; index++) {\n\t\t\t\tconst bytes = data.subarray(index * SNAPSHOT_BLOB_CHUNK_BYTES, (index + 1) * SNAPSHOT_BLOB_CHUNK_BYTES);\n\t\t\t\tstatements.push({ sql: chunk, params: [hash, index, bytes, hash] });\n\t\t\t}\n\t\t\tstatements.push({ sql: header, params: [hash, data.byteLength, new Uint8Array(), chunks] });\n\t\t}\n\t\tif (!chunked && this.database.batch) {\n\t\t\tawait this.database.batch(statements);\n\t\t\treturn;\n\t\t}\n\t\tconst lead = statements.length < MAX_SEQUENCE_REQUEST_STATEMENTS && totalBytes <= SNAPSHOT_BLOB_CHUNK_BYTES;\n\t\tawait this.database.transaction(\n\t\t\tasync (transaction) => {\n\t\t\t\t// On a pipelined connection the statements go out with the commit: one round trip after the locks.\n\t\t\t\tif (transactionFinisher(transaction)?.(statements) === true) return;\n\t\t\t\tfor (const statement of statements) await transaction.run(statement.sql, ...statement.params);\n\t\t\t},\n\t\t\tthis.blobWrite(lead ? statements : undefined, lead),\n\t\t);\n\t}\n\n\t/**\n\t * How a put or a refresh of this table's blobs runs: a serial transaction of the blob table's own domain (#6560). On\n\t * PostgreSQL it holds the database-wide lock shared, so it waits for and excludes collection, whose writes hold that\n\t * lock exclusively, and the blob writers of this table exclude one another, but session writes, which hold the\n\t * database-wide lock shared with their session's domain, run beside it. Rows it writes again (`created_at`) are locked\n\t * in hash order, as an append's check of the blobs it records locks them (`missingBlob`), so neither waits on the\n\t * other in a cycle. Its callback only uses the transaction, so a transient failure runs it again.\n\t */\n\tprivate blobWrite(leading?: readonly SqliteStatement[], leadingOnly = false): SqliteTransactionOptions {\n\t\treturn {\n\t\t\tretryTransientFailures: true,\n\t\t\tconcurrency: { kind: \"serial\", domain: this.table },\n\t\t\t...(leading === undefined ? {} : { leading }),\n\t\t\t...(leading !== undefined && leadingOnly ? { leadingOnly: true } : {}),\n\t\t};\n\t}\n\t/**\n\t * The blob's bytes, read a chunk per statement when it has chunks, so no response holds more than one chunk. A\n\t * chunked blob whose chunks are not all there, as when a collection deleted it during the read, is not returned.\n\t */\n\tasync getBlob(hash: string): Promise<Uint8Array | undefined> {\n\t\tconst row = await this.database.get<SqliteRow & { data: Uint8Array; bytes: number; chunks: number }>(\n\t\t\t`SELECT data, bytes, chunks FROM ${this.table} WHERE hash = ?`,\n\t\t\thash,\n\t\t);\n\t\tif (row === undefined) return undefined;\n\t\tconst chunks = Number(row.chunks);\n\t\tif (chunks === 0) return row.data;\n\t\tconst data = new Uint8Array(Number(row.bytes));\n\t\tlet offset = 0;\n\t\tfor (let index = 0; index < chunks; index++) {\n\t\t\tconst chunk = await this.database.get<SqliteRow & { data: Uint8Array }>(\n\t\t\t\t`SELECT data FROM ${this.tables.blobChunks} WHERE hash = ? AND idx = ?`,\n\t\t\t\thash,\n\t\t\t\tindex,\n\t\t\t);\n\t\t\tif (chunk === undefined || offset + chunk.data.byteLength > data.byteLength) return undefined;\n\t\t\tdata.set(chunk.data, offset);\n\t\t\toffset += chunk.data.byteLength;\n\t\t}\n\t\treturn offset === data.byteLength ? data : undefined;\n\t}\n\t/** Refreshes stored hashes; unknown ages stay protected until collection stamps them. False when any is missing. */\n\tasync refreshBlobs(hashes: readonly string[]): Promise<boolean> {\n\t\tconst unique = [...new Set(hashes)];\n\t\tif (unique.length === 0) return true;\n\t\tconst requested = `hash IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")})`;\n\t\tconst params = [JSON.stringify(unique)];\n\t\tconst update = `UPDATE ${this.table} SET created_at = ${this.dialect.nowSeconds} WHERE ${requested} AND created_at > 0`;\n\t\tconst present = `SELECT hash FROM ${this.table} WHERE ${requested}`;\n\t\tif (this.database.batch) {\n\t\t\tconst [, rows] = await this.database.batch([\n\t\t\t\t{ sql: update, params },\n\t\t\t\t{ sql: present, params },\n\t\t\t]);\n\t\t\treturn rows!.length === unique.length;\n\t\t}\n\t\t// The rows present, locked in hash order before the update writes them (see `blobWrite`). On a pipelined connection\n\t\t// this read goes out with the transaction's start and the update with its commit.\n\t\tconst locked = {\n\t\t\tsql: `${present} ORDER BY hash${this.dialect.byteOrderCollation}${this.dialect.lockClause(\"update\")}`,\n\t\t\tparams,\n\t\t};\n\t\treturn this.database.transaction(\n\t\t\tasync (transaction) => {\n\t\t\t\tconst rows = await transaction.all(locked.sql, ...locked.params);\n\t\t\t\tif (transactionFinisher(transaction)?.([{ sql: update, params }]) !== true)\n\t\t\t\t\tawait transaction.run(update, ...params);\n\t\t\t\treturn rows.length === unique.length;\n\t\t\t},\n\t\t\tthis.blobWrite([locked]),\n\t\t);\n\t}\n\tasync listBlobHashes(): Promise<readonly string[]> {\n\t\tconst rows = await this.database.all<{ hash: string }>(`SELECT hash FROM ${this.table}`);\n\t\treturn rows.map((row) => row.hash);\n\t}\n\n\t/**\n\t * Rejects with a `blobs-collected` {@link WorkspaceSnapshotError} naming the first of `snapshots`' blobs this table\n\t * does not hold in full, a chunked blob's chunks included (#5077). Run in the write transaction that records the\n\t * snapshots, it keeps a collection that ran after their capture stored the blobs from leaving a recorded snapshot\n\t * that cannot be restored: the blobs it finds stay until that transaction ends, and the references it writes keep\n\t * them after.\n\t */\n\tasync assertStored(transaction: SqliteExecutor, snapshots: readonly WorktreeSnapshot[]): Promise<void> {\n\t\tconst missing = await this.missingBlob(transaction, snapshots);\n\t\tif (missing !== undefined) await this.refuseCollected(missing);\n\t}\n\n\t/** The `blobs-collected` {@link WorkspaceSnapshotError} `assertStored` rejects with for `hash`. */\n\tasync refuseCollected(hash: string): Promise<never> {\n\t\t// Loaded only when a write is refused, so the storage entry does not load the workspace error family.\n\t\tconst { WorkspaceSnapshotError } = await import(\"./errors.ts\");\n\t\tthrow new WorkspaceSnapshotError(\"blobs-collected\", hash);\n\t}\n\n\t/** The blobs of `snapshots` that `assertStored` checks, each once, in the order it reports the first missing one. */\n\tstoredHashes(snapshots: readonly WorktreeSnapshot[]): string[] {\n\t\treturn [...new Set(snapshots.flatMap(wellFormedBlobHashes))];\n\t}\n\n\t/**\n\t * The query `missingBlob` reads, for the blobs named by `source`, an SQL expression of a JSON array of hashes: the\n\t * hashes this table holds in full, locked FOR SHARE in hash order. A statement that checks the blobs on the server,\n\t * such as the session append function, runs it as it is (#6599).\n\t */\n\tstoredBlobsQuery(source: string): string {\n\t\treturn `SELECT hash FROM ${this.table} AS b WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues(source)}) AND (chunks = 0 OR chunks = (SELECT COUNT(*) FROM ${this.tables.blobChunks} AS c WHERE c.hash = b.hash)) ORDER BY hash${this.dialect.byteOrderCollation}${this.dialect.lockClause(\"share\")}`;\n\t}\n\n\t/**\n\t * A query that returns a row only while this table holds every blob of `snapshots` in full, for a write planned\n\t * outside a transaction to check in the request that writes it (#5077); undefined when they name no blob.\n\t */\n\tstoredFence(snapshots: readonly WorktreeSnapshot[]): SqliteStatement | undefined {\n\t\tconst hashes = [...new Set(snapshots.flatMap(wellFormedBlobHashes))];\n\t\tif (hashes.length === 0) return undefined;\n\t\treturn {\n\t\t\tsql: `SELECT 1 AS stored WHERE (SELECT COUNT(*) FROM ${this.table} AS b WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")}) AND (chunks = 0 OR chunks = (SELECT COUNT(*) FROM ${this.tables.blobChunks} AS c WHERE c.hash = b.hash))) = ?`,\n\t\t\tparams: [JSON.stringify(hashes), hashes.length],\n\t\t};\n\t}\n\n\t/**\n\t * The first of `snapshots`' blobs this table does not hold in full, read in `transaction`; undefined when none. The\n\t * rows it finds stay locked FOR SHARE until the transaction ends, taken in hash order as a blob write takes them.\n\t */\n\tasync missingBlob(transaction: SqliteExecutor, snapshots: readonly WorktreeSnapshot[]): Promise<string | undefined> {\n\t\tconst hashes = this.storedHashes(snapshots);\n\t\tif (hashes.length === 0) return undefined;\n\t\tconst rows = await transaction.all<SqliteRow & { hash: string }>(\n\t\t\tthis.storedBlobsQuery(\"?\"),\n\t\t\tJSON.stringify(hashes),\n\t\t);\n\t\tconst stored = new Set(rows.map((row) => row.hash));\n\t\treturn hashes.find((hash) => !stored.has(hash));\n\t}\n\n\t/**\n\t * Installs the index triggers of every referencing table that lacks them, each with a watermark, the highest rowid\n\t * the table holds in the same transaction, so every row is either at or below the watermark, to be backfilled, or\n\t * above it, indexed by the triggers. A table that has none yet, an empty one included, costs one watermark of 0.\n\t * Resolves with the state of every referencing table.\n\t */\n\tprivate async installIndex(\n\t\tpace?: BackgroundCollectionPace,\n\t\tincludeDeferred = false,\n\t\tcatalog?: StorageSchemaCatalog,\n\t): Promise<SourceState[]> {\n\t\t// The fork links trigger earlier builds of #6560 installed, asked for in the same read: dropped where found, in the\n\t\t// first write below, so a database that has it runs it no longer once a store of this build opened it.\n\t\tconst legacy = this.legacyForkLinks();\n\t\tconst found = new Set<string>();\n\t\tconst states = await this.readStates(includeDeferred, catalog, legacy && { names: [legacy.name], found });\n\t\tlet drop = legacy !== undefined && found.has(legacy.name) ? legacy : undefined;\n\t\tconst dropLegacy = async (transaction: SqliteExecutor) => {\n\t\t\tif (drop === undefined) return;\n\t\t\tconst { name, table } = drop;\n\t\t\tawait withShortSchemaLockWaits(transaction, this.dialect, () =>\n\t\t\t\ttransaction.exec(this.dialect.dropTrigger(name, table, true)),\n\t\t\t);\n\t\t\tdrop = undefined;\n\t\t};\n\t\tconst missing = states.filter((state) => !state.installed && (includeDeferred || !state.deferred));\n\t\tfor (const { source } of missing) {\n\t\t\tconst reset =\n\t\t\t\tsource.name === \"session-entries\"\n\t\t\t\t\t? await SqlSnapshotBlobStore.prepareSessionIndexReset(this.database)\n\t\t\t\t\t: undefined;\n\t\t\tawait this.write(pace, async (transaction) => {\n\t\t\t\tawait dropLegacy(transaction);\n\t\t\t\tconst [current] = await readSourceStates(transaction, this.dialect, this.tables, [source]);\n\t\t\t\tif (current === undefined || current.installed || (current.deferred && !includeDeferred)) return;\n\t\t\t\t// Its triggers lock the table: under short lock waits, so a stalled transaction never queues writers (#5218).\n\t\t\t\tawait withShortSchemaLockWaits(transaction, this.dialect, () =>\n\t\t\t\t\tinstallSource(transaction, this.dialect, this.tables, source, reset),\n\t\t\t\t);\n\t\t\t});\n\t\t}\n\t\tif (drop !== undefined) await this.write(pace, dropLegacy);\n\t\treturn missing.length === 0 ? states : this.readStates(includeDeferred);\n\t}\n\n\t/** The fork links trigger earlier builds of #6560 installed on the session entries, and its table. */\n\tprivate legacyForkLinks(): { readonly name: string; readonly table: string } | undefined {\n\t\tconst entries = this.sources.find((source) => source.name === \"session-entries\");\n\t\treturn entries && { name: legacyForkLinksTriggerName(entries.table), table: entries.table };\n\t}\n\n\t/**\n\t * The state of every source, read outside a transaction. On PostgreSQL the objects and the progress rows are read in\n\t * one read-only transaction whose start carries both, so they cost one round trip, not one each. An open's\n\t * `catalog` answers which objects exist only when it found every one: only its positive answers are final, and a\n\t * source table it lacks may have been created since (#6560). `also` asks which of other objects exist in the same\n\t * read, as `readSourceStates` does.\n\t */\n\tprivate readStates(\n\t\tincludeDeferred: boolean,\n\t\tcatalog?: StorageSchemaCatalog,\n\t\talso?: { readonly names: readonly string[]; readonly found: Set<string> },\n\t): Promise<SourceState[]> {\n\t\tif (this.dialect.name !== \"postgres\")\n\t\t\treturn readSourceStates(\n\t\t\t\tthis.database,\n\t\t\t\tthis.dialect,\n\t\t\t\tthis.tables,\n\t\t\t\tthis.sources,\n\t\t\t\tincludeDeferred,\n\t\t\t\tundefined,\n\t\t\t\talso,\n\t\t\t);\n\t\tconst names = sourceObjectNames(this.sources);\n\t\tconst present =\n\t\t\tcatalog !== undefined && names.every((name) => catalog.hasObject(name))\n\t\t\t\t? new Set([...names, ...(also?.names ?? []).filter((name) => catalog.hasObject(name))])\n\t\t\t\t: undefined;\n\t\treturn this.database.transaction(\n\t\t\t(transaction) =>\n\t\t\t\treadSourceStates(transaction, this.dialect, this.tables, this.sources, includeDeferred, present, also),\n\t\t\t{\n\t\t\t\treadOnly: true,\n\t\t\t\tretryTransientFailures: true,\n\t\t\t\tleading: [\n\t\t\t\t\t...(present === undefined ? [this.dialect.schemaObjects([...names, ...(also?.names ?? [])])] : []),\n\t\t\t\t\tsourceProgressRead(this.tables),\n\t\t\t\t],\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * Indexes the rows that referencing tables held before their triggers were installed, in transactions of\n\t * {@link SNAPSHOT_INDEX_BACKFILL_BATCH} rows, so that the index covers every reference. A one-time cost in the number\n\t * of existing rows, paid in the background by the first collection; resumes where it stopped. Does nothing once the\n\t * index is complete. Yields to the event loop after every batch, so the next batch, of the same table or another,\n\t * or what follows the index, such as a sweep's first batch, starts on a turn of its own (#5530). Checks `signal`\n\t * before each batch and rejects with its reason.\n\t */\n\tasync completeIndex(options: SnapshotIndexOptions = {}): Promise<void> {\n\t\tconst states = await this.installIndex(options.pace, true);\n\t\tfor (const { source, backfilled } of states) {\n\t\t\tif (backfilled) continue;\n\t\t\tconst reset =\n\t\t\t\tsource.name === \"session-entries\"\n\t\t\t\t\t? await SqlSnapshotBlobStore.prepareSessionIndexReset(this.database)\n\t\t\t\t\t: undefined;\n\t\t\tfor (let done = false; !done; ) {\n\t\t\t\toptions.signal?.throwIfAborted();\n\t\t\t\tdone = await this.backfillBatch(source, options, reset);\n\t\t\t\tawait this.betweenBatches(options.pace);\n\t\t\t}\n\t\t}\n\t\t// Reclamation must not delay publication: released collectors see exactly the same install and backfill as\n\t\t// before, even when either version exits at a batch boundary. Only unreferenced physical rows remain here.\n\t\tfor (const { retired } of states)\n\t\t\tfor (const receipt of retired ?? []) {\n\t\t\t\tconst { drainRetiredSessionIndex } = await import(\"./session-index-reset.js\");\n\t\t\t\tfor (;;) {\n\t\t\t\t\tawait this.betweenBatches(options.pace);\n\t\t\t\t\toptions.signal?.throwIfAborted();\n\t\t\t\t\tconst done = await this.write(options.pace, async (tx) => {\n\t\t\t\t\t\tconst finished = await drainRetiredSessionIndex(tx, this.tables, receipt);\n\t\t\t\t\t\tif (options.holder !== undefined) await this.renewClaim(tx, options.holder);\n\t\t\t\t\t\treturn finished;\n\t\t\t\t\t});\n\t\t\t\t\tif (done) break;\n\t\t\t\t}\n\t\t\t}\n\t}\n\n\t/** Indexes the next rows of `source`, and resolves true once every row at or below its watermark is indexed. */\n\tprivate backfillBatch(\n\t\tsource: IndexSource,\n\t\t{ holder, pace, signal }: SnapshotIndexOptions,\n\t\treset?: SessionIndexReset,\n\t): Promise<boolean> {\n\t\tconst t = this.tables;\n\t\tconst row = this.dialect.rowOrder();\n\t\tconst withholds = withholdsVersion(this.dialect, source);\n\t\treturn this.write(pace, async (transaction) => {\n\t\t\tconst [state] = await readSourceStates(transaction, this.dialect, t, [source]);\n\t\t\tif (state === undefined || state.backfilled) return true;\n\t\t\tif (state.foreign) {\n\t\t\t\t// A build before 0.9.88 installed its own triggers since the loop read the states: the source is installed again\n\t\t\t\t// in this transaction, its old rows removed, as at the start of a collection. Left as it is, that build could\n\t\t\t\t// index it its way, and builds 0.9.88 and 0.9.89 trust their version row (#5558).\n\t\t\t\tawait withShortSchemaLockWaits(transaction, this.dialect, () =>\n\t\t\t\t\tinstallSource(transaction, this.dialect, t, source, reset),\n\t\t\t\t);\n\t\t\t\tif (holder !== undefined) await this.renewClaim(transaction, holder);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t// A source that lost triggers meanwhile is indexed on, as its rows still need this build's statements; the sweep\n\t\t\t// installs its triggers again before it deletes anything.\n\t\t\tconst progress = await transaction.get<SqliteRow & { watermark: number; backfilled_through: number }>(\n\t\t\t\t`SELECT watermark, backfilled_through FROM ${t.sources} WHERE source = ?`,\n\t\t\t\tsource.name,\n\t\t\t);\n\t\t\tif (progress === undefined || progress.watermark < 0) return true;\n\t\t\tif (state.takeover) {\n\t\t\t\t// Installed by a build of 0.9.88 or 0.9.89 whose backfill is not done, which a build before 0.9.88 may have\n\t\t\t\t// indexed some of its way: this build indexes it again from its first row, with its own triggers, whose\n\t\t\t\t// pending trigger moves its own progress back, and holds the version row back until it is done, so that\n\t\t\t\t// builds 0.9.88 and 0.9.89 do not trust it meanwhile (#5558).\n\t\t\t\tawait transaction.run(\n\t\t\t\t\t`INSERT INTO ${t.sources} (source, watermark, backfilled_through) VALUES (?, ?, 0) ${REPLACE_PROGRESS}`,\n\t\t\t\t\tsource.own!,\n\t\t\t\t\tprogress.watermark,\n\t\t\t\t);\n\t\t\t\tfor (const name of [source.version!, rebuildRow(source)])\n\t\t\t\t\tawait transaction.run(`DELETE FROM ${t.sources} WHERE source = ?`, name);\n\t\t\t\tfor (const trigger of source.triggers)\n\t\t\t\t\tawait transaction.exec(this.dialect.dropTrigger(trigger.name, trigger.table));\n\t\t\t\tawait transaction.exec(source.triggers.map((trigger) => this.dialect.renderTrigger(trigger)).join(\"\\n\"));\n\t\t\t}\n\t\t\t// This build's own progress (#5558): rows an older build indexed past it are indexed again. On Postgres, which\n\t\t\t// no build before 0.9.88 opens, a source a build of 0.9.88 or 0.9.89 installed has none: its backfill, which\n\t\t\t// indexes what this one does, is trusted as far as it got.\n\t\t\tlet own =\n\t\t\t\tsource.own === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: await transaction.get<SqliteRow & { backfilled_through: number }>(\n\t\t\t\t\t\t\t`SELECT backfilled_through FROM ${t.sources} WHERE source = ?`,\n\t\t\t\t\t\t\tsource.own,\n\t\t\t\t\t\t);\n\t\t\tif (source.own !== undefined && own === undefined && progress.backfilled_through < progress.watermark) {\n\t\t\t\tawait transaction.run(\n\t\t\t\t\t`INSERT INTO ${t.sources} (source, watermark, backfilled_through) VALUES (?, ?, ?) ${REPLACE_PROGRESS}`,\n\t\t\t\t\tsource.own,\n\t\t\t\t\tprogress.watermark,\n\t\t\t\t\tprogress.backfilled_through,\n\t\t\t\t);\n\t\t\t\town = { backfilled_through: progress.backfilled_through };\n\t\t\t}\n\t\t\tconst from =\n\t\t\t\town !== undefined && own.backfilled_through < progress.backfilled_through\n\t\t\t\t\t? own.backfilled_through\n\t\t\t\t\t: progress.backfilled_through;\n\t\t\t// The version row says the index is this build's and complete: never while a trigger is missing, which a build\n\t\t\t// before 0.9.88 would install again its way under it (#5558).\n\t\t\tconst publish = withholds && state.installed;\n\t\t\tif (from >= progress.watermark) {\n\t\t\t\tif (publish) await statementBatch(transaction, [publishVersion(t, source)], []);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tconst { upper: lastRow } = (await transaction.get<SqliteRow & { upper: number | null }>(\n\t\t\t\t`SELECT MAX(${row}) AS upper FROM (SELECT ${row} FROM ${source.table} WHERE ${row} > ? AND ${row} <= ? ORDER BY ${row} LIMIT ?)`,\n\t\t\t\tfrom,\n\t\t\t\tprogress.watermark,\n\t\t\t\tSNAPSHOT_INDEX_BACKFILL_BATCH,\n\t\t\t))!;\n\t\t\tconst upper = lastRow ?? progress.watermark;\n\t\t\tfor (const sql of source.backfill) await transaction.run(sql, from, upper);\n\t\t\tif (source.rowwise !== undefined) {\n\t\t\t\tconst rows = await transaction.all<SqliteRow & { id: number }>(\n\t\t\t\t\t`SELECT ${row} AS id FROM ${source.table} WHERE ${row} > ? AND ${row} <= ? ORDER BY ${row}`,\n\t\t\t\t\tfrom,\n\t\t\t\t\tupper,\n\t\t\t\t);\n\t\t\t\t// The session entries are linked in each session's seq order, whatever order their rows are stored in (#6560).\n\t\t\t\tconst linking =\n\t\t\t\t\tsource.name === \"session-entries\" ? entryLinking(source, this.dialect, t.sessionLinks) : undefined;\n\t\t\t\tfor (const { id } of rows) {\n\t\t\t\t\t// Stopping between rows rolls the whole batch back, progress included, so the pass stays resumable.\n\t\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\t\tif (linking !== undefined) await linkStoredEntry(transaction, linking, id);\n\t\t\t\t\telse for (const sql of source.rowwise) await transaction.run(sql, id);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Indexing rows again behind the source's progress, for this build's own, never moves the progress back.\n\t\t\tawait transaction.run(\n\t\t\t\t`UPDATE ${t.sources} SET backfilled_through = ? WHERE source = ? AND backfilled_through < ?`,\n\t\t\t\tupper,\n\t\t\t\tsource.name,\n\t\t\t\tupper,\n\t\t\t);\n\t\t\tif (own !== undefined)\n\t\t\t\tawait transaction.run(\n\t\t\t\t\t`UPDATE ${t.sources} SET watermark = ?, backfilled_through = ? WHERE source = ?`,\n\t\t\t\t\tprogress.watermark,\n\t\t\t\t\tupper,\n\t\t\t\t\tsource.own!,\n\t\t\t\t);\n\t\t\tif (holder !== undefined) await this.renewClaim(transaction, holder);\n\t\t\tconst done = upper >= progress.watermark;\n\t\t\t// Both progress rows reach the watermark: builds 0.9.88 and 0.9.89 may trust the index now (#5558).\n\t\t\tif (done && publish) await statementBatch(transaction, [publishVersion(t, source)], []);\n\t\t\treturn done;\n\t\t});\n\t}\n\n\t/**\n\t * Deletes every blob stored or re-stored at least `graceSeconds` ago on the database clock that no retained snapshot\n\t * and no snapshot dispatched work carries references, and resolves with the hashes deleted. Reads the reference index\n\t * and the blob table's age index, never a journal or a session. Ages are counted in whole seconds, so a blob can stay\n\t * up to a second past `graceSeconds`, never less.\n\t *\n\t * Pages through the aged blobs, oldest first, {@link SNAPSHOT_COLLECTION_BATCH} at a time, and keeps as candidates\n\t * those no retaining run, no carried work and no session retains. A session's retained snapshots are found by walking\n\t * its snapshot entries, at most {@link SNAPSHOT_COLLECTION_SESSION_REFS} of them per statement, once per sweep\n\t * (#5530). The candidates are deleted in batches, each one write transaction that finds the retained snapshots of the\n\t * sessions it walked for its blobs again, in one statement, and deletes only the blobs none of them retains, no other\n\t * session records, and that are still old and unreferenced by runs and carried work. So a reference published before\n\t * the batch commits keeps its blob, and a process killed mid-collection leaves only garbage. The event loop never\n\t * gets a turn inside a write transaction: another connection of this process that wrote then would wait for the\n\t * write lock while holding the event loop, and the transaction could not end until it gave up.\n\t *\n\t * Every batch first checks, in its transaction, that every referencing table has its triggers and a finished\n\t * backfill, as {@link completeIndex} leaves them. When one does not, because a table appeared or lost its triggers\n\t * since, nothing is deleted until the index has been completed again. A sweep repairs the index once; when it is\n\t * incomplete again after that, because the schema keeps changing under it, the sweep stops without deleting\n\t * anything more and the next collection tries again. Gives the event loop a turn between statements that walk\n\t * sessions, between batches and between pages, and checks `signal` before each and rejects with its reason.\n\t */\n\tasync sweep(options: SnapshotSweepOptions): Promise<readonly string[]> {\n\t\tconst t = this.tables;\n\t\toptions.signal?.throwIfAborted();\n\t\tconst trigger = `${t.blobs}_chunks_delete_all`;\n\t\tconst required = [trigger, `${t.blobs}_age`, `${t.blobs}_inline_size`];\n\t\t// Asked with them: whether forks share their parents' histories, whose inherited snapshots the sweep keeps (#6560).\n\t\tconst schema = this.dialect.schemaObjects([...required, this.forkSegments]);\n\t\tconst present = new Set(\n\t\t\t(await this.database.all<SqliteRow & { name: string }>(schema.sql, ...schema.params)).map((row) => row.name),\n\t\t);\n\t\tconst forks = present.has(this.forkSegments);\n\t\tif (!required.every((name) => present.has(name))) {\n\t\t\toptions.signal?.throwIfAborted();\n\t\t\tawait this.write(options.pace, async (transaction) => {\n\t\t\t\tif (options.holder !== undefined) await this.renewClaim(transaction, options.holder);\n\t\t\t\tawait withShortSchemaLockWaits(transaction, this.dialect, async () => {\n\t\t\t\t\tif (!present.has(trigger)) await addBlobChunks(transaction, t, this.dialect);\n\t\t\t\t\tawait addBlobMaintenanceIndexes(transaction, t);\n\t\t\t\t});\n\t\t\t});\n\t\t\tawait this.betweenBatches(options.pace);\n\t\t}\n\t\tconst minimumAge = collectableAge(options.graceSeconds);\n\t\tconst deleted: string[] = [];\n\t\tconst turns = new SweepTurns(options, () => this.betweenBatches(options.pace));\n\t\tlet sessions = new SweepSessions();\n\t\tlet cursor: PageRow | undefined;\n\t\tlet repaired = false;\n\t\tlet renewedAt = Number.NEGATIVE_INFINITY;\n\t\tfor (;;) {\n\t\t\tawait turns.next();\n\t\t\tif (options.holder !== undefined && performance.now() - renewedAt >= SWEEP_CLAIM_RENEWAL_MS) {\n\t\t\t\t// Pages that hold nothing to delete write nothing else; the claim is renewed when the sweep starts and then\n\t\t\t\t// at least once per quarter lease.\n\t\t\t\tconst holder = options.holder;\n\t\t\t\tawait this.write(options.pace, (transaction) => this.renewClaim(transaction, holder));\n\t\t\t\trenewedAt = performance.now();\n\t\t\t}\n\t\t\tconst page = await this.page(minimumAge, cursor);\n\t\t\tconst candidates = await this.unretainedOf(\n\t\t\t\tpage.map((row) => row.hash),\n\t\t\t\tsessions,\n\t\t\t\tturns,\n\t\t\t\tforks,\n\t\t\t);\n\t\t\tlet incomplete = false;\n\t\t\tfor (const batch of sessions.batches(candidates)) {\n\t\t\t\t// Every delete batch starts on a turn of its own and ends with one: never a turn while it holds the write lock.\n\t\t\t\tawait turns.next();\n\t\t\t\tconst removed = await this.deleteUnretained(batch, minimumAge, options);\n\t\t\t\tturns.held();\n\t\t\t\tif (removed === undefined) {\n\t\t\t\t\tincomplete = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\trenewedAt = performance.now();\n\t\t\t\tdeleted.push(...removed);\n\t\t\t\toptions.onBatch?.(removed);\n\t\t\t}\n\t\t\tif (incomplete) {\n\t\t\t\tif (repaired) return deleted;\n\t\t\t\trepaired = true;\n\t\t\t\tawait this.completeIndex(options);\n\t\t\t\tsessions = new SweepSessions();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (page.length < SNAPSHOT_COLLECTION_BATCH) {\n\t\t\t\tawait this.stampLegacyAges(options);\n\t\t\t\tawait this.moveChunksToRowTable(options);\n\t\t\t\treturn deleted;\n\t\t\t}\n\t\t\tcursor = page.at(-1);\n\t\t\t// Every page holds the event loop, also one whose blobs runs, carried work or sessions this sweep walked\n\t\t\t// already retain, which walks no session and deletes nothing: the next page starts after a turn (#5530).\n\t\t\tturns.held();\n\t\t}\n\t}\n\n\t/**\n\t * Which of `hashes` no retaining run, no carried work and no session retains, as far as these reads see: the sweep's\n\t * candidates, which a delete batch checks again in its transaction. Finds the retained blobs of each session that\n\t * references one of them and that `sessions` has not walked yet, in statements of at most\n\t * {@link SNAPSHOT_COLLECTION_SESSION_REFS} snapshot entries, with a turn between them.\n\t */\n\tprivate async unretainedOf(\n\t\thashes: readonly string[],\n\t\tsessions: SweepSessions,\n\t\tturns: SweepTurns,\n\t\tforks: boolean,\n\t): Promise<SweepCandidate[]> {\n\t\tif (hashes.length === 0) return [];\n\t\tconst t = this.tables;\n\t\tconst free = await this.database.all<SqliteRow & { hash: string }>(\n\t\t\t`SELECT value AS hash FROM ${this.dialect.jsonValues(\"?\")} WHERE ${this.unreferencedByRuns(\"value\")}`,\n\t\t\tJSON.stringify(hashes),\n\t\t);\n\t\tif (free.length === 0) return [];\n\t\tconst referencing = new Map<string, string[]>(free.map((row) => [row.hash, []]));\n\t\tfor (const { hash, session_id } of await this.database.all<SqliteRow & { hash: string; session_id: string }>(\n\t\t\t`SELECT DISTINCT hash, session_id FROM ${t.sessionRecords} WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")})`,\n\t\t\tJSON.stringify([...referencing.keys()]),\n\t\t))\n\t\t\treferencing.get(hash)?.push(session_id);\n\t\tconst unwalked = sessions.unwalked([...referencing.values()].flat());\n\t\tif (unwalked.length > 0) {\n\t\t\tconst costs = await this.sessionCosts(unwalked, () => turns.light());\n\t\t\tsessions.cost(costs);\n\t\t\tfor (const group of sessionGroups(costs)) {\n\t\t\t\tawait turns.next();\n\t\t\t\tsessions.retain(group, await this.retainedBySessions(group, forks));\n\t\t\t\tturns.held();\n\t\t\t}\n\t\t}\n\t\treturn [...referencing]\n\t\t\t.filter(([hash]) => !sessions.retains(hash))\n\t\t\t.map(([hash, referencedBy]) => ({ hash, sessions: referencedBy }));\n\t}\n\n\t/**\n\t * Deletes the blobs of `batch` that are still old and that no retaining run, no carried work and no session retains,\n\t * in one write transaction, and resolves with the hashes deleted; undefined, deleting nothing, when the reference\n\t * index is incomplete. The transaction checks the batch's blobs again in one statement, so what it sees is what\n\t * holds when the batch commits: the snapshots the batch's sessions, those the sweep walked for its blobs, retain now,\n\t * and the sessions that record its blobs now. A blob a session the sweep did not walk records, such as one created\n\t * since, is kept; the next collection walks that session. Nothing in the transaction waits for a turn of the event\n\t * loop (#5530).\n\t *\n\t * It runs as a whole-database transaction on purpose, so no other write runs beside it. With only the blob table's\n\t * lock it would not be safe: it decides which blobs sessions still use in one statement and deletes in the next. A\n\t * session write that records a blob meanwhile holds the blob's row only until it commits its reference; the delete\n\t * waits for it, then goes ahead without looking at the references again, and removes a blob a session has just\n\t * recorded. The same goes for the references retaining runs and carried work write.\n\t */\n\tprivate deleteUnretained(\n\t\tbatch: SweepDeleteBatch,\n\t\tminimumAge: number,\n\t\toptions: SnapshotSweepOptions,\n\t): Promise<string[] | undefined> {\n\t\tconst t = this.tables;\n\t\treturn this.write(options.pace, async (transaction) => {\n\t\t\tconst found = new Set<string>();\n\t\t\tconst states = await readSourceStates(transaction, this.dialect, this.tables, this.sources, false, undefined, {\n\t\t\t\tnames: [this.forkSegments],\n\t\t\t\tfound,\n\t\t\t});\n\t\t\tif (!states.every((state) => state.installed && state.backfilled)) return undefined;\n\t\t\tif (options.holder !== undefined) await this.renewClaim(transaction, options.holder);\n\t\t\tconst kept = new Set(await this.keptBySessions(transaction, batch, found.has(this.forkSegments)));\n\t\t\tconst unretained = batch.hashes.filter((hash) => !kept.has(hash));\n\t\t\tif (unretained.length === 0) return [];\n\t\t\tconst rows = await transaction.all<SqliteRow & { hash: string }>(\n\t\t\t\t`DELETE FROM ${t.blobs} WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")}) AND created_at > 0 AND created_at <= ${this.dialect.nowSeconds} - ? AND ${this.unreferencedByRuns(`${t.blobs}.hash`)} RETURNING hash`,\n\t\t\t\tJSON.stringify(unretained),\n\t\t\t\tminimumAge,\n\t\t\t);\n\t\t\treturn rows.map((row) => row.hash);\n\t\t});\n\t}\n\n\t/** A condition that no retaining run and no carried work references the blob `hash` names. */\n\tprivate unreferencedByRuns(hash: string): string {\n\t\tconst t = this.tables;\n\t\treturn `NOT EXISTS (\n\t\t\t\tSELECT 1 FROM ${t.runRefs} AS ref WHERE ref.hash = ${hash}\n\t\t\t\tAND NOT EXISTS (SELECT 1 FROM ${t.runState} AS state WHERE state.run_id = ref.run_id AND state.retained = 0)\n\t\t\t) AND NOT EXISTS (SELECT 1 FROM ${t.carriedRefs} AS carried WHERE carried.hash = ${hash})`;\n\t}\n\n\t/**\n\t * How many snapshot entries finding the retained snapshots of each of `sessions` walks: the entries of the session,\n\t * once for each distinct latest snapshot entry of its open leaves, which bounds the entries on those leaves'\n\t * branches. Reads one session per statement, waiting for `turn` between statements.\n\t */\n\tprivate async sessionCosts(sessions: readonly string[], turn: () => Promise<void>): Promise<Map<string, number>> {\n\t\tconst t = this.tables;\n\t\tconst costs = new Map<string, number>();\n\t\tfor (const [index, session] of sessions.entries()) {\n\t\t\tif (index > 0) await turn();\n\t\t\tconst row = await this.database.get<SqliteRow & { refs: number; anchors: number }>(\n\t\t\t\t`SELECT count(*) AS refs,\n\t\t\t\t\t(SELECT count(DISTINCT anchor_seq) FROM ${t.sessionLinks} WHERE session_id = ? AND children = 0 AND anchor_seq IS NOT NULL) AS anchors\n\t\t\t\tFROM ${t.sessionRefs} WHERE session_id = ?`,\n\t\t\t\tsession,\n\t\t\t\tsession,\n\t\t\t);\n\t\t\tcosts.set(session, Math.max(1, Number(row?.refs ?? 0) * Number(row?.anchors ?? 0)));\n\t\t}\n\t\treturn costs;\n\t}\n\n\t/**\n\t * The blobs that the snapshots `sessions` retain reference, in one statement. A session whose tree the index could\n\t * not follow retains every snapshot it records.\n\t */\n\tprivate async retainedBySessions(sessions: readonly string[], forks: boolean): Promise<string[]> {\n\t\tconst t = this.tables;\n\t\tconst ids = JSON.stringify(sessions);\n\t\tconst inherited = this.inheritedRecord(forks);\n\t\tconst rows = await this.database.all<SqliteRow & { hash: string }>(\n\t\t\t`SELECT DISTINCT record.hash FROM ${t.sessionRecords} AS record\n\t\t\tWHERE record.session_id IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")})\n\t\t\tAND (\n\t\t\t\t(record.session_id, record.snapshot_id) IN (${this.sessionHeads(`session_id IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")})`)})\n\t\t\t\tOR EXISTS (SELECT 1 FROM ${t.sessionLinks} AS broken WHERE broken.session_id = record.session_id AND broken.broken = 1)${inherited}\n\t\t\t)`,\n\t\t\tids,\n\t\t\tids,\n\t\t);\n\t\treturn rows.map((row) => row.hash);\n\t}\n\n\t/**\n\t * A condition, after `OR`, that another session inherits the session record `record` through a fork segment\n\t * (#6560); empty when `forks` says the fork segments table is not there, as while shared-history forks are off. A\n\t * fork that shares its parent's history stores none of the entries it inherits, so its own references never name\n\t * their snapshots: a record a segment names is kept whatever its session retains, as long as the segment lasts. A\n\t * delete batch reads whether the table exists in its own transaction, so it sees the segments that hold when it\n\t * commits.\n\t */\n\tprivate inheritedRecord(forks: boolean): string {\n\t\tif (!forks) return \"\";\n\t\treturn `\n\t\t\t\tOR EXISTS (SELECT 1 FROM ${this.forkSegments} AS segment WHERE segment.source_id = record.session_id AND record.seq BETWEEN segment.from_seq AND segment.to_seq)`;\n\t}\n\n\t/**\n\t * The blobs of `batch` that a session records and that the delete must keep, in one statement: those the snapshots\n\t * of `batch.sessions` retain, and those a session not among them records, whose snapshots the sweep did not walk.\n\t * Walks only `batch.sessions`, whose snapshot entries the sweep bounded when it made the batch (#5530).\n\t */\n\tprivate async keptBySessions(executor: SqliteExecutor, batch: SweepDeleteBatch, forks: boolean): Promise<string[]> {\n\t\tconst t = this.tables;\n\t\tconst ids = JSON.stringify(batch.sessions);\n\t\tconst walked = `(SELECT value FROM ${this.dialect.jsonValues(\"?\")})`;\n\t\tconst inherited = this.inheritedRecord(forks);\n\t\tconst rows = await executor.all<SqliteRow & { hash: string }>(\n\t\t\t`SELECT DISTINCT record.hash FROM ${t.sessionRecords} AS record\n\t\t\tWHERE record.hash IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")})\n\t\t\tAND (\n\t\t\t\trecord.session_id NOT IN ${walked}\n\t\t\t\tOR (record.session_id, record.snapshot_id) IN (${this.sessionHeads(`session_id IN ${walked}`)})\n\t\t\t\tOR EXISTS (SELECT 1 FROM ${t.sessionLinks} AS broken WHERE broken.session_id = record.session_id AND broken.broken = 1)${inherited}\n\t\t\t)`,\n\t\t\tJSON.stringify(batch.hashes),\n\t\t\tids,\n\t\t\tids,\n\t\t);\n\t\treturn rows.map((row) => row.hash);\n\t}\n\n\t/**\n\t * Stamps every blob of unknown age with the database clock, in hash order, in write transactions of at most\n\t * {@link SNAPSHOT_LEGACY_STAMP_BYTES} of blobs. Moves every in-row blob larger than\n\t * {@link SNAPSHOT_BLOB_CHUNK_BYTES} to chunks regardless of age. Chunk writes have the same byte bound;\n\t * publishing also frees the old in-row value, whose cost grows with its size. Starts with a turn of the event loop\n\t * when there is anything to do, so its first write does not share the turn of the sweep's last batch, and every\n\t * stamp and every statement of a move ends with a turn, whatever it found, so every page does too (#5530).\n\t */\n\tprivate async stampLegacyAges(options: SnapshotIndexOptions): Promise<void> {\n\t\tconst oversized = `chunks = 0 AND length(data) > ${SNAPSHOT_BLOB_CHUNK_BYTES}`;\n\t\tif (\n\t\t\t!(await this.database.get(\n\t\t\t\t`SELECT 1 FROM ${this.table} WHERE created_at = 0 UNION ALL SELECT 1 FROM ${this.table} WHERE ${oversized} LIMIT 1`,\n\t\t\t))\n\t\t)\n\t\t\treturn;\n\t\tawait this.betweenBatches(options.pace);\n\t\tlet after = \"\";\n\t\tfor (;;) {\n\t\t\toptions.signal?.throwIfAborted();\n\t\t\tconst page = await this.database.all<SqliteRow & { hash: string; size: number }>(\n\t\t\t\t`SELECT hash, length(data) AS size FROM ${this.table} WHERE created_at = 0 AND hash > ? UNION ALL SELECT hash, length(data) AS size FROM ${this.table} WHERE ${oversized} AND created_at > 0 AND hash > ? ORDER BY hash LIMIT ?`,\n\t\t\t\tafter,\n\t\t\t\tafter,\n\t\t\t\tSNAPSHOT_COLLECTION_BATCH,\n\t\t\t);\n\t\t\tlet batch: string[] = [];\n\t\t\tlet bytes = 0;\n\t\t\tfor (const { hash, size } of page) {\n\t\t\t\tconst oversized = Number(size) > SNAPSHOT_BLOB_CHUNK_BYTES;\n\t\t\t\tif (batch.length > 0 && (oversized || bytes + Number(size) > SNAPSHOT_LEGACY_STAMP_BYTES)) {\n\t\t\t\t\tawait this.stampInRows(batch, options);\n\t\t\t\t\tbatch = [];\n\t\t\t\t\tbytes = 0;\n\t\t\t\t}\n\t\t\t\tif (oversized) {\n\t\t\t\t\tawait this.moveLegacyBlobToChunks(hash, options);\n\t\t\t\t} else {\n\t\t\t\t\tbatch.push(hash);\n\t\t\t\t\tbytes += Number(size);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (batch.length > 0) await this.stampInRows(batch, options);\n\t\t\tif (page.length < SNAPSHOT_COLLECTION_BATCH) return;\n\t\t\tafter = page.at(-1)!.hash;\n\t\t}\n\t}\n\n\t/** Stamps the blobs `hashes` name that still have an unknown age, in their rows, in one write transaction. */\n\tprivate async stampInRows(hashes: readonly string[], options: SnapshotIndexOptions): Promise<void> {\n\t\toptions.signal?.throwIfAborted();\n\t\tawait this.write(options.pace, async (transaction) => {\n\t\t\tif (options.holder !== undefined) await this.renewClaim(transaction, options.holder);\n\t\t\tawait transaction.run(\n\t\t\t\t`UPDATE ${this.table} SET created_at = ${this.dialect.nowSeconds} WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")}) AND created_at = 0`,\n\t\t\t\tJSON.stringify(hashes),\n\t\t\t);\n\t\t});\n\t\tawait this.betweenBatches(options.pace);\n\t}\n\n\t/**\n\t * Moves an in-row legacy blob to chunks regardless of age. Reads its bytes without the writer and writes at most\n\t * {@link SNAPSHOT_LEGACY_STAMP_BYTES} per transaction while readers retain the in-row value. Publishing stamps\n\t * only an unknown age and frees the old value under the writer, with time proportional to the freed size. A stopped\n\t * move leaves chunks the next move reuses.\n\t * Gives the event loop a turn after reading the blob's bytes and after every transaction, also when another host\n\t * moved or deleted the blob first (#5530).\n\t */\n\tprivate async moveLegacyBlobToChunks(hash: string, options: SnapshotIndexOptions): Promise<void> {\n\t\tconst t = this.tables;\n\t\tconst unmoved = `hash = ? AND chunks = 0 AND length(data) > ${SNAPSHOT_BLOB_CHUNK_BYTES}`;\n\t\tconst legacy = await this.database.get<SqliteRow & { data: Uint8Array }>(\n\t\t\t`SELECT data FROM ${t.blobs} WHERE ${unmoved}`,\n\t\t\thash,\n\t\t);\n\t\tawait this.betweenBatches(options.pace);\n\t\tif (legacy === undefined) return;\n\t\tconst { data } = legacy;\n\t\tconst chunks = Math.ceil(data.byteLength / SNAPSHOT_BLOB_CHUNK_BYTES);\n\t\tconst perTransaction = SNAPSHOT_LEGACY_STAMP_BYTES / SNAPSHOT_BLOB_CHUNK_BYTES;\n\t\tfor (let first = 0; first < chunks; first += perTransaction) {\n\t\t\toptions.signal?.throwIfAborted();\n\t\t\tconst pending = await this.write(options.pace, async (transaction) => {\n\t\t\t\tif (options.holder !== undefined) await this.renewClaim(transaction, options.holder);\n\t\t\t\tif (!(await transaction.get(`SELECT 1 FROM ${t.blobs} WHERE ${unmoved}`, hash))) {\n\t\t\t\t\tawait this.dropStrayChunks(transaction, [hash]);\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tfor (let index = first; index < Math.min(first + perTransaction, chunks); index++) {\n\t\t\t\t\tawait transaction.run(\n\t\t\t\t\t\t`INSERT INTO ${t.blobChunks} (hash, idx, data) VALUES (?, ?, ?) ON CONFLICT DO NOTHING`,\n\t\t\t\t\t\thash,\n\t\t\t\t\t\tindex,\n\t\t\t\t\t\tdata.subarray(index * SNAPSHOT_BLOB_CHUNK_BYTES, (index + 1) * SNAPSHOT_BLOB_CHUNK_BYTES),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t});\n\t\t\tawait this.betweenBatches(options.pace);\n\t\t\tif (!pending) return;\n\t\t}\n\t\toptions.signal?.throwIfAborted();\n\t\tawait this.write(options.pace, async (transaction) => {\n\t\t\tif (options.holder !== undefined) await this.renewClaim(transaction, options.holder);\n\t\t\tconst { changes } = await transaction.run(\n\t\t\t\t`UPDATE ${t.blobs} SET data = ?, chunks = ?, created_at = CASE WHEN created_at = 0 THEN ${this.dialect.nowSeconds} ELSE created_at END WHERE ${unmoved} AND (SELECT count(*) FROM ${t.blobChunks} WHERE hash = ?) = ?`,\n\t\t\t\tnew Uint8Array(),\n\t\t\t\tchunks,\n\t\t\t\thash,\n\t\t\t\thash,\n\t\t\t\tchunks,\n\t\t\t);\n\t\t\tif (changes === 0) await this.dropStrayChunks(transaction, [hash]);\n\t\t});\n\t\tawait this.betweenBatches(options.pace);\n\t}\n\n\t/**\n\t * Deletes the chunks of the blobs `hashes` names whose rows hold their bytes themselves or are gone: chunks that a\n\t * move wrote before another writer deleted or replaced its row. Completed chunked blobs retain their chunks.\n\t */\n\tprivate async dropStrayChunks(transaction: SqliteExecutor, hashes: readonly string[]): Promise<void> {\n\t\tconst t = this.tables;\n\t\tawait transaction.run(\n\t\t\t`DELETE FROM ${t.blobChunks} WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")}) AND NOT EXISTS (SELECT 1 FROM ${t.blobs} AS stored WHERE stored.hash = ${t.blobChunks}.hash AND stored.chunks > 0)`,\n\t\t\tJSON.stringify(hashes),\n\t\t);\n\t}\n\n\t/**\n\t * Moves a chunk table that an earlier release created `WITHOUT ROWID` to the row layout of\n\t * {@link chunkTableDefinition} (#5541), in write transactions that each copy or free at most\n\t * {@link SNAPSHOT_CHUNK_MOVE_ROWS} chunks in all. It copies the rows, in key order, to a new table in that layout;\n\t * later transactions copy the rows written since and drop the copies of rows deleted since, and the one that leaves\n\t * the new table holding exactly the chunk table's rows gives it the chunk table's name, under which the old one is\n\t * kept until later transactions empty and drop it. The chunk table keeps its name, columns and key throughout, so\n\t * a process of an earlier release reads and writes it unchanged, and a chunk is copied with its bytes: its key, a\n\t * blob's hash and an index, names them. A stopped move resumes from what the tables hold. Does nothing on a chunk\n\t * table in the row layout, which every Postgres table is.\n\t */\n\tprivate async moveChunksToRowTable(options: SnapshotSweepOptions, offline = false): Promise<void> {\n\t\tconst t = this.tables;\n\t\tconst { next, retired } = chunkMoveTables(t);\n\t\t// The old table is `WITHOUT ROWID` under either name, so one statement tells a store with nothing to move, as\n\t\t// every store is once its move is over.\n\t\tconst probe = this.dialect.withoutRowidTables([t.blobChunks, retired]);\n\t\tconst clustered = async (executor: SqliteExecutor) =>\n\t\t\t(await executor.all<SqliteRow & { name: string }>(probe.sql, ...probe.params)).map((row) => row.name);\n\t\tconst rows = SNAPSHOT_CHUNK_MOVE_ROWS;\n\t\tconst pending = await clustered(this.database);\n\t\tif (pending.includes(retired)) await this.dropChunkTable(retired, options, offline);\n\t\tif (!pending.includes(t.blobChunks)) return;\n\t\t// A copy the disk has no room for would fill it (#5694): the table stays as it is, read and written as before, and a\n\t\t// partial copy an earlier collection left is dropped, its pages back on the database's free list.\n\t\tconst pendingMove = await this.chunkCopySpace(next, offline);\n\t\tif (pendingMove) {\n\t\t\tif (offline)\n\t\t\t\tthrow new Error(\n\t\t\t\t\tpendingMove.reason === \"free-space\"\n\t\t\t\t\t\t? `The chunk move needs ${pendingMove.requiredFreeBytes} free bytes; ${pendingMove.freeBytes} are available.`\n\t\t\t\t\t\t: \"Cannot measure free disk space for the offline chunk move.\",\n\t\t\t\t);\n\t\t\toptions.onPendingChunkMove?.(pendingMove);\n\t\t\treturn this.dropChunkTable(next, options);\n\t\t}\n\t\t// Copies the rows after the last one copied: no other statement writes the new table before it is renamed.\n\t\tconst copyNext = async (transaction: SqliteExecutor) => {\n\t\t\tconst last = await transaction.get<SqliteRow & { hash: string; idx: number }>(\n\t\t\t\t`SELECT hash, idx FROM ${next} ORDER BY hash DESC, idx DESC LIMIT 1`,\n\t\t\t);\n\t\t\tconst { changes } = await transaction.run(\n\t\t\t\t`INSERT INTO ${next} (hash, idx, data) SELECT hash, idx, data FROM ${t.blobChunks} WHERE (hash, idx) > (?, ?) ORDER BY hash, idx LIMIT ? ON CONFLICT DO NOTHING`,\n\t\t\t\tlast?.hash ?? \"\",\n\t\t\t\tlast?.idx ?? -1,\n\t\t\t\trows,\n\t\t\t);\n\t\t\treturn changes;\n\t\t};\n\t\t// Copies the first rows the new table lacks, wherever they are: rows written behind the copy.\n\t\tconst copyMissing = async (transaction: SqliteExecutor) => {\n\t\t\tconst { changes } = await transaction.run(\n\t\t\t\t`INSERT INTO ${next} (hash, idx, data) SELECT old.hash, old.idx, old.data FROM ${t.blobChunks} AS old WHERE NOT EXISTS (SELECT 1 FROM ${next} AS copy WHERE copy.hash = old.hash AND copy.idx = old.idx) ORDER BY old.hash, old.idx LIMIT ?`,\n\t\t\t\trows,\n\t\t\t);\n\t\t\treturn changes;\n\t\t};\n\t\t// The rows the new table holds and the chunk table no longer does: copies of rows deleted since they were copied.\n\t\tconst stale = `SELECT hash, idx FROM ${next} EXCEPT SELECT hash, idx FROM ${t.blobChunks}`;\n\t\tfor (let copying = true; ; ) {\n\t\t\toptions.signal?.throwIfAborted();\n\t\t\tif (offline) await this.requireOfflineBatchSpace();\n\t\t\tlet moved: boolean;\n\t\t\ttry {\n\t\t\t\tmoved = await this.write(options.pace, async (transaction) => {\n\t\t\t\t\tif (options.holder !== undefined) await this.renewClaim(transaction, options.holder);\n\t\t\t\t\tif (!(await clustered(transaction)).includes(t.blobChunks)) return true;\n\t\t\t\t\tawait transaction.exec(chunkTableDefinition(next, this.dialect));\n\t\t\t\t\tif (copying) {\n\t\t\t\t\t\tcopying = (await copyNext(transaction)) === rows;\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\t// Rows copied and stale copies dropped share the transaction's rows. The tables are renamed only by a transaction\n\t\t\t\t\t// that leaves the new table holding exactly the chunk table's rows; otherwise the next transaction continues.\n\t\t\t\t\tconst copied = await copyMissing(transaction);\n\t\t\t\t\tif (copied === rows) return false;\n\t\t\t\t\tconst room = rows - copied;\n\t\t\t\t\tconst { changes: dropped } = await transaction.run(\n\t\t\t\t\t\t`DELETE FROM ${next} WHERE (hash, idx) IN (${stale} LIMIT ?)`,\n\t\t\t\t\t\troom,\n\t\t\t\t\t);\n\t\t\t\t\tif (dropped === room && (await transaction.get(`${stale} LIMIT 1`)) !== undefined) return false;\n\t\t\t\t\t// Renaming the table would point a trigger that names it at the old table: both of the delete triggers releases\n\t\t\t\t\t// installed are dropped, and the current one is installed again on the new table.\n\t\t\t\t\tawait transaction.exec(this.dialect.dropTrigger(`${t.blobs}_chunks_delete`, t.blobs));\n\t\t\t\t\tawait transaction.exec(this.dialect.dropTrigger(`${t.blobs}_chunks_delete_all`, t.blobs));\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait transaction.exec(`ALTER TABLE ${t.blobChunks} RENAME TO ${retired}`);\n\t\t\t\t\t\tawait transaction.exec(`ALTER TABLE ${next} RENAME TO ${t.blobChunks}`);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tawait this.confirmRenameBlocker(transaction, error);\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t\tawait transaction.exec(this.dialect.renderTrigger(chunksDeleteTrigger(t)));\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\t// A disk that fills up ends the move, not the collection (#5694): the partial copy is dropped, its pages back on\n\t\t\t\t// the database's free list, and a later collection tries again.\n\t\t\t\tif (offline || !isStorageSpaceFailure(error)) throw error;\n\t\t\t\tawait this.betweenBatches(options.pace);\n\t\t\t\treturn this.dropChunkTable(next, options);\n\t\t\t}\n\t\t\tif (offline) await this.checkpointChunkMove();\n\t\t\tawait this.betweenBatches(options.pace);\n\t\t\tif (moved) break;\n\t\t}\n\t\tawait this.dropChunkTable(retired, options, offline);\n\t}\n\n\t/**\n\t * Records on `error`, a rename that failed in `transaction`, the trigger or view SQLite named in it, when the schema\n\t * holds exactly one trigger or view that the error's words can name (#5622). The failed statement left the\n\t * transaction open on the schema SQLite checked, so that object is the one SQLite named. Otherwise, or when the schema\n\t * cannot be read, nothing is recorded and the collection warning names no object.\n\t */\n\tprivate async confirmRenameBlocker(transaction: SqliteExecutor, error: unknown): Promise<void> {\n\t\tconst candidates = renameBlockerCandidates(error);\n\t\tif (candidates.length === 0) return;\n\t\tconst names = JSON.stringify([...new Set(candidates.map((candidate) => candidate.name))]);\n\t\tconst objects = (schema: string) =>\n\t\t\t`SELECT type, name FROM ${schema} WHERE type IN ('trigger', 'view') AND name IN (SELECT value FROM ${this.dialect.jsonValues(\"?\")})`;\n\t\tconst rows = await transaction\n\t\t\t.all<SqliteRow & SchemaObject>(\n\t\t\t\t`${objects(\"sqlite_master\")} UNION ALL ${objects(\"sqlite_temp_master\")}`,\n\t\t\t\tnames,\n\t\t\t\tnames,\n\t\t\t)\n\t\t\t.catch(() => undefined);\n\t\tif (rows === undefined) return;\n\t\tconst named = rows.filter((row) =>\n\t\t\tcandidates.some((candidate) => candidate.type === row.type && candidate.name === row.name),\n\t\t);\n\t\tconst [only] = named;\n\t\tif (named.length === 1 && only !== undefined && typeof error === \"object\" && error !== null)\n\t\t\tReflect.defineProperty(error, RENAME_BLOCKER, { value: { type: only.type, name: only.name } });\n\t}\n\n\t/**\n\t * Whether the file system of a SQLite database file has room to copy what is left of the chunk table to the\n\t * row layout (#5694): the copy grows the file by the bytes its free pages do not hold, and the write-ahead log can\n\t * hold every page the copy writes until a checkpoint moves them into the file, with\n\t * {@link SNAPSHOT_CHUNK_MOVE_HEADROOM_BYTES} left over; the database's own `freeBytes` says how much the file system\n\t * holds. A database whose disk this process cannot see, such as a libSQL server, moves only what is left of a table\n\t * no larger than that headroom: the move must never be what fills a disk, and the old layout works as before.\n\t */\n\tprivate async chunkCopySpace(next: string, offline: boolean): Promise<PendingChunkMove | undefined> {\n\t\tconst rowsOf = async (table: string) =>\n\t\t\tNumber(\n\t\t\t\t(await this.database.get<SqliteRow & { rows: number }>(`SELECT count(*) AS rows FROM ${table}`))?.rows ?? 0,\n\t\t\t);\n\t\tconst copy = this.dialect.tableExists(next);\n\t\tconst copyExists = async () => (await this.database.get(copy.sql, ...copy.params)) !== undefined;\n\t\t// The chunks the copy lacks, counted in one statement against what it holds: a copy may also hold copies of chunks\n\t\t// deleted since, which take no more room, and chunks stored since that it lacks.\n\t\tconst lacking = async () =>\n\t\t\tNumber(\n\t\t\t\t(\n\t\t\t\t\tawait this.database.get<SqliteRow & { rows: number }>(\n\t\t\t\t\t\t`SELECT count(*) AS rows FROM ${this.tables.blobChunks} AS old WHERE NOT EXISTS (SELECT 1 FROM ${next} AS copy WHERE copy.hash = old.hash AND copy.idx = old.idx)`,\n\t\t\t\t\t)\n\t\t\t\t)?.rows ?? 0,\n\t\t\t);\n\t\tconst rows = !(await copyExists())\n\t\t\t? await rowsOf(this.tables.blobChunks)\n\t\t\t: await lacking().catch(async (error: unknown) => {\n\t\t\t\t\t// Another collector finished the move, which took the copy's name, or dropped the copy, since it was found:\n\t\t\t\t\t// none of it is left to count on. The move's own transactions see which.\n\t\t\t\t\tif (!(await copyExists())) return rowsOf(this.tables.blobChunks);\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\tconst left = rows * SNAPSHOT_BLOB_CHUNK_BYTES;\n\t\tlet free: number | undefined;\n\t\ttry {\n\t\t\tfree = await this.database.freeBytes?.();\n\t\t} catch {\n\t\t\t// A reading that fails is no reading: the collection goes on as for a disk this process cannot see.\n\t\t\tfree = undefined;\n\t\t}\n\t\tif (free === undefined)\n\t\t\treturn !offline && left <= SNAPSHOT_CHUNK_MOVE_HEADROOM_BYTES\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\treason: \"space-unknown\",\n\t\t\t\t\t\tremainingBytes: left,\n\t\t\t\t\t\tautomaticLimitBytes: SNAPSHOT_CHUNK_MOVE_HEADROOM_BYTES,\n\t\t\t\t\t};\n\t\tconst freePages = await this.database.get<SqliteRow & { bytes: number }>(\n\t\t\t\"SELECT (SELECT freelist_count FROM pragma_freelist_count()) * (SELECT page_size FROM pragma_page_size()) AS bytes\",\n\t\t);\n\t\tconst reused = Math.min(left, Number(freePages?.bytes ?? 0));\n\t\tconst requiredFreeBytes =\n\t\t\tleft - reused + (offline ? OFFLINE_CHUNK_LOG_ALLOWANCE : left) + SNAPSHOT_CHUNK_MOVE_HEADROOM_BYTES;\n\t\treturn free >= requiredFreeBytes\n\t\t\t? undefined\n\t\t\t: { reason: \"free-space\", remainingBytes: left, requiredFreeBytes, freeBytes: free };\n\t}\n\n\t/**\n\t * Empties `table`, the chunk table a move to the row layout retired or a partial copy of the move (#5694), in write\n\t * transactions of at most {@link SNAPSHOT_CHUNK_MOVE_ROWS} rows, from its first key on, then drops it; its pages go\n\t * to the database's free list. A full disk stops it without a failure: a later collection goes on.\n\t */\n\tprivate async dropChunkTable(table: string, options: SnapshotIndexOptions, offline = false): Promise<void> {\n\t\tconst probe = this.dialect.tableExists(table);\n\t\tif ((await this.database.get(probe.sql, ...probe.params)) === undefined) return;\n\t\tfor (;;) {\n\t\t\toptions.signal?.throwIfAborted();\n\t\t\tif (offline) await this.requireOfflineBatchSpace();\n\t\t\tlet dropped: boolean;\n\t\t\ttry {\n\t\t\t\tdropped = await this.write(options.pace, async (transaction) => {\n\t\t\t\t\tif (options.holder !== undefined) await this.renewClaim(transaction, options.holder);\n\t\t\t\t\tif ((await transaction.get(probe.sql, ...probe.params)) === undefined) return true;\n\t\t\t\t\tconst last = await transaction.get<SqliteRow & { hash: string; idx: number }>(\n\t\t\t\t\t\t`SELECT hash, idx FROM ${table} ORDER BY hash, idx LIMIT 1 OFFSET ?`,\n\t\t\t\t\t\tSNAPSHOT_CHUNK_MOVE_ROWS - 1,\n\t\t\t\t\t);\n\t\t\t\t\tif (last === undefined) {\n\t\t\t\t\t\tawait transaction.exec(`DROP TABLE IF EXISTS ${table}`);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tawait transaction.run(`DELETE FROM ${table} WHERE (hash, idx) <= (?, ?)`, last.hash, last.idx);\n\t\t\t\t\treturn false;\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tif (!offline && isStorageSpaceFailure(error)) return;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tif (offline) await this.checkpointChunkMove();\n\t\t\tawait this.betweenBatches(options.pace);\n\t\t\tif (dropped) return;\n\t\t}\n\t}\n\n\t/** {@link completeIndex}, then {@link sweep}: what a manual collection does. */\n\tasync collectGarbage(options: SnapshotSweepOptions): Promise<readonly string[]> {\n\t\tawait this.completeIndex(options);\n\t\treturn this.sweep(options);\n\t}\n\n\t/**\n\t * The snapshots the sessions that `sessions` selects keep, a condition on `session_id` (#5530), as a subquery of\n\t * `(session_id, snapshot_id)`: for every leaf of their session trees,\n\t * the latest snapshot entry of each checkout on the leaf's branch, followed through each entry's link to the\n\t * nearest snapshot entry before it. A leaf costs the snapshot entries on its branch and never a message, and leaves\n\t * that share their latest snapshot are followed once. Roots are grouped into checkouts the way resume does: a root\n\t * a restore moved to is the root it moved from, taking the branch's restores from the newest back. Resume compares\n\t * canonical paths where this compares the recorded ones, so a checkout reached through a symbolic link can keep one\n\t * snapshot more than resume needs and never fewer. A head that records a partly restored worktree also keeps the\n\t * snapshot it lacks, named in `degraded_from`, for {@link DEGRADED_RESTORE_RETENTION_DAYS} (#4922).\n\t */\n\tprivate sessionHeads(sessions: string): string {\n\t\tconst t = this.tables;\n\t\treturn `WITH RECURSIVE\n\t\t\topen_anchors(session_id, seq) AS (SELECT DISTINCT session_id, anchor_seq FROM ${t.sessionLinks} WHERE ${sessions} AND children = 0 AND anchor_seq IS NOT NULL),\n\t\t\tbranch(session_id, start_seq, root, snapshot_id, restore_from, restore_to, degraded_from, degraded_since, prev_seq, depth) AS (\n\t\t\t\tSELECT ref.session_id, ref.seq, ref.root, ref.snapshot_id, ref.restore_from, ref.restore_to, ref.degraded_from, ref.degraded_since, ref.prev_seq, 0 FROM open_anchors AS anchor JOIN ${t.sessionRefs} AS ref ON ref.session_id = anchor.session_id AND ref.seq = anchor.seq\n\t\t\t\tUNION ALL\n\t\t\t\tSELECT branch.session_id, branch.start_seq, ref.root, ref.snapshot_id, ref.restore_from, ref.restore_to, ref.degraded_from, ref.degraded_since, ref.prev_seq, branch.depth + 1 FROM branch JOIN ${t.sessionRefs} AS ref ON ref.session_id = branch.session_id AND ref.seq = branch.prev_seq\n\t\t\t),\n\t\t\twalk(session_id, start_seq, root, current, position) AS (\n\t\t\t\tSELECT DISTINCT session_id, start_seq, root, root, -1 FROM branch\n\t\t\t\tUNION ALL\n\t\t\t\tSELECT walk.session_id, walk.start_seq, walk.root, CASE WHEN restore.restore_to = walk.current THEN restore.restore_from ELSE walk.current END, restore.depth\n\t\t\t\tFROM walk JOIN branch AS restore ON restore.session_id = walk.session_id AND restore.start_seq = walk.start_seq AND restore.restore_to IS NOT NULL\n\t\t\t\t\tAND restore.depth = (SELECT min(later.depth) FROM branch AS later WHERE later.session_id = walk.session_id AND later.start_seq = walk.start_seq AND later.restore_to IS NOT NULL AND later.depth > walk.position)\n\t\t\t),\n\t\t\tcheckout(session_id, start_seq, root, original) AS (\n\t\t\t\tSELECT session_id, start_seq, root, current FROM walk AS last WHERE position = (SELECT max(other.position) FROM walk AS other WHERE other.session_id = last.session_id AND other.start_seq = last.start_seq AND other.root = last.root)\n\t\t\t),\n\t\t\tsession_heads(session_id, start_seq, original, depth) AS (\n\t\t\t\tSELECT branch.session_id, branch.start_seq, checkout.original, min(branch.depth) FROM branch JOIN checkout ON checkout.session_id = branch.session_id AND checkout.start_seq = branch.start_seq AND checkout.root = branch.root GROUP BY branch.session_id, branch.start_seq, checkout.original\n\t\t\t),\n\t\t\thead_records(session_id, snapshot_id, degraded_from, degraded_since) AS (\n\t\t\t\tSELECT branch.session_id, branch.snapshot_id, branch.degraded_from, branch.degraded_since FROM session_heads JOIN checkout ON checkout.session_id = session_heads.session_id AND checkout.start_seq = session_heads.start_seq AND checkout.original = session_heads.original JOIN branch ON branch.session_id = checkout.session_id AND branch.start_seq = checkout.start_seq AND branch.root = checkout.root AND branch.depth = session_heads.depth\n\t\t\t)\n\t\t\tSELECT session_id, snapshot_id FROM head_records\n\t\t\tUNION SELECT session_id, degraded_from FROM head_records WHERE degraded_from IS NOT NULL AND (degraded_since IS NULL OR degraded_since > ${this.dialect.nowSeconds} - ${DEGRADED_PIN_SECONDS})`;\n\t}\n\n\t/**\n\t * The next {@link SNAPSHOT_COLLECTION_BATCH} blobs whose `created_at` is at least `minimumAge` whole seconds behind\n\t * the database clock, oldest first, after `after`: a range of the age index, whatever references them. A page after\n\t * `after` searches the index from `after`, which already excludes an unknown age (0): with `created_at > 0` as a\n\t * second lower bound, SQLite searched from the oldest blob instead, so each page cost more than the one before (#5530).\n\t */\n\tprivate page(minimumAge: number, after: PageRow | undefined): Promise<PageRow[]> {\n\t\tconst t = this.tables;\n\t\treturn after === undefined\n\t\t\t? this.database.all<PageRow>(\n\t\t\t\t\t`SELECT created_at, hash FROM ${t.blobs} WHERE created_at > 0 AND created_at <= ${this.dialect.nowSeconds} - ? ORDER BY created_at, hash LIMIT ?`,\n\t\t\t\t\tminimumAge,\n\t\t\t\t\tSNAPSHOT_COLLECTION_BATCH,\n\t\t\t\t)\n\t\t\t: this.database.all<PageRow>(\n\t\t\t\t\t`SELECT created_at, hash FROM ${t.blobs} WHERE created_at <= ${this.dialect.nowSeconds} - ? AND (created_at, hash) > (?, ?) ORDER BY created_at, hash LIMIT ?`,\n\t\t\t\t\tminimumAge,\n\t\t\t\t\tafter.created_at,\n\t\t\t\t\tafter.hash,\n\t\t\t\t\tSNAPSHOT_COLLECTION_BATCH,\n\t\t\t\t);\n\t}\n\n\t/**\n\t * Claims this table's next collection for `holder` when it is due on the database clock: none was ever claimed, or\n\t * the last one finished at least `intervalSeconds` ago, or an unfinished one has renewed its claim in no batch for\n\t * {@link SNAPSHOT_COLLECTION_LEASE_SECONDS}, so it stopped. A failed collection finishes with its error code, so it\n\t * backs off for the whole interval. A read without the write lock answers \"not due\" first; only a due claim takes\n\t * the lock, waiting for it on `pace` when one is given.\n\t */\n\tasync claimCollection(intervalSeconds: number, holder: string, pace?: BackgroundCollectionPace): Promise<boolean> {\n\t\tconst due = `id = 1 AND (claimed_at IS NULL OR (finished_at IS NULL AND claimed_at <= ${this.dialect.nowSeconds} - ?) OR (finished_at IS NOT NULL AND finished_at <= ${this.dialect.nowSeconds} - ?))`;\n\t\tconst lease = SNAPSHOT_COLLECTION_LEASE_SECONDS;\n\t\tif (!(await this.database.get(`SELECT id FROM ${this.tables.collection} WHERE ${due}`, lease, intervalSeconds)))\n\t\t\treturn false;\n\t\tconst { changes } = await this.write(pace, (transaction) =>\n\t\t\ttransaction.run(\n\t\t\t\t`UPDATE ${this.tables.collection} SET claimed_at = ${this.dialect.nowSeconds}, holder = ?, finished_at = NULL, deleted = NULL, error_code = NULL WHERE ${due}`,\n\t\t\t\tholder,\n\t\t\t\tlease,\n\t\t\t\tintervalSeconds,\n\t\t\t),\n\t\t);\n\t\treturn changes === 1;\n\t}\n\n\tprivate renewClaim(transaction: SqliteExecutor, holder: string): Promise<unknown> {\n\t\treturn transaction.run(\n\t\t\t`UPDATE ${this.tables.collection} SET claimed_at = ${this.dialect.nowSeconds} WHERE id = 1 AND holder = ?`,\n\t\t\tholder,\n\t\t);\n\t}\n\n\t/**\n\t * Records how `holder`'s claimed collection ended; a later claim by another holder is left alone. Waits for the\n\t * write lock on `pace` when one is given.\n\t */\n\tasync recordCollection(\n\t\tholder: string,\n\t\toutcome: { readonly deleted: number; readonly errorCode: string | null },\n\t\tpace?: BackgroundCollectionPace,\n\t): Promise<void> {\n\t\tawait this.write(pace, (transaction) =>\n\t\t\ttransaction.run(\n\t\t\t\t`UPDATE ${this.tables.collection} SET finished_at = ${this.dialect.nowSeconds}, deleted = ?, error_code = ? WHERE id = 1 AND holder = ?`,\n\t\t\t\toutcome.deleted,\n\t\t\t\toutcome.errorCode,\n\t\t\t\tholder,\n\t\t\t),\n\t\t);\n\t}\n\n\t/** Waits between two batches: on `pace` in the background, otherwise until the event loop has run once. */\n\tprivate betweenBatches(pace: BackgroundCollectionPace | undefined): Promise<void> {\n\t\treturn pace === undefined ? yieldToEventLoop() : pace.wait(0);\n\t}\n\n\t/**\n\t * Runs `body` in a write transaction. With `pace`, the transaction never waits for a write lock another connection\n\t * holds: it is refused at once (SQLite `StorageWriteLockTimeoutError` or PostgreSQL not-applied `lock-conflict`) and\n\t * tried again after a wait on `pace` that doubles each time, so the process can exit meanwhile; once the waits add\n\t * up to {@link SNAPSHOT_COLLECTION_LEASE_SECONDS}, it rejects with the refusal.\n\t */\n\tprivate async write<T>(\n\t\tpace: BackgroundCollectionPace | undefined,\n\t\tbody: (transaction: SqliteExecutor) => Promise<T>,\n\t): Promise<T> {\n\t\tif (pace === undefined) return this.database.transaction(body);\n\t\tlet waited = 0;\n\t\tfor (let delay = SNAPSHOT_COLLECTION_LOCK_RETRY_FIRST_MS; ; ) {\n\t\t\ttry {\n\t\t\t\treturn await this.database.transaction(body, { lockWaitMs: 0 });\n\t\t\t} catch (error) {\n\t\t\t\tconst lockRefused =\n\t\t\t\t\terror instanceof StorageWriteLockTimeoutError ||\n\t\t\t\t\t(error instanceof StorageTransientError &&\n\t\t\t\t\t\terror.code === \"lock-conflict\" &&\n\t\t\t\t\t\terror.outcome === \"not-applied\");\n\t\t\t\tif (!lockRefused || waited >= SNAPSHOT_COLLECTION_LEASE_SECONDS * 1_000) throw error;\n\t\t\t}\n\t\t\tawait pace.wait(delay);\n\t\t\tpace.signal?.throwIfAborted();\n\t\t\twaited += delay;\n\t\t\tdelay = Math.min(delay * 2, SNAPSHOT_COLLECTION_LOCK_RETRY_MAX_MS);\n\t\t}\n\t}\n}\n"]}
|