Skip to content

Commit 7209a5f

Browse files
easonLiangWorldedtecheasonLiangWorldedtech
authored andcommitted
Merge upstream main 5319fe9 into fws/u5-guard-core at d2b65a5
The only conflict was src/core/task/Task.ts. Main's side removed the `abort` boolean field and the `this.abort = true` assignments in requestAbort() and requestDispose(), because abort is now a getter reading the run-state reducer (abort(this.runState), abortReason likewise). The lane's side is the `cancellationGeneration` monotonic fence and its comments. Both sides are kept in the recorded order: main's field removal and getters are taken verbatim, and the lane's counter declaration and its increments in requestAbort() and requestDispose() sit on top of them. The lane comment inside requestAbort() was rewritten because it explained the abort flag being set at that line, which main's side no longer does. Adaptation the textual merge could not express: main's Task exposes abort as a getter, so it is read-only at a call site, and guardedWrite.spec.ts assigned task.abort at six places to park 'cancelled, then resumed' - abort raised, the generation advanced, abort cleared again. tsc reported all six as TS2540 once main's Task.ts was in the tree. They now go through one documented test-local helper that writes the pair on the double; no assertion changed, and the two sites that clear abort still clear it. main contains neither guardedWrite.ts nor its spec, so this file is lane-only and main's own tree never compiled it. Gates on the merged tree, pinned node 22.23.4: tsc --noEmit exit 0; eslint in the form lint-staged declares (--max-warnings=0 --no-warn-ignored) exit 0 on both edited files; pnpm format:check - prettier --check . at the repository root - exit 0. Shards: core 198 files / 4345 passed 9 skipped; misc 122 files / 2132 passed 19 skipped 1 file skipped; api 114 files / 4070 passed 2 skipped; services 5 failed 1685 passed; unit 5 failed 12569 passed 43 skipped, where those ten failures are the same services/rules/__tests__/rules.spec .ts rows that fail with EPERM on symlink creation on an untouched tree on this host. The merge also brought main's pnpm-lock.yaml. The src/eslint-suppressions.json blob stayed in main's canonical serialisation on both sides and in the merge result (30,910 bytes, newline-terminated, prettier --check clean), so this commit carries no re-serialised copy of it; the shard runs above used this worktree's existing junction install rather than a fresh install against the newly merged lockfile.
2 parents d2b65a5 + 5319fe9 commit 7209a5f

22 files changed

Lines changed: 159 additions & 81 deletions

‎apps/vscode-e2e/AGENTS.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,13 @@ The `model` field can be added to either match when a test targets a specific mo
140140
Use `streamingProfile: { ttft: <ms> }` on a fixture, not a flat `latency: <ms>`, when a test needs
141141
to simulate a slow or hung provider (e.g. to cancel an in-flight request mid-stream). `ttft` delays
142142
only the first SSE chunk, so the pending window is exactly the configured value. Flat `latency`
143-
delays _every_ chunk, and aimock never observes client disconnects — after a test cancels the
144-
request, a flat-latency stream keeps flushing chunks server-side for `chunks × latency` before
145-
reaching the dead socket, which can interleave with the next test's request against the same mock
146-
server. See `SUBTASK_API_HANG_RESPONSE_LATENCY_MS` in `fixtures/subtasks.ts` for an example,
147-
including the bounded post-test drain the calling suite uses to wait out that window.
143+
delays _every_ chunk. Before aimock 1.47.0, the mock did not observe client disconnects — after a
144+
test cancelled the request, a flat-latency stream kept flushing chunks server-side for
145+
`chunks × latency` before reaching the dead socket, which could interleave with the next test's
146+
request against the same mock server. Version 1.47.0 stops the reply on disconnect, but the
147+
suite keeps its drain wait until an e2e run shows it is not needed. See
148+
`SUBTASK_API_HANG_RESPONSE_LATENCY_MS` in `fixtures/subtasks.ts` for an example, including the
149+
bounded post-test drain the calling suite uses to wait out that window.
148150

149151
## 404 errors in logs are expected
150152

‎apps/vscode-e2e/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"@roo-code/config-eslint": "workspace:^",
2626
"@roo-code/config-typescript": "workspace:^",
2727
"@roo-code/types": "workspace:^",
28-
"@copilotkit/aimock": "1.35.0",
28+
"@copilotkit/aimock": "1.47.0",
2929
"@types/mocha": "10.0.10",
3030
"@types/node": "catalog:",
3131
"@types/vscode": "1.100.0",

