Skip to content

Commit d67a85a

Browse files
committed
Throttle calls to calculate task folder size
1 parent a08461a commit d67a85a

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

.changeset/twenty-planes-prove.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Throttle calls to calculate task folder size

src/core/Cline.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ export class Cline extends EventEmitter<ClineEvents> {
374374
this.emit("message", { action: "updated", message: partialMessage })
375375
}
376376

377+
private taskDirSize = 0
378+
private taskDirSizeCheckedAt = 0
379+
private readonly taskDirSizeCheckInterval = 30_000
380+
377381
private async saveClineMessages() {
378382
try {
379383
const taskDir = await this.ensureTaskDirectoryExists()
@@ -393,14 +397,16 @@ export class Cline extends EventEmitter<ClineEvents> {
393397
)
394398
]
395399

396-
let taskDirSize = 0
400+
if (Date.now() - this.taskDirSizeCheckedAt > this.taskDirSizeCheckInterval) {
401+
this.taskDirSizeCheckedAt = Date.now()
397402

398-
try {
399-
taskDirSize = await getFolderSize.loose(taskDir)
400-
} catch (err) {
401-
console.error(
402-
`[saveClineMessages] failed to get task directory size (${taskDir}): ${err instanceof Error ? err.message : String(err)}`,
403-
)
403+
try {
404+
this.taskDirSize = await getFolderSize.loose(taskDir)
405+
} catch (err) {
406+
console.error(
407+
`[saveClineMessages] failed to get task directory size (${taskDir}): ${err instanceof Error ? err.message : String(err)}`,
408+
)
409+
}
404410
}
405411

406412
await this.providerRef.deref()?.updateTaskHistory({
@@ -413,7 +419,7 @@ export class Cline extends EventEmitter<ClineEvents> {
413419
cacheWrites: tokenUsage.totalCacheWrites,
414420
cacheReads: tokenUsage.totalCacheReads,
415421
totalCost: tokenUsage.totalCost,
416-
size: taskDirSize,
422+
size: this.taskDirSize,
417423
workspace: this.cwd,
418424
})
419425
} catch (error) {
@@ -1064,10 +1070,13 @@ export class Cline extends EventEmitter<ClineEvents> {
10641070
const DEFAULT_THINKING_MODEL_MAX_TOKENS = 16_384
10651071

10661072
const modelInfo = this.api.getModel().info
1073+
10671074
const maxTokens = modelInfo.thinking
10681075
? this.apiConfiguration.modelMaxTokens || DEFAULT_THINKING_MODEL_MAX_TOKENS
10691076
: modelInfo.maxTokens
1077+
10701078
const contextWindow = modelInfo.contextWindow
1079+
10711080
const trimmedMessages = await truncateConversationIfNeeded({
10721081
messages: this.apiConversationHistory,
10731082
totalTokens,
@@ -1896,11 +1905,13 @@ export class Cline extends EventEmitter<ClineEvents> {
18961905
// now add to apiconversationhistory
18971906
// need to save assistant responses to file before proceeding to tool use since user can exit at any moment and we wouldn't be able to save the assistant's response
18981907
let didEndLoop = false
1908+
18991909
if (assistantMessage.length > 0) {
19001910
await this.addToApiConversationHistory({
19011911
role: "assistant",
19021912
content: [{ type: "text", text: assistantMessage }],
19031913
})
1914+
19041915
telemetryService.captureConversationMessage(this.taskId, "assistant")
19051916

19061917
// NOTE: this comment is here for future reference - this was a workaround for userMessageContent not getting set to true. It was due to it not recursively calling for partial blocks when didRejectTool, so it would get stuck waiting for a partial block to complete before it could continue.

0 commit comments

Comments
 (0)