Skip to content

Commit 184c4ed

Browse files
author
jetnet
committed
fix: guard tilldone nudge to prevent orphaned tool_result errors
Skip sendMessage nudge when conversation branch exceeds 150 messages to avoid 400 invalid_request_error from the API when context truncation drops the matching tool_use block. Addresses Issue disler#12.
1 parent 72d404a commit 184c4ed

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

extensions/tilldone.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,20 @@ export default function (pi: ExtensionAPI) {
368368

369369
nudgedThisCycle = true;
370370

371+
// Guard: avoid sending nudge if context is very large (>150 messages)
372+
// to prevent orphaned tool_result errors after context truncation.
373+
// The API rejects tool_result blocks whose matching tool_use was truncated.
374+
try {
375+
const branch = _ctx.sessionManager.getBranch();
376+
if (branch.length > 150) {
377+
// Too deep — skip the nudge to avoid 400 errors
378+
return;
379+
}
380+
} catch {
381+
// If we can't check, skip to be safe
382+
return;
383+
}
384+
371385
const taskList = incomplete
372386
.map((t) => ` ${STATUS_ICON[t.status]} #${t.id} [${STATUS_LABEL[t.status]}]: ${t.text}`)
373387
.join("\n");

0 commit comments

Comments
 (0)