fix triage handoff state
This commit is contained in:
5
.changeset/clear-triage-status-on-todo.md
Normal file
5
.changeset/clear-triage-status-on-todo.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@gsxdsm/fusion": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Clear active triage state when manually moving a task from triage to todo.
|
||||||
@@ -3450,6 +3450,28 @@ Task with acceptance criteria
|
|||||||
expect(moved.status).toBe("custom-status");
|
expect(moved.status).toBe("custom-status");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("clears triage control status when moving from triage to todo", async () => {
|
||||||
|
const task = await store.createTask({ description: "test specifying to todo" });
|
||||||
|
await store.updateTask(task.id, {
|
||||||
|
status: "specifying",
|
||||||
|
error: "still running",
|
||||||
|
});
|
||||||
|
|
||||||
|
const moved = await store.moveTask(task.id, "todo");
|
||||||
|
expect(moved.column).toBe("todo");
|
||||||
|
expect(moved.status).toBeUndefined();
|
||||||
|
expect(moved.error).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("clears awaiting approval status when moving from triage to todo", async () => {
|
||||||
|
const task = await store.createTask({ description: "test awaiting approval to todo" });
|
||||||
|
await store.updateTask(task.id, { status: "awaiting-approval" });
|
||||||
|
|
||||||
|
const moved = await store.moveTask(task.id, "todo");
|
||||||
|
expect(moved.column).toBe("todo");
|
||||||
|
expect(moved.status).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
it("clears status, error, worktree, and blockedBy when moving from in-progress to done", async () => {
|
it("clears status, error, worktree, and blockedBy when moving from in-progress to done", async () => {
|
||||||
const task = await store.createTask({ description: "test clear fields to done" });
|
const task = await store.createTask({ description: "test clear fields to done" });
|
||||||
await store.moveTask(task.id, "todo");
|
await store.moveTask(task.id, "todo");
|
||||||
|
|||||||
@@ -1652,6 +1652,22 @@ export class TaskStore extends EventEmitter<TaskStoreEvents> {
|
|||||||
task.blockedBy = undefined;
|
task.blockedBy = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Moving a task out of triage is a manual approval/override path. Clear
|
||||||
|
// triage-only control statuses so the todo card is ready for execution
|
||||||
|
// instead of continuing to look like an active specification job.
|
||||||
|
if (
|
||||||
|
fromColumn === "triage"
|
||||||
|
&& toColumn === "todo"
|
||||||
|
&& (
|
||||||
|
task.status === "specifying"
|
||||||
|
|| task.status === "awaiting-approval"
|
||||||
|
|| task.status === "needs-respecify"
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
task.status = undefined;
|
||||||
|
task.error = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
// Clear recovery metadata when task reaches in-review (successful completion)
|
// Clear recovery metadata when task reaches in-review (successful completion)
|
||||||
if (toColumn === "in-review") {
|
if (toColumn === "in-review") {
|
||||||
task.recoveryRetryCount = undefined;
|
task.recoveryRetryCount = undefined;
|
||||||
|
|||||||
@@ -686,6 +686,31 @@ describe("TriageProcessor", () => {
|
|||||||
expect(store.on).toHaveBeenCalledWith("settings:updated", expect.any(Function));
|
expect(store.on).toHaveBeenCalledWith("settings:updated", expect.any(Function));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("terminates active triage when the task is manually moved out of triage", () => {
|
||||||
|
const movedListeners: Array<(event: { task: Task; from: string; to: string }) => void> = [];
|
||||||
|
store = createMockStore();
|
||||||
|
(store.on as ReturnType<typeof vi.fn>).mockImplementation(
|
||||||
|
(event: any, cb: any) => {
|
||||||
|
if (event === "task:moved") movedListeners.push(cb);
|
||||||
|
return store;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
processor = new TriageProcessor(store, rootDir);
|
||||||
|
|
||||||
|
const dispose = vi.fn();
|
||||||
|
(processor as any).processing.add("FN-001");
|
||||||
|
(processor as any).activeSessions.set("FN-001", { dispose });
|
||||||
|
|
||||||
|
movedListeners.forEach((listener) => listener({
|
||||||
|
task: { ...mockTaskDetail, id: "FN-001", column: "todo" },
|
||||||
|
from: "triage",
|
||||||
|
to: "todo",
|
||||||
|
}));
|
||||||
|
|
||||||
|
expect(dispose).toHaveBeenCalledTimes(1);
|
||||||
|
expect((processor as any).moveAborted.has("FN-001")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it("re-reads settings when review_spec runs so reviewer uses the latest validator model", async () => {
|
it("re-reads settings when review_spec runs so reviewer uses the latest validator model", async () => {
|
||||||
const taskId = "FN-001";
|
const taskId = "FN-001";
|
||||||
const testRootDir = await createTriageFixtureRoot("fusion-triage-review-spec-");
|
const testRootDir = await createTriageFixtureRoot("fusion-triage-review-spec-");
|
||||||
|
|||||||
@@ -278,6 +278,8 @@ export class TriageProcessor {
|
|||||||
private activeSessions = new Map<string, { dispose: () => void }>();
|
private activeSessions = new Map<string, { dispose: () => void }>();
|
||||||
/** Tasks aborted due to globalPause (to avoid reporting as errors). */
|
/** Tasks aborted due to globalPause (to avoid reporting as errors). */
|
||||||
private pauseAborted = new Set<string>();
|
private pauseAborted = new Set<string>();
|
||||||
|
/** Tasks manually moved out of triage while specification was queued/running. */
|
||||||
|
private moveAborted = new Set<string>();
|
||||||
/** Tasks killed by the stuck task detector (to avoid reporting as errors). */
|
/** Tasks killed by the stuck task detector (to avoid reporting as errors). */
|
||||||
private stuckAborted = new Set<string>();
|
private stuckAborted = new Set<string>();
|
||||||
|
|
||||||
@@ -336,6 +338,21 @@ export class TriageProcessor {
|
|||||||
this.poll();
|
this.poll();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
store.on("task:moved", ({ task, from, to }: { task: Task; from: string; to: string }) => {
|
||||||
|
if (from !== "triage" || to === "triage") return;
|
||||||
|
if (!this.processing.has(task.id) && !this.activeSessions.has(task.id)) return;
|
||||||
|
|
||||||
|
this.moveAborted.add(task.id);
|
||||||
|
this.options.stuckTaskDetector?.untrackTask(task.id);
|
||||||
|
const session = this.activeSessions.get(task.id);
|
||||||
|
if (session) {
|
||||||
|
triageLog.log(`Task moved ${from} → ${to} — terminating triage session for ${task.id}`);
|
||||||
|
session.dispose();
|
||||||
|
} else {
|
||||||
|
triageLog.log(`Task moved ${from} → ${to} — skipping queued triage for ${task.id}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
start(): void {
|
start(): void {
|
||||||
@@ -552,11 +569,41 @@ export class TriageProcessor {
|
|||||||
this.options.onSpecifyStart?.(task);
|
this.options.onSpecifyStart?.(task);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const detail = await this.store.getTask(task.id);
|
const detail = (await this.store.getTask(task.id)) ?? {
|
||||||
|
...task,
|
||||||
|
prompt: "",
|
||||||
|
attachments: [],
|
||||||
|
comments: [],
|
||||||
|
};
|
||||||
const settings = await this.store.getSettings();
|
const settings = await this.store.getSettings();
|
||||||
const promptPath = `.fusion/tasks/${task.id}/PROMPT.md`;
|
const promptPath = `.fusion/tasks/${task.id}/PROMPT.md`;
|
||||||
|
|
||||||
const agentWork = async () => {
|
const agentWork = async () => {
|
||||||
|
const hasLeftTriage = async (): Promise<boolean> => {
|
||||||
|
if (this.moveAborted.has(task.id)) return true;
|
||||||
|
try {
|
||||||
|
const latestTask = await this.store.getTask(task.id);
|
||||||
|
return latestTask ? latestTask.column !== "triage" : false;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (await hasLeftTriage()) return;
|
||||||
|
|
||||||
|
let currentTask = detail;
|
||||||
|
try {
|
||||||
|
currentTask = (await this.store.getTask(task.id)) ?? detail;
|
||||||
|
} catch {
|
||||||
|
currentTask = detail;
|
||||||
|
}
|
||||||
|
if (currentTask.column !== "triage") {
|
||||||
|
triageLog.log(
|
||||||
|
`${task.id} left triage before specification started — skipping`,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set status only after the semaphore slot has been acquired, so
|
// Set status only after the semaphore slot has been acquired, so
|
||||||
// tasks waiting in the queue don't appear as "specifying".
|
// tasks waiting in the queue don't appear as "specifying".
|
||||||
await this.store.updateTask(task.id, { status: "specifying" });
|
await this.store.updateTask(task.id, { status: "specifying" });
|
||||||
@@ -683,6 +730,8 @@ export class TriageProcessor {
|
|||||||
stuckDetector?.recordActivity(task.id);
|
stuckDetector?.recordActivity(task.id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (await hasLeftTriage()) return;
|
||||||
|
|
||||||
// Read attachment contents for inlining in prompt
|
// Read attachment contents for inlining in prompt
|
||||||
const { attachmentContents, imageContents } =
|
const { attachmentContents, imageContents } =
|
||||||
await readAttachmentContents(
|
await readAttachmentContents(
|
||||||
@@ -725,6 +774,8 @@ export class TriageProcessor {
|
|||||||
// Re-raise errors that pi-coding-agent swallowed after exhausting retries.
|
// Re-raise errors that pi-coding-agent swallowed after exhausting retries.
|
||||||
checkSessionError(session);
|
checkSessionError(session);
|
||||||
|
|
||||||
|
if (await hasLeftTriage()) return;
|
||||||
|
|
||||||
if (createdSubtasksRef.current.length > 0) {
|
if (createdSubtasksRef.current.length > 0) {
|
||||||
const childTaskIds = createdSubtasksRef.current.join(", ");
|
const childTaskIds = createdSubtasksRef.current.join(", ");
|
||||||
await this.store.logEntry(
|
await this.store.logEntry(
|
||||||
@@ -822,6 +873,9 @@ export class TriageProcessor {
|
|||||||
// so the next poll can re-pick this task up.
|
// so the next poll can re-pick this task up.
|
||||||
const restoreStatus = task.status === "needs-respecify" ? "needs-respecify" : null;
|
const restoreStatus = task.status === "needs-respecify" ? "needs-respecify" : null;
|
||||||
await this.store.updateTask(task.id, { status: restoreStatus }).catch(() => {});
|
await this.store.updateTask(task.id, { status: restoreStatus }).catch(() => {});
|
||||||
|
} else if (this.moveAborted.has(task.id)) {
|
||||||
|
this.moveAborted.delete(task.id);
|
||||||
|
triageLog.log(`${task.id} aborted because task left triage`);
|
||||||
} else if (this.stuckAborted.has(task.id)) {
|
} else if (this.stuckAborted.has(task.id)) {
|
||||||
// Stuck task detector killed this session — clear specifying status so the
|
// Stuck task detector killed this session — clear specifying status so the
|
||||||
// next poll retries the task from scratch without reporting an error.
|
// next poll retries the task from scratch without reporting an error.
|
||||||
@@ -880,6 +934,7 @@ export class TriageProcessor {
|
|||||||
this.options.onSpecifyError?.(task, err);
|
this.options.onSpecifyError?.(task, err);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
this.moveAborted.delete(task.id);
|
||||||
this.processing.delete(task.id);
|
this.processing.delete(task.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user