Merge pull request #1252 from buster-so/fixCutOffResponseMessage

Temporary solution to fix response message being cut off
This commit is contained in:
wellsbunk5 2025-10-03 02:17:51 -06:00 committed by GitHub
commit 977f5f0f35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 14 deletions

View File

@ -90,6 +90,8 @@ export function createDoneToolExecute(context: DoneToolContext, state: DoneToolS
} }
state.isFinalizing = true; state.isFinalizing = true;
// Part of temporary solution: wait for 300ms after state is set to isFinalizing to block new requests and allow current pending requests to complete
await new Promise((resolve) => setTimeout(resolve, 300));
// CRITICAL: Wait for ALL pending updates from delta/finish to complete FIRST // CRITICAL: Wait for ALL pending updates from delta/finish to complete FIRST
// This ensures execute's update is always the last one in the queue // This ensures execute's update is always the last one in the queue
if (typeof state.latestSequenceNumber === 'number') { if (typeof state.latestSequenceNumber === 'number') {

View File

@ -70,16 +70,17 @@ function getOrCreateQueueState(messageId: string): MessageUpdateQueueState {
return initialState; return initialState;
} }
function cleanupQueueIfIdle(messageId: string, state: MessageUpdateQueueState): void { // function cleanupQueueIfIdle(messageId: string, state: MessageUpdateQueueState): void {
if ( // if (
state.closed && // state.closed &&
state.finalSequence !== undefined && // state.finalSequence !== undefined &&
state.lastCompletedSequence >= state.finalSequence && // state.lastCompletedSequence >= state.finalSequence &&
state.pending.size === 0 // state.pending.size === 0
) { // ) {
updateQueues.delete(messageId); // console.info('[cleanupQueueIfIdle] CLEANING UP QUEUE');
} // updateQueues.delete(messageId);
} // }
// }
export function isMessageUpdateQueueClosed(messageId: string): boolean { export function isMessageUpdateQueueClosed(messageId: string): boolean {
const queue = updateQueues.get(messageId); const queue = updateQueues.get(messageId);
@ -107,7 +108,7 @@ export async function waitForPendingUpdates(
if (targetSequence === undefined) { if (targetSequence === undefined) {
await queue.tailPromise; await queue.tailPromise;
cleanupQueueIfIdle(messageId, queue); // cleanupQueueIfIdle(messageId, queue);
return; return;
} }
@ -115,7 +116,7 @@ export async function waitForPendingUpdates(
const effectiveTarget = Math.min(targetSequence, maxKnownSequence); const effectiveTarget = Math.min(targetSequence, maxKnownSequence);
if (effectiveTarget <= queue.lastCompletedSequence) { if (effectiveTarget <= queue.lastCompletedSequence) {
cleanupQueueIfIdle(messageId, queue); // cleanupQueueIfIdle(messageId, queue);
return; return;
} }
@ -134,7 +135,7 @@ export async function waitForPendingUpdates(
await queue.tailPromise; await queue.tailPromise;
} }
cleanupQueueIfIdle(messageId, queue); // cleanupQueueIfIdle(messageId, queue);
} }
/** /**
@ -272,7 +273,7 @@ export async function updateMessageEntries(
if (isFinal) { if (isFinal) {
queue.finalSequence = sequenceNumber; queue.finalSequence = sequenceNumber;
} }
cleanupQueueIfIdle(messageId, queue); // cleanupQueueIfIdle(messageId, queue);
return success; return success;
}; };