@bastani/atomic 0.10.18-alpha.1 → 0.10.19-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.
Files changed (369) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/README.md +27 -5
  3. package/dist/_shared/config-binary-install-SNFYFXWB.js +70 -0
  4. package/dist/_shared/config-binary-install-SNFYFXWB.js.map +1 -0
  5. package/dist/_shared/dist-KOELCESV.js +2 -2
  6. package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
  7. package/dist/_shared/lib-4PES5P4V.js +2 -2
  8. package/dist/_shared/{mode-interactive-sdk-7KXUFI2F.js → mode-interactive-sdk-JXBZ3H27.js} +434 -11
  9. package/dist/_shared/mode-interactive-sdk-JXBZ3H27.js.map +1 -0
  10. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +21 -6
  11. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js.map +1 -1
  12. package/dist/_shared/mode-shared-2QJSCUM6.js +7 -6
  13. package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -1
  14. package/dist/_shared/p0-cli-BB45ZQY6.js +56 -3
  15. package/dist/_shared/p0-cli-BB45ZQY6.js.map +1 -1
  16. package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
  17. package/dist/_shared/runtime-O4KCSG4C.js +3 -3
  18. package/dist/_shared/{sdk-OHKMDJ74.js → sdk-BHX35EPK.js} +47 -17
  19. package/dist/_shared/sdk-BHX35EPK.js.map +1 -0
  20. package/dist/_shared/session-data-AHTU7IS6.js +2 -2
  21. package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
  22. package/dist/_shared/{startup-0-0-OV6RAEAP.js → startup-0-0-4EDVBK5P.js} +464 -7
  23. package/dist/_shared/startup-0-0-4EDVBK5P.js.map +1 -0
  24. package/dist/_shared/{startup-0-1-EZAJI6RE.js → startup-0-1-H5IXVRXQ.js} +85 -7
  25. package/dist/_shared/startup-0-1-H5IXVRXQ.js.map +1 -0
  26. package/dist/_shared/startup-0-2-YZZOC22D.js +4 -4
  27. package/dist/_shared/startup-0-3-DE2NCS6A.js +4 -4
  28. package/dist/_shared/startup-0-4-ZMJV547D.js +6 -5
  29. package/dist/_shared/startup-0-4-ZMJV547D.js.map +1 -1
  30. package/dist/_shared/startup-0-5-HZX3ZPTP.js +44 -13
  31. package/dist/_shared/startup-0-5-HZX3ZPTP.js.map +1 -1
  32. package/dist/_shared/startup-10-0-TDQNBDDL.js +5 -5
  33. package/dist/_shared/startup-12-0-55AAXBJZ.js +2 -2
  34. package/dist/_shared/startup-14-0-MLX36RBG.js +3 -3
  35. package/dist/_shared/startup-15-0-YUKGAC63.js +3 -3
  36. package/dist/_shared/{startup-15-1-4S7FLMNG.js → startup-15-1-WQZBOTMZ.js} +70 -28
  37. package/dist/_shared/{startup-15-1-4S7FLMNG.js.map → startup-15-1-WQZBOTMZ.js.map} +1 -1
  38. package/dist/_shared/startup-8-0-34CBHPZH.js +4 -4
  39. package/dist/_shared/{startup-8-1-LZFXSD3Z.js → startup-8-1-QZMXUGHI.js} +242 -20
  40. package/dist/_shared/startup-8-1-QZMXUGHI.js.map +1 -0
  41. package/dist/_shared/storage-command-7MGXLJGZ.js +75 -11
  42. package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
  43. package/dist/_shared/storage-status-K7PX2RXA.js +3 -3
  44. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  45. package/dist/_shared/team-DOQKICG2.js +2 -2
  46. package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
  47. package/dist/binary-self-update.js +281 -0
  48. package/dist/binary-self-update.js.map +1 -0
  49. package/dist/builtin/intercom/broker/broker.bundle.mjs +158 -78
  50. package/dist/builtin/intercom/broker/multinode-router.ts +41 -8
  51. package/dist/builtin/intercom/broker/multinode-state-store.ts +6 -1
  52. package/dist/builtin/intercom/broker/sql-lease-store.ts +89 -80
  53. package/dist/builtin/intercom/broker/sql-pending-ask-store.ts +65 -6
  54. package/dist/builtin/intercom/index.bundle.mjs +2 -1
  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 +15 -0
  59. package/dist/builtin/subagents/package.json +1 -1
  60. package/dist/builtin/subagents/skills/agent-browser/SKILL.md +1 -1
  61. package/dist/builtin/subagents/skills/impeccable/SKILL.md +3 -3
  62. package/dist/builtin/subagents/skills/impeccable/reference/audit.md +2 -2
  63. package/dist/builtin/subagents/skills/impeccable/reference/critique.md +3 -3
  64. package/dist/builtin/subagents/skills/impeccable/reference/generate.md +1 -1
  65. package/dist/builtin/subagents/skills/impeccable/reference/init.md +0 -2
  66. package/dist/builtin/subagents/skills/impeccable/reference/live.md +4 -2
  67. package/dist/builtin/subagents/skills/impeccable/reference/new-work-comp.md +1 -1
  68. package/dist/builtin/subagents/skills/impeccable/reference/new-work-world.md +1 -1
  69. package/dist/builtin/subagents/skills/impeccable/scripts/VERSION +1 -1
  70. package/dist/builtin/subagents/skills/impeccable/scripts/engine-checksums.txt +5 -5
  71. package/dist/builtin/subagents/skills/impeccable/scripts/impeccable +28 -5
  72. package/dist/builtin/subagents/skills/impeccable/scripts/impeccable.cmd +11 -2
  73. package/dist/builtin/subagents/skills/impeccable/scripts/live-browser.js +10 -6
  74. package/dist/builtin/subagents/skills/research-codebase/SKILL.md +13 -19
  75. package/dist/builtin/subagents/skills/skill-creator/SKILL.md +1 -1
  76. package/dist/builtin/subagents/skills/subagent/SKILL.md +7 -7
  77. package/dist/builtin/subagents/skills/workflow/SKILL.md +98 -0
  78. package/dist/builtin/subagents/src/extension/index.bundle.mjs +2 -1
  79. package/dist/builtin/web-access/index.bundle.mjs +2 -1
  80. package/dist/builtin/web-access/package.json +1 -1
  81. package/dist/cli/args.js +2 -2
  82. package/dist/cli/auth-cli.code.js +3 -3
  83. package/dist/cli/auth-cli.impl.js +3 -3
  84. package/dist/cli/auth-cli.js +3 -3
  85. package/dist/cli/blueprint-command.code.js +2 -2
  86. package/dist/cli/blueprint-command.impl.js +3 -3
  87. package/dist/cli/blueprint-command.js +3 -3
  88. package/dist/cli/intercom-command.code.js +2 -2
  89. package/dist/cli/intercom-command.impl.js +3 -3
  90. package/dist/cli/intercom-command.js +3 -3
  91. package/dist/cli/list-models.code.js +2 -2
  92. package/dist/cli/list-models.impl.js +3 -3
  93. package/dist/cli/list-models.js +3 -3
  94. package/dist/cli/session-picker.code.js +1 -1
  95. package/dist/cli/session-picker.impl.js +3 -3
  96. package/dist/cli/session-picker.js +3 -3
  97. package/dist/cli/startup-ui.code.js +1 -1
  98. package/dist/cli/startup-ui.impl.js +3 -3
  99. package/dist/cli/startup-ui.js +3 -3
  100. package/dist/cli/storage-command.impl.js +3 -3
  101. package/dist/cli/storage-command.js +3 -3
  102. package/dist/cli/storage-search-session.code.js +3 -3
  103. package/dist/cli/storage-search-session.impl.js +3 -3
  104. package/dist/cli/storage-search-session.js +3 -3
  105. package/dist/cli/team-command.code.js +1 -1
  106. package/dist/cli/team-command.impl.js +3 -3
  107. package/dist/cli/team-command.js +3 -3
  108. package/dist/cli/usage-command.js +22 -0
  109. package/dist/cli/usage-command.js.map +1 -0
  110. package/dist/cli.js +2 -2
  111. package/dist/config-binary-install.js +3 -0
  112. package/dist/config-binary-install.js.map +1 -0
  113. package/dist/core/agent-session-services.js +3 -0
  114. package/dist/core/agent-session-services.js.map +1 -0
  115. package/dist/core/debug.impl.js +3 -3
  116. package/dist/core/debug.js +3 -3
  117. package/dist/core/export-html/card-projection.impl.js +3 -3
  118. package/dist/core/export-html/card-projection.js +3 -3
  119. package/dist/core/export-html/index.code.js +2 -2
  120. package/dist/core/export-html/index.impl.js +3 -3
  121. package/dist/core/export-html/index.js +3 -3
  122. package/dist/core/export-html/json-spans.impl.js +3 -3
  123. package/dist/core/export-html/json-spans.js +3 -3
  124. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  125. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  126. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  127. package/dist/core/export-html/tool-renderer.js +3 -3
  128. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  129. package/dist/core/extensions/jiti-loader.js +3 -3
  130. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  131. package/dist/core/extensions/jiti-static-loader.js +3 -3
  132. package/dist/core/extensions/loader-host-modules.code.js +1 -1
  133. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  134. package/dist/core/extensions/loader-host-modules.js +3 -3
  135. package/dist/core/extensions/loader-virtual-modules.js +1 -1
  136. package/dist/core/extensions/runner-context.js +2 -2
  137. package/dist/core/intercom-broker-control-host.code.js +1 -1
  138. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  139. package/dist/core/intercom-broker-control-host.js +3 -3
  140. package/dist/core/intercom-broker-control.code.js +3 -3
  141. package/dist/core/intercom-broker-control.impl.js +3 -3
  142. package/dist/core/intercom-broker-control.js +3 -3
  143. package/dist/core/{legacy-workflow-files.d.ts → legacy-workflows.d.ts} +1 -1
  144. package/dist/core/model-runtime.d.ts +8 -2
  145. package/dist/core/package-manager-storage-adapters.code.js +1 -1
  146. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  147. package/dist/core/package-manager-storage-adapters.js +3 -3
  148. package/dist/core/resource-loader-core.d.ts +1 -1
  149. package/dist/core/resource-loader-internals.d.ts +1 -1
  150. package/dist/core/resource-loader-types.d.ts +1 -1
  151. package/dist/core/resource-loader-types.js.map +1 -1
  152. package/dist/core/sdk.code.js +4 -4
  153. package/dist/core/sdk.impl.js +3 -3
  154. package/dist/core/sdk.js +3 -3
  155. package/dist/core/session-manager-core.js +5 -5
  156. package/dist/core/session-manager-list.impl.js +3 -3
  157. package/dist/core/session-manager-list.js +3 -3
  158. package/dist/core/session-manager.code.js +1 -1
  159. package/dist/core/session-manager.impl.js +3 -3
  160. package/dist/core/session-manager.js +3 -3
  161. package/dist/core/session-storage.code.js +1 -1
  162. package/dist/core/session-storage.impl.js +3 -3
  163. package/dist/core/session-storage.js +3 -3
  164. package/dist/core/settings-manager.js +5 -0
  165. package/dist/core/settings-manager.js.map +1 -0
  166. package/dist/core/storage/database.d.ts +6 -2
  167. package/dist/core/storage/database.js.map +1 -1
  168. package/dist/core/storage/fenced-paths.d.ts +15 -0
  169. package/dist/core/storage/fenced-paths.js +25 -0
  170. package/dist/core/storage/fenced-paths.js.map +1 -1
  171. package/dist/core/storage/index.js +2 -2
  172. package/dist/core/storage/migrations.d.ts +2 -11
  173. package/dist/core/storage/migrations.js +2 -9
  174. package/dist/core/storage/migrations.js.map +1 -1
  175. package/dist/core/storage/node-sqlite-thread.js +2 -2
  176. package/dist/core/storage/node-sqlite.js +2 -2
  177. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  178. package/dist/core/storage/offline-snapshot-file.js +3 -3
  179. package/dist/core/storage/postgres-locks.d.ts +11 -0
  180. package/dist/core/storage/postgres-locks.js +9 -0
  181. package/dist/core/storage/postgres-locks.js.map +1 -0
  182. package/dist/core/storage/provider.js +2 -2
  183. package/dist/core/storage/selection.js +2 -2
  184. package/dist/core/storage/session/branch-fork-source.code.js +2 -2
  185. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  186. package/dist/core/storage/session/branch-fork-source.js +3 -3
  187. package/dist/core/storage/session/card-view.impl.js +3 -3
  188. package/dist/core/storage/session/card-view.js +3 -3
  189. package/dist/core/storage/session/child-reader.code.js +3 -3
  190. package/dist/core/storage/session/child-reader.impl.js +3 -3
  191. package/dist/core/storage/session/child-reader.js +3 -3
  192. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  193. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  194. package/dist/core/storage/session/expanded-child-details.code.js +2 -2
  195. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  196. package/dist/core/storage/session/expanded-child-details.js +3 -3
  197. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  198. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  199. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  200. package/dist/core/storage/session/fork-row-index.js +3 -3
  201. package/dist/core/storage/session/fork-staging.code.js +2 -2
  202. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  203. package/dist/core/storage/session/fork-staging.js +3 -3
  204. package/dist/core/storage/session/fork-window.code.js +3 -3
  205. package/dist/core/storage/session/fork-window.impl.js +3 -3
  206. package/dist/core/storage/session/fork-window.js +3 -3
  207. package/dist/core/storage/session/history-pages.impl.js +3 -3
  208. package/dist/core/storage/session/history-pages.js +3 -3
  209. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  210. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  211. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  212. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  213. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  214. package/dist/core/storage/session/memory-session-store.js +3 -3
  215. package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
  216. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  217. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  218. package/dist/core/storage/session/released-history-files.code.js +2 -2
  219. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  220. package/dist/core/storage/session/released-history-files.js +3 -3
  221. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  222. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  223. package/dist/core/storage/session/session-resume.impl.js +3 -3
  224. package/dist/core/storage/session/session-resume.js +3 -3
  225. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  226. package/dist/core/storage/session/snapshot-cut.js +3 -3
  227. package/dist/core/storage/session/snapshot-history.code.js +3 -3
  228. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  229. package/dist/core/storage/session/snapshot-history.js +3 -3
  230. package/dist/core/storage/session/sql-session-store.code.js +1 -1
  231. package/dist/core/storage/session/sql-session-store.d.ts +1 -1
  232. package/dist/core/storage/session/sql-session-store.impl.js +3 -3
  233. package/dist/core/storage/session/sql-session-store.js +3 -3
  234. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  235. package/dist/core/storage/session/tree-outline.js +3 -3
  236. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  237. package/dist/core/storage/session/tree-presentation.js +3 -3
  238. package/dist/core/storage/sqlite-facade.js +6 -4
  239. package/dist/core/storage/sqlite-facade.js.map +1 -1
  240. package/dist/core/storage/storage-status.impl.js +3 -3
  241. package/dist/core/storage/storage-status.js +3 -3
  242. package/dist/core/storage/team.impl.js +3 -3
  243. package/dist/core/storage/team.js +3 -3
  244. package/dist/core/structured-output/index.code.js +1 -1
  245. package/dist/core/structured-output/index.impl.js +3 -3
  246. package/dist/core/structured-output/index.js +3 -3
  247. package/dist/core/subscription-usage-credential.d.ts +2 -0
  248. package/dist/core/subscription-usage-endpoints.d.ts +54 -0
  249. package/dist/core/subscription-usage.d.ts +55 -0
  250. package/dist/core/subscription-usage.js +3 -0
  251. package/dist/core/subscription-usage.js.map +1 -0
  252. package/dist/core/tasks/heartbeat-notice.d.ts +0 -1
  253. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  254. package/dist/core/tasks/task-completion-entry.js +3 -3
  255. package/dist/core/tasks/task-file-history.code.js +3 -3
  256. package/dist/core/tasks/task-file-history.impl.js +3 -3
  257. package/dist/core/tasks/task-file-history.js +3 -3
  258. package/dist/core/tasks/task-reference-archive.code.js +4 -4
  259. package/dist/core/tasks/task-reference-archive.js +3 -3
  260. package/dist/core/tasks/task-reference-identity.js +3 -3
  261. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  262. package/dist/core/tasks/task-reference-stream.js +3 -3
  263. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  264. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  265. package/dist/core/tasks/task-view-source.code.js +1 -1
  266. package/dist/core/tasks/task-view-source.impl.js +3 -3
  267. package/dist/core/tasks/task-view-source.js +3 -3
  268. package/dist/core/tools/edit-diff.d.ts +4 -6
  269. package/dist/core/tools/read-url.code.js +3 -3
  270. package/dist/core/tools/read-url.impl.js +3 -3
  271. package/dist/core/tools/read-url.js +3 -3
  272. package/dist/core/worktree-snapshot/blob-store.d.ts +14 -16
  273. package/dist/core/worktree-snapshot/blob-store.js +194 -81
  274. package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
  275. package/dist/core/worktree-snapshot/collection-claim.js +8 -0
  276. package/dist/core/worktree-snapshot/collection-claim.js.map +1 -0
  277. package/dist/core/worktree-snapshot/errors.code.js +2 -2
  278. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  279. package/dist/core/worktree-snapshot/errors.js +3 -3
  280. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  281. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  282. package/dist/core/worktree-snapshot/snapshot-epoch-migration.js +209 -0
  283. package/dist/core/worktree-snapshot/snapshot-epoch-migration.js.map +1 -0
  284. package/dist/core/worktree-snapshot/snapshot-epoch.js +100 -0
  285. package/dist/core/worktree-snapshot/snapshot-epoch.js.map +1 -0
  286. package/dist/extensions/codemode/execute.code.js +1 -1
  287. package/dist/extensions/codemode/execute.impl.js +3 -3
  288. package/dist/extensions/codemode/execute.js +3 -3
  289. package/dist/extensions/codemode/renderer.code.js +2 -2
  290. package/dist/extensions/codemode/renderer.impl.js +3 -3
  291. package/dist/extensions/codemode/renderer.js +3 -3
  292. package/dist/extensions/mcp/cli.code.js +2 -2
  293. package/dist/extensions/mcp/cli.impl.js +3 -3
  294. package/dist/extensions/mcp/cli.js +3 -3
  295. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  296. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  297. package/dist/extensions/mcp/cli.lazy.js +3 -3
  298. package/dist/extensions/mcp/runtime.code.js +1 -1
  299. package/dist/extensions/mcp/runtime.impl.js +3 -3
  300. package/dist/extensions/mcp/runtime.js +3 -3
  301. package/dist/index.d.ts +3 -0
  302. package/dist/index.js +7 -7
  303. package/dist/main-first-time-setup.code.js +1 -1
  304. package/dist/main-first-time-setup.impl.js +3 -3
  305. package/dist/main-first-time-setup.js +3 -3
  306. package/dist/main.js +2 -2
  307. package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
  308. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  309. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  310. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  311. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  312. package/dist/modes/interactive/interactive-mode-surface.d.ts +1 -0
  313. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  314. package/dist/modes/interactive/interactive-mode.js +1 -1
  315. package/dist/modes/interactive-engine/isolated-runtime.d.ts +3 -0
  316. package/dist/modes/print-mode.js +1 -1
  317. package/dist/modes/rpc/rpc-client-api.d.ts +3 -0
  318. package/dist/modes/rpc/rpc-types.d.ts +25 -0
  319. package/dist/package-manager-cli.code.js +31 -8
  320. package/dist/package-manager-cli.code.js.map +1 -1
  321. package/dist/package-manager-cli.impl.js +3 -3
  322. package/dist/package-manager-cli.js +3 -3
  323. package/dist/rpc-entry.js +2 -2
  324. package/dist/startup-files.json +1 -1
  325. package/dist/startup-stages/12.js +1 -1
  326. package/dist/startup-stages/4.js +1 -1
  327. package/dist/startup-stages/6.js +1 -1
  328. package/dist/subscription-usage-sdk.d.ts +9 -0
  329. package/dist/utils/changelog.d.ts +1 -0
  330. package/dist/utils/startup-database-spare.code.js +2 -2
  331. package/dist/utils/startup-database-spare.impl.js +3 -3
  332. package/dist/utils/startup-database-spare.js +3 -3
  333. package/dist/utils/tools-manager.code.js +1 -1
  334. package/dist/utils/tools-manager.impl.js +3 -3
  335. package/dist/utils/tools-manager.js +3 -3
  336. package/docs/background-tasks/reference.md +1 -1
  337. package/docs/background-tasks.md +1 -1
  338. package/docs/changelog.mdx +53 -1
  339. package/docs/containerization.md +17 -15
  340. package/docs/docs.json +1 -0
  341. package/docs/getting-started/installation.md +132 -80
  342. package/docs/guides/subscription-usage.md +133 -0
  343. package/docs/guides/team-setup.md +14 -3
  344. package/docs/guides.md +3 -0
  345. package/docs/index.md +18 -6
  346. package/docs/intercom/operations.md +1 -1
  347. package/docs/orchestration/migrating-workflows.md +16 -10
  348. package/docs/orchestration/patterns.md +8 -2
  349. package/docs/orchestration.md +17 -8
  350. package/docs/quickstart.md +7 -15
  351. package/docs/reference/cli.md +32 -24
  352. package/docs/rpc/protocol.md +9 -1
  353. package/docs/rpc.md +1 -1
  354. package/docs/sdk/reference.md +5 -1
  355. package/docs/skills.md +20 -4
  356. package/docs/slash-commands.md +3 -2
  357. package/docs/storage/postgres/tuning.md +2 -0
  358. package/docs/storage/postgres.md +17 -0
  359. package/docs/tools.md +57 -12
  360. package/docs/usage.md +1 -0
  361. package/docs/windows.md +4 -4
  362. package/docs/worktree-snapshots/reference.md +1 -1
  363. package/package.json +9 -9
  364. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +0 -1
  365. package/dist/_shared/sdk-OHKMDJ74.js.map +0 -1
  366. package/dist/_shared/startup-0-0-OV6RAEAP.js.map +0 -1
  367. package/dist/_shared/startup-0-1-EZAJI6RE.js.map +0 -1
  368. package/dist/_shared/startup-8-1-LZFXSD3Z.js.map +0 -1
  369. package/dist/builtin/subagents/skills/workflow-files/SKILL.md +0 -28
