fix: stop report_progress loop and reinforce review-mode output discipline

This commit is contained in:
2026-06-01 12:44:57 -05:00
parent eb8871d6d2
commit b36abf39d4
2 changed files with 50 additions and 7 deletions
+31 -7
View File
@@ -148,6 +148,8 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
let pendingModeNudge = false;
let calledOutputTool = false;
let addedContinueNudge = false;
let reportProgressCount = 0;
let selectedModeName = "";
while (iterations < MAX_ITERATIONS) {
iterations++;
@@ -222,13 +224,16 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
"» model stopped before completing task — nudging to continue",
);
addedContinueNudge = true;
const isReview =
selectedModeName === "Review" || selectedModeName === "IncrementalReview";
messages.push({
role: "user",
content:
"Your task is not complete yet. Continue executing the workflow — " +
"call the next required tool to finish. " +
"Do not stop until you have submitted a review (create_pull_request_review) " +
"or called report_progress with a final summary.",
(isReview
? "Do not stop until you have submitted a review via create_pull_request_review."
: "Do not stop until you have submitted a review (create_pull_request_review) or called report_progress with a final summary."),
});
continue;
}
@@ -279,6 +284,17 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
role: "tool",
content: result,
});
// report_progress called more than once means the model is looping —
// it has no signal to stop since the tool always returns success.
if (toolName === "report_progress") {
reportProgressCount++;
if (reportProgressCount >= 2) {
log.info("» report_progress called multiple times — stopping loop");
await unloadModel(ollama, model);
return { success: true };
}
}
}
// After the FIRST select_mode call, nudge the model to act on the guidance.
@@ -301,10 +317,18 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
// best-effort
}
const firstStep =
selectedMode === "Review" || selectedMode === "IncrementalReview"
? "Your first tool call must be checkout_pr with the PR number from the event context."
: "Call the first tool required by the workflow now.";
const isReviewMode =
selectedMode === "Review" || selectedMode === "IncrementalReview";
selectedModeName = selectedMode;
const firstStep = isReviewMode
? "Your first tool call must be checkout_pr with the PR number from the event context."
: "Call the first tool required by the workflow now.";
const endCondition = isReviewMode
? "Your ONLY valid final action is create_pull_request_review. Do NOT call report_progress — the mode workflow explicitly forbids it."
: "Execute the complete workflow step by step until you call create_pull_request_review or report_progress.";
messages.push({
role: "user",
@@ -312,7 +336,7 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
`Good. You have selected ${selectedMode || "a"} mode and received the workflow. ` +
"Do NOT call select_mode again. " +
`${firstStep} ` +
"Execute the complete workflow step by step until you call create_pull_request_review or report_progress.",
endCondition,
});
}
}