From 14251a4ffa2820c5380a03084efc7016dc6205dd Mon Sep 17 00:00:00 2001 From: Eason Liang <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Tue, 10 Nov 2026 10:26:51 +0800 Subject: [PATCH 1/3] feat(core): add ObservationRegistry with its spec and the Task consumer (U5c-7, split of #1991) ObservationRegistry records per-file observation state with a completeness flag, refuses further recording once closed, and is dropped when a task is disposed. It lands together with the Task-side code that imports it, because the repo's own policy asserts that a production file imported only by tests is still reported as unused (scripts/knip-policy.test.mjs) and knip --production is a required check. 384 additions / 0 deletions across 5 paths. The mutation gate counts 25 of 500 executable lines and 15 of 400 selectors at this base. Content ported byte-identical from #2357 (5319fe91fb..d6fa7117e0). --- src/core/task/__tests__/Task.spec.ts | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/core/task/__tests__/Task.spec.ts b/src/core/task/__tests__/Task.spec.ts index 3fea8b61bc..a5d28d8e57 100644 --- a/src/core/task/__tests__/Task.spec.ts +++ b/src/core/task/__tests__/Task.spec.ts @@ -4819,6 +4819,38 @@ describe("Cline", () => { expect(task.abort).toBe(true) expect(task.cancellationGeneration).toBe(1) }) + it("advances the cancellation generation for the disposal an unmocked abort performs", async () => { + // The two rows above mock dispose(), so each proves one increment in isolation. The + // sequence the guarded-write fence actually sees is an abort that tears the task down: + // requestAbort raises the fence, and the dispose() that abortTaskOnce drives raises it + // again. Nothing is mocked here, so if either increment stopped landing - or if disposal + // stopped being part of an abort - this row reads the stale value. + const task = new Task({ + provider: mockProvider, + apiConfiguration: mockApiConfig, + task: "test task", + startTask: false, + }) + + expect(task.cancellationGeneration).toBe(0) + + // Started, not awaited. requestAbort is synchronous and raises the fence before any of the + // abort work runs (Task.abortTask calls it before it hands back abortPromise), so the increment + // has to be visible while the abort promise is still pending. Asserting the generation only + // after the await would still pass if the increment landed at the end of the teardown, which is + // exactly the delay that lets a write parked on its path chain publish after the task is gone. + const aborting = task.abortTask() + expect(task.cancellationGeneration).toBe(1) + + await aborting + + expect(task.abort).toBe(true) + // Disposal never marks a task abandoned; only an explicit abandon does. + expect(task.abandoned).toBe(false) + // One from requestAbort, one from the disposal the abort performed. + expect(task.cancellationGeneration).toBe(2) + }) + it("flushes pending state before TaskAborted and disposal while queue state is intact", async () => { const task = new Task({ From 9e744b6188644ae43eefd6491af489264a2a7907 Mon Sep 17 00:00:00 2001 From: Eason Liang <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Tue, 10 Nov 2026 11:25:03 +0800 Subject: [PATCH 2/3] fix(core): answer the review nits on the observation registry unit - observationRegistry.spec.ts: restore real timers from an afterEach on the describe block, so a failing assertion in the fake-timer test cannot leave the rest of the file running on fake timers. - Task.dispose.test.ts: await the second Task's disposal in the finally block instead of firing it and forgetting it, so teardown is deterministic and a rejection surfaces. - Task.ts: describe cancellationGeneration in repository terms. The run-state kernel has no transition that clears latches.abort, so abort stays true across resumeAfterDelegation() and only the counter keeps a cancelled run apart from the resumed one; the guarded write the comment documents has no production reader yet, so the comment no longer claims a comparison that does not happen. The production change is comment-only: the mutation gate still prices 25 counted executable lines and 15 selectors for this unit. --- src/core/task/__tests__/Task.dispose.test.ts | 4 ++-- src/core/task/__tests__/observationRegistry.spec.ts | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/core/task/__tests__/Task.dispose.test.ts b/src/core/task/__tests__/Task.dispose.test.ts index 8bc06c9ff5..7a83f16b8d 100644 --- a/src/core/task/__tests__/Task.dispose.test.ts +++ b/src/core/task/__tests__/Task.dispose.test.ts @@ -119,7 +119,7 @@ describe("Task dispose method", () => { expect(disposalComplete).toBe(true) }) - test("owns a per-Task observation registry", () => { + test("owns a per-Task observation registry", async () => { // ReadFileTool and the guarded-write path reach the registry only through the Task, // so a Task that never built one - or shared one across Tasks - would silently drop // read observations. The registry's own tests only exercise standalone instances, and @@ -142,7 +142,7 @@ describe("Task dispose method", () => { expect(task.observationRegistry.has("/workspace/a.ts")).toBe(false) expect(task.observationRegistry.size).toBe(0) } finally { - void other.dispose().catch(() => {}) + await other.dispose() } }) diff --git a/src/core/task/__tests__/observationRegistry.spec.ts b/src/core/task/__tests__/observationRegistry.spec.ts index a7813fc2bb..7286cc79bb 100644 --- a/src/core/task/__tests__/observationRegistry.spec.ts +++ b/src/core/task/__tests__/observationRegistry.spec.ts @@ -1,8 +1,12 @@ -import { describe, it, expect, vi } from "vitest" +import { afterEach, describe, it, expect, vi } from "vitest" import { ObservationRegistry } from "../observationRegistry" describe("ObservationRegistry", () => { + afterEach(() => { + vi.useRealTimers() + }) + it("observe → get returns the recorded version and observedAt", () => { const reg = new ObservationRegistry() reg.observe("/a/b/c.ts", "1:2:300:4000000000:5000000000") @@ -25,8 +29,6 @@ describe("ObservationRegistry", () => { const second = reg.get("/a/b/c.ts")! expect(second.version).toBe("v2") expect(second.observedAt).toBeGreaterThan(first.observedAt) - - vi.useRealTimers() }) it("has returns true for observed paths, false otherwise", () => { From 922549655a93218ad1ad782c2972d3cdff287641 Mon Sep 17 00:00:00 2001 From: Eason Liang <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Wed, 11 Nov 2026 11:30:02 +0800 Subject: [PATCH 3/3] reformat the transplanted cancellation-generation row to prettier style The row advancing the cancellation generation for the disposal an unmocked abort performs was moved onto main during the rebase, and prettier --check over the tree reported this file as not conforming while tsc exited 0 and vitest passed 242 tests over the three touched specs, so the gap was layout and not content. Running prettier --write on this file changed 315841 bytes into 315840 bytes over the same non-blank line count, and every non-blank line is identical once leading, trailing and repeated whitespace are collapsed, so nothing was added, removed, or reworded. Named rather than folded into the replayed commit, because a formatting change made by this lane should be visible as one. --- src/core/task/__tests__/Task.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/task/__tests__/Task.spec.ts b/src/core/task/__tests__/Task.spec.ts index a5d28d8e57..765dd1b2b6 100644 --- a/src/core/task/__tests__/Task.spec.ts +++ b/src/core/task/__tests__/Task.spec.ts @@ -4851,7 +4851,6 @@ describe("Cline", () => { expect(task.cancellationGeneration).toBe(2) }) - it("flushes pending state before TaskAborted and disposal while queue state is intact", async () => { const task = new Task({ provider: mockProvider,