@bastani/atomic 0.10.11-alpha.2 → 0.10.11-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +150 -0
- package/README.md +5 -8
- package/dist/_shared/dist-KOELCESV.js +2 -2
- package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
- package/dist/_shared/lib-4PES5P4V.js +2 -2
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +6 -6
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +5 -5
- package/dist/_shared/mode-shared-2QJSCUM6.js +6 -6
- package/dist/_shared/p0-cli-BB45ZQY6.js +46 -67
- package/dist/_shared/p0-cli-BB45ZQY6.js.map +1 -1
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +7 -8
- package/dist/_shared/p1a-prewarm-XIU57JHF.js.map +1 -1
- package/dist/_shared/{p1b-elig-ENCUPKKJ.js → p1b-elig-TVB5CBLL.js} +36 -8
- package/dist/_shared/p1b-elig-TVB5CBLL.js.map +1 -0
- package/dist/_shared/p2-shell-main-B2WIALFD.js +6 -3
- package/dist/_shared/p2-shell-main-B2WIALFD.js.map +1 -1
- package/dist/_shared/runtime-O4KCSG4C.js +3 -3
- package/dist/_shared/{sdk-IQMULKFU.js → sdk-B5LEWGGI.js} +1218 -657
- package/dist/_shared/sdk-B5LEWGGI.js.map +1 -0
- package/dist/_shared/session-data-AHTU7IS6.js +2 -2
- package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
- package/dist/_shared/{startup-0-0-3IXNMFM2.js → startup-0-0-XJJDOIEC.js} +50 -48
- package/dist/_shared/startup-0-0-XJJDOIEC.js.map +1 -0
- package/dist/_shared/{startup-0-1-7T2IAE7J.js → startup-0-1-M6OWAYHH.js} +540 -136
- package/dist/_shared/startup-0-1-M6OWAYHH.js.map +1 -0
- package/dist/_shared/startup-0-2-5QHPCEON.js +47 -48
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -1
- package/dist/_shared/startup-0-3-4ZYBYQNM.js +5 -5
- package/dist/_shared/startup-0-4-ZMJV547D.js +12 -7
- package/dist/_shared/startup-0-4-ZMJV547D.js.map +1 -1
- package/dist/_shared/startup-0-5-YDW47QX6.js +7 -7
- package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -1
- package/dist/_shared/startup-10-0-TDQNBDDL.js +6 -6
- package/dist/_shared/startup-12-0-55AAXBJZ.js +2 -2
- package/dist/_shared/startup-14-0-MLX36RBG.js +4 -5
- package/dist/_shared/startup-14-0-MLX36RBG.js.map +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +4 -4
- package/dist/_shared/startup-15-1-4S7FLMNG.js +19 -27
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +2144 -249
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/{startup-8-1-X32CYSXB.js → startup-8-1-LZFXSD3Z.js} +98 -1184
- package/dist/_shared/startup-8-1-LZFXSD3Z.js.map +1 -0
- package/dist/_shared/storage-command-7MGXLJGZ.js +188 -37
- package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
- package/dist/_shared/storage-status-K7PX2RXA.js +557 -0
- package/dist/_shared/storage-status-K7PX2RXA.js.map +1 -0
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/team-DOQKICG2.js +376 -0
- package/dist/_shared/team-DOQKICG2.js.map +1 -0
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +42 -0
- package/dist/builtin/intercom/README.md +2 -2
- package/dist/builtin/intercom/broker/broker.bundle.mjs +1917 -381
- package/dist/builtin/intercom/broker/client.ts +8 -0
- package/dist/builtin/intercom/broker/database-wake-up-bus.ts +324 -68
- package/dist/builtin/intercom/broker/multinode-router.ts +256 -39
- package/dist/builtin/intercom/broker/multinode-state-store.ts +71 -5
- package/dist/builtin/intercom/broker/open-broker-state.ts +14 -0
- package/dist/builtin/intercom/broker/send-order-gate.ts +5 -2
- package/dist/builtin/intercom/broker/sql-add-column.ts +50 -5
- package/dist/builtin/intercom/broker/sql-ended-child-queue-store.ts +3 -2
- package/dist/builtin/intercom/broker/sql-held-send-store.ts +2 -2
- package/dist/builtin/intercom/broker/sql-known-session-store.ts +43 -19
- package/dist/builtin/intercom/broker/sql-lease-store.ts +473 -121
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +821 -79
- package/dist/builtin/intercom/broker/sql-pending-ask-store.ts +8 -5
- package/dist/builtin/intercom/broker/sql-released-ask-store.ts +12 -5
- package/dist/builtin/intercom/broker/sql-restoring-reservation-store.ts +256 -8
- package/dist/builtin/intercom/broker/sql-retention.ts +150 -0
- package/dist/builtin/intercom/broker/sql-schema.ts +175 -24
- package/dist/builtin/intercom/broker/sql-sent-message-authority.ts +74 -19
- package/dist/builtin/intercom/broker/wake-up-bus.ts +6 -0
- package/dist/builtin/intercom/index.bundle.mjs +14 -4
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +6 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/skill-creator/eval-viewer/generate_review.py +8 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/index.bundle.mjs +2 -10
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/bun/bundled-sqlite.js +41 -0
- package/dist/bun/bundled-sqlite.js.map +1 -0
- package/dist/cli/args.js +2 -2
- package/dist/cli/auth-cli.code.js +4 -4
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +3 -3
- package/dist/cli/blueprint-command.impl.js +3 -3
- package/dist/cli/blueprint-command.js +3 -3
- package/dist/cli/intercom-command.code.js +3 -3
- package/dist/cli/intercom-command.code.js.map +1 -1
- package/dist/cli/intercom-command.impl.js +3 -3
- package/dist/cli/intercom-command.js +3 -3
- package/dist/cli/list-models.code.js +2 -2
- package/dist/cli/list-models.impl.js +3 -3
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/session-picker.code.js +1 -1
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +1 -1
- package/dist/cli/startup-ui.impl.js +3 -3
- package/dist/cli/startup-ui.js +3 -3
- package/dist/cli/storage-command.impl.js +3 -3
- package/dist/cli/storage-command.js +3 -3
- package/dist/cli/storage-search-session.code.js +3 -3
- package/dist/cli/storage-search-session.impl.js +3 -3
- package/dist/cli/storage-search-session.js +3 -3
- package/dist/cli/team-command.code.js +19 -113
- package/dist/cli/team-command.code.js.map +1 -1
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +5 -18
- package/dist/cli.js.map +1 -1
- package/dist/core/agent-rehydrate-errors.d.ts +4 -9
- package/dist/core/compaction/compactor.d.ts +3 -3
- package/dist/core/debug.code.js +1 -1
- package/dist/core/debug.impl.js +3 -3
- package/dist/core/debug.js +3 -3
- package/dist/core/export-html/card-projection.impl.js +3 -3
- package/dist/core/export-html/card-projection.js +3 -3
- package/dist/core/export-html/index.code.js +4 -4
- package/dist/core/export-html/index.code.js.map +1 -1
- package/dist/core/export-html/index.impl.js +3 -3
- package/dist/core/export-html/index.js +3 -3
- package/dist/core/export-html/json-spans.impl.js +3 -3
- package/dist/core/export-html/json-spans.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.js +3 -3
- package/dist/core/export-html/tool-renderer.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/extensions/jiti-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-loader.js +3 -3
- package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-static-loader.js +3 -3
- package/dist/core/extensions/loader-host-modules.code.js +1 -1
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/extensions/loader-virtual-modules.js +1 -1
- package/dist/core/extensions/runner-context.js +2 -2
- package/dist/core/intercom-broker-control-host.code.js +2 -2
- package/dist/core/intercom-broker-control-host.impl.js +3 -3
- package/dist/core/intercom-broker-control-host.js +3 -3
- package/dist/core/intercom-broker-control.code.js +3 -3
- package/dist/core/intercom-broker-control.impl.js +3 -3
- package/dist/core/intercom-broker-control.js +3 -3
- package/dist/core/package-manager-storage-adapters.code.js +1 -1
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/process-start-token.d.ts +12 -3
- package/dist/core/process-tree-containment.d.ts +16 -0
- package/dist/core/sdk-types.d.ts +1 -2
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.code.js +3 -3
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +5 -5
- package/dist/core/session-manager-list.impl.js +3 -3
- package/dist/core/session-manager-list.js +3 -3
- package/dist/core/session-manager.code.js +1 -1
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-storage.code.js +1 -1
- package/dist/core/session-storage.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/settings-schema.d.ts +0 -3
- package/dist/core/storage/added-exports-0-10-11.js +19 -0
- package/dist/core/storage/added-exports-0-10-11.js.map +1 -0
- package/dist/core/storage/creation-time.js +105 -0
- package/dist/core/storage/creation-time.js.map +1 -0
- package/dist/core/storage/database.d.ts +25 -5
- package/dist/core/storage/database.js.map +1 -1
- package/dist/core/storage/dialect.d.ts +1 -1
- package/dist/core/storage/dialect.js +1 -1
- package/dist/core/storage/dialect.js.map +1 -1
- package/dist/core/storage/errors.d.ts +13 -13
- package/dist/core/storage/errors.js +10 -16
- package/dist/core/storage/errors.js.map +1 -1
- package/dist/core/storage/fenced-paths.d.ts +18 -6
- package/dist/core/storage/fenced-paths.js +18 -6
- package/dist/core/storage/fenced-paths.js.map +1 -1
- package/dist/core/storage/file-identity.d.ts +2 -0
- package/dist/core/storage/file-identity.js +24 -8
- package/dist/core/storage/file-identity.js.map +1 -1
- package/dist/core/storage/index.d.ts +3 -2
- package/dist/core/storage/index.js +5 -3
- package/dist/core/storage/index.js.map +1 -1
- package/dist/core/storage/libsql-removed.d.ts +71 -0
- package/dist/core/storage/libsql-removed.js +123 -0
- package/dist/core/storage/libsql-removed.js.map +1 -0
- package/dist/core/storage/migrations.d.ts +78 -14
- package/dist/core/storage/migrations.js +375 -49
- package/dist/core/storage/migrations.js.map +1 -1
- package/dist/core/storage/node-sqlite-file-gate.js +0 -15
- package/dist/core/storage/node-sqlite-file-gate.js.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +215 -30
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.js +484 -72
- package/dist/core/storage/node-sqlite.js.map +1 -1
- package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
- package/dist/core/storage/offline-snapshot-file.js +3 -3
- package/dist/core/storage/prefix.d.ts +1 -1
- package/dist/core/storage/prefix.js +9 -2
- package/dist/core/storage/prefix.js.map +1 -1
- package/dist/core/storage/process-selection.d.ts +5 -5
- package/dist/core/storage/provider.js +2 -2
- package/dist/core/storage/schema-catalog.d.ts +76 -15
- package/dist/core/storage/schema-catalog.js +359 -68
- package/dist/core/storage/schema-catalog.js.map +1 -1
- package/dist/core/storage/selection.d.ts +7 -82
- package/dist/core/storage/selection.js +20 -235
- package/dist/core/storage/selection.js.map +1 -1
- package/dist/core/storage/session/branch-fork-source.code.js +2 -2
- package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
- package/dist/core/storage/session/branch-fork-source.js +3 -3
- package/dist/core/storage/session/card-view.impl.js +3 -3
- package/dist/core/storage/session/card-view.js +3 -3
- package/dist/core/storage/session/child-reader.code.js +3 -3
- package/dist/core/storage/session/child-reader.impl.js +3 -3
- package/dist/core/storage/session/child-reader.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.js +3 -3
- package/dist/core/storage/session/expanded-child-details.code.js +2 -2
- package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
- package/dist/core/storage/session/expanded-child-details.js +3 -3
- package/dist/core/storage/session/fork-detach.d.ts +11 -1
- package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.js +3 -3
- package/dist/core/storage/session/fork-row-index.impl.js +3 -3
- package/dist/core/storage/session/fork-row-index.js +3 -3
- package/dist/core/storage/session/fork-staging.code.js +4 -7
- package/dist/core/storage/session/fork-staging.code.js.map +1 -1
- package/dist/core/storage/session/fork-staging.impl.js +3 -3
- package/dist/core/storage/session/fork-staging.js +3 -3
- package/dist/core/storage/session/fork-sweep.js +31 -7
- package/dist/core/storage/session/fork-sweep.js.map +1 -1
- package/dist/core/storage/session/fork-window.code.js +3 -3
- package/dist/core/storage/session/fork-window.impl.js +3 -3
- package/dist/core/storage/session/fork-window.js +3 -3
- package/dist/core/storage/session/history-pages.impl.js +3 -3
- package/dist/core/storage/session/history-pages.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
- package/dist/core/storage/session/jsonl-session-lock.d.ts +100 -0
- package/dist/core/storage/session/jsonl-session-store.d.ts +46 -24
- package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.js +3 -3
- package/dist/core/storage/session/memory-session-store.impl.js +3 -3
- package/dist/core/storage/session/memory-session-store.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.js +3 -3
- package/dist/core/storage/session/released-history-files.code.js +9 -9
- package/dist/core/storage/session/released-history-files.code.js.map +1 -1
- package/dist/core/storage/session/released-history-files.impl.js +3 -3
- package/dist/core/storage/session/released-history-files.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.js +3 -3
- package/dist/core/storage/session/session-resume.impl.js +3 -3
- package/dist/core/storage/session/session-resume.js +3 -3
- package/dist/core/storage/session/session-search-index.d.ts +52 -5
- package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
- package/dist/core/storage/session/snapshot-cut.js +3 -3
- package/dist/core/storage/session/snapshot-history.code.js +3 -3
- package/dist/core/storage/session/snapshot-history.impl.js +3 -3
- package/dist/core/storage/session/snapshot-history.js +3 -3
- package/dist/core/storage/session/sql-session-store.code.js +1 -1
- package/dist/core/storage/session/sql-session-store.d.ts +99 -18
- package/dist/core/storage/session/sql-session-store.impl.js +3 -3
- package/dist/core/storage/session/sql-session-store.js +3 -3
- package/dist/core/storage/session/tree-outline.impl.js +3 -3
- package/dist/core/storage/session/tree-outline.js +3 -3
- package/dist/core/storage/session/tree-presentation.impl.js +3 -3
- package/dist/core/storage/session/tree-presentation.js +3 -3
- package/dist/core/storage/sqlite-facade.d.ts +12 -1
- package/dist/core/storage/sqlite-facade.js +310 -33
- package/dist/core/storage/sqlite-facade.js.map +1 -1
- package/dist/core/storage/sqlite-open-batch.js +10 -0
- package/dist/core/storage/sqlite-open-batch.js.map +1 -0
- package/dist/core/storage/storage-status.code.js +1 -1
- package/dist/core/storage/storage-status.impl.js +3 -3
- package/dist/core/storage/storage-status.js +3 -3
- package/dist/core/storage/team.code.js +1 -1
- package/dist/core/storage/team.d.ts +26 -115
- package/dist/core/storage/team.impl.js +3 -3
- package/dist/core/storage/team.js +3 -3
- package/dist/core/structured-output/index.code.js +1 -1
- package/dist/core/structured-output/index.impl.js +3 -3
- package/dist/core/structured-output/index.js +3 -3
- package/dist/core/tasks/task-completion-entry.impl.js +3 -3
- package/dist/core/tasks/task-completion-entry.js +3 -3
- package/dist/core/tasks/task-file-history.code.js +3 -3
- package/dist/core/tasks/task-file-history.impl.js +3 -3
- package/dist/core/tasks/task-file-history.js +3 -3
- package/dist/core/tasks/task-reference-archive.code.js +4 -4
- package/dist/core/tasks/task-reference-archive.js +3 -3
- package/dist/core/tasks/task-reference-identity.js +3 -3
- package/dist/core/tasks/task-reference-stream.impl.js +3 -3
- package/dist/core/tasks/task-reference-stream.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.js +3 -3
- package/dist/core/tasks/task-view-source.code.js +1 -1
- package/dist/core/tasks/task-view-source.impl.js +3 -3
- package/dist/core/tasks/task-view-source.js +3 -3
- package/dist/core/tools/history-tasks.d.ts +3 -2
- package/dist/core/tools/read-url.code.js +4 -4
- package/dist/core/tools/read-url.impl.js +3 -3
- package/dist/core/tools/read-url.js +3 -3
- package/dist/core/worktree-snapshot/blob-store.d.ts +44 -5
- package/dist/core/worktree-snapshot/blob-store.js +553 -30
- package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
- package/dist/core/worktree-snapshot/errors.code.js +2 -2
- package/dist/core/worktree-snapshot/errors.impl.js +3 -3
- package/dist/core/worktree-snapshot/errors.js +3 -3
- package/dist/core/worktree-snapshot/fork-blob-guard.js +81 -0
- package/dist/core/worktree-snapshot/fork-blob-guard.js.map +1 -0
- package/dist/core/worktree-snapshot/fork-snapshot-index.js +208 -50
- package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -1
- package/dist/core/worktree-snapshot/session-index-reset.code.js +4 -0
- package/dist/core/worktree-snapshot/session-index-reset.code.js.map +1 -1
- package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
- package/dist/extensions/codemode/execute.code.js +1 -1
- package/dist/extensions/codemode/execute.impl.js +3 -3
- package/dist/extensions/codemode/execute.js +3 -3
- package/dist/extensions/codemode/renderer.code.js +2 -2
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +3 -3
- package/dist/extensions/mcp/cli.impl.js +3 -3
- package/dist/extensions/mcp/cli.js +3 -3
- package/dist/extensions/mcp/cli.lazy.code.js +2 -2
- package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
- package/dist/extensions/mcp/cli.lazy.js +3 -3
- package/dist/extensions/mcp/runtime.code.js +1 -1
- package/dist/extensions/mcp/runtime.impl.js +3 -3
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -5
- package/dist/main-first-time-setup.code.js +1 -1
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/main.js +1 -1
- package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
- package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
- package/dist/modes/interactive/startup-shell-eligibility.js +1 -1
- package/dist/modes/interactive-engine/engine-prewarm.d.ts +1 -1
- package/dist/modes/print-mode.js +1 -1
- package/dist/package-manager-cli.code.js +6 -6
- package/dist/package-manager-cli.impl.js +3 -3
- package/dist/package-manager-cli.js +3 -3
- package/dist/rpc-entry.js +1 -1
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/10.js +1 -1
- package/dist/startup-stages/11.js +1 -1
- package/dist/startup-stages/12.js +1 -1
- package/dist/startup-stages/2.js +2 -4
- package/dist/startup-stages/3.js +1 -3
- package/dist/startup-stages/4.js +1 -2
- package/dist/startup-stages/5.js +1 -1
- package/dist/startup-stages/6.js +5 -7
- package/dist/startup-stages/7.js +3 -10
- package/dist/startup-stages/8.js +7 -2
- package/dist/startup-stages/9.js +1 -7
- package/dist/startup-stages/stages.json +1 -1
- package/dist/utils/compile-cache-deferral.js +8 -13
- package/dist/utils/compile-cache-deferral.js.map +1 -1
- package/dist/utils/compile-cache-warmup-host.js +3 -4
- package/dist/utils/compile-cache-warmup-host.js.map +1 -1
- package/dist/utils/compile-cache.js +12 -100
- package/dist/utils/compile-cache.js.map +1 -1
- package/dist/utils/startup-database-spare.code.js +2 -2
- package/dist/utils/startup-database-spare.impl.js +3 -3
- package/dist/utils/startup-database-spare.js +3 -3
- package/dist/utils/tools-manager.code.js +1 -1
- package/dist/utils/tools-manager.impl.js +3 -3
- package/dist/utils/tools-manager.js +3 -3
- package/dist/utils/worker-threads.js +2 -15
- package/dist/utils/worker-threads.js.map +1 -1
- package/docs/build.md +3 -3
- package/docs/changelog.mdx +1470 -69
- package/docs/compaction/reference.md +5 -5
- package/docs/compaction.md +7 -9
- package/docs/containerization.md +2 -2
- package/docs/custom-provider/api-reference.md +1 -1
- package/docs/docs.json +37 -10
- package/docs/environment-variables.md +0 -2
- package/docs/extensions/api-reference.md +4 -4
- package/docs/getting-started/installation.md +3 -0
- package/docs/guides/configuration.md +1 -1
- package/docs/guides/non-interactive.md +1 -1
- package/docs/guides/resume-on-any-machine.md +14 -22
- package/docs/guides/team-setup.md +56 -83
- package/docs/guides.md +2 -4
- package/docs/herdr.md +1 -1
- package/docs/index.md +1 -1
- package/docs/intercom/operations.md +26 -21
- package/docs/intercom/reference.md +2 -2
- package/docs/intercom.md +1 -1
- package/docs/libraries/storage-postgres.md +9 -9
- package/docs/libraries.md +2 -3
- package/docs/models-configuration.md +2 -2
- package/docs/models.md +2 -3
- package/docs/packages/authoring.md +7 -7
- package/docs/packages.md +1 -1
- package/docs/programmatic.md +2 -2
- package/docs/quickstart.md +1 -1
- package/docs/reference/cli.md +6 -11
- package/docs/reference.md +2 -2
- package/docs/rpc/extension-ui.md +2 -2
- package/docs/sdk/reference.md +5 -4
- package/docs/sdk/storage.md +8 -92
- package/docs/sdk/structured-decisions.md +1 -1
- package/docs/sdk/web-server.md +3 -3
- package/docs/sdk.md +14 -4
- package/docs/security.md +1 -1
- package/docs/session-format.md +5 -5
- package/docs/sessions.md +29 -49
- package/docs/settings.md +7 -8
- package/docs/storage/custom-adapters.md +255 -0
- package/docs/storage/jsonl.md +117 -0
- package/docs/{guides/postgres-pgbouncer.md → storage/postgres/pgbouncer.md} +66 -68
- package/docs/storage/postgres/tuning.md +337 -0
- package/docs/storage/postgres.md +556 -0
- package/docs/storage/sqlite.md +99 -0
- package/docs/storage.md +326 -990
- package/docs/subagents/authoring.md +1 -1
- package/docs/subagents.md +2 -2
- package/docs/tools.md +1 -1
- package/docs/worktree-snapshots.md +2 -2
- package/package.json +9 -9
- package/schemas/models.schema.json +2 -2
- package/schemas/settings.schema.json +0 -14
- package/dist/_shared/p1b-elig-ENCUPKKJ.js.map +0 -1
- package/dist/_shared/sdk-IQMULKFU.js.map +0 -1
- package/dist/_shared/startup-0-0-3IXNMFM2.js.map +0 -1
- package/dist/_shared/startup-0-1-7T2IAE7J.js.map +0 -1
- package/dist/_shared/startup-8-1-X32CYSXB.js.map +0 -1
- package/dist/core/intercom-broker-control.d.ts +0 -129
- package/dist/startup-stages/13.js +0 -1
- package/docs/guides/postgres-tuning.md +0 -311
- package/docs/libraries/storage-libsql.md +0 -97
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import type { SqliteExecutor } from "./storage/database.js";
|
|
2
|
-
/**
|
|
3
|
-
* The part of the bundled Intercom package's `broker/control.ts` that `atomic storage status` and
|
|
4
|
-
* `atomic intercom restart` use. Intercom owns its broker protocol, socket paths and shared-state tables; the CLI
|
|
5
|
-
* loads that module from the bundled package, as it loads extensions, rather than reimplementing them.
|
|
6
|
-
*/
|
|
7
|
-
export interface BrokerMultiNodeStatus {
|
|
8
|
-
readonly status: "off" | "starting" | "on" | "unavailable";
|
|
9
|
-
readonly reason?: string;
|
|
10
|
-
readonly adapter?: string;
|
|
11
|
-
readonly prefix?: string;
|
|
12
|
-
readonly peers?: readonly string[];
|
|
13
|
-
}
|
|
14
|
-
export interface BrokerStatusReport {
|
|
15
|
-
readonly pid: number;
|
|
16
|
-
readonly sessions: number;
|
|
17
|
-
readonly storage?: {
|
|
18
|
-
readonly digest: string;
|
|
19
|
-
readonly source: "env" | "settings";
|
|
20
|
-
};
|
|
21
|
-
readonly multiNode: BrokerMultiNodeStatus;
|
|
22
|
-
/** The wire protocol versions the broker accepts; absent from a broker of protocol 1 (0.9.71 and earlier). */
|
|
23
|
-
readonly protocol?: BrokerProtocolRange;
|
|
24
|
-
}
|
|
25
|
-
/** Wire protocol versions, inclusive at both ends. */
|
|
26
|
-
export interface BrokerProtocolRange {
|
|
27
|
-
readonly min: number;
|
|
28
|
-
readonly max: number;
|
|
29
|
-
}
|
|
30
|
-
export type BrokerQuery = {
|
|
31
|
-
readonly state: "stopped";
|
|
32
|
-
} | {
|
|
33
|
-
readonly state: "running";
|
|
34
|
-
readonly report: BrokerStatusReport;
|
|
35
|
-
} | {
|
|
36
|
-
readonly state: "legacy";
|
|
37
|
-
readonly pid?: number;
|
|
38
|
-
};
|
|
39
|
-
export interface ExpectedBrokerStorage {
|
|
40
|
-
readonly digest: string;
|
|
41
|
-
readonly source: "env" | "settings";
|
|
42
|
-
readonly adapter: string;
|
|
43
|
-
readonly prefix?: string;
|
|
44
|
-
}
|
|
45
|
-
export type RestartOutcome = {
|
|
46
|
-
readonly status: "not-running";
|
|
47
|
-
} | {
|
|
48
|
-
readonly status: "stopped";
|
|
49
|
-
readonly previous: {
|
|
50
|
-
readonly pid: number;
|
|
51
|
-
readonly sessions?: number;
|
|
52
|
-
};
|
|
53
|
-
} | {
|
|
54
|
-
readonly status: "restarted";
|
|
55
|
-
readonly previous: {
|
|
56
|
-
readonly pid: number;
|
|
57
|
-
readonly sessions?: number;
|
|
58
|
-
};
|
|
59
|
-
readonly current: Exclude<BrokerQuery, {
|
|
60
|
-
state: "stopped";
|
|
61
|
-
}>;
|
|
62
|
-
};
|
|
63
|
-
export type StopIdleOutcome = {
|
|
64
|
-
readonly status: "not-running";
|
|
65
|
-
} | {
|
|
66
|
-
readonly status: "unreported";
|
|
67
|
-
readonly pid?: number;
|
|
68
|
-
} | {
|
|
69
|
-
readonly status: "busy";
|
|
70
|
-
readonly pid: number;
|
|
71
|
-
readonly sessions: number;
|
|
72
|
-
} | {
|
|
73
|
-
readonly status: "stopped";
|
|
74
|
-
readonly pid: number;
|
|
75
|
-
} | {
|
|
76
|
-
readonly status: "not-stopped";
|
|
77
|
-
readonly pid: number;
|
|
78
|
-
};
|
|
79
|
-
export type UpgradeOutcome = {
|
|
80
|
-
readonly status: "not-running";
|
|
81
|
-
} | {
|
|
82
|
-
readonly status: "unreported";
|
|
83
|
-
readonly pid?: number;
|
|
84
|
-
} | {
|
|
85
|
-
readonly status: "current";
|
|
86
|
-
readonly pid: number;
|
|
87
|
-
readonly protocol: BrokerProtocolRange;
|
|
88
|
-
readonly decision: "compatible" | "incompatible";
|
|
89
|
-
} | {
|
|
90
|
-
readonly status: "deferred";
|
|
91
|
-
readonly pid: number;
|
|
92
|
-
readonly sessions: number;
|
|
93
|
-
readonly protocol: BrokerProtocolRange;
|
|
94
|
-
} | {
|
|
95
|
-
readonly status: "stopped";
|
|
96
|
-
readonly previous: {
|
|
97
|
-
readonly pid: number;
|
|
98
|
-
readonly protocol: BrokerProtocolRange;
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
export interface IntercomBrokerControl {
|
|
102
|
-
/** The protocol versions this version's broker accepts. */
|
|
103
|
-
readonly BROKER_PROTOCOL: BrokerProtocolRange;
|
|
104
|
-
queryIntercomBroker(agentDir: string): Promise<BrokerQuery>;
|
|
105
|
-
expectedBrokerStorage(agentDir: string, env?: NodeJS.ProcessEnv): ExpectedBrokerStorage | undefined;
|
|
106
|
-
readLiveBrokers(database: SqliteExecutor, prefix: string | undefined): Promise<string[] | undefined>;
|
|
107
|
-
restartIntercomBroker(agentDir: string, options?: {
|
|
108
|
-
readonly onProgress?: (line: string) => void;
|
|
109
|
-
}): Promise<RestartOutcome>;
|
|
110
|
-
/** Stop the broker only when it reports 0 connected sessions; never interrupts active or legacy brokers. */
|
|
111
|
-
stopIdleIntercomBroker?(agentDir: string, options?: {
|
|
112
|
-
readonly stopTimeoutMs?: number;
|
|
113
|
-
readonly controlTimeoutMs?: number;
|
|
114
|
-
}): Promise<StopIdleOutcome>;
|
|
115
|
-
/** #4538: replace an older broker when that is safe; see `atomic intercom upgrade`. */
|
|
116
|
-
upgradeIntercomBroker(agentDir: string, options?: {
|
|
117
|
-
readonly onProgress?: (line: string) => void;
|
|
118
|
-
}): Promise<UpgradeOutcome>;
|
|
119
|
-
describeMultiNodeStatus(multiNode: BrokerMultiNodeStatus): string;
|
|
120
|
-
/**
|
|
121
|
-
* The group a session in `cwd` joins when no policy, `ATOMIC_INTERCOM_GROUP` or Intercom `config.json`
|
|
122
|
-
* group applies, while multi-node routing is selected: `project:<owner>/<repo>` from the origin remote, or the
|
|
123
|
-
* directory name. `undefined` while multi-node routing is off, where it is `default`.
|
|
124
|
-
*/
|
|
125
|
-
projectHomeGroup(cwd: string, agentDir: string, storageEnv: NodeJS.ProcessEnv, gitEnv: NodeJS.ProcessEnv): string | undefined;
|
|
126
|
-
}
|
|
127
|
-
/** Load `broker/control.ts` from the bundled Intercom package, in the npm package and the standalone binary alike. */
|
|
128
|
-
export declare function loadIntercomBrokerControl(): Promise<IntercomBrokerControl>;
|
|
129
|
-
//# sourceMappingURL=intercom-broker-control.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "../main.js";
|
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Tune PostgreSQL for many agents"
|
|
3
|
-
sidebarTitle: "Tune PostgreSQL"
|
|
4
|
-
description: "Server-side tuning for a PostgreSQL database shared by many Atomic agents: where the time goes, distance, connections, memory, monitoring, busy tables, and what to leave alone."
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
This guide is for the person who runs the PostgreSQL server that Atomic's agents share. It follows what we did on a production server and measured there. Use it after you set up the database as in [PostgreSQL storage](/storage#postgresql).
|
|
8
|
-
|
|
9
|
-
**The server we tuned:** PostgreSQL 18 on a machine with 8 CPU cores, 30 GB of memory and an NVMe disk. It served up to 200 agents about 80 ms away over the network. Each section says what we measured on that server, what is general advice, and what we have not tried on managed services such as Amazon RDS, Azure or Google Cloud SQL.
|
|
10
|
-
|
|
11
|
-
The table names below assume Atomic's default schema, `atomic`, and no `prefix`. With a prefix, each table name starts with it, for example `atomic.team_session_sessions`.
|
|
12
|
-
|
|
13
|
-
## Where the time goes
|
|
14
|
-
|
|
15
|
-
For Atomic, a database server is rarely short of CPU or disk. On our server the load average stayed below 1.7 while 200 agents worked, and every query that did real work took under 60 seconds in total over a 13-minute test. The limits are:
|
|
16
|
-
|
|
17
|
-
- **Round trips.** Each save waits for answers from the server. The farther away the server, the longer each wait.
|
|
18
|
-
- **Connections.** Each server has a fixed number. When agents need more than it has, they get errors.
|
|
19
|
-
- **Locks.** Agents that write the same data wait for each other. Before Atomic's own locking was fixed, waiting for locks was 99 to 100% of the time the server spent on Atomic's queries.
|
|
20
|
-
|
|
21
|
-
To tell which one you are hitting, run these as an administrator. Replace `atomic` with your database's name.
|
|
22
|
-
|
|
23
|
-
How many connections are in use, and what they are doing. `active` means running a query, and `idle` means open but unused:
|
|
24
|
-
|
|
25
|
-
```sql
|
|
26
|
-
SELECT state, count(*)
|
|
27
|
-
FROM pg_stat_activity
|
|
28
|
-
WHERE datname = 'atomic'
|
|
29
|
-
GROUP BY state
|
|
30
|
-
ORDER BY 2 DESC;
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
What the busy connections are waiting for. A large count with `wait_event_type` `Lock` means lock waits. `Client` with `ClientRead` means the server waits for the agent, which usually means distance:
|
|
34
|
-
|
|
35
|
-
```sql
|
|
36
|
-
SELECT wait_event_type, wait_event, count(*)
|
|
37
|
-
FROM pg_stat_activity
|
|
38
|
-
WHERE datname = 'atomic' AND state <> 'idle'
|
|
39
|
-
GROUP BY 1, 2
|
|
40
|
-
ORDER BY 3 DESC;
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
How close the server is to its connection limit:
|
|
44
|
-
|
|
45
|
-
```sql
|
|
46
|
-
SELECT count(*) AS used, current_setting('max_connections')::int AS max
|
|
47
|
-
FROM pg_stat_activity
|
|
48
|
-
WHERE backend_type = 'client backend';
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
On the machine itself, `uptime` shows the load average. If it stays well below the number of CPU cores while agents are slow, the server is waiting, not working.
|
|
52
|
-
|
|
53
|
-
## Put the database close to the agents
|
|
54
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
65
|
-
Run the server in the same region as the agents, and ideally the same zone. No server setting makes up for distance.
|
|
66
|
-
|
|
67
|
-
## Connections
|
|
68
|
-
|
|
69
|
-
Each Atomic process opens up to `maxConnections` plus `readerMaxConnections` connections to the server, 10 by default. An Intercom broker process opens one more, for wake-ups. [Count the connections Atomic needs](/storage#count-the-connections-atomic-needs) explains the arithmetic, and [Tuning for many concurrent agents](/storage#tuning-for-many-concurrent-agents) shows how to size `maxConnections`.
|
|
70
|
-
|
|
71
|
-
On the server:
|
|
72
|
-
|
|
73
|
-
- **`max_connections`** is the total the server accepts. Each connection uses memory for its own work, so the server cannot accept unlimited connections. On our server we raised it from 300 to 400, which needs a restart. That leaves room for PgBouncer's pool, one wake-up connection per broker, and administrators.
|
|
74
|
-
- **Per-role limits.** `ALTER ROLE atomic_runtime CONNECTION LIMIT 300;` caps one role, so a runaway fleet cannot take every slot. We raised Atomic's role from 150 to 300, because every broker holds a direct wake-up connection.
|
|
75
|
-
- **PgBouncer.** When agents need more connections than the server can give, put [PgBouncer](/guides/postgres-pgbouncer) in front. With 200 agents and a 300-connection server, we had to.
|
|
76
|
-
|
|
77
|
-
```sql
|
|
78
|
-
SHOW max_connections;
|
|
79
|
-
ALTER ROLE atomic_runtime CONNECTION LIMIT 300;
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
## Memory
|
|
83
|
-
|
|
84
|
-
### Shared buffers
|
|
85
|
-
|
|
86
|
-
`shared_buffers` is the memory PostgreSQL keeps for table and index pages. A common starting point is a quarter of the machine's memory. Our server has 30 GB and uses `shared_buffers = 8GB`. Atomic's data was small enough that 99.999% of page reads came from memory, so a larger value would not have helped. Changing it needs a restart.
|
|
87
|
-
|
|
88
|
-
### Huge pages
|
|
89
|
-
|
|
90
|
-
The operating system tracks memory in pages, usually 4 KB each. Every server process that touches shared memory keeps its own table of those pages. With 8 GB of shared buffers and hundreds of connections, those tables alone can take gigabytes. Huge pages are 2 MB each on Linux, so the tables are 512 times smaller.
|
|
91
|
-
|
|
92
|
-
PostgreSQL uses huge pages when `huge_pages` is `try` (the default) or `on`, and the operating system has enough of them reserved. Our server had `huge_pages = try` but none reserved, so `huge_pages_status` was `off`. To fix that on Linux:
|
|
93
|
-
|
|
94
|
-
1. **Find out how many pages PostgreSQL needs.** Stop the server first: this setting can only be read while it is not running. Run, as the `postgres` user, with your data directory:
|
|
95
|
-
|
|
96
|
-
```bash
|
|
97
|
-
postgres -D /var/lib/postgresql/18/main -C shared_memory_size_in_huge_pages
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
On Debian and Ubuntu, `postgres` is in `/usr/lib/postgresql/18/bin/`. Add `-c config_file=/etc/postgresql/18/main/postgresql.conf` so it reads your settings. On our server it printed `4259`.
|
|
101
|
-
|
|
102
|
-
2. **Reserve a little more than that**, rounded up, and keep it across reboots. We reserved 4350, which leaves about 180 MB spare:
|
|
103
|
-
|
|
104
|
-
```bash
|
|
105
|
-
echo 'vm.nr_hugepages = 4350' | sudo tee /etc/sysctl.d/60-postgresql-hugepages.conf
|
|
106
|
-
sudo sysctl -p /etc/sysctl.d/60-postgresql-hugepages.conf
|
|
107
|
-
grep HugePages_Total /proc/meminfo
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
3. **Start the server and check** that it uses them:
|
|
111
|
-
|
|
112
|
-
```sql
|
|
113
|
-
SHOW huge_pages_status;
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
It should say `on`. `huge_pages_status` exists in PostgreSQL 17 and later. On any version, `HugePages_Rsvd` in `/proc/meminfo` should be close to the number PostgreSQL needed.
|
|
117
|
-
|
|
118
|
-
Reserved huge pages are taken out of the memory other programs can use. On our server, available memory went from 30.0 GB to 21.7 GB, because 8.5 GB was now reserved as huge pages for PostgreSQL's shared memory. We did not measure how much page-table memory this saved. To undo it, set `vm.nr_hugepages` back to `0` after stopping the server.
|
|
119
|
-
|
|
120
|
-
Managed services decide huge pages for you. We have not checked how each one sets them.
|
|
121
|
-
|
|
122
|
-
## See what is slow
|
|
123
|
-
|
|
124
|
-
`pg_stat_statements` is an extension that records how often each query runs and how long it takes in total. It is the only way to see what hundreds of agents actually ask of the server.
|
|
125
|
-
|
|
126
|
-
1. **Load it at server start.** Add this line to `postgresql.conf`, or to a file in its `conf.d` directory, and restart:
|
|
127
|
-
|
|
128
|
-
```ini
|
|
129
|
-
shared_preload_libraries = 'pg_stat_statements'
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
If the line already lists other libraries, add it to the list, separated by a comma.
|
|
133
|
-
|
|
134
|
-
2. **Create the extension** in Atomic's database, as a superuser. Atomic's owner role cannot: it gets `permission denied to create extension "pg_stat_statements"` with the hint `Must be superuser to create this extension`.
|
|
135
|
-
|
|
136
|
-
```sql
|
|
137
|
-
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
3. **Let your monitoring role see every query.** Without this, a role sees the text only of its own queries:
|
|
141
|
-
|
|
142
|
-
```sql
|
|
143
|
-
GRANT pg_read_all_stats TO atomic_owner;
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
Queries to run, all in the `atomic` database:
|
|
147
|
-
|
|
148
|
-
The queries that take the most total time. This is where to look first:
|
|
149
|
-
|
|
150
|
-
```sql
|
|
151
|
-
SELECT calls, round(total_exec_time) AS total_ms, round(mean_exec_time::numeric, 2) AS mean_ms,
|
|
152
|
-
left(query, 100) AS query
|
|
153
|
-
FROM pg_stat_statements
|
|
154
|
-
ORDER BY total_exec_time DESC
|
|
155
|
-
LIMIT 10;
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
The slowest queries on average:
|
|
159
|
-
|
|
160
|
-
```sql
|
|
161
|
-
SELECT calls, round(mean_exec_time::numeric, 2) AS mean_ms, round(max_exec_time::numeric, 2) AS max_ms,
|
|
162
|
-
left(query, 100) AS query
|
|
163
|
-
FROM pg_stat_statements
|
|
164
|
-
WHERE calls > 50
|
|
165
|
-
ORDER BY mean_exec_time DESC
|
|
166
|
-
LIMIT 10;
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
How much of the time is lock waits. Atomic takes its locks with `pg_advisory_xact_lock`, so a large share here means agents wait for each other, not for the server:
|
|
170
|
-
|
|
171
|
-
```sql
|
|
172
|
-
SELECT round((100 * sum(total_exec_time) FILTER (WHERE query LIKE '%pg_advisory%')
|
|
173
|
-
/ nullif(sum(total_exec_time), 0))::numeric, 1) AS lock_share_percent
|
|
174
|
-
FROM pg_stat_statements;
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
To start a new measurement, clear the counters:
|
|
178
|
-
|
|
179
|
-
```sql
|
|
180
|
-
SELECT pg_stat_statements_reset();
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
## Busy small tables
|
|
184
|
-
|
|
185
|
-
A few of Atomic's tables are small but change constantly:
|
|
186
|
-
|
|
187
|
-
| Table | What changes it |
|
|
188
|
-
| --- | --- |
|
|
189
|
-
| `atomic.session_sessions` | One row per session, updated on every save |
|
|
190
|
-
| `atomic.intercom_leases` | Leases that Intercom brokers renew every few seconds |
|
|
191
|
-
| `atomic.snapshot_session_links` | Links between sessions and worktree snapshots, updated when sessions change |
|
|
192
|
-
|
|
193
|
-
### Clean them up sooner
|
|
194
|
-
|
|
195
|
-
PostgreSQL never changes a row in place. An update writes a new version of the row and leaves the old one behind as a dead row. A background process, autovacuum, later frees the dead rows. By default it waits until a fifth of a table is dead, which on a small table that changes constantly can mean many dead rows between cleanups, and queries that read past them.
|
|
196
|
-
|
|
197
|
-
Tell autovacuum to clean these tables after a fixed number of dead rows instead. This takes effect at once, with no restart. These are the settings we use:
|
|
198
|
-
|
|
199
|
-
```sql
|
|
200
|
-
ALTER TABLE atomic.session_sessions SET (
|
|
201
|
-
autovacuum_vacuum_scale_factor = 0, autovacuum_vacuum_threshold = 500,
|
|
202
|
-
autovacuum_analyze_scale_factor = 0, autovacuum_analyze_threshold = 500);
|
|
203
|
-
ALTER TABLE atomic.intercom_leases SET (
|
|
204
|
-
autovacuum_vacuum_scale_factor = 0, autovacuum_vacuum_threshold = 500,
|
|
205
|
-
autovacuum_analyze_scale_factor = 0, autovacuum_analyze_threshold = 500);
|
|
206
|
-
ALTER TABLE atomic.snapshot_session_links SET (
|
|
207
|
-
autovacuum_vacuum_scale_factor = 0, autovacuum_vacuum_threshold = 1000,
|
|
208
|
-
autovacuum_analyze_scale_factor = 0, autovacuum_analyze_threshold = 1000);
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
On our server, `snapshot_session_links` had 13,444 dead rows before the change. Autovacuum cleaned it 21 seconds later, leaving none. Check dead rows and the last cleanup with:
|
|
212
|
-
|
|
213
|
-
```sql
|
|
214
|
-
SELECT relname, n_live_tup, n_dead_tup, last_autovacuum
|
|
215
|
-
FROM pg_stat_user_tables
|
|
216
|
-
WHERE relname IN ('session_sessions', 'intercom_leases', 'snapshot_session_links');
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
To undo the settings, run `ALTER TABLE <table> RESET (autovacuum_vacuum_scale_factor, autovacuum_vacuum_threshold, autovacuum_analyze_scale_factor, autovacuum_analyze_threshold);`.
|
|
220
|
-
|
|
221
|
-
### Updates that stay on their page
|
|
222
|
-
|
|
223
|
-
When PostgreSQL writes a row's new version on the same page as the old one, and the update changes no indexed column, it can skip updating the table's indexes. This is called a HOT update, for heap-only tuple. It is faster and leaves less to clean up. It only works when the page has free space.
|
|
224
|
-
|
|
225
|
-
`fillfactor` leaves part of every page free for this. Atomic sets `fillfactor = 80` on `session_sessions` and `intercom_leases`, leaving a fifth of each page free, when you run `atomic storage migrate`. You do not set it yourself.
|
|
226
|
-
|
|
227
|
-
| Table | Share of updates that were HOT before | After `fillfactor = 80` | Where we measured |
|
|
228
|
-
| --- | --- | --- | --- |
|
|
229
|
-
| `session_sessions` | 92% | 94.5% | 300 sessions, in a test database |
|
|
230
|
-
| `intercom_leases` | 70 to 76% | about 90%, and the table half the size | 600 leases, in a test database |
|
|
231
|
-
| `session_sessions` | 71% on our server, misses on full pages | not yet measured there | production server |
|
|
232
|
-
|
|
233
|
-
`fillfactor` applies to pages written after the change. To rewrite existing pages, run `VACUUM FULL` on the table, which locks it while it runs, or use `pg_repack`. This is optional.
|
|
234
|
-
|
|
235
|
-
`snapshot_session_links` gets no HOT updates at all: 0 of 5,785 on our server. Its updates change a column that one of its indexes depends on, so free space does not help. The autovacuum settings above keep it small.
|
|
236
|
-
|
|
237
|
-
Check the share of HOT updates per table with:
|
|
238
|
-
|
|
239
|
-
```sql
|
|
240
|
-
SELECT relname, n_tup_upd, n_tup_hot_upd,
|
|
241
|
-
round(100.0 * n_tup_hot_upd / nullif(n_tup_upd, 0), 1) AS hot_percent
|
|
242
|
-
FROM pg_stat_user_tables
|
|
243
|
-
WHERE relname IN ('session_sessions', 'intercom_leases', 'snapshot_session_links');
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
### The search index (optional)
|
|
247
|
-
|
|
248
|
-
Atomic indexes session text for search with a trigram index, `atomic.session_search_trgm`. This kind of index (GIN) collects new entries in a pending list and adds them to the index in one go when the list fills up. That flush happens inside one agent's save, so that save is slow now and then.
|
|
249
|
-
|
|
250
|
-
A smaller pending list makes the flushes smaller. In a benchmark of 460 inserts on PostgreSQL 16, run once per setting on a busy test machine, not on our server:
|
|
251
|
-
|
|
252
|
-
| Index setting | Insert p50 | Insert p99 | Slowest insert | Total insert time | Search |
|
|
253
|
-
| --- | --- | --- | --- | --- | --- |
|
|
254
|
-
| Default, 4 MB pending list | 1.96 ms | 22.9 ms | 26.5 ms | 1,122 ms | 0.83 ms |
|
|
255
|
-
| `gin_pending_list_limit = 1024` (1 MB) | 1.92 ms | 13.7 ms | 15.5 ms | 1,225 ms | 0.81 ms |
|
|
256
|
-
| `gin_pending_list_limit = 256` | 2.08 ms | 11.6 ms | 17.3 ms | 1,713 ms | 0.83 ms |
|
|
257
|
-
| `fastupdate = off` | 10.6 ms | 32.6 ms | 45.1 ms | 5,114 ms | 0.47 ms |
|
|
258
|
-
|
|
259
|
-
A 1 MB list halved the slowest inserts for 9% more total insert time. It does not make Atomic faster overall. If occasional slow saves matter to you, apply it:
|
|
260
|
-
|
|
261
|
-
```sql
|
|
262
|
-
ALTER INDEX atomic.session_search_trgm SET (gin_pending_list_limit = 1024);
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
## What we checked and left alone
|
|
266
|
-
|
|
267
|
-
These settings come up in tuning advice. We measured each on our server and kept the default or the existing value:
|
|
268
|
-
|
|
269
|
-
- **`synchronous_commit = on`.** Turning it off makes commits return before they reach the disk, so a crash can lose the last commits. On our server's NVMe disk, writing the write-ahead log to disk (fsync) took 0.37 ms on average: 7,394 of them took 2.7 seconds in total. That is small next to a round trip, so there is nothing to gain.
|
|
270
|
-
- **`commit_delay`.** It makes commits wait a little so several can share one fsync. With 0.37 ms fsyncs, there is nothing to share.
|
|
271
|
-
- **`wal_compression`.** We kept `zstd`, which was already set. It makes the write-ahead log smaller at a small CPU cost, and the CPU was idle.
|
|
272
|
-
- **`io_method`.** PostgreSQL 18 can read from disk with `worker` (the default) or `io_uring`. With 99.999% of reads served from memory, the disk is rarely read, so we kept `worker`.
|
|
273
|
-
- **The search index's pending list.** See [The search index](#the-search-index-optional). It trades total insert time for fewer slow inserts, and does not raise throughput.
|
|
274
|
-
- **`deadlock_timeout`.** Atomic's lock waits are expected and end at its own lock timeout, so lowering it only adds work. Keep `log_lock_waits = on` to see long waits in the log.
|
|
275
|
-
|
|
276
|
-
We did not change `effective_cache_size`, `random_page_cost`, `max_wal_size` or `idle_in_transaction_session_timeout`. Their existing values worked.
|
|
277
|
-
|
|
278
|
-
## After you upgrade Atomic
|
|
279
|
-
|
|
280
|
-
After every Atomic upgrade, run `atomic storage migrate` once, as the owner role, before you start many agents:
|
|
281
|
-
|
|
282
|
-
```bash
|
|
283
|
-
atomic storage migrate --db 'postgresql://atomic_owner@db.example.com:5432/atomic' --password-file ~/atomic-owner-password
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
Why it matters for performance:
|
|
287
|
-
|
|
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, `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
|
-
|
|
291
|
-
## Checklist
|
|
292
|
-
|
|
293
|
-
| Step | Restart needed | Measured on our server |
|
|
294
|
-
| --- | --- | --- |
|
|
295
|
-
| Run the database in the same region as the agents | — | Yes: 2 round trips per save, 1 after `atomic storage migrate` |
|
|
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
|
-
| Set `shared_buffers` to about a quarter of memory | Yes | Kept 8 GB of 30 GB |
|
|
298
|
-
| Reserve huge pages with `vm.nr_hugepages` and check `huge_pages_status` | Yes | Yes: `on`, 4259 pages needed, 4350 reserved |
|
|
299
|
-
| Preload `pg_stat_statements`, create it as a superuser, grant `pg_read_all_stats` | Yes | Yes |
|
|
300
|
-
| Set per-table autovacuum on `session_sessions`, `intercom_leases` and `snapshot_session_links` | No | Yes |
|
|
301
|
-
| Run `atomic storage migrate` after each Atomic upgrade | No | Yes |
|
|
302
|
-
| Optionally, shrink the search index's pending list | No | In a benchmark only |
|
|
303
|
-
| Leave `synchronous_commit`, `commit_delay`, `wal_compression` and `io_method` as they are | — | Yes |
|
|
304
|
-
|
|
305
|
-
On a managed service, the server settings above may be fixed or set through the service's own parameters. We have not tested this guide on Amazon RDS, Azure Database for PostgreSQL or Google Cloud SQL. The SQL statements work the same way there, except that creating `pg_stat_statements` needs the service's administrator role.
|
|
306
|
-
|
|
307
|
-
## Related pages
|
|
308
|
-
|
|
309
|
-
- [PostgreSQL storage](/storage#postgresql): set up the database and roles.
|
|
310
|
-
- [Tuning for many concurrent agents](/storage#tuning-for-many-concurrent-agents): size Atomic's connection settings.
|
|
311
|
-
- [Run many agents on PostgreSQL with PgBouncer](/guides/postgres-pgbouncer).
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "@bastani/atomic-storage-libsql"
|
|
3
|
-
sidebarTitle: "@bastani/atomic-storage-libsql"
|
|
4
|
-
description: "libSQL and Turso storage adapter for Atomic sessions and Intercom multi-node routing, usable from the CLI or TypeScript SDK."
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
`@bastani/atomic-storage-libsql` is Atomic's standalone libSQL and [Turso](https://turso.tech) storage adapter. It stores sessions and Intercom multi-node routing in a shared Turso database, self-hosted `sqld` server, or local libSQL file with one URL and one auth token. Unlike the six core libraries in [Standalone libraries](/libraries), this package is not bundled inside `@bastani/atomic`; install it only when you use libSQL or Turso.
|
|
8
|
-
|
|
9
|
-
- **Plain ESM with types:** Ships plain JavaScript ESM and TypeScript declarations (`libsql.d.ts`), requiring Node.js 24.20+ with no TypeScript loader.
|
|
10
|
-
- **Batched writes:** Sends statement batches to remote libSQL servers in a single request and redacts auth tokens and custom headers from error diagnostics.
|
|
11
|
-
|
|
12
|
-
For operator setup, see [Turso and libSQL](/storage#turso-and-libsql). For sharing Intercom across a team while keeping personal sessions local, see [Team and CI setup](/guides/team-setup). For all five SDK storage backends and `createAgentSessionRuntime()`, see [SDK storage backends](/sdk/storage).
|
|
13
|
-
|
|
14
|
-
## Installation
|
|
15
|
-
|
|
16
|
-
Install according to how you use Atomic:
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
# CLI (install in user scope without -l; Atomic searches user-scope packages for adapters)
|
|
20
|
-
atomic install npm:@bastani/atomic-storage-libsql
|
|
21
|
-
|
|
22
|
-
# TypeScript SDK application
|
|
23
|
-
npm install @bastani/atomic-storage-libsql @bastani/atomic
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## SDK quick start
|
|
27
|
-
|
|
28
|
-
```typescript
|
|
29
|
-
import { createAgentSession } from "@bastani/atomic";
|
|
30
|
-
import { openLibsqlDatabase } from "@bastani/atomic-storage-libsql";
|
|
31
|
-
|
|
32
|
-
const database = await openLibsqlDatabase({
|
|
33
|
-
url: "libsql://<db>.turso.io",
|
|
34
|
-
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
const { session } = await createAgentSession({
|
|
39
|
-
sessionStore: { kind: "database", database, prefix: "app_" },
|
|
40
|
-
});
|
|
41
|
-
try {
|
|
42
|
-
await session.prompt("Summarize the failing tests in this repository");
|
|
43
|
-
} finally {
|
|
44
|
-
await session.dispose();
|
|
45
|
-
}
|
|
46
|
-
} finally {
|
|
47
|
-
await database.close();
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
Pass the returned `SqliteDatabase` to `createAgentSession({ sessionStore: { kind: "database", database, prefix? } })` or `SqlSessionStore.open(database, { prefix? })`. Atomic leaves caller-owned database handles open on `session.dispose()`, so always close `database` in your outer `finally`.
|
|
52
|
-
|
|
53
|
-
## `LibsqlDatabaseOptions`
|
|
54
|
-
|
|
55
|
-
| Option | Type | Required | Description |
|
|
56
|
-
| --- | --- | --- | --- |
|
|
57
|
-
| `url` | `string` | Yes | A `libsql://`, `https://`, `http://`, `wss://`, `ws://`, or `file:` URL. (`atomic storage join` and `atomic team join` accept `libsql://`, `https://`, `http://`, `wss://`, `ws://`, or an absolute `file:` URL without embedded credentials.) |
|
|
58
|
-
| `authToken` | `string` | For remote databases | Database auth token. In CLI settings, pass through `secrets` (`{ "file": ... }` or `{ "env": ... }`) so it never lands in `settings.json`. |
|
|
59
|
-
| `namespace` | `string` | No | Self-hosted `sqld` namespace (`sqld --enable-namespaces`), sent as the `x-namespace` header. Requires a `libsql:`, `https:`, or `http:` URL. |
|
|
60
|
-
| `headers` | `Readonly<Record<string, string>>` | No | Extra request headers sent on every HTTP/libSQL request and redacted from diagnostics. Requires a `libsql:`, `https:`, or `http:` URL. |
|
|
61
|
-
| `keepAliveMs` | `number` | No | How long, in milliseconds, an unused HTTP connection stays open for reuse on `libsql:`, `https:` and `http:` URLs. A positive integer. Unset, Atomic closes an unused connection after about 4 seconds. Leave it unset for Turso, which closes unused connections after 5 seconds. Ignored for `ws:` and `wss:` URLs. |
|
|
62
|
-
| `concurrency` | `number` | No | On a libSQL server, the most reads one connection runs at the same time. A positive integer, default `20` (`DEFAULT_CONCURRENCY`). Writes still run one at a time. No effect on `file:` URLs. |
|
|
63
|
-
|
|
64
|
-
## Exported API
|
|
65
|
-
|
|
66
|
-
- `openLibsqlDatabase(options: LibsqlDatabaseOptions): Promise<SqliteDatabase>` — opens a libSQL/Turso-backed `SqliteDatabase`.
|
|
67
|
-
- Type: `LibsqlDatabaseOptions`.
|
|
68
|
-
- Default export: `StorageAdapterModule` (`{ atomicStorageAdapter: 1, openDatabase }`) used by `atomic` CLI settings, `{ kind: "adapter" }` selections, and `teamProfileSelection()`.
|
|
69
|
-
|
|
70
|
-
## Concurrency, WAL, and `sqld` retries
|
|
71
|
-
|
|
72
|
-
- **Local `file:` databases:** On first open, the adapter enables write-ahead logging (WAL, creating `-wal` and `-shm` sidecar files) with a 5-second busy timeout matching Atomic's built-in SQLite stores. Single statements, single-statement `exec`, batches, and transaction starts retry when another connection commits while waiting; multi-statement `exec` calls are not retried. Open a local file through only one SQLite library at a time so concurrent readers do not see stale WAL state.
|
|
73
|
-
- **Remote `sqld` servers:** When `sqld` hits a WAL checkpoint, it returns `SQLITE_BUSY` immediately without running the write. The adapter retries single statements, single-statement `exec`, batches, and transaction starts with jittered exponential backoff for up to 5 seconds within a 10-second wall-clock ceiling (one 5-second lock timeout plus one 5-second checkpoint window). For self-hosted `sqld`, start with `--checkpoint-interval-s 60` (or `SQLD_CHECKPOINT_INTERVAL_S=60`).
|
|
74
|
-
- **Server transactions:** A transaction sends its first reads with its `BEGIN` and its last writes with its `COMMIT`, so saving entries to a session takes 2 requests. The commit runs only if every write before it succeeded; otherwise nothing commits.
|
|
75
|
-
- **Readers:** `openReader()` returns a handle with its own client, for local files and servers. Its reads do not wait behind the main handle's calls. Closing the database closes its readers.
|
|
76
|
-
- **Throughput:** On a server, a connection runs up to `concurrency` reads at the same time. Writes run one at a time, in call order, and a libSQL database has one writer at a time. See [Tuning for many concurrent agents](/storage#tuning-libsql-and-turso).
|
|
77
|
-
|
|
78
|
-
## CLI configuration
|
|
79
|
-
|
|
80
|
-
Join a shared database for both sessions and Intercom:
|
|
81
|
-
|
|
82
|
-
```bash
|
|
83
|
-
turso db tokens create <db> > ~/turso-token
|
|
84
|
-
chmod 600 ~/turso-token
|
|
85
|
-
atomic storage join libsql://<db>.turso.io --token-file ~/turso-token
|
|
86
|
-
atomic intercom restart
|
|
87
|
-
atomic storage status
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
To share Intercom across machines while keeping personal sessions in local SQLite, run `atomic team join <url> --token-file ~/turso-token` instead (see [Team and CI setup](/guides/team-setup)). Run `atomic storage migrate` when upgrading schemas on a shared database.
|
|
91
|
-
|
|
92
|
-
## Related docs
|
|
93
|
-
|
|
94
|
-
- [Turso and libSQL operator guide](/storage#turso-and-libsql): CLI setup, manual `settings.json`, size limits, and storage errors.
|
|
95
|
-
- [Team and CI setup](/guides/team-setup): shared team Intercom, CI runner profiles, and `teamProfileSelection()`.
|
|
96
|
-
- [SDK storage backends](/sdk/storage): complete `createAgentSession()`, `createAgentSessionRuntime()`, and error-handling recipes.
|
|
97
|
-
- [Standalone libraries](/libraries): all published `@bastani/atomic-*` packages.
|