@@ -248,7 +248,7 @@ export namespace SessionProcessor {
248248 type : "text" ,
249249 synthetic : true ,
250250 text :
251- `⚠️ altimate-code: session stopped — \`${ value . toolName } \` was called ${ totalCalls } + times, ` +
251+ `⚠️ altimate-code: session stopped — \`${ value . toolName } \` was called ${ totalCalls } times, ` +
252252 `indicating the agent is stuck in a loop. Please start a new session with a revised prompt.` ,
253253 time : { start : Date . now ( ) , end : Date . now ( ) } ,
254254 } )
@@ -270,9 +270,9 @@ export namespace SessionProcessor {
270270 messageID : input . assistantMessage . id ,
271271 sessionID : input . assistantMessage . sessionID ,
272272 type : "text" ,
273- // synthetic: false so the LLM actually sees this warning and can course-correct
273+ synthetic : false ,
274274 text :
275- `⚠️ altimate-code: \`${ value . toolName } \` has been called ${ totalCalls } + times this session. ` +
275+ `⚠️ altimate-code: \`${ value . toolName } \` has been called ${ totalCalls } times this session. ` +
276276 `You appear to be stuck in a loop. Stop repeating the same approach. ` +
277277 `Either try a fundamentally different strategy or explain to the user what is blocking you. ` +
278278 `The session will be force-stopped if this continues.` ,
@@ -281,6 +281,8 @@ export namespace SessionProcessor {
281281 }
282282
283283 // Escalation level 1: ask permission (existing behavior)
284+ // Reset before ask so denial/exception doesn't leave count at threshold
285+ toolCallCounts [ value . toolName ] = 0
284286 const agent = await Agent . get ( input . assistantMessage . agent )
285287 await PermissionNext . ask ( {
286288 permission : "doom_loop" ,
@@ -294,7 +296,6 @@ export namespace SessionProcessor {
294296 always : [ value . toolName ] ,
295297 ruleset : agent . permission ,
296298 } )
297- toolCallCounts [ value . toolName ] = 0
298299 }
299300 // altimate_change end
300301 }
0 commit comments