‎apps/vscode-e2e/src/suite/subtasks.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@ const waitForAimockRequestContaining = async (
9393
// suite becomes flaky again on slow CI runners, widen this value first.
9494
const SUBTASK_API_HANG_DRAIN_GRACE_MS = 500
9595

96-
// aimock does not observe client disconnects: after the API-hang child request is cancelled,
97-
// the mock keeps the delayed stream pending server-side until the fixture's ttft has fully
98-
// elapsed, then flushes the remaining chunks to the dead socket. A streamed request opened by
99-
// the next test can interleave with that late flush, so wait out the remainder of the delayed
96+
// aimock 1.47.0 stops and journals a reply when the client disconnects. Before that, the mock
97+
// kept the delayed stream pending server-side until the fixture's ttft had fully elapsed, then
98+
// flushed the remaining chunks to the dead socket. A streamed request opened by the next test
99+
// could interleave with that late flush. This wait is a conservative guard kept until an e2e
100+
// run shows it is not needed: wait out the remainder of the delayed
100101
// window before the next test runs. The deadline is anchored to the journal timestamp of the
101102
// request this test created (never earlier traffic), and bounded by one latency window plus
102103
// grace, so it cannot hide a genuine hang.

‎pnpm-lock.yaml‎

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/core/task/Task.ts‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ import { mergeConsecutiveApiMessages } from "./mergeConsecutiveApiMessages"
145145
import { prepareApiConversationMessage } from "./apiConversationHistory"
146146
import { shouldAddUserMessageToHistory } from "./messageCounting"
147147
import { type TaskExecutionContext } from "./providerHandoff"
148-
import { initialRunState, type Ask, type RunEvent, type RunState } from "./run-state/runState"
148+
import { abort, abortReason, initialRunState, type Ask, type RunEvent, type RunState } from "./run-state/runState"
149149
import { applyRunEvent, type RunRejection } from "./run-state/runStateShadow"
150150
import {
151151
divergenceKey,
@@ -397,7 +397,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
397397

398398
providerRef: WeakRef<ClineProvider>
399399
private readonly globalStoragePath: string
400-
abort: boolean = false
401400
// Monotonic cancellation counter. `requestAbort()` and `requestDispose()` advance
402401
// this fence, and the guarded-write path compares the value it captured when the
403402
// write was queued with the value at publish time, so a queued write cannot publish
@@ -420,7 +419,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
420419

421420
didFinishAbortingStream = false
422421
abandoned = false
423-
abortReason?: ClineApiReqCancelReason
424422
isInitialized = false
425423

426424
runState: RunState = initialRunState
@@ -3591,23 +3589,28 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
35913589
this.driveRunEvent({ tag: "completionAccepted", askTs })
35923590
}
35933591

3592+
get abort(): boolean {
3593+
return abort(this.runState)
3594+
}
3595+
3596+
get abortReason(): ClineApiReqCancelReason | undefined {
3597+
return abortReason(this.runState)
3598+
}
3599+
35943600
setAbortReason(reason: ClineApiReqCancelReason): void {
3595-
this.abortReason ??= reason
35963601
this.driveRunEvent({ tag: "reasonSet", reason })
35973602
}
35983603

35993604
requestAbort(isAbandoned: boolean): void {
36003605
if (isAbandoned) {
36013606
this.abandoned = true
36023607
}
3603-
this.abort = true
36043608
// The S4a write guard compares this counter with the value a queued write
36053609
// captured when it started, so every cancellation must advance it and it
3606-
// must never go backwards: the abort flag is set here and no resume path
3607-
// clears it, so on a resumed task it only says that some cancellation
3608-
// happened - never WHICH cancellation a queued write belongs to. Only the
3609-
// generation keeps a cancelled run's queued writes apart from the
3610-
// resumed run's, and only if it advances monotonically.
3610+
// must never go backwards. Main moved the abort flag into the run-state
3611+
// reducer (see the abort(this.runState) getter above), so this counter is
3612+
// the only thing left that separates a cancelled run's queued writes from
3613+
// the resumed run's, and only if it advances monotonically.
36113614
this.cancellationGeneration++
36123615
this.driveRunEvent({ tag: "abortRequested", abandoned: isAbandoned })
36133616
}
@@ -3618,7 +3621,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
36183621
}
36193622

