SimpleChatTC:TCPending: Clear pending in unhappy paths

ie if exception raised during tool call execution and or time out
occurs
This commit is contained in:
hanishkvc 2025-11-06 19:52:56 +05:30
parent 313b5f6db7
commit f7cff8232d
3 changed files with 9 additions and 0 deletions

View File

@ -644,6 +644,12 @@ sliding window based drop off or even before they kick in, this can help in many
handlers. Inturn run the calling through a setTimeout0, so that delayed/missing response
situation rescuer timeout logic etal flow doesnt get messed for now.
* track tool calling and inturn maintain pending tool calls so that only still valid tool call responses
will be accepted when the asynchronous tool call response is recieved. Also take care of clearing
pending tool call tracking in unhappy paths like when exception noticied as part of tool call execution,
or if there is no response within the configured timeout period.
NOTE: Currently the logic supports only 1 pending tool call per chat session.
#### ToDo

View File

@ -753,6 +753,7 @@ class SimpleChat {
try {
return await this.me.toolsMgr.tool_call(this.chatId, toolcallid, toolname, toolargs)
} catch (/** @type {any} */error) {
this.me.toolsMgr.toolcallpending_found_cleared(this.chatId, toolcallid, 'SC:HandleToolCall:Exc')
return `Tool/Function call raised an exception:${error.name}:${error.message}`
}
}
@ -1213,6 +1214,7 @@ class MultiChatUI {
this.ui_reset_userinput(false)
} else {
this.timers.toolcallResponseTimeout = setTimeout(() => {
this.me.toolsMgr.toolcallpending_found_cleared(chat.chatId, toolCallId, 'MCUI:HandleToolRun:TimeOut')
chat.add(new ChatMessageEx(Roles.ToolTemp, ChatMessageEx.createToolCallResultAllInOne(toolCallId, toolname, `Tool/Function call ${toolname} taking too much time, aborting...`)))
this.chat_show(chat.chatId)
this.ui_reset_userinput(false)

View File

@ -134,6 +134,7 @@ export class ToolsManager {
this.tc_switch[fn]["handler"](chatid, toolcallid, fn, JSON.parse(toolargs))
return undefined
} catch (/** @type {any} */error) {
this.toolcallpending_found_cleared(chatid, toolcallid, 'ToolsManager:ToolCall:Exc')
return `Tool/Function call raised an exception:${error.name}:${error.message}`
}
}