Cap owner/reviewer pending prompts to recent turn outputs

The owner and reviewer each resume a persistent session that already
holds the running paired thread, yet buildOwnerPendingPrompt /
buildReviewerPendingPrompt re-sent the ENTIRE accumulated turnOutputs
list every turn, so the prompt grew linearly with round-trips for no
benefit. Only the arbiter path was capped.

Reuse the arbiter's latestTurnOutputMessagesWithOmissionMarker cap
(now a shared TURN_OUTPUT_CONTEXT_LIMIT = 6) so owner/reviewer prompts
send at most the 6 most recent outputs plus an omission marker. On a
long ping-pong task this bounds per-turn prompt size instead of
re-sending every prior round's output. Behavior for tasks with <=6
outputs is unchanged.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-09-01 17:12:44 +09:00
parent 84672590d7
commit 4485a7fd72
2 changed files with 73 additions and 3 deletions

View File

@@ -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',

View File

@@ -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;