@bastani/atomic 0.10.10 → 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 (402) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/README.md +1 -1
  3. package/dist/_shared/dist-KOELCESV.js +2 -2
  4. package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
  5. package/dist/_shared/lib-4PES5P4V.js +2 -2
  6. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +11 -13
  7. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
  8. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +9 -9
  9. package/dist/_shared/mode-shared-2QJSCUM6.js +55 -18
  10. package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -1
  11. package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
  12. package/dist/_shared/runtime-O4KCSG4C.js +5 -5
  13. package/dist/_shared/{sdk-RRLVN7ER.js → sdk-IQMULKFU.js} +2962 -470
  14. package/dist/_shared/sdk-IQMULKFU.js.map +1 -0
  15. package/dist/_shared/session-data-AHTU7IS6.js +4 -4
  16. package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
  17. package/dist/_shared/settings-startup-8-DNZ2RIHM.js +1 -1
  18. package/dist/_shared/{settings-startup-4QCVCI53.js → settings-startup-HXQLSUWM.js} +8 -2
  19. package/dist/_shared/settings-startup-HXQLSUWM.js.map +1 -0
  20. package/dist/_shared/{startup-0-0-4VG2G44V.js → startup-0-0-3IXNMFM2.js} +482 -53
  21. package/dist/_shared/startup-0-0-3IXNMFM2.js.map +1 -0
  22. package/dist/_shared/{startup-0-1-XTIL65D4.js → startup-0-1-7T2IAE7J.js} +121 -251
  23. package/dist/_shared/startup-0-1-7T2IAE7J.js.map +1 -0
  24. package/dist/_shared/{startup-0-2-27OWFHV6.js → startup-0-2-5QHPCEON.js} +293 -10
  25. package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -0
  26. package/dist/_shared/{startup-0-3-T4DVFYWX.js → startup-0-3-4ZYBYQNM.js} +273 -14
  27. package/dist/_shared/startup-0-3-4ZYBYQNM.js.map +1 -0
  28. package/dist/_shared/startup-0-4-ZMJV547D.js +6 -6
  29. package/dist/_shared/{startup-0-5-FD2P735I.js → startup-0-5-YDW47QX6.js} +29 -71
  30. package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -0
  31. package/dist/_shared/startup-10-0-TDQNBDDL.js +9 -9
  32. package/dist/_shared/startup-12-0-55AAXBJZ.js +4 -4
  33. package/dist/_shared/startup-14-0-MLX36RBG.js +6 -6
  34. package/dist/_shared/startup-15-0-YUKGAC63.js +34 -10
  35. package/dist/_shared/startup-15-0-YUKGAC63.js.map +1 -1
  36. package/dist/_shared/startup-15-1-4S7FLMNG.js +10 -9
  37. package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
  38. package/dist/_shared/startup-8-0-34CBHPZH.js +421 -84
  39. package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
  40. package/dist/_shared/{startup-8-1-4KANEHRA.js → startup-8-1-X32CYSXB.js} +1291 -722
  41. package/dist/_shared/startup-8-1-X32CYSXB.js.map +1 -0
  42. package/dist/_shared/storage-command-7MGXLJGZ.js +17 -9
  43. package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
  44. package/dist/_shared/task-reference-stream-JWMUZSJX.js +1 -1
  45. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  46. package/dist/_shared/tree-outline-MUEPK5B7.js +3 -3
  47. package/dist/builtin/intercom/CHANGELOG.md +29 -0
  48. package/dist/builtin/intercom/broker/broker.bundle.mjs +1138 -384
  49. package/dist/builtin/intercom/broker/database-wake-up-bus.ts +103 -24
  50. package/dist/builtin/intercom/broker/multinode-router.ts +42 -21
  51. package/dist/builtin/intercom/broker/multinode-state-store.ts +22 -1
  52. package/dist/builtin/intercom/broker/open-broker-state.ts +82 -31
  53. package/dist/builtin/intercom/broker/paths.ts +8 -4
  54. package/dist/builtin/intercom/broker/released-asker-remote-replies.ts +18 -6
  55. package/dist/builtin/intercom/broker/sql-add-column.ts +4 -1
  56. package/dist/builtin/intercom/broker/sql-ended-child-queue-store.ts +65 -44
  57. package/dist/builtin/intercom/broker/sql-held-send-store.ts +11 -3
  58. package/dist/builtin/intercom/broker/sql-known-session-store.ts +24 -12
  59. package/dist/builtin/intercom/broker/sql-lease-store.ts +386 -65
  60. package/dist/builtin/intercom/broker/sql-outbox-store.ts +462 -130
  61. package/dist/builtin/intercom/broker/sql-pending-ask-store.ts +20 -9
  62. package/dist/builtin/intercom/broker/sql-released-ask-store.ts +14 -6
  63. package/dist/builtin/intercom/broker/sql-restoring-reservation-store.ts +27 -11
  64. package/dist/builtin/intercom/broker/sql-schema.ts +198 -5
  65. package/dist/builtin/intercom/broker/sql-sent-message-authority.ts +97 -34
  66. package/dist/builtin/intercom/index.bundle.mjs +11 -8
  67. package/dist/builtin/intercom/package.json +1 -1
  68. package/dist/builtin/mcp/index.bundle.mjs +1 -1
  69. package/dist/builtin/mcp/package.json +1 -1
  70. package/dist/builtin/subagents/CHANGELOG.md +18 -0
  71. package/dist/builtin/subagents/package.json +1 -1
  72. package/dist/builtin/subagents/skills/skill-creator/SKILL.md +1 -1
  73. package/dist/builtin/subagents/src/extension/index.bundle.mjs +62 -23
  74. package/dist/builtin/web-access/index.bundle.mjs +1 -1
  75. package/dist/builtin/web-access/package.json +1 -1
  76. package/dist/cli/args.js +2 -2
  77. package/dist/cli/auth-cli.code.js +6 -6
  78. package/dist/cli/auth-cli.impl.js +3 -3
  79. package/dist/cli/auth-cli.js +3 -3
  80. package/dist/cli/blueprint-command.code.js +4 -4
  81. package/dist/cli/blueprint-command.impl.js +3 -3
  82. package/dist/cli/blueprint-command.js +3 -3
  83. package/dist/cli/intercom-command.code.js +3 -3
  84. package/dist/cli/intercom-command.impl.js +3 -3
  85. package/dist/cli/intercom-command.js +3 -3
  86. package/dist/cli/list-models.code.js +2 -2
  87. package/dist/cli/list-models.impl.js +3 -3
  88. package/dist/cli/list-models.js +3 -3
  89. package/dist/cli/session-picker.code.js +2 -2
  90. package/dist/cli/session-picker.impl.js +3 -3
  91. package/dist/cli/session-picker.js +3 -3
  92. package/dist/cli/startup-ui.code.js +2 -2
  93. package/dist/cli/startup-ui.impl.js +3 -3
  94. package/dist/cli/startup-ui.js +3 -3
  95. package/dist/cli/storage-command.impl.js +3 -3
  96. package/dist/cli/storage-command.js +3 -3
  97. package/dist/cli/storage-search-session.code.js +3 -3
  98. package/dist/cli/storage-search-session.impl.js +3 -3
  99. package/dist/cli/storage-search-session.js +3 -3
  100. package/dist/cli/team-command.code.js +3 -3
  101. package/dist/cli/team-command.impl.js +3 -3
  102. package/dist/cli/team-command.js +3 -3
  103. package/dist/cli.js +2 -2
  104. package/dist/core/agent-session-methods.d.ts +3 -0
  105. package/dist/core/agent-session-methods.js.map +1 -1
  106. package/dist/core/agent-session.d.ts +1 -0
  107. package/dist/core/compaction/compactor.d.ts +2 -0
  108. package/dist/core/debug.impl.js +3 -3
  109. package/dist/core/debug.js +3 -3
  110. package/dist/core/export-html/card-projection.code.js +1 -1
  111. package/dist/core/export-html/card-projection.impl.js +3 -3
  112. package/dist/core/export-html/card-projection.js +3 -3
  113. package/dist/core/export-html/index.code.js +2 -2
  114. package/dist/core/export-html/index.impl.js +3 -3
  115. package/dist/core/export-html/index.js +3 -3
  116. package/dist/core/export-html/json-spans.impl.js +3 -3
  117. package/dist/core/export-html/json-spans.js +3 -3
  118. package/dist/core/export-html/oversized-render-inputs.code.js +2 -2
  119. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  120. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  121. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  122. package/dist/core/export-html/tool-renderer.js +3 -3
  123. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  124. package/dist/core/extensions/jiti-loader.js +3 -3
  125. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  126. package/dist/core/extensions/jiti-static-loader.js +3 -3
  127. package/dist/core/extensions/loader-host-modules.code.js +1 -1
  128. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  129. package/dist/core/extensions/loader-host-modules.js +3 -3
  130. package/dist/core/extensions/loader-virtual-modules.js +2 -2
  131. package/dist/core/extensions/runner-context.js +4 -4
  132. package/dist/core/extensions/runner-context.js.map +1 -1
  133. package/dist/core/intercom-broker-control-host.code.js +1 -1
  134. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  135. package/dist/core/intercom-broker-control-host.js +3 -3
  136. package/dist/core/intercom-broker-control.code.js +3 -3
  137. package/dist/core/intercom-broker-control.impl.js +3 -3
  138. package/dist/core/intercom-broker-control.js +3 -3
  139. package/dist/core/model-registry.js +1 -1
  140. package/dist/core/model-resolver-defaults.d.ts +3 -2
  141. package/dist/core/package-manager-storage-adapters.code.js +1 -1
  142. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  143. package/dist/core/package-manager-storage-adapters.js +3 -3
  144. package/dist/core/sdk.code.js +4 -5
  145. package/dist/core/sdk.impl.js +3 -3
  146. package/dist/core/sdk.js +3 -3
  147. package/dist/core/session-manager-core.d.ts +5 -2
  148. package/dist/core/session-manager-core.js +39 -23
  149. package/dist/core/session-manager-core.js.map +1 -1
  150. package/dist/core/session-manager-list.impl.js +3 -3
  151. package/dist/core/session-manager-list.js +3 -3
  152. package/dist/core/session-manager.code.js +3 -3
  153. package/dist/core/session-manager.impl.js +3 -3
  154. package/dist/core/session-manager.js +3 -3
  155. package/dist/core/session-open-markers.js +3 -0
  156. package/dist/core/session-open-markers.js.map +1 -0
  157. package/dist/core/session-storage.code.js +1 -1
  158. package/dist/core/session-storage.impl.js +3 -3
  159. package/dist/core/session-storage.js +3 -3
  160. package/dist/core/storage/added-exports.d.ts +6 -0
  161. package/dist/core/storage/added-exports.js +19 -0
  162. package/dist/core/storage/added-exports.js.map +1 -0
  163. package/dist/core/storage/database.d.ts +53 -0
  164. package/dist/core/storage/database.js.map +1 -1
  165. package/dist/core/storage/fenced-paths.d.ts +47 -0
  166. package/dist/core/storage/fenced-paths.js +53 -0
  167. package/dist/core/storage/fenced-paths.js.map +1 -1
  168. package/dist/core/storage/file-identity.js +31 -2
  169. package/dist/core/storage/file-identity.js.map +1 -1
  170. package/dist/core/storage/index.d.ts +4 -1
  171. package/dist/core/storage/index.js +5 -2
  172. package/dist/core/storage/index.js.map +1 -1
  173. package/dist/core/storage/migrations.d.ts +33 -2
  174. package/dist/core/storage/migrations.js +73 -5
  175. package/dist/core/storage/migrations.js.map +1 -1
  176. package/dist/core/storage/node-sqlite-thread.js +48 -6
  177. package/dist/core/storage/node-sqlite-thread.js.map +1 -1
  178. package/dist/core/storage/node-sqlite.js +137 -4
  179. package/dist/core/storage/node-sqlite.js.map +1 -1
  180. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  181. package/dist/core/storage/offline-snapshot-file.js +3 -3
  182. package/dist/core/storage/prefix.d.ts +3 -2
  183. package/dist/core/storage/prefix.js +23 -2
  184. package/dist/core/storage/prefix.js.map +1 -1
  185. package/dist/core/storage/provider.js +2 -2
  186. package/dist/core/storage/schema-catalog.d.ts +120 -0
  187. package/dist/core/storage/schema-catalog.js +351 -0
  188. package/dist/core/storage/schema-catalog.js.map +1 -0
  189. package/dist/core/storage/selection.js +2 -2
  190. package/dist/core/storage/session/branch-fork-source.code.js +47 -25
  191. package/dist/core/storage/session/branch-fork-source.code.js.map +1 -1
  192. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  193. package/dist/core/storage/session/branch-fork-source.js +3 -3
  194. package/dist/core/storage/session/card-view.impl.js +3 -3
  195. package/dist/core/storage/session/card-view.js +3 -3
  196. package/dist/core/storage/session/child-reader.code.js +4 -4
  197. package/dist/core/storage/session/child-reader.impl.js +3 -3
  198. package/dist/core/storage/session/child-reader.js +3 -3
  199. package/dist/core/storage/session/chunked-resume-projection.code.js +1 -1
  200. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  201. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  202. package/dist/core/storage/session/errors.js +1 -1
  203. package/dist/core/storage/session/expanded-child-details.code.js +4 -4
  204. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  205. package/dist/core/storage/session/expanded-child-details.js +3 -3
  206. package/dist/core/storage/session/fork-detach.d.ts +118 -0
  207. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  208. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  209. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  210. package/dist/core/storage/session/fork-row-index.js +3 -3
  211. package/dist/core/storage/session/fork-schema.js +53 -0
  212. package/dist/core/storage/session/fork-schema.js.map +1 -0
  213. package/dist/core/storage/session/fork-segments.d.ts +58 -0
  214. package/dist/core/storage/session/fork-staging.code.js +176 -36
  215. package/dist/core/storage/session/fork-staging.code.js.map +1 -1
  216. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  217. package/dist/core/storage/session/fork-staging.js +3 -3
  218. package/dist/core/storage/session/fork-sweep.js +61 -0
  219. package/dist/core/storage/session/fork-sweep.js.map +1 -0
  220. package/dist/core/storage/session/fork-window.code.js +4 -4
  221. package/dist/core/storage/session/fork-window.impl.js +3 -3
  222. package/dist/core/storage/session/fork-window.js +3 -3
  223. package/dist/core/storage/session/history-pages.impl.js +3 -3
  224. package/dist/core/storage/session/history-pages.js +3 -3
  225. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  226. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  227. package/dist/core/storage/session/jsonl-session-store.d.ts +37 -1
  228. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  229. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  230. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  231. package/dist/core/storage/session/memory-session-store.js +3 -3
  232. package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
  233. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  234. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  235. package/dist/core/storage/session/released-history-files.code.js +3 -3
  236. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  237. package/dist/core/storage/session/released-history-files.js +3 -3
  238. package/dist/core/storage/session/resident-fork-rows.code.js +1 -1
  239. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  240. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  241. package/dist/core/storage/session/session-resume.impl.js +3 -3
  242. package/dist/core/storage/session/session-resume.js +3 -3
  243. package/dist/core/storage/session/session-search-index.d.ts +5 -0
  244. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  245. package/dist/core/storage/session/snapshot-cut.js +3 -3
  246. package/dist/core/storage/session/snapshot-history.code.js +4 -4
  247. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  248. package/dist/core/storage/session/snapshot-history.js +3 -3
  249. package/dist/core/storage/session/sql-chat-records.d.ts +15 -0
  250. package/dist/core/storage/session/sql-session-store.code.js +1 -1
  251. package/dist/core/storage/session/sql-session-store.d.ts +445 -11
  252. package/dist/core/storage/session/sql-session-store.impl.js +4 -4
  253. package/dist/core/storage/session/sql-session-store.js +4 -4
  254. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  255. package/dist/core/storage/session/tree-outline.js +3 -3
  256. package/dist/core/storage/session/tree-presentation.code.js +1 -1
  257. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  258. package/dist/core/storage/session/tree-presentation.js +3 -3
  259. package/dist/core/storage/session/types.d.ts +36 -0
  260. package/dist/core/storage/sqlite-facade.d.ts +54 -6
  261. package/dist/core/storage/sqlite-facade.js +384 -18
  262. package/dist/core/storage/sqlite-facade.js.map +1 -1
  263. package/dist/core/storage/statement-sequence.d.ts +83 -0
  264. package/dist/core/storage/statement-sequence.js +21 -0
  265. package/dist/core/storage/statement-sequence.js.map +1 -1
  266. package/dist/core/storage/storage-status.code.js +1 -1
  267. package/dist/core/storage/storage-status.impl.js +3 -3
  268. package/dist/core/storage/storage-status.js +3 -3
  269. package/dist/core/storage/team.code.js +1 -1
  270. package/dist/core/storage/team.impl.js +3 -3
  271. package/dist/core/storage/team.js +3 -3
  272. package/dist/core/structured-output/index.code.js +1 -1
  273. package/dist/core/structured-output/index.impl.js +3 -3
  274. package/dist/core/structured-output/index.js +3 -3
  275. package/dist/core/tasks/task-completion-entry.code.js +1 -1
  276. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  277. package/dist/core/tasks/task-completion-entry.js +3 -3
  278. package/dist/core/tasks/task-file-history.code.js +4 -4
  279. package/dist/core/tasks/task-file-history.impl.js +3 -3
  280. package/dist/core/tasks/task-file-history.js +3 -3
  281. package/dist/core/tasks/task-reference-archive.code.js +5 -5
  282. package/dist/core/tasks/task-reference-archive.js +3 -3
  283. package/dist/core/tasks/task-reference-identity.js +3 -3
  284. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  285. package/dist/core/tasks/task-reference-stream.js +3 -3
  286. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  287. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  288. package/dist/core/tasks/task-view-source.code.js +1 -1
  289. package/dist/core/tasks/task-view-source.impl.js +3 -3
  290. package/dist/core/tasks/task-view-source.js +3 -3
  291. package/dist/core/tools/bash.d.ts +8 -4
  292. package/dist/core/tools/history-session.d.ts +7 -0
  293. package/dist/core/tools/history-tasks.d.ts +123 -0
  294. package/dist/core/tools/kill.d.ts +5 -2
  295. package/dist/core/tools/powershell.d.ts +2 -2
  296. package/dist/core/tools/read-url.code.js +3 -3
  297. package/dist/core/tools/read-url.impl.js +3 -3
  298. package/dist/core/tools/read-url.js +3 -3
  299. package/dist/core/tools/read.d.ts +12 -2
  300. package/dist/core/tools/resource-selectors.d.ts +2 -0
  301. package/dist/core/tools/search.d.ts +12 -2
  302. package/dist/core/worktree-snapshot/blob-store.d.ts +45 -2
  303. package/dist/core/worktree-snapshot/blob-store.js +228 -60
  304. package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
  305. package/dist/core/worktree-snapshot/errors.code.js +3 -3
  306. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  307. package/dist/core/worktree-snapshot/errors.js +3 -3
  308. package/dist/core/worktree-snapshot/fork-snapshot-index.js +121 -0
  309. package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -0
  310. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  311. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  312. package/dist/extensions/codemode/execute.code.js +3 -3
  313. package/dist/extensions/codemode/execute.impl.js +3 -3
  314. package/dist/extensions/codemode/execute.js +3 -3
  315. package/dist/extensions/codemode/renderer.code.js +2 -2
  316. package/dist/extensions/codemode/renderer.impl.js +3 -3
  317. package/dist/extensions/codemode/renderer.js +3 -3
  318. package/dist/extensions/mcp/cli.code.js +3 -3
  319. package/dist/extensions/mcp/cli.impl.js +3 -3
  320. package/dist/extensions/mcp/cli.js +3 -3
  321. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  322. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  323. package/dist/extensions/mcp/cli.lazy.js +3 -3
  324. package/dist/extensions/mcp/runtime.code.js +1 -1
  325. package/dist/extensions/mcp/runtime.impl.js +3 -3
  326. package/dist/extensions/mcp/runtime.js +3 -3
  327. package/dist/index.js +8 -8
  328. package/dist/main-first-time-setup.code.js +2 -2
  329. package/dist/main-first-time-setup.impl.js +3 -3
  330. package/dist/main-first-time-setup.js +3 -3
  331. package/dist/main.js +1 -1
  332. package/dist/modes/interactive/components/agent-panel.d.ts +1 -0
  333. package/dist/modes/interactive/components/stored-tree-view.code.js +3 -3
  334. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  335. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  336. package/dist/modes/interactive/components/task-inspector.d.ts +2 -0
  337. package/dist/modes/interactive/components/user-message-selector-archive.code.js +1 -1
  338. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  339. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  340. package/dist/modes/interactive/interactive-mode-helpers.d.ts +2 -2
  341. package/dist/modes/print-mode.js +1 -1
  342. package/dist/modes/rpc/agent-panel-bridge.d.ts +5 -0
  343. package/dist/package-manager-cli.code.js +7 -7
  344. package/dist/package-manager-cli.impl.js +3 -3
  345. package/dist/package-manager-cli.js +3 -3
  346. package/dist/rpc-entry.js +1 -1
  347. package/dist/startup-files.json +1 -1
  348. package/dist/startup-stages/0.js +1 -1
  349. package/dist/startup-stages/1.js +1 -1
  350. package/dist/startup-stages/10.js +1 -1
  351. package/dist/startup-stages/12.js +1 -1
  352. package/dist/startup-stages/2.js +9 -1
  353. package/dist/startup-stages/3.js +1 -6
  354. package/dist/startup-stages/5.js +1 -1
  355. package/dist/startup-stages/7.js +1 -1
  356. package/dist/startup-stages/8.js +2 -2
  357. package/dist/utils/startup-database-spare.code.js +3 -3
  358. package/dist/utils/startup-database-spare.impl.js +3 -3
  359. package/dist/utils/startup-database-spare.js +3 -3
  360. package/dist/utils/tools-manager.code.js +1 -1
  361. package/dist/utils/tools-manager.impl.js +3 -3
  362. package/dist/utils/tools-manager.js +3 -3
  363. package/docs/background-tasks.md +123 -23
  364. package/docs/compaction.md +18 -0
  365. package/docs/docs.json +2 -0
  366. package/docs/environment-variables.md +1 -1
  367. package/docs/getting-started/installation.md +9 -2
  368. package/docs/guides/postgres-pgbouncer.md +346 -0
  369. package/docs/guides/postgres-tuning.md +311 -0
  370. package/docs/guides/resume-on-any-machine.md +2 -2
  371. package/docs/guides.md +2 -0
  372. package/docs/index.md +1 -1
  373. package/docs/libraries/agent-core.md +1 -1
  374. package/docs/libraries/ai.md +2 -2
  375. package/docs/libraries/codemode.md +1 -1
  376. package/docs/libraries/storage-libsql.md +6 -1
  377. package/docs/libraries/storage-postgres.md +11 -6
  378. package/docs/libraries/tui.md +1 -1
  379. package/docs/libraries.md +2 -2
  380. package/docs/programmatic.md +1 -1
  381. package/docs/quickstart.md +1 -1
  382. package/docs/sdk/storage.md +1 -1
  383. package/docs/sdk/web-server.md +1 -3
  384. package/docs/sdk.md +1 -7
  385. package/docs/sessions.md +67 -2
  386. package/docs/settings.md +20 -1
  387. package/docs/skills/authoring.md +1 -1
  388. package/docs/skills.md +79 -6
  389. package/docs/storage.md +305 -14
  390. package/docs/subagents/reference.md +2 -2
  391. package/docs/subagents.md +4 -3
  392. package/docs/tools.md +44 -10
  393. package/docs/windows.md +1 -1
  394. package/package.json +9 -9
  395. package/dist/_shared/sdk-RRLVN7ER.js.map +0 -1
  396. package/dist/_shared/settings-startup-4QCVCI53.js.map +0 -1
  397. package/dist/_shared/startup-0-0-4VG2G44V.js.map +0 -1
  398. package/dist/_shared/startup-0-1-XTIL65D4.js.map +0 -1
  399. package/dist/_shared/startup-0-2-27OWFHV6.js.map +0 -1
  400. package/dist/_shared/startup-0-3-T4DVFYWX.js.map +0 -1
  401. package/dist/_shared/startup-0-5-FD2P735I.js.map +0 -1
  402. package/dist/_shared/startup-8-1-4KANEHRA.js.map +0 -1
