@runeditrun/rer 0.2.20 → 0.2.21
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/cli/demo-host.mjs +4 -3
- package/cli/demo-removal-provider.mjs +24 -0
- package/cli/deploy-command.mjs +8 -5
- package/cli/deploy-hook.mjs +10 -14
- package/global/CHANGELOG.md +7 -1
- package/modules/container/build.mjs +3 -1
- package/modules/demo-host/README.md +9 -0
- package/modules/demo-host/container.mjs +14 -8
- package/modules/demo-host/diagnostics.mjs +1 -0
- package/modules/demo-host/placement.mjs +23 -0
- package/modules/demo-host/plan.mjs +1 -1
- package/modules/demo-host/startup.mjs +1 -1
- package/modules/demo-host/worker.mjs +1 -1
- package/modules/deploy-kit/README.md +12 -0
- package/modules/deploy-kit/health-request.mjs +7 -5
- package/package.json +1 -1
package/cli/demo-host.mjs
CHANGED
|
@@ -21,7 +21,7 @@ export async function demoHostCommand(project, options, store, signal, out, oper
|
|
|
21
21
|
let plan;
|
|
22
22
|
try { plan = demoPlan({ project: app.project, environment: options.environment ?? 'production', compatibilityDate: app.compatibilityDate, originVar: app.originVar, declaration, turnstileSiteKey: process.env.TURNSTILE_SITE_KEY?.trim() }); }
|
|
23
23
|
catch (error) { throw invalid(`The demo deploy declaration is invalid (${error.message}). deploy-demo.json holds {"version": 1, "domain": "<run site apex>", "name": "<product name>"}, optionally "maxInstances", "instanceType" (${INSTANCE_TYPES.join(', ')}; default basic) and plain "settings".`); }
|
|
24
|
-
if (options.remove) return removeDemo(plan, store);
|
|
24
|
+
if (options.remove) return removeDemo(plan, store, signal);
|
|
25
25
|
if (process.env.RER_DEMO_OPERATOR_TOKEN && (process.env.RER_DEMO_OPERATOR_TOKEN.length < 32 || process.env.RER_DEMO_OPERATOR_TOKEN.length > 512)) throw invalid('RER_DEMO_OPERATOR_TOKEN must contain 32 to 512 characters.');
|
|
26
26
|
const folder = join(project.root, '.rer', 'demo-host');
|
|
27
27
|
await rm(folder, { recursive: true, force: true });
|
|
@@ -54,15 +54,16 @@ export async function demoHostCommand(project, options, store, signal, out, oper
|
|
|
54
54
|
return { dryRun: false, deployed: true, origin: plan.origin, demo: summary };
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
async function removeDemo(plan, store) {
|
|
57
|
+
async function removeDemo(plan, store, signal) {
|
|
58
58
|
const names = ['CLOUDFLARE_ACCOUNT_ID', 'CLOUDFLARE_API_TOKEN'];
|
|
59
59
|
if (names.some(name => !process.env[name]?.trim())) throw missing(`${names.join(' and ')} are required to remove the demo; see DEMO.md "Removing a hosted demo".`);
|
|
60
60
|
const { cloudflare } = await import('../modules/deploy-kit/provider.mjs');
|
|
61
61
|
const { providerRefusal } = await import('../modules/deploy-kit/diagnostics.mjs');
|
|
62
62
|
const { demoRemove } = await import('../modules/demo-host/remove.mjs');
|
|
63
|
+
const { demoRemovalFetch } = await import('./demo-removal-provider.mjs');
|
|
63
64
|
await store.step(`Removing the demo Worker ${plan.worker} on ${plan.hostname}`);
|
|
64
65
|
let result;
|
|
65
|
-
try { result = await demoRemove({ api: cloudflare({ accountId: process.env.CLOUDFLARE_ACCOUNT_ID, token: process.env.CLOUDFLARE_API_TOKEN }), plan }); }
|
|
66
|
+
try { result = await demoRemove({ api: cloudflare({ accountId: process.env.CLOUDFLARE_ACCOUNT_ID, token: process.env.CLOUDFLARE_API_TOKEN, fetch: demoRemovalFetch(signal) }), plan }); }
|
|
66
67
|
catch (error) {
|
|
67
68
|
if (error instanceof RerError) throw error;
|
|
68
69
|
const code = /^[a-z0-9-]{1,80}$/.test(error.message) ? error.message : 'demo-remove-failed';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { setTimeout as pause } from 'node:timers/promises';
|
|
2
|
+
|
|
3
|
+
// Only demo removal uses these retries. The provider's original request signal
|
|
4
|
+
// bounds every attempt and backoff together; no retry gets a fresh deadline.
|
|
5
|
+
export function demoRemovalFetch(signal, request = globalThis.fetch) {
|
|
6
|
+
return async (input, init = {}) => {
|
|
7
|
+
const signals = [init.signal, signal].filter(Boolean);
|
|
8
|
+
const bounded = signals.length ? AbortSignal.any(signals) : undefined;
|
|
9
|
+
const method = init.method ?? 'GET';
|
|
10
|
+
for (let attempt = 0; ; attempt++) {
|
|
11
|
+
bounded?.throwIfAborted();
|
|
12
|
+
const response = await request(input, { ...init, signal: bounded });
|
|
13
|
+
// A DELETE can have succeeded before the provider lost its answer. Its
|
|
14
|
+
// retry then sees 404; the remover still performs its full absence readback.
|
|
15
|
+
if (method === 'DELETE' && response.status === 404) {
|
|
16
|
+
void response.body?.cancel().catch(() => {});
|
|
17
|
+
return new Response(null, { status: 204 });
|
|
18
|
+
}
|
|
19
|
+
if (!['GET', 'DELETE'].includes(method) || response.status < 500 || response.status > 599 || attempt === 2) return response;
|
|
20
|
+
void response.body?.cancel().catch(() => {});
|
|
21
|
+
await pause(250 * 2 ** attempt, undefined, { signal: bounded });
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
package/cli/deploy-command.mjs
CHANGED
|
@@ -78,9 +78,9 @@ export async function deployCommand(context) {
|
|
|
78
78
|
const command = (verb, extra = [], values = env, more = {}) => owner([verb, '--declaration', path, '--environment', environment, ...(hookRecord ? ['--state', hookRecord] : []), ...extra], values, { cwd: root, localOnlyKeys, ...more });
|
|
79
79
|
// A hook that deployed through the kit's standard record lets rer issue and
|
|
80
80
|
// retire the setup token; a hook keeping an unnamed record of its own keeps its token.
|
|
81
|
-
let recorded;
|
|
81
|
+
let recorded, hookReturned = false;
|
|
82
82
|
const inspect = async (origin = deployed?.origin) => {
|
|
83
|
-
try { return recorded = await command('inspect', [], env, {propagation:observedReadiness(origin)?.propagation}); }
|
|
83
|
+
try { return recorded = await command('inspect', [], env, hookReturned ? {} : {propagation:observedReadiness(origin)?.propagation}); }
|
|
84
84
|
catch (error) { if (error.message !== 'missing-owner-receipt') throw error; }
|
|
85
85
|
};
|
|
86
86
|
let observedClaims = [];
|
|
@@ -97,18 +97,21 @@ export async function deployCommand(context) {
|
|
|
97
97
|
for (const key of Object.keys(process.env)) if (!Object.hasOwn(saved, key)) delete process.env[key];
|
|
98
98
|
Object.assign(process.env, saved);
|
|
99
99
|
}
|
|
100
|
+
hookReturned = true;
|
|
100
101
|
if (options.dryRun) return deployed;
|
|
101
102
|
await rememberHookState(root, environment, deployed?.state);
|
|
102
103
|
hookRecord = await hookState(root, environment);
|
|
103
104
|
const origin = hookOrigin(deployed, deployAgain(options));
|
|
104
105
|
const uploaded = observedReadiness(origin);
|
|
105
|
-
step = 'wait for the deployed source';
|
|
106
|
-
await waitForSource({ origin, sourceSha, uploaded, again: deployAgain(options) });
|
|
107
106
|
step = 'verify recorded deployment';
|
|
108
|
-
|
|
107
|
+
// A hook may already have claimed the owner and retired its token. Read the
|
|
108
|
+
// current version independently of the original upload's spent deadline.
|
|
109
|
+
const state = await inspect(origin);
|
|
109
110
|
if ((state?.origin ?? origin) !== origin || claims.some(item => item.origin !== origin)) throw new Error('owner-claim-origin-mismatch');
|
|
110
111
|
if (claims.some(item => !item.outcome)) throw new Error('owner-claim-failed');
|
|
111
112
|
claimed = claims.at(-1)?.outcome;
|
|
113
|
+
step = 'wait for the deployed source';
|
|
114
|
+
await waitForSource({ origin, sourceSha, versionId: state?.versionId ?? (!claims.length && !deployed.owner ? uploaded?.versionId : undefined), again: deployAgain(options) });
|
|
112
115
|
step = 'claim owner';
|
|
113
116
|
if (typeof deployed.setupToken === 'string' && deployed.setupToken) addSecret(deployed.setupToken);
|
|
114
117
|
const sentSecrets = (uploaded?.sentSecrets ?? []).filter(binding => uploaded.propagation.matchesToken(binding, env[declaration.secrets.find(item => item.binding === binding)?.environment]));
|
package/cli/deploy-hook.mjs
CHANGED
|
@@ -12,25 +12,21 @@ export function hookOrigin(deployed, again) {
|
|
|
12
12
|
throw hookFailure(`The deploy hook finished without reporting a live deployment, so rer claimed no owner. A deploy hook returns { deployed: true, origin } once its upload is live. Check the hook's output above, fix the hook, then run ${again} again.`);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export async function waitForSource({ origin, sourceSha,
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
try { await waitHealth({ origin, expected: { sourceSha, ...(uploaded?.versionId ? { versionId: uploaded.versionId } : {}) },
|
|
22
|
-
request: (url, init) => globalThis.fetch(url, init),
|
|
23
|
-
...(window ? { window, clock: window.clock, sleep: window.sleep, freshUpload: true } : {}) }); }
|
|
15
|
+
export async function waitForSource({ origin, sourceSha, versionId, again }) {
|
|
16
|
+
// Finalization gets its own 90 seconds after the hook returns: upload, owner
|
|
17
|
+
// claim and token retirement may have consumed the upload readiness window.
|
|
18
|
+
// Retirement also creates a new version; use the current recorded identity.
|
|
19
|
+
try { await waitHealth({ origin, expected: { sourceSha, ...(versionId ? { versionId } : {}) }, retryIdentityMismatch: true,
|
|
20
|
+
request: (url, init) => globalThis.fetch(url, init) }); }
|
|
24
21
|
catch (error) {
|
|
25
22
|
const last = error.attempts?.at(-1);
|
|
26
|
-
let named;
|
|
27
|
-
try {
|
|
23
|
+
let named, version;
|
|
24
|
+
try { const identity = JSON.parse(last.body).deployment; named = identity?.sourceSha; version = identity?.versionId; } catch {}
|
|
28
25
|
const seen = !last || last.status === null ? 'it did not answer'
|
|
29
26
|
: last.status !== 200 ? `its last answer was HTTP ${last.status}`
|
|
30
|
-
: typeof named === 'string' && /^[0-9a-f]{7,64}$/.test(named) ? `it still answers for commit ${named.slice(0, 12)}`
|
|
27
|
+
: typeof named === 'string' && /^[0-9a-f]{7,64}$/.test(named) ? `it still answers for commit ${named.slice(0, 12)}${typeof version === 'string' && /^[a-zA-Z0-9_-]{1,64}$/.test(version) ? `, Worker version ${version}` : ''}`
|
|
31
28
|
: 'it answers without a deploy identity';
|
|
32
|
-
|
|
33
|
-
throw hookFailure(`The deploy hook reported a deployment at ${origin}, but its /health never named this checkout's commit ${sourceSha.slice(0, 12)}${uploaded?.versionId ? ' and the uploaded Worker version' : ''}${deadline} (${seen}), so rer stopped before owner finalization. Check that the hook uploaded this build and that /health answers deploymentHealth(env), then run ${again} again.`);
|
|
29
|
+
throw hookFailure(`The deploy hook reported a deployment at ${origin}, but its /health did not confirm this checkout's commit ${sourceSha.slice(0, 12)}${versionId ? ' and the current recorded Worker version' : ''} within the 90-second finalization wait (${seen}; ${last?.errorClass ?? 'health-timeout'}), so rer stopped before owner finalization. Check that the hook uploaded this build and that /health answers deploymentHealth(env), then run ${again} again.`);
|
|
34
30
|
}
|
|
35
31
|
}
|
|
36
32
|
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 0.2.21
|
|
4
|
+
|
|
5
|
+
- Demo removal retries transient Cloudflare provider failures while preserving the resource ownership checks.
|
|
6
|
+
- Deployment finalization lets health and source identity settle before refusing a successful rollout.
|
|
7
|
+
- Hosted demos keep the same visitor reservation while Cloudflare prepares an available container, within the existing startup budget. Placement exhaustion returns a clean capacity refusal.
|
|
8
|
+
- Status polling retains a failed start's terminal answer briefly after cleanup, including after Durable Object recovery.
|
|
9
|
+
- Demo image builds load Vite configuration preparation before checking the root Wrangler Worker entry.
|
|
4
10
|
|
|
5
11
|
- Concurrent checkout launches validate server registry state under its transaction lock, avoiding a false foreign-file refusal during atomic updates.
|
|
6
12
|
- A checkout behind the front door serves its run-site preview above the app's assigned port instead of trying privileged ports.
|
|
@@ -18,9 +18,11 @@ async function buildImage(root, { output = join(root,'.rer/container/image'), en
|
|
|
18
18
|
declaration ??= JSON.parse(await readFile(join(root,'deploy.json'),'utf8'));
|
|
19
19
|
engine ??= declaration.container?.engine ?? 'workerd'; cacheContract ??= declaration.container?.cacheContract; runner ??= declaration.container?.runner;
|
|
20
20
|
if (!['workerd','node'].includes(engine)) throw new Error('Unsupported container engine');
|
|
21
|
-
await checkBoundary(root,{engine,cacheContract});
|
|
22
21
|
const vite = await import(pathToFileURL(require.resolve('vite'))), loaded = await vite.loadConfigFromFile({ command:'build',mode:'production' },undefined,root);
|
|
23
22
|
if (!loaded) throw new Error('Vite configuration missing');
|
|
23
|
+
// Config loading may prepare the seed's root Wrangler configuration. Inspect
|
|
24
|
+
// its declared entry after that preparation, still before compiling the app.
|
|
25
|
+
await checkBoundary(root,{engine,cacheContract});
|
|
24
26
|
const config = loaded.config;
|
|
25
27
|
const outputExports = new Map();
|
|
26
28
|
const freshServerFiles = new Set(), serverOutput = resolve(root,'dist/server');
|
|
@@ -103,3 +103,12 @@ Failed destruction retains its alarm and capacity reservation for cleanup;
|
|
|
103
103
|
only confirmed destruction (or an already-stopped container) releases the
|
|
104
104
|
place. A cleanup failure is logged separately and cannot replace the startup
|
|
105
105
|
failure shown to the visitor.
|
|
106
|
+
|
|
107
|
+
Cloudflare may briefly report that it has no prepared container instance even
|
|
108
|
+
when the application is below `max_instances`. `placement.mjs` keeps the same
|
|
109
|
+
reservation and launch options, requests placement again only for that specific
|
|
110
|
+
provider response, and stays within the original startup deadline. Boot, health
|
|
111
|
+
and claim errors are not retried. Placement exhaustion answers 503 with the
|
|
112
|
+
capacity notice and releases the reservation. Cleanup keeps only that terminal
|
|
113
|
+
answer and correlation for one minute, so a status poll after object recovery
|
|
114
|
+
still receives the right answer; its alarm then deletes the remaining metadata.
|
|
@@ -3,6 +3,7 @@ import { claimKeys, signClaim } from './claim.mjs';
|
|
|
3
3
|
import { bounded, boundedFetch, category, report } from './diagnostics.mjs';
|
|
4
4
|
import { endedPage, clearCookie } from './pages.mjs';
|
|
5
5
|
import { finishStart } from './startup.mjs';
|
|
6
|
+
import { placeContainer } from './placement.mjs';
|
|
6
7
|
|
|
7
8
|
// One visitor's demo: a Durable Object (newUniqueId) and its container, the
|
|
8
9
|
// seed's image from `rer build --platform container` on the workerd engine.
|
|
@@ -70,19 +71,16 @@ export class DemoContainer extends DurableObject {
|
|
|
70
71
|
|
|
71
72
|
/** Start the container, wait for /health, claim the owner; returns the claim's 303. */
|
|
72
73
|
async start({ origin, originVar, ends, endsLocal, settings, correlation }) {
|
|
73
|
-
this.correlation = correlation; this.started = Date.now(); this.stopped = false;
|
|
74
|
+
this.correlation = correlation; this.started = Date.now(); this.stopped = false; this.cancelled = false;
|
|
74
75
|
const deadline = this.started + this.startTimeout;
|
|
75
76
|
const id = this.ctx.id.toString(), keys = await claimKeys(), now = Date.now();
|
|
76
77
|
await this.ctx.storage.put({ ends, seen: now, correlation, started: this.started, startDeadline: deadline });
|
|
77
78
|
report(correlation, this.started, 'start');
|
|
78
79
|
if (this.stopped) throw new Error('container-stopped');
|
|
79
|
-
this
|
|
80
|
+
await placeContainer(this, { enableInternet: true, env: { ...settings, RER_DEMO: '1', [originVar]: origin, RER_INGRESS_ORIGIN: origin,
|
|
80
81
|
SESSION_SECRET: random(), SETUP_TOKEN: random(), OWNER_EMAIL: OWNER, RER_OWNER_CLAIM_ISSUER: origin, RER_OWNER_CLAIM_INSTALLATION_ID: id,
|
|
81
|
-
RER_OWNER_CLAIM_PUBLIC_KEYS: JSON.stringify(keys.publicKeys), RER_DEMO_EXPIRES: endsLocal } });
|
|
82
|
-
// A container that stops by itself ends the demo too.
|
|
83
|
-
this.watch();
|
|
82
|
+
RER_OWNER_CLAIM_PUBLIC_KEYS: JSON.stringify(keys.publicKeys), RER_DEMO_EXPIRES: endsLocal } }, deadline);
|
|
84
83
|
await this.ctx.storage.setAlarm(Date.now());
|
|
85
|
-
await this.healthy(deadline);
|
|
86
84
|
const token = await signClaim(keys, { origin, installationId: id, email: OWNER, now: Date.now() });
|
|
87
85
|
const claimed = await boundedFetch(this.port(), 'http://container/auth/owner-claim', { method: 'POST', redirect: 'manual',
|
|
88
86
|
headers: { origin, 'content-type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ token }) }, Math.max(1, Math.min(10_000, deadline - Date.now())));
|
|
@@ -112,6 +110,8 @@ export class DemoContainer extends DurableObject {
|
|
|
112
110
|
}
|
|
113
111
|
|
|
114
112
|
async exited(error) {
|
|
113
|
+
this.watching = false;
|
|
114
|
+
this.stopReason = error ? category(error) : 'container-stopped';
|
|
115
115
|
this.stopped = true;
|
|
116
116
|
this.record('exit', { outcome: error ? category(error) : 'exited', ...(Number.isInteger(error?.exitCode) ? { exitCode: error.exitCode } : {}) });
|
|
117
117
|
if ((await this.ctx.storage.get('startup'))?.phase === 'starting') return;
|
|
@@ -140,7 +140,7 @@ export class DemoContainer extends DurableObject {
|
|
|
140
140
|
async alarm() {
|
|
141
141
|
const state = await this.ctx.storage.get(['ends', 'seen', 'startDeadline']), now = Date.now();
|
|
142
142
|
if (await this.ctx.storage.get('stopping')) return this.end();
|
|
143
|
-
if (!state.get('ends')) return;
|
|
143
|
+
if (!state.get('ends')) return this.ctx.storage.deleteAll();
|
|
144
144
|
const due = Math.min(state.get('ends'), state.get('seen') + this.idle, state.get('startDeadline') ?? Infinity);
|
|
145
145
|
if (now >= due || !this.container.running) {
|
|
146
146
|
if ((await this.ctx.storage.get('startup'))?.phase === 'starting') { this.stopped = true; return; }
|
|
@@ -158,7 +158,8 @@ export class DemoContainer extends DurableObject {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
async cleanup() {
|
|
161
|
-
this.stopped = true; this.wake?.();
|
|
161
|
+
this.cancelled = true; this.stopped = true; this.wake?.();
|
|
162
|
+
const startup = await this.ctx.storage.get('startup');
|
|
162
163
|
// Keep the alarm and capacity reservation if destruction fails; retry cleanup.
|
|
163
164
|
await this.ctx.storage.put('stopping', true);
|
|
164
165
|
await this.ctx.storage.setAlarm(Date.now() + this.cleanupRetry);
|
|
@@ -170,6 +171,11 @@ export class DemoContainer extends DurableObject {
|
|
|
170
171
|
await bounded(this.env.CAPACITY.get(this.env.CAPACITY.idFromName('capacity')).release(this.ctx.id.toString()), 2000);
|
|
171
172
|
await this.ctx.storage.deleteAlarm();
|
|
172
173
|
await this.ctx.storage.deleteAll();
|
|
174
|
+
// Retain only the terminal answer briefly, so polling survives a fresh DO.
|
|
175
|
+
if (startup?.phase === 'failed') {
|
|
176
|
+
await this.ctx.storage.put({ startup, correlation: this.correlation, started: this.started });
|
|
177
|
+
await this.ctx.storage.setAlarm(Date.now() + 60_000);
|
|
178
|
+
}
|
|
173
179
|
report(this.correlation, this.started, 'ended');
|
|
174
180
|
}
|
|
175
181
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// container response body, cookie, environment value or raw error is retained.
|
|
3
3
|
export function category(error) {
|
|
4
4
|
const message = String(error?.message ?? '');
|
|
5
|
+
if (message === 'placement-unavailable' || /there is no container instance that can be provided to this Durable Object, try again later/i.test(message)) return 'placement-unavailable';
|
|
5
6
|
if (error?.name === 'TimeoutError' || error?.name === 'AbortError') return 'probe-timeout';
|
|
6
7
|
if (/connection refused|not listening|port.*not.*ready/i.test(message)) return 'port-not-ready';
|
|
7
8
|
if (/container.*not.*running|container.*stopped/i.test(message)) return 'container-stopped';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Cloudflare can exhaust its prepared instances before reaching max_instances.
|
|
2
|
+
// Keep this visitor's reservation while that pool grows. Only the provider's
|
|
3
|
+
// explicit no-instance response permits another placement attempt; boot, health
|
|
4
|
+
// and claim failures still terminate the start.
|
|
5
|
+
export async function placeContainer(demo, options, deadline) {
|
|
6
|
+
let attempt = 0;
|
|
7
|
+
while (Date.now() < deadline && !demo.cancelled) {
|
|
8
|
+
demo.stopped = false;
|
|
9
|
+
demo.stopReason = undefined;
|
|
10
|
+
demo.container.start(options);
|
|
11
|
+
demo.watch();
|
|
12
|
+
await demo.ctx.storage.setAlarm(deadline);
|
|
13
|
+
try {
|
|
14
|
+
await demo.healthy(deadline);
|
|
15
|
+
return;
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (demo.cancelled || demo.stopReason !== 'placement-unavailable') throw error;
|
|
18
|
+
demo.record('placement', { attempt: ++attempt, outcome: 'waiting' });
|
|
19
|
+
await new Promise(resolve => setTimeout(resolve, Math.min(1000, Math.max(0, deadline - Date.now()))));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
throw new Error(demo.cancelled ? 'container-stopped' : 'placement-unavailable');
|
|
23
|
+
}
|
|
@@ -9,7 +9,7 @@ import { siteDeclaration } from '../deploy-kit/site.mjs';
|
|
|
9
9
|
* running the seed's own image (`rer build --platform container`, workerd
|
|
10
10
|
* engine), deployed by `wrangler deploy` with the image beside it. */
|
|
11
11
|
|
|
12
|
-
export const DEMO_FILES = ['worker.mjs', 'container.mjs', 'startup.mjs', 'capacity.mjs', 'claim.mjs', 'pages.mjs', 'start-script.mjs', 'diagnostics.mjs', 'operator.mjs'];
|
|
12
|
+
export const DEMO_FILES = ['worker.mjs', 'container.mjs', 'startup.mjs', 'placement.mjs', 'capacity.mjs', 'claim.mjs', 'pages.mjs', 'start-script.mjs', 'diagnostics.mjs', 'operator.mjs'];
|
|
13
13
|
const FRONT_SET = /^(?:RER_.*|SESSION_SECRET|SETUP_TOKEN|OWNER_EMAIL)$/;
|
|
14
14
|
const SECRET = /SECRET|TOKEN|PASSWORD|_KEY$/;
|
|
15
15
|
// Cloudflare Containers' predefined instance types, smallest first (developers.cloudflare.com/containers/platform-details/limits).
|
|
@@ -19,7 +19,7 @@ export async function finishStart(demo, options) {
|
|
|
19
19
|
const diagnostic = await bounded(demo.diagnostic(), 3000);
|
|
20
20
|
await bounded(demo.env.CAPACITY.get(demo.env.CAPACITY.idFromName('diagnostics')).record(correlation, { ...diagnostic, failure }), 3000);
|
|
21
21
|
} catch (capture) { report(correlation, demo.started, 'diagnostic', { error: category(capture) }); }
|
|
22
|
-
await demo.ctx.storage.put('startup', { phase: 'failed' });
|
|
22
|
+
await demo.ctx.storage.put('startup', { phase: 'failed', capacity: failure === 'placement-unavailable' });
|
|
23
23
|
try { await demo.end(); } catch (cleanup) { report(correlation, demo.started, 'cleanup', { error: category(cleanup) }); }
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -47,7 +47,7 @@ function refusal(request, env, status, notice, headers = {}) {
|
|
|
47
47
|
function progress(request, env, id, state) {
|
|
48
48
|
const headers = new Headers({ 'cache-control': 'no-store' });
|
|
49
49
|
if (state.correlation) headers.set('x-rer-demo-correlation', state.correlation);
|
|
50
|
-
if (state.phase === 'failed') return refusal(request, env, 502, 'The demo did not start. Try again.', { ...Object.fromEntries(headers), 'set-cookie': clearCookie(env) });
|
|
50
|
+
if (state.phase === 'failed') return refusal(request, env, state.capacity ? 503 : 502, state.capacity ? 'Every demo is in use right now. Try again in a few minutes.' : 'The demo did not start. Try again.', { ...Object.fromEntries(headers), 'set-cookie': clearCookie(env) });
|
|
51
51
|
headers.append('set-cookie', demoCookie(env, id.toString()));
|
|
52
52
|
if (state.phase === 'starting') {
|
|
53
53
|
headers.set('retry-after', '1');
|
|
@@ -292,6 +292,18 @@ again, within 30 seconds. Library `verifyHealth`
|
|
|
292
292
|
retains the existing window, retrying only 404, 503 and network failures for
|
|
293
293
|
30 seconds by default.
|
|
294
294
|
|
|
295
|
+
Custom-hook `rer deploy` finalization gets a separate 90-second `/health` wait
|
|
296
|
+
after the hook returns, using the current recorded Worker version when available.
|
|
297
|
+
The hook can already have claimed the owner and retired its token, which creates
|
|
298
|
+
another version and can exhaust the original upload window. First hosted Slate
|
|
299
|
+
and Pencil deploys on 15 October 2026 failed this final gate even though health
|
|
300
|
+
named the right commit seconds later. Reusing the existing 90-second propagation
|
|
301
|
+
budget gives this final observation the same bounded allowance, without spending
|
|
302
|
+
it on the hook's earlier work. Transport failures and healthy identity mismatches wait;
|
|
303
|
+
permanent HTTP or malformed responses still fail. The deadline includes request
|
|
304
|
+
time and backoff; each request is capped at 30 seconds. Failure names the last
|
|
305
|
+
observed answer and the exact same-environment rerun.
|
|
306
|
+
|
|
295
307
|
The returned receipt carries `health: {ok, versionId, attempts}`. Each attempt is
|
|
296
308
|
`{offsetMs, status, cfRay, contentType, errorClass}`: `status` is null for
|
|
297
309
|
a transport failure and `errorClass` is null for the passing attempt. The receipt
|
|
@@ -21,7 +21,7 @@ async function bodyPrefix(response) {
|
|
|
21
21
|
|
|
22
22
|
/** One credential-free, bounded request. Retain only bounded response evidence. */
|
|
23
23
|
/** `expected` holds the deploy identity fields the caller knows; each must match. */
|
|
24
|
-
export async function healthRequest({origin, expected, request, timeoutMs, offsetMs}) {
|
|
24
|
+
export async function healthRequest({origin, expected, request, timeoutMs, offsetMs, retryIdentityMismatch = false}) {
|
|
25
25
|
const attempt = {offsetMs,status:null,cfRay:null,contentType:null,body:'',errorClass:null};
|
|
26
26
|
let response;
|
|
27
27
|
try {
|
|
@@ -63,10 +63,12 @@ export async function healthRequest({origin, expected, request, timeoutMs, offse
|
|
|
63
63
|
if (body?.ok !== true || Object.entries(expected).some(([key, value]) => body.deployment?.[key] !== value)) {
|
|
64
64
|
attempt.errorClass = 'health-identity-mismatch';
|
|
65
65
|
// Right after an upload the edge can still answer from another version: that
|
|
66
|
-
// settles within the bound.
|
|
66
|
+
// settles within the bound. Final source observation also waits out healthy
|
|
67
|
+
// identity mismatches; other callers reject a wrong identity from the
|
|
68
|
+
// expected version at once.
|
|
67
69
|
const key = expected.versionId ? 'versionId' : 'sourceSha';
|
|
68
70
|
const other = body?.ok === true && typeof body.deployment?.[key] === 'string' && body.deployment[key] !== expected[key];
|
|
69
|
-
return {attempt,transient:other};
|
|
71
|
+
return {attempt,transient:other || retryIdentityMismatch && body?.ok === true};
|
|
70
72
|
}
|
|
71
73
|
return {attempt,transient:false};
|
|
72
74
|
}
|
|
@@ -77,13 +79,13 @@ const MIN_DELAY_MS = 2000, MAX_DELAY_MS = 10000;
|
|
|
77
79
|
|
|
78
80
|
/** The total bound includes requests, body reads and backoff; no request starts at the deadline.
|
|
79
81
|
* Only a transient outcome is retried. Every attempt is recorded, in order, whatever the end. */
|
|
80
|
-
export async function waitHealth({origin,receipt,versionId,expected={sourceSha:receipt.source.sha,fingerprint:receipt.fingerprint,versionId},request,timeoutMs=30000,totalMs=90000,clock=()=>performance.now(),sleep=ms=>new Promise(resolve=>setTimeout(resolve,ms)),onAttempt=()=>{},single=false,freshUpload=false,window}) {
|
|
82
|
+
export async function waitHealth({origin,receipt,versionId,expected={sourceSha:receipt.source.sha,fingerprint:receipt.fingerprint,versionId},request,timeoutMs=30000,totalMs=90000,clock=()=>performance.now(),sleep=ms=>new Promise(resolve=>setTimeout(resolve,ms)),onAttempt=()=>{},single=false,freshUpload=false,window,retryIdentityMismatch=false}) {
|
|
81
83
|
assert(Number.isFinite(totalMs) && totalMs > 0 && totalMs <= 90000 && Number.isFinite(timeoutMs) && timeoutMs > 0,'invalid-health-bound');
|
|
82
84
|
const start = clock(); const attempts = []; let delay = 1000;
|
|
83
85
|
while (true) {
|
|
84
86
|
const remaining = Math.min(totalMs - (clock()-start), window?.remaining() ?? Infinity);
|
|
85
87
|
if (remaining <= 0) break;
|
|
86
|
-
const result = await healthRequest({origin,expected,request,timeoutMs:Math.max(1,Math.ceil(Math.min(timeoutMs,remaining))),offsetMs:Math.round(clock()-start)});
|
|
88
|
+
const result = await healthRequest({origin,expected,request,timeoutMs:Math.max(1,Math.ceil(Math.min(timeoutMs,remaining))),offsetMs:Math.round(clock()-start),retryIdentityMismatch});
|
|
87
89
|
attempts.push(result.attempt); await onAttempt(result.attempt,attempts);
|
|
88
90
|
if (!result.attempt.errorClass) return {ok:true,versionId,attempts};
|
|
89
91
|
// A newly uploaded workers.dev route can briefly disappear even after its
|