Skip to content

Commit 9af61f8

Browse files
authored
refactor(task): remove dead Task.isPaused field (RSK-12) (#1894)
* refactor(task): remove dead isPaused field (RSK-12) * test(task): cover request continuation and update lifecycle doc
1 parent 1368407 commit 9af61f8

6 files changed

Lines changed: 60 additions & 33 deletions

File tree

‎docs/architecture/task-lifecycle-target-architecture.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The bugs come from the runtime layer and from state that escapes the checked red
6161

6262
### Run state is a set of loose booleans
6363

64-
`Task` models mutually exclusive run phases with independent flags. Examples: `abort`, `didFinishAbortingStream`, `isInitialized`, `isPaused`, `isWaitingForFirstChunk`, `isStreaming`, `didRejectTool`, `didAlreadyUseTool`, `didToolFailInCurrentTurn`, `didCompleteReadingStream`. Dispatch re-entrancy uses `presentAssistantMessageLocked` and `presentAssistantMessageHasPendingUpdates`.
64+
`Task` models mutually exclusive run phases with independent flags. Examples: `abort`, `didFinishAbortingStream`, `isInitialized`, `isWaitingForFirstChunk`, `isStreaming`, `didRejectTool`, `didAlreadyUseTool`, `didToolFailInCurrentTurn`, `didCompleteReadingStream`. Dispatch re-entrancy uses `presentAssistantMessageLocked` and `presentAssistantMessageHasPendingUpdates`.
6565

6666
N independent booleans admit 2^N representable states. Only a few are legal. The type system cannot reject the rest. Some combinations are legal phases. For example, `abort` and `isStreaming` are both true during the graceful drain window (`Task.ts:2685, 3484, 3756`). The type system cannot tell a legal combination from an illegal one. The one flag-combination defect with a source is the duplicated render state in #325.
6767

‎src/__tests__/new-task-delegation.spec.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ describe("Task.startSubtask() metadata-driven delegation", () => {
3131
})
3232
expect(child.taskId).toBe("child-1")
3333

34-
// Parent should not be paused and no paused/unpaused events should be emitted
35-
expect((parent as any).isPaused).not.toBe(true)
34+
// No paused/unpaused events should be emitted
3635
expect((parent as any).childTaskId).toBeUndefined()
3736
const emittedEvents = (parent.emit as any).mock.calls.map((c: any[]) => c[0])
3837
expect(emittedEvents).not.toContain(RooCodeEventName.TaskPaused)

‎src/core/task/Task.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
402402
abandoned = false
403403
abortReason?: ClineApiReqCancelReason
404404
isInitialized = false
405-
isPaused: boolean = false
406405

407406
// API
408407
apiConfiguration: ProviderSettings
@@ -4688,9 +4687,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
46884687
this.consecutiveNoToolUseCount = 0
46894688
}
46904689