@@ -1,6 +1,8 @@
1
1
  import {
2
2
  dialectOf,
3
+ fencedPath,
3
4
  type SqliteDatabase,
5
+ type SqliteExecutor,
4
6
  type SqliteRow,
5
7
  type StorageNotificationSubscription,
6
8
  validateStoragePrefix,
@@ -15,7 +17,7 @@ import type {
15
17
  WakeUpSubscribeResult,
16
18
  WakeUpSubscription,
17
19
  } from "./wake-up-bus.js";
18
- import { ensureBrokerSchema } from "./sql-schema.js";
20
+ import { ensureBrokerSchema, withBrokerSchemaCatalog } from "./sql-schema.js";
19
21
 
20
22
  /**
21
23
  * S4 wake-up bus (specs/2026-10-19-intercom-multi-node.md §5.6): a hint log in the shared storage database. Each
@@ -27,13 +29,25 @@ import { ensureBrokerSchema } from "./sql-schema.js";
27
29
  * On a database that delivers notifications (Postgres), a publish also notifies the channel named like the table, in
28
30
  * the transaction that writes the hint, and a subscribed connection polls as soon as a notification for one of its
29
31
  * brokers arrives (#5103). The interval poll stays: notifications are lost while the listening connection is down, and
30
- * none arrive through a transaction pooler.
32
+ * none arrive through a transaction pooler. While the database reports its listening connection live, the poll only
33
+ * backs the notifications up and runs at `WAKE_UP_LISTENING_POLL_INTERVAL_MS`; the listener's `listening` event, sent
34
+ * when it listens again after an outage, polls at once (#6560).
31
35
  */
32
36
 
33
- /** How often a connection with subscriptions reads its hints. */
37
+ /** How often a connection with subscriptions reads its hints when no notification would announce them. */
34
38
  export const WAKE_UP_POLL_INTERVAL_MS = 500;
39
+ /**
40
+ * How often a connection with subscriptions reads its hints while its notifications are live: only a notification lost
41
+ * in an outage the listener has not noticed yet waits for this poll.
42
+ */
43
+ export const WAKE_UP_LISTENING_POLL_INTERVAL_MS = 5_000;
35
44
  /** Hints nobody consumed (their broker exited) are deleted after this age; the backup poll has covered them. */
36
45
  export const WAKE_UP_HINT_RETENTION_MS = OUTBOX_BACKUP_POLL_INTERVAL_MS;
46
+ /**
47
+ * How often at most one connection deletes the hints past the retention, at a publish (#6560): a hint nobody consumed
48
+ * then stays at most this much longer than the retention.
49
+ */
50
+ export const WAKE_UP_PRUNE_INTERVAL_MS = 10_000;
37
51
  /**
38
52
  * Hints read and deleted per statement; a poll repeats until a batch comes back short. Each batch's delete binds one
39
53
  * parameter per hint, so a backlog never exceeds SQLite's bound-parameter limit (999 on old builds).
@@ -51,7 +65,15 @@ export interface DatabaseWakeUpBusOptions {
51
65
  /** The validated storage prefix; the table is `<prefix>intercom_wakeups`. */
52
66
  readonly prefix?: string;
53
67
  readonly pollIntervalMs?: number;
68
+ readonly listeningPollIntervalMs?: number;
54
69
  readonly schedule?: WakeUpPollScheduler;
70
+ /**
71
+ * A separate handle on the same database that the poll reads its hints through, so a poll never queues behind the
72
+ * database's writes (#6560); the bus does not close it. On PostgreSQL the poll takes and deletes its hints through
73
+ * it in one statement (`DELETE … RETURNING`), so it must accept writes. Absent: the poll runs on the database it
74
+ * opened.
75
+ */
76
+ readonly reader?: SqliteExecutor;
55
77
  }
