feat(FN-4892): complete Step 6 — wire ghost-bug preflight at triage finalize
Fusion-Task-Id: FN-4892 Fusion-Task-Lineage: 6f56b468-a827-416d-ba1f-444e1326d613
This commit is contained in:
committed by
gsxdsm
parent
77d4a9b466
commit
19e4aeb87b
@@ -52,6 +52,7 @@ import {
|
||||
sendNtfyNotification,
|
||||
type NtfyNotifier,
|
||||
} from "./notifier.js";
|
||||
import type { GhostBugDecision } from "./triage-preflight.js";
|
||||
|
||||
const log = createLogger("self-healing");
|
||||
const worktreeMetadataReconcileLog = createLogger("worktree-metadata-reconcile");
|
||||
@@ -60,6 +61,30 @@ const DONE_TASK_INTEGRITY_SWEEP_LIMIT = 50;
|
||||
const BOARD_STALL_NOTIFICATION_COOLDOWN_MS = 60 * 60_000;
|
||||
export const STALE_ACTIVE_BRANCH_EXECUTION_GRACE_MS = 10 * 60_000;
|
||||
|
||||
export async function archiveAsGhostBug(
|
||||
store: TaskStore,
|
||||
taskId: string,
|
||||
taskTitle: string,
|
||||
decision: GhostBugDecision,
|
||||
): Promise<void> {
|
||||
await store.moveTask(taskId, "archived");
|
||||
await store.logEntry(
|
||||
taskId,
|
||||
"Auto-archived as ghost bug — cited code construct not present on main",
|
||||
JSON.stringify({ reason: decision.reason, findings: decision.findings }, null, 2),
|
||||
);
|
||||
await store.recordActivity({
|
||||
type: "task:auto-archived-ghost-bug",
|
||||
taskId,
|
||||
taskTitle,
|
||||
details: "Cited construct not found on main",
|
||||
metadata: {
|
||||
reason: decision.reason,
|
||||
findings: decision.findings.slice(0, 10),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function classifyOwnedLandedEvidenceForSelfHealing(rootDir: string, task: Task, mergeTargetBranch: string): Promise<OwnedLandedClassification> {
|
||||
const { classifyOwnedLandedEvidence } = await import("./merger.js");
|
||||
return classifyOwnedLandedEvidence(rootDir, task, { mergeTargetBranch });
|
||||
|
||||
@@ -48,8 +48,10 @@ import { isTransientError, isSilentTransientError } from "./transient-error-dete
|
||||
import { withRateLimitRetry } from "./rate-limit-retry.js";
|
||||
import { computeRecoveryDecision, formatDelay, MAX_RECOVERY_RETRIES } from "./recovery-policy.js";
|
||||
import type { StuckTaskDetector } from "./stuck-task-detector.js";
|
||||
import { exec } from "node:child_process";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import {
|
||||
createAgentTask,
|
||||
createDelegateTaskTool,
|
||||
@@ -64,6 +66,9 @@ import {
|
||||
getResearchGuidanceForSurface,
|
||||
isResearchToolSurfaceEnabled,
|
||||
} from "./tool-availability.js";
|
||||
import { runGhostBugPreflight } from "./triage-preflight.js";
|
||||
import { archiveAsGhostBug } from "./self-healing.js";
|
||||
import { createRunAuditor, generateSyntheticRunId } from "./run-audit.js";
|
||||
|
||||
export const TRIAGE_SYSTEM_PROMPT = `You are a task specification agent for "fn", an AI-orchestrated task board.
|
||||
|
||||
@@ -2209,6 +2214,44 @@ export class TriageProcessor {
|
||||
|
||||
await this.store.updateTask(task.id, taskUpdates);
|
||||
|
||||
try {
|
||||
const preflightDecision = await Promise.race([
|
||||
runGhostBugPreflight(
|
||||
{ title: task.title ?? "", description: task.description ?? "" },
|
||||
written,
|
||||
{
|
||||
cwd: this.rootDir,
|
||||
exec: promisify(exec),
|
||||
},
|
||||
),
|
||||
new Promise<null>((resolve) => setTimeout(() => resolve(null), 15_000)),
|
||||
]);
|
||||
|
||||
if (preflightDecision && preflightDecision.decision === "archive") {
|
||||
await archiveAsGhostBug(this.store, task.id, task.title ?? "", preflightDecision);
|
||||
const auditor = createRunAuditor(this.store, {
|
||||
taskId: task.id,
|
||||
agentId: task.assignedAgentId ?? "triage",
|
||||
runId: generateSyntheticRunId("triage", task.id),
|
||||
phase: "triage",
|
||||
source: "triage",
|
||||
});
|
||||
await auditor.database({
|
||||
type: "task:auto-archived-ghost-bug",
|
||||
target: task.id,
|
||||
metadata: {
|
||||
reason: preflightDecision.reason,
|
||||
findings: preflightDecision.findings.slice(0, 10),
|
||||
},
|
||||
});
|
||||
planLog.log(`${task.id} auto-archived as ghost bug`);
|
||||
return;
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
planLog.warn(`${task.id}: ghost-bug preflight failed open: ${message}`);
|
||||
}
|
||||
|
||||
if (settings.requirePlanApproval) {
|
||||
const approvalUpdates: Record<string, unknown> = { status: "awaiting-approval" };
|
||||
if (shouldApplyPromptDeclaredTitle && promptDeclaredTitle) {
|
||||
|
||||
Reference in New Issue
Block a user