fix: drain sdk follow-up turns (#219)

This commit is contained in:
Eyejoker
2026-06-03 17:58:24 +08:00
committed by GitHub
parent 879d16235f
commit 807828e0ce
7 changed files with 137 additions and 10 deletions

View File

@@ -65,7 +65,6 @@ export class GroupQueue {
this.processMessagesFn = fn;
}
/** Limit concurrency after restart to avoid API rate-limit storms. */
enterRecoveryMode(): void {
this.recoveryMode = true;
logger.info(
@@ -101,7 +100,6 @@ export class GroupQueue {
const state = this.getGroup(groupJid);
// Pre-set IPC dir so sendMessage can pipe follow-ups while agent process starts
if (ipcDir && !state.ipcDir) {
state.ipcDir = ipcDir;
}
@@ -157,7 +155,6 @@ export class GroupQueue {
const state = this.getGroup(groupJid);
// Prevent double-queuing: check both pending and currently-running task
if (state.runningTaskId === taskId) {
logger.debug({ groupJid, taskId }, 'Task already running, skipping');
return;
@@ -196,7 +193,6 @@ export class GroupQueue {
return;
}
// Run immediately
this.runTask(groupJid, { id: taskId, groupJid, fn }).catch((err) =>
logger.error({ groupJid, taskId, err }, 'Unhandled error in runTask'),
);
@@ -207,10 +203,12 @@ export class GroupQueue {
proc: ChildProcess,
processName: string,
ipcDir?: string,
options?: { drainFollowUpsAfterRun?: boolean },
): void {
const state = this.getGroup(groupJid);
state.process = proc;
state.processName = processName;
state.drainFollowUpsAfterRun = options?.drainFollowUpsAfterRun === true;
if (ipcDir) state.ipcDir = ipcDir;
logger.info(
{
@@ -241,6 +239,7 @@ export class GroupQueue {
try {
const filename = queueFollowUpMessage(state.ipcDir, text);
state.pendingMessages ||= state.drainFollowUpsAfterRun;
logger.info(
{
groupJid,
@@ -248,6 +247,7 @@ export class GroupQueue {
ipcDir: state.ipcDir,
textLength: text.length,
filename,
pendingMessages: state.pendingMessages,
},
'Queued follow-up message for active agent',
);