Serialize gate confirmation mirror writes

This commit is contained in:
Nicky Leach committed 2026-06-20 02:13:58 +00:00
1 parent 13a2ec5716
commit 45bccb700d
2 files changed
+14 -6

No files matched your search

+7 -1
View File
@@ -2957,7 +2957,13 @@ describeEmbeddedPostgres("issueService.create workspace inheritance", () => {
body: `A user pasted the mirror marker: <!-- gate-confirmation-mirror:${child.id} -->`,
});
const mirrored = await svc.mirrorGateConfirmationToParent(child.id);
const mirrorResults = await Promise.all([
svc.mirrorGateConfirmationToParent(child.id),
svc.mirrorGateConfirmationToParent(child.id),
]);
expect(mirrorResults.filter(Boolean)).toHaveLength(1);
expect(mirrorResults.filter((result) => result === null)).toHaveLength(1);
const mirrored = mirrorResults.find(Boolean);
expect(mirrored).toMatchObject({
issueId: parentIssueId,
authorType: "system",
+7 -5
View File
@@ -4645,8 +4645,8 @@ export function issueService(db: Db) {
};
},
mirrorGateConfirmationToParent: async (childIssueId: string) => {
const child = await db
mirrorGateConfirmationToParent: async (childIssueId: string) => db.transaction(async (tx) => {
const child = await tx
.select({
id: issues.id,
companyId: issues.companyId,
@@ -4658,6 +4658,7 @@ export function issueService(db: Db) {
})
.from(issues)
.where(eq(issues.id, childIssueId))
.for("update")
.then((rows) => rows[0] ?? null);
if (!child || child.status !== "done" || !child.parentId) return null;
@@ -4665,7 +4666,7 @@ export function issueService(db: Db) {
if (!mirror || mirror.parentIssueId !== child.parentId) return null;
const marker = buildGateConfirmationMirrorMarker(child.id);
const existingMirror = await db
const existingMirror = await tx
.select({ id: issueComments.id })
.from(issueComments)
.where(and(
@@ -4678,7 +4679,7 @@ export function issueService(db: Db) {
.then((rows) => rows[0] ?? null);
if (existingMirror) return null;
const latestChildComment = await db
const latestChildComment = await tx
.select({ body: issueComments.body })
.from(issueComments)
.where(and(
@@ -4700,8 +4701,9 @@ export function issueService(db: Db) {
}),
{},
{ authorType: "system" },
tx,
);
},
}),
createChild: async (
parentIssueId: string,