Prewarm Codex Live with safe fallback

Return after a durable starting record, overlap app-server initialization with page startup, dynamically reclaim generation after worker failure, and cap hard-crash leases at 15 seconds.\n\nAI-assisted: OpenAI Codex.
This commit is contained in:
Paul Bakaus
2026-07-12 21:11:50 -07:00
parent 6f3076051f
commit 6ed43ca682
9 changed files with 170 additions and 24 deletions
@@ -32,6 +32,7 @@ import {
} from '../live-poll.mjs';
export const CODEX_WORKER_EVENT_TYPES = Object.freeze(['generate', 'accept', 'discard', 'prefetch']);
export const CODEX_WORKER_EVENT_LEASE_MS = 15_000;
export class CodexLiveWorkerSupervisor {
constructor({
@@ -117,7 +118,10 @@ export class CodexLiveWorkerSupervisor {
if (!this.thread) await this.initialize();
this.running = true;
while (this.running) {
const event = await this.fetchEvent(this.base, this.token, { types: CODEX_WORKER_EVENT_TYPES });
const event = await this.fetchEvent(this.base, this.token, {
types: CODEX_WORKER_EVENT_TYPES,
leaseMs: CODEX_WORKER_EVENT_LEASE_MS,
});
if (!event || event.type === 'timeout') continue;
if (event.type === 'exit') {
await this.cancelActive('live_exit');