@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
@@ -43,10 +43,17 @@ So nothing Atomic does depends on keeping the same connection to PostgreSQL betw
43
43
 
44
44
  If you leave out `listenUrl`, Atomic notices that it is behind a pooler and stops waiting for wake-ups. Brokers then check the database for new messages every half second instead of every 5 seconds. Messages still arrive, a little later, and the database gets more queries.
45
45
 
46
- **Prepared statements.** A prepared statement is a query that PostgreSQL parses and plans once, then runs many times. Atomic can keep its frequent queries prepared, which saves the server work, but only if the pooler keeps track of them. The Atomic setting `maxPreparedStatements` controls this:
46
+ **Prepared statements.** A prepared statement is a query that PostgreSQL parses and plans once, then runs many times. Atomic can keep its frequent queries prepared, which saves the server work, but only if the pooler keeps track of them. PgBouncer 1.21 and later does, when its `max_prepared_statements` setting is above `0`. PgBouncer 1.24 and later set it to 200 by default.
47
47
 
48
- - By default, Atomic turns prepared statements off when `listenUrl` is set or the URL's port is 6432 or 6543. Most setups need nothing more.
49
- - To use them through PgBouncer, you need PgBouncer 1.21 or later with `max_prepared_statements` above `0`. PgBouncer 1.24 and later set it to 200 by default. Then set `maxPreparedStatements` in Atomic to `256`.
48
+ Atomic turns prepared statements on by itself when it finds such a PgBouncer, so you do not need to set anything:
49
+
50
+ - **PgBouncer 1.26 and later** tell each client their version and `max_prepared_statements` when it logs in. Atomic reads them from its first connection.
51
+ - **PgBouncer 1.21 to 1.25** do not. On its first connection, Atomic prepares one test statement in a transaction, and checks whether PgBouncer renamed it, as it renames the statements it keeps. Then Atomic removes the statement again. The test goes out together with Atomic's first query, so it costs no extra round trip.
52
+ - **Other poolers.** The same test compares the server process that runs it with the one the connection's cancel key names. A pooler that hands out cancel keys of its own, as PgBouncer does, gets caught this way on any port, and Atomic keeps prepared statements off behind it.
53
+ - **Anything else stays off:** PgBouncer before 1.21, PgBouncer with `max_prepared_statements = 0`, Supabase's Supavisor, other poolers, and any pooler Atomic cannot identify. This is the safe choice, because a pooler that loses prepared statements makes queries fail.
54
+ - **If your pooler listens on another port, set `listenUrl` or `maxPreparedStatements: 0`.** A pooler on a port other than 6432 or 6543 that passes the server's own cancel key through looks like PostgreSQL itself to Atomic, so prepared statements stay on there. A pooler needs `listenUrl` for wake-ups anyway.
55
+
56
+ Atomic's `maxPreparedStatements` setting overrides this. Set it to `0` to keep prepared statements off, or to `256` to turn them on without the check. If you change PgBouncer's `max_prepared_statements` to `0` while Atomic runs, the next query that needs a lost statement fails once and runs again, and Atomic stops preparing statements until it restarts.
50
57
 
51
58
  ```text
52
59
  agent processes ──> PgBouncer :6432 ──> PostgreSQL :5432
@@ -162,7 +169,7 @@ reserve_pool_timeout = 3
162
169
  max_db_connections = 85
163
170
 
164
171
  ;; Remember up to this many prepared statements per PostgreSQL connection.
165
- ;; Atomic uses them only when its maxPreparedStatements setting is above 0.
172
+ ;; Atomic finds this setting and uses prepared statements when it is above 0.
166
173
  max_prepared_statements = 200
167
174
 
168
175
  ;; Close a PostgreSQL connection unused for 10 minutes, and replace any connection after 1 hour.
@@ -300,7 +307,7 @@ What this shows:
300
307
 
301
308
  - With the database close to the agents, 80 pooled connections serve 200 agents with room to spare. Only 13 to 18 were in use at a time.
302
309
  - With the database far away, transactions last longer and lock waits hold connections, so the same pool fills up. A larger pool removed the queue. The remaining errors were lock timeouts between agents sending, claiming and delivering Intercom messages at once, which PgBouncer does not cause.
303
- - Turning on prepared statements (`maxPreparedStatements: 256`) worked through PgBouncer but did not change these times. Leave it unset unless your own measurements show a gain.
310
+ - Turning on prepared statements (`maxPreparedStatements: 256`) worked through PgBouncer but did not change these times. Atomic now turns them on by itself behind PgBouncer 1.21 or later, which saves the server parsing and planning work. Round trips are what set these times.
304
311
 
305
312
  ## Common errors
306
313
 
@@ -315,7 +322,7 @@ Atomic reports these as `StorageUnavailableError` or `StorageTransientError`. Th
315
322
  | `wake-ups: polling only, notifications do not pass the URL's transaction pooler` in `atomic storage status` | `listenUrl` is missing or points at PgBouncer. | Set `listenUrl` to PostgreSQL's own address. |