56
78
 
57
79
  interface HintRow extends SqliteRow {
@@ -88,12 +110,22 @@ async function createSchema(database: SqliteDatabase, table: string, prefix: str
88
110
  await ensureBrokerSchema(database, prefix, "wakeups", (tx) => tx.exec(schema));
89
111
  }
90
112
 
91
- async function openSchemaConnection(options: DatabaseWakeUpBusOptions, table: string): Promise<SqliteDatabase> {
113
+ /**
114
+ * Opens a connection to the bus's database and sets up its table, checked against one read of the schema catalog, so a
115
+ * current table costs no transaction or lock (#6560). With `schemaSetUp`, this bus set the table up already, on an
116
+ * earlier connection: a schema only moves forward, so the connection runs no schema statement at all.
117
+ */
118
+ async function openSchemaConnection(
119
+ options: DatabaseWakeUpBusOptions,
120
+ table: string,
121
+ schemaSetUp = false,
122
+ ): Promise<SqliteDatabase> {
92
123
  const database = await options.openDatabase();
93
124
  try {
94
125
  // Refused before anything is created when the prefix is too long for this backend's identifiers (#5067).
95
126
  validateStoragePrefix(options.prefix, dialectOf(database).name);
96
- await createSchema(database, table, options.prefix);
127
+ if (!schemaSetUp)
128
+ await withBrokerSchemaCatalog(database, options.prefix, () => createSchema(database, table, options.prefix));
97
129
  } catch (cause) {
98
130
  await database.close().catch(() => {});
99
131
  throw cause;
@@ -106,6 +138,7 @@ class DatabaseWakeUpBus implements WakeUpBus {
106
138
  private readonly options: DatabaseWakeUpBusOptions;
107
139
  private readonly table: string;
108
140
  private readonly pollIntervalMs: number;
141
+ private readonly listeningPollIntervalMs: number;
109
142
  private readonly schedule: WakeUpPollScheduler;
110
143
  private database: SqliteDatabase | undefined;
111
144
  private opening: Promise<SqliteDatabase | undefined> | undefined;
@@ -117,15 +150,25 @@ class DatabaseWakeUpBus implements WakeUpBus {
117
150
  private reconnectFailures = 0;
118
151
  private reconnectNotBefore = 0;
119
152
  /** The notification channel this connection listens on, and the database it listens through. */
120
- private listening: { readonly database: SqliteDatabase; readonly subscription: StorageNotificationSubscription } | undefined;
153
+ private listening:
154
+ | {
155
+ readonly database: SqliteDatabase;
156
+ readonly subscription: StorageNotificationSubscription;
157
+ /** The database reported its listening connection live, as of the latest check. */
158
+ live: boolean;
159
+ }
160
+ | undefined;
121
161
  /** A notification arrived during a poll: the next poll runs as soon as that one ends. */
122
162
  private pollAgain = false;
163
+ /** When a publish last deleted the hints past the retention, by this process's clock. */
164
+ private prunedAt: number | undefined;
123
165
 
124
166
  constructor(options: DatabaseWakeUpBusOptions, table: string, database: SqliteDatabase) {
125
167
  this.options = options;
126
168
  this.table = table;
127
169
  this.database = database;
128
170
  this.pollIntervalMs = options.pollIntervalMs ?? WAKE_UP_POLL_INTERVAL_MS;
171
+ this.listeningPollIntervalMs = options.listeningPollIntervalMs ?? WAKE_UP_LISTENING_POLL_INTERVAL_MS;
129
172
  this.schedule = options.schedule ?? scheduleTimeout;
130
173
  }
131
174
 
@@ -139,20 +182,26 @@ class DatabaseWakeUpBus implements WakeUpBus {
139
182
  try {
140
183
  if (notifications === undefined) await database.run(insert, hint.brokerId, hint.reason, hint.version);
141
184
  else {
142
- // The notification goes out when the hint commits, so the poll it starts finds the hint.
185
+ // The notification goes out when the hint commits, so the poll it starts finds the hint. A hint is a new
186
+ // row that no write checks first, so its writers take no lock domain (#6560): see
187
+ // `fencedPath("intercom-wakeup-hint")`.
143
188
  const notify = notifications.notify(this.table, hint.brokerId);
144
189
  await database.transaction(
145
190
  async (tx) => {
146
191
  await tx.run(insert, hint.brokerId, hint.reason, hint.version);
147
192
  await tx.run(notify.sql, ...notify.params);
148
193
  },
149
- { concurrency: { kind: "serial", domain: this.table } },
194
+ { concurrency: { kind: "fenced", audit: fencedPath("intercom-wakeup-hint") } },
195
+ );
196
+ }
197
+ // #6560: at most once per interval, not at every publish: each prune is a write every broker would send.
198
+ if (this.prunedAt === undefined || Date.now() - this.prunedAt >= WAKE_UP_PRUNE_INTERVAL_MS) {
199
+ this.prunedAt = Date.now();
200
+ await database.run(
201
+ `DELETE FROM ${this.table} WHERE created_at < ${nowMs} - ?`,
202
+ WAKE_UP_HINT_RETENTION_MS,
150
203
  );
151
204
  }
152
- await database.run(
153
- `DELETE FROM ${this.table} WHERE created_at < ${nowMs} - ?`,
154
- WAKE_UP_HINT_RETENTION_MS,
155
- );
156
205
  } catch {
157
206
  this.drop(database);
158
207
  return { status: "unavailable" };
@@ -213,10 +262,25 @@ class DatabaseWakeUpBus implements WakeUpBus {
213
262
  const notifications = database.notifications;
214
263
  if (notifications === undefined) return;
215
264
  const subscription = notifications.listen(this.table, (event) => {
216
- if (event.kind === "listening" || [...this.subscriptions].some((open) => open.brokerId === event.payload))
265
+ if (event.kind === "listening") {
266
+ if (this.listening?.subscription === subscription) this.listening.live = true;
217
267
  this.pollNow();
268
+ } else if ([...this.subscriptions].some((open) => open.brokerId === event.payload)) this.pollNow();
218
269
  });
219
- this.listening = { database, subscription };
270
+ this.listening = { database, subscription, live: false };
271
+ void this.checkListening();
272
+ }
273
+
274
+ /** Asks the database whether its listening connection is live, for the interval of the next poll. */
275
+ private async checkListening(): Promise<void> {
276
+ const listening = this.listening;
277
+ const notifications = listening?.database.notifications;
278
+ if (listening === undefined || notifications === undefined) return;
279
+ const live = await notifications.state().then(
280
+ (state) => state.status === "listening",
281
+ () => false,
282
+ );
283
+ if (this.listening === listening) listening.live = live;
220
284
  }
221
285
 
222
286
  /** Polls at once, or as soon as the poll in progress ends, instead of at the next interval. */
@@ -237,7 +301,9 @@ class DatabaseWakeUpBus implements WakeUpBus {
237
301
  this.cancelPoll = this.schedule(() => {
238
302
  this.cancelPoll = undefined;
239
303
  this.pollAgain = false;
240
- this.polling = this.poll().finally(() => {
304
+ this.polling = this.poll()
305
+ .then(() => this.checkListening())
306
+ .finally(() => {
241
307
  this.polling = undefined;
242
308
  this.armPoll(this.pollAgain ? 0 : this.nextPollDelayMs());
243
309
  });
@@ -245,6 +311,8 @@ class DatabaseWakeUpBus implements WakeUpBus {
245
311
  }
246
312
 
247
313
  private nextPollDelayMs(): number {
314
+ if (this.database !== undefined && this.listening?.database === this.database && this.listening.live)
315
+ return this.listeningPollIntervalMs;
248
316
  if (this.database !== undefined || this.reconnectFailures === 0) return this.pollIntervalMs;
249
317
  return Math.min(this.pollIntervalMs * 2 ** this.reconnectFailures, WAKE_UP_RECONNECT_MAX_DELAY_MS);
250
318
  }
@@ -254,18 +322,27 @@ class DatabaseWakeUpBus implements WakeUpBus {
254
322
  const brokerIds = [...new Set([...this.subscriptions].map((subscription) => subscription.brokerId))];
255
323
  if (database === undefined || brokerIds.length === 0) return;
256
324
  const placeholders = brokerIds.map(() => "?").join(", ");
325
+ const batch = `FROM ${this.table} WHERE broker_id IN (${placeholders}) ORDER BY id LIMIT ${WAKE_UP_POLL_BATCH_SIZE}`;
326
+ const reader = this.options.reader ?? database;
257
327
  for (;;) {
258
328
  let rows: HintRow[];
259
329
  try {
260
- rows = await database.all<HintRow>(
261
- `SELECT id, broker_id, reason, version FROM ${this.table} WHERE broker_id IN (${placeholders}) ORDER BY id LIMIT ${WAKE_UP_POLL_BATCH_SIZE}`,
262
- ...brokerIds,
263
- );
264
- if (rows.length > 0) {
265
- await database.run(
266
- `DELETE FROM ${this.table} WHERE id IN (${rows.map(() => "?").join(", ")})`,
267
- ...rows.map((row) => row.id),
330
+ if (dialectOf(database).name === "postgres") {
331
+ // #6560: one statement takes the batch and deletes it, through the reader, whose calls never queue
332
+ // behind this database's writes. It returns the hints in no particular order.
333
+ rows = await reader.all<HintRow>(
334
+ `DELETE FROM ${this.table} WHERE id IN (SELECT id ${batch}) RETURNING id, broker_id, reason, version`,
335
+ ...brokerIds,
268
336
  );
337
+ rows.sort((left, right) => Number(left.id) - Number(right.id));
338
+ } else {
339
+ rows = await reader.all<HintRow>(`SELECT id, broker_id, reason, version ${batch}`, ...brokerIds);
340
+ if (rows.length > 0) {
341
+ await database.run(
342
+ `DELETE FROM ${this.table} WHERE id IN (${rows.map(() => "?").join(", ")})`,
343
+ ...rows.map((row) => row.id),
344
+ );
345
+ }
269
346
  }
270
347
  } catch {
271
348
  this.drop(database);
@@ -299,7 +376,9 @@ class DatabaseWakeUpBus implements WakeUpBus {
299
376
  private async reconnect(): Promise<SqliteDatabase | undefined> {
300
377
  let database: SqliteDatabase;
301
378
  try {
302
- database = await openSchemaConnection(this.options, this.table);
379
+ // The bus set its table up when it opened: replacing a dropped connection runs no schema statement, so it never
380
+ // takes the database's write lock, however many brokers lose their connections at once (#6560).
381
+ database = await openSchemaConnection(this.options, this.table, true);
303
382
  } catch {
304
383
  this.reconnectFailures++;
305
384
  this.reconnectNotBefore = Date.now() + this.nextPollDelayMs();
@@ -2775,21 +2775,22 @@ export class MultiNodeRouter {
2775
2775
  */
2776
2776
  private async sweepLostRecipients(): Promise<void> {
2777
2777
  const { afterRestartMs, afterStaleLeaseMs } = this.lostBounds;
2778
- const presences = await this.state.leases.listLive("presence", Number.MAX_SAFE_INTEGER);
2779
- const live = new Set<string>();
2778
+ const { leases } = this.state;
2779
+ const lostAfterMs = BROKER_LEASE_STALE_AFTER_MS + afterStaleLeaseMs;
2780
+ // #6560: only the leases stale past the bound, which while every broker renews its sessions' is none: every
2781
+ // broker sweeps every backup poll, and reading every lease each time grew with the square of the swarm.
2782
+ const aged =
2783
+ leases.listAged === undefined
2784
+ ? (await leases.listLive("presence", Number.MAX_SAFE_INTEGER)).filter((lease) => lease.ageMs >= lostAfterMs)
2785
+ : await leases.listAged("presence", lostAfterMs);
2780
2786
  const lost = new Map<string, { from: SessionInfo; targetIdentity: string; boundMs: number }>();
2781
- for (const lease of presences) {
2787
+ for (const lease of aged) {
2782
2788
  const subject = lease.subject as RecipientPresenceSubject;
2783
- if (lease.ageMs <= BROKER_LEASE_STALE_AFTER_MS) {
2784
- live.add(subject.session.id);
2785
- live.add(subject.targetIdentity);
2786
- } else if (lease.ageMs >= BROKER_LEASE_STALE_AFTER_MS + afterStaleLeaseMs) {
2787
- lost.set(subject.session.id, {
2788
- from: subject.session,
2789
- targetIdentity: subject.targetIdentity,
2790
- boundMs: afterStaleLeaseMs,
2791
- });
2792
- }
2789
+ lost.set(subject.session.id, {
2790
+ from: subject.session,
2791
+ targetIdentity: subject.targetIdentity,
2792
+ boundMs: afterStaleLeaseMs,
2793
+ });
2793
2794
  }
2794
2795
  for (const known of await this.state.knownSessions.listLost(afterRestartMs)) {
2795
2796
  const from: SessionInfo = {
@@ -2805,6 +2806,14 @@ export class MultiNodeRouter {
2805
2806
  };
2806
2807
  lost.set(known.intercomSessionId, { from, targetIdentity: known.targetIdentity, boundMs: afterRestartMs });
2807
2808
  }
2809
+ if (lost.size === 0) return;
2810
+ // A session lost under one identity may be present under another: the live leases, read only when one is lost.
2811
+ const live = new Set<string>();
2812
+ for (const lease of await leases.listLive("presence", BROKER_LEASE_STALE_AFTER_MS)) {
2813
+ const subject = lease.subject as RecipientPresenceSubject;
2814
+ live.add(subject.session.id);
2815
+ live.add(subject.targetIdentity);
2816
+ }
2808
2817
  for (const [sessionId, { from, targetIdentity, boundMs }] of lost) {
2809
2818
  if (live.has(sessionId) || live.has(targetIdentity) || this.host.sessions.has(sessionId)) continue;
2810
2819
  if (await this.reservedForReturn(sessionId, targetIdentity, from)) continue;
@@ -4221,8 +4230,18 @@ export class MultiNodeRouter {
4221
4230
  if (await this.routeReleasedReply(request, undefined, ticket)) return;
4222
4231
  if (this.closed) return;
4223
4232
  const from = request.from;
4233
+ const leases = this.state.leases;
4234
+ // Presences are stored with every string well formed (#6560): a target ending in half a surrogate pair names them
4235
+ // as their stored strings do.
4236
+ const target = request.target.toWellFormed();
4224
4237
  for (;;) {
4225
- const live = (await this.state.leases.listLive("presence", BROKER_LEASE_STALE_AFTER_MS)).filter(
4238
+ // Only the presences the target may name, by index, where the store can (#6560): what follows resolves the
4239
+ // target among those alone, as it would among every live presence.
4240
+ const candidates =
4241
+ leases.listLiveFor === undefined
4242
+ ? leases.listLive("presence", BROKER_LEASE_STALE_AFTER_MS)
4243
+ : leases.listLiveFor(target, BROKER_LEASE_STALE_AFTER_MS);
4244
+ const live = (await candidates).filter(
4226
4245
  (lease) =>
4227
4246
  lease.subject.kind === "presence" &&
4228
4247
  lease.holderId !== this.brokerId &&
@@ -4234,8 +4253,8 @@ export class MultiNodeRouter {
4234
4253
  // #5607: a plain send to an id a session holds as an alias reaches that session.
4235
4254
  const plain = isPlainSend(request);
4236
4255
  const exact =
4237
- live.find((lease) => presenceOf(lease).session.id === request.target) ??
4238
- (plain ? await this.aliasHolder(live, request.target) : undefined);
4256
+ live.find((lease) => presenceOf(lease).session.id === target) ??
4257
+ (plain ? await this.aliasHolder(live, target) : undefined);
4239
4258
  if (this.closed) return;
4240
4259
  let resolved: LeaseState | undefined = exact;
4241
4260
  if (resolved === undefined) {
@@ -4255,15 +4274,17 @@ export class MultiNodeRouter {
4255
4274
  const nonAgentNamed = visible.some(
4256
4275
  (lease) =>
4257
4276
  !isAgentRecipient(presenceOf(lease).session) &&
4258
- presenceOf(lease).session.name?.toLowerCase() === request.target.toLowerCase(),
4277
+ presenceOf(lease).session.name?.toLowerCase() === target.toLowerCase(),
4259
4278
  );
4260
4279
  const agents = visible.filter((lease) => isAgentRecipient(presenceOf(lease).session));
4261
4280
  const infos = agents.map((lease) => presenceOf(lease).session);
4262
- let resolution: SessionTargetResolution = resolveSessionTarget(infos, request.target);
4281
+ let resolution: SessionTargetResolution = resolveSessionTarget(infos, target);
4263
4282
  if (resolution.kind === "not_found") {
4264
- resolution = resolveSessionTargetByHostSessionId(infos, request.target, (info) => {
4283
+ resolution = resolveSessionTargetByHostSessionId(infos, target, (info) => {
4265
4284
  const lease = agents.find((candidate) => presenceOf(candidate).session === info);
4266
- return lease === undefined ? undefined : returnAddressOf(presenceOf(lease).targetIdentity);
4285
+ return lease === undefined
4286
+ ? undefined
4287
+ : returnAddressOf(presenceOf(lease).targetIdentity)?.toWellFormed();
4267
4288
  });
4268
4289
  }
4269
4290
  // A sender this one holds a return path to answers to its name only when nothing visible does.
@@ -4282,7 +4303,7 @@ export class MultiNodeRouter {
4282
4303
  if (answerable.length > 0) {
4283
4304
  const answered = resolveSessionTarget(
4284
4305
  answerable.map((lease) => presenceOf(lease).session),
4285
- request.target,
4306
+ target,
4286
4307
  );
4287
4308
  if (answered.kind !== "not_found") {
4288
4309
  resolution = answered;
@@ -1,5 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
- import type { SqliteDatabase } from "@bastani/atomic/storage";
2
+ import type { SqliteDatabase, SqliteExecutor } from "@bastani/atomic/storage";
3
3
  import type { BrokerMessage, ClientMessage, ReachPolicyFrame, SessionInfo } from "../types.js";
4
4
  import type { EndedChildQueueStore } from "./sql-ended-child-queue-store.js";
5
5
  import { isReleasedReservationKey } from "./released-children.js";
@@ -180,6 +180,22 @@ export interface BrokerLeaseStore {
180
180
  read(key: LeaseKey): Promise<LeaseReadResult>;
181
181
  /** Live leases of one kind, in the order their keys were first acquired. */
182
182
  listLive(kind: LeaseKind, staleAfterMs: number): Promise<LeaseState[]>;
183
+ /**
184
+ * The live presence leases a send to `target` may resolve to, in the order their keys were first acquired: every one
185
+ * whose session's id is `target` or `target` trimmed, whose session's name is either of them in any case, whose UUID
186
+ * id starts with `target` trimmed when that is an 8-digit hex prefix, whose identity's return address is `target`
187
+ * trimmed, or whose aliases include `target`. It may list others too, which the caller's own matching leaves out. Read
188
+ * by index, so a send's read does not grow with the presences of other sessions (#6560). Absent on custom stores and
189
+ * on a database whose role may not add the columns it reads, where `listLive("presence")` serves instead.
190
+ */
191
+ listLiveFor?(target: string, staleAfterMs: number): Promise<LeaseState[]>;
192
+ /**
193
+ * Held leases of one kind at least `minAgeMs` old, in the order their keys were first acquired: what `listLive` with
194
+ * no bound lists past that age, without reading the younger ones. While every lease is renewed it reads no row, so a
195
+ * periodic check for leases left behind costs one empty read rather than every lease (#6560). Absent on custom
196
+ * stores, which `listLive` with no bound serves instead.
197
+ */
198
+ listAged?(kind: LeaseKind, minAgeMs: number): Promise<LeaseState[]>;
183
199
  /**
184
200
  * #5038: give up every lease `holderId` holds, as its own `release` would, so their next acquisitions need not
185
201
  * wait for them to go stale. Resolves to the number of leases retired.
@@ -1056,6 +1072,11 @@ export interface IntercomBrokerStateOptions {
1056
1072
  readonly database: SqliteDatabase;
1057
1073
  /** The adapter's validated table prefix. */
1058
1074
  readonly prefix: string;
1075
+ /**
1076
+ * A separate handle on `database` for the reads that answer within a bound (live leases, known sessions), so they
1077
+ * never queue behind its writes (#6560); the store does not close it. Absent: they read through `database`.
1078
+ */
1079
+ readonly reader?: SqliteExecutor;
1059
1080
  }
1060
1081
 
1061
1082
  export type OpenIntercomBrokerStateStore = (options: IntercomBrokerStateOptions) => Promise<IntercomBrokerStateStore>;
@@ -17,14 +17,15 @@ import {
17
17
  } from "@bastani/atomic/storage";
18
18
  import { type DatabaseWakeUpBusOptions, openDatabaseWakeUpBus } from "./database-wake-up-bus.js";
19
19
  import type { IntercomBrokerStateStore } from "./multinode-state-store.js";
20
- import { openSqlEndedChildQueueStore } from "./sql-ended-child-queue-store.js";
20
+ import { ensureEndedChildQueueSchema, openSqlEndedChildQueueStore } from "./sql-ended-child-queue-store.js";
21
21
  import { openSqlHeldSendStore } from "./sql-held-send-store.js";
22
22
  import { openSqlKnownSessionStore } from "./sql-known-session-store.js";
23
23
  import { openSqlBrokerLeaseStore } from "./sql-lease-store.js";
24
- import { openSqlOutboxStore, withoutFailedWake } from "./sql-outbox-store.js";
24
+ import { openSqlOutboxStore, recipientTransaction, runLast, withoutFailedWake } from "./sql-outbox-store.js";
25
25
  import { openSqlPendingAskStore } from "./sql-pending-ask-store.js";
26
26
  import { openSqlReleasedAskStore } from "./sql-released-ask-store.js";
27
27
  import { openSqlRestoringReservationStore } from "./sql-restoring-reservation-store.js";
28
+ import { withBrokerSchemaCatalog } from "./sql-schema.js";
28
29
  import { openSqlSentMessageAuthority } from "./sql-sent-message-authority.js";
29
30
  import type { WakeUpBus } from "./wake-up-bus.js";
30
31
 
@@ -124,29 +125,55 @@ export function borrowedDatabase(database: SqliteDatabase): SqliteDatabase {
124
125
  return new Proxy(database, { get: (target, key) => (key === "close" ? close : Reflect.get(target, key)) });
125
126
  }
126
127
 
128
+ /**
129
+ * Creates the tables a broker creates only on first use, today the ended-child queue's, for `atomic storage migrate`:
130
+ * with `openIntercomBrokerState`, every table a broker needs, so a runtime role that may not create tables finds them
131
+ * (#6560).
132
+ */
133
+ export async function ensureLazyIntercomSchemas(source: SharedDatabaseSource): Promise<void> {
134
+ const database = await source.openDatabase();
135
+ try {
136
+ await ensureEndedChildQueueSchema({ database, prefix: source.prefix ?? "" });
137
+ } finally {
138
+ await database.close();
139
+ }
140
+ }
141
+
127
142
  /** Compose S1–S4 and the S5 known-session store, and the wake-up bus, on one connection. */
128
143
  export async function openIntercomBrokerState(
129
144
  source: SharedDatabaseSource,
130
- busOptions: Pick<DatabaseWakeUpBusOptions, "pollIntervalMs" | "schedule"> = {},
145
+ busOptions: Pick<DatabaseWakeUpBusOptions, "pollIntervalMs" | "listeningPollIntervalMs" | "schedule"> = {},
131
146
  ): Promise<OpenedBrokerState> {
132
147
  const database = await source.openDatabase();
148
+ let reader: SqliteDatabase | undefined;
133
149
  try {
134
150
  // The backend is known once the database is open: refuse a prefix too long for it before creating anything (#5067).
135
151
  validateStoragePrefix(source.prefix, dialectOf(database).name);
136
- const options = { database, prefix: source.prefix ?? "" };
137
- const leases = await openSqlBrokerLeaseStore(options);
138
- const outbox = await openSqlOutboxStore(options);
139
- const heldSends = await openSqlHeldSendStore(options);
140
- const reservations = await openSqlRestoringReservationStore(options);
141
- const pendingAsks = await openSqlPendingAskStore(options);
142
- const releasedAsks = await openSqlReleasedAskStore(options);
143
- const sentMessages = await openSqlSentMessageAuthority(options);
144
- const knownSessions = await openSqlKnownSessionStore(options);
145
- const bus = await openDatabaseWakeUpBus({
146
- openDatabase: async () => borrowedDatabase(database),
147
- prefix: source.prefix,
148
- ...busOptions,
149
- });
152
+ // Reads that answer within a bound go through a handle of their own, never queued behind the writes (#6560).
153
+ reader = await database.openReader?.();
154
+ const options = { database, prefix: source.prefix ?? "", ...(reader === undefined ? {} : { reader }) };
155
+ const borrowed = borrowedDatabase(database);
156
+ const openStores = async () => {
157
+ const leases = await openSqlBrokerLeaseStore(options);
158
+ const outbox = await openSqlOutboxStore(options);
159
+ const heldSends = await openSqlHeldSendStore(options);
160
+ const reservations = await openSqlRestoringReservationStore(options);
161
+ const pendingAsks = await openSqlPendingAskStore(options);
162
+ const releasedAsks = await openSqlReleasedAskStore(options);
163
+ const sentMessages = await openSqlSentMessageAuthority(options);
164
+ const knownSessions = await openSqlKnownSessionStore(options);
165
+ const bus = await openDatabaseWakeUpBus({
166
+ openDatabase: async () => borrowed,
167
+ prefix: source.prefix,
168
+ ...busOptions,
169
+ ...(reader === undefined ? {} : { reader }),
170
+ });
171
+ return { leases, outbox, heldSends, reservations, pendingAsks, releasedAsks, sentMessages, knownSessions, bus };
172
+ };
173
+ // One read of the schema for every store: a broker whose stores are current opens without a schema transaction,
174
+ // so brokers starting together neither take nor wait for the database's write lock (#6560).
175
+ const { leases, outbox, heldSends, reservations, pendingAsks, releasedAsks, sentMessages, knownSessions, bus } =
176
+ await withBrokerSchemaCatalog(database, options.prefix, openStores, [borrowed]);
150
177
  let closing: Promise<void> | undefined;
151
178
  const state: IntercomBrokerStateStore = {
152
179
  leases,
@@ -158,32 +185,56 @@ export async function openIntercomBrokerState(
158
185
  sentMessages,
159
186
  knownSessions,
160
187
  reserveAndEnqueue(reservation, request) {
188
+ // The recipient's domain: sends to it run one at a time, and sends to others beside them (#6560).
189
+ const send = recipientTransaction(database, source.prefix, request.targetIdentity);
190
+ // The reservation's read and the enqueue's go out with the transaction's start, the reservation's write
191
+ // and the row's insert together, then the commit, on a pipelined connection: three round trips (#6560).
192
+ const leading = (attempt: typeof request) => [
193
+ sentMessages.lookupStatement(reservation.messageId),
194
+ ...outbox.enqueueLeading(attempt),
195
+ ];
161
196
  // #5607: written again, without it, when only an offline recipient's wake-up hint failed.
162
- return withoutFailedWake(request, (attempt) => database.transaction(async (tx) => {
163
- const key = { messageId: reservation.messageId, digest: reservation.digest };
164
- const earlier = await sentMessages.lookupIn(tx, key);
165
- if (earlier.status === "conflict") return { status: "conflict", messageId: reservation.messageId } as const;
166
- const enqueued = await outbox.enqueueIn(tx, attempt);
167
- if (enqueued.status === "full") {
168
- // Refused before anything was written, so the transaction has no commit to sync.
169
- if (earlier.status === "match") await sentMessages.forgetIn(tx, key);
197
+ return withoutFailedWake(request, (attempt) =>
198
+ database.transaction(async (tx) => {
199
+ const key = { messageId: reservation.messageId, digest: reservation.digest };
200
+ const earlier = await sentMessages.lookupIn(tx, key);
201
+ if (earlier.status === "conflict")
202
+ return { status: "conflict", messageId: reservation.messageId } as const;
203
+ // The reservation is written first and the row inserted only under it: a reservation of the message
204
+ // with another digest, on another connection and in no domain of this recipient, either commits first
205
+ // and the row is refused, or waits for this send and is refused itself (#6560).
206
+ const reserve = sentMessages.reserveStatement(reservation);
207
+ const enqueued = await outbox.enqueueIn(
208
+ tx,
209
+ attempt,
210
+ reserve === undefined
211
+ ? undefined
212
+ : { first: reserve, condition: sentMessages.reservedCondition(key) },
213
+ );
214
+ if (enqueued.status === "full") {
215
+ // Refused before anything was written, so the transaction has no commit to sync.
216
+ if (earlier.status === "match") await sentMessages.forgetIn(tx, key);
217
+ return enqueued;
218
+ }
219
+ // Another send's row of the message, with another digest: the reservation this send wrote goes too.
220
+ if (enqueued.status === "conflict" && earlier.status === "miss") await sentMessages.forgetIn(tx, key);
221
+ // A duplicate the leading read found wrote nothing: its reservation is recorded again, as before.
222
+ else if (enqueued.status === "duplicate" && reserve !== undefined) await runLast(tx, reserve);
170
223
  return enqueued;
171
- }
172
- // Its answer is not needed: the outbox's unique message id is the authority for a row it holds (spec §5.5).
173
- await sentMessages.reserveIn(tx, reservation);
174
- return enqueued;
175
- }));
224
+ }, { ...send, leading: leading(attempt) }),
225
+ );
176
226
  },
177
227
  openEndedChildQueue(owner) {
178
228
  return openSqlEndedChildQueueStore(options, owner);
179
229
  },
180
230
  close() {
181
- closing ??= database.close();
231
+ closing ??= Promise.all([reader?.close(), database.close()]).then(() => {});
182
232
  return closing;
183
233
  },
184
234
  };
185
235
  return { state, bus };
186
236
  } catch (cause) {
237
+ await reader?.close().catch(() => {});
187
238
  await database.close().catch(() => {});
188
239
  throw cause;
189
240
  }
@@ -2,7 +2,7 @@ import { createHash } from "crypto";
2
2
  import { type BigIntStats, lstatSync, mkdirSync, readFileSync, renameSync, type Stats, writeFileSync } from "fs";
3
3
  import { lstat, mkdir, readFile } from "node:fs/promises";
4
4
  import { homedir, tmpdir } from "os";
5
- import { basename, dirname, join, resolve } from "path";
5
+ import { basename, dirname, isAbsolute, join, resolve } from "path";
6
6
 
7
7
  /**
8
8
  * The shared storage selection (`ATOMIC_STORAGE` JSON) the launching Atomic process hands its broker: its
@@ -251,6 +251,10 @@ function inDirectorySocketPath(agentDir: string): string {
251
251
  return join(getIntercomDirPath(agentDir), "broker.sock");
252
252
  }
253
253
 
254
+ function absoluteSocketPath(socketPath: string): string {
255
+ return isAbsolute(socketPath) ? socketPath : resolve(socketPath);
256
+ }
257
+
254
258
  function fitsUnixSocketPath(socketPath: string, platform: NodeJS.Platform): boolean {
255
259
  return Buffer.byteLength(socketPath) <= maxUnixSocketPathBytes(platform);
256
260
  }
@@ -264,7 +268,7 @@ export function directBrokerSocketPath(
264
268
  return pipe.length <= MAX_PIPE_NAME_LENGTH ? pipe : `${WINDOWS_PIPE_PREFIX}${agentDirDigest(agentDir)}`;
265
269
  }
266
270
  const socketPath = inDirectorySocketPath(agentDir);
267
- return fitsUnixSocketPath(socketPath, platform) ? socketPath : undefined;
271
+ return fitsUnixSocketPath(absoluteSocketPath(socketPath), platform) ? socketPath : undefined;
268
272
  }
269
273
 
270
274
  /**
@@ -327,7 +331,7 @@ export function chooseBrokerSocketPath(
327
331
  const direct = directBrokerSocketPath(platform, agentDir);
328
332
  if (direct !== undefined) return direct;
329
333
 
330
- const socketPath = inDirectorySocketPath(agentDir);
334
+ const socketPath = absoluteSocketPath(inDirectorySocketPath(agentDir));
331
335
  const shortPath = join(privateSocketDirectory(), `${agentDirDigest(agentDir)}.sock`);
332
336
  if (!fitsUnixSocketPath(shortPath, platform)) {
333
337
  throw new Error(
@@ -344,7 +348,7 @@ export async function chooseBrokerSocketPathAsync(
344
348
  const direct = directBrokerSocketPath(platform, agentDir);
345
349
  if (direct !== undefined) return direct;
346
350
 
347
- const socketPath = inDirectorySocketPath(agentDir);
351
+ const socketPath = absoluteSocketPath(inDirectorySocketPath(agentDir));
348
352
  const shortPath = join(await privateSocketDirectoryAsync(), `${agentDirDigest(agentDir)}.sock`);
349
353
  if (!fitsUnixSocketPath(shortPath, platform)) {
350
354
  throw new Error(