diff --git a/src/client/TaskWindow.tsx b/src/client/TaskWindow.tsx index 5eedf8cf..5a7a8545 100644 --- a/src/client/TaskWindow.tsx +++ b/src/client/TaskWindow.tsx @@ -314,15 +314,11 @@ export function TaskWindow(props: TaskWindowProps): ReactNode { // by itself. } else { if (result.code === CONFLICT_CODE) { - // A stale-revision write is rejected WITHOUT advancing the revision, - // so the snapshot is still behind. Re-base it to the projection's - // latest revision only when that has already moved past the rejected - // one (read the render-time mirror, not the `task` this closure - // captured); otherwise leave the mark for the effect above, which - // takes the projection's next revision. The conflict note stays up, - // the draft and editing stay put, and the reader's NEXT Save submits - // against the new base (an explicit "overwrite anyway"). Exiting here - // would lose the draft. + // A stale write is rejected WITHOUT advancing the revision. Use the + // mirror once it has overtaken the rejected one; until then the effect + // above takes the projection's next revision. The note, the draft and + // editing stay put (exiting would lose the draft), and the next Save + // submits against the new base — an explicit "overwrite anyway". const submitted = editRevisionRef.current ?? task?.revision const latest = latestRevisionRef.current if (submitted !== undefined) { @@ -422,13 +418,9 @@ export function TaskWindow(props: TaskWindowProps): ReactNode { size="sm" icon={} onClick={() => { - // Draft and CAS base must come from the SAME read: the - // projection may have moved on while this window sat in the - // view, and saving the older text against the newer base is - // the silent overwrite this snapshot exists to prevent. + // Draft and CAS base from the same read (see editRevisionRef), + // so a pending conflict re-base has nothing left to correct. editRevisionRef.current = task.revision - // Re-opening seeds the draft from the same read, so a - // pending conflict re-base has nothing left to correct. staleFromRef.current = undefined setSubject(task.subject) setDescription(task.description) diff --git a/tests/search-engines.spec.ts b/tests/search-engines.spec.ts index 2bfac4fd..61127416 100644 --- a/tests/search-engines.spec.ts +++ b/tests/search-engines.spec.ts @@ -466,6 +466,7 @@ describe('bundledRgCandidates', () => { describe('probe cache and failure handling', () => { afterEach(() => { + vi.useRealTimers() resetEngines() }) @@ -587,20 +588,16 @@ describe('probe cache and failure handling', () => { // EMFILE burst) used to cost the fast path for the rest of the session. it('retries a disabled engine once the cooldown elapses', async () => { vi.useFakeTimers() - try { - vi.setSystemTime(0) - setEngineHooks({ prober: async () => [fdProbe, rgProbe] }) - setEngineHooks({ runner: async () => { throw new Error('boom') } }) - for (let i = 0; i < 3; i += 1) { - await runEngine(fdProbe, '/w', 'x', 10).catch(() => {}) - } - expect((await usableEngines()).map(probe => probe.engine)).toEqual(['rg']) - - vi.setSystemTime(60_000) - expect((await usableEngines()).map(probe => probe.engine)).toEqual(['fd', 'rg']) - } finally { - vi.useRealTimers() + vi.setSystemTime(0) + setEngineHooks({ prober: async () => [fdProbe, rgProbe] }) + setEngineHooks({ runner: async () => { throw new Error('boom') } }) + for (let i = 0; i < 3; i += 1) { + await runEngine(fdProbe, '/w', 'x', 10).catch(() => {}) } + expect((await usableEngines()).map(probe => probe.engine)).toEqual(['rg']) + + vi.setSystemTime(60_000) + expect((await usableEngines()).map(probe => probe.engine)).toEqual(['fd', 'rg']) }) })