feat: auto-merge and deploy self-heal patches that pass a live smoke test

The patched code must generate a real image on chatgpt.com (src/smoke.ts)
before the PR is squash-merged and scripts/update.sh deploys it. Patches
failing the live check stay as open PRs. The self-heal state and cooldown
are restored from the log after the service restart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Opus 5.5 committed 2026-10-07 20:17:31 +02:00
1 parent d456081aac
commit 51cd5b1e40
7 files changed
+254 -16

No files matched your search

+27 -1
View File
@@ -53,7 +53,18 @@ export class SelfHealer {
state: "idle", lastStartedAt: null, lastFinishedAt: null, lastExitCode: null, lastPullRequest: null,
};
constructor(private readonly options: SelfHealOptions = selfHealOptionsFromEnv()) {}
constructor(private readonly options: SelfHealOptions = selfHealOptionsFromEnv()) {
// A successful run ends with update.sh restarting the service, so restore the last run from the
// log: its status for reporting, and its start time so the cooldown survives the restart.
const last = parseSelfHealLog(options.logFile);
if (last.startedAt) {
this.lastStartedAt = Date.parse(last.startedAt);
this.status = {
state: last.merged || last.result === "succeeded" ? "succeeded" : last.result === "failed" ? "failed" : "idle",
lastStartedAt: last.startedAt, lastFinishedAt: null, lastExitCode: null, lastPullRequest: last.pullRequest,
};
}
}
recordSuccess(): void {
this.consecutiveFailures = 0;
@@ -125,6 +136,21 @@ export class SelfHealer {
}
}
export function parseSelfHealLog(logFile: string): { startedAt: string | null; pullRequest: string | null; merged: boolean; result: "succeeded" | "failed" | null } {
let text = "";
try { text = readFileSync(logFile, "utf8"); } catch { return { startedAt: null, pullRequest: null, merged: false, result: null }; }
const runs = text.split(/^(?=\[[^\]]+\] self-heal started:)/m);
const lastRun = runs.at(-1) ?? "";
const startedAt = lastRun.match(/^\[([^\]]+)\] self-heal started:/)?.[1] ?? null;
const result = lastRun.match(/SELFHEAL_RESULT (.*)$/m)?.[1];
return {
startedAt,
pullRequest: lastRun.match(/^SELFHEAL_PR_CREATED (\S+)/m)?.[1] ?? null,
merged: /^SELFHEAL_MERGED /m.test(lastRun),
result: result === undefined ? null : /merged|pull request created|dry run ok/.test(result) ? "succeeded" : "failed",
};
}
export function lastPullRequestUrl(logFile: string): string | null {
try {
const matches = [...readFileSync(logFile, "utf8").matchAll(/^SELFHEAL_PR_CREATED (\S+)/gm)];
+21
View File
@@ -0,0 +1,21 @@
import "dotenv/config";
import { randomUUID } from "node:crypto";
import { ChatGptImageProvider } from "./chatgpt/provider.js";
import { ensureMediaDir } from "./media.js";
// Live end-to-end check: generates one real image on chatgpt.com with the configured profile.
// Used by scripts/selfheal.sh before auto-merging a patch. Consumes one image of the account quota.
// Exit codes: 0 image generated, 1 generation failed.
const prompt = process.env.SMOKE_PROMPT || "A simple red cube on a plain white background, studio lighting";
const provider = new ChatGptImageProvider();
try {
await ensureMediaDir();
const [output] = await provider.generateImages(randomUUID(), { prompt, aspectRatio: "1:1", imageCount: 1, references: [] });
console.log(`SMOKE_OK ${output.filename} ${output.mimeType} ${output.width ?? "?"}x${output.height ?? "?"} ${output.sizeBytes} bytes`);
} catch (error) {
console.error(`SMOKE_FAILED ${error instanceof Error ? error.message : String(error)}`);
process.exitCode = 1;
} finally {
await provider.close();
}