@@ -8,8 +8,11 @@ import { renderStorageIdentifiers, storageMigrationTable, validateStoragePrefix
8
8
  import { schemaCatalogOf, withStorageSchemaCatalog } from "../storage/schema-catalog.js";
9
9
  import { queueSqliteSchemaSetup } from "../storage/sqlite-open-batch.js";
10
10
  import { statementBatch } from "../storage/statement-batches.js";
11
+ import { SnapshotCollectionClaimLost } from "./collection-claim.js";
11
12
  import { forkInheritedBlobGuard, forkInheritedBlobGuardName } from "./fork-blob-guard.js";
12
13
  import { entriesIndexComplete, forkLinksCheck, forkSegmentsTable, forkSessionLink, legacyForkLinksTriggerName, materializedForkLinks, ownDuplicate, ownParentSeq, parentColumns, snapshotEntryCondition, } from "./fork-snapshot-index.js";
14
+ import { snapshotEpochActive, snapshotEpochTransaction, snapshotReferenceTransaction } from "./snapshot-epoch.js";
15
+ import { changeSnapshotEpoch, snapshotSourceObjects } from "./snapshot-epoch-migration.js";
13
16
  /**
14
17
  * The key under which a failed rename's error carries the trigger or view that stopped it, once confirmed in the
15
18
  * database (#5622); `WorkspaceCollectionError` names it in its hint. A `Symbol.for` key, shared without an import.
@@ -280,6 +283,20 @@ function collectableAge(graceSeconds) {
280
283
  * milliseconds for a large session whose pages are not cached, so each session is counted in a statement of its own.
281
284
  */
282
285
  const SWEEP_TURN_MS = 8;
286
+ /** Aim for short deletes even when a batch's blobs are chunked; an oversized blob is deleted by itself. */
287
+ const SNAPSHOT_COLLECTION_DELETE_BYTES = 16 * SNAPSHOT_BLOB_CHUNK_BYTES;
288
+ /**
289
+ * Deadline for a granted PostgreSQL cleanup transaction where supported (17+). PostgreSQL 16 has no transaction
290
+ * deadline: cap each statement and each pause between requests there too. A normal delete does at most four SQL
291
+ * statements between the grant and commit, without sleeps, so the limits leave room under the 2 s writer budget.
292
+ */
293
+ const POSTGRES_COLLECTION_LIMITS = {
294
+ sql: `SELECT set_config('statement_timeout', '250ms', true),
295
+ set_config('idle_in_transaction_session_timeout', '100ms', true),
296
+ CASE WHEN current_setting('transaction_timeout', true) IS NOT NULL
297
+ THEN set_config('transaction_timeout', '1s', true) END`,
298
+ params: [],
299
+ };
283
300
  /**
284
301
  * How long a sweep goes without a write before it renews its claim in a transaction of its own: a quarter of the claim
285
302
  * lease, so pages with nothing to delete, which write nothing else, never let the lease run out.
@@ -376,16 +393,21 @@ class SweepSessions {
376
393
  let batch = [];
377
394
  let sessions = new Set();
378
395
  let total = 0;
396
+ let bytes = 0;
379
397
  const added = (candidate) => candidate.sessions.reduce((sum, session) => (sessions.has(session) ? sum : sum + (this.costs.get(session) ?? 1)), 0);
380
398
  for (const candidate of candidates) {
381
399
  if (batch.length === SNAPSHOT_COLLECTION_DELETE_BATCH ||
382
- (batch.length > 0 && total + added(candidate) > SNAPSHOT_COLLECTION_SESSION_REFS)) {
400
+ (batch.length > 0 &&
401
+ (total + added(candidate) > SNAPSHOT_COLLECTION_SESSION_REFS ||
402
+ bytes + candidate.bytes > SNAPSHOT_COLLECTION_DELETE_BYTES))) {
383
403
  batches.push({ hashes: batch, sessions: [...sessions] });
384
404
  batch = [];
385
405
  sessions = new Set();
386
406
  total = 0;
407
+ bytes = 0;
387
408
  }
388
409
  total += added(candidate);
410
+ bytes += candidate.bytes;
389
411
  batch.push(candidate.hash);
390
412
  for (const session of candidate.sessions)
391
413
  sessions.add(session);
@@ -1194,12 +1216,14 @@ async function readSourceStates(executor, dialect, t, sources, listRetired = fal
1194
1216
  : source.triggers.map((trigger) => ({ trigger: trigger.name, text: source.marker })))
1195
1217
  : [];
1196
1218
  const holds = (checks) => checks.length === 0 ? "NULL" : `CASE ${checks.map(() => "WHEN name = ? THEN instr(sql, ?) > 0").join(" ")} END`;
1197
- const objects = signatures.length + markers.length === 0
1198
- ? dialect.schemaObjects(names)
1199
- : {
1200
- sql: `SELECT name, ${holds(signatures)} AS signed, ${holds(markers)} AS marked FROM sqlite_schema WHERE name IN (${names.map(() => "?").join(", ")})`,
1201
- params: [...signatures, ...markers].flatMap((check) => [check.trigger, check.text]).concat(names),
1202
- };
1219
+ const objects = !sqlite
1220
+ ? snapshotSourceObjects(dialect.schemaObjects(names))
1221
+ : signatures.length + markers.length === 0
1222
+ ? dialect.schemaObjects(names)
1223
+ : {
1224
+ sql: `SELECT name, ${holds(signatures)} AS signed, ${holds(markers)} AS marked FROM sqlite_schema WHERE name IN (${names.map(() => "?").join(", ")})`,
1225
+ params: [...signatures, ...markers].flatMap((check) => [check.trigger, check.text]).concat(names),
1226
+ };
1203
1227
  const progressRead = sourceProgressRead(t);
1204
1228
  // Read together: the progress rows do not depend on the objects.
1205
1229
  const [objectRows, progressRows] = await statementBatch(executor, [], [
@@ -1305,6 +1329,31 @@ export class SqlSnapshotBlobStore {
1305
1329
  this.forkSegments = forkSegments;
1306
1330
  this.table = tables.blobs;
1307
1331
  }
1332
+ /** Explicit owner operation; automatic cleanup never changes the compatibility mode. */
1333
+ async setRecordCoordination(active, minimumVersion) {
1334
+ if (this.dialect.name !== "postgres")
1335
+ throw new Error("Snapshot cleanup coordination is only configurable for PostgreSQL.");
1336
+ if ((await snapshotEpochActive(this.database, this.table)) === active)
1337
+ return false;
1338
+ if (active) {
1339
+ await this.completeIndex();
1340
+ await this.stampLegacyAges({});
1341
+ }
1342
+ const entries = this.sources.find((source) => source.name === "session-entries").table;
1343
+ return changeSnapshotEpoch(this.database, {
1344
+ tables: this.tables,
1345
+ entries,
1346
+ forkSegments: this.forkSegments,
1347
+ formerSources: this.sources.filter(({ table }) => table !== entries).map(({ table }) => table),
1348
+ sessionHeads: this.sessionHeads("session_id IN (SELECT value FROM jsonb_array_elements_text(touched_sessions))"),
1349
+ }, active, async (tx) => {
1350
+ const states = await readSourceStates(tx, this.dialect, this.tables, this.sources);
1351
+ if (!states.every(({ installed, backfilled }) => installed && backfilled))
1352
+ throw new Error("Snapshot references changed during the switch; rerun the snapshot cleanup migration.");
1353
+ if (await tx.get(`SELECT 1 FROM ${this.table} WHERE created_at = 0 OR (chunks = 0 AND length(data) > ${SNAPSHOT_BLOB_CHUNK_BYTES}) LIMIT 1`))
1354
+ throw new Error("Legacy snapshots changed during the switch; rerun the snapshot cleanup migration.");
1355
+ }, minimumVersion);
1356
+ }
1308
1357
  /** Which table this store collects, for telling stores of one database and prefix apart from others. */
1309
1358
  get identity() {
1310
1359
  return `${databaseIdentity(this.database.descriptor)}${this.table}`;
@@ -1525,7 +1574,7 @@ export class SqlSnapshotBlobStore {
1525
1574
  if (!linksHot)
1526
1575
  await ensureHotSessionLinks(database, t, prefix);
1527
1576
  const store = new SqlSnapshotBlobStore(database, dialect, t, indexSources(prefix, t, dialect, (await shared) ? segments : undefined), segments);
1528
- await store.installIndex(undefined, false, await schemaCatalogOf(database));
1577
+ await store.installIndex({}, false, await schemaCatalogOf(database));
1529
1578
  return store;
1530
1579
  }
1531
1580
  /**
@@ -1677,26 +1726,34 @@ export class SqlSnapshotBlobStore {
1677
1726
  }
1678
1727
  statements.push({ sql: header, params: [hash, data.byteLength, new Uint8Array(), chunks] });
1679
1728
  }
1680
- if (!chunked && this.database.batch) {
1729
+ if (!chunked && this.dialect.name !== "postgres" && this.database.batch) {
1681
1730
  await this.database.batch(statements);
1682
1731
  return;
1683
1732
  }
1684
1733
  const lead = statements.length < MAX_SEQUENCE_REQUEST_STATEMENTS && totalBytes <= SNAPSHOT_BLOB_CHUNK_BYTES;
1685
- await this.database.transaction(async (transaction) => {
1734
+ // Chunk inserts read the header before the upsert. Lock it first, in a separate READ COMMITTED statement, so
1735
+ // a put that waits for a collector deleting the old copy also sees that deletion when deciding to insert bytes.
1736
+ const locked = chunked && this.dialect.name === "postgres"
1737
+ ? {
1738
+ sql: `SELECT hash FROM ${this.table} WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues("?")})
1739
+ ORDER BY hash${this.dialect.byteOrderCollation} FOR NO KEY UPDATE`,
1740
+ params: [JSON.stringify(blobs.map(({ hash }) => hash))],
1741
+ }
1742
+ : undefined;
1743
+ await snapshotReferenceTransaction(this.database, this.table, async (transaction) => {
1744
+ if (locked !== undefined)
1745
+ await transaction.all(locked.sql, ...locked.params);
1686
1746
  // On a pipelined connection the statements go out with the commit: one round trip after the locks.
1687
1747
  if (transactionFinisher(transaction)?.(statements) === true)
1688
1748
  return;
1689
1749
  for (const statement of statements)
1690
1750
  await transaction.run(statement.sql, ...statement.params);
1691
- }, this.blobWrite(lead ? statements : undefined, lead));
1751
+ }, this.blobWrite(lead ? statements : locked === undefined ? undefined : [locked], lead));
1692
1752
  }
1693
1753
  /**
1694
- * How a put or a refresh of this table's blobs runs: a serial transaction of the blob table's own domain (#6560). On
1695
- * PostgreSQL it holds the database-wide lock shared, so it waits for and excludes collection, whose writes hold that
1696
- * lock exclusively, and the blob writers of this table exclude one another, but session writes, which hold the
1697
- * database-wide lock shared with their session's domain, run beside it. Rows it writes again (`created_at`) are locked
1698
- * in hash order, as an append's check of the blobs it records locks them (`missingBlob`), so neither waits on the
1699
- * other in a cycle. Its callback only uses the transaction, so a transient failure runs it again.
1754
+ * A put or refresh retains the blob writer's domain and locks only its hashes, in hash order. In PostgreSQL
1755
+ * compatibility mode it also takes the legacy shared key; in record mode cleanup coordinates on the row locks
1756
+ * instead. Its callback only uses the transaction, so a transient failure runs it again.
1700
1757
  */
1701
1758
  blobWrite(leading, leadingOnly = false) {
1702
1759
  return {
@@ -1737,7 +1794,7 @@ export class SqlSnapshotBlobStore {
1737
1794
  const params = [JSON.stringify(unique)];
1738
1795
  const update = `UPDATE ${this.table} SET created_at = ${this.dialect.nowSeconds} WHERE ${requested} AND created_at > 0`;
1739
1796
  const present = `SELECT hash FROM ${this.table} WHERE ${requested}`;
1740
- if (this.database.batch) {
1797
+ if (this.dialect.name !== "postgres" && this.database.batch) {
1741
1798
  const [, rows] = await this.database.batch([
1742
1799
  { sql: update, params },
1743
1800
  { sql: present, params },
@@ -1750,7 +1807,7 @@ export class SqlSnapshotBlobStore {
1750
1807
  sql: `${present} ORDER BY hash${this.dialect.byteOrderCollation}${this.dialect.lockClause("update")}`,
1751
1808
  params,
1752
1809
  };
1753
- return this.database.transaction(async (transaction) => {
1810
+ return snapshotReferenceTransaction(this.database, this.table, async (transaction) => {
1754
1811
  const rows = await transaction.all(locked.sql, ...locked.params);
1755
1812
  if (transactionFinisher(transaction)?.([{ sql: update, params }]) !== true)
1756
1813
  await transaction.run(update, ...params);
@@ -1822,7 +1879,7 @@ export class SqlSnapshotBlobStore {
1822
1879
  * above it, indexed by the triggers. A table that has none yet, an empty one included, costs one watermark of 0.
1823
1880
  * Resolves with the state of every referencing table.
1824
1881
  */
1825
- async installIndex(pace, includeDeferred = false, catalog) {
1882
+ async installIndex({ pace, holder }, includeDeferred = false, catalog) {
1826
1883
  // The fork links trigger earlier builds of #6560 installed, asked for in the same read: dropped where found, in the
1827
1884
  // first write below, so a database that has it runs it no longer once a store of this build opened it.
1828
1885
  const legacy = this.legacyForkLinks();
@@ -1833,8 +1890,7 @@ export class SqlSnapshotBlobStore {
1833
1890
  if (drop === undefined)
1834
1891
  return;
1835
1892
  const { name, table } = drop;
1836
- await withShortSchemaLockWaits(transaction, this.dialect, () => transaction.exec(this.dialect.dropTrigger(name, table, true)));
1837
- drop = undefined;
1893
+ await this.repairSchema(transaction, pace, table, () => transaction.exec(this.dialect.dropTrigger(name, table, true)));
1838
1894
  };
1839
1895
  const missing = states.filter((state) => !state.installed && (includeDeferred || !state.deferred));
1840
1896
  for (const { source } of missing) {
@@ -1842,16 +1898,23 @@ export class SqlSnapshotBlobStore {
1842
1898
  ? await SqlSnapshotBlobStore.prepareSessionIndexReset(this.database)
1843
1899
  : undefined;
1844
1900
  await this.write(pace, async (transaction) => {
1901
+ if (holder !== undefined)
1902
+ await this.renewClaim(transaction, holder);
1845
1903
  await dropLegacy(transaction);
1846
1904
  const [current] = await readSourceStates(transaction, this.dialect, this.tables, [source]);
1847
1905
  if (current === undefined || current.installed || (current.deferred && !includeDeferred))
1848
1906
  return;
1849
- // Its triggers lock the table: under short lock waits, so a stalled transaction never queues writers (#5218).
1850
- await withShortSchemaLockWaits(transaction, this.dialect, () => installSource(transaction, this.dialect, this.tables, source, reset));
1907
+ await this.repairSchema(transaction, pace, source.table, () => installSource(transaction, this.dialect, this.tables, source, reset));
1908
+ });
1909
+ drop = undefined;
1910
+ }
1911
+ if (drop !== undefined) {
1912
+ await this.write(pace, async (transaction) => {
1913
+ if (holder !== undefined)
1914
+ await this.renewClaim(transaction, holder);
1915
+ await dropLegacy(transaction);
1851
1916
  });
1852
1917
  }
1853
- if (drop !== undefined)
1854
- await this.write(pace, dropLegacy);
1855
1918
  return missing.length === 0 ? states : this.readStates(includeDeferred);
1856
1919
  }
1857
1920
  /** The fork links trigger earlier builds of #6560 installed on the session entries, and its table. */
@@ -1877,7 +1940,9 @@ export class SqlSnapshotBlobStore {
1877
1940
  readOnly: true,
1878
1941
  retryTransientFailures: true,
1879
1942
  leading: [
1880
- ...(present === undefined ? [this.dialect.schemaObjects([...names, ...(also?.names ?? [])])] : []),
1943
+ ...(present === undefined
1944
+ ? [snapshotSourceObjects(this.dialect.schemaObjects([...names, ...(also?.names ?? [])]))]
1945
+ : []),
1881
1946
  sourceProgressRead(this.tables),
1882
1947
  ],
1883
1948
  });
@@ -1891,7 +1956,7 @@ export class SqlSnapshotBlobStore {
1891
1956
  * before each batch and rejects with its reason.
1892
1957
  */
1893
1958
  async completeIndex(options = {}) {
1894
- const states = await this.installIndex(options.pace, true);
1959
+ const states = await this.installIndex(options, true);
1895
1960
  for (const { source, backfilled } of states) {
1896
1961
  if (backfilled)
1897
1962
  continue;
@@ -1913,10 +1978,9 @@ export class SqlSnapshotBlobStore {
1913
1978
  await this.betweenBatches(options.pace);
1914
1979
  options.signal?.throwIfAborted();
1915
1980
  const done = await this.write(options.pace, async (tx) => {
1916
- const finished = await drainRetiredSessionIndex(tx, this.tables, receipt);
1917
1981
  if (options.holder !== undefined)
1918
1982
  await this.renewClaim(tx, options.holder);
1919
- return finished;
1983
+ return drainRetiredSessionIndex(tx, this.tables, receipt);
1920
1984
  });
1921
1985
  if (done)
1922
1986
  break;
@@ -1928,17 +1992,19 @@ export class SqlSnapshotBlobStore {
1928
1992
  const t = this.tables;
1929
1993
  const row = this.dialect.rowOrder();
1930
1994
  const withholds = withholdsVersion(this.dialect, source);
1931
- return this.write(pace, async (transaction) => {
1995
+ return this.write(pace, async (transaction, recordMode) => {
1996
+ if (holder !== undefined)
1997
+ await this.renewClaim(transaction, holder);
1932
1998
  const [state] = await readSourceStates(transaction, this.dialect, t, [source]);
1933
1999
  if (state === undefined || state.backfilled)
1934
2000
  return true;
2001
+ if (recordMode)
2002
+ this.refuseRecordModeRepair();
1935
2003
  if (state.foreign) {
1936
2004
  // A build before 0.9.88 installed its own triggers since the loop read the states: the source is installed again
1937
2005
  // in this transaction, its old rows removed, as at the start of a collection. Left as it is, that build could
1938
2006
  // index it its way, and builds 0.9.88 and 0.9.89 trust their version row (#5558).
1939
- await withShortSchemaLockWaits(transaction, this.dialect, () => installSource(transaction, this.dialect, t, source, reset));
1940
- if (holder !== undefined)
1941
- await this.renewClaim(transaction, holder);
2007
+ await this.repairSchema(transaction, pace, source.table, () => installSource(transaction, this.dialect, t, source, reset));
1942
2008
  return false;
1943
2009
  }
1944
2010
  // A source that lost triggers meanwhile is indexed on, as its rows still need this build's statements; the sweep
@@ -2001,8 +2067,6 @@ export class SqlSnapshotBlobStore {
2001
2067
  await transaction.run(`UPDATE ${t.sources} SET backfilled_through = ? WHERE source = ? AND backfilled_through < ?`, upper, source.name, upper);
2002
2068
  if (own !== undefined)
2003
2069
  await transaction.run(`UPDATE ${t.sources} SET watermark = ?, backfilled_through = ? WHERE source = ?`, progress.watermark, upper, source.own);
2004
- if (holder !== undefined)
2005
- await this.renewClaim(transaction, holder);
2006
2070
  const done = upper >= progress.watermark;
2007
2071
  // Both progress rows reach the watermark: builds 0.9.88 and 0.9.89 may trust the index now (#5558).
2008
2072
  if (done && publish)
@@ -2047,7 +2111,7 @@ export class SqlSnapshotBlobStore {
2047
2111
  await this.write(options.pace, async (transaction) => {
2048
2112
  if (options.holder !== undefined)
2049
2113
  await this.renewClaim(transaction, options.holder);
2050
- await withShortSchemaLockWaits(transaction, this.dialect, async () => {
2114
+ await this.repairSchema(transaction, options.pace, t.blobs, async () => {
2051
2115
  if (!present.has(trigger))
2052
2116
  await addBlobChunks(transaction, t, this.dialect);
2053
2117
  await addBlobMaintenanceIndexes(transaction, t);
@@ -2068,11 +2132,11 @@ export class SqlSnapshotBlobStore {
2068
2132
  // Pages that hold nothing to delete write nothing else; the claim is renewed when the sweep starts and then
2069
2133
  // at least once per quarter lease.
2070
2134
  const holder = options.holder;
2071
- await this.write(options.pace, (transaction) => this.renewClaim(transaction, holder));
2135
+ await this.write(options.pace, (transaction) => this.renewClaim(transaction, holder), "claim");
2072
2136
  renewedAt = performance.now();
2073
2137
  }
2074
2138
  const page = await this.page(minimumAge, cursor);
2075
- const candidates = await this.unretainedOf(page.map((row) => row.hash), sessions, turns, forks);
2139
+ const candidates = await this.unretainedOf(page, sessions, turns, forks);
2076
2140
  let incomplete = false;
2077
2141
  for (const batch of sessions.batches(candidates)) {
2078
2142
  // Every delete batch starts on a turn of its own and ends with one: never a turn while it holds the write lock.
@@ -2096,7 +2160,8 @@ export class SqlSnapshotBlobStore {
2096
2160
  continue;
2097
2161
  }
2098
2162
  if (page.length < SNAPSHOT_COLLECTION_BATCH) {
2099
- await this.stampLegacyAges(options);
2163
+ if (this.dialect.name !== "postgres" || !(await snapshotEpochActive(this.database, this.table)))
2164
+ await this.stampLegacyAges(options);
2100
2165
  await this.moveChunksToRowTable(options);
2101
2166
  return deleted;
2102
2167
  }
@@ -2107,16 +2172,17 @@ export class SqlSnapshotBlobStore {
2107
2172
  }
2108
2173
  }
2109
2174
  /**
2110
- * Which of `hashes` no retaining run, no carried work and no session retains, as far as these reads see: the sweep's
2175
+ * Which blobs in `page` no retaining run, no carried work and no session retains, as far as these reads see: the sweep's
2111
2176
  * candidates, which a delete batch checks again in its transaction. Finds the retained blobs of each session that
2112
2177
  * references one of them and that `sessions` has not walked yet, in statements of at most
2113
2178
  * {@link SNAPSHOT_COLLECTION_SESSION_REFS} snapshot entries, with a turn between them.
2114
2179
  */
2115
- async unretainedOf(hashes, sessions, turns, forks) {
2116
- if (hashes.length === 0)
2180
+ async unretainedOf(page, sessions, turns, forks) {
2181
+ if (page.length === 0)
2117
2182
  return [];
2183
+ const sizes = new Map(page.map(({ hash, bytes }) => [hash, Number(bytes)]));
2118
2184
  const t = this.tables;
2119
- const free = await this.database.all(`SELECT value AS hash FROM ${this.dialect.jsonValues("?")} WHERE ${this.unreferencedByRuns("value")}`, JSON.stringify(hashes));
2185
+ const free = await this.database.all(`SELECT value AS hash FROM ${this.dialect.jsonValues("?")} WHERE ${this.unreferencedByRuns("value")}`, JSON.stringify([...sizes.keys()]));
2120
2186
  if (free.length === 0)
2121
2187
  return [];
2122
2188
  const referencing = new Map(free.map((row) => [row.hash, []]));
@@ -2134,7 +2200,7 @@ export class SqlSnapshotBlobStore {
2134
2200
  }
2135
2201
  return [...referencing]
2136
2202
  .filter(([hash]) => !sessions.retains(hash))
2137
- .map(([hash, referencedBy]) => ({ hash, sessions: referencedBy }));
2203
+ .map(([hash, referencedBy]) => ({ hash, sessions: referencedBy, bytes: sizes.get(hash) }));
2138
2204
  }
2139
2205
  /**
2140
2206
  * Deletes the blobs of `batch` that are still old and that no retaining run, no carried work and no session retains,
@@ -2145,15 +2211,12 @@ export class SqlSnapshotBlobStore {
2145
2211
  * since, is kept; the next collection walks that session. Nothing in the transaction waits for a turn of the event
2146
2212
  * loop (#5530).
2147
2213
  *
2148
- * It runs as a whole-database transaction on purpose, so no other write runs beside it. With only the blob table's
2149
- * lock it would not be safe: it decides which blobs sessions still use in one statement and deletes in the next. A
2150
- * session write that records a blob meanwhile holds the blob's row only until it commits its reference; the delete
2151
- * waits for it, then goes ahead without looking at the references again, and removes a blob a session has just
2152
- * recorded. The same goes for the references retaining runs and carried work write.
2214
+ * In record mode, lock existing candidate blobs before starting the retention recheck. The recheck must be a
2215
+ * separate READ COMMITTED command: neither EvalPlanQual nor SKIP LOCKED refreshes a DELETE's join snapshot.
2153
2216
  */
2154
2217
  deleteUnretained(batch, minimumAge, options) {
2155
2218
  const t = this.tables;
2156
- return this.write(options.pace, async (transaction) => {
2219
+ return this.write(options.pace, async (transaction, recordMode) => {
2157
2220
  const found = new Set();
2158
2221
  const states = await readSourceStates(transaction, this.dialect, this.tables, this.sources, false, undefined, {
2159
2222
  names: [this.forkSegments],
@@ -2163,11 +2226,24 @@ export class SqlSnapshotBlobStore {
2163
2226
  return undefined;
2164
2227
  if (options.holder !== undefined)
2165
2228
  await this.renewClaim(transaction, options.holder);
2166
- const kept = new Set(await this.keptBySessions(transaction, batch, found.has(this.forkSegments)));
2167
- const unretained = batch.hashes.filter((hash) => !kept.has(hash));
2168
- if (unretained.length === 0)
2169
- return [];
2170
- const rows = await transaction.all(`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`, JSON.stringify(unretained), minimumAge);
2229
+ let unretained = batch.hashes;
2230
+ if (recordMode) {
2231
+ const locked = await transaction.all(`SELECT hash FROM ${t.blobs} WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues("?")})
2232
+ ORDER BY hash${this.dialect.byteOrderCollation} FOR UPDATE SKIP LOCKED`, JSON.stringify(unretained));
2233
+ unretained = locked.map(({ hash }) => hash);
2234
+ if (unretained.length === 0)
2235
+ return [];
2236
+ }
2237
+ const kept = this.keptBySessions({ ...batch, hashes: unretained }, found.has(this.forkSegments));
2238
+ // Keep the recheck and delete in one server call on PostgreSQL, to shorten the exclusive hold.
2239
+ const inDelete = this.dialect.name === "postgres";
2240
+ if (!inDelete) {
2241
+ const retained = new Set((await transaction.all(kept.sql, ...kept.params)).map(({ hash }) => hash));
2242
+ unretained = unretained.filter((hash) => !retained.has(hash));
2243
+ if (unretained.length === 0)
2244
+ return [];
2245
+ }
2246
+ const rows = await transaction.all(`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`)}${inDelete ? ` AND hash NOT IN (${kept.sql})` : ""} RETURNING hash`, JSON.stringify(unretained), minimumAge, ...(inDelete ? kept.params : []));
2171
2247
  return rows.map((row) => row.hash);
2172
2248
  });
2173
2249
  }
@@ -2232,19 +2308,21 @@ export class SqlSnapshotBlobStore {
2232
2308
  * of `batch.sessions` retain, and those a session not among them records, whose snapshots the sweep did not walk.
2233
2309
  * Walks only `batch.sessions`, whose snapshot entries the sweep bounded when it made the batch (#5530).
2234
2310
  */
2235
- async keptBySessions(executor, batch, forks) {
2311
+ keptBySessions(batch, forks) {
2236
2312
  const t = this.tables;
2237
2313
  const ids = JSON.stringify(batch.sessions);
2238
2314
  const walked = `(SELECT value FROM ${this.dialect.jsonValues("?")})`;
2239
2315
  const inherited = this.inheritedRecord(forks);
2240
- const rows = await executor.all(`SELECT DISTINCT record.hash FROM ${t.sessionRecords} AS record
2316
+ return {
2317
+ sql: `SELECT DISTINCT record.hash FROM ${t.sessionRecords} AS record
2241
2318
  WHERE record.hash IN (SELECT value FROM ${this.dialect.jsonValues("?")})
2242
2319
  AND (
2243
2320
  record.session_id NOT IN ${walked}
2244
2321
  OR (record.session_id, record.snapshot_id) IN (${this.sessionHeads(`session_id IN ${walked}`)})
2245
2322
  OR EXISTS (SELECT 1 FROM ${t.sessionLinks} AS broken WHERE broken.session_id = record.session_id AND broken.broken = 1)${inherited}
2246
- )`, JSON.stringify(batch.hashes), ids, ids);
2247
- return rows.map((row) => row.hash);
2323
+ )`,
2324
+ params: [JSON.stringify(batch.hashes), ids, ids],
2325
+ };
2248
2326
  }
2249
2327
  /**
2250
2328
  * Stamps every blob of unknown age with the database clock, in hash order, in write transactions of at most
@@ -2290,7 +2368,9 @@ export class SqlSnapshotBlobStore {
2290
2368
  /** Stamps the blobs `hashes` name that still have an unknown age, in their rows, in one write transaction. */
2291
2369
  async stampInRows(hashes, options) {
2292
2370
  options.signal?.throwIfAborted();
2293
- await this.write(options.pace, async (transaction) => {
2371
+ await this.write(options.pace, async (transaction, recordMode) => {
2372
+ if (recordMode)
2373
+ return;
2294
2374
  if (options.holder !== undefined)
2295
2375
  await this.renewClaim(transaction, options.holder);
2296
2376
  await transaction.run(`UPDATE ${this.table} SET created_at = ${this.dialect.nowSeconds} WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues("?")}) AND created_at = 0`, JSON.stringify(hashes));
@@ -2317,7 +2397,9 @@ export class SqlSnapshotBlobStore {
2317
2397
  const perTransaction = SNAPSHOT_LEGACY_STAMP_BYTES / SNAPSHOT_BLOB_CHUNK_BYTES;
2318
2398
  for (let first = 0; first < chunks; first += perTransaction) {
2319
2399
  options.signal?.throwIfAborted();
2320
- const pending = await this.write(options.pace, async (transaction) => {
2400
+ const pending = await this.write(options.pace, async (transaction, recordMode) => {
2401
+ if (recordMode)
2402
+ return false;
2321
2403
  if (options.holder !== undefined)
2322
2404
  await this.renewClaim(transaction, options.holder);
2323
2405
  if (!(await transaction.get(`SELECT 1 FROM ${t.blobs} WHERE ${unmoved}`, hash))) {
@@ -2334,7 +2416,9 @@ export class SqlSnapshotBlobStore {
2334
2416
  return;
2335
2417
  }
2336
2418
  options.signal?.throwIfAborted();
2337
- await this.write(options.pace, async (transaction) => {
2419
+ await this.write(options.pace, async (transaction, recordMode) => {
2420
+ if (recordMode)
2421
+ return;
2338
2422
  if (options.holder !== undefined)
2339
2423
  await this.renewClaim(transaction, options.holder);
2340
2424
  const { changes } = await transaction.run(`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 = ?) = ?`, new Uint8Array(), chunks, hash, hash, chunks);
@@ -2620,8 +2704,8 @@ export class SqlSnapshotBlobStore {
2620
2704
  page(minimumAge, after) {
2621
2705
  const t = this.tables;
2622
2706
  return after === undefined
2623
- ? this.database.all(`SELECT created_at, hash FROM ${t.blobs} WHERE created_at > 0 AND created_at <= ${this.dialect.nowSeconds} - ? ORDER BY created_at, hash LIMIT ?`, minimumAge, SNAPSHOT_COLLECTION_BATCH)
2624
- : this.database.all(`SELECT created_at, hash FROM ${t.blobs} WHERE created_at <= ${this.dialect.nowSeconds} - ? AND (created_at, hash) > (?, ?) ORDER BY created_at, hash LIMIT ?`, minimumAge, after.created_at, after.hash, SNAPSHOT_COLLECTION_BATCH);
2707
+ ? this.database.all(`SELECT created_at, hash, bytes FROM ${t.blobs} WHERE created_at > 0 AND created_at <= ${this.dialect.nowSeconds} - ? ORDER BY created_at, hash LIMIT ?`, minimumAge, SNAPSHOT_COLLECTION_BATCH)
2708
+ : this.database.all(`SELECT created_at, hash, bytes FROM ${t.blobs} WHERE created_at <= ${this.dialect.nowSeconds} - ? AND (created_at, hash) > (?, ?) ORDER BY created_at, hash LIMIT ?`, minimumAge, after.created_at, after.hash, SNAPSHOT_COLLECTION_BATCH);
2625
2709
  }
2626
2710
  /**
2627
2711
  * Claims this table's next collection for `holder` when it is due on the database clock: none was ever claimed, or
@@ -2635,36 +2719,65 @@ export class SqlSnapshotBlobStore {
2635
2719
  const lease = SNAPSHOT_COLLECTION_LEASE_SECONDS;
2636
2720
  if (!(await this.database.get(`SELECT id FROM ${this.tables.collection} WHERE ${due}`, lease, intervalSeconds)))
2637
2721
  return false;
2638
- const { changes } = await this.write(pace, (transaction) => transaction.run(`UPDATE ${this.tables.collection} SET claimed_at = ${this.dialect.nowSeconds}, holder = ?, finished_at = NULL, deleted = NULL, error_code = NULL WHERE ${due}`, holder, lease, intervalSeconds));
2722
+ const { changes } = await this.write(pace, (transaction) => transaction.run(`UPDATE ${this.tables.collection} SET claimed_at = ${this.dialect.nowSeconds}, holder = ?, finished_at = NULL, deleted = NULL, error_code = NULL WHERE ${due}`, holder, lease, intervalSeconds), "claim");
2639
2723
  return changes === 1;
2640
2724
  }
2641
- renewClaim(transaction, holder) {
2642
- return transaction.run(`UPDATE ${this.tables.collection} SET claimed_at = ${this.dialect.nowSeconds} WHERE id = 1 AND holder = ?`, holder);
2725
+ async renewClaim(transaction, holder) {
2726
+ const { changes } = await transaction.run(`UPDATE ${this.tables.collection} SET claimed_at = ${this.dialect.nowSeconds} WHERE id = 1 AND holder = ? AND finished_at IS NULL`, holder);
2727
+ if (changes !== 1)
2728
+ throw new SnapshotCollectionClaimLost();
2643
2729
  }
2644
2730
  /**
2645
2731
  * Records how `holder`'s claimed collection ended; a later claim by another holder is left alone. Waits for the
2646
2732
  * write lock on `pace` when one is given.
2647
2733
  */
2648
2734
  async recordCollection(holder, outcome, pace) {
2649
- await this.write(pace, (transaction) => transaction.run(`UPDATE ${this.tables.collection} SET finished_at = ${this.dialect.nowSeconds}, deleted = ?, error_code = ? WHERE id = 1 AND holder = ?`, outcome.deleted, outcome.errorCode, holder));
2735
+ await this.write(pace, (transaction) => transaction.run(`UPDATE ${this.tables.collection} SET finished_at = ${this.dialect.nowSeconds}, deleted = ?, error_code = ? WHERE id = 1 AND holder = ?`, outcome.deleted, outcome.errorCode, holder), "claim");
2736
+ }
2737
+ /** A background repair must not wait for a table lock or sleep while it holds the database lock. */
2738
+ async repairSchema(transaction, pace, table, setup) {
2739
+ if (this.dialect.name === "postgres" && (await snapshotEpochActive(transaction, this.table)))
2740
+ this.refuseRecordModeRepair();
2741
+ if (pace === undefined || this.dialect.name !== "postgres")
2742
+ return withShortSchemaLockWaits(transaction, this.dialect, setup);
2743
+ // Dropping the old trigger can need ACCESS EXCLUSIVE. If a reader has the table, fail this transaction and
2744
+ // let write() back off, rather than retrying in a savepoint with the database lock still held.
2745
+ await transaction.exec(`LOCK TABLE ${table} IN ACCESS EXCLUSIVE MODE NOWAIT`);
2746
+ await setup();
2747
+ }
2748
+ refuseRecordModeRepair() {
2749
+ throw new Error("The worktree snapshot index needs repair. Disable faster snapshot cleanup with `atomic storage migrate --snapshot-cleanup disable`, then run storage migration again.");
2650
2750
  }
2651
2751
  /** Waits between two batches: on `pace` in the background, otherwise until the event loop has run once. */
2652
2752
  betweenBatches(pace) {
2653
2753
  return pace === undefined ? yieldToEventLoop() : pace.wait(0);
2654
2754
  }
2655
2755
  /**
2656
- * Runs `body` in a write transaction. With `pace`, the transaction never waits for a write lock another connection
2657
- * holds: it is refused at once (SQLite `StorageWriteLockTimeoutError` or PostgreSQL not-applied `lock-conflict`) and
2658
- * tried again after a wait on `pace` that doubles each time, so the process can exit meanwhile; once the waits add
2659
- * up to {@link SNAPSHOT_COLLECTION_LEASE_SECONDS}, it rejects with the refusal.
2756
+ * Background PostgreSQL batches try their advisory locks without joining a queue. In compatibility mode that
2757
+ * includes the legacy key. After the switch, only other collectors share its advisory scope. SQLite uses its
2758
+ * existing no-wait writer admission. Retry outside the transaction, with jitter.
2660
2759
  */
2661
- async write(pace, body) {
2760
+ async write(pace, body, scope = "data") {
2761
+ const limits = this.dialect.name === "postgres" && scope === "data" && pace !== undefined
2762
+ ? POSTGRES_COLLECTION_LIMITS
2763
+ : undefined;
2764
+ const attempt = () => snapshotEpochTransaction(this.database, this.table, {
2765
+ kind: "collector",
2766
+ claim: scope === "claim",
2767
+ scope: this.tables.collection,
2768
+ background: pace !== undefined,
2769
+ }, async (transaction, recordMode) => {
2770
+ if (limits !== undefined)
2771
+ await transaction.get(limits.sql, ...limits.params);
2772
+ return body(transaction, recordMode);
2773
+ }, pace === undefined ? {} : { lockWaitMs: 0, ...(limits === undefined ? {} : { leading: [limits] }) });
2662
2774
  if (pace === undefined)
2663
- return this.database.transaction(body);
2775
+ return attempt();
2664
2776
  let waited = 0;
2665
2777
  for (let delay = SNAPSHOT_COLLECTION_LOCK_RETRY_FIRST_MS;;) {
2778
+ pace.signal?.throwIfAborted();
2666
2779
  try {
2667
- return await this.database.transaction(body, { lockWaitMs: 0 });
2780
+ return await attempt();
2668
2781
  }
2669
2782
  catch (error) {
2670
2783
  const lockRefused = error instanceof StorageWriteLockTimeoutError ||
@@ -2674,9 +2787,9 @@ export class SqlSnapshotBlobStore {
2674
2787
  if (!lockRefused || waited >= SNAPSHOT_COLLECTION_LEASE_SECONDS * 1_000)
2675
2788
  throw error;
2676
2789
  }
2677
- await pace.wait(delay);
2678
- pace.signal?.throwIfAborted();
2679
- waited += delay;
2790
+ const jittered = delay * (0.5 + Math.random() / 2);
2791
+ await pace.wait(jittered);
2792
+ waited += jittered;
2680
2793
  delay = Math.min(delay * 2, SNAPSHOT_COLLECTION_LOCK_RETRY_MAX_MS);
2681
2794
  }
2682
2795
  }
@@ -2688,7 +2801,7 @@ function __atomicOnDemandFailed(error, feature) {
2688
2801
  return (async () => {
2689
2802
  const root = new URL("../../", import.meta.url);
2690
2803
  const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
2691
- const key = `${root.href}#0.10.18-alpha.1`;
2804
+ const key = `${root.href}#0.10.19-alpha.1`;
2692
2805
  let release = releases.get(key);
2693
2806
  if (release === undefined) {
2694
2807
  const current = (async () => {
@@ -2716,7 +2829,7 @@ function __atomicOnDemandFailed(error, feature) {
2716
2829
  } catch {
2717
2830
  // No installation to read, as in a bundle of the package: the release the process runs decides.
2718
2831
  }
2719
- const updatedTo = typeof installed === "string" && installed !== "0.10.18-alpha.1" ? installed : running !== undefined && running.version !== "0.10.18-alpha.1" ? "0.10.18-alpha.1" : undefined;
2832
+ const updatedTo = typeof installed === "string" && installed !== "0.10.19-alpha.1" ? installed : running !== undefined && running.version !== "0.10.19-alpha.1" ? "0.10.19-alpha.1" : undefined;
2720
2833
  if (updatedTo === undefined) throw error;
2721
2834
  const application = typeof running?.name === "string" ? running.name : "atomic";
2722
2835
  const restart = new Error(`${application} was updated to ${updatedTo} while this session was running; restart it to keep using ${feature}.`, {