@bastani/atomic 0.10.11-alpha.3 → 0.10.11-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/_shared/dist-KOELCESV.js +2 -2
  3. package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
  4. package/dist/_shared/lib-4PES5P4V.js +2 -2
  5. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +4 -4
  6. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +4 -4
  7. package/dist/_shared/mode-shared-2QJSCUM6.js +4 -4
  8. package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
  9. package/dist/_shared/p1b-elig-TVB5CBLL.js +22 -6
  10. package/dist/_shared/p1b-elig-TVB5CBLL.js.map +1 -1
  11. package/dist/_shared/p2-shell-main-B2WIALFD.js +6 -3
  12. package/dist/_shared/p2-shell-main-B2WIALFD.js.map +1 -1
  13. package/dist/_shared/runtime-O4KCSG4C.js +2 -2
  14. package/dist/_shared/sdk-B5LEWGGI.js +899 -515
  15. package/dist/_shared/sdk-B5LEWGGI.js.map +1 -1
  16. package/dist/_shared/session-data-AHTU7IS6.js +2 -2
  17. package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
  18. package/dist/_shared/{startup-0-0-EZUKEP4Q.js → startup-0-0-XJJDOIEC.js} +6 -12
  19. package/dist/_shared/{startup-0-0-EZUKEP4Q.js.map → startup-0-0-XJJDOIEC.js.map} +1 -1
  20. package/dist/_shared/{startup-0-1-RTOHJFDJ.js → startup-0-1-M6OWAYHH.js} +354 -103
  21. package/dist/_shared/startup-0-1-M6OWAYHH.js.map +1 -0
  22. package/dist/_shared/startup-0-2-5QHPCEON.js +18 -9
  23. package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -1
  24. package/dist/_shared/startup-0-3-4ZYBYQNM.js +4 -4
  25. package/dist/_shared/startup-0-4-ZMJV547D.js +4 -4
  26. package/dist/_shared/startup-0-5-YDW47QX6.js +4 -4
  27. package/dist/_shared/startup-10-0-TDQNBDDL.js +4 -4
  28. package/dist/_shared/startup-12-0-55AAXBJZ.js +1 -1
  29. package/dist/_shared/startup-14-0-MLX36RBG.js +2 -2
  30. package/dist/_shared/startup-15-0-YUKGAC63.js +2 -2
  31. package/dist/_shared/startup-15-1-4S7FLMNG.js +4 -4
  32. package/dist/_shared/startup-8-0-34CBHPZH.js +2114 -235
  33. package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
  34. package/dist/_shared/startup-8-1-LZFXSD3Z.js +12 -12
  35. package/dist/_shared/storage-command-7MGXLJGZ.js +6 -6
  36. package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
  37. package/dist/_shared/storage-status-K7PX2RXA.js +2 -2
  38. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  39. package/dist/_shared/team-DOQKICG2.js +1 -1
  40. package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
  41. package/dist/builtin/intercom/CHANGELOG.md +19 -0
  42. package/dist/builtin/intercom/broker/broker.bundle.mjs +1020 -108
  43. package/dist/builtin/intercom/broker/client.ts +8 -0
  44. package/dist/builtin/intercom/broker/database-wake-up-bus.ts +91 -14
  45. package/dist/builtin/intercom/broker/multinode-router.ts +102 -17
  46. package/dist/builtin/intercom/broker/multinode-state-store.ts +41 -2
  47. package/dist/builtin/intercom/broker/send-order-gate.ts +5 -2
  48. package/dist/builtin/intercom/broker/sql-add-column.ts +22 -1
  49. package/dist/builtin/intercom/broker/sql-lease-store.ts +304 -48
  50. package/dist/builtin/intercom/broker/sql-outbox-store.ts +541 -50
  51. package/dist/builtin/intercom/broker/sql-restoring-reservation-store.ts +239 -8
  52. package/dist/builtin/intercom/broker/sql-retention.ts +11 -2
  53. package/dist/builtin/intercom/broker/sql-schema.ts +42 -8
  54. package/dist/builtin/intercom/index.bundle.mjs +13 -2
  55. package/dist/builtin/intercom/package.json +1 -1
  56. package/dist/builtin/mcp/index.bundle.mjs +1 -1
  57. package/dist/builtin/mcp/package.json +1 -1
  58. package/dist/builtin/subagents/CHANGELOG.md +6 -0
  59. package/dist/builtin/subagents/package.json +1 -1
  60. package/dist/builtin/subagents/skills/skill-creator/eval-viewer/generate_review.py +8 -1
  61. package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
  62. package/dist/builtin/web-access/index.bundle.mjs +1 -1
  63. package/dist/builtin/web-access/package.json +1 -1
  64. package/dist/cli/args.js +2 -2
  65. package/dist/cli/auth-cli.code.js +2 -2
  66. package/dist/cli/auth-cli.impl.js +3 -3
  67. package/dist/cli/auth-cli.js +3 -3
  68. package/dist/cli/blueprint-command.code.js +1 -1
  69. package/dist/cli/blueprint-command.impl.js +3 -3
  70. package/dist/cli/blueprint-command.js +3 -3
  71. package/dist/cli/intercom-command.code.js +2 -2
  72. package/dist/cli/intercom-command.impl.js +3 -3
  73. package/dist/cli/intercom-command.js +3 -3
  74. package/dist/cli/list-models.code.js +2 -2
  75. package/dist/cli/list-models.impl.js +3 -3
  76. package/dist/cli/list-models.js +3 -3
  77. package/dist/cli/session-picker.code.js +1 -1
  78. package/dist/cli/session-picker.impl.js +3 -3
  79. package/dist/cli/session-picker.js +3 -3
  80. package/dist/cli/startup-ui.code.js +1 -1
  81. package/dist/cli/startup-ui.impl.js +3 -3
  82. package/dist/cli/startup-ui.js +3 -3
  83. package/dist/cli/storage-command.impl.js +3 -3
  84. package/dist/cli/storage-command.js +3 -3
  85. package/dist/cli/storage-search-session.code.js +1 -1
  86. package/dist/cli/storage-search-session.impl.js +3 -3
  87. package/dist/cli/storage-search-session.js +3 -3
  88. package/dist/cli/team-command.code.js +1 -1
  89. package/dist/cli/team-command.impl.js +3 -3
  90. package/dist/cli/team-command.js +3 -3
  91. package/dist/cli.js +2 -2
  92. package/dist/core/debug.impl.js +3 -3
  93. package/dist/core/debug.js +3 -3
  94. package/dist/core/export-html/card-projection.impl.js +3 -3
  95. package/dist/core/export-html/card-projection.js +3 -3
  96. package/dist/core/export-html/index.code.js +4 -4
  97. package/dist/core/export-html/index.code.js.map +1 -1
  98. package/dist/core/export-html/index.impl.js +3 -3
  99. package/dist/core/export-html/index.js +3 -3
  100. package/dist/core/export-html/json-spans.impl.js +3 -3
  101. package/dist/core/export-html/json-spans.js +3 -3
  102. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  103. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  104. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  105. package/dist/core/export-html/tool-renderer.js +3 -3
  106. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  107. package/dist/core/extensions/jiti-loader.js +3 -3
  108. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  109. package/dist/core/extensions/jiti-static-loader.js +3 -3
  110. package/dist/core/extensions/loader-host-modules.code.js +1 -1
  111. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  112. package/dist/core/extensions/loader-host-modules.js +3 -3
  113. package/dist/core/extensions/loader-virtual-modules.js +1 -1
  114. package/dist/core/extensions/runner-context.js +1 -1
  115. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  116. package/dist/core/intercom-broker-control-host.js +3 -3
  117. package/dist/core/intercom-broker-control.code.js +3 -3
  118. package/dist/core/intercom-broker-control.impl.js +3 -3
  119. package/dist/core/intercom-broker-control.js +3 -3
  120. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  121. package/dist/core/package-manager-storage-adapters.js +3 -3
  122. package/dist/core/process-start-token.d.ts +5 -4
  123. package/dist/core/sdk.code.js +2 -2
  124. package/dist/core/sdk.impl.js +3 -3
  125. package/dist/core/sdk.js +3 -3
  126. package/dist/core/session-manager-core.js +4 -4
  127. package/dist/core/session-manager-list.impl.js +3 -3
  128. package/dist/core/session-manager-list.js +3 -3
  129. package/dist/core/session-manager.code.js +1 -1
  130. package/dist/core/session-manager.impl.js +3 -3
  131. package/dist/core/session-manager.js +3 -3
  132. package/dist/core/session-storage.impl.js +3 -3
  133. package/dist/core/session-storage.js +3 -3
  134. package/dist/core/storage/database.d.ts +6 -0
  135. package/dist/core/storage/database.js.map +1 -1
  136. package/dist/core/storage/fenced-paths.d.ts +7 -6
  137. package/dist/core/storage/fenced-paths.js +7 -6
  138. package/dist/core/storage/fenced-paths.js.map +1 -1
  139. package/dist/core/storage/index.js +2 -2
  140. package/dist/core/storage/node-sqlite-thread.js +209 -19
  141. package/dist/core/storage/node-sqlite-thread.js.map +1 -1
  142. package/dist/core/storage/node-sqlite.js +435 -71
  143. package/dist/core/storage/node-sqlite.js.map +1 -1
  144. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  145. package/dist/core/storage/offline-snapshot-file.js +3 -3
  146. package/dist/core/storage/provider.js +2 -2
  147. package/dist/core/storage/schema-catalog.d.ts +69 -7
  148. package/dist/core/storage/schema-catalog.js +352 -61
  149. package/dist/core/storage/schema-catalog.js.map +1 -1
  150. package/dist/core/storage/selection.js +2 -2
  151. package/dist/core/storage/session/branch-fork-source.code.js +2 -2
  152. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  153. package/dist/core/storage/session/branch-fork-source.js +3 -3
  154. package/dist/core/storage/session/card-view.impl.js +3 -3
  155. package/dist/core/storage/session/card-view.js +3 -3
  156. package/dist/core/storage/session/child-reader.code.js +3 -3
  157. package/dist/core/storage/session/child-reader.impl.js +3 -3
  158. package/dist/core/storage/session/child-reader.js +3 -3
  159. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  160. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  161. package/dist/core/storage/session/expanded-child-details.code.js +2 -2
  162. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  163. package/dist/core/storage/session/expanded-child-details.js +3 -3
  164. package/dist/core/storage/session/fork-detach.d.ts +11 -1
  165. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  166. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  167. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  168. package/dist/core/storage/session/fork-row-index.js +3 -3
  169. package/dist/core/storage/session/fork-staging.code.js +1 -1
  170. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  171. package/dist/core/storage/session/fork-staging.js +3 -3
  172. package/dist/core/storage/session/fork-sweep.js +31 -7
  173. package/dist/core/storage/session/fork-sweep.js.map +1 -1
  174. package/dist/core/storage/session/fork-window.code.js +3 -3
  175. package/dist/core/storage/session/fork-window.impl.js +3 -3
  176. package/dist/core/storage/session/fork-window.js +3 -3
  177. package/dist/core/storage/session/history-pages.impl.js +3 -3
  178. package/dist/core/storage/session/history-pages.js +3 -3
  179. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  180. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  181. package/dist/core/storage/session/jsonl-session-lock.d.ts +100 -0
  182. package/dist/core/storage/session/jsonl-session-store.d.ts +41 -23
  183. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  184. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  185. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  186. package/dist/core/storage/session/memory-session-store.js +3 -3
  187. package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
  188. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  189. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  190. package/dist/core/storage/session/released-history-files.code.js +8 -8
  191. package/dist/core/storage/session/released-history-files.code.js.map +1 -1
  192. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  193. package/dist/core/storage/session/released-history-files.js +3 -3
  194. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  195. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  196. package/dist/core/storage/session/session-resume.impl.js +3 -3
  197. package/dist/core/storage/session/session-resume.js +3 -3
  198. package/dist/core/storage/session/session-search-index.d.ts +9 -1
  199. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  200. package/dist/core/storage/session/snapshot-cut.js +3 -3
  201. package/dist/core/storage/session/snapshot-history.code.js +3 -3
  202. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  203. package/dist/core/storage/session/snapshot-history.js +3 -3
  204. package/dist/core/storage/session/sql-session-store.d.ts +51 -7
  205. package/dist/core/storage/session/sql-session-store.impl.js +3 -3
  206. package/dist/core/storage/session/sql-session-store.js +3 -3
  207. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  208. package/dist/core/storage/session/tree-outline.js +3 -3
  209. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  210. package/dist/core/storage/session/tree-presentation.js +3 -3
  211. package/dist/core/storage/sqlite-facade.d.ts +6 -0
  212. package/dist/core/storage/sqlite-facade.js +309 -33
  213. package/dist/core/storage/sqlite-facade.js.map +1 -1
  214. package/dist/core/storage/sqlite-open-batch.js +10 -0
  215. package/dist/core/storage/sqlite-open-batch.js.map +1 -0
  216. package/dist/core/storage/storage-status.impl.js +3 -3
  217. package/dist/core/storage/storage-status.js +3 -3
  218. package/dist/core/storage/team.impl.js +3 -3
  219. package/dist/core/storage/team.js +3 -3
  220. package/dist/core/structured-output/index.impl.js +3 -3
  221. package/dist/core/structured-output/index.js +3 -3
  222. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  223. package/dist/core/tasks/task-completion-entry.js +3 -3
  224. package/dist/core/tasks/task-file-history.code.js +3 -3
  225. package/dist/core/tasks/task-file-history.impl.js +3 -3
  226. package/dist/core/tasks/task-file-history.js +3 -3
  227. package/dist/core/tasks/task-reference-archive.code.js +3 -3
  228. package/dist/core/tasks/task-reference-archive.js +3 -3
  229. package/dist/core/tasks/task-reference-identity.js +3 -3
  230. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  231. package/dist/core/tasks/task-reference-stream.js +3 -3
  232. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  233. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  234. package/dist/core/tasks/task-view-source.impl.js +3 -3
  235. package/dist/core/tasks/task-view-source.js +3 -3
  236. package/dist/core/tools/read-url.code.js +2 -2
  237. package/dist/core/tools/read-url.impl.js +3 -3
  238. package/dist/core/tools/read-url.js +3 -3
  239. package/dist/core/worktree-snapshot/blob-store.d.ts +5 -3
  240. package/dist/core/worktree-snapshot/blob-store.js +151 -21
  241. package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
  242. package/dist/core/worktree-snapshot/errors.code.js +2 -2
  243. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  244. package/dist/core/worktree-snapshot/errors.js +3 -3
  245. package/dist/core/worktree-snapshot/fork-snapshot-index.js +158 -41
  246. package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -1
  247. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  248. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  249. package/dist/extensions/codemode/execute.code.js +1 -1
  250. package/dist/extensions/codemode/execute.impl.js +3 -3
  251. package/dist/extensions/codemode/execute.js +3 -3
  252. package/dist/extensions/codemode/renderer.code.js +1 -1
  253. package/dist/extensions/codemode/renderer.impl.js +3 -3
  254. package/dist/extensions/codemode/renderer.js +3 -3
  255. package/dist/extensions/mcp/cli.code.js +1 -1
  256. package/dist/extensions/mcp/cli.impl.js +3 -3
  257. package/dist/extensions/mcp/cli.js +3 -3
  258. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  259. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  260. package/dist/extensions/mcp/cli.lazy.js +3 -3
  261. package/dist/extensions/mcp/runtime.impl.js +3 -3
  262. package/dist/extensions/mcp/runtime.js +3 -3
  263. package/dist/index.js +2 -2
  264. package/dist/main-first-time-setup.code.js +1 -1
  265. package/dist/main-first-time-setup.impl.js +3 -3
  266. package/dist/main-first-time-setup.js +3 -3
  267. package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
  268. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  269. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  270. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  271. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  272. package/dist/package-manager-cli.code.js +4 -4
  273. package/dist/package-manager-cli.impl.js +3 -3
  274. package/dist/package-manager-cli.js +3 -3
  275. package/dist/rpc-entry.js +1 -1
  276. package/dist/startup-files.json +1 -1
  277. package/dist/startup-stages/3.js +1 -1
  278. package/dist/startup-stages/5.js +1 -1
  279. package/dist/utils/startup-database-spare.code.js +2 -2
  280. package/dist/utils/startup-database-spare.impl.js +3 -3
  281. package/dist/utils/startup-database-spare.js +3 -3
  282. package/dist/utils/tools-manager.code.js +1 -1
  283. package/dist/utils/tools-manager.impl.js +3 -3
  284. package/dist/utils/tools-manager.js +3 -3
  285. package/docs/changelog.mdx +49 -0
  286. package/docs/storage/jsonl.md +3 -3
  287. package/package.json +8 -8
  288. package/dist/_shared/startup-0-1-RTOHJFDJ.js.map +0 -1
