fix: promote visible progress after silent final

This commit is contained in:
Eyejoker
2026-03-28 06:27:36 +09:00
parent 38d96578a4
commit de913985ba
4 changed files with 102 additions and 8 deletions

View File

@@ -1483,6 +1483,100 @@ describe('createMessageRuntime', () => {
expect(channel.setTyping).not.toHaveBeenCalledWith(chatJid, true);
});
it('promotes the last visible progress to a final message when the final output is structured silent', async () => {
vi.useFakeTimers();
const chatJid = 'group@test';
const group = makeGroup('codex');
const channel = makeChannel(chatJid);
const lastAgentTimestamps: Record<string, string> = {};
const saveState = vi.fn();
vi.mocked(db.getMessagesSince).mockReturnValue([
{
id: 'msg-1',
chat_jid: chatJid,
sender: 'user@test',
sender_name: 'User',
content: 'hello',
timestamp: '2026-03-19T00:00:00.000Z',
seq: 1,
},
]);
vi.mocked(channel.sendAndTrack!).mockResolvedValueOnce('progress-1');
vi.mocked(agentRunner.runAgentProcess).mockImplementation(
async (_group, _input, _onProcess, onOutput) => {
await onOutput?.({
status: 'success',
phase: 'progress',
result: '첫 번째 진행상황입니다.',
newSessionId: 'session-progress-structured-silent',
});
await onOutput?.({
status: 'success',
phase: 'progress',
result: '두 번째 진행상황입니다.',
newSessionId: 'session-progress-structured-silent',
});
await vi.runOnlyPendingTimersAsync();
await onOutput?.({
status: 'success',
phase: 'final',
result: null,
output: { visibility: 'silent' },
newSessionId: 'session-progress-structured-silent',
});
return {
status: 'success',
result: null,
output: { visibility: 'silent' },
newSessionId: 'session-progress-structured-silent',
};
},
);
const runtime = createMessageRuntime({
assistantName: 'Andy',
idleTimeout: 1_000,
pollInterval: 1_000,
timezone: 'UTC',
triggerPattern: /^@Andy\b/i,
channels: [channel],
queue: {
registerProcess: vi.fn(),
closeStdin: vi.fn(),
notifyIdle: vi.fn(),
} as any,
getRegisteredGroups: () => ({ [chatJid]: group }),
getSessions: () => ({}),
getLastTimestamp: () => '',
setLastTimestamp: vi.fn(),
getLastAgentTimestamps: () => lastAgentTimestamps,
saveState,
persistSession: vi.fn(),
clearSession: vi.fn(),
});
try {
const result = await runtime.processGroupMessages(chatJid, {
runId: 'run-progress-structured-silent',
reason: 'messages',
});
expect(result).toBe(true);
expect(channel.sendAndTrack).toHaveBeenCalledTimes(1);
expect(channel.sendMessage).toHaveBeenCalledTimes(1);
expect(channel.sendMessage).toHaveBeenCalledWith(
chatJid,
'첫 번째 진행상황입니다.',
);
} finally {
vi.useRealTimers();
}
});
it('defers typing-on until the first visible output for suppress-capable turns', async () => {
const chatJid = 'group@test';
const group = makeGroup('claude-code');

View File

@@ -311,8 +311,13 @@ export class MessageTurnController {
await this.deliverFinalText(text);
}
} else if (silentOutput || suppressState !== 'none') {
const shouldPromoteVisibleProgressToFinal =
this.visiblePhase === 'progress' &&
typeof this.latestProgressTextForFinal === 'string';
await this.finalizeProgressMessage();
this.latestProgressTextForFinal = null;
if (!shouldPromoteVisibleProgressToFinal) {
this.latestProgressTextForFinal = null;
}
} else if (raw) {
logger.info(
{

View File

@@ -86,9 +86,7 @@ describe('runClaudeRotationLoop', () => {
it('uses structured public output text as the next rotation message', async () => {
vi.mocked(getTokenCount).mockReturnValue(2);
vi.mocked(rotateToken)
.mockReturnValueOnce(true)
.mockReturnValueOnce(false);
vi.mocked(rotateToken).mockReturnValueOnce(true).mockReturnValueOnce(false);
let attempts = 0;
const outcome = await runClaudeRotationLoop(

View File

@@ -117,10 +117,7 @@ export function evaluateStreamedOutput(
}
}
if (
countsAsFinalOutput &&
hasAgentOutputPayload(output)
) {
if (countsAsFinalOutput && hasAgentOutputPayload(output)) {
nextState.sawOutput = true;
} else if (
options.trackSuccessNullResult &&