fix: prevent bot ping-pong in implicit continuation window
Exclude is_bot_message from implicit continuation trigger check. Previously, bot A's response would trigger bot B's continuation window, causing infinite back-and-forth responses. Also: tool activity sub-lines use description over summary, and max activities reduced to 2.
This commit is contained in:
@@ -555,20 +555,12 @@ async function runQuery(
|
||||
const tp = message as Record<string, unknown>;
|
||||
const summary = typeof tp.summary === 'string' ? tp.summary : '';
|
||||
const description = typeof tp.description === 'string' ? tp.description : '';
|
||||
if (summary) {
|
||||
log(`Subagent progress: ${summary.slice(0, 200)}`);
|
||||
writeOutput({
|
||||
status: 'success',
|
||||
phase: 'progress',
|
||||
result: summary,
|
||||
newSessionId,
|
||||
});
|
||||
}
|
||||
if (description) {
|
||||
const activityText = description || summary;
|
||||
if (activityText) {
|
||||
writeOutput({
|
||||
status: 'success',
|
||||
phase: 'tool-activity',
|
||||
result: description,
|
||||
result: activityText,
|
||||
newSessionId,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -44,7 +44,9 @@ export function createImplicitContinuationTracker(idleTimeout: number) {
|
||||
implicitContinuationUntil.delete(chatJid);
|
||||
return false;
|
||||
}
|
||||
return messages.some((message) => message.is_from_me !== true);
|
||||
return messages.some(
|
||||
(message) => message.is_from_me !== true && !message.is_bot_message,
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -228,11 +228,16 @@ export class MessageTurnController {
|
||||
if (minutes > 0) elapsedParts.push(`${minutes}분`);
|
||||
elapsedParts.push(`${seconds}초`);
|
||||
|
||||
const activityLines = this.toolActivities.length > 0
|
||||
? '\n' + this.toolActivities.map((a) => `├ ${a}`).join('\n')
|
||||
: '';
|
||||
const activityLines =
|
||||
this.toolActivities.length > 0
|
||||
? '\n' + this.toolActivities.map((a) => `├ ${a}`).join('\n')
|
||||
: '';
|
||||
const suffix = `\n\n${elapsedParts.join(' ')}`;
|
||||
const maxText = 2000 - TASK_STATUS_MESSAGE_PREFIX.length - activityLines.length - suffix.length;
|
||||
const maxText =
|
||||
2000 -
|
||||
TASK_STATUS_MESSAGE_PREFIX.length -
|
||||
activityLines.length -
|
||||
suffix.length;
|
||||
const truncated =
|
||||
text.length > maxText ? text.slice(0, maxText - 1) + '…' : text;
|
||||
return `${TASK_STATUS_MESSAGE_PREFIX}${truncated}${activityLines}${suffix}`;
|
||||
@@ -265,16 +270,16 @@ export class MessageTurnController {
|
||||
private bufferProgress(text: string): void {
|
||||
if (this.pendingProgressText) {
|
||||
void this.sendProgressMessage(this.pendingProgressText);
|
||||
this.toolActivities = [];
|
||||
}
|
||||
this.pendingProgressText = text;
|
||||
this.toolActivities = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a tool activity line and update the progress message in-place.
|
||||
*/
|
||||
private addToolActivity(description: string): void {
|
||||
const MAX_ACTIVITIES = 5;
|
||||
const MAX_ACTIVITIES = 2;
|
||||
this.toolActivities.push(description);
|
||||
if (this.toolActivities.length > MAX_ACTIVITIES) {
|
||||
this.toolActivities = this.toolActivities.slice(-MAX_ACTIVITIES);
|
||||
|
||||
Reference in New Issue
Block a user