⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(integrations): retire intents from obsolete provider bindings
Tinb085cb128529
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.tsindex e7db76ba8..a156927e2 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@@ -30,6 +30,7 @@ export async function syncLatestTaskValue(let value = initialValue;let attempts = 0;let identity = expectedBinding;+ let lastIntentId: string | undefined;const currentBinding = async () => {const binding = (await findExternalLinksByTask(taskId)).find((candidate) =>@@ -46,8 +47,15 @@ export async function syncLatestTaskValue(binding.integration.type !== identity.type) ||(identity?.config !== undefined &&binding.integration.config !== identity.config)))- )+ ) {+ // The old request cannot identify deliveries from the retained new binding.+ // Retire only its UUID, preserving newer intents and current field metadata.+ if (lastIntentId)+ await updateExternalLink(link.id, {+ retireOutboundIntents: { field, intentIds: [lastIntentId] },+ });return;+ }return binding;};for (;;) {@@ -70,6 +78,7 @@ export async function syncLatestTaskValue(issueEditScope(binding.integration) === queued.scope);const intentId = randomUUID();+ lastIntentId = intentId;// Webhooks may arrive before PATCH returns, including from another instance.const persisted = await updateExternalLink(link.id, {outbound: { field, value, intentId, pending: true },diff --git a/tests/api-integration/deferred-issue-edits.test.ts b/tests/api-integration/deferred-issue-edits.test.tsindex a9fc49db7..57b506c27 100644--- a/tests/api-integration/deferred-issue-edits.test.ts+++ b/tests/api-integration/deferred-issue-edits.test.ts@@ -626,6 +626,7 @@ async function deliverField(value: string,version: string,integrationId: string,+ repositoryName = "repo",) {const payload = {action:@@ -640,7 +641,7 @@ async function deliverField(body: field === "description" ? value : "unchanged",state: field === "state" ? value : "open",updated_at: version,- html_url: "https://git.example/owner/repo/issues/1",+ html_url: `https://git.example/owner/${repositoryName}/issues/1`,},changes:field === "title"@@ -648,10 +649,10 @@ async function deliverField(: { body: { from: "before" } },repository: {id: 20,- name: "repo",- full_name: "owner/repo",+ name: repositoryName,+ full_name: `owner/${repositoryName}`,owner: { login: "owner" },- html_url: "https://git.example/owner/repo",+ html_url: `https://git.example/owner/${repositoryName}`,},};if (field !== "state") {@@ -1848,3 +1849,84 @@ it("reconciles an existing overlapping inbound/repair job from the current proviexpect((await current(task.id))?.title).toBe("C");expect(m.write).not.toHaveBeenCalled();});++it.each(+ providerFields.flatMap((entry) =>+ [false, true].map((failed) => ({ ...entry, failed })),+ ),+)(+ "retires an old $provider $field intent after repository reconfiguration (failed=$failed)",+ async ({ provider, field, failed }) => {+ const { task, integration, link } = await seed(provider);+ await db+ .update(schema.externalLinkTable)+ .set({ metadata: "{}" })+ .where(eq(schema.externalLinkTable.id, link.id));+ const older = field === "state" ? "closed" : "A";+ const fresh = field === "state" ? "open" : "new-repo-value";+ const write = vi.fn(async () => {+ const config = JSON.stringify({+ ...JSON.parse(integration.config),+ repositoryName: "new-repo",+ });+ const [rebound] = await db+ .update(schema.integrationTable)+ .set({ config })+ .where(eq(schema.integrationTable.id, integration.id))+ .returning();+ m.integrations = [rebound];+ await updateExternalLink(link.id, {+ outbound: {+ field,+ value: fresh,+ intentId: "new-repo-intent",+ pending: true,+ },+ });+ if (failed) throw new Error("old repository request failed");+ return "2026-09-30T00:00:02Z";+ });+ const result = syncLatestTaskValue(+ task.id,+ integration.projectId,+ link,+ field,+ older,+ write,+ undefined,+ integration,+ );+ if (failed)+ await expect(result).rejects.toThrow("old repository request failed");+ else await result;+ const stamp = (await metadata(link.id)).lastSync[field];+ const oldIntent = stamp.outbound.find(+ (entry: { intentId: string }) => entry.intentId !== "new-repo-intent",+ );+ expect(oldIntent).toMatchObject({+ pending: false,+ uncertain: false,+ cancelled: true,+ });+ expect(+ stamp.outbound.find(+ (entry: { intentId: string }) => entry.intentId === "new-repo-intent",+ ),+ ).toMatchObject({ pending: true });+ await deliverField(+ provider,+ field,+ older,+ "2026-09-30T00:00:03Z",+ integration.id,+ "new-repo",+ );+ const row = await current(task.id);+ expect(field === "state" ? row?.status : row?.[field]).toBe(+ field === "state" ? "done" : older,+ );+ expect((await metadata(link.id)).deferredIssueEdit).toBeUndefined();+ expect(write).toHaveBeenCalledTimes(1);+ expect(m.write).not.toHaveBeenCalled();+ },+);