diff --git a/src/message-runtime-prompts.test.ts b/src/message-runtime-prompts.test.ts index 900b8ca..9b9d7e5 100644 --- a/src/message-runtime-prompts.test.ts +++ b/src/message-runtime-prompts.test.ts @@ -284,6 +284,64 @@ describe('message-runtime-prompts output-only context', () => { expect(prompt).not.toContain('이전 작업의 사용자 메시지'); }); + it('caps reviewer pending prompts to the most recent turn outputs with an omission marker', () => { + const prompt = buildReviewerPendingPrompt({ + chatJid: 'group@test', + timezone: 'UTC', + turnOutputs: Array.from({ length: 8 }, (_, index) => { + const turnNumber = index + 1; + return makeTurnOutput( + `pending-context-output-${String(turnNumber).padStart(2, '0')}`, + turnNumber % 2 === 0 ? 'reviewer' : 'owner', + { + id: turnNumber, + turn_number: turnNumber, + created_at: `2026-04-20T02:${String(turnNumber).padStart(2, '0')}:00.000Z`, + }, + ); + }), + recentHumanMessages: [], + lastHumanMessage: null, + }); + + expect(prompt).not.toContain('pending-context-output-01'); + expect(prompt).not.toContain('pending-context-output-02'); + expect(prompt).toContain( + '[Earlier paired turn outputs omitted: 2 older outputs not shown]', + ); + expect(prompt).toContain('pending-context-output-03'); + expect(prompt).toContain('pending-context-output-08'); + }); + + it('caps owner pending prompts to the most recent turn outputs with an omission marker', () => { + const prompt = buildOwnerPendingPrompt({ + chatJid: 'group@test', + timezone: 'UTC', + turnOutputs: Array.from({ length: 8 }, (_, index) => { + const turnNumber = index + 1; + return makeTurnOutput( + `pending-context-output-${String(turnNumber).padStart(2, '0')}`, + turnNumber % 2 === 0 ? 'reviewer' : 'owner', + { + id: turnNumber, + turn_number: turnNumber, + created_at: `2026-04-20T02:${String(turnNumber).padStart(2, '0')}:00.000Z`, + }, + ); + }), + recentHumanMessages: [], + lastHumanMessage: null, + }); + + expect(prompt).not.toContain('pending-context-output-01'); + expect(prompt).not.toContain('pending-context-output-02'); + expect(prompt).toContain( + '[Earlier paired turn outputs omitted: 2 older outputs not shown]', + ); + expect(prompt).toContain('pending-context-output-03'); + expect(prompt).toContain('pending-context-output-08'); + }); + it('includes current task user scope in owner pending prompts without pulling older human messages', () => { const prompt = buildOwnerPendingPrompt({ chatJid: 'group@test', diff --git a/src/message-runtime-prompts.ts b/src/message-runtime-prompts.ts index d84edaa..cb2fd1a 100644 --- a/src/message-runtime-prompts.ts +++ b/src/message-runtime-prompts.ts @@ -20,7 +20,12 @@ const CARRIED_FORWARD_MARKER_PREFIX = const CARRIED_FORWARD_OWNER_FINAL_GUIDANCE = `System note: If you see a message beginning with "${CARRIED_FORWARD_MARKER_PREFIX}", treat it as background only. Do not repeat, continue, or answer that carried-forward final directly. Respond only to the latest human request and the current task.`; -const ARBITER_TURN_OUTPUT_CONTEXT_LIMIT = 6; +// Cap on how many recent paired turn outputs any pending prompt re-sends. The +// owner/reviewer each resume a persistent session that already holds the running +// thread, so re-sending every accumulated output each turn grows the prompt +// linearly with round-trips for no benefit. Bound it (with an omission marker) +// to the most recent outputs, matching the arbiter path. +const TURN_OUTPUT_CONTEXT_LIMIT = 6; function isImageAttachment(attachment: OutboundAttachment): boolean { if (attachment.mime?.toLowerCase().startsWith('image/')) return true; @@ -215,7 +220,14 @@ function turnOutputsOnlyPrompt( ): string { return prependCarriedForwardGuidance( formatMessages( - [...taskHumanMessages, ...turnOutputsToMessages(turnOutputs, chatJid)], + [ + ...taskHumanMessages, + ...latestTurnOutputMessagesWithOmissionMarker( + turnOutputs, + chatJid, + TURN_OUTPUT_CONTEXT_LIMIT, + ), + ], timezone, ), turnOutputs, @@ -289,7 +301,7 @@ export function buildArbiterPromptForTask(args: { ...latestTurnOutputMessagesWithOmissionMarker( args.turnOutputs, args.chatJid, - ARBITER_TURN_OUTPUT_CONTEXT_LIMIT, + TURN_OUTPUT_CONTEXT_LIMIT, ), ] : args.labeledRecentMessages;