Skip to content

Commit 954a7da

Browse files
mindfnclaude
andcommitted
fix(#406): defer in-memory cursor until persistence succeeds
Per Codex P2 review: swapped order so patchAutomationState runs before memory Map update in both commitCursor and echo-skip paths. If store fails, memory cursor stays behind → gate retries naturally. [宪宪/Opus-46🐾] Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2914baf commit 954a7da

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

packages/api/src/infrastructure/email/ReviewFeedbackTaskSpec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ export function createReviewFeedbackTaskSpec(opts: ReviewFeedbackTaskSpecOptions
9090
const allSkipped = newComments.length === 0 && newDecisions.length === 0;
9191
const hadNewItems = allNewComments.length > 0 || allNewReviews.length > 0;
9292
if (hadNewItems && allSkipped) {
93-
commentCursors.set(prKey, maxCommentId);
94-
reviewCursors.set(prKey, maxReviewId);
95-
// #406: Persist echo-skip cursor advance so restarts don't re-process
93+
// #406: Persist first — memory advances only after store succeeds
9694
await opts.taskStore.patchAutomationState(task.id, {
9795
review: { lastCommentCursor: maxCommentId, lastDecisionCursor: maxReviewId },
9896
});
97+
commentCursors.set(prKey, maxCommentId);
98+
reviewCursors.set(prKey, maxReviewId);
9999
continue;
100100
}
101101

@@ -109,16 +109,16 @@ export function createReviewFeedbackTaskSpec(opts: ReviewFeedbackTaskSpecOptions
109109
newComments,
110110
newDecisions,
111111
commitCursor: async () => {
112-
commentCursors.set(prKey, maxCommentId);
113-
reviewCursors.set(prKey, maxReviewId);
114-
// #406: Persist cursor to TaskStore so restarts don't replay
112+
// #406: Persist first — if store fails, memory stays behind so gate retries
115113
await opts.taskStore.patchAutomationState(task.id, {
116114
review: {
117115
lastCommentCursor: maxCommentId,
118116
lastDecisionCursor: maxReviewId,
119117
lastNotifiedAt: Date.now(),
120118
},
121119
});
120+
commentCursors.set(prKey, maxCommentId);
121+
reviewCursors.set(prKey, maxReviewId);
122122
},
123123
},
124124
// #320 KD-15: unified subject_key format

0 commit comments

Comments
 (0)