@bastani/atomic 0.10.11-alpha.1 → 0.10.11-alpha.2

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 (303) hide show
  1. package/CHANGELOG.md +56 -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 +7 -7
  6. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +7 -7
  7. package/dist/_shared/mode-shared-2QJSCUM6.js +7 -7
  8. package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
  9. package/dist/_shared/runtime-O4KCSG4C.js +5 -5
  10. package/dist/_shared/{sdk-AVFII7NK.js → sdk-IQMULKFU.js} +2438 -470
  11. package/dist/_shared/sdk-IQMULKFU.js.map +1 -0
  12. package/dist/_shared/session-data-AHTU7IS6.js +3 -3
  13. package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
  14. package/dist/_shared/settings-startup-8-DNZ2RIHM.js +1 -1
  15. package/dist/_shared/{settings-startup-4QCVCI53.js → settings-startup-HXQLSUWM.js} +8 -2
  16. package/dist/_shared/settings-startup-HXQLSUWM.js.map +1 -0
  17. package/dist/_shared/{startup-0-0-57KF6LZH.js → startup-0-0-3IXNMFM2.js} +392 -15
  18. package/dist/_shared/startup-0-0-3IXNMFM2.js.map +1 -0
  19. package/dist/_shared/{startup-0-1-GIY75K46.js → startup-0-1-7T2IAE7J.js} +51 -243
  20. package/dist/_shared/startup-0-1-7T2IAE7J.js.map +1 -0
  21. package/dist/_shared/{startup-0-2-27OWFHV6.js → startup-0-2-5QHPCEON.js} +225 -7
  22. package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -0
  23. package/dist/_shared/{startup-0-3-T4DVFYWX.js → startup-0-3-4ZYBYQNM.js} +273 -14
  24. package/dist/_shared/startup-0-3-4ZYBYQNM.js.map +1 -0
  25. package/dist/_shared/startup-0-4-ZMJV547D.js +6 -6
  26. package/dist/_shared/startup-0-5-YDW47QX6.js +7 -7
  27. package/dist/_shared/startup-10-0-TDQNBDDL.js +7 -7
  28. package/dist/_shared/startup-12-0-55AAXBJZ.js +2 -2
  29. package/dist/_shared/startup-14-0-MLX36RBG.js +4 -4
  30. package/dist/_shared/startup-15-0-YUKGAC63.js +5 -5
  31. package/dist/_shared/startup-15-1-4S7FLMNG.js +7 -7
  32. package/dist/_shared/startup-8-0-34CBHPZH.js +421 -84
  33. package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
  34. package/dist/_shared/startup-8-1-X32CYSXB.js +77 -13
  35. package/dist/_shared/startup-8-1-X32CYSXB.js.map +1 -1
  36. package/dist/_shared/storage-command-7MGXLJGZ.js +7 -5
  37. package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
  38. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  39. package/dist/_shared/tree-outline-MUEPK5B7.js +3 -3
  40. package/dist/builtin/intercom/CHANGELOG.md +11 -0
  41. package/dist/builtin/intercom/broker/broker.bundle.mjs +205 -82
  42. package/dist/builtin/intercom/broker/sql-lease-store.ts +38 -27
  43. package/dist/builtin/intercom/broker/sql-outbox-store.ts +228 -65
  44. package/dist/builtin/intercom/broker/sql-schema.ts +82 -27
  45. package/dist/builtin/intercom/index.bundle.mjs +1 -1
  46. package/dist/builtin/intercom/package.json +1 -1
  47. package/dist/builtin/mcp/index.bundle.mjs +1 -1
  48. package/dist/builtin/mcp/package.json +1 -1
  49. package/dist/builtin/subagents/CHANGELOG.md +6 -0
  50. package/dist/builtin/subagents/package.json +1 -1
  51. package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
  52. package/dist/builtin/web-access/index.bundle.mjs +1 -1
  53. package/dist/builtin/web-access/package.json +1 -1
  54. package/dist/cli/args.js +2 -2
  55. package/dist/cli/auth-cli.code.js +4 -4
  56. package/dist/cli/auth-cli.impl.js +3 -3
  57. package/dist/cli/auth-cli.js +3 -3
  58. package/dist/cli/blueprint-command.code.js +2 -2
  59. package/dist/cli/blueprint-command.impl.js +3 -3
  60. package/dist/cli/blueprint-command.js +3 -3
  61. package/dist/cli/intercom-command.code.js +3 -3
  62. package/dist/cli/intercom-command.impl.js +3 -3
  63. package/dist/cli/intercom-command.js +3 -3
  64. package/dist/cli/list-models.code.js +2 -2
  65. package/dist/cli/list-models.impl.js +3 -3
  66. package/dist/cli/list-models.js +3 -3
  67. package/dist/cli/session-picker.code.js +2 -2
  68. package/dist/cli/session-picker.impl.js +3 -3
  69. package/dist/cli/session-picker.js +3 -3
  70. package/dist/cli/startup-ui.code.js +2 -2
  71. package/dist/cli/startup-ui.impl.js +3 -3
  72. package/dist/cli/startup-ui.js +3 -3
  73. package/dist/cli/storage-command.impl.js +3 -3
  74. package/dist/cli/storage-command.js +3 -3
  75. package/dist/cli/storage-search-session.code.js +2 -2
  76. package/dist/cli/storage-search-session.impl.js +3 -3
  77. package/dist/cli/storage-search-session.js +3 -3
  78. package/dist/cli/team-command.code.js +2 -2
  79. package/dist/cli/team-command.impl.js +3 -3
  80. package/dist/cli/team-command.js +3 -3
  81. package/dist/cli.js +2 -2
  82. package/dist/core/debug.impl.js +3 -3
  83. package/dist/core/debug.js +3 -3
  84. package/dist/core/export-html/card-projection.impl.js +3 -3
  85. package/dist/core/export-html/card-projection.js +3 -3
  86. package/dist/core/export-html/index.code.js +2 -2
  87. package/dist/core/export-html/index.impl.js +3 -3
  88. package/dist/core/export-html/index.js +3 -3
  89. package/dist/core/export-html/json-spans.impl.js +3 -3
  90. package/dist/core/export-html/json-spans.js +3 -3
  91. package/dist/core/export-html/oversized-render-inputs.code.js +1 -1
  92. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  93. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  94. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  95. package/dist/core/export-html/tool-renderer.js +3 -3
  96. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  97. package/dist/core/extensions/jiti-loader.js +3 -3
  98. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  99. package/dist/core/extensions/jiti-static-loader.js +3 -3
  100. package/dist/core/extensions/loader-host-modules.code.js +1 -1
  101. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  102. package/dist/core/extensions/loader-host-modules.js +3 -3
  103. package/dist/core/extensions/loader-virtual-modules.js +1 -1
  104. package/dist/core/extensions/runner-context.js +2 -2
  105. package/dist/core/intercom-broker-control-host.code.js +1 -1
  106. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  107. package/dist/core/intercom-broker-control-host.js +3 -3
  108. package/dist/core/intercom-broker-control.code.js +3 -3
  109. package/dist/core/intercom-broker-control.impl.js +3 -3
  110. package/dist/core/intercom-broker-control.js +3 -3
  111. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  112. package/dist/core/package-manager-storage-adapters.js +3 -3
  113. package/dist/core/sdk.code.js +3 -3
  114. package/dist/core/sdk.impl.js +3 -3
  115. package/dist/core/sdk.js +3 -3
  116. package/dist/core/session-manager-core.js +26 -14
  117. package/dist/core/session-manager-core.js.map +1 -1
  118. package/dist/core/session-manager-list.impl.js +3 -3
  119. package/dist/core/session-manager-list.js +3 -3
  120. package/dist/core/session-manager.code.js +3 -3
  121. package/dist/core/session-manager.impl.js +3 -3
  122. package/dist/core/session-manager.js +3 -3
  123. package/dist/core/session-open-markers.js +3 -0
  124. package/dist/core/session-open-markers.js.map +1 -0
  125. package/dist/core/session-storage.impl.js +3 -3
  126. package/dist/core/session-storage.js +3 -3
  127. package/dist/core/storage/added-exports.js +3 -0
  128. package/dist/core/storage/added-exports.js.map +1 -1
  129. package/dist/core/storage/database.d.ts +37 -0
  130. package/dist/core/storage/database.js.map +1 -1
  131. package/dist/core/storage/index.d.ts +1 -1
  132. package/dist/core/storage/index.js +2 -2
  133. package/dist/core/storage/index.js.map +1 -1
  134. package/dist/core/storage/migrations.d.ts +12 -3
  135. package/dist/core/storage/migrations.js +24 -11
  136. package/dist/core/storage/migrations.js.map +1 -1
  137. package/dist/core/storage/node-sqlite-thread.js +31 -2
  138. package/dist/core/storage/node-sqlite-thread.js.map +1 -1
  139. package/dist/core/storage/node-sqlite.js +86 -2
  140. package/dist/core/storage/node-sqlite.js.map +1 -1
  141. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  142. package/dist/core/storage/offline-snapshot-file.js +3 -3
  143. package/dist/core/storage/prefix.js +5 -0
  144. package/dist/core/storage/prefix.js.map +1 -1
  145. package/dist/core/storage/provider.js +2 -2
  146. package/dist/core/storage/schema-catalog.d.ts +82 -4
  147. package/dist/core/storage/schema-catalog.js +242 -32
  148. package/dist/core/storage/schema-catalog.js.map +1 -1
  149. package/dist/core/storage/selection.js +2 -2
  150. package/dist/core/storage/session/branch-fork-source.code.js +9 -8
  151. package/dist/core/storage/session/branch-fork-source.code.js.map +1 -1
  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 +4 -4
  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/errors.js +1 -1
  162. package/dist/core/storage/session/expanded-child-details.code.js +3 -3
  163. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  164. package/dist/core/storage/session/expanded-child-details.js +3 -3
  165. package/dist/core/storage/session/fork-detach.d.ts +118 -0
  166. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  167. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  168. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  169. package/dist/core/storage/session/fork-row-index.js +3 -3
  170. package/dist/core/storage/session/fork-schema.js +53 -0
  171. package/dist/core/storage/session/fork-schema.js.map +1 -0
  172. package/dist/core/storage/session/fork-segments.d.ts +58 -0
  173. package/dist/core/storage/session/fork-staging.code.js +3 -3
  174. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  175. package/dist/core/storage/session/fork-staging.js +3 -3
  176. package/dist/core/storage/session/fork-sweep.js +61 -0
  177. package/dist/core/storage/session/fork-sweep.js.map +1 -0
  178. package/dist/core/storage/session/fork-window.code.js +4 -4
  179. package/dist/core/storage/session/fork-window.impl.js +3 -3
  180. package/dist/core/storage/session/fork-window.js +3 -3
  181. package/dist/core/storage/session/history-pages.impl.js +3 -3
  182. package/dist/core/storage/session/history-pages.js +3 -3
  183. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  184. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  185. package/dist/core/storage/session/jsonl-session-store.d.ts +37 -1
  186. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  187. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  188. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  189. package/dist/core/storage/session/memory-session-store.js +3 -3
  190. package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
  191. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  192. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  193. package/dist/core/storage/session/released-history-files.code.js +3 -3
  194. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  195. package/dist/core/storage/session/released-history-files.js +3 -3
  196. package/dist/core/storage/session/resident-fork-rows.code.js +1 -1
  197. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  198. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  199. package/dist/core/storage/session/session-resume.impl.js +3 -3
  200. package/dist/core/storage/session/session-resume.js +3 -3
  201. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  202. package/dist/core/storage/session/snapshot-cut.js +3 -3
  203. package/dist/core/storage/session/snapshot-history.code.js +4 -4
  204. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  205. package/dist/core/storage/session/snapshot-history.js +3 -3
  206. package/dist/core/storage/session/sql-session-store.code.js +1 -1
  207. package/dist/core/storage/session/sql-session-store.d.ts +349 -12
  208. package/dist/core/storage/session/sql-session-store.impl.js +4 -4
  209. package/dist/core/storage/session/sql-session-store.js +4 -4
  210. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  211. package/dist/core/storage/session/tree-outline.js +3 -3
  212. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  213. package/dist/core/storage/session/tree-presentation.js +3 -3
  214. package/dist/core/storage/session/types.d.ts +22 -0
  215. package/dist/core/storage/sqlite-facade.d.ts +17 -1
  216. package/dist/core/storage/sqlite-facade.js +33 -0
  217. package/dist/core/storage/sqlite-facade.js.map +1 -1
  218. package/dist/core/storage/storage-status.impl.js +3 -3
  219. package/dist/core/storage/storage-status.js +3 -3
  220. package/dist/core/storage/team.impl.js +3 -3
  221. package/dist/core/storage/team.js +3 -3
  222. package/dist/core/structured-output/index.code.js +1 -1
  223. package/dist/core/structured-output/index.impl.js +3 -3
  224. package/dist/core/structured-output/index.js +3 -3
  225. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  226. package/dist/core/tasks/task-completion-entry.js +3 -3
  227. package/dist/core/tasks/task-file-history.code.js +4 -4
  228. package/dist/core/tasks/task-file-history.impl.js +3 -3
  229. package/dist/core/tasks/task-file-history.js +3 -3
  230. package/dist/core/tasks/task-reference-archive.code.js +4 -4
  231. package/dist/core/tasks/task-reference-archive.js +3 -3
  232. package/dist/core/tasks/task-reference-identity.js +3 -3
  233. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  234. package/dist/core/tasks/task-reference-stream.js +3 -3
  235. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  236. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  237. package/dist/core/tasks/task-view-source.impl.js +3 -3
  238. package/dist/core/tasks/task-view-source.js +3 -3
  239. package/dist/core/tools/history-session.d.ts +2 -0
  240. package/dist/core/tools/read-url.code.js +2 -2
  241. package/dist/core/tools/read-url.impl.js +3 -3
  242. package/dist/core/tools/read-url.js +3 -3
  243. package/dist/core/worktree-snapshot/blob-store.d.ts +31 -0
  244. package/dist/core/worktree-snapshot/blob-store.js +164 -49
  245. package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
  246. package/dist/core/worktree-snapshot/errors.code.js +3 -3
  247. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  248. package/dist/core/worktree-snapshot/errors.js +3 -3
  249. package/dist/core/worktree-snapshot/fork-snapshot-index.js +121 -0
  250. package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -0
  251. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  252. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  253. package/dist/extensions/codemode/execute.code.js +2 -2
  254. package/dist/extensions/codemode/execute.impl.js +3 -3
  255. package/dist/extensions/codemode/execute.js +3 -3
  256. package/dist/extensions/codemode/renderer.code.js +1 -1
  257. package/dist/extensions/codemode/renderer.impl.js +3 -3
  258. package/dist/extensions/codemode/renderer.js +3 -3
  259. package/dist/extensions/mcp/cli.code.js +2 -2
  260. package/dist/extensions/mcp/cli.impl.js +3 -3
  261. package/dist/extensions/mcp/cli.js +3 -3
  262. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  263. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  264. package/dist/extensions/mcp/cli.lazy.js +3 -3
  265. package/dist/extensions/mcp/runtime.code.js +1 -1
  266. package/dist/extensions/mcp/runtime.impl.js +3 -3
  267. package/dist/extensions/mcp/runtime.js +3 -3
  268. package/dist/index.js +6 -6
  269. package/dist/main-first-time-setup.code.js +2 -2
  270. package/dist/main-first-time-setup.impl.js +3 -3
  271. package/dist/main-first-time-setup.js +3 -3
  272. package/dist/modes/interactive/components/stored-tree-view.code.js +3 -3
  273. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  274. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  275. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  276. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  277. package/dist/modes/print-mode.js +1 -1
  278. package/dist/package-manager-cli.code.js +5 -5
  279. package/dist/package-manager-cli.impl.js +3 -3
  280. package/dist/package-manager-cli.js +3 -3
  281. package/dist/rpc-entry.js +1 -1
  282. package/dist/startup-files.json +1 -1
  283. package/dist/startup-stages/2.js +1 -0
  284. package/dist/startup-stages/5.js +1 -1
  285. package/dist/startup-stages/7.js +5 -1
  286. package/dist/startup-stages/8.js +2 -2
  287. package/dist/utils/startup-database-spare.code.js +3 -3
  288. package/dist/utils/startup-database-spare.impl.js +3 -3
  289. package/dist/utils/startup-database-spare.js +3 -3
  290. package/dist/utils/tools-manager.code.js +1 -1
  291. package/dist/utils/tools-manager.impl.js +3 -3
  292. package/dist/utils/tools-manager.js +3 -3
  293. package/docs/guides/postgres-pgbouncer.md +14 -7
  294. package/docs/guides/postgres-tuning.md +9 -9
  295. package/docs/sessions.md +9 -0
  296. package/docs/storage.md +47 -6
  297. package/package.json +8 -8
  298. package/dist/_shared/sdk-AVFII7NK.js.map +0 -1
  299. package/dist/_shared/settings-startup-4QCVCI53.js.map +0 -1
  300. package/dist/_shared/startup-0-0-57KF6LZH.js.map +0 -1
  301. package/dist/_shared/startup-0-1-GIY75K46.js.map +0 -1
  302. package/dist/_shared/startup-0-2-27OWFHV6.js.map +0 -1
  303. package/dist/_shared/startup-0-3-T4DVFYWX.js.map +0 -1
