426e9eeabd
Voice Workbench / headless workbench (mocked backends) (push) Has been cancelled
Voice Workbench / real acoustic lane (nightly, provisioned only) (push) Has been cancelled
ci / test (push) Has been cancelled
ci / lint-and-format (push) Has been cancelled
ci / build (push) Has been cancelled
ci / dev-startup (push) Has been cancelled
gitleaks / gitleaks (push) Has been cancelled
Markdown Links / Relative Markdown Links (push) Has been cancelled
Quality (Extended) / Homepage Build (PR smoke) (push) Has been cancelled
Quality (Extended) / Comment-only diff guard (push) Has been cancelled
Quality (Extended) / Format + Type Safety Ratchet (push) Has been cancelled
Quality (Extended) / Develop Gate (secret scan + UI determinism) (push) Has been cancelled
Quality (Extended) / Develop Gate (lint) (push) Has been cancelled
Chat shell gestures / Chat shell gesture + parity e2e (push) Has been cancelled
Cloud Gateway Discord / Test (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx @biomejs/biome check packages/lifeops-bench/src, benchmark-lint) (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx vitest run --config packages/lifeops-bench/vitest.config.ts --root packages/lifeops-bench --passWithNoTests, benchmark-tests) (push) Has been cancelled
Build Agent Image / build-and-push (push) Has been cancelled
Dev Smoke / bun run dev onboarding chat (push) Has been cancelled
Dev Smoke / Vite HMR dependency-level smoke (push) Has been cancelled
Electrobun Submodule Guard / electrobun gitlink is fetchable (push) Has been cancelled
Publish @elizaos/example-code / check_npm (push) Has been cancelled
Publish @elizaos/example-code / publish_npm (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / verify_version (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / publish_npm (push) Has been cancelled
Sandbox Live Smoke / Sandbox live smoke (push) Has been cancelled
Snap Build & Test / Build Snap (amd64) (push) Has been cancelled
Snap Build & Test / Build Snap (arm64) (push) Has been cancelled
Test Packaging / elizaos CLI global-install smoke (node + bun) (push) Has been cancelled
Cloud Gateway Webhook / Test (push) Has been cancelled
Cloud Tests / lint-and-types (push) Has been cancelled
Cloud Tests / unit-tests (push) Has been cancelled
Cloud Tests / integration-tests (push) Has been cancelled
Cloud Tests / e2e-tests (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Apps Worker (Product 2) / Determine environment (push) Has been cancelled
Deploy Apps Worker (Product 2) / Deploy apps worker to apps-control host (${{ needs.determine-env.outputs.environment }}) (push) Has been cancelled
Deploy Eliza Provisioning Worker / Determine environment (push) Has been cancelled
Deploy Eliza Provisioning Worker / Deploy worker to Hetzner host (${{ needs.determine-env.outputs.environment }} @ ${{ needs.determine-env.outputs.deployment_sha }}) (push) Has been cancelled
Dev Smoke / Classify changed paths (push) Has been cancelled
supply-chain / sbom (push) Has been cancelled
supply-chain / vulnerability-scan (push) Has been cancelled
Build, Push & Deploy to Phala Cloud / build-and-push (push) Has been cancelled
Test Packaging / Validate Packaging Configs (push) Has been cancelled
Test Packaging / Build & Test PyPI Package (push) Has been cancelled
Test Packaging / PyPI on Python ${{ matrix.python }} (push) Has been cancelled
Test Packaging / Pack & Test JS Tarballs (push) Has been cancelled
UI Fixture E2E / ui-fixture-e2e (push) Has been cancelled
UI Fixture E2E / fixture-e2e (push) Has been cancelled
UI Story Gate / story-gate (push) Has been cancelled
vault-ci / test (macos-latest) (push) Has been cancelled
vault-ci / test (ubuntu-latest) (push) Has been cancelled
vault-ci / test (windows-latest) (push) Has been cancelled
vault-ci / app-core wiring tests (push) Has been cancelled
verify-patches / verify patches/CHECKSUMS.sha256 (push) Has been cancelled
Voice Benchmark Smoke / voice-emotion fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voiceagentbench fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench-quality unit smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench TypeScript unit (no audio) (push) Has been cancelled
Voice Benchmark Smoke / voice bench smoke summary (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/app-core test bun run --cwd packages/elizaos test bun run --cwd packages/cloud/shared test], app-and-cli) (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/scenario-runner test bun run --cwd packages/vault test bun run --cwd packages/security test bun run --cwd plugins/plugin-coding-tools test], framework-packages) (push) Has been cancelled
Windows CI / windows ([bun run --cwd plugins/plugin-elizacloud test bun run --cwd plugins/plugin-discord test bun run --cwd plugins/plugin-anthropic test bun run --cwd plugins/plugin-openai test bun run --cwd plugins/plugin-app-control test bun run --cwd plugins/pl… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run build --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/agent --concurrency=4 node packages/scripts/run-bash-linux-only.mjs scripts/verify-riscv64-buildpaths.sh node packages/scripts/run… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run typecheck --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/cloud-shared --concurrency=4 bun run --cwd packages/core test bun run --cwd packages/shared test], core-runtime, 75) (push) Has been cancelled
229 lines
7.7 KiB
JavaScript
229 lines
7.7 KiB
JavaScript
/**
|
|
* Cloud deploy freshness guard (#14083).
|
|
*
|
|
* Zombie CI runs that were stuck `queued` during a runner freeze eventually
|
|
* execute and deploy their OLD ref OVER a newer build — staging/prod regress to
|
|
* a pre-fix bundle HOURS after newer builds were live (observed #14082: staging
|
|
* regressed to `8deb9cbd07`, a pre-#13410 ref, clobbering newer deploys).
|
|
*
|
|
* This guard runs BEFORE `wrangler pages deploy` / `wrangler deploy` and:
|
|
* 1. Fetches the currently-served build stamp (the deployed
|
|
* `eliza-renderer-build.json` for Pages, or `/api/health` for the Worker,
|
|
* whose `commit` field records the ref that built it).
|
|
* 2. Skips the deploy when the run's SHA is an ANCESTOR of the served commit
|
|
* (`git merge-base --is-ancestor <runSha> <servedCommit>`) — i.e. the
|
|
* currently-served build is strictly newer than what this run would ship.
|
|
* 3. A `--force` flag (wired from a `workflow_dispatch` input) bypasses the
|
|
* guard for intentional rollbacks.
|
|
*
|
|
* FAIL-OPEN by design: the guard only SKIPS on a DEFINITIVE stale signal (the
|
|
* run SHA is provably an ancestor of a known-newer served commit). Every
|
|
* ambiguous state — served stamp unreachable/unparseable, no commit recorded,
|
|
* histories unrelated, ancestry undeterminable — DEPLOYS. A freshness guard must
|
|
* never turn a transient signal-fetch failure into an undeployable state (that
|
|
* would block the exact fix that needs to ship). "Deploy" is the safe default;
|
|
* "skip" is the narrow, provable case.
|
|
*/
|
|
|
|
export const DEPLOY_FRESHNESS_SCHEMA = "elizaos.deploy.freshness-guard/v1";
|
|
|
|
/**
|
|
* @typedef {"deploy" | "skip"} FreshnessDecision
|
|
* @typedef {object} FreshnessResult
|
|
* @property {FreshnessDecision} decision
|
|
* @property {string} reason machine-stable reason code
|
|
* @property {string} detail human-readable explanation
|
|
* @property {string|null} runSha
|
|
* @property {string|null} servedCommit
|
|
*/
|
|
|
|
/**
|
|
* Pure decision core. No I/O — every input is passed in so this is fully
|
|
* unit-testable and deterministic.
|
|
*
|
|
* @param {object} args
|
|
* @param {string|null|undefined} args.runSha the SHA this run would deploy
|
|
* @param {string|null|undefined} args.servedCommit commit of the currently-served build (null if unknown)
|
|
* @param {boolean} [args.force] bypass the guard (intentional rollback)
|
|
* @param {(runSha: string, servedCommit: string) => (boolean|null)} args.isAncestor
|
|
* returns true if runSha is a strict-or-equal ancestor of servedCommit,
|
|
* false if it is not, and null if ancestry could NOT be determined
|
|
* (histories unrelated / commit not fetchable / git error).
|
|
* @returns {FreshnessResult}
|
|
*/
|
|
export function decideDeployFreshness({
|
|
runSha,
|
|
servedCommit,
|
|
force = false,
|
|
isAncestor,
|
|
}) {
|
|
const normalizedRun =
|
|
typeof runSha === "string" && runSha.trim() ? runSha.trim() : null;
|
|
const normalizedServed =
|
|
typeof servedCommit === "string" && servedCommit.trim()
|
|
? servedCommit.trim()
|
|
: null;
|
|
|
|
const base = {
|
|
runSha: normalizedRun,
|
|
servedCommit: normalizedServed,
|
|
};
|
|
|
|
if (force) {
|
|
return {
|
|
...base,
|
|
decision: "deploy",
|
|
reason: "forced",
|
|
detail: "--force set: bypassing freshness guard (intentional rollback).",
|
|
};
|
|
}
|
|
|
|
if (!normalizedRun) {
|
|
// Can't reason about freshness with no run SHA — deploy (fail-open).
|
|
return {
|
|
...base,
|
|
decision: "deploy",
|
|
reason: "no_run_sha",
|
|
detail: "No run SHA provided; cannot compare freshness. Deploying.",
|
|
};
|
|
}
|
|
|
|
if (!normalizedServed) {
|
|
// No served stamp / no commit recorded → first deploy, or an old build
|
|
// without a stamp. Deploy (fail-open).
|
|
return {
|
|
...base,
|
|
decision: "deploy",
|
|
reason: "no_served_commit",
|
|
detail:
|
|
"No served build commit available (missing/unstamped build). Deploying.",
|
|
};
|
|
}
|
|
|
|
if (normalizedRun === normalizedServed) {
|
|
// Re-deploying the same commit is legitimate (secret rotation, retry).
|
|
return {
|
|
...base,
|
|
decision: "deploy",
|
|
reason: "same_commit",
|
|
detail:
|
|
"Run SHA equals the served commit. Deploying (idempotent redeploy).",
|
|
};
|
|
}
|
|
|
|
let ancestor;
|
|
try {
|
|
ancestor = isAncestor(normalizedRun, normalizedServed);
|
|
} catch {
|
|
ancestor = null;
|
|
}
|
|
|
|
if (ancestor === true) {
|
|
// The run's SHA is an ancestor of the served commit → the served build is
|
|
// strictly NEWER than what this run would ship → this is a stale run.
|
|
return {
|
|
...base,
|
|
decision: "skip",
|
|
reason: "stale_run",
|
|
detail:
|
|
`Run SHA ${normalizedRun} is an ancestor of the currently-served ` +
|
|
`commit ${normalizedServed}: the served build is newer. Skipping stale deploy.`,
|
|
};
|
|
}
|
|
|
|
if (ancestor === false) {
|
|
// The run SHA is NOT an ancestor of the served commit → it is newer or on a
|
|
// divergent tip that should win. Deploy.
|
|
return {
|
|
...base,
|
|
decision: "deploy",
|
|
reason: "run_is_newer",
|
|
detail:
|
|
`Run SHA ${normalizedRun} is not an ancestor of served commit ` +
|
|
`${normalizedServed}: this run is newer or divergent. Deploying.`,
|
|
};
|
|
}
|
|
|
|
// ancestor === null → ancestry undeterminable (unrelated histories, commit
|
|
// not fetchable, git error). Fail-open: deploy.
|
|
return {
|
|
...base,
|
|
decision: "deploy",
|
|
reason: "ancestry_unknown",
|
|
detail:
|
|
`Could not determine ancestry between run SHA ${normalizedRun} and ` +
|
|
`served commit ${normalizedServed}. Deploying (fail-open).`,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Extract the served build commit from a fetched `eliza-renderer-build.json`
|
|
* body. Returns the commit string, or null when absent/unparseable/blank.
|
|
*
|
|
* @param {string|null|undefined} body raw response body text
|
|
* @returns {string|null}
|
|
*/
|
|
export function parseServedCommit(body) {
|
|
if (typeof body !== "string" || !body.trim()) return null;
|
|
let parsed;
|
|
try {
|
|
parsed = JSON.parse(body);
|
|
} catch {
|
|
return null;
|
|
}
|
|
if (!parsed || typeof parsed !== "object") return null;
|
|
const commit = /** @type {{ commit?: unknown }} */ (parsed).commit;
|
|
if (typeof commit !== "string" || !commit.trim()) return null;
|
|
return commit.trim();
|
|
}
|
|
|
|
/**
|
|
* Fetch the served deploy stamp and return its recorded commit, or null on any
|
|
* failure (fail-open — an unreachable stamp must not block deploys).
|
|
*
|
|
* @param {string} baseUrl e.g. "https://staging.elizacloud.ai"
|
|
* @param {object} [opts]
|
|
* @param {typeof fetch} [opts.fetchImpl]
|
|
* @param {string} [opts.stampPath]
|
|
* @param {number} [opts.timeoutMs]
|
|
* @returns {Promise<string|null>}
|
|
*/
|
|
export async function fetchServedCommit(
|
|
baseUrl,
|
|
{
|
|
fetchImpl = fetch,
|
|
stampPath = "/eliza-renderer-build.json",
|
|
timeoutMs = 15000,
|
|
} = {},
|
|
) {
|
|
if (typeof baseUrl !== "string" || !baseUrl.trim()) return null;
|
|
const normalizedStampPath =
|
|
typeof stampPath === "string" && stampPath.trim()
|
|
? stampPath.trim()
|
|
: "/eliza-renderer-build.json";
|
|
const path = normalizedStampPath.startsWith("/")
|
|
? normalizedStampPath
|
|
: `/${normalizedStampPath}`;
|
|
const url = `${baseUrl.replace(/\/+$/, "")}${path}`;
|
|
const controller =
|
|
typeof AbortController !== "undefined" ? new AbortController() : null;
|
|
const timer = controller
|
|
? setTimeout(() => controller.abort(), timeoutMs)
|
|
: null;
|
|
try {
|
|
const res = await fetchImpl(url, {
|
|
// Never let a CDN/service-worker hand back a cached stamp — we need the
|
|
// live served build identity.
|
|
headers: { "cache-control": "no-cache" },
|
|
...(controller ? { signal: controller.signal } : {}),
|
|
});
|
|
if (!res?.ok) return null;
|
|
const body = await res.text();
|
|
return parseServedCommit(body);
|
|
} catch {
|
|
return null;
|
|
} finally {
|
|
if (timer) clearTimeout(timer);
|
|
}
|
|
}
|