fix: keep paired rooms moving when owner turn preparation fails

A wargame room stalled after its owner ran npm install in a bun project:
both bun.lock and package-lock.json existed, so every owner turn threw
'Ambiguous package manager' while provisioning the workspace. The queue
had already claimed the turn, nothing released the claim, and the 5s
backoff retry was skipped as 'already claimed elsewhere', so the room
sat idle until a human wrote again (and then failed the same way).

- Owner workspace provisioning and the review handoff no longer fail
  when the dependency install step throws; they log a warning and go on.
- If preparing a paired run throws, mark the claimed turn failed and
  release its execution lease so the retry can run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-10-29 15:09:47 +09:00
parent fdd98e9eb8
commit 720223eb10
4 changed files with 171 additions and 35 deletions

View File

@@ -1,4 +1,5 @@
import { AgentOutput } from './agent-runner.js';
import { logger } from './logger.js';
import { GroupQueue } from './group-queue.js';
import type { AgentTriggerReason } from './agent-error-detection.js';
import {
@@ -20,7 +21,11 @@ import {
markRunPausedForClaudeUsage,
pauseRoomForClaudeUsage,
} from './claude-usage-pause.js';
import { getPairedTaskById } from './db.js';
import {
failPairedTurn,
getPairedTaskById,
releasePairedTaskExecutionLease,
} from './db.js';
import {
formatUsageAlignmentHoldMessage,
formatUsageLimitAlignedPauseMessage,
@@ -314,6 +319,32 @@ async function deliverNoticeAndFailExecution(args: {
args.pairedExecutionLifecycle.completeImmediately({ status: 'failed' });
}
/**
* The queue claims the paired turn (execution lease + running attempt) before
* this executor runs. If preparing the run throws, nothing else releases that
* claim, so the backoff retry is skipped as "already claimed elsewhere" and the
* room stalls until a human writes again. Release it so the retry can run.
*/
function releaseClaimedTurnAfterPrepareFailure(
turnIdentity: PairedTurnIdentity | undefined,
runId: string,
error: unknown,
): void {
if (!turnIdentity) return;
try {
failPairedTurn({
turnIdentity,
error: error instanceof Error ? error.message : String(error),
});
releasePairedTaskExecutionLease({ taskId: turnIdentity.taskId, runId });
} catch (releaseError) {
logger.error(
{ taskId: turnIdentity.taskId, runId, releaseError },
'Failed to release paired turn claim after execution prepare failure',
);
}
}
export interface MessageAgentExecutorDeps {
assistantName: string;
queue: Pick<GroupQueue, 'registerProcess' | 'enqueueMessageCheck'> &
@@ -346,18 +377,30 @@ export async function runAgentForGroup(
},
): Promise<'success' | 'error'> {
const { group, prompt, chatJid, runId, startSeq, endSeq, onOutput } = args;
const preparedExecution = await prepareMessageAgentExecutionTarget(deps, {
group,
prompt,
chatJid,
runId,
startSeq,
endSeq,
hasHumanMessage: args.hasHumanMessage,
forcedRole: args.forcedRole,
forcedAgentType: args.forcedAgentType,
pairedTurnIdentity: args.pairedTurnIdentity,
});
let preparedExecution: Awaited<
ReturnType<typeof prepareMessageAgentExecutionTarget>
>;
try {
preparedExecution = await prepareMessageAgentExecutionTarget(deps, {
group,
prompt,
chatJid,
runId,
startSeq,
endSeq,
hasHumanMessage: args.hasHumanMessage,
forcedRole: args.forcedRole,
forcedAgentType: args.forcedAgentType,
pairedTurnIdentity: args.pairedTurnIdentity,
});
} catch (error) {
releaseClaimedTurnAfterPrepareFailure(
args.pairedTurnIdentity,
runId,
error,
);
throw error;
}
const {
activeRole,
effectiveServiceId,