From b2507518889d78e7c80058204645e79a39fe9eaa Mon Sep 17 00:00:00 2001 From: Manohar Date: Wed, 10 Jun 2026 15:12:42 +0000 Subject: [PATCH] fix(bridge): audit shows cron job names, not UUIDs --- bridge/src/routes/activity-audit.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/bridge/src/routes/activity-audit.ts b/bridge/src/routes/activity-audit.ts index 9a1cda0..ccc21e8 100644 --- a/bridge/src/routes/activity-audit.ts +++ b/bridge/src/routes/activity-audit.ts @@ -132,6 +132,22 @@ function outputEvents(beforeIso: string | null, limit: number): AuditEvent[] { let cronCache: { stamp: string; events: AuditEvent[] } | null = null; +/** jobId → human name, from cron/jobs.json (cached per cron rebuild). */ +function loadJobNames(): Record { + try { + const raw = JSON.parse( + readFileSync(join(DATA_DIR, "cron", "jobs.json"), "utf-8"), + ) as { jobs?: Array<{ id?: string; name?: string }> }; + const map: Record = {}; + for (const j of raw.jobs ?? []) { + if (j.id && j.name) map[j.id] = j.name; + } + return map; + } catch { + return {}; + } +} + function cronEvents(): AuditEvent[] { const runsDir = join(DATA_DIR, "cron", "runs"); if (!existsSync(runsDir)) return []; @@ -149,6 +165,7 @@ function cronEvents(): AuditEvent[] { const stamp = files.join("|"); if (cronCache && cronCache.stamp === stamp) return cronCache.events; + const jobNames = loadJobNames(); const events: AuditEvent[] = []; for (const file of files) { let content: string; @@ -170,7 +187,8 @@ function cronEvents(): AuditEvent[] { const ts = run.startedAt ?? run.ts ?? run.runAtMs ?? run.timestamp; if (!ts) continue; const iso = typeof ts === "number" ? new Date(ts).toISOString() : toIso(String(ts)); - const name = run.jobName ?? run.name ?? file.replace(/\.jsonl$/, ""); + const jobId = String(run.jobId ?? file.replace(/\.jsonl$/, "")); + const name = run.jobName ?? run.name ?? jobNames[jobId] ?? jobId; const status = run.status ?? (run.error ? "error" : "ok"); events.push({ id: `cron:${file}:${iso}`, @@ -179,7 +197,7 @@ function cronEvents(): AuditEvent[] { actor: "cron", summary: String(name).slice(0, 160), status: String(status), - ref: run.jobId ?? file.replace(/\.jsonl$/, ""), + ref: jobId, }); } }