@@ -16,11 +16,12 @@ import {
16
16
  OUTBOX_EXPIRED_REASON,
17
17
  OUTBOX_TARGET_MAX_BYTES,
18
18
  OUTBOX_TARGET_MAX_ROWS,
19
- type ClaimedOutboxRow,
20
19
  type InvalidStateInput,
21
20
  type IntercomBrokerStateOptions,
22
21
  type OutboxClaim,
22
+ type OutboxClaimResult,
23
23
  type OutboxClaimWriteRejection,
24
+ type OutboxDeliveredResult,
24
25
  type OutboxEnqueueRequest,
25
26
  type OutboxEnqueueResult,
26
27
  type OutboxFrame,
@@ -33,6 +34,10 @@ import { addMissingColumns } from "./sql-add-column.js";
33
34
  import { ensureBrokerSchema, withBrokerSchemaCatalog } from "./sql-schema.js";
34
35
 
35
36
  const UNDELIVERED = "state IN ('queued', 'claimed')";
37
+ /** The setting a PostgreSQL claim transaction records in that its recipient has undelivered rows, and its locks are held. */
38
+ const CLAIM_GATE = "atomic.intercom_outbox_claim";
39
+ /** The most `markDelivered` calls one transaction settles together (#6560). */
40
+ const MARK_DELIVERED_BATCH_MAX = 100;
36
41
 
37
42
  interface OutboxRecord extends SqliteRow {
38
43
  readonly sequence: SqliteValue;
@@ -175,9 +180,9 @@ export function rowTransaction(): SqliteTransactionOptions {
175
180
  /**
176
181
  * S2 outbox on the shared storage adapter's database, in `<prefix>intercom_outbox`. Every read-modify-write runs in
177
182
  * one `BEGIN IMMEDIATE` transaction, and every age is measured on the database clock. On a database whose transactions
178
- * run concurrently (PostgreSQL), an enqueue holds its recipient's domain (`recipientTransaction`); a claim locks the
179
- * recipient's rows in sequence order and every write of a claimed row is one statement guarded by its claim token
180
- * (`rowTransaction`), so no write waits for another recipient's (#6560).
183
+ * run concurrently (PostgreSQL), an enqueue holds its recipient's domain (`recipientTransaction`); a claim holds its
184
+ * recipient's claim domain and locks the recipient's rows in sequence order, and every write of a claimed row is one
185
+ * statement guarded by its claim token (`rowTransaction`), so no write waits for another recipient's (#6560).
181
186
  */
182
187
  export function openSqlOutboxStore(options: IntercomBrokerStateOptions): Promise<SqlOutboxStore> {
183
188
  // Its schema checks answer from one read of the catalog, shared with an open around it: a current schema costs
@@ -189,7 +194,7 @@ async function openOutboxStoreInCatalog(options: IntercomBrokerStateOptions): Pr
189
194
  const { database } = options;
190
195
  const table = `${validateStoragePrefix(options.prefix, dialectOf(database).name)}intercom_outbox`;
191
196
  const { types, nowMs, greatest, lockClause, name: dialect } = dialectOf(database);
192
- /** Claims, claim writes and expiry: each decides on the rows it locks (#6560). */
197
+ /** Claim writes and expiry: each decides on the rows it locks (#6560). */
193
198
  const fenced = rowTransaction();
194
199
  const ageSince = (column: string) => greatest("0", `${nowMs} - ${column}`);
195
200
  // In a serial transaction, so brokers opening a new store at once take turns creating it (#5054).
@@ -253,8 +258,6 @@ async function openOutboxStoreInCatalog(options: IntercomBrokerStateOptions): Pr
253
258
  limit,
254
259
  );
255
260
  };
256
- const isLive = (record: OutboxRecord, staleAfterMs: number): boolean =>
257
- record.claim_age !== null && Number(record.claim_age) <= staleAfterMs;
258
261
 
259
262
  /**
260
263
  * Applies `assignments` (with their parameters) to the row only while `claim` is its current claim: one UPDATE whose
@@ -292,6 +295,89 @@ async function openOutboxStoreInCatalog(options: IntercomBrokerStateOptions): Pr
292
295
  const settled = `failure_reason = ?, settled_at = ${nowMs},
293
296
  claimant_id = NULL, claim_token = NULL, claim_renewed_at = NULL, saving_at = NULL`;
294
297
 
298
+ /**
299
+ * Settles each of `claims`, of distinct rows, as delivered, in one transaction: one UPDATE, sent with its start, that
300
+ * locks their rows in sequence order, as a claim locks a recipient's rows, and changes those whose claim is still
301
+ * current. Only when it changed fewer rows than it was given are the others read, to report why (#6560).
302
+ */
303
+ const markDeliveredTogether = (claims: readonly OutboxClaim[]): Promise<OutboxDeliveredResult[]> => {
304
+ const current = claims.map(() => "(message_id = ? AND claim_token = ? AND claimant_id = ?)").join(" OR ");
305
+ const keys = claims.flatMap((claim) => [claim.messageId, claim.token, claim.claimantId]);
306
+ const write: SqliteStatement = {
307
+ sql: `UPDATE ${table} SET state = 'delivered', ${settled}
308
+ WHERE message_id IN (
309
+ SELECT message_id FROM ${table} WHERE state = 'claimed' AND (${current})
310
+ ORDER BY sequence${lockClause("update")}
311
+ ) AND state = 'claimed' AND (${current})
312
+ RETURNING ${columns}`,
313
+ params: [null, ...keys, ...keys],
314
+ };
315
+ return database.transaction(
316
+ async (executor) => {
317
+ const written = new Map(
318
+ (await executor.all<OutboxRecord>(write.sql, ...write.params)).map((record) => [record.message_id, record]),
319
+ );
320
+ const others = claims.filter((claim) => !written.has(claim.messageId));
321
+ const found =
322
+ others.length === 0
323
+ ? new Map<string, OutboxRecord>()
324
+ : new Map(
325
+ (
326
+ await executor.all<OutboxRecord>(
327
+ `SELECT ${columns} FROM ${table} WHERE message_id IN (${others.map(() => "?").join(", ")})`,
328
+ ...others.map((claim) => claim.messageId),
329
+ )
330
+ ).map((record) => [record.message_id, record]),
331
+ );
332
+ return claims.map((claim): OutboxDeliveredResult => {
333
+ const delivered = written.get(claim.messageId);
334
+ if (delivered !== undefined) return { status: "delivered", row: toRow(delivered) };
335
+ const record = found.get(claim.messageId);
336
+ if (record === undefined) return { status: "unknown" };
337
+ if (isSettled(record)) return { status: "settled", row: toRow(record) };
338
+ return { status: "stale" };
339
+ });
340
+ },
341
+ { ...fenced, leading: [write] },
342
+ );
343
+ };
344
+
345
+ /**
346
+ * The `markDelivered` calls waiting for the transaction that settles them, in the order they were made. On PostgreSQL
347
+ * the calls made while one transaction settles others go together in the next, whose round trips they share, rather
348
+ * than two round trips each: one transaction at a time, so each commits after every call made before it (#6560).
349
+ */
350
+ const deliveries: {
351
+ readonly claim: OutboxClaim;
352
+ readonly resolve: (result: OutboxDeliveredResult) => void;
353
+ readonly reject: (error: unknown) => void;
354
+ }[] = [];
355
+ let delivering = false;
356
+ const deliverQueued = async () => {
357
+ // Calls made in the same turn as the first go with it.
358
+ await undefined;
359
+ while (deliveries.length > 0) {
360
+ // The calls in order, up to one that names a row already in the batch: it goes in the next, so it finds the row as
361
+ // the call before it left it.
362
+ const rows = new Set<string>();
363
+ let count = 0;
364
+ while (
365
+ count < deliveries.length &&
366
+ count < MARK_DELIVERED_BATCH_MAX &&
367
+ !rows.has(deliveries[count]!.claim.messageId)
368
+ )
369
+ rows.add(deliveries[count++]!.claim.messageId);
370
+ const batch = deliveries.splice(0, count);
371
+ try {
372
+ const results = await markDeliveredTogether(batch.map(({ claim }) => claim));
373
+ batch.forEach(({ resolve }, index) => resolve(results[index]!));
374
+ } catch (error) {
375
+ for (const { reject } of batch) reject(error);
376
+ }
377
+ }
378
+ delivering = false;
379
+ };
380
+
295
381
  /**
296
382
  * #4896: the recipient's undelivered rows and their frame bytes, read from `<table>_target_bytes` alone. Only rows an
297
383
  * older broker wrote, without `frame_bytes`, are measured from their frames.
@@ -451,61 +537,131 @@ async function openOutboxStoreInCatalog(options: IntercomBrokerStateOptions): Pr
451
537
  async claim(request) {
452
538
  if (request.claimantId.length === 0) return invalid("empty-claimant-id");
453
539
  if (request.targetIdentity.length === 0) return invalid("empty-target-identity");
454
- // Fast read-only index check so empty scans (such as fan-out wake-up polls across idle sessions) never take a
455
- // SQLite write lock. Linearizable: if a row commits after this snapshot, its enqueue writes a new wake-up hint.
456
- const pending = await database.get(
457
- `SELECT 1 AS present FROM ${table} WHERE target_identity = ? AND ${UNDELIVERED} LIMIT 1`,
458
- request.targetIdentity,
459
- );
460
- if (pending === undefined) return { status: "claimed", rows: [] } as const;
461
- // The recipient's rows are locked in sequence order, as every write of several rows locks them, and read in
462
- // their newest versions: a renewal or settlement of one waits for this claim, or this claim for it, so what it
463
- // decides on stays true until it commits (#6560). It does not skip a locked row (SKIP LOCKED): an earlier row
464
- // passed over could be handed out after a later one, and another claimant's live claim would go unseen.
465
- const locking: SqliteStatement = {
466
- sql: `SELECT ${columns} FROM ${table} WHERE target_identity = ? AND ${UNDELIVERED}
467
- ORDER BY sequence${lockClause("update")}`,
468
- params: [request.targetIdentity],
469
- };
470
- return database.transaction(async (executor) => {
471
- const records = await executor.all<OutboxRecord>(locking.sql, ...locking.params);
472
- const other = records.find(
473
- (record) =>
474
- record.state === "claimed" &&
475
- record.claimant_id !== request.claimantId &&
476
- isLive(record, request.staleAfterMs),
540
+ const { claimantId, targetIdentity, staleAfterMs } = request;
541
+ // Each row's token: this claim's, with the row's sequence, so every claimed row has a token of its own.
542
+ const token = randomUUID();
543
+ const claimed = (records: readonly OutboxRecord[]): OutboxClaimResult => ({
544
+ status: "claimed",
545
+ rows: [...records]
546
+ .sort((first, second) => Number(first.sequence) - Number(second.sequence))
547
+ .map((record) => {
548
+ const row = toRow(record);
549
+ const claim = { messageId: row.messageId, claimantId, token: String(record.claim_token), attempt: row.claimAttempts };
550
+ return { row, claim };
551
+ }),
552
+ });
553
+ const claiming = `state = 'claimed', claim_attempts = claim_attempts + 1, claimant_id = ?,
554
+ claim_token = ? || ':' || CAST(sequence AS TEXT), claim_renewed_at = ${nowMs}, saving_at = NULL`;
555
+ if (dialect === "postgres") {
556
+ // A read and one claim statement, sent with the transaction's start and its commit: one round trip whether or not
557
+ // there is anything to claim (#6560). The claim statement locks the recipient's undelivered rows in sequence order, as every write of several rows
558
+ // locks them, and reads them in their newest versions, so a renewal or settlement of one waits for this claim, or
559
+ // this claim for it. It does not skip a locked row (SKIP LOCKED): an earlier row passed over could be handed out
560
+ // after a later one, and another claimant's live claim would go unseen. Another claimant's live claim holds
561
+ // every row; otherwise each row not live is claimed, and the claimant's own live claims stay in flight.
562
+ // The recipient's claims take turns: the lock domain `<outbox>_claims:<recipient>` is taken before the statement
563
+ // takes its snapshot. The statement sees only rows its snapshot holds, so without it a claim made meanwhile of a
564
+ // row queued meanwhile went unseen: this claim could take over a claimant's older row it was late to renew while
565
+ // that claimant held a newer one, and two brokers would hand out one recipient's messages at once, the newer
566
+ // possibly first. Sends, settlements and other recipients' claims do not take it.
567
+ // Only a recipient with undelivered rows needs the lock. A read sent first, `waiting`, takes it, with the
568
+ // database's lock shared, only when it finds such a row, so the common empty poll takes no lock at all. The read
569
+ // records what it found in a setting of the transaction, and the claim statement locks and claims rows only when
570
+ // the read found some: every claim acts under the lock, with a snapshot taken after it. A row queued after the
571
+ // read waits for the next claim, which its send's wake-up hint brings. An older driver takes the locks with the
572
+ // transaction's start instead, which is just as correct.
573
+ // While it waits for the locks, `waiting` holds the table's share lock. A broker that adds a column to the table
574
+ // under the database's lock at that moment ends one of the two with a deadlock error; a claim that fails so is
575
+ // taken again at the next scan, as after any failed claim.
576
+ const waiting: SqliteStatement = {
577
+ sql: `SELECT set_config('${CLAIM_GATE}', 'locked', true) AS waiting
578
+ WHERE EXISTS (SELECT 1 FROM ${table} WHERE target_identity = ? AND ${UNDELIVERED})`,
579
+ params: [targetIdentity],
580
+ };
581
+ const statement: SqliteStatement = {
582
+ sql: `WITH locked AS MATERIALIZED (
583
+ SELECT message_id, sequence, state, claimant_id, claim_renewed_at FROM ${table}
584
+ WHERE target_identity = ? AND ${UNDELIVERED}
585
+ AND current_setting('${CLAIM_GATE}', true) = 'locked'
586
+ ORDER BY sequence${lockClause("update")}
587
+ ), live AS MATERIALIZED (
588
+ SELECT message_id, sequence, claimant_id FROM locked
589
+ WHERE state = 'claimed' AND claim_renewed_at IS NOT NULL AND ${ageSince("claim_renewed_at")} <= ?
590
+ ), holder AS MATERIALIZED (
591
+ SELECT claimant_id FROM live WHERE claimant_id <> ? ORDER BY sequence LIMIT 1
592
+ ), claimed AS (
593
+ UPDATE ${table} SET ${claiming}
594
+ WHERE message_id IN (SELECT message_id FROM locked)
595
+ AND message_id NOT IN (SELECT message_id FROM live)
596
+ AND NOT EXISTS (SELECT 1 FROM holder)
597
+ RETURNING ${columns}
598
+ )
599
+ SELECT claimed.*, (SELECT claimant_id FROM holder) AS holder
600
+ FROM (SELECT 1) AS answer LEFT JOIN claimed ON TRUE`,
601
+ params: [targetIdentity, staleAfterMs, claimantId, claimantId, token],
602
+ };
603
+ return database.transaction(
604
+ async (executor) => {
605
+ await executor.all(waiting.sql, ...waiting.params);
606
+ const records = await executor.all<OutboxRecord & { readonly holder: string | null }>(
607
+ statement.sql,
608
+ ...statement.params,
609
+ );
610
+ const holder = records[0]?.holder ?? null;
611
+ if (holder !== null) return { status: "held", claimantId: holder } as const;
612
+ return claimed(records.filter((record) => record.message_id !== null));
613
+ },
614
+ {
615
+ concurrency: { kind: "serial", domain: `${table}_claims:${targetIdentity}` },
616
+ leading: [waiting, statement],
617
+ leadingOnly: true,
618
+ lockIfLeadingFinds: true,
619
+ },
620
+ );
621
+ }
622
+ // SQLite and libSQL: a write statement takes the database's write lock even when it changes nothing, so a read
623
+ // decides first, without it, whether there is anything to claim: empty scans (such as fan-out wake-up polls across
624
+ // idle sessions) cost one read. Linearizable: if a row commits after this snapshot, its enqueue writes a new
625
+ // wake-up hint. The same read answers a claim another claimant holds, or one of only the claimant's own rows in
626
+ // flight. Otherwise one statement claims the rows, deciding again on what it changes (#6560).
627
+ const live = (alias: string) =>
628
+ `${alias}.state = 'claimed' AND ${alias}.claim_renewed_at IS NOT NULL
629
+ AND ${ageSince(`${alias}.claim_renewed_at`)} <= ?`;
630
+ const heldBy = `SELECT live.claimant_id FROM ${table} live
631
+ WHERE live.target_identity = ? AND ${live("live")} AND live.claimant_id <> ?`;
632
+ const probe = () =>
633
+ database.get<{ holder: string | null; claimable: SqliteValue }>(
634
+ `SELECT (${heldBy} ORDER BY live.sequence LIMIT 1) AS holder, EXISTS (
635
+ SELECT 1 FROM ${table} pending WHERE pending.target_identity = ?
636
+ AND pending.${UNDELIVERED} AND NOT (${live("pending")})
637
+ ) AS claimable`,
638
+ targetIdentity,
639
+ staleAfterMs,
640
+ claimantId,
641
+ targetIdentity,
642
+ staleAfterMs,
477
643
  );
478
- if (other?.claimant_id) return { status: "held", claimantId: other.claimant_id } as const;
479
- const rows: ClaimedOutboxRow[] = [];
480
- const claims: SqliteStatement[] = [];
481
- for (const record of records) {
482
- if (record.state === "claimed" && isLive(record, request.staleAfterMs)) continue;
483
- const token = randomUUID();
484
- claims.push({
485
- sql: `UPDATE ${table} SET state = 'claimed', claim_attempts = claim_attempts + 1, claimant_id = ?,
486
- claim_token = ?, claim_renewed_at = ${nowMs}, saving_at = NULL
487
- WHERE message_id = ?`,
488
- params: [request.claimantId, token, record.message_id],
489
- });
490
- // The row as the update leaves it: this transaction holds its lock (#6560).
491
- const row = toRow({
492
- ...record,
493
- state: "claimed",
494
- claim_attempts: Number(record.claim_attempts) + 1,
495
- claimant_id: request.claimantId,
496
- claim_token: token,
497
- claim_age: 0,
498
- saving_age: null,
499
- });
500
- rows.push({
501
- row,
502
- claim: { messageId: row.messageId, claimantId: request.claimantId, token, attempt: row.claimAttempts },
503
- });
504
- }
505
- // Sent with the commit: one round trip for the claim's reads, one for its writes (#6560).
506
- await runLast(executor, ...claims);
507
- return { status: "claimed", rows } as const;
508
- }, { ...fenced, leading: [locking] });
644
+ const found = await probe();
645
+ if (found !== undefined && found.holder !== null) return { status: "held", claimantId: found.holder } as const;
646
+ if (Number(found?.claimable ?? 0) === 0) return { status: "claimed", rows: [] } as const;
647
+ const records = await database.all<OutboxRecord>(
648
+ `UPDATE ${table} SET ${claiming}
649
+ WHERE target_identity = ? AND ${UNDELIVERED} AND NOT (${live(table)}) AND NOT EXISTS (${heldBy})
650
+ RETURNING ${columns}`,
651
+ claimantId,
652
+ token,
653
+ targetIdentity,
654
+ staleAfterMs,
655
+ targetIdentity,
656
+ staleAfterMs,
657
+ claimantId,
658
+ );
659
+ if (records.length > 0) return claimed(records);
660
+ // Another claimant took the rows since the read, or they were settled: only then is the holder read again.
661
+ const again = await probe();
662
+ return again !== undefined && again.holder !== null
663
+ ? ({ status: "held", claimantId: again.holder } as const)
664
+ : ({ status: "claimed", rows: [] } as const);
509
665
  },
510
666
 
511
667
  renewClaim(claim) {
@@ -541,10 +697,17 @@ async function openOutboxStoreInCatalog(options: IntercomBrokerStateOptions): Pr
541
697
  },
542
698
 
543
699
  markDelivered(claim) {
544
- return withClaim(claim, `state = 'delivered', ${settled}`, [null], (written) => ({
545
- status: "delivered" as const,
546
- row: toRow(written),
547
- }));
700
+ if (dialect !== "postgres" || claim.messageId.length === 0 || claim.claimantId.length === 0)
701
+ return withClaim(claim, `state = 'delivered', ${settled}`, [null], (written) => ({
702
+ status: "delivered" as const,
703
+ row: toRow(written),
704
+ }));
705
+ return new Promise<OutboxDeliveredResult>((resolve, reject) => {
706
+ deliveries.push({ claim, resolve, reject });
707
+ if (delivering) return;
708
+ delivering = true;
709
+ void deliverQueued();
710
+ });
548
711
  },
549
712
 
550
713
  markFailed(claim, reason) {
@@ -7,7 +7,10 @@ import { dialectOf, ensureStorageSchema, type SqliteDatabase, type SqliteExecuto
7
7
  * namespace, and without them every open checks its schema in a transaction, as before.
8
8
  */
9
9
  const catalogApi: Partial<
10
- Pick<typeof storage, "storageSchemaCurrent" | "schemaCatalogOf" | "withStorageSchemaCatalog">
10
+ Pick<
11
+ typeof storage,
12
+ "storageSchemaCurrent" | "schemaCatalogOf" | "withStorageSchemaCatalog" | "restampStorageSchemaAtOpenEnd"
13
+ >
11
14
  > = storage;
12
15
 
13
16
  /**
@@ -30,7 +33,12 @@ export async function withBrokerSchemaCatalog<T>(
30
33
  * Runs `setup`, a broker store's idempotent schema statements, in a transaction of its own, unless the prefix's ledger
31
34
  * records `revision` for `store` already (#5218): on PostgreSQL a current schema runs no DDL, so a role with only DML
32
35
  * privileges opens the store. Raise `revision` whenever `setup` creates or alters anything new. Inside an open that read
33
- * the catalog (`withStorageSchemaCatalog`), a revision it found recorded skips the transaction too (#6560).
36
+ * the catalog (`withStorageSchemaCatalog`), a revision it found recorded skips the transaction too (#6560). On SQLite and
37
+ * libSQL the store's stamp records it. A setup that runs stamps nothing: later setups of the same open would leave its
38
+ * stamp behind, and stamping costs a new database's first open statements and a transaction. The next open finds the
39
+ * store in the catalog instead; there a setup whose objects the catalog holds is checked again, and a counter it seeds
40
+ * seeded, in the one transaction the open's end stamps every such store in, so later opens of a current schema take no
41
+ * write lock and answer every store from its stamp.
34
42
  */
35
43
  export async function ensureBrokerSchema(
36
44
  database: SqliteDatabase,
@@ -41,30 +49,70 @@ export async function ensureBrokerSchema(
41
49
  ): Promise<void> {
42
50
  const schema = { ledger: storageMigrationTable(prefix), domain: `intercom-${store}`, revision };
43
51
  if (await catalogApi.storageSchemaCurrent?.(database, schema)) return;
44
- if (await createsNothingNew(database, setup)) return;
45
- await database.transaction((tx) =>
46
- ensureStorageSchema(tx, dialectOf(database), schema, async () => {
52
+ const found = await foundInCatalog(database, setup);
53
+ if (found?.present === true) {
54
+ const options = { verify: found.verify, deferred: found.seeds };
55
+ if (catalogApi.restampStorageSchemaAtOpenEnd?.(database, schema, setup, options) === true) return;
56
+ if (!found.seeds) return;
57
+ }
58
+ const dialect = dialectOf(database);
59
+ await database.transaction(async (tx) => {
60
+ if (!dialect.versionedMigrations) {
61
+ await setup(tx);
62
+ return;
63
+ }
64
+ await ensureStorageSchema(tx, dialect, schema, async () => {
47
65
  await setup(tx);
48
- }),
49
- );
66
+ });
67
+ });
68
+ // Stamped where the end of the open takes a transaction for other stores anyway, as after a repair or an upgrade.
69
+ if (!dialect.versionedMigrations)
70
+ catalogApi.restampStorageSchemaAtOpenEnd?.(database, schema, setup, { verify: found?.verify, alongside: true });
50
71
  }
51
72
 
52
73
  /**
53
- * Whether `setup` would change nothing on a SQLite or libSQL database: where it only runs `CREATE TABLE` and
54
- * `CREATE INDEX` statements with `IF NOT EXISTS`, and the catalog an open in progress read found each object, as a
55
- * table or an index as the statement names it. SQLite records no versions, so such a setup ran at every open in a
56
- * write transaction of its own, which took the database's write lock and, on a server, three round trips (#6560).
57
- * Statements on an existing object of that kind do nothing, so skipping them is the same. The setup runs against a
58
- * handle that only collects the SQL it would run; any other call, or a statement of another form, and it runs as
59
- * before. False outside such an open, and on PostgreSQL, whose ledger decides.
74
+ * Asks the open of `database` in progress to stamp `store`'s `setup` at its end, on SQLite and libSQL, where the open
75
+ * found the store current in the catalog, `verify` says, rather than by its stamp, which a schema change since left
76
+ * behind: the next open then answers from the stamp (#6560). Does nothing where the stamp is current, elsewhere, and
77
+ * outside an open.
60
78
  */
61
- async function createsNothingNew(
79
+ export async function stampBrokerSchemaAtOpenEnd(
62
80
  database: SqliteDatabase,
81
+ prefix: string | undefined,
82
+ store: string,
63
83
  setup: (tx: SqliteExecutor) => Promise<unknown>,
64
- ): Promise<boolean> {
65
- if (dialectOf(database).versionedMigrations) return false;
66
- const typeOf = (await openCatalogOf(database))?.sqliteObjectType;
67
- if (typeOf === undefined) return false;
84
+ verify: (catalog: storage.StorageSchemaCatalog) => boolean,
85
+ revision = 1,
86
+ ): Promise<void> {
87
+ const schema = { ledger: storageMigrationTable(prefix), domain: `intercom-${store}`, revision };
88
+ if (await catalogApi.storageSchemaCurrent?.(database, schema)) return;
89
+ catalogApi.restampStorageSchemaAtOpenEnd?.(database, schema, setup, { verify });
90
+ }
91
+
92
+ /**
93
+ * What `setup` creates on a SQLite or libSQL database, where it only runs `CREATE TABLE` and `CREATE INDEX` statements
94
+ * with `IF NOT EXISTS` and seeds rows with `INSERT … ON CONFLICT … DO NOTHING`: `present`, whether the catalog an open
95
+ * in progress read found each object, as a table or an index as the statement names it; `verify`, the same check
96
+ * against another catalog; and `seeds`, whether it seeds rows, which still have to be written. SQLite records no
97
+ * versions, so such a setup ran at every open in a write transaction of its own, which took the database's write lock
98
+ * and, on a server, three round trips (#6560); statements on an existing object of that kind do nothing. The setup runs
99
+ * against a handle that only collects the SQL it would run. Undefined for any other call or statement, outside such an
100
+ * open, and on PostgreSQL, whose ledger decides.
101
+ */
102
+ async function foundInCatalog(
103
+ database: SqliteDatabase,
104
+ setup: (tx: SqliteExecutor) => Promise<unknown>,
105
+ ): Promise<
106
+ | {
107
+ readonly verify: (catalog: storage.StorageSchemaCatalog) => boolean;
108
+ readonly seeds: boolean;
109
+ readonly present: boolean;
110
+ }
111
+ | undefined
112
+ > {
113
+ if (dialectOf(database).versionedMigrations) return undefined;
114
+ const catalog = await openCatalogOf(database);
115
+ if (catalog?.sqliteObjectType === undefined) return undefined;
68
116
  const scripts: string[] = [];
69
117
  let other = false;
70
118
  const refuse = () => {
@@ -83,22 +131,29 @@ async function createsNothingNew(
83
131
  try {
84
132
  await setup(collecting);
85
133
  } catch {
86
- return false;
134
+ return undefined;
87
135
  }
88
- if (other) return false;
136
+ if (other) return undefined;
137
+ const created: { readonly name: string; readonly type: string }[] = [];
138
+ let seeds = false;
89
139
  for (const script of scripts) {
90
140
  const statements = splitStatements(script);
91
- if (statements === undefined) return false;
141
+ if (statements === undefined) return undefined;
92
142
  for (const statement of statements) {
93
- const created = CREATE_IF_NOT_EXISTS.exec(statement);
94
- if (created === null) return false;
95
- const name = created[3] ?? created[4]!;
96
- if (typeOf(name) !== created[2]!.toLowerCase()) return false;
143
+ const create = CREATE_IF_NOT_EXISTS.exec(statement);
144
+ if (create !== null) created.push({ name: create[3] ?? create[4]!, type: create[2]!.toLowerCase() });
145
+ else if (SEED.test(statement)) seeds = true;
146
+ else return undefined;
97
147
  }
98
148
  }
99
- return true;
149
+ const verify = (found: storage.StorageSchemaCatalog) =>
150
+ created.every(({ name, type }) => found.sqliteObjectType?.(name) === type);
151
+ return { verify, seeds, present: verify(catalog) };
100
152
  }
101
153
 
154
+ /** `INSERT INTO … ON CONFLICT … DO NOTHING`: rows a setup seeds once, which writing again leaves as they are. */
155
+ const SEED = /^INSERT\s+INTO\s[\s\S]*\sON\s+CONFLICT\b[\s\S]*\sDO\s+NOTHING$/i;
156
+
102
157
  /** `CREATE [UNIQUE] TABLE|INDEX IF NOT EXISTS <name>`, the name plain or double-quoted and never schema-qualified. */
103
158
  const CREATE_IF_NOT_EXISTS =
104
159
  /^CREATE\s+(UNIQUE\s+)?(TABLE|INDEX)\s+IF\s+NOT\s+EXISTS\s+(?:"([^"]+)"|([A-Za-z_][A-Za-z0-9_]*))(?![A-Za-z0-9_$."])/i;
@@ -7,7 +7,7 @@ import * as __atomicHostImport1 from "@bastani/atomic-ai";
7
7
  if (!(name in namespace)) missing.push(`The requested module '${specifier}' does not provide an export named '${name}'`);
8
8
  if (missing.length > 0) {
9
9
  const application = typeof __atomicHostImport0.APP_NAME === "string" ? __atomicHostImport0.APP_NAME : "atomic";
10
- if (__atomicHostImport0.VERSION !== "0.10.11-alpha.1") missing.unshift(application + " was updated to 0.10.11-alpha.1 while this session was running; restart it to keep using the intercom extension.");
10
+ if (__atomicHostImport0.VERSION !== "0.10.11-alpha.2") missing.unshift(application + " was updated to 0.10.11-alpha.2 while this session was running; restart it to keep using the intercom extension.");
11
11
  throw new Error(missing.join("\n"));
12
12
  }
13
13
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/intercom",
3
- "version": "0.10.11-alpha.1",
3
+ "version": "0.10.11-alpha.2",
4
4
  "private": true,
5
5
  "description": "Atomic extension for direct messaging and coordination between parent, child, and peer agent sessions.",
6
6
  "contributors": [
@@ -6,7 +6,7 @@ import * as __atomicHostImport0 from "@bastani/atomic";
6
6
  if (!(name in namespace)) missing.push(`The requested module '${specifier}' does not provide an export named '${name}'`);
7
7
  if (missing.length > 0) {
8
8
  const application = typeof __atomicHostImport0.APP_NAME === "string" ? __atomicHostImport0.APP_NAME : "atomic";
9
- if (__atomicHostImport0.VERSION !== "0.10.11-alpha.1") missing.unshift(application + " was updated to 0.10.11-alpha.1 while this session was running; restart it to keep using the mcp extension.");
9
+ if (__atomicHostImport0.VERSION !== "0.10.11-alpha.2") missing.unshift(application + " was updated to 0.10.11-alpha.2 while this session was running; restart it to keep using the mcp extension.");
10
10
  throw new Error(missing.join("\n"));
11
11
  }
12
12
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/mcp",
3
- "version": "0.10.11-alpha.1",
3
+ "version": "0.10.11-alpha.2",
4
4
  "private": true,
5
5
  "description": "Atomic's MCP integration for server connections, OAuth, tools, resources, and terminal management.",
6
6
  "contributors": [
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.10.11-alpha.2] - 2026-11-26
6
+
7
+ ### Changed
8
+
9
+ - A subagent started with `context: "fork"` now shares its parent's history in the session store instead of copying it, so it starts about as fast from a long conversation as from a short one. It reads, resumes and exports as before. See [Shared-history forks](../coding-agent/docs/storage.md#shared-history-forks) in Atomic's storage guide ([#6608](https://github.com/bastani-inc/atomic/pull/6608), [#6560](https://github.com/bastani-inc/atomic/issues/6560)).
10
+
5
11
  ## [0.10.11-alpha.1] - 2026-11-25
6
12
 
7
13
  ### Changed
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/subagents",
3
- "version": "0.10.11-alpha.1",
3
+ "version": "0.10.11-alpha.2",
4
4
  "private": true,
5
5
  "description": "Atomic extension for delegating tasks to subagents with parallel execution.",
6
6
  "contributors": [
@@ -10,7 +10,7 @@ import * as __atomicHostImport4 from "@bastani/atomic-ai";
10
10
  if (!(name in namespace)) missing.push(`The requested module '${specifier}' does not provide an export named '${name}'`);
11
11
  if (missing.length > 0) {
12
12
  const application = typeof __atomicHostImport0.APP_NAME === "string" ? __atomicHostImport0.APP_NAME : "atomic";
13
- if (__atomicHostImport0.VERSION !== "0.10.11-alpha.1") missing.unshift(application + " was updated to 0.10.11-alpha.1 while this session was running; restart it to keep using the subagents extension.");
13
+ if (__atomicHostImport0.VERSION !== "0.10.11-alpha.2") missing.unshift(application + " was updated to 0.10.11-alpha.2 while this session was running; restart it to keep using the subagents extension.");
14
14
  throw new Error(missing.join("\n"));
15
15
  }
16
16
  }
@@ -8,7 +8,7 @@ import * as __atomicHostImport2 from "@bastani/atomic-ai/compat";
8
8
  if (!(name in namespace)) missing.push(`The requested module '${specifier}' does not provide an export named '${name}'`);
9
9
  if (missing.length > 0) {
10
10
  const application = typeof __atomicHostImport0.APP_NAME === "string" ? __atomicHostImport0.APP_NAME : "atomic";
11
- if (__atomicHostImport0.VERSION !== "0.10.11-alpha.1") missing.unshift(application + " was updated to 0.10.11-alpha.1 while this session was running; restart it to keep using the web-access extension.");
11
+ if (__atomicHostImport0.VERSION !== "0.10.11-alpha.2") missing.unshift(application + " was updated to 0.10.11-alpha.2 while this session was running; restart it to keep using the web-access extension.");
12
12
  throw new Error(missing.join("\n"));
13
13
  }
14
14
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/web-access",
3
- "version": "0.10.11-alpha.1",
3
+ "version": "0.10.11-alpha.2",
4
4
  "private": true,
5
5
  "description": "Atomic extension for web search, URL fetching, GitHub repository cloning, and PDF and video extraction.",
6
6
  "contributors": [
package/dist/cli/args.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "../_shared/rolldown-runtime-BGM3D5V3.js";
2
- import { isValidThinkingLevel } from "../_shared/startup-0-0-57KF6LZH.js";
3
- import { insertForcedOptionsBeforeTerminator, parseArgs, printHelp } from "../_shared/startup-0-1-GIY75K46.js";
2
+ import { isValidThinkingLevel } from "../_shared/startup-0-0-3IXNMFM2.js";
3
+ import { insertForcedOptionsBeforeTerminator, parseArgs, printHelp } from "../_shared/startup-0-1-7T2IAE7J.js";
4
4
  export { insertForcedOptionsBeforeTerminator, isValidThinkingLevel, parseArgs, printHelp };
5
5
  //# sourceMappingURL=args.js.map
@@ -3,12 +3,12 @@ import chalk from "chalk";
3
3
  import { APP_NAME, ENV_DEBUG, getAgentDir, getAuthPath, setEnvValue } from "../_shared/p0-cli-BB45ZQY6.js";
4
4
  import { AuthStorage, ReadOnlyAuthStorage } from "../_shared/startup-0-4-ZMJV547D.js";
5
5
  import { CredentialSynchronizationError, ModelRuntime, isOAuthLoginCancelled } from "../_shared/startup-0-5-YDW47QX6.js";
6
- import { RawStdoutWriteError, flushRawStdout, restoreStdout, takeOverStdout, writeRawStdout, writeRawStdoutOnce } from "../_shared/startup-0-0-57KF6LZH.js";
7
- import { findExactModelReferenceMatch, resolveModelReference } from "../_shared/startup-0-2-27OWFHV6.js";
6
+ import { RawStdoutWriteError, flushRawStdout, restoreStdout, takeOverStdout, writeRawStdout, writeRawStdoutOnce } from "../_shared/startup-0-0-3IXNMFM2.js";
7
+ import { findExactModelReferenceMatch, resolveModelReference } from "../_shared/startup-0-2-5QHPCEON.js";
8
8
  import { SettingsManager } from "../_shared/startup-8-1-X32CYSXB.js";
9
- import { parseArgs } from "../_shared/startup-0-1-GIY75K46.js";
9
+ import { parseArgs } from "../_shared/startup-0-1-7T2IAE7J.js";
10
10
  import { ModelsError } from "@bastani/atomic-ai";
11
- import { InMemoryCodingAgentModelsStore, resolveCliModel } from "../_shared/startup-0-3-T4DVFYWX.js";
11
+ import { InMemoryCodingAgentModelsStore, resolveCliModel } from "../_shared/startup-0-3-4ZYBYQNM.js";
12
12
  import { extractBearerToken, redactCredentialShapes } from "../_shared/p1b-elig-ENCUPKKJ.js";
13
13
  import { inspect } from "node:util";
14
14
  import { replaceControlCharacters } from "@bastani/atomic-tui";