Skip to content

Commit e6e261c

Browse files
committed
delegate.js: don't silently discard a checkpoint when resuming with max_steps below steps already completed
Previously, resuming with a max_steps ceiling lower than checkpoint.stepsDone meant startStep > cappedSteps, so the loop body never ran -- it fell straight through to deleteCheckpoint() + the generic "stopped after reaching the step cap" message, discarding a checkpoint that had real completed work in it without ever surfacing that work or explaining what happened. Added an explicit guard right after the checkpoint state is established: if there's nothing new to do because the requested ceiling is already met/exceeded, leave the checkpoint alone (still resumable with a higher max_steps) and return the existing transcript with a message that says so plainly.
1 parent db61b82 commit e6e261c

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

connectors/gemini/delegate.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,28 @@ export async function runInvestigation({ task, max_steps = 6, resume_run_id }) {
860860
startStep = 1;
861861
}
862862

863+
// Resuming with a max_steps ceiling that's already been met or exceeded
864+
// by the checkpoint's own stepsDone (e.g. a checkpoint has 5 completed
865+
// steps and the caller resumes with max_steps: 2) -- there's no budget
866+
// left to take even one more step. Don't fall into the loop-and-fall-
867+
// through path below: that unconditionally deletes the checkpoint via
868+
// deleteCheckpoint(runId) once the loop exits, which would throw away a
869+
// still-good, still-resumable checkpoint for no reason (the loop body
870+
// simply never executes when startStep > cappedSteps), and the generic
871+
// step-cap message doesn't explain that anything was actually completed.
872+
// Leave the checkpoint alone -- it's still resumable with a higher
873+
// max_steps -- and say so explicitly instead.
874+
if (checkpoint && startStep > cappedSteps) {
875+
return {
876+
answer: `(This run already completed ${startStep - 1} step(s), which meets or exceeds the requested max_steps of ${cappedSteps} -- no new steps were taken this call. The checkpoint has NOT been discarded. Call gemini_investigate again with resume_run_id: "${runId}" and a higher max_steps to continue, or treat the ${transcript.length} tool call(s) below as the result so far.)`,
877+
steps: startStep - 1,
878+
transcript,
879+
runId,
880+
task: effectiveTask,
881+
failed: true,
882+
};
883+
}
884+
863885
for (let step = startStep; step <= cappedSteps; step++) {
864886
// On the final allowed step, withhold the function-calling tools
865887
// entirely instead of just reminding the model to wrap up: a text-only

0 commit comments

Comments
 (0)