fix: harden addressed registry recovery and routes

This commit is contained in:
2026-08-11 15:02:43 +02:00
parent ee5ac381b3
commit 1b24337a98
8 changed files with 220 additions and 82 deletions
@@ -1 +1,11 @@
import { mkdir, writeFile } from "node:fs/promises"; const root=process.env.JOB_ROOT; if (!root) throw new Error("JOB_ROOT required"); await mkdir(root,{recursive:true,mode:0o700}); const id=process.env.RUN_ID??"a".repeat(32); await writeFile(`${root}/${id}.json`,JSON.stringify({runId:id,phase:"request_claimed"})+"\n",{flag:"wx",mode:0o600}); process.stdout.write(JSON.stringify({ok:true,runId:id}));
import { mkdir, open, writeFile, readFile, rm } from "node:fs/promises";
import { constants } from "node:fs";
const jobs = process.env.JOB_ROOT;
if (!jobs) throw new Error("JOB_ROOT required");
const id = process.env.RUN_ID ?? "a".repeat(32);
const barrier = process.env.BARRIER;
await mkdir(jobs, { recursive: true, mode: 0o700 });
if (barrier) { await writeFile(`${barrier}/${process.pid}.ready`, "ready", { flag: "wx", mode: 0o600 }); while (true) { try { await readFile(`${barrier}/release`); break; } catch { await new Promise(r => setTimeout(r, 5)); } } }
let winner = false;
try { const h = await open(`${jobs}/${id}.json`, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600); await h.writeFile(JSON.stringify({ schemaVersion: 1, runId: id, phase: "request_claimed" }) + "\n"); await h.sync(); await h.close(); winner = true; } catch (e) { if (e?.code !== "EEXIST") throw e; }
process.stdout.write(JSON.stringify({ ok: true, runId: id, winner }) + "\n");