Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/tools/taskStatusPolicy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** Worker-facing task completion is terminal and cannot move backwards. */
export function isTerminalTaskTransition(current: unknown, requested: string): boolean {
return current === "Done" && requested !== "Done";
}
6 changes: 2 additions & 4 deletions src/tools/updateTaskStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { db } from "../firestore.js";
import { logActivity } from "../activityEvents.js";
import type { Tool } from "./types.js";
import { redactClaimTokens } from "./outputSanitizer.js";
import { isTerminalTaskTransition } from "./taskStatusPolicy.js";

const ProofSchema = z
.object({
Expand Down Expand Up @@ -103,10 +104,7 @@ export const updateTaskStatus: Tool<typeof InputSchema> = {
// unbounded loop that burns LLM tokens for no new output. Treat re-opening
// a Done task as a no-op success so the agent moves on instead of churning.
const current = data.status;
if (
current === "Done" &&
(args.status === "In progress" || args.status === "Backlog")
) {
if (isTerminalTaskTransition(current, args.status)) {
return {
ok: true,
data: { taskId: args.taskId, status: "Done" },
Expand Down
17 changes: 17 additions & 0 deletions tests/task-status.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, it } from "vitest";

import { isTerminalTaskTransition } from "../src/tools/taskStatusPolicy.js";

describe("isTerminalTaskTransition", () => {
it.each(["Backlog", "In progress", "Review"])(
"blocks Done → %s",
(requested) => {
expect(isTerminalTaskTransition("Done", requested)).toBe(true);
},
);

it("allows idempotent completion and normal forward movement", () => {
expect(isTerminalTaskTransition("Done", "Done")).toBe(false);
expect(isTerminalTaskTransition("In progress", "Done")).toBe(false);
});
});
Loading