From 9d49f538b44fc18fd6dc02b3434902f4116934ac Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Tue, 17 Nov 2026 05:52:44 -0600 Subject: [PATCH 1/2] fix(pm-stack): rung-4 escalation speaks the validated queue contract (#6033) The watchdog core (PR #11243) wires watchdog-escalation.ts into the live tick, but the production enqueueTask wrapper was not a valid repo-task/v1 packet: fleet queue validate rejects it on 13 fields (no payload.repo/problem/evidence/acceptance/tests/context_refs/scope/risk/timebox/dedupe, no payload identity, dedupe_key matching no design pattern). Since enqueue ran first, a live escalation created neither the queue task nor the incident issue. Fix: create the incident issue first (a small_fix packet's fix-family dedupe key must name an existing issue), stamp the confirmed issue number into the enqueue packet in applyEscalationActions, and translate the packet through the new pure buildQueueTaskWrapper (fix-family dedupe key, payload.issue.number, full escalation context in payload.escalation_packet). Partial-hand-off resume keeps its semantics, mirrored: a failed enqueue now surfaces the confirmed issue number and the retry plans only the missing task, whose packet carries the recorded number. Tests: exporters suite 39 pass (plan order, apply stamping, wrapper contract, resume packet, flipped partial-failure case, tick-level issue-before-enqueue assertion). The generated wrapper passes the real validator: packet valid (repo-task/v1). --- pm-stack/exporters/README.md | 8 +- pm-stack/exporters/src/watchdog-escalation.ts | 145 +++++++++++++++++- pm-stack/exporters/src/watchdog.ts | 17 +- .../test/watchdog-escalation.test.ts | 96 ++++++++++-- pm-stack/exporters/test/watchdog.test.ts | 12 +- 5 files changed, 245 insertions(+), 33 deletions(-) diff --git a/pm-stack/exporters/README.md b/pm-stack/exporters/README.md index ff08cad34b..f76a3930c6 100644 --- a/pm-stack/exporters/README.md +++ b/pm-stack/exporters/README.md @@ -30,7 +30,13 @@ of exactly this kind of state machine. deduped queue-task + incident-issue effects behind injected effectors, records the refs on the incident, plans recovery (comment + close + complete), and renders the NEEDS DREW surfacing line (immediate when -human-blocked, after 24 h unresolved otherwise). +human-blocked, after 24 h unresolved otherwise). The hand-off creates +the incident issue **first**: fleet queue validation only accepts a +`small_fix` packet whose fix-family dedupe key names an existing issue +(`repo-health:v1:fix::issue:`, payload.issue.number matching), +so `buildQueueTaskWrapper` translates the escalation packet into the +validated repo-task/v1 envelope — full escalation context riding inside +the payload — once the issue number is confirmed. `src/adapters.ts` + `adapters/` — the **adapter loader**. An adapter is a per-provider JSON file (origins allowlist, CDP port, producer document diff --git a/pm-stack/exporters/src/watchdog-escalation.ts b/pm-stack/exporters/src/watchdog-escalation.ts index 2f72534fc3..a1e7e565db 100644 --- a/pm-stack/exporters/src/watchdog-escalation.ts +++ b/pm-stack/exporters/src/watchdog-escalation.ts @@ -25,6 +25,17 @@ // the #6032 remainder — which calls planEscalation / planRecovery with // the tick's pre-decision health record and persists whatever // recordEscalation returns. +// +// Ordering (task 20118): the incident issue is created BEFORE the +// queue task is enqueued. Fleet queue validation (repo-task/v1) only +// accepts a small_fix packet whose dedupe key is the fix family — +// `repo-health:v1:fix::issue:` — with payload.issue.number +// matching the key, so the task cannot be built until the issue +// exists. applyEscalationActions stamps the confirmed issue number +// into the enqueue packet, and buildQueueTaskWrapper is the pure +// translation from an escalation packet to the validated envelope +// (the pre-fix production wrapper failed validation on 13 fields and +// the live hand-off created neither artifact). import type { EscalationRecord, FailureClass, SourceHealth } from "./watchdog-state.ts"; /** How long an ordinary escalation stays quiet before it surfaces. */ @@ -47,6 +58,14 @@ export interface EscalationPacket { schema: "watchdog-escalation/v1"; kind: "small_fix"; source: string; + /** Repo that owns the adapter: the incident issue's repo, and the + * queue task's payload.repo / dedupe-key repo. */ + issueRepo: string; + /** Incident issue number once the issue exists. Null in a fresh + * plan (the issue is created first; applyEscalationActions stamps + * the confirmed number in), and carried from the escalation record + * on a partial-hand-off resume. */ + issueNumber: number | null; /** Dedupe pair: (source, failure class). */ dedupeKey: string; outcomeWanted: string; @@ -86,6 +105,13 @@ export function escalationDedupeKey(source: string, cls: FailureClass | null): s return `watchdog-escalation:${source}:${cls ?? "unknown"}`; } +/** Every hand-off record this incident carries, latest first — the + * dedupe view planEscalation and buildEscalationPacket share. */ +function escalationRecords(health: SourceHealth): EscalationRecord[] { + const existing = health.incident?.escalation; + return existing ? [existing, ...(existing.previous ?? [])] : []; +} + /** Build the queue-task packet for an incident that is escalating. */ export function buildEscalationPacket(health: SourceHealth, ctx: EscalationContext): EscalationPacket { const cls = health.currentClass; @@ -93,6 +119,8 @@ export function buildEscalationPacket(health: SourceHealth, ctx: EscalationConte schema: "watchdog-escalation/v1", kind: "small_fix", source: health.source, + issueRepo: ctx.issueRepo, + issueNumber: escalationRecords(health).find((r) => r.class === cls)?.issueNumber ?? null, dedupeKey: escalationDedupeKey(health.source, cls), outcomeWanted: `source \`${health.source}\` produces a fresh \`latest.json\` with real quota windows again`, failure: { @@ -161,20 +189,115 @@ export function planEscalation( // the latest (Codex P2 on PR #8357): a failure class that changes // back finds its original pair in `previous` instead of creating a // third hand-off. - const existing = incident.escalation; - const records: EscalationRecord[] = existing ? [existing, ...(existing.previous ?? [])] : []; + const records = escalationRecords(health); const forClass = records.find((r) => r.class === health.currentClass); if (forClass) { // Resume a partial hand-off: plan only the creations that never - // confirmed, so a retry cannot duplicate the confirmed half. + // confirmed, so a retry cannot duplicate the confirmed half. The + // issue still plans before the task (the task packet names it). const actions: EscalationAction[] = []; - if (forClass.queueTaskId === null) actions.push({ type: "enqueue_task", packet }); if (forClass.issueNumber === null) actions.push(openIssue); + if (forClass.queueTaskId === null) actions.push({ type: "enqueue_task", packet }); return { actions, deduped: actions.length === 0 }; } return { deduped: false, - actions: [{ type: "enqueue_task", packet }, openIssue], + actions: [openIssue, { type: "enqueue_task", packet }], + }; +} + +/** The repo-task/v1 envelope the fleet queue validates and enqueues. + * Pure translation of an escalation packet: the production + * enqueueTask effector writes this to a file and hands it to + * `fleet queue enqueue`. The full escalation packet rides inside the + * payload, so the claimed task still starts from the packet alone + * (#6033 acceptance: the queue task packet matches the context list). */ +export interface QueueTaskWrapper { + title: string; + body: string; + dedupe_key: string; + priority: number; + payload: Record; +} + +export function buildQueueTaskWrapper(packet: EscalationPacket, at: string): QueueTaskWrapper { + if (packet.issueNumber === null) { + throw new Error( + `escalation packet for ${packet.source} carries no incident issue number — the issue must be created before the queue task can name it`, + ); + } + const repo = packet.issueRepo; + const n = packet.issueNumber; + const cls = packet.failure.class ?? "unknown"; + const repairLines = packet.failure.repairLog.map( + (e) => `rung ${e.rung} ${e.outcome} at ${e.at}: ${e.detail}`, + ); + return { + title: `watchdog incident: ${packet.source} (${cls}) — repair the quota producer`, + body: [ + packet.outcomeWanted, + "", + `Incident issue: ${repo}#${n} (the watchdog auto-closes it on the next producer success — do not close it by hand).`, + `Required capability: ${packet.requiredCapability}`, + `Acceptance: ${packet.acceptance}`, + ].join("\n"), + dedupe_key: `repo-health:v1:fix:${repo}:issue:${n}`, + priority: 30, + payload: { + schema: "repo-task/v1", + kind: "small_fix", + repo, + issue: { number: n }, + problem: + `Source \`${packet.source}\` quota producer is failing (${cls}) and every watchdog ` + + `repair rung is spent, so the watchdog escalated (watchdog dedupe ${packet.dedupeKey}). ` + + `Last detail: ${packet.failure.lastDetail || "(none)"}. The full context packet is in ` + + `payload.escalation_packet; the incident issue ${repo}#${n} is the reporting surface.`, + priority_reason: + "Quota watchdog rung-4 escalation (#6033): a dead quota producer blinds the fleet's " + + "provider-quota reads until a browser-enabled agent repairs it; the watchdog has " + + "already exhausted its automated repair ladder.", + evidence: [ + `consecutive failures: ${packet.failure.consecutiveFailures}`, + ...(repairLines.length > 0 ? repairLines : ["repair log empty — ladder spent without entries"]), + `watchdog state file: ${packet.failure.stateFilePath}`, + ], + acceptance: [ + packet.acceptance, + `incident issue ${repo}#${n} is auto-commented and auto-closed by the watchdog on producer success (the fixer closes nothing by hand)`, + ], + tests: [ + "the producer for this source writes a fresh latest.json with status ok and real quota windows", + "the watchdog state file shows the incident cleared after the recovery tick", + ], + context_refs: [ + packet.failure.stateFilePath, + packet.failure.historyRef, + packet.failure.adapterRef, + `${repo}#${n}`, + "developing-today/code#6033", + ], + scope: { + include: [ + `restore fresh quota documents for source ${packet.source} via its adapter's browser flow (adapter: ${packet.failure.adapterRef})`, + "report progress on the incident issue", + ], + exclude: [ + ...packet.stopConditions, + "rebuilding the watchdog core or the escalation module — report on the incident issue instead if the ladder itself is broken", + ], + }, + risk: { level: "low", flags: [] }, + timebox_minutes: 45, + dedupe: { + checked_at: at, + basis: + `watchdog escalation record for (${packet.source}, ${cls}): the incident issue ` + + `${repo}#${n} was created by this same hand-off, and the fix-family dedupe key ` + + "names it, so a second live task for the incident cannot be enqueued.", + }, + escalation_packet: packet, + }, }; } @@ -320,9 +443,17 @@ export async function applyEscalationActions( for (const action of actions) { try { switch (action.type) { - case "enqueue_task": - queueTaskId = await effectors.enqueueTask(action.packet); + case "enqueue_task": { + // The queue task names the incident issue (fix-family + // dedupe): stamp the number this same run just confirmed + // into a packet planned before the issue existed. A resume + // packet already carries its recorded number. + const pkt = action.packet.issueNumber === null && issueNumber !== null + ? { ...action.packet, issueNumber } + : action.packet; + queueTaskId = await effectors.enqueueTask(pkt); break; + } case "open_issue": issueNumber = await effectors.openIssue(action); break; diff --git a/pm-stack/exporters/src/watchdog.ts b/pm-stack/exporters/src/watchdog.ts index 8762db373b..7bb018ba19 100644 --- a/pm-stack/exporters/src/watchdog.ts +++ b/pm-stack/exporters/src/watchdog.ts @@ -48,6 +48,7 @@ import { } from "./watchdog-state.ts"; import { applyEscalationActions, + buildQueueTaskWrapper, EscalationPartialError, planEscalation, planRecovery, @@ -279,17 +280,11 @@ function productionEscalationEffectors(live: boolean): EscalationEffectors { return { async enqueueTask(packet) { guard(); - const wrapper = { - title: `watchdog incident: ${packet.source} (${packet.failure.class ?? "unknown"})`, - body: packet.outcomeWanted, - dedupe_key: packet.dedupeKey, - priority: 30, - payload: { - schema: "repo-task/v1", - kind: packet.kind, - packet, - }, - }; + // The validated repo-task/v1 envelope (task 20118): the packet + // names the incident issue created earlier in this hand-off — + // buildQueueTaskWrapper throws when it does not, rather than + // enqueueing a packet the queue would reject. + const wrapper = buildQueueTaskWrapper(packet, new Date().toISOString()); const file = join("/tmp", `watchdog-escalation-${packet.source}-${Date.now()}.json`); await writeFile(file, JSON.stringify(wrapper)); const out = await run(["fleet", "queue", "enqueue", "--queue", "repo-health-code-pilot", file]); diff --git a/pm-stack/exporters/test/watchdog-escalation.test.ts b/pm-stack/exporters/test/watchdog-escalation.test.ts index efc0161e86..5f586b3f4c 100644 --- a/pm-stack/exporters/test/watchdog-escalation.test.ts +++ b/pm-stack/exporters/test/watchdog-escalation.test.ts @@ -5,6 +5,7 @@ import { describe, expect, test } from "bun:test"; import { applyEscalationActions, buildEscalationPacket, + buildQueueTaskWrapper, EscalationPartialError, ESCALATION_NEEDS_DREW_AFTER_MS, planEscalation, @@ -77,11 +78,11 @@ describe("planEscalation + dedupe (#6033 acceptance 1)", () => { const health = escalatingHealth(); const plan = planEscalation(health, CTX); expect(plan.deduped).toBe(false); - expect(plan.actions.map((a) => a.type)).toEqual(["enqueue_task", "open_issue"]); + expect(plan.actions.map((a) => a.type)).toEqual(["open_issue", "enqueue_task"]); const { calls, effectors } = countingEffectors(); const refs = await applyEscalationActions(plan.actions, effectors); - expect(calls).toEqual(["enqueue", "open"]); + expect(calls).toEqual(["open", "enqueue"]); expect(refs).toEqual({ queueTaskId: "task-4242", issueNumber: 777 }); const recorded = recordEscalation(health, CTX, refs, T0); @@ -125,6 +126,81 @@ describe("packet completeness (#6033 acceptance 2)", () => { expect(packet.stopConditions.join(" ")).toContain("human-only challenge"); expect(packet.stopConditions.join(" ")).toContain("origin allowlist"); expect(packet.dedupeKey).toBe("watchdog-escalation:mistral:session-expired"); + expect(packet.issueRepo).toBe(CTX.issueRepo); + // A fresh plan has no incident issue yet: it is created first in + // the hand-off and its number is stamped in at apply time. + expect(packet.issueNumber).toBeNull(); + }); +}); + +describe("queue task wrapper — the repo-task/v1 contract (task 20118)", () => { + test("apply stamps the confirmed issue number into the enqueue packet", async () => { + const seen: (number | null)[] = []; + const effectors: EscalationEffectors = { + enqueueTask: async (packet) => { + seen.push(packet.issueNumber); + return "task-4242"; + }, + openIssue: async () => 777, + commentIssue: async () => {}, + closeIssue: async () => {}, + completeTask: async () => {}, + }; + const plan = planEscalation(escalatingHealth(), CTX); + const refs = await applyEscalationActions(plan.actions, effectors); + expect(seen).toEqual([777]); + expect(refs).toEqual({ queueTaskId: "task-4242", issueNumber: 777 }); + }); + + test("the wrapper names the incident issue in its dedupe key and payload identity", () => { + const packet = { ...buildEscalationPacket(escalatingHealth(), CTX), issueNumber: 777 }; + const w = buildQueueTaskWrapper(packet, T0); + expect(w.dedupe_key).toBe("repo-health:v1:fix:developing-today-forks/openchamber:issue:777"); + expect(w.priority).toBe(30); + const p = w.payload as Record; + expect(p.schema).toBe("repo-task/v1"); + expect(p.kind).toBe("small_fix"); + expect(p.repo).toBe(CTX.issueRepo); + expect(p.issue).toEqual({ number: 777 }); + expect(typeof p.problem).toBe("string"); + expect((p.problem as string).length).toBeGreaterThan(0); + expect(typeof p.priority_reason).toBe("string"); + for (const f of ["evidence", "acceptance", "tests", "context_refs"]) { + expect(Array.isArray(p[f])).toBe(true); + expect((p[f] as unknown[]).length).toBeGreaterThan(0); + expect((p[f] as unknown[]).every((e) => typeof e === "string")).toBe(true); + } + expect((p.scope as any).include.length).toBeGreaterThan(0); + expect((p.scope as any).exclude.length).toBeGreaterThan(0); + expect((p.risk as any).level).toBe("low"); + expect(p.timebox_minutes).toBeGreaterThan(0); + expect((p.dedupe as any).checked_at).toBe(T0); + expect(((p.dedupe as any).basis as string).length).toBeGreaterThan(0); + // The full escalation context survives inside the payload, so a + // browser-enabled agent can start from the claimed task alone. + expect((p.escalation_packet as any).dedupeKey).toBe("watchdog-escalation:mistral:session-expired"); + expect((p.escalation_packet as any).failure.stateFilePath).toBe(CTX.stateFilePath); + expect((p.escalation_packet as any).requiredCapability).toContain("browser-enabled"); + }); + + test("the wrapper refuses a packet whose incident issue does not exist yet", () => { + const packet = buildEscalationPacket(escalatingHealth(), CTX); + expect(packet.issueNumber).toBeNull(); + expect(() => buildQueueTaskWrapper(packet, T0)).toThrow(/no incident issue number/); + }); + + test("a resume packet carries the recorded issue number, so the retry needs no new issue", () => { + const recorded = recordEscalation( + escalatingHealth(), + CTX, + { queueTaskId: null, issueNumber: 777 }, + T0, + ); + const plan = planEscalation(recorded, CTX); + expect(plan.actions.map((a) => a.type)).toEqual(["enqueue_task"]); + const action = plan.actions[0] as Extract<(typeof plan.actions)[number], { type: "enqueue_task" }>; + expect(action.packet.issueNumber).toBe(777); + expect(action.packet.issueRepo).toBe(CTX.issueRepo); }); }); @@ -209,14 +285,14 @@ describe("Codex findings on PR #8357 (class change, partial progress, surfacing expect(plan.actions).toEqual([]); }); - test("a failed openIssue surfaces the confirmed task id; the retry plans only the missing issue", async () => { + test("a failed enqueueTask surfaces the confirmed issue number; the retry plans only the missing task", async () => { const health = escalatingHealth(); const plan = planEscalation(health, CTX); const failing: EscalationEffectors = { - enqueueTask: async () => "task-4242", - openIssue: async () => { - throw new Error("gh unavailable"); + enqueueTask: async () => { + throw new Error("queue unavailable"); }, + openIssue: async () => 777, commentIssue: async () => {}, closeIssue: async () => {}, completeTask: async () => {}, @@ -224,16 +300,16 @@ describe("Codex findings on PR #8357 (class change, partial progress, surfacing const err = await applyEscalationActions(plan.actions, failing).catch((e: unknown) => e); expect(err).toBeInstanceOf(EscalationPartialError); expect((err as EscalationPartialError).refs).toEqual({ - queueTaskId: "task-4242", - issueNumber: null, + queueTaskId: null, + issueNumber: 777, }); const recorded = recordEscalation(health, CTX, (err as EscalationPartialError).refs, T0); const retry = planEscalation(recorded, CTX); expect(retry.deduped).toBe(false); - expect(retry.actions.map((a) => a.type)).toEqual(["open_issue"]); + expect(retry.actions.map((a) => a.type)).toEqual(["enqueue_task"]); - const completed = recordEscalation(recorded, CTX, { queueTaskId: null, issueNumber: 777 }, T0); + const completed = recordEscalation(recorded, CTX, { queueTaskId: "task-4242", issueNumber: null }, T0); expect(completed.incident?.escalation?.queueTaskId).toBe("task-4242"); expect(completed.incident?.escalation?.issueNumber).toBe(777); expect(completed.incident?.escalation?.since).toBe(T0); diff --git a/pm-stack/exporters/test/watchdog.test.ts b/pm-stack/exporters/test/watchdog.test.ts index 9ccffc55a4..1f3b18fa52 100644 --- a/pm-stack/exporters/test/watchdog.test.ts +++ b/pm-stack/exporters/test/watchdog.test.ts @@ -87,7 +87,7 @@ async function harness(opts: { return opts.rung3?.() ?? { outcome: "failed", detail: "re-login failed" }; }, escalation: { - enqueueTask: async (packet) => { escCalls.push(`enqueue:${packet.dedupeKey}`); return "4242"; }, + enqueueTask: async (packet) => { escCalls.push(`enqueue:${packet.dedupeKey}`); escCalls.push(`enqueue-issue:${packet.issueNumber}`); return "4242"; }, openIssue: async (a) => { escCalls.push(`open:${a.repo}`); return 777; }, commentIssue: async (a) => { escCalls.push(`comment:${a.issueNumber}`); }, closeIssue: async (a) => { escCalls.push(`close:${a.issueNumber}`); }, @@ -155,15 +155,19 @@ describe("watchdog entry point — acceptance fixtures", () => { expect(health.incident?.surfacing).toBe("escalate"); expect(health.incident?.escalation?.queueTaskId).toBe("4242"); expect(health.incident?.escalation?.issueNumber).toBe(777); - expect(h.escCalls.filter((c) => c.startsWith("enqueue"))).toHaveLength(1); + expect(h.escCalls.filter((c) => c.startsWith("enqueue:"))).toHaveLength(1); expect(h.escCalls.filter((c) => c.startsWith("open"))).toHaveLength(1); + // The issue is created first and its number reaches the enqueue: + // the queue task names the incident issue (task 20118). + expect(h.escCalls).toContain("enqueue-issue:777"); + expect(h.escCalls.indexOf("open:developing-today/code")).toBeLessThan(h.escCalls.indexOf("enqueue-issue:777")); // Repair log records every rung attempt and stays within its bound. const rungs = health.repairLog.filter((e) => e.outcome === "attempted").map((e) => e.rung); expect(rungs).toEqual([1, 1, 2, 2, 3, 3]); // A further failing tick dedupes: no second task, no second issue. await h.setDoc(failDoc(7, "mystery-failure")); await h.tick(7); - expect(h.escCalls.filter((c) => c.startsWith("enqueue"))).toHaveLength(1); + expect(h.escCalls.filter((c) => c.startsWith("enqueue:"))).toHaveLength(1); expect(h.escCalls.filter((c) => c.startsWith("open"))).toHaveLength(1); await rm(h.dir, { recursive: true, force: true }); }); @@ -207,7 +211,7 @@ describe("watchdog entry point — acceptance fixtures", () => { await h.setDoc(failDoc(min, "mystery-failure")); await h.tick(min); } - expect(h.escCalls.filter((c) => c.startsWith("enqueue"))).toHaveLength(1); + expect(h.escCalls.filter((c) => c.startsWith("enqueue:"))).toHaveLength(1); await h.setDoc(okDoc(10)); const { state } = await h.tick(10); expect(state.sources.fixture.incident).toBeNull(); From 7ae86e8ebc1818945b63728c18f7ae2e357109c4 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Tue, 17 Nov 2026 05:59:12 -0600 Subject: [PATCH 2/2] fix(pm-stack): watchdog recovery resolves the unclaimed escalation task (#6033) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Live fixture demo (task 20118): recovery auto-commented and auto-closed the incident issue, but the queue task stayed queued — complete requires holding the claim and the watchdog never claims, so its best-effort complete always fails for a still-queued task (the common case: the source healed before a fixer picked the task up). completeTask now falls back, only when the task is untouched (no timeline records — an unclaimed task has none), to cancel with the recovery reason. A task with timeline records has an owner and is left to them; the auto-closed incident issue is their signal. --- pm-stack/exporters/src/watchdog.ts | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/pm-stack/exporters/src/watchdog.ts b/pm-stack/exporters/src/watchdog.ts index 7bb018ba19..a2f4a3f66e 100644 --- a/pm-stack/exporters/src/watchdog.ts +++ b/pm-stack/exporters/src/watchdog.ts @@ -317,13 +317,30 @@ function productionEscalationEffectors(live: boolean): EscalationEffectors { }, async completeTask(action) { guard(); - // The escalation task is completed by whoever claimed and fixed - // it in the normal case; the watchdog's recovery completion is - // best-effort (the task may already be claimed/done). - await run([ + // Recovery resolution of the escalation task, best-effort at + // every step (task 20118 live demo): `complete` requires + // holding the claim, and the watchdog never claims — so for a + // task still sitting queued it always fails with "not claimed + // by repo-worker-code". That case is the common one (the + // source healed before any fixer picked the task up), and the + // honest terminal verb for it is `cancel` with the recovery + // reason — but cancel also cancels CLAIMED tasks, so it is + // only safe when the task is untouched: an unclaimed task has + // no timeline records. A task with records has an owner; leave + // it to them — the auto-closed incident issue is their signal, + // and their own completion closes the task out. + const completed = await run([ "fleet", "queue", "complete", action.queueTaskId, "--worker", "repo-worker-code", "--result", JSON.stringify({ outcome: "already_done", note: "watchdog recovery: source healthy again (#6033)" }), - ]).catch(() => ""); + ]).then(() => true).catch(() => false); + if (completed) return; + const timeline = await run(["fleet", "queue", "timeline", action.queueTaskId]).catch(() => ""); + if (timeline.includes("no timeline records")) { + await run([ + "fleet", "queue", "cancel", action.queueTaskId, "--worker", "repo-worker-code", + "--reason", "watchdog recovery: source healthy again; the repair this task commissioned is no longer needed (#6033)", + ]).catch(() => ""); + } }, }; }