@@ -1,10 +1,11 @@
1
1
  import { storageSchemaCurrent, transactionFinisher } from "../storage/added-exports.js";
2
- import { noteStorageSchemaTables } from "../storage/added-exports-0-10-11.js";
2
+ import { MAX_SEQUENCE_REQUEST_STATEMENTS, noteStorageSchemaTables } from "../storage/added-exports-0-10-11.js";
3
3
  import { dialectOf } from "../storage/dialect.js";
4
4
  import { StorageWriteLockTimeoutError } from "../storage/errors.js";
5
5
  import { applyStorageMigrations, ensureStorageSchema, withShortSchemaLockWaits } from "../storage/migrations.js";
6
6
  import { renderStorageIdentifiers, storageMigrationTable, validateStoragePrefix } from "../storage/prefix.js";
7
- import { schemaCatalogOf } from "../storage/schema-catalog.js";
7
+ import { schemaCatalogOf, withStorageSchemaCatalog } from "../storage/schema-catalog.js";
8
+ import { queueSqliteSchemaSetup } from "../storage/sqlite-open-batch.js";
8
9
  import { statementBatch } from "../storage/statement-batches.js";
9
10
  import { forkInheritedBlobGuard, forkInheritedBlobGuardName } from "./fork-blob-guard.js";
