fix: only reset merge_ready to active when human message is present
The finalize turn (auto-triggered after reviewer approval) was being treated as a new working turn because merge_ready was unconditionally reset to active. Now merge_ready is only reset when a human message is in the batch, preserving the finalize flow for bot-only turns.
This commit is contained in:
@@ -78,6 +78,7 @@ export async function runAgentForGroup(
|
|||||||
runId: string;
|
runId: string;
|
||||||
startSeq?: number | null;
|
startSeq?: number | null;
|
||||||
endSeq?: number | null;
|
endSeq?: number | null;
|
||||||
|
hasHumanMessage?: boolean;
|
||||||
onOutput?: (output: AgentOutput) => Promise<void>;
|
onOutput?: (output: AgentOutput) => Promise<void>;
|
||||||
},
|
},
|
||||||
): Promise<'success' | 'error'> {
|
): Promise<'success' | 'error'> {
|
||||||
@@ -159,6 +160,7 @@ export async function runAgentForGroup(
|
|||||||
chatJid,
|
chatJid,
|
||||||
runId,
|
runId,
|
||||||
roomRoleContext,
|
roomRoleContext,
|
||||||
|
hasHumanMessage: args.hasHumanMessage,
|
||||||
});
|
});
|
||||||
const effectivePrompt = prompt;
|
const effectivePrompt = prompt;
|
||||||
let pairedExecutionStatus: 'succeeded' | 'failed' = 'failed';
|
let pairedExecutionStatus: 'succeeded' | 'failed' = 'failed';
|
||||||
|
|||||||
@@ -272,6 +272,7 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
|
|||||||
options?: {
|
options?: {
|
||||||
startSeq?: number | null;
|
startSeq?: number | null;
|
||||||
endSeq?: number | null;
|
endSeq?: number | null;
|
||||||
|
hasHumanMessage?: boolean;
|
||||||
},
|
},
|
||||||
): Promise<'success' | 'error'> =>
|
): Promise<'success' | 'error'> =>
|
||||||
runAgentForGroup(
|
runAgentForGroup(
|
||||||
@@ -290,6 +291,7 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
|
|||||||
runId,
|
runId,
|
||||||
startSeq: options?.startSeq,
|
startSeq: options?.startSeq,
|
||||||
endSeq: options?.endSeq,
|
endSeq: options?.endSeq,
|
||||||
|
hasHumanMessage: options?.hasHumanMessage,
|
||||||
onOutput,
|
onOutput,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -302,6 +304,7 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
|
|||||||
channel: Channel;
|
channel: Channel;
|
||||||
startSeq: number | null;
|
startSeq: number | null;
|
||||||
endSeq: number | null;
|
endSeq: number | null;
|
||||||
|
hasHumanMessage?: boolean;
|
||||||
}): Promise<{
|
}): Promise<{
|
||||||
outputStatus: 'success' | 'error';
|
outputStatus: 'success' | 'error';
|
||||||
deliverySucceeded: boolean;
|
deliverySucceeded: boolean;
|
||||||
@@ -358,7 +361,7 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
|
|||||||
chatJid,
|
chatJid,
|
||||||
runId,
|
runId,
|
||||||
(result) => turnController.handleOutput(result),
|
(result) => turnController.handleOutput(result),
|
||||||
{ startSeq, endSeq },
|
{ startSeq, endSeq, hasHumanMessage: args.hasHumanMessage },
|
||||||
);
|
);
|
||||||
|
|
||||||
const { deliverySucceeded, visiblePhase } =
|
const { deliverySucceeded, visiblePhase } =
|
||||||
@@ -755,6 +758,7 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
|
|||||||
pendingTaskForChannel.status === 'in_review');
|
pendingTaskForChannel.status === 'in_review');
|
||||||
const turnChannel = useReviewerChannel ? reviewerChannel : channel;
|
const turnChannel = useReviewerChannel ? reviewerChannel : channel;
|
||||||
|
|
||||||
|
const hasHumanMsg = !isBotOnlyPairedRoomTurn(chatJid, missedMessages);
|
||||||
const { deliverySucceeded, visiblePhase } = await executeTurn({
|
const { deliverySucceeded, visiblePhase } = await executeTurn({
|
||||||
group,
|
group,
|
||||||
prompt,
|
prompt,
|
||||||
@@ -763,6 +767,7 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
|
|||||||
channel: turnChannel,
|
channel: turnChannel,
|
||||||
startSeq,
|
startSeq,
|
||||||
endSeq,
|
endSeq,
|
||||||
|
hasHumanMessage: hasHumanMsg,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!deliverySucceeded) {
|
if (!deliverySucceeded) {
|
||||||
|
|||||||
@@ -198,6 +198,7 @@ export function preparePairedExecutionContext(args: {
|
|||||||
chatJid: string;
|
chatJid: string;
|
||||||
runId: string;
|
runId: string;
|
||||||
roomRoleContext?: RoomRoleContext;
|
roomRoleContext?: RoomRoleContext;
|
||||||
|
hasHumanMessage?: boolean;
|
||||||
}): PreparedPairedExecutionContext | undefined {
|
}): PreparedPairedExecutionContext | undefined {
|
||||||
const { group, chatJid, roomRoleContext } = args;
|
const { group, chatJid, roomRoleContext } = args;
|
||||||
if (!roomRoleContext || !group.workDir) {
|
if (!roomRoleContext || !group.workDir) {
|
||||||
@@ -217,9 +218,13 @@ export function preparePairedExecutionContext(args: {
|
|||||||
if (roomRoleContext.role === 'owner') {
|
if (roomRoleContext.role === 'owner') {
|
||||||
// New human message → new ping-pong cycle. Reset round trip counter
|
// New human message → new ping-pong cycle. Reset round trip counter
|
||||||
// AND status so the owner turn is not treated as a finalize turn.
|
// AND status so the owner turn is not treated as a finalize turn.
|
||||||
|
// Reset status on new human message so the owner gets a fresh working
|
||||||
|
// turn. merge_ready is only reset when a human message is present —
|
||||||
|
// without it, this is a finalize turn after reviewer approval and
|
||||||
|
// resetting would prevent task completion.
|
||||||
const needsReset =
|
const needsReset =
|
||||||
latestTask.round_trip_count > 0 ||
|
latestTask.round_trip_count > 0 ||
|
||||||
latestTask.status === 'merge_ready' ||
|
(latestTask.status === 'merge_ready' && args.hasHumanMessage === true) ||
|
||||||
latestTask.status === 'review_ready' ||
|
latestTask.status === 'review_ready' ||
|
||||||
latestTask.status === 'in_review';
|
latestTask.status === 'in_review';
|
||||||
if (needsReset) {
|
if (needsReset) {
|
||||||
|
|||||||
Reference in New Issue
Block a user