316
323
  | `too many connections for role "atomic_runtime"` | The role's `CONNECTION LIMIT` is lower than PgBouncer's pool plus the brokers' wake-up connections. | Raise the limit, or lower `default_pool_size`. |
317
324
  | `sorry, too many clients already` | PostgreSQL's `max_connections` is lower than PgBouncer's pool plus the wake-up and other connections. | Raise `max_connections`, or lower `default_pool_size` and `max_db_connections`. |
318
- | `prepared statement "atomic_…" does not exist` | Atomic's `maxPreparedStatements` is above `0`, but PgBouncer does not keep prepared statements: it is older than 1.21, or `max_prepared_statements` is `0`. | Set `max_prepared_statements` above `0` in PgBouncer, or set `maxPreparedStatements` to `0` in Atomic. |
325
+ | `prepared statement "atomic_…" does not exist` | Atomic sends prepared statements, but PgBouncer does not keep them: it is older than 1.21, or `max_prepared_statements` is `0`. Atomic turns them on by itself only behind a PgBouncer that keeps them, so this follows setting `maxPreparedStatements` by hand, or changing `max_prepared_statements` while Atomic runs. | Set `max_prepared_statements` above `0` in PgBouncer, or set `maxPreparedStatements` to `0` in Atomic. |
319
326
  | `unsupported startup parameter: <name>` | A client sent a connection setting that PgBouncer does not forward. Atomic sends only `application_name`, which PgBouncer forwards. | Add the name to `ignore_startup_parameters` for other clients that need it, such as `extra_float_digits` for Java clients. Never add `application_name`. |
320
327
  | `bouncer config error`, with `auth_query response contained null user name` in PgBouncer's log | The lookup function returned a row of empty values for an unknown role. | Declare the function with `RETURNS TABLE`, as in [A role for password lookups](#a-role-for-password-lookups). |