4691-
// Push to stack if there's content OR if we're paused waiting for a subtask.
4692-
// When paused, we push an empty item so the loop continues to the pause check.
4693-
if (this.userMessageContent.length > 0 || this.isPaused) {
4690+
if (this.userMessageContent.length > 0) {
46944691
stack.push({
46954692
userContent: [...this.userMessageContent], // Create a copy to avoid mutation issues
46964693
includeFileDetails: false, // Subsequent iterations don't need file details

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

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -444,30 +444,30 @@ describe("Cline", () => {
444444
baseProviderState = await mockProvider.getState()
445445
})
446446

447-
describe("empty-response retries", () => {
448-
function stream(chunks: ApiStreamChunk[]): AsyncGenerator<ApiStreamChunk> {
449-
return (async function* () {
450-
yield* chunks
451-
})()
452-
}
447+
function stream(chunks: ApiStreamChunk[]): AsyncGenerator<ApiStreamChunk> {
448+
return (async function* () {
449+
yield* chunks
450+
})()
451+
}
453452

454-
async function createTaskWithManualRetries() {
455-
const task = new Task({
456-
provider: mockProvider,
457-
apiConfiguration: mockApiConfig,
458-
task: "test task",
459-
startTask: false,
460-
})
461-
const state = await mockProvider.getState()
462-
vi.spyOn(mockProvider, "getState").mockResolvedValue({
463-
...state,
464-
apiConfiguration: mockApiConfig,
465-
autoApprovalEnabled: false,
466-
})
467-
vi.spyOn(task.diffViewProvider, "reset").mockResolvedValue(undefined)
468-
return task
469-
}
453+
async function createTaskWithManualRetries() {
454+
const task = new Task({
455+
provider: mockProvider,
456+
apiConfiguration: mockApiConfig,
457+
task: "test task",
458+
startTask: false,
459+
})
460+
const state = await mockProvider.getState()
461+
vi.spyOn(mockProvider, "getState").mockResolvedValue({
462+
...state,
463+
apiConfiguration: mockApiConfig,
464+
autoApprovalEnabled: false,
465+
})
466+
vi.spyOn(task.diffViewProvider, "reset").mockResolvedValue(undefined)
467+
return task
468+
}
470469

470+
describe("empty-response retries", () => {
471471
it("restores the user message before a confirmed empty-response retry", async () => {
472472
const task = await createTaskWithManualRetries()
473473
let retryHistory: ApiMessage[] | undefined
@@ -521,6 +521,40 @@ describe("Cline", () => {
521521
})
522522
})
523523

524+
describe("request continuation", () => {
525+
it("sends the no-tool-use reminder in a second request when the first response has no tool use", async () => {
526+
const task = await createTaskWithManualRetries()
527+
let secondRequestHistory: ApiMessage[] | undefined
528+
529+
const attemptApiRequestSpy = vi
530+
.spyOn(task, "attemptApiRequest")
531+
.mockImplementationOnce(() => stream([{ type: "text", text: "no tool here" }]))
532+
.mockImplementationOnce(() => {
533+
secondRequestHistory = structuredClone(task.apiConversationHistory)
534+
throw new Error("stop after continuation request")
535+
})
536+
537+
await task.recursivelyMakeClineRequests([{ type: "text", text: "original user request" }])
538+
539+
expect(attemptApiRequestSpy).toHaveBeenCalledTimes(2)
540+
expect(secondRequestHistory).toMatchObject([
541+
{
542+
role: "user",
543+
content: expect.arrayContaining([expect.objectContaining({ text: "original user request" })]),
544+
},
545+
{ role: "assistant", content: [{ type: "text", text: "no tool here" }] },
546+
{
547+
role: "user",
548+
content: expect.arrayContaining([
549+
expect.objectContaining({
550+
text: expect.stringContaining("You did not use a tool in your previous response"),
551+
}),
552+
]),
553+
},
554+
])
555+
})
556+
})
557+
524558
describe("output token limit mid-stream", () => {
525559
async function* truncatedStream(): AsyncGenerator<ApiStreamChunk> {
526560
yield { type: "text", text: "partial answer" }

‎src/core/tools/__tests__/newTaskTool.spec.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ const mockCline = {
9191
emit: mockEmit,
9292
recordToolError: mockRecordToolError,
9393
consecutiveMistakeCount: 0,
94-
isPaused: false,
9594
pausedModeSlug: "ask",
9695
taskId: "mock-parent-task-id",
9796
enableCheckpoints: false,
@@ -135,7 +134,6 @@ describe("newTaskTool", () => {
135134
groups: ["command", "read", "edit"],
136135
}) // Default valid mode
137136
mockCline.consecutiveMistakeCount = 0
138-
mockCline.isPaused = false
139137
// Default: VSCode setting is disabled
140138
const mockGet = vi.fn().mockReturnValue(false)
141139
vi.mocked(vscode.workspace.getConfiguration).mockReturnValue({
@@ -593,7 +591,6 @@ describe("newTaskTool delegation flow", () => {
593591
emit: localEmit,
594592
recordToolError: mockRecordToolError,
595593
consecutiveMistakeCount: 0,
596-
isPaused: false,
597594
pausedModeSlug: "ask",
598595
taskId: "mock-parent-task-id",
599596
setPendingTaskAction: vi.fn(),

‎src/eslint-suppressions.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
"__tests__/new-task-delegation.spec.ts": {
4848
"@typescript-eslint/no-explicit-any": {
49-
"count": 9
49+
"count": 8
5050
}
5151
},
5252
"activate/CodeActionProvider.ts": {

0 commit comments

Comments
 (0)