36203623
requestDispose(): void {
3621-
this.abort = true
36223624
// A host teardown never calls abortTask(): disposal has to raise the same
36233625
// counter, or a write still parked on its path chain publishes after the
36243626
// task is gone.

‎src/core/task/__tests__/Task.persistence.spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ContextProxy } from "../../config/ContextProxy"
2121
import { providerIdentifiers } from "@roo-code/types/provider-identifiers"
2222
import { attemptCompletionTool, type AttemptCompletionCallbacks } from "../../tools/AttemptCompletionTool"
2323
import type { ToolUse } from "../../../shared/tools"
24+
import { setAbortLatch } from "../../../test-utils/run-state"
2425

2526
type TaskPersistenceAccess = {
2627
addToApiConversationHistory: (message: Anthropic.MessageParam) => Promise<void>
@@ -909,7 +910,7 @@ describe("Task persistence", () => {
909910
task: "test task",
910911
startTask: false,
911912
})
912-
task.abort = true
913+
setAbortLatch(task, true)
913914
task.userMessageContent = [{ type: "tool_result", tool_use_id: "tool-1", content: "done" }]
914915
const waitForPersistence = vi.spyOn(task, "waitForCurrentAssistantMessagePersistence")
915916

‎src/core/task/__tests__/Task.run-shadow.spec.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ describe("Task run-state write helpers", () => {
101101
task.requestAbort(false)
102102

103103
expect([task.abort, task.abandoned]).toEqual([true, false])
104-
expect(task.runState.latches).toMatchObject({ abort: true, abandoned: false })
104+
expect(task.runState.latches.abandoned).toBe(false)
105105
})
106106

107107
it("requestAbort(true) sets abort and abandoned", () => {
108108
task.requestAbort(true)
109109

110110
expect([task.abort, task.abandoned]).toEqual([true, true])
111-
expect(task.runState.latches).toMatchObject({ abort: true, abandoned: true })
111+
expect(task.runState.latches.abandoned).toBe(true)
112112
})
113113

114114
it("requestAbandon sets abandoned after an abort", () => {
@@ -124,7 +124,7 @@ describe("Task run-state write helpers", () => {
124124
task.requestDispose()
125125

126126
expect(task.abort).toBe(true)
127-
expect(task.runState.latches).toMatchObject({ abort: true, disposed: true })
127+
expect(task.runState.latches.disposed).toBe(true)
128128
})
129129

130130
it("drives the ask events", () => {
@@ -149,12 +149,15 @@ describe("Task run-state write helpers", () => {
149149
expect(task.runRejections).toEqual([{ event: { tag: "abandonRequested" }, state: initialRunState }])
150150
})
151151

152-
it("keeps the first abort reason in the field and in the kernel", () => {
152+
it("has no abort reason before one is set", () => {
153+
expect(task.abortReason).toBeUndefined()
154+
})
155+
156+
it("keeps the first abort reason", () => {
153157
task.setAbortReason("user_cancelled")
154158
task.setAbortReason("streaming_failed")
155159

156160
expect(task.abortReason).toBe("user_cancelled")
157-
expect(task.runState.latches.reason).toBe("user_cancelled")
158161
expect(task.runRejections).toEqual([])
159162
})
160163
})

‎src/core/task/__tests__/Task.spec.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ vi.mock("delay", () => ({
9999

100100
import delay from "delay"
101101
import pWaitFor from "p-wait-for"
102+
import { setAbortLatch } from "../../../test-utils/run-state"
102103

103104
vi.mock("uuid", async (importOriginal) => {
104105
const actual = await importOriginal<typeof import("uuid")>()
@@ -1071,7 +1072,7 @@ describe("Cline", () => {
10711072
const saySpy = vi.spyOn(task, "say").mockImplementation(async (...args) => {
10721073
const [type, _text, _images, partial] = args
10731074
if (type === "text" && partial === false) {
1074-
task.abort = true
1075+
setAbortLatch(task, true)
10751076
throw new Error("presenter text failed while aborting")
10761077
}
10771078
return say(...args)
@@ -4973,7 +4974,7 @@ describe("Cline", () => {
49734974
const abortTaskSpy = vi.spyOn(task, "abortTask").mockResolvedValue(undefined)
49744975

49754976
// Test Case 1: Stream failure should NOT abort task
4976-
task.abort = false
4977+
setAbortLatch(task, false)
49774978
task.abandoned = false
49784979

49794980
// Simulate the catch block behavior for stream failure
@@ -4994,7 +4995,7 @@ describe("Cline", () => {
49944995
expect(abortTaskSpy).not.toHaveBeenCalled()
49954996

49964997
// Test Case 2: User cancellation SHOULD abort task
4997-
task.abort = true
4998+
setAbortLatch(task, true)
49984999

49995000
// For user cancellation, abortTask SHOULD be called
50005001
if (task.abort) {
@@ -7395,7 +7396,7 @@ describe("Cline", () => {
73957396
await flushMicrotasks()
73967397
consoleErrorSpy.mockClear()
73977398

7398-
task.abort = true
7399+
setAbortLatch(task, true)
73997400
getTaskTestAccess(task).presentAssistantMessageSafe()
74007401
await flushMicrotasks()
74017402

@@ -7449,7 +7450,7 @@ describe("Cline", () => {
74497450
consoleErrorSpy.mockClear()
74507451

74517452
// Simulate the TOCTOU race: abort flips between throw and catch.
7452-
task.abort = true
7453+
setAbortLatch(task, true)
74537454
getTaskTestAccess(task).presentAssistantMessageSafe()
74547455
await flushMicrotasks()
74557456

‎src/core/task/__tests__/ask-abort-race.spec.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ClineMessage } from "@roo-code/types"
33
import { checkAutoApproval } from "../../auto-approval"
44
import { MessageQueueService } from "../../message-queue/MessageQueueService"
55
import { Task } from "../Task"
6+
import { setAbortLatch } from "../../../test-utils/run-state"
67

78
vi.mock("../../auto-approval", async (importOriginal) => {
89
const actual = await importOriginal<typeof import("../../auto-approval")>()
@@ -11,7 +12,7 @@ vi.mock("../../auto-approval", async (importOriginal) => {
1112

1213
function buildTask(getState: () => Promise<Record<string, unknown>>) {
1314
const task = Object.create(Task.prototype) as Task
14-
task["abort"] = false
15+
setAbortLatch(task, false)
1516
task["clineMessages"] = []
1617
task["lastMessageTs"] = undefined
1718
task["addToClineMessages"] = vi.fn(async () => {})
@@ -44,7 +45,7 @@ describe("Task.ask abort during the auto-approval await", () => {
4445
})
4546

4647
const askPromise = task.ask("tool", JSON.stringify({ tool: "readFile" }), partial)
47-
task["abort"] = true
48+
setAbortLatch(task, true)
4849
gate.release()
4950

5051
await expect(askPromise).rejects.toThrow(/aborted/)
@@ -62,7 +63,7 @@ describe("Task.ask abort during the auto-approval await", () => {
6263

6364
const askPromise = task.ask("tool", JSON.stringify({ tool: "readFile" }), false)
6465
await vi.waitFor(() => expect(checkAutoApproval).toHaveBeenCalled())
65-
task["abort"] = true
66+
setAbortLatch(task, true)
6667
gate.release()
6768

6869
await expect(askPromise).rejects.toThrow(/aborted/)
@@ -83,7 +84,7 @@ describe("Task.ask abort during the auto-approval await", () => {
8384
task["clineMessages"] = [{ ...original }]
8485

8586
const askPromise = task.ask("followup", "new", partial)
86-
task["abort"] = true
87+
setAbortLatch(task, true)
8788
gate.release()
8889

8990
await expect(askPromise).rejects.toThrow(/aborted/)
@@ -102,7 +103,7 @@ describe("Task.ask abort during the auto-approval await", () => {
102103
task.messageQueueService.addMessage("queued feedback")
103104

104105
const askPromise = task.ask("followup", "Q?", false)
105-
task["abort"] = true
106+
setAbortLatch(task, true)
106107
gate.release()
107108

108109
await expect(askPromise).rejects.toThrow(/aborted/)

‎src/core/task/__tests__/ask-allowlist-cwd.spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import type { ExtensionState } from "@roo-code/types"
44

55
import { Task } from "../Task"
6+
import { setAbortLatch } from "../../../test-utils/run-state"
67

78
// The allowlist patterns are resolved against a workspace root, and the path in
89
// the tool message was made relative by `getReadablePath(task.cwd, ...)`. So the
@@ -23,7 +24,7 @@ type ProviderStub = {
2324

2425
function buildTask(provider: ProviderStub, taskCwd: string) {
2526
const task = Object.create(Task.prototype) as Task
26-
task["abort"] = false
27+
setAbortLatch(task, false)
2728
task["clineMessages"] = []
2829
task["askResponse"] = undefined
2930
task["askResponseText"] = undefined

0 commit comments

Comments
 (0)