feat: skip or slim down the owner finalize turn

(a) When the reviewer approves the owner's first TASK_DONE answer on the
first review (one review round, outputs are exactly owner -> reviewer, no
revision or arbiter turns) and the owner workspace still matches the
approved tree with a clean working tree, no owner run happens: the task is
completed as done and the reviewed answer (status line stripped) is posted
as the final message. If the review was requested with a bare "검토해줘"
after a review-skipped answer, a one-line confirmation is posted instead of
repeating the answer.

(b) Every other finalize turn runs in a fresh, non-persisted session (no
resume of the task's long working session, no room memory briefing) with a
self-contained prompt: this task's user messages, the latest six turn
outputs and the finalize instructions/format. All three finalize entry
points (pending turn, inline bot-only follow-up, queued turn) use it.

The owner prompt now states that the first TASK_DONE answer must already
follow the final-message format because it may be posted as the final
message unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-10-01 20:42:12 +09:00
parent 7f54c47e64
commit 0283abbb56
14 changed files with 604 additions and 39 deletions

View File

@@ -17,6 +17,10 @@ import { completePairedTaskWithReason } from './paired-task-status.js';
import { prepareMessageAgentExecutionTarget } from './message-agent-executor-target.js';
import { shouldRetryFreshSessionOnAgentFailure } from './session-recovery.js';
import { bindPairedSessionToTask } from './paired-session-binding.js';
import {
completeTaskWithoutFinalizeRun,
resolveFastFinalizeText,
} from './paired-finalize.js';
import type { AgentType, PairedRoomRole, RegisteredGroup } from './types.js';
import {
clearCompactRefreshIfUnchanged,
@@ -106,6 +110,39 @@ async function reportClaudeUsageLimitToRoom(
return true;
}
/**
* Owner finalize without an agent run (see paired-finalize.ts): close the task
* and deliver the already-reviewed answer as the final message. Returns false
* when the finalize turn must run normally.
*/
async function deliverFinalizeWithoutRun(args: {
taskId: string;
pairedExecutionLifecycle: PairedExecutionLifecycle;
onOutput?: (output: AgentOutput) => Promise<void>;
log: { info: (obj: Record<string, unknown>, msg: string) => void };
}): Promise<boolean> {
const task = getPairedTaskById(args.taskId);
const text = task ? resolveFastFinalizeText(task) : null;
if (!task || !text || !completeTaskWithoutFinalizeRun(task)) return false;
args.log.info(
{ pairedTaskId: task.id, textLength: text.length },
'Reviewer approved the first answer unchanged; finalized without an owner run',
);
const { pairedExecutionLifecycle } = args;
pairedExecutionLifecycle.updateSummary({ outputText: text });
if (pairedExecutionLifecycle.recordFinalOutputBeforeDelivery(text)) {
await args.onOutput?.({
status: 'success',
result: text,
output: { visibility: 'public', text },
phase: 'final',
});
}
pairedExecutionLifecycle.markSawOutput(true);
pairedExecutionLifecycle.markStatus('succeeded');
return true;
}
/** Send a final notice to the room and record the execution as failed. */
async function deliverNoticeAndFailExecution(args: {
notice: string;
@@ -265,6 +302,28 @@ export async function runAgentForGroup(
return 'success';
}
if (
pairedExecutionContext &&
runtimePairedTurnIdentity?.intentKind === 'finalize-owner-turn'
) {
let finalizedWithoutRun = false;
try {
finalizedWithoutRun = await deliverFinalizeWithoutRun({
taskId: pairedExecutionContext.task.id,
pairedExecutionLifecycle,
onOutput,
log,
});
} catch (err) {
await pairedExecutionLifecycle.asyncFinalize();
throw err;
}
if (finalizedWithoutRun) {
await pairedExecutionLifecycle.asyncFinalize();
return 'success';
}
}
const runAttempt = (currentProvider: 'claude' | 'codex') =>
runMessageAgentAttempt({
provider: currentProvider,