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(integrations): order provider edits and repair uncertain writes

Tin1666d4d8f0d5
diff --git a/apps/api/src/plugins/gitea/webhooks/issue-closed.ts b/apps/api/src/plugins/gitea/webhooks/issue-closed.ts
index c0c2b6f46..c8d128875 100644
--- a/apps/api/src/plugins/gitea/webhooks/issue-closed.ts
+++ b/apps/api/src/plugins/gitea/webhooks/issue-closed.ts
@@ -115,7 +115,11 @@ export async function handleGiteaIssueClosed(
"closed",
issue.updated_at,
current ? (current.state ?? issue.state) : undefined,
- { linkId: externalLink.id, field: "state" },
+ {
+ linkId: externalLink.id,
+ field: "state",
+ localValue: task.status === "done" ? "closed" : "open",
+ },
)
)
return;
@@ -177,6 +181,7 @@ export async function handleGiteaIssueClosed(
existingMetadata.lastSync?.state,
"closed",
"gitea",
+ current?.updated_at ?? issue.updated_at,
),
},
},
diff --git a/apps/api/src/plugins/gitea/webhooks/issue-edited.ts b/apps/api/src/plugins/gitea/webhooks/issue-edited.ts
index 0961746eb..9266c5abe 100644
--- a/apps/api/src/plugins/gitea/webhooks/issue-edited.ts
+++ b/apps/api/src/plugins/gitea/webhooks/issue-edited.ts
@@ -121,7 +121,11 @@ export async function handleGiteaIssueEdited(
issue.title,
issue.updated_at,
current?.title,
- { linkId: externalLink.id, field: "title" },
+ {
+ linkId: externalLink.id,
+ field: "title",
+ localValue: task.title,
+ },
)
) {
shouldUpdateTitle = false;
@@ -134,6 +138,7 @@ export async function handleGiteaIssueEdited(
metadata.lastSync?.title,
issue.title,
"gitea",
+ current?.updated_at ?? issue.updated_at,
);
}
}
@@ -159,7 +164,11 @@ export async function handleGiteaIssueEdited(
task.id,
)
: undefined,
- { linkId: externalLink.id, field: "description" },
+ {
+ linkId: externalLink.id,
+ field: "description",
+ localValue: task.description || "",
+ },
)
) {
shouldUpdateDescription = false;
@@ -172,6 +181,7 @@ export async function handleGiteaIssueEdited(
metadata.lastSync?.description,
formattedDescription,
"gitea",
+ current?.updated_at ?? issue.updated_at,
);
}
}
diff --git a/apps/api/src/plugins/gitea/webhooks/issue-reopened.ts b/apps/api/src/plugins/gitea/webhooks/issue-reopened.ts
index 9727cec87..3ab480731 100644
--- a/apps/api/src/plugins/gitea/webhooks/issue-reopened.ts
+++ b/apps/api/src/plugins/gitea/webhooks/issue-reopened.ts
@@ -116,7 +116,11 @@ export async function handleGiteaIssueReopened(
"open",
issue.updated_at,
current ? (current.state ?? issue.state) : undefined,
- { linkId: externalLink.id, field: "state" },
+ {
+ linkId: externalLink.id,
+ field: "state",
+ localValue: task.status === "done" ? "closed" : "open",
+ },
)
)
return;
@@ -178,6 +182,7 @@ export async function handleGiteaIssueReopened(
existingMetadata.lastSync?.state,
"open",
"gitea",
+ current?.updated_at ?? issue.updated_at,
),
},
},
diff --git a/apps/api/src/plugins/github/services/apply-observed-task-value.ts b/apps/api/src/plugins/github/services/apply-observed-task-value.ts
index 1570ee606..94f5ad092 100644
--- a/apps/api/src/plugins/github/services/apply-observed-task-value.ts
+++ b/apps/api/src/plugins/github/services/apply-observed-task-value.ts
@@ -59,7 +59,13 @@ export async function applyObservedTaskValue(
...(field === "state" ? { state: value } : {}),
lastSync: {
...metadata.lastSync,
- [field]: inboundStamp(stamp, value, integration.type),
+ [field]: inboundStamp(
+ stamp,
+ value,
+ integration.type,
+ stamp?.outbound?.find((entry) => entry.intentId === intentId)
+ ?.observedUpdatedAt,
+ ),
},
},
},
diff --git a/apps/api/src/plugins/github/services/deferred-issue-edits.ts b/apps/api/src/plugins/github/services/deferred-issue-edits.ts
index fadf7ed99..08778a717 100644
--- a/apps/api/src/plugins/github/services/deferred-issue-edits.ts
+++ b/apps/api/src/plugins/github/services/deferred-issue-edits.ts
@@ -223,7 +223,12 @@ export async function replayDeferredIssueEdits() {
),
state: issue.state,
};
- const repairs: Array<{ field: IssueField; value: string }> = [];
+ const repairs: Array<{
+ field: IssueField;
+ value: string;
+ intentId?: string;
+ providerValue: string;
+ }> = [];
const applied = await withIntegrationLink(
link,
integration,
@@ -287,7 +292,12 @@ export async function replayDeferredIssueEdits() {
},
tx,
);
- repairs.push({ field, value: local });
+ repairs.push({
+ field,
+ value: local,
+ intentId: uncertain.intentId,
+ providerValue: values[field],
+ });
}
}
// Classify every field before writing any: PendingEcho commits only its observation.
@@ -304,7 +314,18 @@ export async function replayDeferredIssueEdits() {
values[field],
issue.updated_at,
values[field],
- { linkId: link.id, field },
+ {
+ linkId: link.id,
+ field,
+ localValue:
+ field === "state"
+ ? task.status === "done"
+ ? "closed"
+ : "open"
+ : field === "description"
+ ? task.description || ""
+ : task.title,
+ },
),
);
for (const field of accepted) {
@@ -322,6 +343,7 @@ export async function replayDeferredIssueEdits() {
current.lastSync?.[field],
values[field],
integration.type,
+ issue.updated_at,
),
};
if (field === "state") current.state = values.state;
@@ -371,6 +393,26 @@ export async function replayDeferredIssueEdits() {
link,
integration,
async (tx) => {
+ // The repair succeeded. Retire its uncertain intent so a future
+ // genuine provider edit to the old value remains importable.
+ for (const repair of repairs) {
+ if (repair.intentId)
+ await updateExternalLink(
+ link.id,
+ {
+ outbound: {
+ field: repair.field,
+ value: repair.providerValue,
+ intentId: repair.intentId,
+ updatedAt: issue.updated_at,
+ pending: false,
+ uncertain: false,
+ cancelled: true,
+ },
+ },
+ tx,
+ );
+ }
await updateExternalLink(
link.id,
{ completeDeferredEdit: job.id },
diff --git a/apps/api/src/plugins/github/utils/inbound-echo.ts b/apps/api/src/plugins/github/utils/inbound-echo.ts
index 979253828..f6e3adca2 100644
--- a/apps/api/src/plugins/github/utils/inbound-echo.ts
+++ b/apps/api/src/plugins/github/utils/inbound-echo.ts
@@ -3,9 +3,12 @@ import {
ambiguousOutboundEcho,
isOutboundEcho,
pendingOutboundIntent,
+ uncertainOutboundIntent,
+ inboundOccurredAfterIntent,
type SyncStamp,
} from "./sync-echo";
class ConfirmationRequired extends Error {}
+class RepairRequired extends Error {}
export class PendingResponseTimeout extends Error {}
export class PendingEcho extends Error {
recorded = false;
@@ -25,8 +28,48 @@ export function inboundEcho(
value: string,
updatedAt?: string,
providerValue?: string,
- context?: { linkId: string; field: "title" | "description" | "state" },
+ context?: {
+ linkId: string;
+ field: "title" | "description" | "state";
+ localValue?: string;
+ },
) {
+ const version = Date.parse(updatedAt ?? "");
+ const inboundVersion = Date.parse(stamp?.inboundUpdatedAt ?? "");
+ const knownVersions = [
+ inboundVersion,
+ ...(stamp?.outbound ?? [])
+ .filter((entry) => !entry.cancelled && !entry.pending && !entry.uncertain)
+ .map((entry) => Date.parse(entry.updatedAt ?? "")),
+ ].filter(Number.isFinite);
+ if (
+ Number.isFinite(version) &&
+ knownVersions.some((known) => known > version)
+ )
+ return true;
+ if (
+ Number.isFinite(version) &&
+ version === inboundVersion &&
+ stamp?.inboundValue !== value
+ ) {
+ if (providerValue === undefined) throw new ConfirmationRequired();
+ if (providerValue !== value) return true;
+ }
+ const uncertain = uncertainOutboundIntent(stamp, value);
+ const localValue = context?.localValue ?? stamp?.value;
+ if (
+ uncertain &&
+ localValue !== value &&
+ !(
+ stamp?.source !== "kaneo" &&
+ stamp?.inboundValue === localValue &&
+ inboundOccurredAfterIntent(stamp, uncertain)
+ )
+ ) {
+ if (providerValue === undefined) throw new ConfirmationRequired();
+ if (providerValue !== value) return true;
+ throw new RepairRequired();
+ }
const pending = pendingOutboundIntent(stamp, value);
if (pending) throw new PendingEcho(pending.intentId, updatedAt, context);
if (!isOutboundEcho(stamp, value, updatedAt)) {
@@ -61,7 +104,21 @@ export async function withEchoConfirmation<Provider, Result>(
if (result instanceof PendingEcho) throw result;
return result;
} catch (error) {
- if (error instanceof PendingEcho) {
+ if (error instanceof RepairRequired) {
+ if (!defer)
+ throw new PendingResponseTimeout(
+ "Uncertain outbound write needs durable repair",
+ );
+ try {
+ await defer();
+ return;
+ } catch (cause) {
+ throw new PendingResponseTimeout(
+ "Could not persist deferred webhook delivery",
+ { cause },
+ );
+ }
+ } else if (error instanceof PendingEcho) {
const { context, intentId, updatedAt } = error;
const key = `${intentId}:${updatedAt}`;
if (
diff --git a/apps/api/src/plugins/github/utils/sync-echo.ts b/apps/api/src/plugins/github/utils/sync-echo.ts
index e52ed1e8d..84c2be442 100644
--- a/apps/api/src/plugins/github/utils/sync-echo.ts
+++ b/apps/api/src/plugins/github/utils/sync-echo.ts
@@ -22,6 +22,7 @@ export type SyncStamp = {
inboundAt?: string;
inboundId?: string;
inboundValue?: string;
+ inboundUpdatedAt?: string;
outbound?: OutboundEntry[];
};
@@ -155,6 +156,7 @@ export function inboundStamp(
previous: SyncStamp | undefined,
value: string,
source: string,
+ updatedAt?: string,
): SyncStamp {
const timestamp = new Date().toISOString();
return {
@@ -165,6 +167,7 @@ export function inboundStamp(
inboundAt: timestamp,
inboundId: randomUUID(),
inboundValue: value,
+ inboundUpdatedAt: updatedAt ?? previous?.inboundUpdatedAt,
};
}
export function ambiguousOutboundEcho(
diff --git a/apps/api/src/plugins/github/webhooks/issue-closed.ts b/apps/api/src/plugins/github/webhooks/issue-closed.ts
index 1f4056408..485b62f13 100644
--- a/apps/api/src/plugins/github/webhooks/issue-closed.ts
+++ b/apps/api/src/plugins/github/webhooks/issue-closed.ts
@@ -99,7 +99,11 @@ export async function handleIssueClosed(payload: IssueClosedPayload) {
"closed",
issue.updated_at,
current?.state,
- { linkId: externalLink.id, field: "state" },
+ {
+ linkId: externalLink.id,
+ field: "state",
+ localValue: task.status === "done" ? "closed" : "open",
+ },
)
)
return;
@@ -146,6 +150,7 @@ export async function handleIssueClosed(payload: IssueClosedPayload) {
existingMetadata.lastSync?.state,
"closed",
"github",
+ current?.updated_at ?? issue.updated_at,
),
},
},
diff --git a/apps/api/src/plugins/github/webhooks/issue-edited.ts b/apps/api/src/plugins/github/webhooks/issue-edited.ts
index 22b117ba8..4848b68f1 100644
--- a/apps/api/src/plugins/github/webhooks/issue-edited.ts
+++ b/apps/api/src/plugins/github/webhooks/issue-edited.ts
@@ -128,7 +128,11 @@ export async function handleIssueEdited(payload: IssueEditedPayload) {
issue.title,
issue.updated_at,
current?.title,
- { linkId: externalLink.id, field: "title" },
+ {
+ linkId: externalLink.id,
+ field: "title",
+ localValue: task.title,
+ },
)
) {
console.log(
@@ -144,6 +148,7 @@ export async function handleIssueEdited(payload: IssueEditedPayload) {
metadata.lastSync?.title,
issue.title,
"github",
+ current?.updated_at ?? issue.updated_at,
);
console.log(
`Updating task title from GitHub: "${changes.title.from}" → "${issue.title}"`,
@@ -172,7 +177,11 @@ export async function handleIssueEdited(payload: IssueEditedPayload) {
task.id,
)
: undefined,
- { linkId: externalLink.id, field: "description" },
+ {
+ linkId: externalLink.id,
+ field: "description",
+ localValue: task.description || "",
+ },
)
) {
console.log(
@@ -188,6 +197,7 @@ export async function handleIssueEdited(payload: IssueEditedPayload) {
metadata.lastSync?.description,
formattedDescription,
"github",
+ current?.updated_at ?? issue.updated_at,
);
console.log("Updating task description from GitHub");
}
diff --git a/apps/api/src/plugins/github/webhooks/issue-reopened.ts b/apps/api/src/plugins/github/webhooks/issue-reopened.ts
index be81fff5a..e08cac429 100644
--- a/apps/api/src/plugins/github/webhooks/issue-reopened.ts
+++ b/apps/api/src/plugins/github/webhooks/issue-reopened.ts
@@ -102,7 +102,11 @@ export async function handleIssueReopened(payload: IssueReopenedPayload) {
"open",
issue.updated_at,
current?.state,
- { linkId: externalLink.id, field: "state" },
+ {
+ linkId: externalLink.id,
+ field: "state",
+ localValue: task.status === "done" ? "closed" : "open",
+ },
)
)
return;
@@ -149,6 +153,7 @@ export async function handleIssueReopened(payload: IssueReopenedPayload) {
existingMetadata.lastSync?.state,
"open",
"github",
+ current?.updated_at ?? issue.updated_at,
),
},
},
diff --git a/tests/api-integration/deferred-issue-edits.test.ts b/tests/api-integration/deferred-issue-edits.test.ts
index 3115ffbda..a818836a8 100644
--- a/tests/api-integration/deferred-issue-edits.test.ts
+++ b/tests/api-integration/deferred-issue-edits.test.ts
@@ -9,6 +9,10 @@ import {
import { updateExternalLink } from "../../apps/api/src/plugins/github/services/link-manager";
import { handleGiteaIssueEdited } from "../../apps/api/src/plugins/gitea/webhooks/issue-edited";
import { handleIssueEdited } from "../../apps/api/src/plugins/github/webhooks/issue-edited";
+import { handleIssueClosed } from "../../apps/api/src/plugins/github/webhooks/issue-closed";
+import { handleIssueReopened } from "../../apps/api/src/plugins/github/webhooks/issue-reopened";
+import { handleGiteaIssueClosed } from "../../apps/api/src/plugins/gitea/webhooks/issue-closed";
+import { handleGiteaIssueReopened } from "../../apps/api/src/plugins/gitea/webhooks/issue-reopened";
import {
inboundStamp,
outboundStamp,
@@ -612,3 +616,277 @@ it("retains missing-issue work when credentials rotate during the read", async (
expect((await current(task.id))?.description).toBe("recovered body");
expect((await metadata(link.id)).deferredIssueEdit).toBeUndefined();
});
+
+type IssueField = "title" | "description" | "state";
+async function deliverField(
+ provider: string,
+ field: IssueField,
+ value: string,
+ version: string,
+ integrationId: string,
+) {
+ const payload = {
+ action:
+ field === "state"
+ ? value === "closed"
+ ? "closed"
+ : "reopened"
+ : "edited",
+ issue: {
+ number: 1,
+ title: field === "title" ? value : "unchanged",
+ body: field === "description" ? value : "unchanged",
+ state: field === "state" ? value : "open",
+ updated_at: version,
+ html_url: "https://git.example/owner/repo/issues/1",
+ },
+ changes:
+ field === "title"
+ ? { title: { from: "before" } }
+ : { body: { from: "before" } },
+ repository: {
+ id: 20,
+ name: "repo",
+ full_name: "owner/repo",
+ owner: { login: "owner" },
+ html_url: "https://git.example/owner/repo",
+ },
+ };
+ if (field !== "state") {
+ if (provider === "github") await handleIssueEdited(payload);
+ else await handleGiteaIssueEdited(payload, integrationId);
+ } else if (provider === "github") {
+ await (value === "closed" ? handleIssueClosed : handleIssueReopened)(
+ payload,
+ );
+ } else {
+ await (
+ value === "closed" ? handleGiteaIssueClosed : handleGiteaIssueReopened
+ )(payload, integrationId);
+ }
+}
+const providerFields = ["github", "gitea"].flatMap((provider) =>
+ (["title", "description", "state"] as const).map((field) => ({
+ provider,
+ field,
+ })),
+);
+it.each(
+ providerFields.flatMap((entry) =>
+ [false, true].map((collision) => ({ ...entry, collision })),
+ ),
+)(
+ "preserves the latest genuine $provider $field delivery (sameVersion=$collision)",
+ async ({ provider, field, collision }) => {
+ const { task, integration, link } = await seed(provider);
+ await db
+ .update(schema.externalLinkTable)
+ .set({ metadata: "{}" })
+ .where(eq(schema.externalLinkTable.id, link.id));
+ const latest = field === "state" ? "open" : "remote-new";
+ const older = field === "state" ? "closed" : "remote-old";
+ const version = "2026-09-30T00:00:03Z";
+ m.read.mockResolvedValue({
+ title: latest,
+ body: latest,
+ state: "open",
+ updated_at: version,
+ });
+ await deliverField(provider, field, latest, version, integration.id);
+ await deliverField(
+ provider,
+ field,
+ older,
+ collision ? version : "2026-09-30T00:00:02Z",
+ integration.id,
+ );
+ const row = await current(task.id);
+ expect(field === "state" ? row?.status : row?.[field]).toBe(
+ field === "state" ? "to-do" : latest,
+ );
+ expect((await metadata(link.id)).lastSync[field].inboundUpdatedAt).toBe(
+ version,
+ );
+ if (collision) expect(m.read).toHaveBeenCalledOnce();
+ else expect(m.read).not.toHaveBeenCalled();
+ await deliverField(
+ provider,
+ field,
+ older,
+ "2026-09-30T00:00:04Z",
+ integration.id,
+ );
+ const after = await current(task.id);
+ expect(field === "state" ? after?.status : after?.[field]).toBe(
+ field === "state" ? "done" : older,
+ );
+ },
+);
+it.each(providerFields)(
+ "repairs a late timed-out $provider $field write without reverting the newer local value",
+ async ({ provider, field }) => {
+ const { task, integration, link } = await seed(provider);
+ const older = field === "state" ? "closed" : "remote-old";
+ const latest =
+ field === "state" ? "open" : field === "title" ? "B" : "old body";
+ const pending = outboundStamp(undefined, older, undefined, {
+ intentId: "timed-out",
+ pending: true,
+ });
+ const uncertain = outboundStamp(pending, older, undefined, {
+ intentId: "timed-out",
+ pending: false,
+ uncertain: true,
+ });
+ const stamp = outboundStamp(uncertain, latest, "2026-09-30T00:00:02Z", {
+ intentId: "newer-completed",
+ });
+ await db
+ .update(schema.externalLinkTable)
+ .set({ metadata: JSON.stringify({ lastSync: { [field]: stamp } }) })
+ .where(eq(schema.externalLinkTable.id, link.id));
+ m.read.mockResolvedValue({
+ title: older,
+ body: older,
+ state: "closed",
+ updated_at: "2026-09-30T00:00:03Z",
+ });
+ await deliverField(
+ provider,
+ field,
+ older,
+ "2026-09-30T00:00:03Z",
+ integration.id,
+ );
+ expect((await metadata(link.id)).deferredIssueEdit.fields).toEqual([field]);
+ expect(await current(task.id)).toMatchObject({
+ title: "B",
+ description: "old body",
+ status: "to-do",
+ });
+ await replayDeferredIssueEdits();
+ expect(await current(task.id)).toMatchObject({
+ title: "B",
+ description: "old body",
+ status: "to-do",
+ });
+ expect(m.write).toHaveBeenCalledWith(
+ expect.objectContaining(
+ field === "description"
+ ? { body: expect.stringContaining(latest) }
+ : { [field]: latest },
+ ),
+ );
+ expect((await metadata(link.id)).deferredIssueEdit).toBeUndefined();
+ expect(publishEvent).not.toHaveBeenCalled();
+ await deliverField(
+ provider,
+ field,
+ older,
+ "2026-09-30T00:00:05Z",
+ integration.id,
+ );
+ const later = await current(task.id);
+ expect(field === "state" ? later?.status : later?.[field]).toBe(
+ field === "state" ? "done" : older,
+ );
+ expect((await metadata(link.id)).deferredIssueEdit).toBeUndefined();
+ },
+);
+
+it("completes uncertain replay when the task already equals the provider", async () => {
+ const { task, integration, link } = await seed();
+ const uncertain = outboundStamp(
+ outboundStamp(undefined, "A", undefined, {
+ intentId: "uncertain",
+ pending: true,
+ }),
+ "A",
+ undefined,
+ { intentId: "uncertain", pending: false, uncertain: true },
+ );
+ const stamp = outboundStamp(uncertain, "B", "2026-09-30T00:00:02Z");
+ await db
+ .update(schema.externalLinkTable)
+ .set({ metadata: JSON.stringify({ lastSync: { title: stamp } }) })
+ .where(eq(schema.externalLinkTable.id, link.id));
+ await db
+ .update(schema.taskTable)
+ .set({ title: "A" })
+ .where(eq(schema.taskTable.id, task.id));
+ await deferIssueEdit(link, integration, ["title"]);
+ expect(await replayDeferredIssueEdits()).toEqual({ degraded: false });
+ expect((await metadata(link.id)).deferredIssueEdit).toBeUndefined();
+ expect((await current(task.id))?.title).toBe("A");
+ expect(m.write).not.toHaveBeenCalled();
+});
+it("repairs an uncertain delivery over an unstamped local edit after a genuine provider edit", async () => {
+ const { task, integration, link } = await seed();
+ const pending = outboundStamp(undefined, "A", undefined, {
+ intentId: "uncertain",
+ pending: true,
+ });
+ const stamp = inboundStamp(
+ outboundStamp(pending, "A", undefined, {
+ intentId: "uncertain",
+ pending: false,
+ uncertain: true,
+ }),
+ "B",
+ "github",
+ "2026-09-30T00:00:02Z",
+ );
+ await db
+ .update(schema.externalLinkTable)
+ .set({ metadata: JSON.stringify({ lastSync: { title: stamp } }) })
+ .where(eq(schema.externalLinkTable.id, link.id));
+ await db
+ .update(schema.taskTable)
+ .set({ title: "C" })
+ .where(eq(schema.taskTable.id, task.id));
+ await deliverField(
+ "github",
+ "title",
+ "A",
+ "2026-09-30T00:00:03Z",
+ integration.id,
+ );
+ expect((await current(task.id))?.title).toBe("C");
+ expect((await metadata(link.id)).deferredIssueEdit.fields).toEqual(["title"]);
+ await replayDeferredIssueEdits();
+ expect(m.write).toHaveBeenCalledWith(expect.objectContaining({ title: "C" }));
+});
+
+it("retains the uncertain intent and job when corrective provider HTTP fails", async () => {
+ const { task, integration, link } = await seed();
+ const pending = outboundStamp(undefined, "A", undefined, {
+ intentId: "failed-repair",
+ pending: true,
+ });
+ const stamp = outboundStamp(
+ outboundStamp(pending, "A", undefined, {
+ intentId: "failed-repair",
+ pending: false,
+ uncertain: true,
+ }),
+ "B",
+ "2026-09-30T00:00:02Z",
+ );
+ await db
+ .update(schema.externalLinkTable)
+ .set({ metadata: JSON.stringify({ lastSync: { title: stamp } }) })
+ .where(eq(schema.externalLinkTable.id, link.id));
+ await deferIssueEdit(link, integration, ["title"]);
+ m.write.mockRejectedValueOnce(new Error("provider unavailable"));
+ expect(await replayDeferredIssueEdits()).toEqual({ degraded: true });
+ const queued = await metadata(link.id);
+ expect(queued.deferredIssueEdit).toBeDefined();
+ const retained = queued.lastSync.title.outbound.find(
+ (entry: { intentId: string }) => entry.intentId === "failed-repair",
+ );
+ expect(retained.uncertain).toBe(true);
+ expect(retained.cancelled).not.toBe(true);
+ await replayDeferredIssueEdits();
+ expect((await current(task.id))?.title).toBe("B");
+ expect((await metadata(link.id)).deferredIssueEdit).toBeUndefined();
+});
diff --git a/tests/api/plugins/github/outbound-intent.test.ts b/tests/api/plugins/github/outbound-intent.test.ts
index f5589f8f9..80ca42337 100644
--- a/tests/api/plugins/github/outbound-intent.test.ts
+++ b/tests/api/plugins/github/outbound-intent.test.ts
@@ -304,9 +304,15 @@ it.each([
);
expect(echo).toBe(true);
expect(m.current.title).toBe("B");
- expect(inboundEcho(m.stamps.title, "A", "2026-09-30T00:00:03Z", "A")).toBe(
- false,
+ const defer = vi.fn(async () => undefined);
+ await withEchoConfirmation(
+ async () => "A",
+ async (current) =>
+ inboundEcho(m.stamps.title, "A", "2026-09-30T00:00:03Z", current),
+ defer,
);
+ expect(defer).toHaveBeenCalledOnce();
+ expect(m.current.title).toBe("B");
},
);
@@ -411,3 +417,17 @@ it("distinguishes earlier and intervening inbound edits within one millisecond",
expect(inboundOccurredAfterIntent(later, intent)).toBe(true);
vi.useRealTimers();
});
+
+it("confirms different inbound values sharing a provider version", async () => {
+ const version = "2026-09-30T00:00:03Z";
+ const stamp = inboundStamp(undefined, "B", "github", version);
+ expect(inboundEcho(stamp, "A", "2026-09-30T00:00:02Z")).toBe(true);
+ const read = vi.fn(async () => "B");
+ expect(
+ await withEchoConfirmation(read, async (current) =>
+ inboundEcho(stamp, "A", version, current),
+ ),
+ ).toBe(true);
+ expect(read).toHaveBeenCalledOnce();
+ expect(inboundEcho(stamp, "A", version, "A")).toBe(false);
+});