10
11
  import { entriesIndexComplete, forkLinksCheck, forkSegmentsTable, forkSessionLink, legacyForkLinksTriggerName, materializedForkLinks, ownDuplicate, ownParentSeq, parentColumns, snapshotEntryCondition, } from "./fork-snapshot-index.js";
@@ -810,18 +811,23 @@ export function sessionEntryLinks(prefix, dialect, forkSegments) {
810
811
  const source = indexSources(prefix, t, dialect, forkSegments).find((source) => source.name === "session-entries");
811
812
  const linking = entryLinking(source, dialect, t.sessionLinks);
812
813
  const complete = entriesIndexComplete(t.sources);
813
- // The rows to check, from their links, which name each entry's id and its parent's, so no entry's JSON is parsed. A
814
- // link without a parent is taken for a root: one whose parent is a value of another type, which no store writes, is
815
- // linked broken, so the check finds it and the session is linked again row by row, from its JSON. A snapshot entry
816
- // is its own anchor, as no other entry is.
817
- const linked = `(SELECT l.session_id, l.seq, l.entry_id, l.parent_id, CASE WHEN l.parent_id IS NOT NULL THEN 'text' ELSE 'null' END AS parent_type, l.anchor_seq AS own_anchor FROM ${t.sessionLinks} AS l WHERE l.session_id = ? AND l.seq >= ?)`;
818
- const check = forkLinksCheck({ links: t.sessionLinks, segments: forkSegments, refs: t.sessionRefs }, linked, "r.own_anchor = r.seq", complete);
814
+ const tables = { links: t.sessionLinks, segments: forkSegments, refs: t.sessionRefs };
815
+ const materializePlain = dialect.name === "postgres";
816
+ const checkWithSegments = forkLinksCheck(tables, complete, { hasSegments: true });
817
+ const checkWithoutSegments = forkLinksCheck(tables, complete, {
818
+ hasSegments: false,
819
+ materialize: materializePlain,
820
+ });
819
821
  return {
820
- materialized: materializedForkLinks(t.sessionLinks, forkSegments, complete, dialect.types.int),
821
- async settle(executor, sessionId, fromSeq, before) {
822
+ materialized: materializedForkLinks(t.sessionLinks, forkSegments, complete, dialect.types.int, dialect.name),
823
+ async settle(executor, sessionId, fromSeq, before, hasSegments = true) {
822
824
  const [, verdict] = await Promise.all([
823
825
  runInOrder(executor, before),
824
- executor.get(check, sessionId, fromSeq, sessionId, fromSeq, sessionId, fromSeq),
826
+ hasSegments
827
+ ? executor.get(checkWithSegments, sessionId, sessionId, fromSeq, sessionId, fromSeq)
828
+ : materializePlain
829
+ ? executor.get(checkWithoutSegments, sessionId, fromSeq, sessionId, fromSeq)
830
+ : executor.get(checkWithoutSegments, sessionId, fromSeq, sessionId, fromSeq, sessionId, fromSeq),
825
831
  ]);
826
832
  if (verdict === undefined)
827
833
  return;
@@ -1307,11 +1313,16 @@ export class SqlSnapshotBlobStore {
1307
1313
  /**
1308
1314
  * Opens the blob table and its reference index, creating the tables that are missing in their own transaction, such
1309
1315
  * as those an index written by an earlier build lacks, and indexes referencing tables created since. A store whose
1310
- * tables and index exist opens without the write lock.
1316
+ * tables and index exist opens without the write lock. On SQLite inside an open scope (`withStorageSchemaCatalog`),
1317
+ * table creation and index installation queue into the open's single write transaction (#6709).
1311
1318
  */
1312
- static async open(database, prefix = "") {
1319
+ static open(database, prefix = "") {
1320
+ return withStorageSchemaCatalog(database, storageMigrationTable(prefix), () => SqlSnapshotBlobStore.openWithCatalog(database, prefix));
1321
+ }
1322
+ static async openWithCatalog(database, prefix) {
1313
1323
  const t = snapshotIndexTables(prefix);
1314
1324
  const dialect = dialectOf(database);
1325
+ const ledger = storageMigrationTable(prefix);
1315
1326
  const columns = [
1316
1327
  [t.blobs, "created_at"],
1317
1328
  [t.blobs, "chunks"],
@@ -1323,6 +1334,9 @@ export class SqlSnapshotBlobStore {
1323
1334
  ...columns.map(([table, column]) => dialect.columnExists(table, column)),
1324
1335
  dialect.schemaObjects(triggers),
1325
1336
  ];
1337
+ const tablesPresent = (found) => Object.values(t).every((table) => found.hasTable(table)) &&
1338
+ columns.every(([table, column]) => found.hasColumn(table, column)) &&
1339
+ triggers.some((trigger) => found.hasObject(trigger));
1326
1340
  // One catalog read answers the schema questions where an open read it (#6560): always on Postgres, at the first
1327
1341
  // question on SQLite.
1328
1342
  const catalog = await schemaCatalogOf(database);
@@ -1338,10 +1352,122 @@ export class SqlSnapshotBlobStore {
1338
1352
  const current = dialect.versionedMigrations
1339
1353
  ? false
1340
1354
  : catalog !== undefined
1341
- ? Object.values(t).every((table) => catalog.hasTable(table)) &&
1342
- columns.every(([table, column]) => catalog.hasColumn(table, column)) &&
1343
- triggers.some((trigger) => catalog.hasObject(trigger))
1355
+ ? tablesPresent(catalog)
1344
1356
  : (await Promise.all(probes.map((probe) => database.get(probe.sql, ...probe.params)))).every((row) => row !== undefined);
1357
+ // On SQLite inside an open scope, when the snapshot tables are missing or incomplete, queue both table creation
1358
+ // and source index trigger installation into the open's single write transaction without reading uncommitted tables
1359
+ // beforehand (#6709).
1360
+ if (!current && !dialect.versionedMigrations && catalog !== undefined) {
1361
+ const needsReset = catalog.hasTable(t.sessionLinks) || catalog.hasTable(t.sessionRefs) || catalog.hasTable(t.sessionRecords);
1362
+ const reset = needsReset ? await SqlSnapshotBlobStore.prepareSessionIndexReset(database) : undefined;
1363
+ const store = new SqlSnapshotBlobStore(database, dialect, t, indexSources(prefix, t, dialect, (await shared) ? segments : undefined), segments);
1364
+ const enqueueFreshTables = (ctx, sharedNow) => {
1365
+ const { int, text, blob } = dialect.types;
1366
+ const strict = dialect.tableOptions;
1367
+ const keyed = dialect.withoutRowidTableOptions;
1368
+ const guard = sharedNow ? [forkInheritedBlobGuard(dialect, t, segments).replace(/;\s*$/, "")] : [];
1369
+ ctx.enqueue(`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}`);
1370
+ ctx.enqueue(`
1371
+ CREATE TABLE IF NOT EXISTS ${t.runRefs} (run_id ${text} NOT NULL, hash ${text} NOT NULL, PRIMARY KEY (run_id, hash))${keyed};
1372
+ CREATE INDEX IF NOT EXISTS ${t.runRefs}_hash ON ${t.runRefs} (hash);
1373
+ CREATE TABLE IF NOT EXISTS ${t.runState} (run_id ${text} PRIMARY KEY, retained ${int} NOT NULL, seq ${int} NOT NULL)${keyed};
1374
+ CREATE 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};
1375
+ CREATE 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};
1376
+ CREATE INDEX IF NOT EXISTS ${t.sessionLinks}_entry ON ${t.sessionLinks} (session_id, entry_id);
1377
+ ${sessionLinksLeafIndex(t, dialect)};
1378
+ CREATE INDEX IF NOT EXISTS ${t.sessionLinks}_broken ON ${t.sessionLinks} (session_id) WHERE broken = 1;
1379
+ CREATE 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};
1380
+ CREATE INDEX IF NOT EXISTS ${t.sessionRecords}_hash ON ${t.sessionRecords} (hash);
1381
+ CREATE TABLE IF NOT EXISTS ${t.carriedRefs} (owner ${text} NOT NULL, hash ${text} NOT NULL, PRIMARY KEY (owner, hash))${keyed};
1382
+ CREATE INDEX IF NOT EXISTS ${t.carriedRefs}_hash ON ${t.carriedRefs} (hash);
1383
+ CREATE 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};
1384
+ INSERT INTO ${t.collection} (id) VALUES (1) ON CONFLICT DO NOTHING;
1385
+ CREATE TABLE IF NOT EXISTS ${t.sources} (source ${text} PRIMARY KEY, watermark ${int} NOT NULL, backfilled_through ${int} NOT NULL)${keyed};
1386
+ ${guard.map((statement) => `${statement};`).join("\n")}
1387
+ `);
1388
+ ctx.enqueue(chunkTableDefinition(t.blobChunks, dialect));
1389
+ for (const write of [...blobChunkWrites(t, dialect, [false, false]), ...blobMaintenanceIndexes(t)]) {
1390
+ if (write !== false && write !== undefined)
1391
+ ctx.enqueue(write);
1392
+ }
1393
+ for (const table of Object.values(t))
1394
+ ctx.noteTableCreated(table);
1395
+ };
1396
+ const queued = queueSqliteSchemaSetup(database, ledger, {
1397
+ done: async (freshCatalog) => {
1398
+ if (!tablesPresent(freshCatalog))
1399
+ return false;
1400
+ const sharedNow = freshCatalog.hasTable(segments);
1401
+ if (sharedNow && !freshCatalog.hasObject(forkInheritedBlobGuardName(t.blobs)))
1402
+ return false;
1403
+ const sourcesNow = indexSources(prefix, t, dialect, sharedNow ? segments : undefined);
1404
+ const legacy = store.legacyForkLinks();
1405
+ const foundLegacy = new Set();
1406
+ const states = await readSourceStates(database, dialect, t, sourcesNow, false, undefined, legacy && { names: [legacy.name], found: foundLegacy });
1407
+ if (legacy !== undefined && foundLegacy.has(legacy.name))
1408
+ return false;
1409
+ if (states.some((state) => !state.installed && !state.deferred))
1410
+ return false;
1411
+ store.sources = sourcesNow;
1412
+ return true;
1413
+ },
1414
+ run: async (ctx) => {
1415
+ const sharedNow = ctx.tableExisted(segments) || ctx.createdTable(segments);
1416
+ store.sources = indexSources(prefix, t, dialect, sharedNow ? segments : undefined);
1417
+ const anyTableExisted = Object.values(t).some((table) => ctx.tableExisted(table));
1418
+ const tablesAlreadyCurrent = ctx.catalog !== undefined && tablesPresent(ctx.catalog);
1419
+ const guardName = forkInheritedBlobGuardName(t.blobs);
1420
+ if (!tablesAlreadyCurrent) {
1421
+ if (ctx.catalog !== undefined && !anyTableExisted) {
1422
+ enqueueFreshTables(ctx, sharedNow);
1423
+ }
1424
+ else {
1425
+ await ctx.flushWrites();
1426
+ await createSnapshotIndexTables(ctx.tx, t, prefix, dialect, sharedNow ? [forkInheritedBlobGuard(dialect, t, segments).replace(/;\s*$/, "")] : []);
1427
+ for (const table of Object.values(t))
1428
+ ctx.noteTableCreated(table);
1429
+ }
1430
+ }
1431
+ else if (sharedNow && ctx.catalog?.hasObject(guardName) !== true) {
1432
+ ctx.enqueue(forkInheritedBlobGuard(dialect, t, segments));
1433
+ }
1434
+ // Install snapshot index triggers in the same transaction. When no referencing table or progress table
1435
+ // existed before this transaction, only newly created tables (empty, watermark 0) need triggers.
1436
+ const existingSources = store.sources.filter((source) => ctx.tableExisted(source.table));
1437
+ if (!ctx.tableExisted(t.sources) && existingSources.length === 0) {
1438
+ for (const source of store.sources) {
1439
+ if (!ctx.createdTable(source.table))
1440
+ continue;
1441
+ ctx.enqueue(source.triggers.map((trigger) => dialect.renderTrigger(trigger)).join("\n"));
1442
+ ctx.enqueue({
1443
+ sql: `INSERT INTO ${t.sources} (source, watermark, backfilled_through) VALUES (?, 0, 0) ${REPLACE_PROGRESS}`,
1444
+ params: [source.name],
1445
+ });
1446
+ if (source.own !== undefined)
1447
+ ctx.enqueue({
1448
+ sql: `INSERT INTO ${t.sources} (source, watermark, backfilled_through) VALUES (?, 0, 0) ${REPLACE_PROGRESS}`,
1449
+ params: [source.own],
1450
+ });
1451
+ if (source.version !== undefined)
1452
+ ctx.enqueue(publishVersion(t, source));
1453
+ }
1454
+ return;
1455
+ }
1456
+ await ctx.flushWrites();
1457
+ const legacy = store.legacyForkLinks();
1458
+ const foundLegacy = new Set();
1459
+ const states = await readSourceStates(ctx.tx, dialect, t, store.sources, false, undefined, legacy && { names: [legacy.name], found: foundLegacy });
1460
+ if (legacy !== undefined && foundLegacy.has(legacy.name))
1461
+ await ctx.tx.exec(dialect.dropTrigger(legacy.name, legacy.table, true));
1462
+ for (const { source, installed, deferred } of states) {
1463
+ if (!installed && !deferred)
1464
+ await installSource(ctx.tx, dialect, t, source, reset);
1465
+ }
1466
+ },
1467
+ });
1468
+ if (queued)
1469
+ return store;
1470
+ }
1345
1471
  // A versioned database always checks its ledger: a newer schema with the same tables is refused, and a step it
1346
1472
  // lacks, such as the index triggers, runs even when every table exists.
1347
1473
  // Whether this open created the tables on PostgreSQL, and with them the links indexes of {@link hotSessionLinks}.
@@ -1392,7 +1518,7 @@ export class SqlSnapshotBlobStore {
1392
1518
  },
1393
1519
  ]
1394
1520
  : []),
1395
- ], { table: storageMigrationTable(prefix) });
1521
+ ], { table: ledger });
1396
1522
  // The session store's open, which asks the catalog for the guard next, finds it without reading the schema again.
1397
1523
  if (migrated.applied.includes(1) && (await shared))
1398
1524
  noteStorageSchemaTables(database, [forkInheritedBlobGuardName(t.blobs)]);
@@ -1536,8 +1662,10 @@ export class SqlSnapshotBlobStore {
1536
1662
  const chunk = `INSERT INTO ${this.tables.blobChunks} (hash, idx, data) SELECT ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM ${this.table} WHERE hash = ?) ON CONFLICT DO NOTHING`;
1537
1663
  const statements = [];
1538
1664
  let chunked = false;
1665
+ let totalBytes = 0;
1539
1666
  for (const blob of blobs) {
1540
1667
  const { hash, data } = blob;
1668
+ totalBytes += data.byteLength;
1541
1669
  if (data.byteLength <= SNAPSHOT_BLOB_CHUNK_BYTES) {
1542
1670
  statements.push({ sql: header, params: [hash, data.byteLength, data, 0] });
1543
1671
  continue;
@@ -1554,13 +1682,14 @@ export class SqlSnapshotBlobStore {
1554
1682
  await this.database.batch(statements);
1555
1683
  return;
1556
1684
  }
1685
+ const lead = statements.length < MAX_SEQUENCE_REQUEST_STATEMENTS && totalBytes <= SNAPSHOT_BLOB_CHUNK_BYTES;
1557
1686
  await this.database.transaction(async (transaction) => {
1558
1687
  // On a pipelined connection the statements go out with the commit: one round trip after the locks.
1559
1688
  if (transactionFinisher(transaction)?.(statements) === true)
1560
1689
  return;
1561
1690
  for (const statement of statements)
1562
1691
  await transaction.run(statement.sql, ...statement.params);
1563
- }, this.blobWrite());
1692
+ }, this.blobWrite(lead ? statements : undefined, lead));
1564
1693
  }
1565
1694
  /**
1566
1695
  * How a put or a refresh of this table's blobs runs: a serial transaction of the blob table's own domain (#6560). On
@@ -1570,11 +1699,12 @@ export class SqlSnapshotBlobStore {
1570
1699
  * in hash order, as an append's check of the blobs it records locks them (`missingBlob`), so neither waits on the
1571
1700
  * other in a cycle. Its callback only uses the transaction, so a transient failure runs it again.
1572
1701
  */
1573
- blobWrite(leading) {
1702
+ blobWrite(leading, leadingOnly = false) {
1574
1703
  return {
1575
1704
  retryTransientFailures: true,
1576
1705
  concurrency: { kind: "serial", domain: this.table },
1577
1706
  ...(leading === undefined ? {} : { leading }),
1707
+ ...(leading !== undefined && leadingOnly ? { leadingOnly: true } : {}),
1578
1708
  };
1579
1709
  }
1580
1710
  /**
@@ -2554,7 +2684,7 @@ function __atomicOnDemandFailed(error, feature) {
2554
2684
  return (async () => {
2555
2685
  const root = new URL("../../", import.meta.url);
2556
2686
  const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
2557
- const key = `${root.href}#0.10.11-alpha.3`;
2687
+ const key = `${root.href}#0.10.11-alpha.4`;
2558
2688
  let release = releases.get(key);
2559
2689
  if (release === undefined) {
2560
2690
  const current = (async () => {
@@ -2582,7 +2712,7 @@ function __atomicOnDemandFailed(error, feature) {
2582
2712
  } catch {
2583
2713
  // No installation to read, as in a bundle of the package: the release the process runs decides.
2584
2714
  }
2585
- const updatedTo = typeof installed === "string" && installed !== "0.10.11-alpha.3" ? installed : running !== undefined && running.version !== "0.10.11-alpha.3" ? "0.10.11-alpha.3" : undefined;
2715
+ const updatedTo = typeof installed === "string" && installed !== "0.10.11-alpha.4" ? installed : running !== undefined && running.version !== "0.10.11-alpha.4" ? "0.10.11-alpha.4" : undefined;
2586
2716
  if (updatedTo === undefined) throw error;
2587
2717
  const application = typeof running?.name === "string" ? running.name : "atomic";
2588
2718
  const restart = new Error(`${application} was updated to ${updatedTo} while this session was running; restart it to keep using ${feature}.`, {