321
328
  | `kernel file descriptor limit: 1024` in PgBouncer's log | The service's open-file limit is below `max_client_conn`. | Raise `LimitNOFILE`, as in [Start PgBouncer](#start-pgbouncer). |
@@ -324,7 +331,7 @@ Atomic reports these as `StorageUnavailableError` or `StorageTransientError`. Th
324
331
 
325
332
  These services include a pooler of their own. We have not tested Atomic through them. The notes come from each service's documentation.
326
333
 
327
- - **Supabase.** The shared pooler, Supavisor, runs transaction mode on port 6543. Point `url` at port 6543 and `listenUrl` at the direct connection on port 5432. Supavisor does not keep prepared statements, so leave `maxPreparedStatements` at its default, which is `0` on port 6543.
334
+ - **Supabase.** The shared pooler, Supavisor, runs transaction mode on port 6543. Point `url` at port 6543 and `listenUrl` at the direct connection on port 5432. Supavisor does not keep prepared statements, so leave `maxPreparedStatements` unset. Atomic keeps them off there, because it does not identify Supavisor as a PgBouncer that keeps them.
328
335
  - **Neon.** The pooled host name ends in `-pooler` and runs PgBouncer in transaction mode. Point `url` at the pooled host and `listenUrl` at the same host name without `-pooler`.
329
336
  - **Azure Database for PostgreSQL Flexible Server.** Turn on the built-in PgBouncer with the `pgbouncer.enabled` server parameter, on General Purpose and Memory Optimized tiers. It listens on port 6432 of the same host. Point `listenUrl` at port 5432.
330
337
  - **Amazon RDS Proxy.** RDS Proxy does not pass `LISTEN`, so point `listenUrl` at the database instance's own endpoint. RDS Proxy may keep a client on one database connection ("pinning") when it sees session settings. We have not checked whether Atomic's statements cause pinning. Watch the proxy's pinning metrics in CloudWatch.
@@ -52,15 +52,15 @@ On the machine itself, `uptime` shows the load average. If it stays well below t
52
52
 
53
53
  ## Put the database close to the agents
54
54
 
55
- Saving new entries to a session takes 2 round trips. A round trip is the time a message takes to reach the server and come back, which `ping` shows. So every save takes at least twice that:
55
+ Saving new entries to a session takes 1 round trip once you have run `atomic storage migrate` as the owner role, and 2 before. A round trip is the time a message takes to reach the server and come back, which `ping` shows. So every save takes at least that long:
56
56
 
57
- | Distance to the server | One round trip | Each save, at least |
58
- | --- | --- | --- |
59
- | Same data center | about 1 ms | about 2 ms |
60
- | Same region, different zone | about 2 ms | about 4 ms |
61
- | Across a continent | about 80 ms | about 160 ms |
57
+ | Distance to the server | One round trip | Each save, at least | Before `atomic storage migrate` |
58
+ | --- | --- | --- | --- |
59
+ | Same data center | about 1 ms | about 1 ms | about 2 ms |
60
+ | Same region, different zone | about 2 ms | about 2 ms | about 4 ms |
61
+ | Across a continent | about 80 ms | about 80 ms | about 160 ms |
62
62
 
63
- We measured this on our server. At 80 ms, a save took 164 to 166 ms in the middle of the range (p50) with 25 to 200 agents. At about 10 ms through PgBouncer, a save took 23 ms. Distance also makes every lock wait longer, because a transaction holds its locks for its round trips.
63
+ We measured this on our server with 2 round trips per save. At 80 ms, a save took 164 to 166 ms in the middle of the range (p50) with 25 to 200 agents. At about 10 ms through PgBouncer, a save took 23 ms. Distance also makes every lock wait longer, because a transaction holds its locks for its round trips.
64
64
 
65
65
  Run the server in the same region as the agents, and ideally the same zone. No server setting makes up for distance.
66
66
 
@@ -286,13 +286,13 @@ atomic storage migrate --db 'postgresql://atomic_owner@db.example.com:5432/atomi
286
286
  Why it matters for performance:
287
287
 
288
288
  - **Fast starts.** An agent opens its storage quickly, in a few round trips and without taking locks, only when the database is already up to date. If it is not, each agent starts by checking and updating it, and many agents starting at once queue behind each other.
289
- - **New steps.** `atomic storage migrate` also applies changes a runtime role without DDL rights cannot make: the sequence Intercom uses to order new leases, and `fillfactor` on the busy tables. Until it runs, agents keep working, but without those gains.
289
+ - **New steps.** `atomic storage migrate` also applies changes a runtime role without DDL rights cannot make: the sequence Intercom uses to order new leases, `fillfactor` on the busy tables, and the function that saves entries to a session in 1 round trip instead of 2. Until it runs, agents keep working, but without those gains. Agents find the function the next time they start.
290
290
 
291
291
  ## Checklist
292
292
 
293
293
  | Step | Restart needed | Measured on our server |
294
294
  | --- | --- | --- |
295
- | Run the database in the same region as the agents | — | Yes: 2 round trips per save |
295
+ | Run the database in the same region as the agents | — | Yes: 2 round trips per save, 1 after `atomic storage migrate` |
296
296
  | Size `max_connections` and per-role limits from the connection count, or put PgBouncer in front | `max_connections` only | Yes: raised 300 to 400, role 150 to 300 |
297
297
  | Set `shared_buffers` to about a quarter of memory | Yes | Kept 8 GB of 30 GB |
298
298
  | Reserve huge pages with `vm.nr_hugepages` and check `huge_pages_status` | Yes | Yes: `on`, 4259 pages needed, 4350 reserved |
package/docs/sessions.md CHANGED
@@ -180,6 +180,14 @@ Type anywhere in `/tree` to filter entries through the inline search bar.
180
180
 
181
181
  `atomic --fork <id>`, missing-cwd **Fork**, and same-store SDK `forkTo()` copy all branches. Cross-store forks copy only current context without retired turns or private task records, and reopening warns `Parent history is in its original store or is no longer available.`. For full portable backups of all branches, use `atomic storage export` and `atomic storage import`.
182
182
 
183
+ ### Forks share history within a store {#forks-share-history}
184
+
185
+ In a SQLite, PostgreSQL, or libSQL store, a fork shares the history it was forked from instead of copying it. A fork of a long session is created as quickly as a fork of a short one. The fork reads and resumes exactly as a copy would, and later changes to the parent never show up in it. A store starts sharing on its own; see [shared-history forks](/storage#shared-history-forks) for when it waits, for example while an older Atomic still has a session open. JSONL and in-memory stores always copy.
186
+
187
+ Deleting a session that forks still share history with removes it from every list and search right away. The store keeps the part of its history those forks use, and frees it once the last of them is deleted or no longer needs it. Rewriting such a session first gives each fork its own copy of what it uses.
188
+
189
+ Sharing never crosses a store boundary. Anything that takes a session out of its store makes a full standalone copy: `/export`, `/share`, `atomic --export`, `atomic storage export`, a fork into another store, and moving sessions between stores. The copy holds every entry and tool output the session inherited, and it doesn't need the sessions it was forked from. Importing a session always writes it as a standalone session, never as a fork of anything in the target store.
190
+
183
191
  ## Branch summaries
184
192
 
185
193
  When `/tree` switches away from a branch, Atomic can optionally summarize the abandoned branch. You can choose no summary, the default summary, or custom focus instructions. When `branchSummary.skipPrompt` is enabled, Atomic skips the prompt and defaults to no summary. See [Branch summaries](/compaction#branch-summaries).
@@ -266,6 +274,7 @@ Sessions auto-save to `~/.atomic/workflows/journal.sqlite` unless you configure
266
274
  - **Project trust and resume hints.** Project-local storage settings apply after project trust approval. New conversations switch before saving, while resumed conversations stay in their original store. Keep generated `--session-dir`, `--session-store`, or `--session-prefix` flags when reopening non-default stores, such as `atomic --session-store "/data/project A/sessions.sqlite" --session-prefix project_ --session <id>`.
267
275
  - **Import and export.** `--import <file>` or `/import <file>` imports a JSONL export verbatim, including [worktree snapshots](/worktree-snapshots) written by `/export <file>.jsonl`. Import upgrades older supported formats automatically and raises `SessionExistsError` if the ID already exists. Empty imported IDs reopen through `atomic --session ""` or the picker.
268
276
  - **Ephemeral runs (`--no-session`).** Nothing is saved to a resumable store. When an idle subagent is unloaded from memory during `--no-session`, its history is temporarily saved to a private file in your agent directory and removed on exit; stale files left after a crash are cleaned up on a later startup on the same host. See [Releasing idle sessions](/sdk#releasing-idle-sessions).
277
+ - **Forks share history.** A fork in the same store reads the history it keeps from its parent instead of storing a copy, so forking a long session is about as fast as forking a short one. The first time this release opens a store, it marks the store so that older Atomic releases can no longer open it; it waits to do so until no session of an older release is running on that database. See [Shared-history forks](/storage#shared-history-forks).
269
278
  - **Session stats (`/session`).** Displays the session ID, message count, tokens, and cost. Counts update after each completed message, and per-model cost and cache breakdowns appear once history matches totals.
270
279
 
271
280
  ### Choosing a store
package/docs/storage.md CHANGED
@@ -124,8 +124,12 @@ When the runtime role lacks a required privilege or the schema is behind the cur
124
124
 
125
125
  Once the schema is current, opening the session store or an Intercom broker's shared state reads the schema catalog and the migration ledger once, in two statements sent together, and runs no schema transaction and takes no lock. Many processes can therefore start at once against one database without waiting for each other or for other writers. Only an open that finds something missing or behind takes the schema lock and checks again under it.
126
126
 
127
+ On SQLite and libSQL, Atomic records which version of each Intercom store's tables it set up in a table named `<prefix>atomic_schema_stamps`, together with SQLite's count of schema changes (`PRAGMA schema_version`). Atomic writes that record during the second open of a database, in the write transaction that open already takes; from the third open on, opening a broker whose tables are current takes no write lock. Any later change to the schema, by any program or by an older Atomic that doesn't keep the record, makes the next open check those tables again. Older Atomic versions ignore the table.
128
+
127
129
  `atomic storage migrate` sets `fillfactor = 80` on the sessions table and the Intercom lease table, which every append and lease renewal updates, so those updates usually stay on their page without touching an index. The setting applies to pages written after it. To apply it to existing pages too, run `VACUUM FULL` on those two tables during a quiet period, or use `pg_repack` to do it without a long lock. Both steps are optional. A runtime role that cannot alter these tables leaves the setting to the owner's `atomic storage migrate` and keeps working.
128
130
 
131
+ `atomic storage migrate` also creates a function in the `atomic` schema that saves new entries to a session in 1 round trip instead of 2, and lets every role that may write sessions run it. The function runs with the rights of the role that calls it, so it gives the runtime role no new rights. Each process checks for the function when it opens the database, with no extra query. Until you run `atomic storage migrate`, or if the runtime role may not run the function, saves take 2 round trips as before. Long entries that Atomic stores in chunks, and entries that refer back to earlier parts of a branch, also take the 2-round-trip path. Older Atomic versions ignore the function and keep working.
132
+
129
133
  If you have not run `atomic storage migrate` after an upgrade and a low-privilege runtime role clones a session across connections, Atomic falls back to copying in memory and prints a one-time warning asking you to run `atomic storage migrate` as the owner role.
130
134
 
131
135
  Every Atomic process opens one pool of up to 8 connections (`maxConnections`) per database, however many stores it opens there, plus a smaller pool for reads. See [Connection budget](#connection-budget) for what each process holds, and [Tuning for many concurrent agents](#tuning-for-many-concurrent-agents) for how to size a fleet.
@@ -182,7 +186,7 @@ You can also edit this configuration directly. For password authentication in ad
182
186
  | `connectTimeoutMs` | `10000` | How long opening a connection, or waiting for a free one, may take, in milliseconds. A positive integer |
183
187
  | `idleTimeoutMs` | `300000` | How long, in milliseconds, a pool's last connection stays open after the pool's last call. Connections opened for a burst close after 10 seconds idle, or after `idleTimeoutMs` when it is shorter. A positive integer |
184
188
  | `keepAliveIdleMs` | `60000` | How long, in milliseconds, a connection sits unused before Atomic starts TCP keepalive probes on it. A positive integer |
185
- | `maxPreparedStatements` | `256`, or `0` when `listenUrl` is set or the URL's port is 6432 or 6543 | Most statements each connection keeps prepared on the server, so the server plans each one once. A non-negative integer. `0` turns prepared statements off. Each prepared statement uses some server memory per connection |
189
+ | `maxPreparedStatements` | `256`, or `0` when `listenUrl` is set, the URL's port is 6432 or 6543, or Atomic finds a pooler, unless Atomic finds PgBouncer 1.21 or later with `max_prepared_statements` above `0`. If your pooler listens on another port, set `listenUrl` or `0` | Most statements each connection keeps prepared on the server, so the server plans each one once. A non-negative integer. `0` turns prepared statements off. Each prepared statement uses some server memory per connection. See [Prepared statements](/guides/postgres-pgbouncer#how-atomic-works-with-pgbouncer) |
186
190
  | `listenUrl` | `url` | Direct endpoint for [wake-ups](#wake-ups) when `url` uses a transaction pooler. Enforces the same URL, TLS, proxy, and no-embedded-password rules as `url` (`credential-in-url`) |
187
191
  | `schema` | `"atomic"` | Schema name starting with a lowercase ASCII letter or `_`, followed by lowercase letters, digits, or `_` (1 to 63 characters) |
188
192
  | `proxy` | From environment | `http://` or `https://` proxy URL for all connections, or `"none"` to connect directly |
@@ -319,7 +323,7 @@ Running `atomic install npm:@azure/identity` (or the AWS or Google SDK) installs
319
323
  - **`StorageTransientError` with code `read-only-server` (`25006`).** Point `url` at the primary read/write endpoint instead of a replica, or retry once failover or storage-full recovery completes.
320
324
  - **`sorry, too many clients already`, `remaining connection slots are reserved for roles with the SUPERUSER attribute`, or `too many connections for role "<role>"` (`53300`).** The server, or the role's `CONNECTION LIMIT`, has no connection left. Atomic reports `StorageTransientError` with code `connection-refused`, and the server's message is its cause. Lower `maxConnections` or `readerMaxConnections`, raise the server's `max_connections`, or put [PgBouncer](/guides/postgres-pgbouncer) in front. See [Tuning for many concurrent agents](#tuning-for-many-concurrent-agents).
321
325
  - **`timeout exceeded when trying to connect`.** Every connection in the process's pool stayed busy, or a new connection took longer than `connectTimeoutMs` to open. Atomic reports `StorageTransientError` with code `connection-refused`, and this message is its cause. Raise `maxConnections` if the server has connections to spare. Raise `connectTimeoutMs` if the server is far away or slow to accept connections.
322
- - **`prepared statement "atomic_…" does not exist` or `already exists` behind a pooler.** The pooler does not keep prepared statements across connections. Atomic then stops preparing statements for the rest of the process and retries the call, so you usually see only a one-time warning. A call Atomic cannot retry fails once with `StorageTransientError` code `connection-lost`, and the pooler's message is its cause. Set `maxPreparedStatements` to `0`, or on PgBouncer 1.21 or later set `max_prepared_statements` above `0`.
326
+ - **`prepared statement "atomic_…" does not exist` or `already exists` behind a pooler.** The pooler does not keep prepared statements across connections. Atomic then stops preparing statements for the rest of the process and retries the call, so you usually see only a one-time warning. A call Atomic cannot retry fails once with `StorageTransientError` code `connection-lost`, and the pooler's message is its cause. Set `maxPreparedStatements` to `0`, or on PgBouncer 1.21 or later set `max_prepared_statements` above `0`. Atomic turns prepared statements on by itself only behind a PgBouncer it has confirmed keeps them, so you see this only after setting `maxPreparedStatements` yourself, behind a pooler on another port, or after changing PgBouncer's setting while Atomic runs.
323
327
  - **`StorageTransientError` with code `lock-conflict` or `transaction-timeout`.** The server cancelled a statement or transaction that waited too long or exceeded `statementTimeoutMs`, and wrote nothing. Repeated errors indicate server overload.
324
328
  - **`wake-ups: polling only` in `atomic storage status`.** Messages still arrive via polling. See [Wake-ups](#wake-ups) to restore `LISTEN`/`NOTIFY`.
325
329
  - **Failover or pooler restart disconnects.** Reported as `StorageTransientError` with code `connection-lost`.
@@ -566,12 +570,12 @@ The [PgBouncer guide](/guides/postgres-pgbouncer) has a complete, tested PgBounc
566
570
 
567
571
  Set these in the same `options` object, or pass them to `openPostgresDatabase`. Each takes a positive integer number of milliseconds.
568
572
 
569
- - **Distance.** Saving new entries to a session takes 2 round trips to the server. Put the database in the same region as the agents. A machine 80 ms away from the server spends at least 160 ms on each save.
573
+ - **Distance.** Saving new entries to a session takes 1 round trip to the server once `atomic storage migrate` has run, and 2 before. Put the database in the same region as the agents. A machine 80 ms away from the server spends at least 80 ms on each save, or 160 ms without the migration.
570
574
  - **`idleTimeoutMs`** (default `300000`, 5 minutes). Unused connections stay open this long, so the next call skips the connection and TLS handshakes. A process that exits closes its connections at once. Lower it, for example to `30000`, when long-running processes sit idle and the server is near its limit.
571
575
  - **`statementTimeoutMs`** (default `30000`). The server cancels a statement that runs longer. Raise it only if statements fail with `StorageTransientError` code `transaction-timeout` on a slow server. A lower value does not raise throughput.
572
576
  - **`connectTimeoutMs`** (default `10000`). Opening a connection, or waiting for a free one in the pool, fails after this long. Raise it for a distant server or one that is slow to accept connections.
573
577
  - **`keepAliveIdleMs`** (default `60000`). Atomic sends TCP keepalive probes on a connection that has been unused this long. Lower it if calls fail with `StorageTransientError` code `connection-lost` after pauses, which means a firewall, NAT or load balancer dropped idle connections.
574
- - **`maxPreparedStatements`** (default `256`). Each connection keeps up to this many statements prepared on the server, so the server plans each statement once per connection. It does not change round trips. Atomic turns it off by default when `listenUrl` is set or the URL's port is 6432 or 6543, the usual pooler ports. Set it to `0` behind any other pooler that does not keep prepared statements, such as PgBouncer before 1.21 or Supabase's shared pooler. On PgBouncer 1.21 to 1.23, prepared statements work only when PgBouncer's `max_prepared_statements` is above `0`; 1.24 and later set it to 200 by default. Lower the value if the server is short of memory per connection.
578
+ - **`maxPreparedStatements`** (default `256`). Each connection keeps up to this many statements prepared on the server, so the server plans each statement once per connection. It does not change round trips. Atomic turns it off by default when `listenUrl` is set or the URL's port is 6432 or 6543, the usual pooler ports, unless it finds PgBouncer 1.21 or later there with `max_prepared_statements` above `0`. 1.24 and later set that to 200 by default. Atomic also keeps it off behind any pooler that hands out its own cancel keys, on any port. If your pooler listens on another port, set `listenUrl` or `maxPreparedStatements: 0`. Lower the value if the server is short of memory per connection.
575
579
 
576
580
  #### Check the effect
577
581
 
@@ -663,6 +667,8 @@ A local SQLite file has one writer at a time. Atomic queues the writers of every
663
667
 
664
668
  `atomic storage export <dir>` writes sessions to JSONL files, and `atomic storage import <dir>` restores them. Use these commands to move sessions between machines or migrate from one storage backend to another.
665
669
 
670
+ Forks [share history within a store](/sessions#forks-share-history). Export and moving between stores always make full standalone copies. Each exported file holds every entry and tool output of its session, including what the session inherited from the sessions it was forked from. It restores into any backend without them. Import writes every session as a standalone session, so deleting the original parents, in either store, never affects an imported copy. The header's `parentSessionId` is kept only as a record of where the session came from.
671
+
666
672
  ```bash
667
673
  atomic storage export <dir> [--limit <n>] [--since <time>]
668
674
  atomic storage import <dir>
@@ -763,7 +769,7 @@ Payloads that still exceed a backend's limit fail non-retryably with `StoragePay
763
769
 
764
770
  ### Upgrading older SQLite and shared stores
765
771
 
766
- - **One-way session schema upgrade.** Writing the first chunked session entry permanently upgrades the session schema from version `1` to `2`. Upgrade every host sharing a database together because older releases reject version 2 stores with `StorageSchemaVersionError`.
772
+ - **One-way session schema upgrade.** Writing the first chunked session entry permanently upgrades the session schema from version `1` to `2`. Upgrade every host sharing a database together because older releases reject version 2 stores with `StorageSchemaVersionError`. Version `3` comes from the switch to [shared-history forks](#shared-history-forks), which waits until no older release runs a session on the database.
767
773
  - **Offline local snapshot chunk migration.** On older local SQLite files, background snapshot collection migrates legacy snapshot chunk tables automatically when free disk space allows. To migrate a cleanly closed local SQLite file offline with bounded WAL growth, stop all Atomic processes using that file and run:
768
774
 
769
775
  ```bash
@@ -772,6 +778,41 @@ atomic storage move-snapshot-chunks <sqlite-file> [--prefix <prefix>]
772
778
 
773
779
  The file must be a local WAL-mode SQLite database with an empty WAL and without `auto_vacuum=FULL`. Never delete a WAL file manually after a crash; let SQLite recover it first. PostgreSQL requires no chunk migration.
774
780
 
781
+ ## Shared-history forks
782
+
783
+ A fork made in the same store as its parent shares the parent's history instead of copying it. The fork stores a note of which part of the parent's history it continues from, and reads those entries from the parent; only the entries added after the fork are its own. This applies to `/fork`, `/clone`, `atomic --fork`, and subagents that start from a copy of their parent's conversation. Forking a long session then takes about as long as forking a short one, and the store does not grow by a second copy of the parent's history.
784
+
785
+ There is nothing to turn on or configure. What stays the same:
786
+
787
+ - A fork looks and behaves like a copied fork: the same entries, search results, tree, resume, and export.
788
+ - Changing or deleting the parent never changes a fork. Before the parent's entries change or go away, Atomic copies the entries each fork still reads into that fork, or keeps them stored, hidden, until no fork reads them.
789
+ - `atomic storage export` writes each fork's full history, and a fork into another store copies, so nothing outside the store depends on it.
790
+ - JSONL session directories and in-memory stores always copy.
791
+
792
+ ### How a fork reads its history
793
+
794
+ A fork that shares its parent's history keeps a short list of ranges, for example "my entries 1 to 400 are the parent's entries 1 to 400". Every entry added after the fork, and any entry the fork changed, is stored in the fork itself.
795
+
796
+ - **One query.** When Atomic reads a fork, it looks the list up in the same database query that reads the entries, so the list and the entries always come from the same moment. No copy of the list is kept in memory between reads, so a read never uses an out-of-date list.
797
+ - **Up to the fork point only.** A fork reads its parent's entries only up to the point where it was made. When the parent keeps going, the new entries are the parent's alone.
798
+ - **The parent cannot change a fork.** If the parent is later rewritten, Atomic first copies the entries the fork still uses into the fork, in the same step. If the parent is deleted, its entries stay stored, hidden, until no fork uses them.
799
+ - **Forking never holds the parent up.** On PostgreSQL, the parent keeps appending while forks are made from it. Making a fork takes the same 2 round trips as creating a session, whatever the parent's length or how many forks deep the chain goes, and the first load of a fork takes the same round trips as a session of the same length.
800
+
801
+ ### Older Atomic versions {#older-atomic-versions}
802
+
803
+ A store whose forks share history keeps them in a form that Atomic releases without this feature cannot read correctly: such a release would show a fork's own entries as its whole history, and could delete or rewrite a parent that forks still read. So the first time this release or a later one opens a store, it marks the store as needing this release or later. From then on, an older release refuses to open the store with `StorageSchemaVersionError` ("this store needs a newer Atomic"). The mark is permanent: a store cannot go back to older releases.
804
+
805
+ The switch never pulls a store out from under an older Atomic that is using it:
806
+
807
+ - **It waits for older versions to stop.** Every running session records in the store which release runs it. While a session of an older release is running on any machine that uses the store, Atomic leaves the store as it is, and forks keep copying. The next time Atomic opens the store after those sessions have stopped, for example when a session starts or resumes, the switch happens. A session on the same machine counts as running while its process runs. A session on another machine counts while its record is refreshed, about every 15 seconds; one whose record is more than a minute old, for example on a machine that crashed, no longer counts.
808
+ - **It happens in one step.** The fork tables and the new mark are written in one transaction that waits for writes already in progress to finish, so upgraded sessions keep working through it, and two machines switching at once is safe.
809
+ - **It costs nothing once done.** A store that is already switched opens with the same reads as before.
810
+ - **It needs table privileges.** On PostgreSQL, a runtime role without DDL privileges cannot create the fork tables, so forks there keep copying until the owner runs `atomic storage migrate`, which switches the database too. The new tables are `session_fork_segments`, `session_fork_lineage`, `session_fork_tombstones`, and `session_fork_detach`, and the runtime role reaches them through the default privileges granted in [Set up the database](#set-up-the-database).
811
+
812
+ None of this needs any action and none of it is reported as an error. With debug mode on, Atomic notes in the debug log when it leaves the switch for later, and why.
813
+
814
+ If you still run an older Atomic against a shared database, for example on a machine you have not upgraded yet, upgrade it too. Once its sessions have stopped and an upgraded session opens the store, the older release cannot open the store again. To move sessions back to an older release after the switch, export them with `atomic storage export`, which writes each fork's full history, then import them with that release into a new store.
815
+
775
816
  ## Workflow data from earlier releases
776
817
 
777
818
  Releases before 0.10.0 stored workflow runs under `workflows/journal/`, `workflows/pool/`, `workflows/runs/`, and `wf_*` tables. Atomic no longer runs those workflows and never opens, modifies, or deletes that data, so existing stores continue working and downgrading preserves old runs.
@@ -1019,7 +1060,7 @@ Multiple stores can share one caller-owned `database` without closing it.
1019
1060
 
1020
1061
  Non-SQL backends can implement `openSessionStore` directly (each session has one writer):
1021
1062
 
1022
- - **Required for `history://`.** Implement `readEntryRange(id, query)` honoring `fromSeq`, `toSeq`, `maxChars`, `largeEntryBytes`, `skipTypes`, and `signal`. Return freshly owned UTF-8 JSON buffers and `{ entries: [{ seq, entry }], throughSeq, lastSeq }` without falling back to whole-session `load()`.
1063
+ - **Required for `history://`.** Implement `readEntryRange(id, query)` honoring `fromSeq`, `toSeq`, `seqs`, `maxChars`, `largeEntryBytes`, `skipTypes`, and `signal`. When `query.seqs` lists sequence numbers, return only the entries at those numbers. A `history://` search reads the entries it found, and the lines around them, this way, in one call. A store that returns the whole range instead still gives the same results, but reads more. Return freshly owned UTF-8 JSON buffers and `{ entries: [{ seq, entry }], throughSeq, lastSeq }` without falling back to whole-session `load()`.
1023
1064
  - **Optional fast-path methods.** Implementing these avoids loading entire sessions into memory (stores implementing only `load()` still work with higher memory use):
1024
1065
 
1025
1066
  | Method | Purpose |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/atomic",
3
- "version": "0.10.11-alpha.1",
3
+ "version": "0.10.11-alpha.2",
4
4
  "description": "Atomic coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "atomicConfig": {
@@ -118,13 +118,13 @@
118
118
  "prepack": "node -e \"require('node:fs').existsSync('scripts/split-dist.mjs') && import('./scripts/split-dist.mjs').then(() => import('./scripts/write-startup-files.mjs')).then(() => import('./scripts/write-startup-stages.mjs'))\""
119
119
  },
120
120
  "dependencies": {
121
- "@bastani/atomic-natives": "0.10.11-alpha.1",
122
- "@bastani/atomic-ai": "0.10.11-alpha.1",
123
- "@bastani/atomic-agent-core": "0.10.11-alpha.1",
124
- "@bastani/atomic-codemode": "0.10.11-alpha.1",
125
- "@bastani/atomic-tui": "0.10.11-alpha.1",
126
- "@bastani/atomic-schema": "0.10.11-alpha.1",
127
- "@bastani/atomic-telemetry": "0.10.11-alpha.1",
121
+ "@bastani/atomic-natives": "0.10.11-alpha.2",
122
+ "@bastani/atomic-ai": "0.10.11-alpha.2",
123
+ "@bastani/atomic-agent-core": "0.10.11-alpha.2",
124
+ "@bastani/atomic-codemode": "0.10.11-alpha.2",
125
+ "@bastani/atomic-tui": "0.10.11-alpha.2",
126
+ "@bastani/atomic-schema": "0.10.11-alpha.2",
127
+ "@bastani/atomic-telemetry": "0.10.11-alpha.2",
128
128
  "@silvia-odwyer/photon-node": "0.3.4",
129
129
  "chalk": "6.0.0",
130
130
  "glob": "14.0.6",