Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(api): recheck archived tasks before dispatching issue state

Tin6c04b6f2998c
diff --git a/apps/api/src/plugins/github/services/sync-latest-task-value.ts b/apps/api/src/plugins/github/services/sync-latest-task-value.ts
index bc5cc9cca..d7ca90a65 100644
--- a/apps/api/src/plugins/github/services/sync-latest-task-value.ts
+++ b/apps/api/src/plugins/github/services/sync-latest-task-value.ts
@@ -111,6 +111,7 @@ export async function syncLatestTaskValue(
{ ...link, taskId },
identity?.config,
() => write(value),
+ { issueState: field === "state" },
);
if (!dispatched) {
await updateExternalLink(link.id, {
diff --git a/apps/api/src/plugins/sync/dispatch-issue-write.ts b/apps/api/src/plugins/sync/dispatch-issue-write.ts
index 2770a32ca..b09b520e8 100644
--- a/apps/api/src/plugins/sync/dispatch-issue-write.ts
+++ b/apps/api/src/plugins/sync/dispatch-issue-write.ts
@@ -1,16 +1,18 @@
import type { IssueWrite } from "./issue-write";
import { and, eq, inArray, isNull, or } from "drizzle-orm";
import db from "../../database";
-import { labelTable } from "../../database/schema";
+import { labelTable, taskTable } from "../../database/schema";
import { withIntegrationLink } from "../github/services/with-integration-link";
import { canSyncTask } from "./eligibility";
import { readSyncRules } from "./rules";
import { sameConfig } from "./same-config";
+import { isStateSyncPaused } from "./state-sync-paused";
export async function dispatchIssueWrite<T>(
link: { id: string; taskId: string; integrationId: string | null },
expectedConfig: string | undefined,
send: () => Promise<T>,
+ options: { issueState?: boolean } = {},
): Promise<{ value: T } | undefined> {
if (!link.integrationId) return;
const integration = await db.query.integrationTable.findFirst({
@@ -48,6 +50,14 @@ export async function dispatchIssueWrite<T>(
!(await canSyncTask(link.taskId, integration.id, tx, expectedConfig))
)
return;
+ // An open/closed write must not start once the task is archived.
+ if (options.issueState) {
+ const task = await tx.query.taskTable.findFirst({
+ where: eq(taskTable.id, link.taskId),
+ columns: { status: true },
+ });
+ if (!task || isStateSyncPaused(task.status)) return;
+ }
// Start the request while pause/rule/label writes are excluded. Settle it
// after commit so provider latency never holds these row locks.
request = send().then(
diff --git a/tests/api-integration/deferred-issue-edits.test.ts b/tests/api-integration/deferred-issue-edits.test.ts
index ea50fa8b8..4397b378d 100644
--- a/tests/api-integration/deferred-issue-edits.test.ts
+++ b/tests/api-integration/deferred-issue-edits.test.ts
@@ -7,6 +7,7 @@ import {
replayDeferredIssueEdits,
} from "../../apps/api/src/plugins/github/services/deferred-issue-edits";
import { deferTaskSync } from "../../apps/api/src/plugins/github/services/defer-issue-edit";
+import * as eligibility from "../../apps/api/src/plugins/sync/eligibility";
import { syncLatestTaskValue } from "../../apps/api/src/plugins/github/services/sync-latest-task-value";
import { updateExternalLink } from "../../apps/api/src/plugins/github/services/link-manager";
import { handleGiteaIssueEdited } from "../../apps/api/src/plugins/gitea/webhooks/issue-edited";
@@ -1985,6 +1986,45 @@ it.each(["github", "gitea"])(
},
);
+it.each(["github", "gitea"])(
+ "does not send a %s reopen for a task archived just before dispatch",
+ async (type) => {
+ const { task, integration, link } = await seed(type);
+ await db
+ .update(schema.externalLinkTable)
+ .set({ metadata: "{}" })
+ .where(eq(schema.externalLinkTable.id, link.id));
+ const canSyncTask = eligibility.canSyncTask;
+ let calls = 0;
+ // The second eligibility check runs after the archive check, before dispatch.
+ const guard = vi
+ .spyOn(eligibility, "canSyncTask")
+ .mockImplementation(async (...args) => {
+ if (++calls === 2)
+ await db
+ .update(schema.taskTable)
+ .set({ status: "archived", columnId: null })
+ .where(eq(schema.taskTable.id, task.id));
+ return canSyncTask(...args);
+ });
+ const write = vi.fn(async () => "2026-09-30T00:00:05Z");
+
+ await syncLatestTaskValue(
+ task.id,
+ integration.projectId,
+ link,
+ "state",
+ "open",
+ write,
+ );
+ guard.mockRestore();
+
+ expect(calls).toBeGreaterThan(2);
+ expect(write).not.toHaveBeenCalled();
+ expect((await current(task.id))?.status).toBe("archived");
+ },
+);
+
it("skips provider reads and writes while another replica holds the worker lease", async () => {
const { link, integration } = await seed();
await deferTaskSync(link, integration, ["title"]);