diff --git a/src/commands/list.ts b/src/commands/list.ts index eb8c839..71413ce 100644 --- a/src/commands/list.ts +++ b/src/commands/list.ts @@ -61,13 +61,13 @@ export async function action(opts: { json?: boolean }) { ) const statuses = Object.fromEntries(statusEntries) - // Batch-clear stale in_review flags in a single write - if (staleReviewBranches.length > 0) { - const freshState = await state.load(root) - for (const branch of staleReviewBranches) { - if (freshState.sessions[branch]) freshState.sessions[branch].in_review = false + // Clear stale in_review flags via setSession to avoid clobbering concurrent writes + for (const branch of staleReviewBranches) { + const fresh = await state.getSession(root, branch) + if (fresh) { + fresh.in_review = false + await state.setSession(root, fresh).catch(() => {}) } - await state.save(root, freshState).catch(() => {}) } if (opts.json) { diff --git a/src/commands/review.ts b/src/commands/review.ts index 56ae0f2..faf6560 100644 --- a/src/commands/review.ts +++ b/src/commands/review.ts @@ -69,7 +69,7 @@ Your thoughts, in brief. if (extra) prompt += "\n\n" + extra session.in_review = true - await state.setSession(root, session).catch(() => {}) + await state.setSession(root, session) try { if (opts.print) { @@ -82,8 +82,12 @@ Your thoughts, in brief. } } finally { spin.stop() - session.in_review = false - await state.setSession(root, session).catch(() => {}) + // Load fresh session to avoid clobbering changes made during the review + const fresh = await state.getSession(root, session.branch) + if (fresh) { + fresh.in_review = false + await state.setSession(root, fresh).catch(() => {}) + } if (!opts.print) await saveChanges(session.worktree, session.branch).catch(() => {}) } }