@bastani/atomic 0.10.11-alpha.1 → 0.10.11-alpha.3
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 +155 -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 +9 -9
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +8 -8
- package/dist/_shared/mode-shared-2QJSCUM6.js +9 -9
- 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} +14 -2
- package/dist/_shared/{p1b-elig-ENCUPKKJ.js.map → p1b-elig-TVB5CBLL.js.map} +1 -1
- package/dist/_shared/runtime-O4KCSG4C.js +5 -5
- package/dist/_shared/{sdk-AVFII7NK.js → sdk-B5LEWGGI.js} +2633 -488
- package/dist/_shared/sdk-B5LEWGGI.js.map +1 -0
- package/dist/_shared/session-data-AHTU7IS6.js +3 -3
- package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
- package/dist/_shared/settings-startup-8-DNZ2RIHM.js +1 -1
- package/dist/_shared/{settings-startup-4QCVCI53.js → settings-startup-HXQLSUWM.js} +8 -2
- package/dist/_shared/settings-startup-HXQLSUWM.js.map +1 -0
- package/dist/_shared/{startup-0-0-57KF6LZH.js → startup-0-0-EZUKEP4Q.js} +436 -51
- package/dist/_shared/startup-0-0-EZUKEP4Q.js.map +1 -0
- package/dist/_shared/{startup-0-1-GIY75K46.js → startup-0-1-RTOHJFDJ.js} +240 -279
- package/dist/_shared/startup-0-1-RTOHJFDJ.js.map +1 -0
- package/dist/_shared/{startup-0-2-27OWFHV6.js → startup-0-2-5QHPCEON.js} +254 -46
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -0
- package/dist/_shared/{startup-0-3-T4DVFYWX.js → startup-0-3-4ZYBYQNM.js} +273 -14
- package/dist/_shared/startup-0-3-4ZYBYQNM.js.map +1 -0
- package/dist/_shared/startup-0-4-ZMJV547D.js +14 -9
- package/dist/_shared/startup-0-4-ZMJV547D.js.map +1 -1
- package/dist/_shared/startup-0-5-YDW47QX6.js +10 -10
- package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -1
- package/dist/_shared/startup-10-0-TDQNBDDL.js +9 -9
- package/dist/_shared/startup-12-0-55AAXBJZ.js +3 -3
- package/dist/_shared/startup-14-0-MLX36RBG.js +6 -7
- package/dist/_shared/startup-14-0-MLX36RBG.js.map +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +7 -7
- package/dist/_shared/startup-15-1-4S7FLMNG.js +22 -30
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +455 -102
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/{startup-8-1-X32CYSXB.js → startup-8-1-LZFXSD3Z.js} +162 -1184
- package/dist/_shared/startup-8-1-LZFXSD3Z.js.map +1 -0
- package/dist/_shared/storage-command-7MGXLJGZ.js +189 -36
- 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 +3 -3
- package/dist/builtin/intercom/CHANGELOG.md +34 -0
- package/dist/builtin/intercom/README.md +2 -2
- package/dist/builtin/intercom/broker/broker.bundle.mjs +1091 -344
- package/dist/builtin/intercom/broker/database-wake-up-bus.ts +243 -64
- package/dist/builtin/intercom/broker/multinode-router.ts +154 -22
- package/dist/builtin/intercom/broker/multinode-state-store.ts +30 -3
- package/dist/builtin/intercom/broker/open-broker-state.ts +14 -0
- package/dist/builtin/intercom/broker/sql-add-column.ts +29 -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 +208 -101
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +516 -102
- 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 +24 -7
- package/dist/builtin/intercom/broker/sql-retention.ts +141 -0
- package/dist/builtin/intercom/broker/sql-schema.ts +199 -27
- 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 +2 -3
- 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/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 +6 -6
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +4 -4
- package/dist/cli/blueprint-command.impl.js +3 -3
- package/dist/cli/blueprint-command.js +3 -3
- package/dist/cli/intercom-command.code.js +4 -4
- 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 +2 -2
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +2 -2
- 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 +20 -114
- 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 +2 -2
- 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.code.js +1 -1
- 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 +3 -3
- 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 +8 -0
- 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 +4 -4
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +27 -15
- package/dist/core/session-manager-core.js.map +1 -1
- 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 +3 -3
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-open-markers.js +3 -0
- package/dist/core/session-open-markers.js.map +1 -0
- 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/added-exports.js +3 -0
- package/dist/core/storage/added-exports.js.map +1 -1
- 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 +56 -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 +11 -0
- package/dist/core/storage/fenced-paths.js +11 -0
- 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 +4 -3
- 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 +81 -8
- package/dist/core/storage/migrations.js +386 -47
- 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 +36 -12
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.js +135 -3
- 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 +14 -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 +82 -5
- package/dist/core/storage/schema-catalog.js +244 -34
- 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 +9 -8
- package/dist/core/storage/session/branch-fork-source.code.js.map +1 -1
- 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 +4 -4
- 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/errors.js +1 -1
- package/dist/core/storage/session/expanded-child-details.code.js +3 -3
- 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 +118 -0
- 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-schema.js +53 -0
- package/dist/core/storage/session/fork-schema.js.map +1 -0
- package/dist/core/storage/session/fork-segments.d.ts +58 -0
- package/dist/core/storage/session/fork-staging.code.js +5 -8
- 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 +61 -0
- package/dist/core/storage/session/fork-sweep.js.map +1 -0
- package/dist/core/storage/session/fork-window.code.js +4 -4
- 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-store.d.ts +42 -2
- 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 +4 -4
- 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.code.js +1 -1
- 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 +43 -4
- 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 +4 -4
- 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 +394 -20
- package/dist/core/storage/session/sql-session-store.impl.js +4 -4
- package/dist/core/storage/session/sql-session-store.js +4 -4
- 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/session/types.d.ts +22 -0
- package/dist/core/storage/sqlite-facade.d.ts +23 -2
- package/dist/core/storage/sqlite-facade.js +34 -0
- package/dist/core/storage/sqlite-facade.js.map +1 -1
- 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 +4 -4
- 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 +5 -5
- 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-session.d.ts +2 -0
- 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 +71 -3
- package/dist/core/worktree-snapshot/blob-store.js +575 -67
- package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
- package/dist/core/worktree-snapshot/errors.code.js +3 -3
- 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 +162 -0
- package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -0
- 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 +2 -2
- 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 +8 -8
- package/dist/main-first-time-setup.code.js +2 -2
- 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 +3 -3
- 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 +7 -7
- 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 -3
- 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 -6
- 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 +3 -3
- 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 +1421 -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 +31 -42
- 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} +73 -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 +333 -956
- 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/sdk-AVFII7NK.js.map +0 -1
- package/dist/_shared/settings-startup-4QCVCI53.js.map +0 -1
- package/dist/_shared/startup-0-0-57KF6LZH.js.map +0 -1
- package/dist/_shared/startup-0-1-GIY75K46.js.map +0 -1
- package/dist/_shared/startup-0-2-27OWFHV6.js.map +0 -1
- package/dist/_shared/startup-0-3-T4DVFYWX.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
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "PostgreSQL setup"
|
|
3
|
+
sidebarTitle: "Setup"
|
|
4
|
+
description: "Share Atomic's sessions and Intercom across machines, a team, or CI with one PostgreSQL database: set up roles, join machines, connect through TLS, proxies, and poolers, size connections, and fix common errors."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Use PostgreSQL when more than one machine should see the same sessions and Intercom messages: a team, a CI fleet, or one person on several computers. Every machine that joins the database sees the same sessions, and its agents can message agents on the other machines. For one person on one machine, the default [local SQLite](/storage/sqlite) store needs no setup and is the better choice.
|
|
8
|
+
|
|
9
|
+
This page is for the person who sets up the database and the people who connect their machines to it. It covers:
|
|
10
|
+
|
|
11
|
+
- creating the database and its roles;
|
|
12
|
+
- joining a machine;
|
|
13
|
+
- TLS, HTTP proxies, poolers, and cloud identities;
|
|
14
|
+
- how many connections Atomic opens, and how to size them for many agents;
|
|
15
|
+
- fixes for common errors.
|
|
16
|
+
|
|
17
|
+
Requirements:
|
|
18
|
+
|
|
19
|
+
- **PostgreSQL 16 or newer.** Atomic keeps sessions only on PostgreSQL 16 or newer.
|
|
20
|
+
- **The PostgreSQL adapter, `@bastani/atomic-storage-postgres`,** installed on every machine that connects. [Join a machine](#join-a-machine) shows how.
|
|
21
|
+
|
|
22
|
+
Self-hosted PostgreSQL works, and so do managed services: Azure Database for PostgreSQL Flexible Server, Azure HorizonDB, Amazon RDS and Aurora PostgreSQL, Google Cloud SQL, AlloyDB, Neon, and Supabase.
|
|
23
|
+
|
|
24
|
+
A new PostgreSQL server allows 100 connections, and each Atomic process can open up to 10, or 11 for an Intercom broker. If you will run more than a few Atomic processes, read [Tuning for many concurrent agents](#tuning-for-many-concurrent-agents) before you start. When your agents need more connections than the server allows, put [PgBouncer](/storage/postgres/pgbouncer) in front of it. To tune the server itself, see [Server tuning](/storage/postgres/tuning).
|
|
25
|
+
|
|
26
|
+
## Set up the database
|
|
27
|
+
|
|
28
|
+
Atomic keeps its tables in their own schema, `atomic`, rather than `public`. A shared deployment uses two roles:
|
|
29
|
+
|
|
30
|
+
- **The owner role** owns the database and the `atomic` schema. It creates and upgrades Atomic's tables with `atomic storage migrate`.
|
|
31
|
+
- **The runtime role** is the role every machine connects as. It reads and writes rows, and cannot change the schema.
|
|
32
|
+
|
|
33
|
+
With two roles, a machine that connects as the runtime role can never change or drop Atomic's tables. Every machine can use the same runtime role, or you can create one login role per person with the same grants as `atomic_runtime`. For one person testing on one machine, a single role that owns the database is enough. Atomic then creates its tables the first time it opens the database.
|
|
34
|
+
|
|
35
|
+
Run `atomic storage migrate` once before you start many agents on a new database. Agents that then start together find every table already there and run no setup. Without it, the first agents to open the empty database set it up between them: for each table, one agent creates it while the others wait for it without holding a lock or a connection. At 80 ms from the server, behind PgBouncer, 25 agents that each opened a session store and an Intercom broker on an empty database at once took about 15 seconds to open, and 100 took about 24 seconds. With the schema in place, the same 25 agents opened in about 1.3 seconds.
|
|
36
|
+
|
|
37
|
+
1. **Create the roles and the database.** Connect as the server's administrator, a superuser or the managed service's administrator role, and run:
|
|
38
|
+
|
|
39
|
+
```sql
|
|
40
|
+
CREATE ROLE atomic_owner LOGIN PASSWORD '<owner password>';
|
|
41
|
+
CREATE ROLE atomic_runtime LOGIN PASSWORD '<runtime password>';
|
|
42
|
+
-- On a managed service whose administrator is not a superuser, such as Azure, RDS, or Cloud SQL:
|
|
43
|
+
-- GRANT atomic_owner TO <administrator>;
|
|
44
|
+
CREATE DATABASE atomic OWNER atomic_owner;
|
|
45
|
+
REVOKE ALL ON DATABASE atomic FROM PUBLIC;
|
|
46
|
+
GRANT CONNECT ON DATABASE atomic TO atomic_owner, atomic_runtime;
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Owning the database lets `atomic_owner` create the `atomic` schema. On a managed service whose administrator is not a superuser, remove the `--` before the `GRANT` line, so the administrator may create a database owned by `atomic_owner`.
|
|
50
|
+
|
|
51
|
+
2. **Allow the machines to connect, over TLS.** On a self-hosted server, turn TLS on first, as [TLS](#tls) explains, because Atomic checks the server's certificate by default. Then `pg_hba.conf` decides who may log in. Allow the agent machines as the runtime role, and the machine you run `atomic storage migrate` on as the owner role. Then reload the server, for example with `SELECT pg_reload_conf();`:
|
|
52
|
+
|
|
53
|
+
```text
|
|
54
|
+
# TYPE DATABASE USER ADDRESS METHOD
|
|
55
|
+
hostssl atomic atomic_runtime 10.0.2.0/24 scram-sha-256
|
|
56
|
+
hostssl atomic atomic_owner 10.0.3.10/32 scram-sha-256
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Managed services use firewall rules instead, and have TLS on already.
|
|
60
|
+
|
|
61
|
+
3. **Create Atomic's tables.** On a machine with Atomic installed, install the PostgreSQL adapter, save the owner's password in a file that only you can read, and run `atomic storage migrate` as the owner role. Connect to PostgreSQL directly, not through a pooler:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
atomic install npm:@bastani/atomic-storage-postgres
|
|
65
|
+
(umask 077; printf 'Owner password: '; read -rs password; printf '\n'; printf '%s' "$password" > ~/atomic-owner-password)
|
|
66
|
+
atomic storage migrate --db 'postgresql://atomic_owner@db.example.com:5432/atomic' --password-file ~/atomic-owner-password
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
It prints what it set up:
|
|
70
|
+
|
|
71
|
+
```text
|
|
72
|
+
Atomic's tables in PostgreSQL postgresql://db.example.com:5432/atomic via @bastani/atomic-storage-postgres are set up for this version: sessions and Intercom.
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`--password-file`, `--token-file`, `--auth`, and `--prefix` only work together with `--db`. Without `--db`, `atomic storage migrate` upgrades the database this machine's `storage` setting names.
|
|
76
|
+
|
|
77
|
+
4. **Give the runtime role its privileges.** Connect to the `atomic` database as `atomic_owner` and run:
|
|
78
|
+
|
|
79
|
+
```sql
|
|
80
|
+
GRANT USAGE ON SCHEMA atomic TO atomic_runtime;
|
|
81
|
+
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA atomic TO atomic_runtime;
|
|
82
|
+
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA atomic TO atomic_runtime;
|
|
83
|
+
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA atomic TO atomic_runtime;
|
|
84
|
+
ALTER DEFAULT PRIVILEGES FOR ROLE atomic_owner IN SCHEMA atomic GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO atomic_runtime;
|
|
85
|
+
ALTER DEFAULT PRIVILEGES FOR ROLE atomic_owner IN SCHEMA atomic GRANT USAGE, SELECT ON SEQUENCES TO atomic_runtime;
|
|
86
|
+
ALTER DEFAULT PRIVILEGES FOR ROLE atomic_owner IN SCHEMA atomic GRANT EXECUTE ON FUNCTIONS TO atomic_runtime;
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
These are all the privileges the runtime role needs. The `ALTER DEFAULT PRIVILEGES` statements cover tables that later Atomic upgrades add, so you run them once. Intercom's notifications and locks need no extra grants.
|
|
90
|
+
|
|
91
|
+
5. **Join each machine as the runtime role.** See [Join a machine](#join-a-machine). If you will put PgBouncer in front of the server, set it up first and join with its address, as [Configure Atomic](/storage/postgres/pgbouncer#configure-atomic) shows.
|
|
92
|
+
|
|
93
|
+
Notes for managed services:
|
|
94
|
+
|
|
95
|
+
- **Azure Database for PostgreSQL Flexible Server.** Run the statements as the server administrator, a member of `azure_pg_admin`. If you set the `schema` option to `public`, also run `GRANT CREATE ON SCHEMA public TO atomic_owner;`.
|
|
96
|
+
- **Google Cloud SQL.** Run the statements as `postgres` or another member of `cloudsqlsuperuser`.
|
|
97
|
+
|
|
98
|
+
If the runtime role lacks a privilege, or the tables are older than the Atomic release that opens them, opening the database fails with `StorageConfigError` and reason `missing-privilege`. The error names the `GRANT` statement or the `atomic storage migrate` command to run.
|
|
99
|
+
|
|
100
|
+
### After each Atomic upgrade
|
|
101
|
+
|
|
102
|
+
Run `atomic storage migrate` as the owner role once after you upgrade Atomic, before you start many agents. The runtime role cannot change the schema. If an upgrade needs new tables, machines that connect as the runtime role fail with `missing-privilege` until you run it. Otherwise they keep working, but without the improvements only the owner can apply:
|
|
103
|
+
|
|
104
|
+
- Saving new entries to a session waits for the server once instead of twice, so saves are faster.
|
|
105
|
+
- The busy sessions and Intercom tables leave room on each page for updates, which keeps them faster to update and smaller. See [Server tuning](/storage/postgres/tuning#updates-that-stay-on-their-page).
|
|
106
|
+
- Autovacuum cleans the busy tables sooner, and large values use the faster `lz4` compression where the server supports it. See [Server tuning](/storage/postgres/tuning).
|
|
107
|
+
- On Azure, session history search gets its index once the `pg_trgm` extension is allowed. See [Azure](#azure).
|
|
108
|
+
|
|
109
|
+
Running it on a database that is already current changes nothing.
|
|
110
|
+
|
|
111
|
+
### Share one database between teams
|
|
112
|
+
|
|
113
|
+
Give each team or project its own database, or its own `prefix`. A prefix starts the name of every table Atomic creates, so several groups can use one database without seeing each other's sessions. There is no prefix by default. Pass the same `--prefix` to `atomic storage migrate` and to every `atomic storage join` of that group. A machine with another prefix sees none of the group's sessions.
|
|
114
|
+
|
|
115
|
+
On PostgreSQL, a prefix is at most 24 lowercase ASCII characters. A longer prefix fails with `StoragePrefixError` and reason `too-long`. Uppercase letters fail with reason `uppercase`.
|
|
116
|
+
|
|
117
|
+
### Upgrading from tables in `public`
|
|
118
|
+
|
|
119
|
+
Older releases created Atomic's tables in the `public` schema. Atomic keeps using those tables until you move them:
|
|
120
|
+
|
|
121
|
+
1. Upgrade Atomic on every machine.
|
|
122
|
+
2. Run `atomic storage migrate` once, as the role that owns the tables in `public`. It moves every Atomic table to the `atomic` schema in one transaction.
|
|
123
|
+
3. Give the runtime role its privileges on `atomic`, as in step 4 of [Set up the database](#set-up-the-database).
|
|
124
|
+
4. Restart every Atomic process that opened the database before the move.
|
|
125
|
+
|
|
126
|
+
A process that still writes to `public` after the move is refused, so no data lands in the wrong schema. If an older process created a table in `public` after the move anyway, the next `atomic storage migrate` names it and fails rather than lose it.
|
|
127
|
+
|
|
128
|
+
## Join a machine
|
|
129
|
+
|
|
130
|
+
Joining points a machine's Atomic at the shared database. Run these steps on every machine, as the user who runs Atomic:
|
|
131
|
+
|
|
132
|
+
1. **Install the PostgreSQL adapter.** It is a separate package, so you install it once per machine.
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
atomic install npm:@bastani/atomic-storage-postgres
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
2. **Save the runtime role's password in a file** that only you can read. This command asks for the password, so it stays out of your shell history:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
(umask 077; printf 'Runtime password: '; read -rs password; printf '\n'; printf '%s' "$password" > ~/atomic-db-password)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
3. **Join the database.**
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
atomic storage join 'postgresql://atomic_runtime@db.example.com:5432/atomic' --password-file ~/atomic-db-password
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
It prints what it did:
|
|
151
|
+
|
|
152
|
+
```text
|
|
153
|
+
Connected to postgresql://atomic_runtime@db.example.com:5432/atomic.
|
|
154
|
+
Stored the password in /home/me/.atomic/agent/storage-token.28ab7041-05e2-4ad5-80af-854329035d8c (mode 600).
|
|
155
|
+
Set `storage` in /home/me/.atomic/agent/settings.json; other settings are unchanged.
|
|
156
|
+
Run `atomic storage status` to check each domain.
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
4. **Restart Intercom and check the result.** The Intercom broker is the background process on each machine that passes messages between agents. Restart it so it uses the shared database. The command is safe when no broker is running. Sessions that are already open keep their old store until you restart them.
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
atomic intercom restart
|
|
163
|
+
atomic storage status
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`atomic storage status` exits with code `0` when everything answered, and prints something like this:
|
|
167
|
+
|
|
168
|
+
```text
|
|
169
|
+
Sessions: PostgreSQL postgresql://db.example.com:5432/atomic via @bastani/atomic-storage-postgres
|
|
170
|
+
source: global settings: storage
|
|
171
|
+
adapter: loaded (from /home/me/.atomic/agent/npm/node_modules/@bastani/atomic-storage-postgres/postgres.js)
|
|
172
|
+
connection: ok (postgres postgresql://db.example.com:5432/atomic answered in 20 ms, PostgreSQL 17.12; wake-ups: LISTEN/NOTIFY)
|
|
173
|
+
|
|
174
|
+
Intercom: PostgreSQL postgresql://db.example.com:5432/atomic via @bastani/atomic-storage-postgres
|
|
175
|
+
source: global settings: storage
|
|
176
|
+
adapter: loaded (from /home/me/.atomic/agent/npm/node_modules/@bastani/atomic-storage-postgres/postgres.js)
|
|
177
|
+
connection: ok (postgres postgresql://db.example.com:5432/atomic answered in 11 ms, PostgreSQL 17.12; wake-ups: LISTEN/NOTIFY)
|
|
178
|
+
multi-node: on
|
|
179
|
+
brokers: 0 live in the database
|
|
180
|
+
|
|
181
|
+
Intercom broker: not running (the next session that uses Intercom starts one with the selection above)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
`multi-node: on` means agents on this machine can message agents on the other machines that joined. A broker starts with the first session that uses Intercom, so right after a restart `brokers` can show `0` and the broker `not running`. Once sessions run on the joined machines, `brokers` counts their brokers.
|
|
185
|
+
|
|
186
|
+
5. **Delete your password file**, `~/atomic-db-password`. `atomic storage join` keeps its own copy.
|
|
187
|
+
|
|
188
|
+
`atomic storage join` takes a `postgres://` or `postgresql://` URL that names the user and never the password. Pass exactly one way to log in:
|
|
189
|
+
|
|
190
|
+
| Option | What Atomic does |
|
|
191
|
+
| --- | --- |
|
|
192
|
+
| `--password-file <path>` | Copies the password into a private file in the agent directory, `~/.atomic/agent/storage-token.<id>`, readable only by you. You can delete your own file afterwards. |
|
|
193
|
+
| `--token-file <path>` | Remembers the path and reads the file again for every new connection. Use it when another program, such as a Vault agent, keeps a short-lived password in that file. Atomic removes one trailing line break, so write no other trailing spaces or blank lines. |
|
|
194
|
+
| `--auth azure`, `--auth aws`, or `--auth gcp` | Logs in with the machine's cloud identity. See [Cloud identities](#cloud-identities). |
|
|
195
|
+
|
|
196
|
+
`atomic storage join` checks the URL, the adapter, and the password, and runs `SELECT 1` on the database, within 15 seconds. If any check fails, it changes nothing. Then it writes only the `storage` setting in `~/.atomic/agent/settings.json`, and replaces any `storage` value that was there. Save the old value first if you still need it. The setting looks like this:
|
|
197
|
+
|
|
198
|
+
```json
|
|
199
|
+
{
|
|
200
|
+
"storage": {
|
|
201
|
+
"adapter": "@bastani/atomic-storage-postgres",
|
|
202
|
+
"options": { "url": "postgresql://atomic_runtime@db.example.com:5432/atomic" },
|
|
203
|
+
"secrets": { "password": { "file": "agent/storage-token.28ab7041-05e2-4ad5-80af-854329035d8c" } }
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`atomic storage join` created the password file and chose its name. `storage-token.28ab7041-05e2-4ad5-80af-854329035d8c` stands for that name here and in the examples below, so keep the name your machine has. The path is relative to the [storage home](/storage#storage-home), `~/.atomic`.
|
|
209
|
+
|
|
210
|
+
You can write this setting yourself instead, or pass the same object in `ATOMIC_STORAGE` or `--storage`. Give the password in `secrets.password`, as `{ "file": "<path>" }` or `{ "env": "<variable>" }`. Atomic reads it again for every new connection, so a rotated password takes effect without a restart. A password in `options` is ignored, and a missing `secrets.password` fails with `StorageConfigError` and reason `secret-missing`.
|
|
211
|
+
|
|
212
|
+
### Connection options
|
|
213
|
+
|
|
214
|
+
Put these in `options`. The defaults suit a few machines. [Tuning for many concurrent agents](#tuning-for-many-concurrent-agents) explains when to change them.
|
|
215
|
+
|
|
216
|
+
| Option | Default | What it does |
|
|
217
|
+
| --- | --- | --- |
|
|
218
|
+
| `url` | Required | The `postgres://` or `postgresql://` URL, with the user name and no password. |
|
|
219
|
+
| `auth` | `"password"` | `"azure-entra"`, `"aws-iam"`, or `"gcp-iam"` to log in with a [cloud identity](#cloud-identities). |
|
|
220
|
+
| `maxConnections` | `8` | The most connections one Atomic process opens to this database for its work. A positive whole number. |
|
|
221
|
+
| `readerMaxConnections` | `2` | The most extra connections one process opens only for reads, so reads never wait behind writes. At most `maxConnections`. `0` turns the extra connections off. |
|
|
222
|
+
| `statementTimeoutMs` | `30000` | How long one statement may run before the server cancels it, in milliseconds. If the server stops answering, Atomic drops the connection 5 seconds later. |
|
|
223
|
+
| `connectTimeoutMs` | `10000` | How long opening a connection, or waiting for a free one, may take, in milliseconds. |
|
|
224
|
+
| `idleTimeoutMs` | `300000` | How long a process keeps its last idle connection open, in milliseconds. Extra connections opened for a burst close after 10 seconds idle. |
|
|
225
|
+
| `keepAliveIdleMs` | `60000` | How long a connection sits unused before Atomic sends TCP keepalive probes on it, in milliseconds. |
|
|
226
|
+
| `maxPreparedStatements` | `256`, or `0` behind a pooler | How many queries each connection keeps prepared, so the server plans each one once. `0` turns this off. Atomic turns it off by itself behind a pooler, unless it finds a PgBouncer that supports it. See [Prepared statements](/storage/postgres/pgbouncer#how-atomic-works-with-pgbouncer). |
|
|
227
|
+
| `listenUrl` | Same as `url` | The server's own address, for [wake-ups](#wake-ups): the instant notice of new Intercom messages. Set it when `url` points at a pooler, which cannot pass wake-ups. Follows the same rules as `url`. |
|
|
228
|
+
| `schema` | `"atomic"` | The schema Atomic's tables live in. Lowercase letters, digits, and `_`, starting with a letter or `_`, at most 63 characters. To migrate a custom schema, put it in the `storage` setting and run `atomic storage migrate` without `--db`. |
|
|
229
|
+
| `proxy` | From the environment | An `http://` or `https://` proxy for every connection, or `"none"` to ignore proxy variables. See [Through an HTTP proxy](#through-an-http-proxy). |
|
|
230
|
+
|
|
231
|
+
For a Node.js or TypeScript app built on the SDK, install `@bastani/atomic-storage-postgres` with `npm install` and call `openPostgresDatabase` with the same options. See [`@bastani/atomic-storage-postgres`](/libraries/storage-postgres) and [SDK session storage](/sdk/storage).
|
|
232
|
+
|
|
233
|
+
## TLS
|
|
234
|
+
|
|
235
|
+
Atomic encrypts every connection to a remote server and checks both the server's certificate and its host name, as `sslmode=verify-full` does. Connections to `localhost`, a loopback address, or a Unix socket use no TLS unless the URL sets `sslmode`. If the URL names no host, Atomic uses `PGHOST`.
|
|
236
|
+
|
|
237
|
+
To change this, add `sslmode` to the URL, in lowercase:
|
|
238
|
+
|
|
239
|
+
| `sslmode` | Encrypts | Checks the certificate | Checks the host name |
|
|
240
|
+
| --- | --- | --- | --- |
|
|
241
|
+
| `verify-full`, the default | Yes | Yes | Yes |
|
|
242
|
+
| `verify-ca` | Yes | Yes | No |
|
|
243
|
+
| `require` with `sslrootcert` | Yes | Yes | No |
|
|
244
|
+
| `require` without `sslrootcert` | Yes | Yes | Yes |
|
|
245
|
+
| `prefer` or `allow` | Yes | No | No |
|
|
246
|
+
| `disable` | No | No | No |
|
|
247
|
+
|
|
248
|
+
`require` without `sslrootcert` checks more than the PostgreSQL command-line tools do. An unknown `sslmode`, or a TLS parameter written in uppercase, fails with `StorageConfigError`.
|
|
249
|
+
|
|
250
|
+
Where to find the certificate authority, the certificate that signed the server's certificate:
|
|
251
|
+
|
|
252
|
+
- **Self-hosted PostgreSQL.** Turn TLS on in `postgresql.conf` with `ssl = on`, `ssl_cert_file`, and `ssl_key_file`, using a certificate whose name matches the host in `url`. If your own certificate authority signed it, add `?sslrootcert=/path/to/root.crt` to the URL. The self-signed certificate that some Linux packages install, such as Debian's `snakeoil` certificate, does not pass the default check.
|
|
253
|
+
- **Azure Database for PostgreSQL, Azure HorizonDB, and Neon.** Their certificates are trusted by Node.js already. Add nothing.
|
|
254
|
+
- **Supabase.** Download the project's CA certificate from Project Settings > Database > SSL Configuration, and add `?sslrootcert=/path/to/supabase-ca.pem` to the URL.
|
|
255
|
+
- **Amazon RDS and Aurora.** Download your region's bundle from `https://truststore.pki.rds.amazonaws.com/<region>/<region>-bundle.pem`, and add `?sslrootcert=/path/to/bundle.pem`.
|
|
256
|
+
- **Google Cloud SQL.** Save the server's CA with `gcloud sql instances describe <instance> --format='value(serverCaCert.cert)'`. Over a private IP address, add `?sslmode=verify-ca&sslrootcert=/path/to/server-ca.pem`, because the certificate does not list private addresses.
|
|
257
|
+
|
|
258
|
+
## Through an HTTP proxy
|
|
259
|
+
|
|
260
|
+
Where outbound traffic must go through an HTTP proxy, Atomic tunnels every database connection through it with HTTP `CONNECT`. Allow `<database host>:5432`, or your server's port, on the proxy.
|
|
261
|
+
|
|
262
|
+
- **Which proxy.** Atomic reads `HTTPS_PROXY` or `https_proxy` first, then `ALL_PROXY` when it names an `http://` or `https://` proxy, then `HTTP_PROXY`. A user name and password in the proxy URL are sent to the proxy and hidden from logs and errors.
|
|
263
|
+
- **Hosts that skip the proxy.** `NO_PROXY` or `no_proxy` lists hosts to reach directly, such as `db.example.com`, `.example.com`, `*.example.com`, `host:port`, or `*`. `localhost`, loopback addresses, and Unix sockets never use the proxy.
|
|
264
|
+
- **One store only.** Set the `proxy` option to a proxy URL to use it for this database, or to `"none"` to ignore the proxy variables.
|
|
265
|
+
- **TLS stays end to end.** Atomic's TLS session runs inside the tunnel, so the proxy sees only encrypted traffic. With `verify-full`, the default, the certificate must match the database's host name. `verify-ca` protects against a proxy that intercepts traffic only when `sslrootcert` names a certificate authority used for nothing but your database servers.
|
|
266
|
+
|
|
267
|
+
If the proxy refuses the tunnel with `403` or `407`, opening fails at once with `StorageUnavailableError`. A refused or dropped connection, or a `502` or `503` answer, is retried like an unreachable server, with a warning that names the proxy and the reason.
|
|
268
|
+
|
|
269
|
+
## Connection budget
|
|
270
|
+
|
|
271
|
+
Connections are counted per process. What counts as one Atomic process:
|
|
272
|
+
|
|
273
|
+
- each `atomic` you start, interactive or with `-p`;
|
|
274
|
+
- each `atomic --mode rpc` child that a program starts;
|
|
275
|
+
- the Intercom broker: Atomic runs one Intercom broker per agent directory, usually one per machine or container.
|
|
276
|
+
|
|
277
|
+
Subagents run inside the process that launched them and share its connections, so they add none.
|
|
278
|
+
|
|
279
|
+
Each Atomic process shares one set of connections per database between everything it opens there: its sessions, its subagents' sessions, search, and Intercom. The set holds:
|
|
280
|
+
|
|
281
|
+
| Connections | How many | `application_name` in `pg_stat_activity` |
|
|
282
|
+
| --- | --- | --- |
|
|
283
|
+
| Main pool | Up to `maxConnections`, 8 by default | `atomic` |
|
|
284
|
+
| Read pool | Up to `readerMaxConnections`, 2 by default. Only reads use it | `atomic-reader` |
|
|
285
|
+
| Wake-up connection | 1, only in a process that listens for [wake-ups](#wake-ups), such as an Intercom broker | `atomic-listen` |
|
|
286
|
+
|
|
287
|
+
So a process opens at most `maxConnections` + `readerMaxConnections` connections, 10 with the defaults, and a process that listens, such as an Intercom broker, 1 more: 11.
|
|
288
|
+
|
|
289
|
+
Atomic opens connections only when it needs them, and closes them again. An extra connection opened for a burst closes after 10 seconds unused. The last connection of each pool stays open for `idleTimeoutMs`, 5 minutes by default, so the next call after a pause does not wait for a new connection. So between bursts, a process holds 1 main connection, 1 read connection if it read recently, and its wake-up connection if it listens. Open connections never keep a process from exiting.
|
|
290
|
+
|
|
291
|
+
Size the settings by how many processes you run:
|
|
292
|
+
|
|
293
|
+
- **A few long-lived processes**, such as one interactive session per machine. Keep the defaults.
|
|
294
|
+
- **Many processes, such as a swarm of agent runners.** Work out `maxConnections` with [Tuning for many concurrent agents](#tuning-for-many-concurrent-agents). If the processes often sit idle, set `idleTimeoutMs` between `10000` and `30000`, so idle processes give their connections back sooner.
|
|
295
|
+
- **More processes than the server can take.** Connect through [PgBouncer](/storage/postgres/pgbouncer) in transaction mode, and set `listenUrl` to the server's own address. Then only the wake-up connections go to the server directly.
|
|
296
|
+
|
|
297
|
+
## Connection poolers
|
|
298
|
+
|
|
299
|
+
A pooler lets many clients share a few server connections. Atomic works with poolers in transaction mode or session mode, never statement mode. That includes PgBouncer, Azure's built-in PgBouncer on port 6432, Supabase's Supavisor on port 6543, and Neon's `-pooler` host.
|
|
300
|
+
|
|
301
|
+
A pooler in transaction mode cannot pass notifications, so set `listenUrl` to the server's own address, such as port 5432 on Azure or Neon's host without `-pooler`. Without it, Intercom still works, by checking for new messages every half second. See [Wake-ups](#wake-ups).
|
|
302
|
+
|
|
303
|
+
To run your own PgBouncer, follow the [PgBouncer guide](/storage/postgres/pgbouncer). It has a complete configuration with TLS and SCRAM, how to size the pools, and how to check that it works.
|
|
304
|
+
|
|
305
|
+
## Wake-ups
|
|
306
|
+
|
|
307
|
+
When one machine sends an Intercom message, the receiving machine's broker learns about it at once through PostgreSQL's `LISTEN` and `NOTIFY` commands. Each process that listens, such as an Intercom broker, holds one wake-up connection per database.
|
|
308
|
+
|
|
309
|
+
While wake-ups work, each broker also checks for missed messages every 5 seconds. If the wake-up connection drops, or `url` points at a transaction pooler and `listenUrl` is not set, brokers check every half second instead, so no message is lost. Atomic checks the wake-up connection every 30 seconds and reconnects it. Behind a transaction pooler, it stops trying until the process restarts.
|
|
310
|
+
|
|
311
|
+
`atomic storage status` shows the state:
|
|
312
|
+
|
|
313
|
+
| Status line | Meaning |
|
|
314
|
+
| --- | --- |
|
|
315
|
+
| `wake-ups: LISTEN/NOTIFY` | Wake-ups work. |
|
|
316
|
+
| `wake-ups: connecting` | The wake-up connection is opening. |
|
|
317
|
+
| `wake-ups: polling only, notifications do not pass the URL's transaction pooler (set listenUrl to a direct endpoint)` | `url` points at a pooler. Set `listenUrl` to the server's own address. |
|
|
318
|
+
| `wake-ups: polling only, the listen connection failed` | The wake-up connection could not connect or log in. Check `listenUrl` and the server's connection limit. |
|
|
319
|
+
|
|
320
|
+
## Azure
|
|
321
|
+
|
|
322
|
+
**Azure Database for PostgreSQL Flexible Server:**
|
|
323
|
+
|
|
324
|
+
- Connect to `<server>.postgres.database.azure.com` on port 5432.
|
|
325
|
+
- On General Purpose and Memory Optimized tiers, you can turn on the built-in PgBouncer with the `pgbouncer.enabled` server parameter. It listens on port 6432. Point `url` at port 6432 and `listenUrl` at port 5432.
|
|
326
|
+
- Add `PG_TRGM` to the `azure.extensions` server parameter, then run `atomic storage migrate`, so Atomic can index session history search. Without it, search still works but reads sessions one page at a time, and `atomic storage migrate` tells you to run it again once the extension is allowed.
|
|
327
|
+
- Watch the connection limit. A Burstable B1ms server allows 50 connections and keeps 15 of them for administrators. With the defaults, one Atomic process can open 10, and an Intercom broker 11. Lower `maxConnections`, use PgBouncer, or pick a larger server. See [Connection budget](#connection-budget).
|
|
328
|
+
- Allow your machines' addresses in the firewall rules, or use private access.
|
|
329
|
+
|
|
330
|
+
**Azure HorizonDB (preview, PostgreSQL 17):**
|
|
331
|
+
|
|
332
|
+
- Connect to the cluster's read/write endpoint, `<cluster>.rw.<id>.<region>.horizondb.azure.com`, on port 5432. A read-only endpoint does not work, because Atomic writes on every connection. Wake-ups work on the read/write endpoint.
|
|
333
|
+
- Add `pg_trgm` to `azure.extensions` in the compute pool's parameter group, then run `atomic storage migrate`.
|
|
334
|
+
- Allow your machines' addresses in the firewall rules, or connect over a private endpoint.
|
|
335
|
+
|
|
336
|
+
Both services use certificates Node.js trusts, work with the roles from [Set up the database](#set-up-the-database), and support Microsoft Entra ID with `--auth azure`.
|
|
337
|
+
|
|
338
|
+
## Cloud identities
|
|
339
|
+
|
|
340
|
+
A machine on Azure, AWS, or Google Cloud can log in with its cloud identity instead of a password. Atomic asks the cloud for a short-lived token for each new connection and keeps it only in memory. Install the cloud provider's library first:
|
|
341
|
+
|
|
342
|
+
| `--auth` | `options.auth` | Install | Where the identity comes from |
|
|
343
|
+
| --- | --- | --- | --- |
|
|
344
|
+
| `azure` or `azure-entra` | `"azure-entra"` | `atomic install npm:@azure/identity` | `AZURE_*` variables, AKS workload identity, the managed identity of a VM, App Service, or Container App (`AZURE_CLIENT_ID` picks a user-assigned one), or `az login` |
|
|
345
|
+
| `aws` or `aws-iam` | `"aws-iam"` | `atomic install npm:@aws-sdk/rds-signer` | The default AWS credentials: `AWS_*` variables, profiles, IRSA, or the instance profile |
|
|
346
|
+
| `gcp` or `gcp-iam` | `"gcp-iam"` | `atomic install npm:google-auth-library` | Application Default Credentials: `GOOGLE_APPLICATION_CREDENTIALS`, the Compute Engine, GKE, or Cloud Run metadata server, or `gcloud auth application-default login` |
|
|
347
|
+
|
|
348
|
+
If the library is missing or cannot get a token, opening fails with `StorageConfigError` and reason `auth-unavailable`. Cloud tokens need TLS, so keep the default `sslmode`.
|
|
349
|
+
|
|
350
|
+
Then map the identity to a PostgreSQL role:
|
|
351
|
+
|
|
352
|
+
- **Azure, Flexible Server or HorizonDB.** Turn on Microsoft Entra authentication and add an Entra administrator. Connected to the `postgres` database as that administrator, run `SELECT * FROM pgaadauth_create_principal('<identity name>', false, false);` and grant the new role `CONNECT` on the Atomic database. Use the identity name as the user in the URL.
|
|
353
|
+
- **AWS.** Turn on IAM database authentication. Run `CREATE USER atomic; GRANT rds_iam TO atomic;`, and allow the IAM identity `rds-db:connect` on `arn:aws:rds-db:<region>:<account>:dbuser:<DbiResourceId>/atomic`.
|
|
354
|
+
- **Google Cloud.** Set `cloudsql.iam_authentication=on`, add the service account as an IAM database user, and grant it `roles/cloudsql.instanceUser`. Use the service account's email without `.gserviceaccount.com` as the user in the URL. Compute Engine VMs need the `cloud-platform` scope.
|
|
355
|
+
|
|
356
|
+
Give the mapped role the runtime privileges from [Set up the database](#set-up-the-database), and run `atomic storage migrate` as the owner role. For more detail per service, see [`@bastani/atomic-storage-postgres`](/libraries/storage-postgres).
|
|
357
|
+
|
|
358
|
+
`atomic install` puts these libraries in `~/.atomic/agent/npm`, where the PostgreSQL adapter looks for them.
|
|
359
|
+
|
|
360
|
+
## Tuning for many concurrent agents
|
|
361
|
+
|
|
362
|
+
How many agents can write at once depends on how many connections each process may open. Writes to different sessions run side by side, each on its own connection. Writes to the same session wait for each other.
|
|
363
|
+
|
|
364
|
+
This section covers Atomic's settings. For the server side, such as memory, monitoring, and the busiest tables, see [Server tuning](/storage/postgres/tuning).
|
|
365
|
+
|
|
366
|
+
Every Atomic process on every machine shares the server's `max_connections`. Give each process as many connections as the server can spare, and no more. The steps below work out that number.
|
|
367
|
+
|
|
368
|
+
### Count the connections Atomic needs
|
|
369
|
+
|
|
370
|
+
Each Atomic process, as [Connection budget](#connection-budget) defines it, opens up to this many connections:
|
|
371
|
+
|
|
372
|
+
- **An agent process**, including each `atomic --mode rpc` child: `maxConnections` plus `readerMaxConnections`.
|
|
373
|
+
- **An Intercom broker**: `maxConnections` plus `readerMaxConnections`, plus 1 for [wake-ups](#wake-ups).
|
|
374
|
+
|
|
375
|
+
A quiet process holds fewer. Plan for the maximum anyway, because busy processes reach it.
|
|
376
|
+
|
|
377
|
+
Find what the server has to share. Run these as an administrator:
|
|
378
|
+
|
|
379
|
+
```sql
|
|
380
|
+
SHOW max_connections;
|
|
381
|
+
SHOW superuser_reserved_connections;
|
|
382
|
+
SHOW reserved_connections; -- PostgreSQL 16 and later
|
|
383
|
+
SELECT count(*) FROM pg_stat_activity
|
|
384
|
+
WHERE backend_type = 'client backend' AND application_name NOT LIKE 'atomic%';
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Then work out `maxConnections`:
|
|
388
|
+
|
|
389
|
+
1. Take `max_connections`. Subtract both reserved counts and the connections other clients use. Call the result *available*.
|
|
390
|
+
2. Count *P*, the number of Atomic processes on all machines, and *B*, the number of those that are Intercom brokers. Atomic runs one Intercom broker per agent directory, usually one per machine or container.
|
|
391
|
+
3. Each process may use (*available* − *B*) / *P* connections, rounded down.
|
|
392
|
+
4. Set `maxConnections` to that number minus `readerMaxConnections`.
|
|
393
|
+
|
|
394
|
+
If step 4 gives `maxConnections` below 2, the server cannot give each process enough connections. Use a pooler, as in the second example below.
|
|
395
|
+
|
|
396
|
+
A new PostgreSQL server has `max_connections = 100` with 3 slots reserved for superusers. With Atomic's defaults, each process may need 10 connections and each broker 11, so such a server holds about 8 processes. For example, 20 agent processes on 4 machines, with one broker each, can open up to 20 × 10 + 4 × 11 = 244 connections. Raise `max_connections`, lower `maxConnections`, or use PgBouncer.
|
|
397
|
+
|
|
398
|
+
### Example: 24 processes on a large server
|
|
399
|
+
|
|
400
|
+
Four machines each run five agent processes and one Intercom broker, so *P* is 24 and *B* is 4. The server has `max_connections = 500`, 3 superuser slots, no other reserved slots, and 20 connections used by other clients.
|
|
401
|
+
|
|
402
|
+
- *available* is 500 − 3 − 0 − 20 = 477.
|
|
403
|
+
- Each process may use (477 − 4) / 24 = 19.7, rounded down to 19.
|
|
404
|
+
- With the default `readerMaxConnections` of 2, set `maxConnections` to 19 − 2 = 17.
|
|
405
|
+
|
|
406
|
+
In `~/.atomic/agent/settings.json` on each machine:
|
|
407
|
+
|
|
408
|
+
```json
|
|
409
|
+
{
|
|
410
|
+
"storage": {
|
|
411
|
+
"adapter": "@bastani/atomic-storage-postgres",
|
|
412
|
+
"options": {
|
|
413
|
+
"url": "postgresql://atomic_runtime@db.example.com:5432/atomic",
|
|
414
|
+
"maxConnections": 17,
|
|
415
|
+
"readerMaxConnections": 2
|
|
416
|
+
},
|
|
417
|
+
"secrets": { "password": { "file": "agent/storage-token.28ab7041-05e2-4ad5-80af-854329035d8c" } }
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
The same options in an SDK app:
|
|
423
|
+
|
|
424
|
+
```typescript
|
|
425
|
+
import { openPostgresDatabase } from "@bastani/atomic-storage-postgres";
|
|
426
|
+
|
|
427
|
+
const database = await openPostgresDatabase({
|
|
428
|
+
url: "postgresql://atomic_runtime@db.example.com:5432/atomic",
|
|
429
|
+
password: process.env.ATOMIC_DB_PASSWORD,
|
|
430
|
+
maxConnections: 17,
|
|
431
|
+
readerMaxConnections: 2,
|
|
432
|
+
});
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### Example: 150 machines on a smaller server
|
|
436
|
+
|
|
437
|
+
Here, 150 CI runners each run one agent process and one Intercom broker, so *P* is 300 and *B* is 150. The server has `max_connections = 300`, 3 superuser slots, and 10 connections used by other clients, so *available* is 287.
|
|
438
|
+
|
|
439
|
+
Even at the smallest settings, `maxConnections: 1` and `readerMaxConnections: 0`, the processes need 300 × 1 + 150 = 450 connections. That is more than 287, so connect through a pooler such as PgBouncer in transaction mode, on port 6432:
|
|
440
|
+
|
|
441
|
+
- **Point `url` at PgBouncer.** Connections to PgBouncer do not count against the server, so keep `maxConnections` at its default of 8. Set PgBouncer's `max_client_conn` to at least *P* × (`maxConnections` + `readerMaxConnections`), here 300 × 10 = 3000.
|
|
442
|
+
- **Point `listenUrl` at the server**, or leave it out. PgBouncer cannot pass wake-ups. With `listenUrl`, each broker holds one direct connection, learns of new messages at once, and checks for missed ones every 5 seconds. Without it, brokers check the database every half second, 10 times as often.
|
|
443
|
+
- **Size PgBouncer's pool** to fit in what is left. With `listenUrl`, PgBouncer's pool and its reserve together may use at most 287 − 150 = 137 connections. Without `listenUrl`, up to 287. A smaller pool is often faster. The [PgBouncer guide](/storage/postgres/pgbouncer#choose-the-pool-sizes) starts at 80 plus 5 in reserve.
|
|
444
|
+
|
|
445
|
+
```json
|
|
446
|
+
{
|
|
447
|
+
"storage": {
|
|
448
|
+
"adapter": "@bastani/atomic-storage-postgres",
|
|
449
|
+
"options": {
|
|
450
|
+
"url": "postgresql://atomic_runtime@pgbouncer.example.com:6432/atomic",
|
|
451
|
+
"listenUrl": "postgresql://atomic_runtime@db.example.com:5432/atomic",
|
|
452
|
+
"maxConnections": 8
|
|
453
|
+
},
|
|
454
|
+
"secrets": { "password": { "file": "agent/storage-token.28ab7041-05e2-4ad5-80af-854329035d8c" } }
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
The same options in an SDK app:
|
|
460
|
+
|
|
461
|
+
```typescript
|
|
462
|
+
const database = await openPostgresDatabase({
|
|
463
|
+
url: "postgresql://atomic_runtime@pgbouncer.example.com:6432/atomic",
|
|
464
|
+
listenUrl: "postgresql://atomic_runtime@db.example.com:5432/atomic",
|
|
465
|
+
password: process.env.ATOMIC_DB_PASSWORD,
|
|
466
|
+
maxConnections: 8,
|
|
467
|
+
});
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
The [PgBouncer guide](/storage/postgres/pgbouncer) has a complete PgBouncer configuration, the PostgreSQL and Atomic settings that go with it, and how to check that it works.
|
|
471
|
+
|
|
472
|
+
### Other settings
|
|
473
|
+
|
|
474
|
+
Set these in the same `options` object, or pass them to `openPostgresDatabase`. Each takes a whole number of milliseconds, except `maxPreparedStatements`.
|
|
475
|
+
|
|
476
|
+
- **Distance comes first.** Each save waits for at least one round trip to the server, so a machine 80 ms away spends at least 80 ms on each save. Put the database in the same region as the agents. Saves are slower until the owner has run `atomic storage migrate` after an upgrade.
|
|
477
|
+
- **`idleTimeoutMs`** (default `300000`, 5 minutes). Lower it, for example to `30000`, when long-running processes sit idle and the server is near its connection limit.
|
|
478
|
+
- **`statementTimeoutMs`** (default `30000`). Raise it only if statements fail with `StorageTransientError` code `transaction-timeout` on a slow server. A lower value does not make anything faster.
|
|
479
|
+
- **`connectTimeoutMs`** (default `10000`). Raise it for a distant server or one that is slow to accept connections.
|
|
480
|
+
- **`keepAliveIdleMs`** (default `60000`). Lower it if calls fail with `StorageTransientError` code `connection-lost` after a pause. That error after a pause usually means a firewall, NAT, or load balancer dropped the idle connection.
|
|
481
|
+
- **`maxPreparedStatements`** (default `256`, or `0` behind a pooler). Lower it if the server is short of memory per connection. Atomic expects a pooler on ports 6432 and 6543. Behind a pooler on any other port, set `listenUrl` or `maxPreparedStatements: 0`. See [Prepared statements](/storage/postgres/pgbouncer#how-atomic-works-with-pgbouncer).
|
|
482
|
+
|
|
483
|
+
### Check the effect
|
|
484
|
+
|
|
485
|
+
Run these as an administrator. Replace `atomic` with your database name. Atomic's connections report the application name `atomic`, `atomic-reader`, or `atomic-listen`.
|
|
486
|
+
|
|
487
|
+
How many connections Atomic holds, and what they are doing:
|
|
488
|
+
|
|
489
|
+
```sql
|
|
490
|
+
SELECT application_name, state, count(*)
|
|
491
|
+
FROM pg_stat_activity
|
|
492
|
+
WHERE datname = 'atomic'
|
|
493
|
+
GROUP BY 1, 2
|
|
494
|
+
ORDER BY 3 DESC;
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
What busy connections are waiting for:
|
|
498
|
+
|
|
499
|
+
```sql
|
|
500
|
+
SELECT wait_event_type, wait_event, count(*)
|
|
501
|
+
FROM pg_stat_activity
|
|
502
|
+
WHERE datname = 'atomic' AND state <> 'idle'
|
|
503
|
+
GROUP BY 1, 2
|
|
504
|
+
ORDER BY 3 DESC;
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
How close the server is to its limit:
|
|
508
|
+
|
|
509
|
+
```sql
|
|
510
|
+
SELECT count(*) AS used, current_setting('max_connections')::int AS max
|
|
511
|
+
FROM pg_stat_activity
|
|
512
|
+
WHERE backend_type = 'client backend';
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
What to change:
|
|
516
|
+
|
|
517
|
+
| You see | It means | Change |
|
|
518
|
+
| --- | --- | --- |
|
|
519
|
+
| `sorry, too many clients already`, `remaining connection slots are reserved for roles with the SUPERUSER attribute`, or `too many connections for role "<role>"` | The processes asked for more connections than the server or the role allows. | Lower `maxConnections` or `readerMaxConnections`, raise `max_connections` or the role's `CONNECTION LIMIT`, or [put PgBouncer in front](/storage/postgres/pgbouncer). |
|
|
520
|
+
| `timeout exceeded when trying to connect` | Every connection in a process's pool stayed busy for `connectTimeoutMs`. | Raise `maxConnections` if the server has connections to spare. Otherwise raise `connectTimeoutMs`. |
|
|
521
|
+
| `the call was queued behind an earlier call that ran 60 seconds without settling, and did not run; nothing was written, retry it` | An earlier call ran for a minute, usually because it waited on a lock or on an overloaded server, and this call waited behind it. | Check what busy connections wait for. More connections do not help. |
|
|
522
|
+
| Many connections with `wait_event_type` `Lock` | Agents write to the same sessions at once and wait for each other. | More connections do not help. Spread agents over more sessions. |
|
|
523
|
+
| Most `atomic` connections are `idle` and the server is near its limit | Idle processes keep connections open. | Lower `idleTimeoutMs`. |
|
|
524
|
+
| `wake-ups: polling only, the listen connection failed` in `atomic storage status` | A broker could not open its wake-up connection, often because the server has none left. | Count the connections again with the steps above. |
|
|
525
|
+
|
|
526
|
+
Atomic reports the first two rows as `StorageTransientError` with code `connection-refused`, and the quoted text is the error's cause. The third row is a `StorageUnavailableError` whose message ends with the quoted text.
|
|
527
|
+
|
|
528
|
+
## Troubleshooting
|
|
529
|
+
|
|
530
|
+
Errors from `atomic storage join`, `atomic storage migrate`, and opening the database, with what to do:
|
|
531
|
+
|
|
532
|
+
| Error | Fix |
|
|
533
|
+
| --- | --- |
|
|
534
|
+
| `credential-in-url` | Remove the password from the URL. Pass `--password-file` or `--token-file` instead. |
|
|
535
|
+
| `libsql-removed` | The URL is a libSQL one, such as `libsql://`, `https://`, `wss://`, or `file:`, or the command is `atomic team join`. Use a `postgres://` URL with `atomic storage join`. To move existing sessions, see [Moving off libSQL](/storage#moving-off-libsql). |
|
|
536
|
+
| `unsupported-auth` | `--auth` accepts `azure`, `aws`, or `gcp`, or the long forms `azure-entra`, `aws-iam`, and `gcp-iam`. |
|
|
537
|
+
| `adapter-not-installed` | Run `atomic install npm:@bastani/atomic-storage-postgres` as the user who runs Atomic. |
|
|
538
|
+
| `auth-unavailable` | Install the cloud library the error names, and check that the machine has a cloud identity. Atomic does not retry this error. |
|
|
539
|
+
| `missing-privilege`, with PostgreSQL code `42501` or `3F000` | Run the `GRANT` the error names, as in [Set up the database](#set-up-the-database). If the error mentions ownership or `CREATE`, run `atomic storage migrate` as the owner role. |
|
|
540
|
+
| `This database was upgraded since this process started` | `atomic storage migrate` moved the tables from `public` to `atomic` while this process ran. Restart the process. |
|
|
541
|
+
| A refused password or token, with PostgreSQL code `28P01`, or `28000` on Azure | The token expired, names the wrong user, or has the wrong format. On Azure, use `--auth azure`, or get a token for `https://ossrdbms-aad.database.windows.net` with `az account get-access-token --resource-type oss-rdbms`. |
|
|
542
|
+
| `StorageUnavailableError` on open | The server refused the login (`28P01` or `28000`), the database does not exist (`3D000`), or the server is too old. Use PostgreSQL 16 or newer. |
|
|
543
|
+
| `self-signed certificate in certificate chain` or `unable to get local issuer certificate` | Set `sslrootcert` to your server's certificate authority. See [TLS](#tls). |
|
|
544
|
+
| `INVALID_PURPOSE` | The certificate in `sslrootcert` is not a certificate authority (`basicConstraints=CA:TRUE`), or may only be used for clients. Point `sslrootcert` at the authority that signed the server's certificate. |
|
|
545
|
+
| `PATH_LENGTH_EXCEEDED` | The certificate chain is longer than the root certificate allows. Reissue the root without that limit, or sign the server certificate with the root directly. |
|
|
546
|
+
| `UNSPECIFIED` with a reason, such as `key usage does not include certificate signing` | Node.js reports some certificate problems this way. Follow the reason, for example reissue the certificate authority with `keyCertSign`. |
|
|
547
|
+
| The proxy's own certificate is refused | An `https://` proxy's certificate is checked against Node.js's certificate authorities, never `sslrootcert`. Add your proxy's authority to [`NODE_EXTRA_CA_CERTS`](/environment-variables#tls-certificates). |
|
|
548
|
+
| The proxy refused the tunnel, or cannot be reached | Allow the database's `host:port` on the proxy, give proxy credentials for a `407`, check `HTTPS_PROXY`, or skip the proxy with `NO_PROXY` or `proxy: "none"`. See [Through an HTTP proxy](#through-an-http-proxy). |
|
|
549
|
+
| `unsupported-proxy` | Use an `http://` or `https://` proxy. Atomic does not support `socks5://`. |
|
|
550
|
+
| `StorageTransientError` with code `read-only-server`, PostgreSQL code `25006` | `url` points at a read-only replica, or the server is failing over or out of disk. Point `url` at the read/write endpoint, or retry once the server recovers. |
|
|
551
|
+
| `sorry, too many clients already`, `remaining connection slots are reserved for roles with the SUPERUSER attribute`, or `too many connections for role "<role>"`, PostgreSQL code `53300` | The server, or the role's `CONNECTION LIMIT`, has no connection left. Atomic reports `StorageTransientError` with code `connection-refused`. Lower `maxConnections` or `readerMaxConnections`, raise `max_connections`, or put [PgBouncer](/storage/postgres/pgbouncer) in front. See [Tuning for many concurrent agents](#tuning-for-many-concurrent-agents). |
|
|
552
|
+
| `timeout exceeded when trying to connect` | Every connection in the process's pool stayed busy, or a new connection took longer than `connectTimeoutMs`. Atomic reports `StorageTransientError` with code `connection-refused`. Raise `maxConnections` if the server has connections to spare, or raise `connectTimeoutMs` for a distant or slow server. |
|
|
553
|
+
| `prepared statement "atomic_…" does not exist` or `already exists`, behind a pooler | The pooler does not keep prepared statements. Atomic stops preparing statements for the rest of the process and retries, so you usually see only a one-time warning. Set `maxPreparedStatements` to `0`, or on PgBouncer 1.21 or later set `max_prepared_statements` above `0`. |
|
|
554
|
+
| `StorageTransientError` with code `lock-conflict` or `transaction-timeout` | The server cancelled a statement that waited too long or ran past `statementTimeoutMs`. Nothing was written. If it keeps happening, the server is overloaded. |
|
|
555
|
+
| `wake-ups: polling only` in `atomic storage status` | Messages still arrive, by polling. See [Wake-ups](#wake-ups). |
|
|
556
|
+
| `StorageTransientError` with code `connection-lost` after a failover or pooler restart | The server or pooler closed the connection. Retry. |
|