fix: keep finals separate after silent retries

This commit is contained in:
Eyejoker
2026-03-23 03:54:19 +09:00
parent 290cd95e51
commit 562067352a
2 changed files with 59 additions and 57 deletions

View File

@@ -697,7 +697,10 @@ describe('createMessageRuntime', () => {
'중복 최종 답변입니다.', '중복 최종 답변입니다.',
); );
expect(channel.sendMessage).toHaveBeenCalledTimes(1); expect(channel.sendMessage).toHaveBeenCalledTimes(1);
expect(channel.sendMessage).toHaveBeenCalledWith(chatJid, '최종 답변입니다.'); expect(channel.sendMessage).toHaveBeenCalledWith(
chatJid,
'최종 답변입니다.',
);
} finally { } finally {
vi.useRealTimers(); vi.useRealTimers();
} }
@@ -1537,7 +1540,10 @@ describe('createMessageRuntime', () => {
'아직 진행 중.\n\n10초', '아직 진행 중.\n\n10초',
); );
expect(channel.sendMessage).toHaveBeenCalledTimes(1); expect(channel.sendMessage).toHaveBeenCalledTimes(1);
expect(channel.sendMessage).toHaveBeenCalledWith(chatJid, '아직 진행 중.'); expect(channel.sendMessage).toHaveBeenCalledWith(
chatJid,
'아직 진행 중.',
);
} finally { } finally {
vi.useRealTimers(); vi.useRealTimers();
} }
@@ -1564,16 +1570,14 @@ describe('createMessageRuntime', () => {
}, },
]); ]);
vi.mocked(agentRunner.runAgentProcess).mockImplementation( vi.mocked(agentRunner.runAgentProcess).mockImplementation(async () => {
async () => {
await vi.advanceTimersByTimeAsync(1_100); await vi.advanceTimersByTimeAsync(1_100);
return { return {
status: 'success', status: 'success',
result: null, result: null,
newSessionId: 'session-quiet-budget', newSessionId: 'session-quiet-budget',
}; };
}, });
);
const runtime = createMessageRuntime({ const runtime = createMessageRuntime({
assistantName: 'Andy', assistantName: 'Andy',

View File

@@ -569,7 +569,8 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
const MAX_SILENT_ROLLOVERS = 2; const MAX_SILENT_ROLLOVERS = 2;
const MAX_TOTAL_SILENT_WAIT_MS = const MAX_TOTAL_SILENT_WAIT_MS =
QUIET_RUN_ROLLOVER_MS * (MAX_SILENT_ROLLOVERS + 1); QUIET_RUN_ROLLOVER_MS * (MAX_SILENT_ROLLOVERS + 1);
const FAILURE_FINAL_TEXT = '요청을 완료하지 못했습니다. 다시 시도해 주세요.'; const FAILURE_FINAL_TEXT =
'요청을 완료하지 못했습니다. 다시 시도해 주세요.';
const queueItemBaseCursor = normalizeStoredSeqCursor( const queueItemBaseCursor = normalizeStoredSeqCursor(
deps.getLastAgentTimestamps()[chatJid] || '0', deps.getLastAgentTimestamps()[chatJid] || '0',
chatJid, chatJid,
@@ -630,11 +631,7 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
!requiresTrigger || !requiresTrigger ||
(hasTrigger && (hasTrigger &&
(msg.is_from_me || (msg.is_from_me ||
isTriggerAllowed( isTriggerAllowed(chatJid, msg.sender, loadSenderAllowlist())))
chatJid,
msg.sender,
loadSenderAllowlist(),
)))
); );
}, },
}, },
@@ -680,13 +677,11 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
); );
type VisiblePhase = 'silent' | 'progress' | 'final'; type VisiblePhase = 'silent' | 'progress' | 'final';
type PendingFollowUp = type PendingFollowUp = {
| {
queuedAt: number; queuedAt: number;
textLength: number; textLength: number;
filename: string; filename: string;
} } | null;
| null;
let idleTimer: ReturnType<typeof setTimeout> | null = null; let idleTimer: ReturnType<typeof setTimeout> | null = null;
let hadError = false; let hadError = false;
let producedDeliverySucceeded = true; let producedDeliverySucceeded = true;
@@ -934,7 +929,8 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
idleTimer = null; idleTimer = null;
return; return;
} }
idleTimer = setTimeout(() => { idleTimer = setTimeout(
() => {
const closeReason = const closeReason =
!hasVisibleOutput() && pendingFollowUp !hasVisibleOutput() && pendingFollowUp
? 'follow-up-no-output-preemption' ? 'follow-up-no-output-preemption'
@@ -965,7 +961,9 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
); );
} }
deps.queue.closeStdin(chatJid, { runId, reason: closeReason }); deps.queue.closeStdin(chatJid, { runId, reason: closeReason });
}, hasVisibleOutput() ? deps.idleTimeout : QUIET_RUN_ROLLOVER_MS); },
hasVisibleOutput() ? deps.idleTimeout : QUIET_RUN_ROLLOVER_MS,
);
}; };
const noteFollowUpQueued = (meta?: { const noteFollowUpQueued = (meta?: {