From ad90c9dcc1af360f80a52a3947e62f0768817ca6 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Thu, 19 Mar 2026 10:47:20 -0700 Subject: [PATCH] Fix race condition in stale review flag self-healing Reload fresh state before saving to avoid overwriting concurrent changes from other processes between the initial load and the heal write. Co-Authored-By: Claude Opus 4.6 --- src/commands/list.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/commands/list.ts b/src/commands/list.ts index f2743d1..a08eb9b 100644 --- a/src/commands/list.ts +++ b/src/commands/list.ts @@ -59,10 +59,16 @@ export async function action(opts: { json?: boolean }) { ) const statuses = Object.fromEntries(statusEntries) - // Batch self-heal stale in_review flags with a single state write + // Batch self-heal stale in_review flags — reload fresh state to avoid overwriting concurrent changes if (staleReviewSessions.length > 0) { for (const s of staleReviewSessions) s.in_review = false - await state.save(root, st).catch(() => {}) + const fresh = await state.load(root).catch(() => null) + if (fresh) { + for (const s of staleReviewSessions) { + if (fresh.sessions[s.branch]) fresh.sessions[s.branch].in_review = false + } + await state.save(root, fresh).catch(() => {}) + } } if (opts.json) {