@bastani/atomic 0.9.20-alpha.8 → 0.9.20-alpha.9
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 +41 -0
- package/dist/builtin/intercom/package.json +3 -5
- package/dist/builtin/mcp/package.json +3 -3
- package/dist/builtin/subagents/CHANGELOG.md +6 -0
- package/dist/builtin/subagents/package.json +3 -3
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +11 -2
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +31 -0
- package/dist/builtin/workflows/builtin/adversarial-verification.js +3 -3
- package/dist/builtin/workflows/builtin/{chunk-ffdrv23t.js → chunk-18yz7r43.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-9z3ztr2a.js → chunk-1pd5zcfa.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-5724b0cf.js → chunk-24c235x7.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-vn0wb31x.js → chunk-2jv44yz7.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-hmt5w62g.js → chunk-2npg6daz.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-njmf5ze7.js → chunk-7ps7bnb4.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-jngsbbpm.js → chunk-ad864596.js} +3 -3
- package/dist/builtin/workflows/builtin/{chunk-7n51c5gh.js → chunk-f8jjd90r.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-3tx8ry44.js → chunk-gxrhbnaj.js} +2 -1
- package/dist/builtin/workflows/builtin/{chunk-2hzrv5y8.js → chunk-twefqrv0.js} +986 -199
- package/dist/builtin/workflows/builtin/{chunk-7bzcersz.js → chunk-ynded223.js} +3 -3
- package/dist/builtin/workflows/builtin/{chunk-dxjxtgmp.js → chunk-z5xdqrs6.js} +1 -1
- package/dist/builtin/workflows/builtin/classify-and-act.js +3 -3
- package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +3 -3
- package/dist/builtin/workflows/builtin/generate-and-filter.js +3 -3
- package/dist/builtin/workflows/builtin/goal.js +4 -4
- package/dist/builtin/workflows/builtin/index.js +12 -12
- package/dist/builtin/workflows/builtin/loop-until-done.js +3 -3
- package/dist/builtin/workflows/builtin/open-claude-design.js +3 -3
- package/dist/builtin/workflows/builtin/ralph.js +4 -4
- package/dist/builtin/workflows/builtin/steering-context.js +1 -1
- package/dist/builtin/workflows/builtin/tournament.js +3 -3
- package/dist/builtin/workflows/package.json +4 -4
- package/dist/builtin/workflows/src/authoring.d.ts +6 -3
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +12092 -11365
- package/dist/builtin/workflows/src/index.js +41619 -12907
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +13 -0
- package/dist/core/agent-session-boundaries.d.ts.map +1 -1
- package/dist/core/agent-session-boundaries.js +9 -4
- package/dist/core/agent-session-boundaries.js.map +1 -1
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +4 -0
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +3 -0
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-tasks.js +4 -4
- package/dist/core/agent-session-tasks.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +4 -3
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/agent-session.d.ts +3 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +3 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/cache-stats.d.ts +7 -1
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js +24 -5
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/execution-model-router.d.ts +1 -1
- package/dist/core/execution-model-router.d.ts.map +1 -1
- package/dist/core/execution-model-router.js +23 -14
- package/dist/core/execution-model-router.js.map +1 -1
- package/dist/core/extensions/agent-events.d.ts +9 -1
- package/dist/core/extensions/agent-events.d.ts.map +1 -1
- package/dist/core/extensions/agent-events.js.map +1 -1
- package/dist/core/extensions/api-types.d.ts +2 -1
- package/dist/core/extensions/api-types.d.ts.map +1 -1
- package/dist/core/extensions/api-types.js.map +1 -1
- package/dist/core/extensions/event-types.d.ts +2 -2
- package/dist/core/extensions/event-types.d.ts.map +1 -1
- package/dist/core/extensions/event-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader-core.d.ts.map +1 -1
- package/dist/core/extensions/loader-core.js +1 -0
- package/dist/core/extensions/loader-core.js.map +1 -1
- package/dist/core/extensions/provider-types.d.ts +34 -16
- package/dist/core/extensions/provider-types.d.ts.map +1 -1
- package/dist/core/extensions/provider-types.js.map +1 -1
- package/dist/core/extensions/runtime-types.d.ts +4 -0
- package/dist/core/extensions/runtime-types.d.ts.map +1 -1
- package/dist/core/extensions/runtime-types.js.map +1 -1
- package/dist/core/extensions/tool-types.d.ts +9 -0
- package/dist/core/extensions/tool-types.d.ts.map +1 -1
- package/dist/core/extensions/tool-types.js.map +1 -1
- package/dist/core/fast-model-routing.d.ts.map +1 -1
- package/dist/core/fast-model-routing.js +1 -0
- package/dist/core/fast-model-routing.js.map +1 -1
- package/dist/core/model-registry.d.ts +3 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +6 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-runtime-auth.d.ts +2 -2
- package/dist/core/model-runtime-auth.d.ts.map +1 -1
- package/dist/core/model-runtime-auth.js.map +1 -1
- package/dist/core/model-runtime-streaming.d.ts.map +1 -1
- package/dist/core/model-runtime-streaming.js +2 -1
- package/dist/core/model-runtime-streaming.js.map +1 -1
- package/dist/core/model-runtime.d.ts +11 -3
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +41 -6
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/package-manager-npm.d.ts.map +1 -1
- package/dist/core/package-manager-npm.js +32 -8
- package/dist/core/package-manager-npm.js.map +1 -1
- package/dist/core/package-manager-resolver.js +3 -1
- package/dist/core/package-manager-resolver.js.map +1 -1
- package/dist/core/package-manager-types.d.ts +1 -0
- package/dist/core/package-manager-types.d.ts.map +1 -1
- package/dist/core/package-manager-types.js.map +1 -1
- package/dist/core/provider-composer-internal.d.ts +40 -21
- package/dist/core/provider-composer-internal.d.ts.map +1 -1
- package/dist/core/provider-composer-internal.js +22 -20
- package/dist/core/provider-composer-internal.js.map +1 -1
- package/dist/core/provider-composer.d.ts +3 -3
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +54 -10
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts +8 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +46 -4
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resource-loader-core.d.ts.map +1 -1
- package/dist/core/resource-loader-core.js +7 -3
- package/dist/core/resource-loader-core.js.map +1 -1
- package/dist/core/resource-loader-extension-warnings.d.ts +9 -0
- package/dist/core/resource-loader-extension-warnings.d.ts.map +1 -0
- package/dist/core/resource-loader-extension-warnings.js +54 -0
- package/dist/core/resource-loader-extension-warnings.js.map +1 -0
- package/dist/core/resource-loader-extensions.d.ts.map +1 -1
- package/dist/core/resource-loader-extensions.js +1 -0
- package/dist/core/resource-loader-extensions.js.map +1 -1
- package/dist/core/resource-loader-reload.d.ts.map +1 -1
- package/dist/core/resource-loader-reload.js +6 -0
- package/dist/core/resource-loader-reload.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts.map +1 -1
- package/dist/core/runtime-credentials.js +3 -1
- package/dist/core/runtime-credentials.js.map +1 -1
- package/dist/core/sdk.js +16 -6
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js +4 -4
- package/dist/core/settings-manager-basic-accessors.js.map +1 -1
- package/dist/core/structured-output/choice-schema.d.ts +8 -0
- package/dist/core/structured-output/choice-schema.d.ts.map +1 -0
- package/dist/core/structured-output/choice-schema.js +79 -0
- package/dist/core/structured-output/choice-schema.js.map +1 -0
- package/dist/core/structured-output/index.d.ts +3 -5
- package/dist/core/structured-output/index.d.ts.map +1 -1
- package/dist/core/structured-output/index.js +218 -41
- package/dist/core/structured-output/index.js.map +1 -1
- package/dist/core/structured-output/resolver.d.ts +0 -46
- package/dist/core/structured-output/resolver.d.ts.map +1 -1
- package/dist/core/structured-output/resolver.js +15 -93
- package/dist/core/structured-output/resolver.js.map +1 -1
- package/dist/core/structured-output/types.d.ts +27 -21
- package/dist/core/structured-output/types.d.ts.map +1 -1
- package/dist/core/structured-output/types.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +9 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/owner-store.d.ts +6 -0
- package/dist/core/tasks/owner-store.d.ts.map +1 -1
- package/dist/core/tasks/owner-store.js +16 -3
- package/dist/core/tasks/owner-store.js.map +1 -1
- package/dist/core/tasks/pause.js +1 -1
- package/dist/core/tasks/pause.js.map +1 -1
- package/dist/core/tasks/supervisor.d.ts +4 -2
- package/dist/core/tasks/supervisor.d.ts.map +1 -1
- package/dist/core/tasks/supervisor.js +9 -3
- package/dist/core/tasks/supervisor.js.map +1 -1
- package/dist/core/tools/ask-user-question/ask-user-question.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/ask-user-question.js +1 -0
- package/dist/core/tools/ask-user-question/ask-user-question.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +1 -0
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +1 -0
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-coordinator.d.ts +4 -3
- package/dist/core/tools/file-mutation-coordinator.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-coordinator.js +45 -38
- package/dist/core/tools/file-mutation-coordinator.js.map +1 -1
- package/dist/core/tools/powershell.d.ts +16 -0
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/core/tools/structured-output.d.ts +9 -6
- package/dist/core/tools/structured-output.d.ts.map +1 -1
- package/dist/core/tools/structured-output.js +36 -8
- package/dist/core/tools/structured-output.js.map +1 -1
- package/dist/core/tools/todos.d.ts.map +1 -1
- package/dist/core/tools/todos.js +1 -0
- package/dist/core/tools/todos.js.map +1 -1
- package/dist/core/tools/tool-concurrency.d.ts +23 -0
- package/dist/core/tools/tool-concurrency.d.ts.map +1 -0
- package/dist/core/tools/tool-concurrency.js +58 -0
- package/dist/core/tools/tool-concurrency.js.map +1 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts +4 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +2 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +1 -0
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index-extensions.d.ts +1 -1
- package/dist/index-extensions.d.ts.map +1 -1
- package/dist/index-extensions.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +4 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-items.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-items.js +11 -9
- package/dist/modes/interactive/components/settings-selector-items.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-types.d.ts +2 -1
- package/dist/modes/interactive/components/settings-selector-types.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
- package/dist/modes/interactive/components/task-inspector.d.ts +1 -0
- package/dist/modes/interactive/components/task-inspector.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-inspector.js +11 -11
- package/dist/modes/interactive/components/task-inspector.js.map +1 -1
- package/dist/modes/interactive/components/task-list.d.ts +9 -3
- package/dist/modes/interactive/components/task-list.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-list.js +26 -2
- package/dist/modes/interactive/components/task-list.js.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.js +3 -9
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-auth-login.js +1 -1
- package/dist/modes/interactive/interactive-auth-login.js.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.js +3 -9
- package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
- package/dist/modes/interactive/interactive-resource-rendering.js +6 -9
- package/dist/modes/interactive/interactive-resource-rendering.js.map +1 -1
- package/dist/modes/interactive/interactive-selectors.js +1 -0
- package/dist/modes/interactive/interactive-selectors.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js +2 -4
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +1 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +5 -0
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +14 -17
- package/dist/utils/clipboard-image.js.map +1 -1
- package/docs/background-tasks.md +1 -0
- package/docs/computer-use.md +2 -2
- package/docs/custom-provider/registration.md +1 -1
- package/docs/custom-provider.md +43 -1
- package/docs/extensions/authoring.md +22 -3
- package/docs/extensions/events.md +18 -0
- package/docs/extensions/examples.md +1 -0
- package/docs/models/evals.md +31 -79
- package/docs/models/model-selection.md +5 -1
- package/docs/packages/authoring.md +3 -1
- package/docs/providers.md +7 -11
- package/docs/sdk/reference.md +18 -42
- package/docs/sdk/structured-decisions.md +44 -89
- package/docs/sdk.md +1 -1
- package/docs/settings.md +6 -6
- package/docs/subagents/reference.md +7 -8
- package/docs/usage.md +13 -0
- package/docs/workflows/api-reference.md +38 -35
- package/docs/workflows/authoring.md +113 -1
- package/docs/workflows/builtins.md +1 -1
- package/docs/workflows/operations.md +51 -29
- package/docs/workflows/verification.md +13 -0
- package/examples/extensions/README.md +1 -0
- package/examples/extensions/debug-provider.ts +90 -0
- package/examples/extensions/structured-output.ts +6 -0
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
- package/dist/builtin/workflows/src/durable/dependency-doctor-types.d.ts +0 -42
- package/dist/core/decision-provider.d.ts +0 -4
- package/dist/core/decision-provider.d.ts.map +0 -1
- package/dist/core/decision-provider.js +0 -12
- package/dist/core/decision-provider.js.map +0 -1
- package/dist/core/structured-output/jev-client.d.ts +0 -25
- package/dist/core/structured-output/jev-client.d.ts.map +0 -1
- package/dist/core/structured-output/jev-client.js +0 -174
- package/dist/core/structured-output/jev-client.js.map +0 -1
- package/dist/core/structured-output/jev.d.ts +0 -5
- package/dist/core/structured-output/jev.d.ts.map +0 -1
- package/dist/core/structured-output/jev.js +0 -249
- package/dist/core/structured-output/jev.js.map +0 -1
|
@@ -4955,7 +4955,7 @@ var require_lib2 = __commonJS(function(exports, module) {
|
|
|
4955
4955
|
// dist/builtin/workflows/src/shared/workflow-artifacts.ts
|
|
4956
4956
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
4957
4957
|
import { mkdir as mkdir2, readdir as readdir2, rm as rm2, stat } from "node:fs/promises";
|
|
4958
|
-
import { dirname as
|
|
4958
|
+
import { dirname as dirname4, join as join5 } from "node:path";
|
|
4959
4959
|
import { getAgentDir, getEnvValue } from "@bastani/atomic";
|
|
4960
4960
|
// dist/builtin/workflows/src/durable/backend-process-owner.ts
|
|
4961
4961
|
var DURABLE_BACKEND_PROCESS_OWNER_KEY = Symbol.for("atomic-workflows/durable-backend-process-owner@1");
|
|
@@ -5125,6 +5125,18 @@ function getDbosProcessOwner() {
|
|
|
5125
5125
|
// dist/builtin/workflows/src/durable/dbos-sdk-handle.ts
|
|
5126
5126
|
var ATOMIC_EXECUTOR_ID = `atomic-${process.pid.toString(36)}-${crypto.randomUUID().slice(0, 8)}`;
|
|
5127
5127
|
|
|
5128
|
+
// dist/builtin/workflows/src/durable/dbos-system-database-url.ts
|
|
5129
|
+
function nonEmptyTrimmed(value) {
|
|
5130
|
+
const trimmed = value?.trim();
|
|
5131
|
+
return trimmed === undefined || trimmed.length === 0 ? undefined : trimmed;
|
|
5132
|
+
}
|
|
5133
|
+
function environmentSystemDatabaseUrl() {
|
|
5134
|
+
return nonEmptyTrimmed(process.env.DBOS_SYSTEM_DATABASE_URL);
|
|
5135
|
+
}
|
|
5136
|
+
function explicitDbosSystemDatabaseUrl() {
|
|
5137
|
+
return environmentSystemDatabaseUrl() ?? nonEmptyTrimmed(getDbosProcessOwner().systemDatabaseUrl);
|
|
5138
|
+
}
|
|
5139
|
+
|
|
5128
5140
|
// ../../node_modules/pg/esm/index.mjs
|
|
5129
5141
|
var import_lib = __toESM(require_lib2(), 1);
|
|
5130
5142
|
var Client = import_lib.default.Client;
|
|
@@ -5159,13 +5171,17 @@ function defaultPostgresUrl(database, host = process.env.PGHOST || "localhost",
|
|
|
5159
5171
|
import {
|
|
5160
5172
|
chmodSync,
|
|
5161
5173
|
chownSync,
|
|
5174
|
+
closeSync,
|
|
5162
5175
|
copyFileSync,
|
|
5163
5176
|
existsSync as existsSync3,
|
|
5177
|
+
fstatSync,
|
|
5164
5178
|
lstatSync as lstatSync3,
|
|
5165
5179
|
mkdirSync as mkdirSync2,
|
|
5180
|
+
openSync,
|
|
5166
5181
|
readdirSync as readdirSync2,
|
|
5167
5182
|
readFileSync as readFileSync3,
|
|
5168
5183
|
readlinkSync,
|
|
5184
|
+
readSync,
|
|
5169
5185
|
realpathSync as realpathSync3,
|
|
5170
5186
|
renameSync as renameSync2,
|
|
5171
5187
|
rmdirSync,
|
|
@@ -5174,9 +5190,9 @@ import {
|
|
|
5174
5190
|
symlinkSync,
|
|
5175
5191
|
writeFileSync as writeFileSync2
|
|
5176
5192
|
} from "node:fs";
|
|
5177
|
-
import { createRequire as
|
|
5193
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
5178
5194
|
import { tmpdir, uptime } from "node:os";
|
|
5179
|
-
import { dirname as
|
|
5195
|
+
import { basename as basename2, dirname as dirname3, isAbsolute as isAbsolute3, join as join4, relative as relative2, sep as sep2 } from "node:path";
|
|
5180
5196
|
|
|
5181
5197
|
// dist/builtin/workflows/src/durable/dbos-embedded-postgres-root.ts
|
|
5182
5198
|
import { createHash } from "node:crypto";
|
|
@@ -5188,6 +5204,7 @@ import {
|
|
|
5188
5204
|
mkdir,
|
|
5189
5205
|
open,
|
|
5190
5206
|
readdir,
|
|
5207
|
+
readFile,
|
|
5191
5208
|
readlink,
|
|
5192
5209
|
realpath,
|
|
5193
5210
|
rename,
|
|
@@ -5195,7 +5212,7 @@ import {
|
|
|
5195
5212
|
writeFile
|
|
5196
5213
|
} from "node:fs/promises";
|
|
5197
5214
|
import { homedir } from "node:os";
|
|
5198
|
-
import { dirname, isAbsolute, join, relative, sep } from "node:path";
|
|
5215
|
+
import { basename, dirname, isAbsolute, join, normalize, relative, sep } from "node:path";
|
|
5199
5216
|
|
|
5200
5217
|
// dist/builtin/workflows/src/durable/local-command.ts
|
|
5201
5218
|
import { spawn } from "node:child_process";
|
|
@@ -5368,30 +5385,43 @@ function parseIdentityGroups(result) {
|
|
|
5368
5385
|
}
|
|
5369
5386
|
var STAGE_OWNER_FILE = ".atomic-stage-owner";
|
|
5370
5387
|
var STAGE_PAYLOAD_DIR = "runtime";
|
|
5388
|
+
var RUNTIME_MARKER = ".atomic-runtime-complete.json";
|
|
5389
|
+
var MAX_RUNTIME_REPAIR_GENERATIONS = 8;
|
|
5371
5390
|
var TRAVERSAL_OPERATIONS_PER_YIELD = 16;
|
|
5372
5391
|
var HASH_CHUNK_BYTES = 64 * 1024;
|
|
5392
|
+
var sourceMemo = new Map;
|
|
5393
|
+
var legacyMemo = new Map;
|
|
5394
|
+
var validatedMemo = new Map;
|
|
5395
|
+
var corruptGenerationMemo = new Map;
|
|
5396
|
+
function runtimeGenerationIdentity(rootStat, markerStat) {
|
|
5397
|
+
const identity = (stat) => stat === undefined ? null : [stat.dev, stat.ino, stat.mode, stat.size, stat.mtimeMs, stat.ctimeMs, stat.birthtimeMs];
|
|
5398
|
+
return JSON.stringify([identity(rootStat), identity(markerStat)]);
|
|
5399
|
+
}
|
|
5400
|
+
async function candidateIdentity(candidate, rootStat) {
|
|
5401
|
+
return runtimeGenerationIdentity(rootStat, await lstatOrUndefined(join(candidate, RUNTIME_MARKER)));
|
|
5402
|
+
}
|
|
5373
5403
|
async function prepareBinariesForOwner(binaries, context, runner = runLocalCommand, options = {}) {
|
|
5374
|
-
const owner = context.owner;
|
|
5375
|
-
if (owner === undefined)
|
|
5376
|
-
return binaries;
|
|
5377
|
-
const probe = await context.runAsOwner(binaries.initdb, ["--version"]).catch(() => {
|
|
5378
|
-
return;
|
|
5379
|
-
});
|
|
5380
|
-
if (probe !== undefined && probe.exitCode === 0)
|
|
5381
|
-
return binaries;
|
|
5382
5404
|
const sourceNativeDir = dirname(dirname(binaries.initdb));
|
|
5383
|
-
const
|
|
5405
|
+
const override = process.env.ATOMIC_POSTGRES_RUNTIME_CACHE_DIR;
|
|
5406
|
+
if (override !== undefined && !isAbsolute(override))
|
|
5407
|
+
throw new Error(`Embedded Postgres runtime cache override must be absolute: ${override}`);
|
|
5408
|
+
const copiedRuntimeDir = override === undefined ? join(context.baseDir, "pg-runtime") : normalize(override);
|
|
5384
5409
|
const publisher = publisherIdentity();
|
|
5385
5410
|
const progress = runtimeProgress(options);
|
|
5386
|
-
|
|
5411
|
+
await ensureRuntimeCacheDirectory(copiedRuntimeDir, publisher, context.owner !== undefined, context.owner);
|
|
5412
|
+
const sourceSnapshot = await memoizedSourceSnapshot(sourceNativeDir, copiedRuntimeDir, publisher, progress, options);
|
|
5387
5413
|
await options.afterInitialSourceSnapshot?.();
|
|
5388
|
-
const copiedNativeDir = await findOrCreateRuntimeGeneration(sourceNativeDir, sourceSnapshot, copiedRuntimeDir, publisher, runner, progress, options);
|
|
5414
|
+
const copiedNativeDir = await findOrCreateRuntimeGeneration(binaries, sourceNativeDir, sourceSnapshot, copiedRuntimeDir, publisher, runner, progress, options, context.owner !== undefined);
|
|
5389
5415
|
return {
|
|
5390
|
-
pg_ctl: join(copiedNativeDir, "bin",
|
|
5391
|
-
initdb: join(copiedNativeDir, "bin",
|
|
5392
|
-
postgres: join(copiedNativeDir, "bin",
|
|
5416
|
+
pg_ctl: join(copiedNativeDir, "bin", basename(binaries.pg_ctl)),
|
|
5417
|
+
initdb: join(copiedNativeDir, "bin", basename(binaries.initdb)),
|
|
5418
|
+
postgres: join(copiedNativeDir, "bin", basename(binaries.postgres)),
|
|
5419
|
+
sealedIdentity: sourceSnapshot.sealedIdentity
|
|
5393
5420
|
};
|
|
5394
5421
|
}
|
|
5422
|
+
async function fingerprintPreparedRuntime(binaries, options = {}) {
|
|
5423
|
+
return validatePreparedRuntime(dirname(dirname(binaries.postgres)), binaries, runtimeProgress(options), undefined, options);
|
|
5424
|
+
}
|
|
5395
5425
|
async function cleanupAbandonedRuntimeStages(baseDir, abandonedOwnerTokens = new Set) {
|
|
5396
5426
|
if (abandonedOwnerTokens.size === 0)
|
|
5397
5427
|
return;
|
|
@@ -5419,30 +5449,65 @@ async function cleanupAbandonedRuntimeStages(baseDir, abandonedOwnerTokens = new
|
|
|
5419
5449
|
await rm(stage, { recursive: true, force: true });
|
|
5420
5450
|
}
|
|
5421
5451
|
}
|
|
5422
|
-
async function findOrCreateRuntimeGeneration(sourceNativeDir, sourceSnapshot, copiedRuntimeDir, publisher, runner, progress, options) {
|
|
5423
|
-
await
|
|
5424
|
-
const
|
|
5425
|
-
if (
|
|
5426
|
-
throw new
|
|
5452
|
+
async function findOrCreateRuntimeGeneration(binaries, sourceNativeDir, sourceSnapshot, copiedRuntimeDir, publisher, runner, progress, options, needsPrivilegeDrop) {
|
|
5453
|
+
await ensureRuntimeCacheDirectory(copiedRuntimeDir, publisher, needsPrivilegeDrop);
|
|
5454
|
+
const canonical = join(copiedRuntimeDir, `native-${sourceSnapshot.sourceIdentity}`);
|
|
5455
|
+
if (options.repairCorruptGeneration && !options.publicationLease?.refresh()) {
|
|
5456
|
+
throw new RuntimePublicationLeaseLostError("Embedded Postgres runtime repair requires its setup lease.");
|
|
5427
5457
|
}
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
if (existing !== undefined) {
|
|
5458
|
+
let generationNativeDir;
|
|
5459
|
+
for (let repair = 0;repair <= MAX_RUNTIME_REPAIR_GENERATIONS; repair++) {
|
|
5460
|
+
const candidate = repair === 0 ? canonical : `${canonical}-repair-${repair}`;
|
|
5461
|
+
let candidateFingerprint;
|
|
5433
5462
|
try {
|
|
5434
|
-
|
|
5435
|
-
|
|
5463
|
+
const existing = await lstatOrUndefined(candidate);
|
|
5464
|
+
if (existing === undefined) {
|
|
5465
|
+
if (candidate === options.reservedGeneration)
|
|
5466
|
+
continue;
|
|
5467
|
+
generationNativeDir ??= candidate;
|
|
5468
|
+
if (!options.repairCorruptGeneration)
|
|
5469
|
+
break;
|
|
5470
|
+
continue;
|
|
5436
5471
|
}
|
|
5437
|
-
await
|
|
5438
|
-
|
|
5472
|
+
candidateFingerprint = await candidateIdentity(candidate, existing);
|
|
5473
|
+
const knownCorrupt = corruptGenerationMemo.get(candidate);
|
|
5474
|
+
if (knownCorrupt?.identity === candidateFingerprint)
|
|
5475
|
+
throw new CorruptRuntimeGenerationError(knownCorrupt.reason);
|
|
5476
|
+
const identity = await validatePreparedRuntime(candidate, {
|
|
5477
|
+
pg_ctl: join(candidate, "bin", basename(binaries.pg_ctl)),
|
|
5478
|
+
initdb: join(candidate, "bin", basename(binaries.initdb)),
|
|
5479
|
+
postgres: join(candidate, "bin", basename(binaries.postgres))
|
|
5480
|
+
}, progress, sourceSnapshot.sealedIdentity, options);
|
|
5481
|
+
if (identity !== sourceSnapshot.sealedIdentity)
|
|
5482
|
+
throw new CorruptRuntimeGenerationError("sealed identity mismatch");
|
|
5439
5483
|
} catch (error) {
|
|
5440
|
-
if (error instanceof
|
|
5484
|
+
if (error instanceof RuntimePublicationLeaseLostError)
|
|
5441
5485
|
throw error;
|
|
5442
|
-
|
|
5443
|
-
|
|
5486
|
+
if (!isCorruptRuntimeGeneration(error, candidate))
|
|
5487
|
+
throw error;
|
|
5488
|
+
if (candidateFingerprint !== undefined) {
|
|
5489
|
+
const current = await lstatOrUndefined(candidate);
|
|
5490
|
+
if (current && await candidateIdentity(candidate, current) === candidateFingerprint)
|
|
5491
|
+
corruptGenerationMemo.set(candidate, {
|
|
5492
|
+
identity: candidateFingerprint,
|
|
5493
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
5494
|
+
});
|
|
5495
|
+
}
|
|
5496
|
+
if (!options.repairCorruptGeneration) {
|
|
5497
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
5498
|
+
throw new Error(`Embedded Postgres runtime generation is corrupt and cannot be replaced while it may be in use (${candidate}): ${detail}`);
|
|
5499
|
+
}
|
|
5500
|
+
if (!options.publicationLease?.refresh())
|
|
5501
|
+
throw new RuntimePublicationLeaseLostError("Embedded Postgres runtime repair lost its setup lease.");
|
|
5502
|
+
continue;
|
|
5444
5503
|
}
|
|
5504
|
+
await assertSourceSnapshotUnchanged(sourceNativeDir, sourceSnapshot, publisher, progress, "Embedded Postgres source package changed while selecting an existing generation.");
|
|
5505
|
+
return candidate;
|
|
5445
5506
|
}
|
|
5507
|
+
if (generationNativeDir === undefined)
|
|
5508
|
+
throw new Error("Embedded Postgres runtime repair slots are exhausted; preserve the existing generations.");
|
|
5509
|
+
if (options.reuseOnly)
|
|
5510
|
+
throw new RuntimeGenerationMissingError;
|
|
5446
5511
|
const stageOwner = options.publicationLease?.ownerToken ?? `unmanaged-${process.pid}-${crypto.randomUUID()}`;
|
|
5447
5512
|
const stagedRoot = join(copiedRuntimeDir, `.native-staged-${process.pid}-${crypto.randomUUID()}`);
|
|
5448
5513
|
const stagedNativeDir = join(stagedRoot, STAGE_PAYLOAD_DIR);
|
|
@@ -5451,25 +5516,50 @@ async function findOrCreateRuntimeGeneration(sourceNativeDir, sourceSnapshot, co
|
|
|
5451
5516
|
try {
|
|
5452
5517
|
await progress();
|
|
5453
5518
|
await cp(sourceNativeDir, stagedNativeDir, { recursive: true, verbatimSymlinks: true });
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
throw new Error("Copied embedded Postgres runtime did not match its source package.");
|
|
5457
|
-
}
|
|
5458
|
-
await sealRuntimeForPublisher(stagedNativeDir, publisher, runner, progress);
|
|
5459
|
-
if (await snapshotSealedRuntime(stagedNativeDir, progress) !== sourceSnapshot.sealedIdentity) {
|
|
5460
|
-
throw new Error("Sealed embedded Postgres runtime did not match its source package.");
|
|
5461
|
-
}
|
|
5519
|
+
await assertSourceSnapshotUnchanged(sourceNativeDir, sourceSnapshot, publisher, progress, "Embedded Postgres source package changed while preparing a generation.");
|
|
5520
|
+
await sealRuntimeForPublisher(stagedNativeDir, publisher, runner, progress, needsPrivilegeDrop);
|
|
5462
5521
|
await options.beforePublish?.(stagedNativeDir);
|
|
5463
|
-
|
|
5522
|
+
await assertSourceSnapshotUnchanged(sourceNativeDir, sourceSnapshot, publisher, progress, "Embedded Postgres source package changed while preparing a generation.");
|
|
5523
|
+
const manifest = await snapshotSealedManifest(stagedNativeDir, progress);
|
|
5524
|
+
if (manifest.sealedIdentity !== sourceSnapshot.sealedIdentity)
|
|
5464
5525
|
throw new Error("Embedded Postgres runtime changed after sealed validation and before publication.");
|
|
5465
|
-
}
|
|
5526
|
+
await writeFile(join(stagedNativeDir, RUNTIME_MARKER), JSON.stringify(manifest), { mode: 292, flag: "wx" });
|
|
5527
|
+
await chmod(join(stagedNativeDir, RUNTIME_MARKER), 292);
|
|
5466
5528
|
await assertSourceSnapshotUnchanged(sourceNativeDir, sourceSnapshot, publisher, progress, "Embedded Postgres source package changed while preparing a generation.");
|
|
5467
|
-
assertPublicationLease(options, "Embedded Postgres runtime publication lost its setup lease.");
|
|
5468
5529
|
await progress();
|
|
5469
|
-
|
|
5530
|
+
assertPublicationLease(options, "Embedded Postgres runtime publication lost its setup lease.");
|
|
5531
|
+
try {
|
|
5532
|
+
await (options.renameStage ?? rename)(stagedNativeDir, generationNativeDir);
|
|
5533
|
+
assertPublicationLease(options, "Embedded Postgres runtime lost its setup lease after publication.");
|
|
5534
|
+
legacyMemo.delete(generationNativeDir);
|
|
5535
|
+
corruptGenerationMemo.delete(generationNativeDir);
|
|
5536
|
+
} catch (error) {
|
|
5537
|
+
const code = error instanceof Error && "code" in error ? error.code : undefined;
|
|
5538
|
+
if (!["EEXIST", "ENOTEMPTY", "EPERM", "EACCES"].includes(String(code)) || !await lstatOrUndefined(generationNativeDir))
|
|
5539
|
+
throw error;
|
|
5540
|
+
if (await validatePreparedRuntime(generationNativeDir, {
|
|
5541
|
+
pg_ctl: join(generationNativeDir, "bin", basename(binaries.pg_ctl)),
|
|
5542
|
+
initdb: join(generationNativeDir, "bin", basename(binaries.initdb)),
|
|
5543
|
+
postgres: join(generationNativeDir, "bin", basename(binaries.postgres))
|
|
5544
|
+
}, progress, sourceSnapshot.sealedIdentity) !== sourceSnapshot.sealedIdentity)
|
|
5545
|
+
throw new CorruptRuntimeGenerationError("Concurrent runtime publication disagrees with its source.");
|
|
5546
|
+
assertPublicationLease(options, "Embedded Postgres runtime publication lost its setup lease.");
|
|
5547
|
+
return generationNativeDir;
|
|
5548
|
+
}
|
|
5470
5549
|
await options.afterPublish?.(generationNativeDir);
|
|
5471
|
-
|
|
5472
|
-
|
|
5550
|
+
try {
|
|
5551
|
+
if (await validatePreparedRuntime(generationNativeDir, {
|
|
5552
|
+
pg_ctl: join(generationNativeDir, "bin", basename(binaries.pg_ctl)),
|
|
5553
|
+
initdb: join(generationNativeDir, "bin", basename(binaries.initdb)),
|
|
5554
|
+
postgres: join(generationNativeDir, "bin", basename(binaries.postgres))
|
|
5555
|
+
}, progress, sourceSnapshot.sealedIdentity) !== sourceSnapshot.sealedIdentity)
|
|
5556
|
+
throw new CorruptRuntimeGenerationError("sealed identity mismatch");
|
|
5557
|
+
} catch (error) {
|
|
5558
|
+
if (error instanceof CorruptRuntimeGenerationError)
|
|
5559
|
+
throw new Error(`Embedded Postgres published runtime changed during publication: ${error.message}`, {
|
|
5560
|
+
cause: error
|
|
5561
|
+
});
|
|
5562
|
+
throw error;
|
|
5473
5563
|
}
|
|
5474
5564
|
await assertSourceSnapshotUnchanged(sourceNativeDir, sourceSnapshot, publisher, progress, "Embedded Postgres source package changed during publication.");
|
|
5475
5565
|
await options.afterPublishValidation?.(generationNativeDir);
|
|
@@ -5480,36 +5570,76 @@ async function findOrCreateRuntimeGeneration(sourceNativeDir, sourceSnapshot, co
|
|
|
5480
5570
|
await rm(stagedRoot, { recursive: true, force: true });
|
|
5481
5571
|
}
|
|
5482
5572
|
}
|
|
5573
|
+
async function ensureRuntimeCacheDirectory(path, publisher = publisherIdentity(), needsPrivilegeDrop = false, owner, inspect = lstat) {
|
|
5574
|
+
if (!isAbsolute(path))
|
|
5575
|
+
throw new Error(`Embedded Postgres runtime cache override must be absolute: ${path}`);
|
|
5576
|
+
await mkdir(path, { recursive: true, mode: 493 });
|
|
5577
|
+
const stat = await inspect(path);
|
|
5578
|
+
if (!stat.isDirectory() || stat.isSymbolicLink() || process.getuid !== undefined && stat.uid !== publisher.uid)
|
|
5579
|
+
throw new Error(`Untrusted embedded Postgres runtime cache directory: ${path}`);
|
|
5580
|
+
let ancestor = await realpath(path);
|
|
5581
|
+
while (true) {
|
|
5582
|
+
const info = await inspect(ancestor);
|
|
5583
|
+
if (!info.isDirectory() || process.platform !== "win32" && (info.uid !== 0 && info.uid !== publisher.uid || (info.mode & 18) !== 0 && (info.mode & 512) === 0))
|
|
5584
|
+
throw new Error(`Untrusted embedded Postgres runtime cache directory ancestor: ${ancestor}`);
|
|
5585
|
+
if (needsPrivilegeDrop && owner && publisher.uid === 0 && process.platform !== "win32") {
|
|
5586
|
+
const execute = info.uid === owner.uid ? 64 : info.gid === owner.gid ? 8 : 1;
|
|
5587
|
+
if ((info.mode & execute) === 0)
|
|
5588
|
+
throw new Error(`Embedded Postgres dropped owner cannot traverse runtime cache directory: ${ancestor}`);
|
|
5589
|
+
}
|
|
5590
|
+
const parent = dirname(ancestor);
|
|
5591
|
+
if (parent === ancestor)
|
|
5592
|
+
break;
|
|
5593
|
+
ancestor = parent;
|
|
5594
|
+
}
|
|
5595
|
+
if (needsPrivilegeDrop)
|
|
5596
|
+
await chown(path, publisher.uid, publisher.gid);
|
|
5597
|
+
await chmod(path, 493);
|
|
5598
|
+
}
|
|
5483
5599
|
|
|
5484
5600
|
class SourceRuntimeChangedError extends Error {
|
|
5485
5601
|
}
|
|
5602
|
+
|
|
5603
|
+
class RuntimePublicationLeaseLostError extends Error {
|
|
5604
|
+
}
|
|
5605
|
+
|
|
5606
|
+
class CorruptRuntimeGenerationError extends Error {
|
|
5607
|
+
}
|
|
5608
|
+
|
|
5609
|
+
class RuntimeGenerationMissingError extends Error {
|
|
5610
|
+
}
|
|
5611
|
+
function isCorruptRuntimeGeneration(error, candidate) {
|
|
5612
|
+
if (error instanceof CorruptRuntimeGenerationError)
|
|
5613
|
+
return true;
|
|
5614
|
+
if (!(error instanceof Error))
|
|
5615
|
+
return false;
|
|
5616
|
+
const code = "code" in error ? error.code : undefined;
|
|
5617
|
+
const path = "path" in error ? error.path : undefined;
|
|
5618
|
+
return (code === "ENOENT" || code === "ENOTDIR" || code === "ELOOP" || code === "EACCES") && typeof path === "string" && (path === candidate || path.startsWith(`${candidate}${sep}`));
|
|
5619
|
+
}
|
|
5486
5620
|
async function assertSourceSnapshotUnchanged(sourceNativeDir, expected, publisher, progress, message) {
|
|
5487
|
-
const current = await
|
|
5621
|
+
const current = await memoizedSourceSnapshot(sourceNativeDir, process.env.ATOMIC_POSTGRES_RUNTIME_CACHE_DIR ?? "", publisher, progress);
|
|
5488
5622
|
if (current.sourceIdentity !== expected.sourceIdentity || current.sealedIdentity !== expected.sealedIdentity) {
|
|
5489
5623
|
throw new SourceRuntimeChangedError(message);
|
|
5490
5624
|
}
|
|
5491
5625
|
}
|
|
5492
5626
|
function assertPublicationLease(options, message) {
|
|
5493
5627
|
if (options.publicationLease !== undefined && !options.publicationLease.refresh())
|
|
5494
|
-
throw new
|
|
5628
|
+
throw new RuntimePublicationLeaseLostError(message);
|
|
5495
5629
|
}
|
|
5496
5630
|
function runtimeProgress(options) {
|
|
5497
5631
|
let operations = 0;
|
|
5498
5632
|
const yieldToEventLoop = options.yieldToEventLoop ?? (() => new Promise((resolve) => setImmediate(resolve)));
|
|
5499
|
-
return async () => {
|
|
5500
|
-
if (
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
if (
|
|
5505
|
-
|
|
5506
|
-
if (options.publicationLease !== undefined && !options.publicationLease.refresh()) {
|
|
5507
|
-
throw new Error("Embedded Postgres runtime publication lost its setup lease.");
|
|
5508
|
-
}
|
|
5509
|
-
}
|
|
5633
|
+
return Object.assign(async () => {
|
|
5634
|
+
if (options.publicationLease?.isLost?.())
|
|
5635
|
+
throw new RuntimePublicationLeaseLostError("Embedded Postgres runtime publication lost its setup lease.");
|
|
5636
|
+
if (operations > 0 && operations % TRAVERSAL_OPERATIONS_PER_YIELD === 0) {
|
|
5637
|
+
await yieldToEventLoop();
|
|
5638
|
+
if (options.publicationLease?.isLost?.())
|
|
5639
|
+
throw new RuntimePublicationLeaseLostError("Embedded Postgres runtime publication lost its setup lease.");
|
|
5510
5640
|
}
|
|
5511
5641
|
operations += 1;
|
|
5512
|
-
};
|
|
5642
|
+
}, { onContentRead: options.onContentRead });
|
|
5513
5643
|
}
|
|
5514
5644
|
async function snapshotSourceRuntime(root, publisher, progress) {
|
|
5515
5645
|
const rootStat = await lstat(root);
|
|
@@ -5543,46 +5673,300 @@ async function hashSourceEntry(sourceHash, sealedHash, path, relativePath, rootR
|
|
|
5543
5673
|
await hashFileInto([sourceHash, sealedHash], path, progress);
|
|
5544
5674
|
return;
|
|
5545
5675
|
}
|
|
5546
|
-
throw new
|
|
5676
|
+
throw new CorruptRuntimeGenerationError(`Embedded Postgres runtime contains an unsupported entry: ${relativePath}`);
|
|
5677
|
+
}
|
|
5678
|
+
async function memoizedSourceSnapshot(root, cacheDir, publisher, progress, options = {}) {
|
|
5679
|
+
const realRoot = await realpath(root);
|
|
5680
|
+
const key = `${publisher.uid}:${publisher.gid}:${realRoot}`;
|
|
5681
|
+
const packageSignature = await installedPackageSignature(realRoot);
|
|
5682
|
+
const indexPath = cacheDir ? join(cacheDir, ".atomic-source-index.json") : undefined;
|
|
5683
|
+
const cached = sourceMemo.get(key);
|
|
5684
|
+
const refreshSource = options.refreshSourceSnapshot ?? options.repairCorruptGeneration === true;
|
|
5685
|
+
if (!refreshSource && packageSignature !== undefined && cached !== undefined && (cached.packageSignature ?? cached.signature) === packageSignature)
|
|
5686
|
+
return cached.snapshot;
|
|
5687
|
+
let index = {};
|
|
5688
|
+
if (indexPath) {
|
|
5689
|
+
try {
|
|
5690
|
+
const stat = await lstat(indexPath);
|
|
5691
|
+
if (!stat.isFile() || stat.isSymbolicLink() || process.getuid !== undefined && stat.uid !== publisher.uid || process.platform !== "win32" && (stat.mode & 18) !== 0)
|
|
5692
|
+
throw new Error("Untrusted source index");
|
|
5693
|
+
index = JSON.parse(await readFile(indexPath, "utf8"));
|
|
5694
|
+
if (!index || typeof index !== "object" || Array.isArray(index))
|
|
5695
|
+
throw new Error("Invalid source index");
|
|
5696
|
+
const entry = index[key];
|
|
5697
|
+
if (!refreshSource && packageSignature !== undefined && (entry?.packageSignature ?? entry?.signature) === packageSignature && /^[a-f0-9]{64}$/.test(entry.snapshot?.sourceIdentity) && /^[a-f0-9]{64}$/.test(entry.snapshot?.sealedIdentity)) {
|
|
5698
|
+
sourceMemo.set(key, entry);
|
|
5699
|
+
return entry.snapshot;
|
|
5700
|
+
}
|
|
5701
|
+
} catch {
|
|
5702
|
+
index = {};
|
|
5703
|
+
}
|
|
5704
|
+
}
|
|
5705
|
+
options.onSourceStatPass?.();
|
|
5706
|
+
const entries = await statRuntimeEntries(root, progress, true);
|
|
5707
|
+
const signature = JSON.stringify([realRoot, entries]);
|
|
5708
|
+
if (!refreshSource && cached?.signature === signature && (packageSignature === undefined || cached.packageSignature === packageSignature) && !sourceEntriesRacy(entries, cached.indexWrittenAt))
|
|
5709
|
+
return cached.snapshot;
|
|
5710
|
+
const entry = index[key];
|
|
5711
|
+
if (entry?.signature === signature && (packageSignature === undefined || entry.packageSignature === packageSignature) && !sourceEntriesRacy(entries, entry.indexWrittenAt) && /^[a-f0-9]{64}$/.test(entry.snapshot?.sourceIdentity) && /^[a-f0-9]{64}$/.test(entry.snapshot?.sealedIdentity)) {
|
|
5712
|
+
sourceMemo.set(key, entry);
|
|
5713
|
+
return entry.snapshot;
|
|
5714
|
+
}
|
|
5715
|
+
if (refreshSource)
|
|
5716
|
+
sourceMemo.delete(key);
|
|
5717
|
+
const snapshot = await snapshotSourceRuntime(root, publisher, progress);
|
|
5718
|
+
options.onSourceStatPass?.();
|
|
5719
|
+
if (signature !== JSON.stringify([await realpath(root), await statRuntimeEntries(root, progress, true)]))
|
|
5720
|
+
throw new SourceRuntimeChangedError("Embedded Postgres source package changed during snapshot.");
|
|
5721
|
+
const indexed = { snapshot, signature, packageSignature, indexWrittenAt: Date.now() };
|
|
5722
|
+
sourceMemo.set(key, indexed);
|
|
5723
|
+
if (indexPath) {
|
|
5724
|
+
await ensureRuntimeCacheDirectory(cacheDir, publisher);
|
|
5725
|
+
const temporary = `${indexPath}.${process.pid}-${crypto.randomUUID()}`;
|
|
5726
|
+
try {
|
|
5727
|
+
await writeFile(temporary, JSON.stringify({ ...index, [key]: indexed }), { mode: 384, flag: "wx" });
|
|
5728
|
+
await rename(temporary, indexPath);
|
|
5729
|
+
} catch {
|
|
5730
|
+
return snapshot;
|
|
5731
|
+
} finally {
|
|
5732
|
+
await rm(temporary, { force: true });
|
|
5733
|
+
}
|
|
5734
|
+
}
|
|
5735
|
+
return snapshot;
|
|
5736
|
+
}
|
|
5737
|
+
async function installedPackageSignature(realRoot) {
|
|
5738
|
+
if (process.env.ATOMIC_POSTGRES_RUNTIME_DIR !== undefined || !["native", "postgres-runtime"].includes(basename(realRoot)))
|
|
5739
|
+
return;
|
|
5740
|
+
const packageRoot = dirname(realRoot);
|
|
5741
|
+
const nodeModules = packageRoot.lastIndexOf(`${sep}node_modules${sep}`);
|
|
5742
|
+
if (nodeModules < 0)
|
|
5743
|
+
return;
|
|
5744
|
+
try {
|
|
5745
|
+
const manifest = JSON.parse(await readFile(join(packageRoot, "package.json"), "utf8"));
|
|
5746
|
+
if (!manifest.name || !manifest.version)
|
|
5747
|
+
return;
|
|
5748
|
+
const lockRoot = packageRoot.slice(0, nodeModules + `${sep}node_modules`.length);
|
|
5749
|
+
let installed;
|
|
5750
|
+
try {
|
|
5751
|
+
const lock = JSON.parse(await readFile(join(lockRoot, ".package-lock.json"), "utf8"));
|
|
5752
|
+
const lockKey = `node_modules/${relative(lockRoot, packageRoot).split(sep).join("/")}`;
|
|
5753
|
+
installed = lock.packages?.[lockKey];
|
|
5754
|
+
} catch {
|
|
5755
|
+
installed = undefined;
|
|
5756
|
+
}
|
|
5757
|
+
if (installed?.version !== undefined && installed.version !== manifest.version)
|
|
5758
|
+
return;
|
|
5759
|
+
return JSON.stringify([
|
|
5760
|
+
await realpath(packageRoot),
|
|
5761
|
+
manifest.name,
|
|
5762
|
+
manifest.version,
|
|
5763
|
+
installed?.integrity,
|
|
5764
|
+
installed?.resolved
|
|
5765
|
+
]);
|
|
5766
|
+
} catch {
|
|
5767
|
+
return;
|
|
5768
|
+
}
|
|
5547
5769
|
}
|
|
5548
|
-
|
|
5770
|
+
function sourceEntriesRacy(entries, indexWrittenAt) {
|
|
5771
|
+
if (!Number.isFinite(indexWrittenAt))
|
|
5772
|
+
return true;
|
|
5773
|
+
return entries.some((entry) => {
|
|
5774
|
+
const fields = entry[5]?.split(":");
|
|
5775
|
+
if (!fields || fields.length < 7)
|
|
5776
|
+
return true;
|
|
5777
|
+
return Number(fields.at(-5)) >= indexWrittenAt - 2000 || Number(fields.at(-4)) >= indexWrittenAt - 2000;
|
|
5778
|
+
});
|
|
5779
|
+
}
|
|
5780
|
+
async function validatePreparedRuntime(root, binaries, progress, expected, options = {}) {
|
|
5781
|
+
const marker = join(root, RUNTIME_MARKER);
|
|
5782
|
+
await requiredRuntimeFiles(root, binaries);
|
|
5783
|
+
const markerStat = await lstatOrUndefined(marker);
|
|
5784
|
+
const markerIdentity = markerStat && `${markerStat.dev}:${markerStat.ino}:${markerStat.size}:${markerStat.mtimeMs}:${markerStat.ctimeMs}`;
|
|
5785
|
+
if (options.fullValidation)
|
|
5786
|
+
validatedMemo.delete(root);
|
|
5787
|
+
const cached = validatedMemo.get(root);
|
|
5788
|
+
if (options.quickValidation && markerStat?.isFile() && (markerStat.mode & 146) === 0) {
|
|
5789
|
+
let manifest;
|
|
5790
|
+
try {
|
|
5791
|
+
manifest = JSON.parse(await readFile(marker, "utf8"));
|
|
5792
|
+
} catch {
|
|
5793
|
+
throw new CorruptRuntimeGenerationError("invalid runtime completion marker");
|
|
5794
|
+
}
|
|
5795
|
+
if (manifest.version !== 1 || !Array.isArray(manifest.entries) || !/^[a-f0-9]{64}$/.test(manifest.sealedIdentity))
|
|
5796
|
+
throw new CorruptRuntimeGenerationError("invalid runtime completion marker");
|
|
5797
|
+
return manifest.sealedIdentity;
|
|
5798
|
+
}
|
|
5799
|
+
if (options.memoizedValidation && !options.fullValidation && markerIdentity && cached?.marker === markerIdentity && (expected === undefined || expected === cached.identity)) {
|
|
5800
|
+
return cached.identity;
|
|
5801
|
+
}
|
|
5802
|
+
let manifest;
|
|
5803
|
+
try {
|
|
5804
|
+
const markerStat = await lstat(marker);
|
|
5805
|
+
if (!markerStat.isFile() || (markerStat.mode & 146) !== 0)
|
|
5806
|
+
throw new CorruptRuntimeGenerationError("untrusted runtime completion marker");
|
|
5807
|
+
const text = await readFile(marker, "utf8");
|
|
5808
|
+
manifest = JSON.parse(text);
|
|
5809
|
+
if (manifest.version !== 1 || !Array.isArray(manifest.entries) || !/^[a-f0-9]{64}$/.test(manifest.sealedIdentity))
|
|
5810
|
+
throw new CorruptRuntimeGenerationError("invalid runtime completion marker");
|
|
5811
|
+
} catch (error) {
|
|
5812
|
+
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT") {
|
|
5813
|
+
if (error instanceof CorruptRuntimeGenerationError)
|
|
5814
|
+
throw error;
|
|
5815
|
+
throw new CorruptRuntimeGenerationError("invalid runtime completion marker");
|
|
5816
|
+
}
|
|
5817
|
+
const cached = legacyMemo.get(root);
|
|
5818
|
+
if (cached !== undefined)
|
|
5819
|
+
manifest = cached;
|
|
5820
|
+
else {
|
|
5821
|
+
manifest = await snapshotSealedManifest(root, progress);
|
|
5822
|
+
if (expected !== undefined && manifest.sealedIdentity !== expected)
|
|
5823
|
+
throw new CorruptRuntimeGenerationError("legacy sealed identity mismatch");
|
|
5824
|
+
legacyMemo.set(root, manifest);
|
|
5825
|
+
}
|
|
5826
|
+
}
|
|
5827
|
+
options.onValidation?.();
|
|
5828
|
+
const entries = await statRuntimeEntries(root, progress, false);
|
|
5829
|
+
const metadataChanged = JSON.stringify(entries.map((entry) => entry[0] === "." ? entry.slice(0, 6) : entry)) !== JSON.stringify(manifest.entries.map((entry) => entry[0] === "." ? entry.slice(0, 6) : entry));
|
|
5830
|
+
if (metadataChanged) {
|
|
5831
|
+
if (JSON.stringify(entries.map((entry) => entry.slice(0, 6))) !== JSON.stringify(manifest.entries.map((entry) => entry.slice(0, 6))))
|
|
5832
|
+
throw new CorruptRuntimeGenerationError("runtime completion manifest mismatch");
|
|
5833
|
+
if ((await snapshotSealedManifest(root, progress)).sealedIdentity !== manifest.sealedIdentity)
|
|
5834
|
+
throw new CorruptRuntimeGenerationError("runtime completion manifest mismatch");
|
|
5835
|
+
}
|
|
5836
|
+
for (const binary of [binaries.pg_ctl, binaries.initdb, binaries.postgres]) {
|
|
5837
|
+
if (!entries.some(([name, kind]) => name === relative(root, binary) && kind === "file"))
|
|
5838
|
+
throw new CorruptRuntimeGenerationError("required Postgres executable missing");
|
|
5839
|
+
}
|
|
5840
|
+
const timezone = join("share", ...binaries.postgres.endsWith(".exe") ? [] : ["postgresql"], "timezonesets", "Default");
|
|
5841
|
+
if (entries.some(([name]) => name === "share") && !entries.some(([name, kind]) => name === timezone && kind === "file"))
|
|
5842
|
+
throw new CorruptRuntimeGenerationError("required Postgres timezone data missing");
|
|
5843
|
+
if (markerIdentity)
|
|
5844
|
+
validatedMemo.set(root, { marker: markerIdentity, identity: manifest.sealedIdentity });
|
|
5845
|
+
return manifest.sealedIdentity;
|
|
5846
|
+
}
|
|
5847
|
+
async function requiredRuntimeFiles(root, binaries) {
|
|
5848
|
+
for (const binary of [binaries.postgres, binaries.pg_ctl, binaries.initdb]) {
|
|
5849
|
+
if (!(await lstatOrUndefined(binary))?.isFile())
|
|
5850
|
+
throw new CorruptRuntimeGenerationError("required Postgres executable missing");
|
|
5851
|
+
}
|
|
5852
|
+
const share = join(root, "share");
|
|
5853
|
+
if (await lstatOrUndefined(share)) {
|
|
5854
|
+
const timezone = join(share, ...binaries.postgres.endsWith(".exe") ? [] : ["postgresql"], "timezonesets", "Default");
|
|
5855
|
+
if (!(await lstatOrUndefined(timezone))?.isFile())
|
|
5856
|
+
throw new CorruptRuntimeGenerationError("required Postgres timezone data missing");
|
|
5857
|
+
}
|
|
5858
|
+
}
|
|
5859
|
+
async function statRuntimeEntries(root, progress, source) {
|
|
5860
|
+
const entries = [];
|
|
5861
|
+
const rootStat = await lstat(root);
|
|
5862
|
+
assertRuntimeRoot(root, rootStat);
|
|
5863
|
+
const realRoot = await realpath(root);
|
|
5864
|
+
const visit = async (path, name) => {
|
|
5865
|
+
await progress();
|
|
5866
|
+
const info = await lstat(path);
|
|
5867
|
+
const suffix = source ? `${info.size}:${info.mode & 511}:${info.mtimeMs}:${info.ctimeMs}:${info.birthtimeMs}:${info.dev}:${info.ino}` : undefined;
|
|
5868
|
+
if (info.isSymbolicLink()) {
|
|
5869
|
+
const target = await validatedLinkTarget(path, name, realRoot);
|
|
5870
|
+
entries.push([
|
|
5871
|
+
name,
|
|
5872
|
+
"link",
|
|
5873
|
+
0,
|
|
5874
|
+
info.uid,
|
|
5875
|
+
info.gid,
|
|
5876
|
+
source ? `${target}:${suffix}` : target,
|
|
5877
|
+
source ? undefined : [info.ctimeMs, info.ino, info.dev]
|
|
5878
|
+
]);
|
|
5879
|
+
} else if (info.isDirectory()) {
|
|
5880
|
+
entries.push(source ? [name, "directory", info.mode & 511, info.uid, info.gid, suffix] : name === "." ? [name, "directory", info.mode & 511, info.uid, info.gid, undefined] : [
|
|
5881
|
+
name,
|
|
5882
|
+
"directory",
|
|
5883
|
+
info.mode & 511,
|
|
5884
|
+
info.uid,
|
|
5885
|
+
info.gid,
|
|
5886
|
+
undefined,
|
|
5887
|
+
[info.ctimeMs, info.ino, info.dev]
|
|
5888
|
+
]);
|
|
5889
|
+
for (const child of (await readdir(path)).sort()) {
|
|
5890
|
+
if (!source && name === "." && child === RUNTIME_MARKER)
|
|
5891
|
+
continue;
|
|
5892
|
+
await visit(join(path, child), name === "." ? child : join(name, child));
|
|
5893
|
+
}
|
|
5894
|
+
} else if (info.isFile()) {
|
|
5895
|
+
entries.push([
|
|
5896
|
+
name,
|
|
5897
|
+
"file",
|
|
5898
|
+
info.mode & 511,
|
|
5899
|
+
info.uid,
|
|
5900
|
+
info.gid,
|
|
5901
|
+
source ? `${info.size}:${suffix}` : String(info.size),
|
|
5902
|
+
source ? undefined : [info.ctimeMs, info.ino, info.dev]
|
|
5903
|
+
]);
|
|
5904
|
+
} else
|
|
5905
|
+
throw new CorruptRuntimeGenerationError(`Unsupported runtime entry: ${name}`);
|
|
5906
|
+
};
|
|
5907
|
+
await visit(root, ".");
|
|
5908
|
+
return entries;
|
|
5909
|
+
}
|
|
5910
|
+
async function snapshotSealedManifest(root, progress) {
|
|
5549
5911
|
const rootStat = await lstat(root);
|
|
5550
5912
|
assertRuntimeRoot(root, rootStat);
|
|
5551
5913
|
const rootRealPath = await realpath(root);
|
|
5552
5914
|
const hash = createHash("sha256");
|
|
5553
|
-
|
|
5554
|
-
|
|
5915
|
+
const entries = [];
|
|
5916
|
+
await hashSealedEntry(hash, root, ".", rootRealPath, progress, entries);
|
|
5917
|
+
return { version: 1, sealedIdentity: hash.digest("hex"), entries };
|
|
5555
5918
|
}
|
|
5556
|
-
async function hashSealedEntry(hash, path, relativePath, rootRealPath, progress) {
|
|
5919
|
+
async function hashSealedEntry(hash, path, relativePath, rootRealPath, progress, entries) {
|
|
5557
5920
|
await progress();
|
|
5558
5921
|
const stat = await lstat(path);
|
|
5559
5922
|
if (stat.isSymbolicLink()) {
|
|
5560
5923
|
const target = await validatedLinkTarget(path, relativePath, rootRealPath);
|
|
5924
|
+
entries.push([relativePath, "link", 0, stat.uid, stat.gid, target, [stat.ctimeMs, stat.ino, stat.dev]]);
|
|
5561
5925
|
hashField(hash, "link", relativePath, String(stat.uid), String(stat.gid), target);
|
|
5562
5926
|
return;
|
|
5563
5927
|
}
|
|
5564
5928
|
if (stat.isDirectory()) {
|
|
5565
5929
|
hashField(hash, "directory", relativePath, String(stat.mode & 511), String(stat.uid), String(stat.gid));
|
|
5930
|
+
entries.push(relativePath === "." ? [relativePath, "directory", stat.mode & 511, stat.uid, stat.gid, undefined] : [
|
|
5931
|
+
relativePath,
|
|
5932
|
+
"directory",
|
|
5933
|
+
stat.mode & 511,
|
|
5934
|
+
stat.uid,
|
|
5935
|
+
stat.gid,
|
|
5936
|
+
undefined,
|
|
5937
|
+
[stat.ctimeMs, stat.ino, stat.dev]
|
|
5938
|
+
]);
|
|
5566
5939
|
for (const entry of (await readdir(path)).sort()) {
|
|
5567
|
-
|
|
5940
|
+
if (relativePath === "." && entry === RUNTIME_MARKER)
|
|
5941
|
+
continue;
|
|
5942
|
+
await hashSealedEntry(hash, join(path, entry), relativePath === "." ? entry : join(relativePath, entry), rootRealPath, progress, entries);
|
|
5568
5943
|
}
|
|
5569
5944
|
return;
|
|
5570
5945
|
}
|
|
5571
5946
|
if (stat.isFile()) {
|
|
5947
|
+
entries.push([
|
|
5948
|
+
relativePath,
|
|
5949
|
+
"file",
|
|
5950
|
+
stat.mode & 511,
|
|
5951
|
+
stat.uid,
|
|
5952
|
+
stat.gid,
|
|
5953
|
+
String(stat.size),
|
|
5954
|
+
[stat.ctimeMs, stat.ino, stat.dev]
|
|
5955
|
+
]);
|
|
5572
5956
|
hashField(hash, "file", relativePath, String(stat.mode & 511), String(stat.uid), String(stat.gid), String(stat.size));
|
|
5573
5957
|
await hashFileInto([hash], path, progress);
|
|
5574
5958
|
return;
|
|
5575
5959
|
}
|
|
5576
|
-
throw new
|
|
5960
|
+
throw new CorruptRuntimeGenerationError(`Embedded Postgres runtime contains an unsupported entry: ${relativePath}`);
|
|
5577
5961
|
}
|
|
5578
5962
|
async function validatedLinkTarget(path, relativePath, rootRealPath) {
|
|
5579
5963
|
const target = await readlink(path);
|
|
5580
5964
|
if (isAbsolute(target))
|
|
5581
|
-
throw new
|
|
5965
|
+
throw new CorruptRuntimeGenerationError(`Embedded Postgres runtime contains an absolute link: ${relativePath}`);
|
|
5582
5966
|
const resolvedTarget = await realpath(path);
|
|
5583
5967
|
const targetFromRoot = relative(rootRealPath, resolvedTarget);
|
|
5584
5968
|
if (targetFromRoot === ".." || targetFromRoot.startsWith(`..${sep}`) || isAbsolute(targetFromRoot)) {
|
|
5585
|
-
throw new
|
|
5969
|
+
throw new CorruptRuntimeGenerationError(`Embedded Postgres runtime link escapes its tree: ${relativePath}`);
|
|
5586
5970
|
}
|
|
5587
5971
|
return target;
|
|
5588
5972
|
}
|
|
@@ -5595,6 +5979,7 @@ async function hashFileInto(hashes, path, progress) {
|
|
|
5595
5979
|
if (bytesRead === 0)
|
|
5596
5980
|
return;
|
|
5597
5981
|
const chunk = buffer.subarray(0, bytesRead);
|
|
5982
|
+
progress.onContentRead?.(path);
|
|
5598
5983
|
for (const hash of hashes)
|
|
5599
5984
|
hash.update(chunk);
|
|
5600
5985
|
await progress();
|
|
@@ -5603,10 +5988,12 @@ async function hashFileInto(hashes, path, progress) {
|
|
|
5603
5988
|
await handle.close();
|
|
5604
5989
|
}
|
|
5605
5990
|
}
|
|
5606
|
-
async function sealRuntimeForPublisher(runtimeDir, publisher, runner, progress) {
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5991
|
+
async function sealRuntimeForPublisher(runtimeDir, publisher, runner, progress, needsPrivilegeDrop) {
|
|
5992
|
+
if (needsPrivilegeDrop) {
|
|
5993
|
+
const result = await runner("chown", ["-R", `${publisher.uid}:${publisher.gid}`, runtimeDir]);
|
|
5994
|
+
if (result.exitCode !== 0) {
|
|
5995
|
+
throw new Error(`Could not seal the copied embedded Postgres runtime: ${result.stderr.trim() || result.stdout.trim() || `exit ${result.exitCode}`}`);
|
|
5996
|
+
}
|
|
5610
5997
|
}
|
|
5611
5998
|
await sealRuntimeModes(runtimeDir, progress, true);
|
|
5612
5999
|
}
|
|
@@ -5655,7 +6042,7 @@ function publisherIdentity() {
|
|
|
5655
6042
|
}
|
|
5656
6043
|
function assertRuntimeRoot(root, stat) {
|
|
5657
6044
|
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
5658
|
-
throw new
|
|
6045
|
+
throw new CorruptRuntimeGenerationError(`Embedded Postgres runtime must be a real directory: ${root}`);
|
|
5659
6046
|
}
|
|
5660
6047
|
}
|
|
5661
6048
|
async function lstatOrUndefined(path) {
|
|
@@ -5757,6 +6144,13 @@ function resolveEmbeddedPostgresTarget(host) {
|
|
|
5757
6144
|
// dist/builtin/workflows/src/durable/dbos-postgres-health.ts
|
|
5758
6145
|
var HEALTH_INTERVAL_MS = 5000;
|
|
5759
6146
|
var RECOVERY_ATTEMPTS = 3;
|
|
6147
|
+
function isMonitoringConnectionFailure(error) {
|
|
6148
|
+
if (!(error instanceof Error))
|
|
6149
|
+
return false;
|
|
6150
|
+
if ("code" in error)
|
|
6151
|
+
return ["ECONNREFUSED", "ECONNRESET", "EPIPE", "ETIMEDOUT", "57P01", "57P02", "57P03"].includes(String(error.code));
|
|
6152
|
+
return error.message === "timeout expired" || error.message === "Connection terminated due to connection timeout";
|
|
6153
|
+
}
|
|
5760
6154
|
|
|
5761
6155
|
class PostgresHealth {
|
|
5762
6156
|
operations;
|
|
@@ -5765,6 +6159,7 @@ class PostgresHealth {
|
|
|
5765
6159
|
stopped = false;
|
|
5766
6160
|
available;
|
|
5767
6161
|
attempts = 0;
|
|
6162
|
+
nextRecoveryAt = 0;
|
|
5768
6163
|
failure;
|
|
5769
6164
|
revision = 0;
|
|
5770
6165
|
listeners = new Set;
|
|
@@ -5822,7 +6217,21 @@ class PostgresHealth {
|
|
|
5822
6217
|
}
|
|
5823
6218
|
async probe() {
|
|
5824
6219
|
const revision = this.revision;
|
|
5825
|
-
|
|
6220
|
+
let identity;
|
|
6221
|
+
try {
|
|
6222
|
+
identity = await this.operations.probe();
|
|
6223
|
+
} catch (error) {
|
|
6224
|
+
if (!isMonitoringConnectionFailure(error) || this.stopped)
|
|
6225
|
+
throw error;
|
|
6226
|
+
try {
|
|
6227
|
+
identity = await this.operations.probe();
|
|
6228
|
+
} catch (retryError) {
|
|
6229
|
+
if (!isMonitoringConnectionFailure(retryError))
|
|
6230
|
+
throw retryError;
|
|
6231
|
+
this.failure = retryError;
|
|
6232
|
+
return;
|
|
6233
|
+
}
|
|
6234
|
+
}
|
|
5826
6235
|
if (revision !== this.revision)
|
|
5827
6236
|
return;
|
|
5828
6237
|
if (this.stopped)
|
|
@@ -5833,6 +6242,7 @@ class PostgresHealth {
|
|
|
5833
6242
|
this.invalidate();
|
|
5834
6243
|
this.available = identity;
|
|
5835
6244
|
this.attempts = 0;
|
|
6245
|
+
this.nextRecoveryAt = 0;
|
|
5836
6246
|
return identity.url;
|
|
5837
6247
|
}
|
|
5838
6248
|
async refresh() {
|
|
@@ -5849,6 +6259,8 @@ class PostgresHealth {
|
|
|
5849
6259
|
if (this.attempts === 0)
|
|
5850
6260
|
this.failure = new DbosDependencyError("Managed PostgreSQL failed its live health check.");
|
|
5851
6261
|
this.invalidate();
|
|
6262
|
+
if ((this.operations.now ?? Date.now)() < this.nextRecoveryAt)
|
|
6263
|
+
throw new DbosDependencyError("Managed Postgres recovery is cooling down after bounded attempts.");
|
|
5852
6264
|
while (!this.stopped && this.attempts < RECOVERY_ATTEMPTS) {
|
|
5853
6265
|
const attempt = this.attempts++;
|
|
5854
6266
|
if (attempt > 0)
|
|
@@ -5864,15 +6276,18 @@ class PostgresHealth {
|
|
|
5864
6276
|
this.failure = error instanceof Error ? error : new Error(String(error));
|
|
5865
6277
|
}
|
|
5866
6278
|
}
|
|
6279
|
+
this.attempts = 0;
|
|
6280
|
+
this.nextRecoveryAt = (this.operations.now ?? Date.now)() + HEALTH_INTERVAL_MS;
|
|
5867
6281
|
throw new DbosDependencyError("Managed Postgres is unavailable after bounded recovery. Preserve its data and ownership records.");
|
|
5868
6282
|
}
|
|
5869
6283
|
}
|
|
5870
6284
|
|
|
5871
6285
|
// dist/builtin/workflows/src/durable/dbos-postgres-identity.ts
|
|
5872
6286
|
import { existsSync as existsSync2, lstatSync as lstatSync2, readFileSync as readFileSync2, realpathSync as realpathSync2 } from "node:fs";
|
|
6287
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
5873
6288
|
import { createServer } from "node:net";
|
|
5874
6289
|
import { endianness } from "node:os";
|
|
5875
|
-
import { join as join3 } from "node:path";
|
|
6290
|
+
import { dirname as dirname2, isAbsolute as isAbsolute2, join as join3 } from "node:path";
|
|
5876
6291
|
|
|
5877
6292
|
// dist/builtin/workflows/src/durable/dbos-postgres-ownership.ts
|
|
5878
6293
|
import { randomUUID } from "node:crypto";
|
|
@@ -6037,6 +6452,30 @@ function availablePostgresPort(preferred) {
|
|
|
6037
6452
|
});
|
|
6038
6453
|
});
|
|
6039
6454
|
}
|
|
6455
|
+
function managedPostgresRuntimeHealthy(metadata, port = metadata.server?.port) {
|
|
6456
|
+
return postgresRuntimeFilesExist(managedPostgresLaunchExecutable(metadata, port));
|
|
6457
|
+
}
|
|
6458
|
+
function managedPostgresLaunchExecutable(metadata, port = metadata.server?.port) {
|
|
6459
|
+
const optsPath = join3(metadata.dataDir, "postmaster.opts");
|
|
6460
|
+
if (!lstatSync2(optsPath).isFile())
|
|
6461
|
+
throw new Error("Managed Postgres launch options are missing or untrusted.");
|
|
6462
|
+
const command = readFileSync2(optsPath, "utf8").trimEnd();
|
|
6463
|
+
const launch = /^(.*[\\/]postgres(?:\.exe)?) "-D" "([^"]+)" "-p" "(\d+)" "-c" "listen_addresses=127\.0\.0\.1"/.exec(command);
|
|
6464
|
+
const collector = ' "-c" "logging_collector=on" "-c" "log_directory=log" "-c" "log_filename=postgresql-%a.log" "-c" "log_truncate_on_rotation=on" "-c" "log_rotation_age=1d" "-c" "log_rotation_size=0"';
|
|
6465
|
+
const unsafe = ' "-c" "fsync=off" "-c" "synchronous_commit=off" "-c" "full_page_writes=off"';
|
|
6466
|
+
if (!launch || !isAbsolute2(launch[1]) || !isAbsolute2(launch[2]) || !["", collector, collector + unsafe].includes(command.slice(launch[0].length))) {
|
|
6467
|
+
throw new Error("Managed Postgres launch options do not identify Atomic's PostgreSQL runtime.");
|
|
6468
|
+
}
|
|
6469
|
+
if (realpathSync2(launch[2]) !== metadata.dataDir || port !== undefined && Number(launch[3]) !== port) {
|
|
6470
|
+
throw new Error("Managed Postgres launch options do not match its owned data directory and port.");
|
|
6471
|
+
}
|
|
6472
|
+
return launch[1];
|
|
6473
|
+
}
|
|
6474
|
+
function postgresRuntimeFilesExist(postgres) {
|
|
6475
|
+
const native = dirname2(dirname2(postgres));
|
|
6476
|
+
const timezoneSets = join3(native, "share", ...postgres.endsWith(".exe") ? [] : ["postgresql"], "timezonesets");
|
|
6477
|
+
return lstatSync2(postgres, { throwIfNoEntry: false })?.isFile() === true && lstatSync2(timezoneSets, { throwIfNoEntry: false })?.isDirectory() === true && lstatSync2(join3(timezoneSets, "Default"), { throwIfNoEntry: false })?.isFile() === true;
|
|
6478
|
+
}
|
|
6040
6479
|
function managedPostmaster(metadata) {
|
|
6041
6480
|
const systemIdentifier = managedSystemIdentifier(metadata);
|
|
6042
6481
|
const path = join3(metadata.dataDir, "postmaster.pid");
|
|
@@ -6073,6 +6512,27 @@ var POSTGRES_IDENTITY_SQL = `SELECT current_setting('data_directory') AS data_di
|
|
|
6073
6512
|
inet_server_port() AS port, host(inet_server_addr()) AS host,
|
|
6074
6513
|
split_part(pg_read_file('postmaster.pid'), E'\\n', 3) AS started,
|
|
6075
6514
|
system_identifier::text, current_setting('server_version') AS server_version FROM pg_control_system()`;
|
|
6515
|
+
var POSTGRES_TIMEZONE_SQL = "SELECT set_config('timezone_abbreviations', 'Default', true)";
|
|
6516
|
+
async function probePostgresTimezoneData(port) {
|
|
6517
|
+
const client = new Client({
|
|
6518
|
+
host: "127.0.0.1",
|
|
6519
|
+
port,
|
|
6520
|
+
user: "postgres",
|
|
6521
|
+
password: "atomic",
|
|
6522
|
+
database: "postgres",
|
|
6523
|
+
ssl: false,
|
|
6524
|
+
connectionTimeoutMillis: 1000,
|
|
6525
|
+
query_timeout: 1000,
|
|
6526
|
+
statement_timeout: 1000
|
|
6527
|
+
});
|
|
6528
|
+
client.on("error", () => {});
|
|
6529
|
+
try {
|
|
6530
|
+
await client.connect();
|
|
6531
|
+
await client.query(POSTGRES_TIMEZONE_SQL);
|
|
6532
|
+
} finally {
|
|
6533
|
+
await client.end();
|
|
6534
|
+
}
|
|
6535
|
+
}
|
|
6076
6536
|
async function probePostgresIdentity(port) {
|
|
6077
6537
|
const client = new Client({
|
|
6078
6538
|
host: "127.0.0.1",
|
|
@@ -6099,6 +6559,27 @@ async function probePostgresIdentity(port) {
|
|
|
6099
6559
|
await client.end();
|
|
6100
6560
|
}
|
|
6101
6561
|
}
|
|
6562
|
+
function verifyManagedPostmasterProcess(metadata, expected) {
|
|
6563
|
+
const pidPath = join3(metadata.dataDir, "postmaster.pid");
|
|
6564
|
+
const before = managedPostmaster(metadata);
|
|
6565
|
+
if (metadata.server?.pid !== expected.pid || metadata.server.started !== expected.started || metadata.server.port !== expected.port || metadata.server.systemIdentifier !== expected.systemIdentifier)
|
|
6566
|
+
throw new Error("Managed Postgres published process identity mismatch. Preserve the server and data directory.");
|
|
6567
|
+
if (!before)
|
|
6568
|
+
return { status: "absent" };
|
|
6569
|
+
const beforeFile = readFileSync2(pidPath, "utf8");
|
|
6570
|
+
if (before.pid !== expected.pid || before.started !== expected.started || before.port !== expected.port || before.systemIdentifier !== expected.systemIdentifier || before.pid === process.pid || before.pid === process.ppid || realpathSync2(beforeFile.split(/\r?\n/)[1]) !== metadata.dataDir)
|
|
6571
|
+
throw new Error("Managed Postgres process identity mismatch. Preserve the server and data directory.");
|
|
6572
|
+
const binding = createRequire2(import.meta.url)("@bastani/atomic-natives");
|
|
6573
|
+
const identity = binding.postgresProcessStartTime(before.pid);
|
|
6574
|
+
if (readFileSync2(pidPath, "utf8") !== beforeFile)
|
|
6575
|
+
throw new Error("Managed Postgres OS process start identity mismatch. Preserve the server and data directory.");
|
|
6576
|
+
if (!identity.found)
|
|
6577
|
+
return { status: "absent" };
|
|
6578
|
+
if (identity.startTime === undefined || !Number.isFinite(identity.startTime) || identity.startTime <= 0 || identity.startTime > before.started + 1) {
|
|
6579
|
+
throw new Error("Managed Postgres OS process start identity mismatch. Preserve the server and data directory.");
|
|
6580
|
+
}
|
|
6581
|
+
return { status: "live", server: before, observedCreateTime: identity.startTime };
|
|
6582
|
+
}
|
|
6102
6583
|
async function verifyPostgresIdentity(metadata, port, expectedPid, probe = probePostgresIdentity) {
|
|
6103
6584
|
const before = managedPostmaster(metadata);
|
|
6104
6585
|
if (!before)
|
|
@@ -6157,25 +6638,14 @@ class EmbeddedPostgresCleanupPendingError extends AggregateError {
|
|
|
6157
6638
|
var activeCluster;
|
|
6158
6639
|
var ensureOperation = ensure;
|
|
6159
6640
|
var retainedPostgresSpawnerOverride;
|
|
6641
|
+
var windowsPostgresGuardOverride;
|
|
6160
6642
|
var ensured;
|
|
6161
6643
|
var consumer;
|
|
6162
6644
|
var initializing = false;
|
|
6163
6645
|
var health;
|
|
6164
|
-
var lastFailure;
|
|
6165
|
-
function embeddedPostgresLastFailure() {
|
|
6166
|
-
return health?.lastFailure ?? lastFailure;
|
|
6167
|
-
}
|
|
6168
6646
|
function embeddedPostgresHealth() {
|
|
6169
6647
|
return health;
|
|
6170
6648
|
}
|
|
6171
|
-
async function recoverEmbeddedPostgres(context, metadata) {
|
|
6172
|
-
if (activeCluster && !activeCluster.shared)
|
|
6173
|
-
throw new EmbeddedPostgresCleanupPendingError([], "Managed Postgres cleanup is still pending.");
|
|
6174
|
-
activeCluster?.lease.release();
|
|
6175
|
-
activeCluster = undefined;
|
|
6176
|
-
await ensureCluster({ context, recovery: metadata });
|
|
6177
|
-
ensured ??= Promise.resolve();
|
|
6178
|
-
}
|
|
6179
6649
|
function ensureEmbeddedDbosPostgres() {
|
|
6180
6650
|
if (ensured !== undefined && !initializing && health !== undefined)
|
|
6181
6651
|
return health.check().then(() => {});
|
|
@@ -6186,7 +6656,6 @@ function ensureEmbeddedDbosPostgres() {
|
|
|
6186
6656
|
initializing = true;
|
|
6187
6657
|
ensured ??= ensureOperation().catch((error) => {
|
|
6188
6658
|
ensured = undefined;
|
|
6189
|
-
lastFailure = error instanceof Error ? error : new Error(String(error));
|
|
6190
6659
|
throw error;
|
|
6191
6660
|
}).finally(() => {
|
|
6192
6661
|
initializing = false;
|
|
@@ -6215,8 +6684,9 @@ async function ensureCluster(options = {}) {
|
|
|
6215
6684
|
chmodSync(root, 493);
|
|
6216
6685
|
}
|
|
6217
6686
|
let startedCluster;
|
|
6218
|
-
|
|
6219
|
-
|
|
6687
|
+
await withSetupLock(join4(root, `v${EMBEDDED_PG_MAJOR}.setup-lock`), async (setup) => {
|
|
6688
|
+
let adoptedRegistry;
|
|
6689
|
+
try {
|
|
6220
6690
|
await cleanupAbandonedRuntimeStages(root, setup.abandonedRuntimeStageOwnerTokens);
|
|
6221
6691
|
const preferredPort = preferredPostgresPort();
|
|
6222
6692
|
const registered = existsSync3(postgresOwnershipDirectory(root, EMBEDDED_PG_MAJOR));
|
|
@@ -6229,10 +6699,13 @@ async function ensureCluster(options = {}) {
|
|
|
6229
6699
|
if (!existsSync3(join4(dataDir, "PG_VERSION")) && registered) {
|
|
6230
6700
|
throw new Error(`Managed Postgres data is missing PG_VERSION; preserve its ownership records: ${dataDir}`);
|
|
6231
6701
|
}
|
|
6232
|
-
|
|
6702
|
+
const unregisteredData = !registered && existsSync3(dataDir) && readdirSync2(dataDir).length > 0;
|
|
6703
|
+
if (unregisteredData && (options.recovery || !launchedByPreOwnershipAtomic(dataDir))) {
|
|
6233
6704
|
throw new Error(`Refusing to adopt unregistered Postgres data: ${dataDir}. Preserve it and configure DBOS_SYSTEM_DATABASE_URL explicitly.`);
|
|
6234
6705
|
}
|
|
6235
|
-
let metadata = registered ? managedPostgresMetadata(root, EMBEDDED_PG_MAJOR,
|
|
6706
|
+
let metadata = registered || unregisteredData ? managedPostgresMetadata(root, EMBEDDED_PG_MAJOR, unregisteredData) : undefined;
|
|
6707
|
+
if (unregisteredData)
|
|
6708
|
+
adoptedRegistry = postgresOwnershipDirectory(root, EMBEDDED_PG_MAJOR);
|
|
6236
6709
|
if (options.recovery && !metadata)
|
|
6237
6710
|
throw new Error("Managed Postgres recovery requires existing ownership records.");
|
|
6238
6711
|
if (options.recovery && (metadata?.clusterId !== options.recovery.clusterId || metadata.directoryIdentity !== options.recovery.directoryIdentity || metadata.server?.systemIdentifier !== options.recovery.server?.systemIdentifier)) {
|
|
@@ -6244,18 +6717,135 @@ async function ensureCluster(options = {}) {
|
|
|
6244
6717
|
throw new Error("Managed Postgres published process identity mismatch. Preserve the cluster and ownership records.");
|
|
6245
6718
|
}
|
|
6246
6719
|
let verified;
|
|
6720
|
+
const existingServerProbe = () => options.probeIdentity ?? probePostgresIdentity;
|
|
6247
6721
|
let prepared = options.prepared ? options.binaries : undefined;
|
|
6248
|
-
|
|
6722
|
+
let selectedIdentity = options.runtimeIdentity;
|
|
6723
|
+
let reservedLiveGeneration;
|
|
6724
|
+
const verifyReplacementSource = async (source) => {
|
|
6725
|
+
if (!postgresRuntimeFilesExist(source.postgres)) {
|
|
6726
|
+
throw new Error("Replacement managed Postgres source runtime is incomplete; preserving the running server.");
|
|
6727
|
+
}
|
|
6728
|
+
if (options.probeIdentity !== undefined)
|
|
6729
|
+
return;
|
|
6730
|
+
hydrateBinaryLibraryLinks(source.pg_ctl);
|
|
6731
|
+
for (const binary of [source.postgres, source.pg_ctl, source.initdb]) {
|
|
6732
|
+
const result = await runLocalCommand(binary, ["--version"]);
|
|
6733
|
+
const version = /\(PostgreSQL\)\s+(\d+)\b/.exec(result.stdout);
|
|
6734
|
+
if (result.exitCode !== 0 || Number(version?.[1]) !== EMBEDDED_PG_MAJOR)
|
|
6735
|
+
throw new Error(`incompatible PostgreSQL runtime: ${binary} --version expected major ${EMBEDDED_PG_MAJOR}: ${commandFailureDetail(result)}`);
|
|
6736
|
+
}
|
|
6737
|
+
};
|
|
6738
|
+
const prepareRetainedRuntime = async (source, reservedGeneration, quickValidation = false, fullValidation = false, refreshSourceSnapshot = false) => {
|
|
6739
|
+
const cacheDir = process.env.ATOMIC_POSTGRES_RUNTIME_CACHE_DIR;
|
|
6740
|
+
if (cacheDir === undefined)
|
|
6741
|
+
return prepareBinariesForOwner(source, context, undefined, {
|
|
6742
|
+
publicationLease: setup.runtimePublicationLease,
|
|
6743
|
+
repairCorruptGeneration: true,
|
|
6744
|
+
refreshSourceSnapshot,
|
|
6745
|
+
reservedGeneration,
|
|
6746
|
+
quickValidation,
|
|
6747
|
+
memoizedValidation: true,
|
|
6748
|
+
fullValidation
|
|
6749
|
+
});
|
|
6750
|
+
await ensureRuntimeCacheDirectory(cacheDir, undefined, context.owner !== undefined);
|
|
6751
|
+
try {
|
|
6752
|
+
return await prepareBinariesForOwner(source, context, undefined, {
|
|
6753
|
+
publicationLease: setup.runtimePublicationLease,
|
|
6754
|
+
repairCorruptGeneration: true,
|
|
6755
|
+
refreshSourceSnapshot,
|
|
6756
|
+
reservedGeneration,
|
|
6757
|
+
quickValidation,
|
|
6758
|
+
fullValidation,
|
|
6759
|
+
memoizedValidation: true,
|
|
6760
|
+
reuseOnly: true
|
|
6761
|
+
});
|
|
6762
|
+
} catch (error) {
|
|
6763
|
+
if (!(error instanceof RuntimeGenerationMissingError))
|
|
6764
|
+
throw error;
|
|
6765
|
+
}
|
|
6766
|
+
let result;
|
|
6767
|
+
await withSetupLock(join4(cacheDir, ".publication-lock"), async (cache) => {
|
|
6768
|
+
await cleanupAbandonedRuntimeStages(cacheDir, cache.abandonedRuntimeStageOwnerTokens);
|
|
6769
|
+
result = await prepareBinariesForOwner(source, context, undefined, {
|
|
6770
|
+
publicationLease: {
|
|
6771
|
+
ownerToken: cache.runtimePublicationLease.ownerToken,
|
|
6772
|
+
refresh: () => cache.runtimePublicationLease.refresh() && setup.runtimePublicationLease.refresh(),
|
|
6773
|
+
isLost: () => cache.runtimePublicationLease.isLost?.() === true || setup.runtimePublicationLease.isLost?.() === true
|
|
6774
|
+
},
|
|
6775
|
+
repairCorruptGeneration: true,
|
|
6776
|
+
refreshSourceSnapshot,
|
|
6777
|
+
reservedGeneration,
|
|
6778
|
+
quickValidation,
|
|
6779
|
+
fullValidation,
|
|
6780
|
+
memoizedValidation: true
|
|
6781
|
+
});
|
|
6782
|
+
}, { attempts: READY_ATTEMPTS * 4 });
|
|
6783
|
+
if (result === undefined)
|
|
6784
|
+
throw new Error("Embedded Postgres runtime publication did not complete.");
|
|
6785
|
+
return result;
|
|
6786
|
+
};
|
|
6787
|
+
const chooseRuntime = async (mode = "start") => {
|
|
6788
|
+
if (prepared !== undefined && selectedIdentity !== undefined) {
|
|
6789
|
+
let retainedValid = false;
|
|
6790
|
+
try {
|
|
6791
|
+
retainedValid = await fingerprintPreparedRuntime(prepared, {
|
|
6792
|
+
publicationLease: setup.runtimePublicationLease,
|
|
6793
|
+
quickValidation: mode === "attach",
|
|
6794
|
+
memoizedValidation: mode !== "damage",
|
|
6795
|
+
fullValidation: mode === "damage"
|
|
6796
|
+
}) === selectedIdentity;
|
|
6797
|
+
} catch (error) {
|
|
6798
|
+
if (!isCorruptRuntimeGeneration(error, dirname3(dirname3(prepared.postgres))))
|
|
6799
|
+
throw error;
|
|
6800
|
+
}
|
|
6801
|
+
if (retainedValid)
|
|
6802
|
+
return prepared;
|
|
6803
|
+
const source = await loadEmbeddedPostgresBinaries();
|
|
6804
|
+
await verifyReplacementSource(source);
|
|
6805
|
+
const reservedGeneration = reservedLiveGeneration ?? dirname3(dirname3(prepared.postgres));
|
|
6806
|
+
prepared = await prepareRetainedRuntime(source, reservedGeneration, mode === "attach", mode === "damage", true);
|
|
6807
|
+
selectedIdentity = prepared.sealedIdentity;
|
|
6808
|
+
} else {
|
|
6809
|
+
if (prepared === undefined) {
|
|
6810
|
+
const source = options.binaries ?? await loadEmbeddedPostgresBinaries();
|
|
6811
|
+
await verifyReplacementSource(source);
|
|
6812
|
+
prepared = await prepareRetainedRuntime(source, reservedLiveGeneration, mode === "attach", mode === "damage", mode === "damage");
|
|
6813
|
+
}
|
|
6814
|
+
}
|
|
6815
|
+
if (!postgresRuntimeFilesExist(prepared.postgres) || ![prepared.pg_ctl, prepared.initdb].every((binary) => lstatSync3(binary, { throwIfNoEntry: false })?.isFile()) || prepared.sealedIdentity !== undefined && await fingerprintPreparedRuntime(prepared, {
|
|
6816
|
+
publicationLease: setup.runtimePublicationLease,
|
|
6817
|
+
quickValidation: mode === "attach",
|
|
6818
|
+
memoizedValidation: true
|
|
6819
|
+
}) !== prepared.sealedIdentity) {
|
|
6820
|
+
throw new Error("Replacement managed Postgres runtime is incomplete or changed; preserving the running server.");
|
|
6821
|
+
}
|
|
6822
|
+
return prepared;
|
|
6823
|
+
};
|
|
6824
|
+
if (existing && !managedPostgresRuntimeHealthy(metadata, port)) {
|
|
6825
|
+
reservedLiveGeneration = dirname3(dirname3(managedPostgresLaunchExecutable(metadata, existing.port)));
|
|
6826
|
+
prepared = await chooseRuntime("damage");
|
|
6827
|
+
if (adoptedRegistry !== undefined) {
|
|
6828
|
+
if (verifyManagedPostmasterProcess({ ...metadata, server: existing }, existing).status === "live") {
|
|
6829
|
+
if (!setup.runtimePublicationLease.refresh())
|
|
6830
|
+
throw new Error("Postgres setup lease lost before legacy adoption.");
|
|
6831
|
+
publishPostgresServer(root, metadata, existing);
|
|
6832
|
+
}
|
|
6833
|
+
adoptedRegistry = undefined;
|
|
6834
|
+
}
|
|
6835
|
+
if (await stopBrokenManagedPostmaster(metadata, existing, prepared.pg_ctl, context, setup.runtimePublicationLease, options.shutdownWait)) {
|
|
6836
|
+
activeCluster?.lease.release();
|
|
6837
|
+
activeCluster = undefined;
|
|
6838
|
+
}
|
|
6839
|
+
} else if (existing) {
|
|
6249
6840
|
await waitForClusterReadiness(logFile, undefined, async () => {
|
|
6250
|
-
verified = await verifyPostgresIdentity(metadata, port, existing.pid,
|
|
6841
|
+
verified = await verifyPostgresIdentity(metadata, port, existing.pid, existingServerProbe());
|
|
6251
6842
|
return verified !== undefined || managedPostmaster(metadata) === undefined;
|
|
6252
|
-
}, READY_ATTEMPTS, delay, port);
|
|
6843
|
+
}, READY_ATTEMPTS, delay, port, dataDir);
|
|
6253
6844
|
}
|
|
6845
|
+
if (verified)
|
|
6846
|
+
reservedLiveGeneration = dirname3(dirname3(managedPostgresLaunchExecutable(metadata, verified.port)));
|
|
6254
6847
|
if (!verified) {
|
|
6255
|
-
const
|
|
6256
|
-
const binaries = prepared ?? await prepareBinariesForOwner(loaded, context, undefined, {
|
|
6257
|
-
publicationLease: setup.runtimePublicationLease
|
|
6258
|
-
});
|
|
6848
|
+
const binaries = await chooseRuntime();
|
|
6259
6849
|
prepared = binaries;
|
|
6260
6850
|
if (!existsSync3(join4(dataDir, "PG_VERSION"))) {
|
|
6261
6851
|
if (options.recovery)
|
|
@@ -6274,13 +6864,15 @@ async function ensureCluster(options = {}) {
|
|
|
6274
6864
|
if (!setup.runtimePublicationLease.refresh())
|
|
6275
6865
|
throw new Error("Postgres setup lease lost before start.");
|
|
6276
6866
|
try {
|
|
6277
|
-
const lease = await startCluster(binaries.postgres, dataDir, logFile, context, port
|
|
6867
|
+
const lease = await startCluster(binaries.postgres, dataDir, logFile, context, port, {
|
|
6868
|
+
unsafeDurability: process.env.ATOMIC_POSTGRES_TEST_UNSAFE_DURABILITY === "1"
|
|
6869
|
+
});
|
|
6278
6870
|
startedCluster = { lease };
|
|
6279
6871
|
activeCluster = startedCluster;
|
|
6280
6872
|
await waitForClusterReadiness(logFile, startedCluster, async () => {
|
|
6281
6873
|
verified = await verifyPostgresIdentity(metadata, port, lease.pid, options.probeIdentity);
|
|
6282
6874
|
return verified !== undefined;
|
|
6283
|
-
}, READY_ATTEMPTS, delay, port);
|
|
6875
|
+
}, READY_ATTEMPTS, delay, port, dataDir);
|
|
6284
6876
|
break;
|
|
6285
6877
|
} catch (error) {
|
|
6286
6878
|
if (activeCluster !== undefined || attempt === 2 || !(error instanceof Error) || !/exited early|address already in use|EADDRINUSE/i.test(error.message) || !await isReachable(EMBEDDED_HOST, port, 1000))
|
|
@@ -6291,20 +6883,36 @@ async function ensureCluster(options = {}) {
|
|
|
6291
6883
|
}
|
|
6292
6884
|
if (!metadata || !verified)
|
|
6293
6885
|
throw new Error("Managed Postgres identity was not verified.");
|
|
6886
|
+
if (options.probeIdentity === undefined)
|
|
6887
|
+
await probePostgresTimezoneData(verified.port);
|
|
6888
|
+
let runtimeIdentity;
|
|
6294
6889
|
if (health === undefined) {
|
|
6295
|
-
prepared
|
|
6890
|
+
prepared = await chooseRuntime(verified && startedCluster === undefined ? "attach" : "start");
|
|
6891
|
+
runtimeIdentity = prepared.sealedIdentity ?? await fingerprintPreparedRuntime(prepared, { publicationLease: setup.runtimePublicationLease });
|
|
6296
6892
|
}
|
|
6297
6893
|
if (!setup.runtimePublicationLease.refresh())
|
|
6298
6894
|
throw new Error("Postgres setup lease lost before attach.");
|
|
6299
6895
|
publishPostgresServer(root, metadata, verified);
|
|
6896
|
+
adoptedRegistry = undefined;
|
|
6300
6897
|
actualPort = port;
|
|
6301
6898
|
inspectPostgresConsumers(root, metadata);
|
|
6302
6899
|
const nextConsumer = acquirePostgresConsumer(root, metadata, `${process.execPath} | ${import.meta.url}`);
|
|
6303
6900
|
consumer?.release();
|
|
6304
6901
|
consumer = nextConsumer;
|
|
6902
|
+
if (health !== undefined && options.recovery !== undefined && prepared?.sealedIdentity !== undefined) {
|
|
6903
|
+
options.binaries = prepared;
|
|
6904
|
+
options.runtimeIdentity = selectedIdentity ?? prepared.sealedIdentity;
|
|
6905
|
+
}
|
|
6305
6906
|
if (health === undefined) {
|
|
6306
6907
|
const pinned = { ...metadata, server: verified };
|
|
6307
|
-
const recoveryOptions = {
|
|
6908
|
+
const recoveryOptions = {
|
|
6909
|
+
...options,
|
|
6910
|
+
context,
|
|
6911
|
+
binaries: prepared,
|
|
6912
|
+
prepared: true,
|
|
6913
|
+
recovery: pinned,
|
|
6914
|
+
runtimeIdentity
|
|
6915
|
+
};
|
|
6308
6916
|
const inspect = async (probe = options.probeIdentity) => {
|
|
6309
6917
|
const current = managedPostgresMetadata(root, EMBEDDED_PG_MAJOR, false);
|
|
6310
6918
|
if (current.clusterId !== pinned.clusterId || current.directoryIdentity !== pinned.directoryIdentity || current.server?.systemIdentifier !== pinned.server.systemIdentifier) {
|
|
@@ -6313,11 +6921,17 @@ async function ensureCluster(options = {}) {
|
|
|
6313
6921
|
const server = current.server;
|
|
6314
6922
|
if (!server)
|
|
6315
6923
|
throw new Error("Managed Postgres published identity is missing.");
|
|
6316
|
-
|
|
6924
|
+
if (!managedPostgresRuntimeHealthy(current, server.port)) {
|
|
6925
|
+
verifyManagedPostmasterProcess(current, server);
|
|
6926
|
+
return;
|
|
6927
|
+
}
|
|
6928
|
+
const live = await verifyPostgresIdentity(current, server.port, server.pid, probe ?? existingServerProbe());
|
|
6317
6929
|
if (!live)
|
|
6318
6930
|
return;
|
|
6319
6931
|
if (live.started !== server.started)
|
|
6320
6932
|
throw new Error("Managed Postgres published start identity mismatch.");
|
|
6933
|
+
if (probe === undefined)
|
|
6934
|
+
await probePostgresTimezoneData(live.port);
|
|
6321
6935
|
actualPort = live.port;
|
|
6322
6936
|
return { url: embeddedDbosSystemDatabaseUrl(), identity: JSON.stringify(live) };
|
|
6323
6937
|
};
|
|
@@ -6331,6 +6945,10 @@ async function ensureCluster(options = {}) {
|
|
|
6331
6945
|
});
|
|
6332
6946
|
if (!identity)
|
|
6333
6947
|
throw new DbosDependencyError;
|
|
6948
|
+
if (options.probeIdentity === undefined) {
|
|
6949
|
+
const query = { text: POSTGRES_TIMEZONE_SQL, query_timeout: 1000 };
|
|
6950
|
+
await client.query(query);
|
|
6951
|
+
}
|
|
6334
6952
|
},
|
|
6335
6953
|
recover: async () => {
|
|
6336
6954
|
if (activeCluster && !activeCluster.shared)
|
|
@@ -6341,12 +6959,95 @@ async function ensureCluster(options = {}) {
|
|
|
6341
6959
|
}
|
|
6342
6960
|
});
|
|
6343
6961
|
}
|
|
6344
|
-
})
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6962
|
+
} catch (startupError) {
|
|
6963
|
+
if (startupError instanceof EmbeddedPostgresCleanupPendingError)
|
|
6964
|
+
throw startupError;
|
|
6965
|
+
await rollbackStartedCluster(startedCluster, startupError).catch((error) => {
|
|
6966
|
+
if (adoptedRegistry !== undefined && !(error instanceof EmbeddedPostgresCleanupPendingError))
|
|
6967
|
+
rmSync2(adoptedRegistry, { recursive: true, force: true });
|
|
6968
|
+
throw error;
|
|
6969
|
+
});
|
|
6970
|
+
}
|
|
6971
|
+
});
|
|
6972
|
+
}
|
|
6973
|
+
async function stopBrokenManagedPostmaster(metadata, verified, pgCtl, context, lease, wait = delay, platform = process.platform) {
|
|
6974
|
+
const check = () => {
|
|
6975
|
+
const current = managedPostgresMetadata(context.baseDir, metadata.major, false);
|
|
6976
|
+
if (current.clusterId !== metadata.clusterId || current.directoryIdentity !== metadata.directoryIdentity) {
|
|
6977
|
+
throw new Error("Managed Postgres restart identity changed. Preserve the server and data directory.");
|
|
6978
|
+
}
|
|
6979
|
+
return { current, process: verifyManagedPostmasterProcess(current, verified) };
|
|
6980
|
+
};
|
|
6981
|
+
const { current, process: state } = check();
|
|
6982
|
+
if (state.status === "absent")
|
|
6983
|
+
return true;
|
|
6984
|
+
if (managedPostgresRuntimeHealthy(current, verified.port))
|
|
6985
|
+
return false;
|
|
6986
|
+
const binding = createRequire3(import.meta.url)("@bastani/atomic-natives");
|
|
6987
|
+
const released = async () => {
|
|
6988
|
+
const identity = binding.postgresProcessStartTime(verified.pid);
|
|
6989
|
+
if (identity.found || managedPostmaster(current) !== undefined)
|
|
6990
|
+
return false;
|
|
6991
|
+
if (activeCluster?.lease.pid === verified.pid)
|
|
6992
|
+
await activeCluster.lease.wait(0);
|
|
6993
|
+
return true;
|
|
6994
|
+
};
|
|
6995
|
+
const signal = (mode, observedCreateTime) => {
|
|
6996
|
+
if (!lease.refresh())
|
|
6997
|
+
throw new Error("Postgres setup lease lost before stopping the verified managed server.");
|
|
6998
|
+
const result = binding.signalVerifiedPostgres(verified.pid, observedCreateTime, mode);
|
|
6999
|
+
if (result === "mismatch")
|
|
7000
|
+
throw new Error("Managed Postgres OS process start identity mismatch. Preserve the server and data directory.");
|
|
7001
|
+
};
|
|
7002
|
+
const waitForExit = async (guard) => {
|
|
7003
|
+
for (let attempt = 0;attempt < READY_ATTEMPTS; attempt++) {
|
|
7004
|
+
if (guard?.exited() && await released())
|
|
7005
|
+
return true;
|
|
7006
|
+
if (guard === undefined && await released())
|
|
7007
|
+
return true;
|
|
7008
|
+
await wait(READY_DELAY_MS);
|
|
7009
|
+
}
|
|
7010
|
+
return (guard === undefined || guard.exited()) && released();
|
|
7011
|
+
};
|
|
7012
|
+
const stop = async (mode, observedCreateTime) => {
|
|
7013
|
+
if (platform !== "win32") {
|
|
7014
|
+
signal(mode, observedCreateTime);
|
|
7015
|
+
return waitForExit();
|
|
7016
|
+
}
|
|
7017
|
+
if (!lease.refresh())
|
|
7018
|
+
throw new Error("Postgres setup lease lost before stopping the verified managed server.");
|
|
7019
|
+
const guard = windowsPostgresGuardOverride?.(verified.pid, observedCreateTime) ?? binding.guardWindowsPostgresProcess(verified.pid, observedCreateTime);
|
|
7020
|
+
try {
|
|
7021
|
+
if (guard.status === "mismatch")
|
|
7022
|
+
throw new Error("Managed Postgres OS process start identity mismatch. Preserve the server and data directory.");
|
|
7023
|
+
if (guard.status === "absent") {
|
|
7024
|
+
if (await released())
|
|
7025
|
+
return true;
|
|
7026
|
+
throw new Error("Managed Postgres shutdown did not release its postmaster file.");
|
|
7027
|
+
}
|
|
7028
|
+
const killed = await context.runAsOwner(pgCtl, [
|
|
7029
|
+
"kill",
|
|
7030
|
+
mode === "fast" ? "INT" : "QUIT",
|
|
7031
|
+
String(verified.pid)
|
|
7032
|
+
]);
|
|
7033
|
+
if (killed.exitCode !== 0)
|
|
7034
|
+
throw new Error(`Could not signal the verified managed Postgres server: ${commandFailureDetail(killed)}`);
|
|
7035
|
+
return await waitForExit(guard);
|
|
7036
|
+
} finally {
|
|
7037
|
+
guard.close();
|
|
7038
|
+
}
|
|
7039
|
+
};
|
|
7040
|
+
if (await stop("fast", state.observedCreateTime))
|
|
7041
|
+
return true;
|
|
7042
|
+
const fresh = check();
|
|
7043
|
+
if (fresh.process.status === "absent") {
|
|
7044
|
+
if (await released())
|
|
7045
|
+
return true;
|
|
7046
|
+
throw new Error("Managed Postgres shutdown did not release its postmaster file.");
|
|
6349
7047
|
}
|
|
7048
|
+
if (await stop("immediate", fresh.process.observedCreateTime))
|
|
7049
|
+
return true;
|
|
7050
|
+
throw new Error("Could not stop the verified managed Postgres server within the shutdown budget.");
|
|
6350
7051
|
}
|
|
6351
7052
|
async function rollbackStartedCluster(cluster, startupError) {
|
|
6352
7053
|
if (cluster !== undefined && activeCluster === cluster) {
|
|
@@ -6358,13 +7059,13 @@ async function rollbackStartedCluster(cluster, startupError) {
|
|
|
6358
7059
|
}
|
|
6359
7060
|
throw startupError;
|
|
6360
7061
|
}
|
|
6361
|
-
async function waitForClusterReadiness(logFile, rollbackCluster, isReachable = tcpReachable, attempts = READY_ATTEMPTS, wait = delay, port = EMBEDDED_PORT) {
|
|
7062
|
+
async function waitForClusterReadiness(logFile, rollbackCluster, isReachable = tcpReachable, attempts = READY_ATTEMPTS, wait = delay, port = EMBEDDED_PORT, dataDir = join4(dirname3(logFile), "v18")) {
|
|
6362
7063
|
const deadline = performance.now() + READY_ATTEMPTS * READY_DELAY_MS;
|
|
6363
7064
|
try {
|
|
6364
7065
|
for (let attempt = 0;attempt < attempts && performance.now() < deadline; attempt += 1) {
|
|
6365
|
-
await assertRetainedPostgresRunning(rollbackCluster, logFile, port);
|
|
7066
|
+
await assertRetainedPostgresRunning(rollbackCluster, logFile, port, dataDir);
|
|
6366
7067
|
if (await isReachable(EMBEDDED_HOST, port)) {
|
|
6367
|
-
await assertRetainedPostgresRunning(rollbackCluster, logFile, port);
|
|
7068
|
+
await assertRetainedPostgresRunning(rollbackCluster, logFile, port, dataDir);
|
|
6368
7069
|
if (rollbackCluster !== undefined)
|
|
6369
7070
|
rollbackCluster.shared = true;
|
|
6370
7071
|
return;
|
|
@@ -6376,7 +7077,7 @@ async function waitForClusterReadiness(logFile, rollbackCluster, isReachable = t
|
|
|
6376
7077
|
await rollbackStartedCluster(rollbackCluster, startupError);
|
|
6377
7078
|
}
|
|
6378
7079
|
}
|
|
6379
|
-
async function assertRetainedPostgresRunning(cluster, logFile, port = EMBEDDED_PORT) {
|
|
7080
|
+
async function assertRetainedPostgresRunning(cluster, logFile, port = EMBEDDED_PORT, dataDir = join4(dirname3(logFile), "v18")) {
|
|
6380
7081
|
if (cluster === undefined)
|
|
6381
7082
|
return;
|
|
6382
7083
|
const observed = await cluster.lease.wait(0).catch((error) => {
|
|
@@ -6386,7 +7087,7 @@ async function assertRetainedPostgresRunning(cluster, logFile, port = EMBEDDED_P
|
|
|
6386
7087
|
throw error;
|
|
6387
7088
|
});
|
|
6388
7089
|
if (observed?.exited) {
|
|
6389
|
-
throw new Error(`The embedded Postgres process exited early before accepting connections on ${EMBEDDED_HOST}:${port}; see ${logFile}.${logTail(logFile)}`);
|
|
7090
|
+
throw new Error(`The embedded Postgres process exited early before accepting connections on ${EMBEDDED_HOST}:${port}; see ${logFile}.${logTail(logFile, dataDir)}`);
|
|
6390
7091
|
}
|
|
6391
7092
|
}
|
|
6392
7093
|
function shutdownEmbeddedDbosPostgres() {
|
|
@@ -6422,6 +7123,24 @@ async function stopActiveCluster(cluster) {
|
|
|
6422
7123
|
throw error;
|
|
6423
7124
|
}
|
|
6424
7125
|
}
|
|
7126
|
+
function launchedByPreOwnershipAtomic(dataDir) {
|
|
7127
|
+
const versionFile = join4(dataDir, "PG_VERSION");
|
|
7128
|
+
const optsFile = join4(dataDir, "postmaster.opts");
|
|
7129
|
+
try {
|
|
7130
|
+
if (!lstatSync3(versionFile).isFile() || !lstatSync3(optsFile).isFile())
|
|
7131
|
+
return false;
|
|
7132
|
+
if (readFileSync3(versionFile, "utf8").trim() !== String(EMBEDDED_PG_MAJOR))
|
|
7133
|
+
return false;
|
|
7134
|
+
const launch = /^.+[\\/]postgres(?:\.exe)? "-D" "([^"]+)" "-p" "\d+" "-c" "listen_addresses=127\.0\.0\.1"\s*$/.exec(readFileSync3(optsFile, "utf8"));
|
|
7135
|
+
if (!launch || !isAbsolute3(launch[1]))
|
|
7136
|
+
return false;
|
|
7137
|
+
if (launch[1] === dataDir)
|
|
7138
|
+
return true;
|
|
7139
|
+
return realpathSync3(launch[1]) === realpathSync3(dataDir);
|
|
7140
|
+
} catch {
|
|
7141
|
+
return false;
|
|
7142
|
+
}
|
|
7143
|
+
}
|
|
6425
7144
|
async function initializeCluster(initdb, dataDir, context) {
|
|
6426
7145
|
if (context.owner !== undefined) {
|
|
6427
7146
|
mkdirSync2(dataDir, { recursive: true, mode: 448 });
|
|
@@ -6453,28 +7172,69 @@ async function initializeCluster(initdb, dataDir, context) {
|
|
|
6453
7172
|
rmSync2(passwordFile, { force: true });
|
|
6454
7173
|
}
|
|
6455
7174
|
}
|
|
6456
|
-
async function startCluster(postgres, dataDir, logFile, context, port = EMBEDDED_PORT) {
|
|
7175
|
+
async function startCluster(postgres, dataDir, logFile, context, port = EMBEDDED_PORT, options = {}) {
|
|
6457
7176
|
try {
|
|
7177
|
+
let unsafeDurability = false;
|
|
7178
|
+
if (options.unsafeDurability) {
|
|
7179
|
+
const canonical = (path) => {
|
|
7180
|
+
const resolved = realpathSync3.native(path);
|
|
7181
|
+
return process.platform === "win32" ? resolved.toLowerCase() : resolved;
|
|
7182
|
+
};
|
|
7183
|
+
const canonicalManagedBase = (path) => {
|
|
7184
|
+
try {
|
|
7185
|
+
return canonical(path);
|
|
7186
|
+
} catch (error) {
|
|
7187
|
+
if (error.code !== "ENOENT")
|
|
7188
|
+
throw error;
|
|
7189
|
+
return join4(canonicalManagedBase(dirname3(path)), process.platform === "win32" ? basename2(path).toLowerCase() : basename2(path));
|
|
7190
|
+
}
|
|
7191
|
+
};
|
|
7192
|
+
const realDataDir = canonical(dataDir);
|
|
7193
|
+
const realTempDir = canonical(tmpdir());
|
|
7194
|
+
const withinTemp = relative2(realTempDir, realDataDir);
|
|
7195
|
+
const withinManagedHome = relative2(canonicalManagedBase(defaultEmbeddedBaseDir()), realDataDir);
|
|
7196
|
+
unsafeDurability = withinTemp !== "" && withinTemp !== ".." && !withinTemp.startsWith(`..${sep2}`) && !isAbsolute3(withinTemp) && (withinManagedHome === ".." || withinManagedHome.startsWith(`..${sep2}`) || isAbsolute3(withinManagedHome));
|
|
7197
|
+
}
|
|
6458
7198
|
return retainedPostgresSpawner()({
|
|
6459
7199
|
executable: postgres,
|
|
6460
|
-
args: [
|
|
7200
|
+
args: [
|
|
7201
|
+
"-D",
|
|
7202
|
+
dataDir,
|
|
7203
|
+
"-p",
|
|
7204
|
+
String(port),
|
|
7205
|
+
"-c",
|
|
7206
|
+
`listen_addresses=${EMBEDDED_HOST}`,
|
|
7207
|
+
"-c",
|
|
7208
|
+
"logging_collector=on",
|
|
7209
|
+
"-c",
|
|
7210
|
+
"log_directory=log",
|
|
7211
|
+
"-c",
|
|
7212
|
+
"log_filename=postgresql-%a.log",
|
|
7213
|
+
"-c",
|
|
7214
|
+
"log_truncate_on_rotation=on",
|
|
7215
|
+
"-c",
|
|
7216
|
+
"log_rotation_age=1d",
|
|
7217
|
+
"-c",
|
|
7218
|
+
"log_rotation_size=0",
|
|
7219
|
+
...unsafeDurability ? ["-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"] : []
|
|
7220
|
+
],
|
|
6461
7221
|
cwd: dataDir,
|
|
6462
7222
|
logFile,
|
|
6463
7223
|
...context.owner === undefined ? {} : { uid: context.owner.uid, gid: context.owner.gid }
|
|
6464
7224
|
});
|
|
6465
7225
|
} catch (error) {
|
|
6466
7226
|
const detail = error instanceof Error ? error.message : String(error);
|
|
6467
|
-
throw new Error(`Could not start the embedded Postgres cluster: ${detail}${logTail(logFile)}`);
|
|
7227
|
+
throw new Error(`Could not start the embedded Postgres cluster: ${detail}${logTail(logFile, dataDir)}`);
|
|
6468
7228
|
}
|
|
6469
7229
|
}
|
|
6470
7230
|
function retainedPostgresSpawner() {
|
|
6471
7231
|
if (retainedPostgresSpawnerOverride !== undefined)
|
|
6472
7232
|
return retainedPostgresSpawnerOverride;
|
|
6473
|
-
const binding =
|
|
7233
|
+
const binding = createRequire3(import.meta.url)("@bastani/atomic-natives");
|
|
6474
7234
|
return binding.spawnRetainedPostgres;
|
|
6475
7235
|
}
|
|
6476
7236
|
function hydrateBinaryLibraryLinks(pgCtlPath, createLink = symlinkSync, copyFile = copyFileSync) {
|
|
6477
|
-
let current =
|
|
7237
|
+
let current = dirname3(pgCtlPath);
|
|
6478
7238
|
let manifestPath;
|
|
6479
7239
|
let manifestRoot;
|
|
6480
7240
|
for (let depth = 0;depth < 5; depth += 1) {
|
|
@@ -6490,7 +7250,7 @@ function hydrateBinaryLibraryLinks(pgCtlPath, createLink = symlinkSync, copyFile
|
|
|
6490
7250
|
manifestRoot = current;
|
|
6491
7251
|
break;
|
|
6492
7252
|
}
|
|
6493
|
-
current =
|
|
7253
|
+
current = dirname3(current);
|
|
6494
7254
|
}
|
|
6495
7255
|
if (manifestPath === undefined || manifestRoot === undefined)
|
|
6496
7256
|
return;
|
|
@@ -6504,8 +7264,8 @@ function hydrateBinaryLibraryLinks(pgCtlPath, createLink = symlinkSync, copyFile
|
|
|
6504
7264
|
throw new Error(`incomplete PostgreSQL runtime: invalid aliases in ${manifestPath}`);
|
|
6505
7265
|
}
|
|
6506
7266
|
const firstSource = manifest[0]?.source;
|
|
6507
|
-
if (firstSource?.startsWith("native/") && !existsSync3(join4(manifestRoot, firstSource)) && existsSync3(join4(
|
|
6508
|
-
manifestRoot =
|
|
7267
|
+
if (firstSource?.startsWith("native/") && !existsSync3(join4(manifestRoot, firstSource)) && existsSync3(join4(dirname3(manifestRoot), firstSource))) {
|
|
7268
|
+
manifestRoot = dirname3(manifestRoot);
|
|
6509
7269
|
}
|
|
6510
7270
|
const canonicalRoot = realpathSync3(manifestRoot);
|
|
6511
7271
|
const targets = new Map;
|
|
@@ -6515,9 +7275,9 @@ function hydrateBinaryLibraryLinks(pgCtlPath, createLink = symlinkSync, copyFile
|
|
|
6515
7275
|
const absoluteSource = lstatSync3(sourcePath, { throwIfNoEntry: false }) ? sourcePath : plannedSources.get(source) ?? sourcePath;
|
|
6516
7276
|
const absoluteTarget = join4(manifestRoot, target);
|
|
6517
7277
|
try {
|
|
6518
|
-
for (const path of [absoluteSource,
|
|
7278
|
+
for (const path of [absoluteSource, dirname3(absoluteTarget)]) {
|
|
6519
7279
|
const contained = relative2(canonicalRoot, realpathSync3(path));
|
|
6520
|
-
if (
|
|
7280
|
+
if (isAbsolute3(contained) || contained === ".." || contained.startsWith("../") || contained.startsWith("..\\"))
|
|
6521
7281
|
throw new Error(`alias escapes runtime: ${target}`);
|
|
6522
7282
|
}
|
|
6523
7283
|
if (!statSync(absoluteSource).isFile())
|
|
@@ -6529,7 +7289,7 @@ function hydrateBinaryLibraryLinks(pgCtlPath, createLink = symlinkSync, copyFile
|
|
|
6529
7289
|
throw new Error(`dangling alias target: ${target}`);
|
|
6530
7290
|
if (existsSync3(absoluteTarget)) {
|
|
6531
7291
|
const contained = relative2(canonicalRoot, realpathSync3(absoluteTarget));
|
|
6532
|
-
if (
|
|
7292
|
+
if (isAbsolute3(contained) || contained === ".." || contained.startsWith("../") || contained.startsWith("..\\") || !statSync(absoluteTarget).isFile() || !readFileSync3(absoluteTarget).equals(readFileSync3(absoluteSource)))
|
|
6533
7293
|
throw new Error(`invalid alias target: ${target}`);
|
|
6534
7294
|
}
|
|
6535
7295
|
} catch (cause) {
|
|
@@ -6541,12 +7301,12 @@ function hydrateBinaryLibraryLinks(pgCtlPath, createLink = symlinkSync, copyFile
|
|
|
6541
7301
|
for (const { absoluteSource, absoluteTarget } of plans) {
|
|
6542
7302
|
if (lstatSync3(absoluteTarget, { throwIfNoEntry: false })) {
|
|
6543
7303
|
const contained = relative2(canonicalRoot, realpathSync3(absoluteTarget));
|
|
6544
|
-
if (
|
|
7304
|
+
if (isAbsolute3(contained) || contained === ".." || contained.startsWith("../") || contained.startsWith("..\\") || !statSync(absoluteTarget).isFile() || !readFileSync3(absoluteTarget).equals(readFileSync3(absoluteSource)))
|
|
6545
7305
|
throw new Error(`incomplete PostgreSQL runtime: invalid alias target: ${absoluteTarget}`);
|
|
6546
7306
|
continue;
|
|
6547
7307
|
}
|
|
6548
7308
|
try {
|
|
6549
|
-
createLink(relative2(
|
|
7309
|
+
createLink(relative2(dirname3(absoluteTarget), absoluteSource), absoluteTarget);
|
|
6550
7310
|
} catch {
|
|
6551
7311
|
try {
|
|
6552
7312
|
copyFile(absoluteSource, absoluteTarget);
|
|
@@ -6594,7 +7354,7 @@ function resolvePackageManifest(packageName, resolvePackage) {
|
|
|
6594
7354
|
}
|
|
6595
7355
|
}
|
|
6596
7356
|
function packagedRuntimeCandidate(packageName, resolution) {
|
|
6597
|
-
return resolution.manifest === undefined ? `${packageName}/postgres-runtime (${resolution.error ?? "package is unavailable"})` : join4(
|
|
7357
|
+
return resolution.manifest === undefined ? `${packageName}/postgres-runtime (${resolution.error ?? "package is unavailable"})` : join4(dirname3(resolution.manifest), "postgres-runtime");
|
|
6598
7358
|
}
|
|
6599
7359
|
async function loadEmbeddedPostgresBinaries(options = {}) {
|
|
6600
7360
|
const host = options.host ?? {
|
|
@@ -6605,21 +7365,21 @@ async function loadEmbeddedPostgresBinaries(options = {}) {
|
|
|
6605
7365
|
const target = resolveEmbeddedPostgresTarget(host);
|
|
6606
7366
|
const searched = [];
|
|
6607
7367
|
const moduleUrl = options.moduleUrl ?? import.meta.url;
|
|
6608
|
-
const resolvePackage = options.resolvePackage ??
|
|
7368
|
+
const resolvePackage = options.resolvePackage ?? createRequire3(moduleUrl).resolve;
|
|
6609
7369
|
const rootPackage = resolvePackageManifest("@bastani/atomic-natives", resolvePackage);
|
|
6610
|
-
const leafResolver = options.resolvePackage ?? (rootPackage.manifest === undefined ? resolvePackage :
|
|
7370
|
+
const leafResolver = options.resolvePackage ?? (rootPackage.manifest === undefined ? resolvePackage : createRequire3(rootPackage.manifest).resolve);
|
|
6611
7371
|
const leafPackage = target.nativeLeafPackageName === undefined ? undefined : resolvePackageManifest(target.nativeLeafPackageName, leafResolver);
|
|
6612
7372
|
const explicitRuntime = options.runtimeDirectory ?? process.env.ATOMIC_POSTGRES_RUNTIME_DIR;
|
|
6613
7373
|
const candidates = [
|
|
6614
7374
|
...explicitRuntime === undefined ? [] : [{ path: explicitRuntime, label: explicitRuntime }],
|
|
6615
7375
|
...target.nativeLeafPackageName === undefined || leafPackage === undefined ? [] : [
|
|
6616
7376
|
{
|
|
6617
|
-
path: leafPackage.manifest === undefined ? undefined : join4(
|
|
7377
|
+
path: leafPackage.manifest === undefined ? undefined : join4(dirname3(leafPackage.manifest), "postgres-runtime"),
|
|
6618
7378
|
label: packagedRuntimeCandidate(target.nativeLeafPackageName, leafPackage)
|
|
6619
7379
|
}
|
|
6620
7380
|
],
|
|
6621
7381
|
{
|
|
6622
|
-
path: rootPackage.manifest === undefined ? undefined : join4(
|
|
7382
|
+
path: rootPackage.manifest === undefined ? undefined : join4(dirname3(rootPackage.manifest), "postgres-runtime"),
|
|
6623
7383
|
label: packagedRuntimeCandidate("@bastani/atomic-natives", rootPackage),
|
|
6624
7384
|
validateTarget: true
|
|
6625
7385
|
}
|
|
@@ -6647,7 +7407,7 @@ async function loadEmbeddedPostgresBinaries(options = {}) {
|
|
|
6647
7407
|
const legacy = resolvePackageManifest(target.npmPackageName, resolvePackage);
|
|
6648
7408
|
if (legacy.manifest !== undefined) {
|
|
6649
7409
|
try {
|
|
6650
|
-
return binariesFromDirectory(join4(
|
|
7410
|
+
return binariesFromDirectory(join4(dirname3(legacy.manifest), "native"), host.platform, options.readOnly);
|
|
6651
7411
|
} catch {}
|
|
6652
7412
|
}
|
|
6653
7413
|
}
|
|
@@ -6657,7 +7417,7 @@ async function loadEmbeddedPostgresBinaries(options = {}) {
|
|
|
6657
7417
|
if (typeof binaries.pg_ctl !== "string" || typeof binaries.initdb !== "string") {
|
|
6658
7418
|
throw new Error("package did not export pg_ctl/initdb paths");
|
|
6659
7419
|
}
|
|
6660
|
-
const postgres = join4(
|
|
7420
|
+
const postgres = join4(dirname3(binaries.pg_ctl), host.platform === "win32" ? "postgres.exe" : "postgres");
|
|
6661
7421
|
if (!options.readOnly)
|
|
6662
7422
|
for (const binary of [binaries.pg_ctl, binaries.initdb, postgres])
|
|
6663
7423
|
ensureExecutable(binary);
|
|
@@ -6690,7 +7450,7 @@ async function withSetupLock(lockDir, fn, options = {}) {
|
|
|
6690
7450
|
const isProcessAlive = options.isProcessAlive ?? processIsAlive2;
|
|
6691
7451
|
let lease;
|
|
6692
7452
|
for (let attempt = 0;attempt < attempts; attempt += 1) {
|
|
6693
|
-
lease = acquireSetupLock(lockDir, clock
|
|
7453
|
+
lease = acquireSetupLock(lockDir, clock, staleMs, isProcessAlive, options.beforeOwnerMarkerWrite);
|
|
6694
7454
|
if (lease !== undefined)
|
|
6695
7455
|
break;
|
|
6696
7456
|
if (attempt === attempts - 1) {
|
|
@@ -6700,11 +7460,18 @@ async function withSetupLock(lockDir, fn, options = {}) {
|
|
|
6700
7460
|
}
|
|
6701
7461
|
if (lease === undefined)
|
|
6702
7462
|
throw new Error(`Could not acquire the embedded Postgres setup lock (${lockDir}).`);
|
|
6703
|
-
|
|
7463
|
+
let lost = false;
|
|
7464
|
+
const refresh = () => {
|
|
7465
|
+
if (lost)
|
|
7466
|
+
return false;
|
|
7467
|
+
if (!refreshSetupLockLease(lease, clock(), staleMs, options.beforeHeartbeatReplace))
|
|
7468
|
+
lost = true;
|
|
7469
|
+
return !lost;
|
|
7470
|
+
};
|
|
6704
7471
|
const stopHeartbeat = scheduleHeartbeat(refresh, heartbeatMs);
|
|
6705
7472
|
try {
|
|
6706
7473
|
await fn({
|
|
6707
|
-
runtimePublicationLease: { ownerToken: lease.token, refresh },
|
|
7474
|
+
runtimePublicationLease: { ownerToken: lease.token, refresh, isLost: () => lost },
|
|
6708
7475
|
abandonedRuntimeStageOwnerTokens: lease.abandonedOwnerTokens
|
|
6709
7476
|
});
|
|
6710
7477
|
} finally {
|
|
@@ -6712,20 +7479,20 @@ async function withSetupLock(lockDir, fn, options = {}) {
|
|
|
6712
7479
|
releaseSetupLock(lease);
|
|
6713
7480
|
}
|
|
6714
7481
|
}
|
|
6715
|
-
function acquireSetupLock(lockDir,
|
|
7482
|
+
function acquireSetupLock(lockDir, clock, staleMs, isProcessAlive, beforeOwnerMarkerWrite) {
|
|
6716
7483
|
const abandonedOwnerTokens = new Set;
|
|
6717
7484
|
for (let attempt = 0;attempt < 2; attempt += 1) {
|
|
6718
7485
|
const token = `${process.pid}-${crypto.randomUUID()}`;
|
|
6719
7486
|
if (createSetupLockDirectory(lockDir)) {
|
|
6720
7487
|
beforeOwnerMarkerWrite?.(lockDir);
|
|
6721
|
-
const lease = claimCreatedSetupLock(lockDir, token,
|
|
7488
|
+
const lease = claimCreatedSetupLock(lockDir, token, clock(), abandonedOwnerTokens);
|
|
6722
7489
|
if (lease !== undefined)
|
|
6723
7490
|
return lease;
|
|
6724
7491
|
}
|
|
6725
7492
|
const observation = observeSetupLock(lockDir);
|
|
6726
|
-
if (observation === undefined || !setupLockIsStale(observation,
|
|
7493
|
+
if (observation === undefined || !setupLockIsStale(observation, clock(), staleMs, isProcessAlive))
|
|
6727
7494
|
return;
|
|
6728
|
-
const abandoned = breakStaleSetupLock(lockDir, observation,
|
|
7495
|
+
const abandoned = breakStaleSetupLock(lockDir, observation, clock, staleMs, token, isProcessAlive);
|
|
6729
7496
|
if (abandoned === undefined)
|
|
6730
7497
|
return;
|
|
6731
7498
|
for (const abandonedToken of abandoned)
|
|
@@ -6779,8 +7546,9 @@ function createdSetupLockHoldsOnly(lockDir, markerName) {
|
|
|
6779
7546
|
function errorCode(error) {
|
|
6780
7547
|
return error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : undefined;
|
|
6781
7548
|
}
|
|
6782
|
-
function refreshSetupLockLease(lease, now, beforeReplace) {
|
|
6783
|
-
|
|
7549
|
+
function refreshSetupLockLease(lease, now, staleMs, beforeReplace) {
|
|
7550
|
+
const deadline = performance.now() + Math.min(100, staleMs / 4);
|
|
7551
|
+
if (!ownsSetupLock(lease, deadline))
|
|
6784
7552
|
return false;
|
|
6785
7553
|
const record = { token: lease.token, pid: lease.ownerPid, heartbeatMonotonicMs: now.monotonicMs };
|
|
6786
7554
|
const temporaryMarkerPath = join4(lease.lockDir, `.owner-${lease.token}.tmp-${crypto.randomUUID()}`);
|
|
@@ -6791,12 +7559,18 @@ function refreshSetupLockLease(lease, now, beforeReplace) {
|
|
|
6791
7559
|
flush: true
|
|
6792
7560
|
});
|
|
6793
7561
|
beforeReplace?.(temporaryMarkerPath);
|
|
6794
|
-
if (!ownsSetupLock(lease)) {
|
|
7562
|
+
if (!ownsSetupLock(lease, deadline)) {
|
|
6795
7563
|
removeMarkerIfOwned(temporaryMarkerPath, record);
|
|
6796
7564
|
return false;
|
|
6797
7565
|
}
|
|
6798
|
-
|
|
6799
|
-
|
|
7566
|
+
return retrySetupLockSharingViolation(() => {
|
|
7567
|
+
if (!ownsSetupLock(lease, deadline)) {
|
|
7568
|
+
removeMarkerIfOwned(temporaryMarkerPath, record);
|
|
7569
|
+
return false;
|
|
7570
|
+
}
|
|
7571
|
+
renameSync2(temporaryMarkerPath, lease.markerPath);
|
|
7572
|
+
return ownsSetupLock(lease, deadline);
|
|
7573
|
+
}, deadline);
|
|
6800
7574
|
} catch {
|
|
6801
7575
|
removeMarkerIfOwned(temporaryMarkerPath, record);
|
|
6802
7576
|
return false;
|
|
@@ -6812,10 +7586,26 @@ function removeMarkerIfOwned(path, expected) {
|
|
|
6812
7586
|
}
|
|
6813
7587
|
} catch {}
|
|
6814
7588
|
}
|
|
6815
|
-
function
|
|
7589
|
+
function retrySetupLockSharingViolation(operation, deadline) {
|
|
7590
|
+
let backoffMs = 1;
|
|
7591
|
+
for (;; ) {
|
|
7592
|
+
try {
|
|
7593
|
+
return operation();
|
|
7594
|
+
} catch (error) {
|
|
7595
|
+
const remainingMs = deadline - performance.now();
|
|
7596
|
+
if (!["EPERM", "EACCES", "EBUSY"].includes(errorCode(error) ?? "") || remainingMs <= 0)
|
|
7597
|
+
throw error;
|
|
7598
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, Math.min(backoffMs, remainingMs));
|
|
7599
|
+
backoffMs = Math.min(10, backoffMs * 2);
|
|
7600
|
+
}
|
|
7601
|
+
}
|
|
7602
|
+
}
|
|
7603
|
+
function ownsSetupLock(lease, deadline = performance.now()) {
|
|
6816
7604
|
try {
|
|
6817
|
-
|
|
6818
|
-
|
|
7605
|
+
return retrySetupLockSharingViolation(() => {
|
|
7606
|
+
const record = parseLockOwner(readFileSync3(lease.markerPath, "utf8"));
|
|
7607
|
+
return record?.token === lease.token && record.pid === lease.ownerPid && lstatSync3(lease.markerPath).isFile();
|
|
7608
|
+
}, deadline);
|
|
6819
7609
|
} catch {
|
|
6820
7610
|
return false;
|
|
6821
7611
|
}
|
|
@@ -6828,7 +7618,7 @@ function releaseSetupLock(lease) {
|
|
|
6828
7618
|
rmdirSync(lease.lockDir);
|
|
6829
7619
|
} catch {}
|
|
6830
7620
|
}
|
|
6831
|
-
function breakStaleSetupLock(lockDir, observed,
|
|
7621
|
+
function breakStaleSetupLock(lockDir, observed, clock, staleMs, token, isProcessAlive) {
|
|
6832
7622
|
const breakPath = `${lockDir}.stale-${token}`;
|
|
6833
7623
|
try {
|
|
6834
7624
|
renameSync2(lockDir, breakPath);
|
|
@@ -6836,7 +7626,7 @@ function breakStaleSetupLock(lockDir, observed, now, staleMs, token, isProcessAl
|
|
|
6836
7626
|
return;
|
|
6837
7627
|
}
|
|
6838
7628
|
const displaced = observeSetupLock(breakPath);
|
|
6839
|
-
if (displaced === undefined || displaced.fingerprint !== observed.fingerprint || !setupLockIsStale(displaced,
|
|
7629
|
+
if (displaced === undefined || displaced.fingerprint !== observed.fingerprint || !setupLockIsStale(displaced, clock(), staleMs, isProcessAlive)) {
|
|
6840
7630
|
try {
|
|
6841
7631
|
renameSync2(breakPath, lockDir);
|
|
6842
7632
|
} catch {}
|
|
@@ -6951,17 +7741,45 @@ function scheduleSetupLockHeartbeat(heartbeat, intervalMs) {
|
|
|
6951
7741
|
timer.unref();
|
|
6952
7742
|
return () => clearInterval(timer);
|
|
6953
7743
|
}
|
|
6954
|
-
function
|
|
7744
|
+
function readLogSuffix(file) {
|
|
7745
|
+
const fd = openSync(file, "r");
|
|
6955
7746
|
try {
|
|
6956
|
-
const
|
|
7747
|
+
const size = fstatSync(fd).size;
|
|
7748
|
+
const buffer = Buffer.alloc(Math.min(size, 65536));
|
|
7749
|
+
const bytesRead = readSync(fd, buffer, 0, buffer.length, size - buffer.length);
|
|
7750
|
+
return buffer.toString("utf8", 0, bytesRead);
|
|
7751
|
+
} finally {
|
|
7752
|
+
closeSync(fd);
|
|
7753
|
+
}
|
|
7754
|
+
}
|
|
7755
|
+
function logTail(logFile, dataDir) {
|
|
7756
|
+
const tails = [];
|
|
7757
|
+
const appendTail = (file, label) => {
|
|
7758
|
+
try {
|
|
7759
|
+
const lines = readLogSuffix(file).trimEnd().split(`
|
|
6957
7760
|
`);
|
|
6958
|
-
|
|
6959
|
-
Postgres log tail:
|
|
7761
|
+
tails.push(`${label}:
|
|
6960
7762
|
${lines.slice(-5).join(`
|
|
6961
|
-
`)}
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
7763
|
+
`)}`);
|
|
7764
|
+
} catch {}
|
|
7765
|
+
};
|
|
7766
|
+
appendTail(logFile, "Postgres log tail");
|
|
7767
|
+
try {
|
|
7768
|
+
const current = readLogSuffix(join4(dataDir, "current_logfiles")).match(/^stderr\s+(.+)$/m)?.[1];
|
|
7769
|
+
if (current) {
|
|
7770
|
+
const logDir = join4(dataDir, "log");
|
|
7771
|
+
const realDataDir = realpathSync3(dataDir);
|
|
7772
|
+
const realLogDir = realpathSync3(logDir);
|
|
7773
|
+
const candidate = join4(dataDir, current.trim());
|
|
7774
|
+
const lexical = relative2(logDir, candidate);
|
|
7775
|
+
const resolved = relative2(realLogDir, realpathSync3(candidate));
|
|
7776
|
+
if (realLogDir === join4(realDataDir, "log") && [lexical, resolved].every((part) => part !== "" && part !== ".." && !part.startsWith(`..${sep2}`) && !isAbsolute3(part)))
|
|
7777
|
+
appendTail(candidate, "Postgres collector log tail");
|
|
7778
|
+
}
|
|
7779
|
+
} catch {}
|
|
7780
|
+
return tails.length ? `
|
|
7781
|
+
${tails.join(`
|
|
7782
|
+
`)}` : "";
|
|
6965
7783
|
}
|
|
6966
7784
|
|
|
6967
7785
|
// dist/builtin/workflows/src/durable/dbos-local-postgres.ts
|
|
@@ -6991,44 +7809,13 @@ var owner = ownerBag3[ownerKey] ?? {
|
|
|
6991
7809
|
resolve: resolveDbosSystemDatabaseUrl,
|
|
6992
7810
|
provision: provisionResolvedLocalDbos,
|
|
6993
7811
|
shutdown: shutdownResolvedLocalDbos,
|
|
6994
|
-
health: resolvedPostgresHealth
|
|
6995
|
-
provider: resolvedPostgresProvider,
|
|
6996
|
-
failure: postgresLastFailure,
|
|
6997
|
-
recover: recoverManagedPostgres
|
|
7812
|
+
health: resolvedPostgresHealth
|
|
6998
7813
|
};
|
|
6999
7814
|
ownerBag3[ownerKey] = owner;
|
|
7000
|
-
function resolvedPostgresProvider() {
|
|
7001
|
-
if (owner.provider !== resolvedPostgresProvider)
|
|
7002
|
-
return owner.provider?.() ?? "unresolved";
|
|
7003
|
-
return resolvedProvider === embeddedProvider ? "embedded" : resolvedProvider === dockerProvider ? "docker" : "unresolved";
|
|
7004
|
-
}
|
|
7005
|
-
function postgresLastFailure() {
|
|
7006
|
-
if (owner.failure !== postgresLastFailure)
|
|
7007
|
-
return owner.failure?.();
|
|
7008
|
-
return embeddedPostgresLastFailure();
|
|
7009
|
-
}
|
|
7010
|
-
async function recoverManagedPostgres(context, metadata) {
|
|
7011
|
-
if (owner.recover !== recoverManagedPostgres) {
|
|
7012
|
-
if (!owner.recover)
|
|
7013
|
-
throw new Error("Reloaded PostgreSQL owner does not support explicit recovery. Restart Atomic without deleting data.");
|
|
7014
|
-
return owner.recover(context, metadata);
|
|
7015
|
-
}
|
|
7016
|
-
if (process.env.DBOS_SYSTEM_DATABASE_URL?.trim() || resolvedProvider === dockerProvider)
|
|
7017
|
-
throw new Error("Managed recovery is not allowed for the selected provider.");
|
|
7018
|
-
resolvedPostgresHealth()?.invalidate();
|
|
7019
|
-
try {
|
|
7020
|
-
await recoverEmbeddedPostgres(context, metadata);
|
|
7021
|
-
resolvedProvider = embeddedProvider;
|
|
7022
|
-
} catch (error) {
|
|
7023
|
-
if (error instanceof EmbeddedPostgresCleanupPendingError)
|
|
7024
|
-
resolvedProvider = embeddedProvider;
|
|
7025
|
-
throw error;
|
|
7026
|
-
}
|
|
7027
|
-
}
|
|
7028
7815
|
function resolvedPostgresHealth(url) {
|
|
7029
7816
|
if (owner.health !== resolvedPostgresHealth)
|
|
7030
7817
|
return owner.health?.(url);
|
|
7031
|
-
if (
|
|
7818
|
+
if (explicitDbosSystemDatabaseUrl() || resolvedProvider !== embeddedProvider)
|
|
7032
7819
|
return;
|
|
7033
7820
|
if (url !== undefined && url !== embeddedDbosSystemDatabaseUrl())
|
|
7034
7821
|
return;
|
|
@@ -7049,7 +7836,7 @@ function resolveDbosSystemDatabaseUrl() {
|
|
|
7049
7836
|
async function provisionResolvedLocalDbos() {
|
|
7050
7837
|
if (owner.provision !== provisionResolvedLocalDbos)
|
|
7051
7838
|
return owner.provision();
|
|
7052
|
-
if (
|
|
7839
|
+
if (explicitDbosSystemDatabaseUrl())
|
|
7053
7840
|
return;
|
|
7054
7841
|
await (resolvedProvider ?? embeddedProvider)();
|
|
7055
7842
|
}
|
|
@@ -7166,7 +7953,7 @@ async function dockerPostgresQueryReady(host, port) {
|
|
|
7166
7953
|
}
|
|
7167
7954
|
}
|
|
7168
7955
|
async function resolve() {
|
|
7169
|
-
const explicit =
|
|
7956
|
+
const explicit = explicitDbosSystemDatabaseUrl();
|
|
7170
7957
|
if (explicit)
|
|
7171
7958
|
return;
|
|
7172
7959
|
try {
|
|
@@ -9438,7 +10225,7 @@ function workflowArtifactRoot() {
|
|
|
9438
10225
|
const override = getEnvValue(ENV_WORKFLOW_ARTIFACT_DIR);
|
|
9439
10226
|
if (override !== undefined && override.length > 0)
|
|
9440
10227
|
return override;
|
|
9441
|
-
return join5(
|
|
10228
|
+
return join5(dirname4(getAgentDir()), "workflows");
|
|
9442
10229
|
}
|
|
9443
10230
|
function workflowArtifactRunsRoot() {
|
|
9444
10231
|
return join5(workflowArtifactRoot(), "runs");
|