fix: use stepOffset to bypass 775-step API limit with full details
This commit is contained in:
@@ -1539,23 +1539,55 @@ function setupMonitor() {
|
||||
// Diagnostic: compare returned steps vs trajectory stepCount
|
||||
logToFile(`[STEP-PROBE] returned=${steps.length} vs trajectory.stepCount=${currentCount}`);
|
||||
if (steps.length < currentCount) {
|
||||
logToFile(`[STEP-PROBE] ⚠️ 775-limit hit! steps=${steps.length} < stepCount=${currentCount}`);
|
||||
// 775-LIMIT FALLBACK: API can't return latest steps.
|
||||
// Use stall detection to create a generic pending.
|
||||
if (consecutiveIdleCount >= 3 && lastPendingStepIndex !== currentCount) {
|
||||
logToFile(`[STEP-PROBE] 775-LIMIT FALLBACK: creating generic pending for step ~${currentCount}`);
|
||||
stallProbed = true;
|
||||
lastPendingStepIndex = currentCount;
|
||||
lastPendingTime = Date.now();
|
||||
sawRunningAfterPending = false;
|
||||
writePendingApproval({
|
||||
conversation_id: activeSessionId,
|
||||
command: `run_command: (step ${currentCount}, beyond API limit)`,
|
||||
description: `Step ~${currentCount} (775-limit, type unknown)`,
|
||||
step_type: 'run_command',
|
||||
step_index: currentCount,
|
||||
source: 'step_probe_775_fallback',
|
||||
logToFile(`[STEP-PROBE] ⚠️ 775-limit hit! steps=${steps.length} < stepCount=${currentCount} — retrying with stepOffset`);
|
||||
// 775-LIMIT FIX: Retry with stepOffset to get latest steps
|
||||
try {
|
||||
const offset = Math.max(0, currentCount - 10);
|
||||
const offsetResp = await sdk.ls.rawRPC('GetCascadeTrajectorySteps', {
|
||||
cascadeId: bestSessionId,
|
||||
stepOffset: offset,
|
||||
});
|
||||
if (offsetResp?.steps?.length > 0) {
|
||||
// Replace steps array with offset results
|
||||
const offsetSteps = offsetResp.steps;
|
||||
logToFile(`[STEP-PROBE] offset=${offset} returned ${offsetSteps.length} steps (latest)`);
|
||||
// Scan for WAITING in offset results
|
||||
for (let osi = offsetSteps.length - 1; osi >= 0; osi--) {
|
||||
const oStep = offsetSteps[osi];
|
||||
if (oStep?.status === 'CORTEX_STEP_STATUS_WAITING') {
|
||||
const toolCall = oStep?.metadata?.toolCall;
|
||||
const toolName = toolCall?.name || (oStep.type || '').replace('CORTEX_STEP_TYPE_', '').toLowerCase();
|
||||
let command = toolName;
|
||||
if (toolCall?.argumentsJson) {
|
||||
try {
|
||||
const args = JSON.parse(toolCall.argumentsJson);
|
||||
if (args.CommandLine) command = `${toolName}: ${args.CommandLine.substring(0, 150)}`;
|
||||
else if (args.TargetFile) command = `${toolName}: ${args.TargetFile.split(/[\\/]/).pop()}`;
|
||||
else command = `${toolName}: ${Object.keys(args).join(', ')}`;
|
||||
} catch { command = toolName; }
|
||||
}
|
||||
const actualIndex = offset + osi;
|
||||
logToFile(`[STEP-PROBE] ★ WAITING (via offset)! step=${actualIndex} type=${oStep.type} cmd='${command}'`);
|
||||
if (actualIndex !== lastPendingStepIndex) {
|
||||
stallProbed = true;
|
||||
lastPendingStepIndex = actualIndex;
|
||||
lastPendingTime = Date.now();
|
||||
sawRunningAfterPending = false;
|
||||
writePendingApproval({
|
||||
conversation_id: activeSessionId,
|
||||
command,
|
||||
description: `Step #${actualIndex} (${(oStep.type || '').replace('CORTEX_STEP_TYPE_', '')})`,
|
||||
step_type: toolName,
|
||||
step_index: actualIndex,
|
||||
source: 'step_probe_offset',
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (oe: any) {
|
||||
logToFile(`[STEP-PROBE] offset retry failed: ${oe.message.substring(0, 100)}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user