fix: use stepOffset to bypass 775-step API limit with full details
This commit is contained in:
@@ -1559,23 +1559,62 @@ function setupMonitor() {
|
|||||||
// Diagnostic: compare returned steps vs trajectory stepCount
|
// Diagnostic: compare returned steps vs trajectory stepCount
|
||||||
logToFile(`[STEP-PROBE] returned=${steps.length} vs trajectory.stepCount=${currentCount}`);
|
logToFile(`[STEP-PROBE] returned=${steps.length} vs trajectory.stepCount=${currentCount}`);
|
||||||
if (steps.length < currentCount) {
|
if (steps.length < currentCount) {
|
||||||
logToFile(`[STEP-PROBE] ⚠️ 775-limit hit! steps=${steps.length} < stepCount=${currentCount}`);
|
logToFile(`[STEP-PROBE] ⚠️ 775-limit hit! steps=${steps.length} < stepCount=${currentCount} — retrying with stepOffset`);
|
||||||
// 775-LIMIT FALLBACK: API can't return latest steps.
|
// 775-LIMIT FIX: Retry with stepOffset to get latest steps
|
||||||
// Use stall detection to create a generic pending.
|
try {
|
||||||
if (consecutiveIdleCount >= 3 && lastPendingStepIndex !== currentCount) {
|
const offset = Math.max(0, currentCount - 10);
|
||||||
logToFile(`[STEP-PROBE] 775-LIMIT FALLBACK: creating generic pending for step ~${currentCount}`);
|
const offsetResp = await sdk.ls.rawRPC('GetCascadeTrajectorySteps', {
|
||||||
stallProbed = true;
|
cascadeId: bestSessionId,
|
||||||
lastPendingStepIndex = currentCount;
|
stepOffset: offset,
|
||||||
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',
|
|
||||||
});
|
});
|
||||||
|
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) {
|
||||||
|
logToFile(`[STEP-PROBE] offset retry failed: ${oe.message.substring(0, 100)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Scan last 5 steps backwards to find WAITING (RUN_COMMAND may not be last)
|
// Scan last 5 steps backwards to find WAITING (RUN_COMMAND may not be last)
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1539,23 +1539,55 @@ function setupMonitor() {
|
|||||||
// Diagnostic: compare returned steps vs trajectory stepCount
|
// Diagnostic: compare returned steps vs trajectory stepCount
|
||||||
logToFile(`[STEP-PROBE] returned=${steps.length} vs trajectory.stepCount=${currentCount}`);
|
logToFile(`[STEP-PROBE] returned=${steps.length} vs trajectory.stepCount=${currentCount}`);
|
||||||
if (steps.length < currentCount) {
|
if (steps.length < currentCount) {
|
||||||
logToFile(`[STEP-PROBE] ⚠️ 775-limit hit! steps=${steps.length} < stepCount=${currentCount}`);
|
logToFile(`[STEP-PROBE] ⚠️ 775-limit hit! steps=${steps.length} < stepCount=${currentCount} — retrying with stepOffset`);
|
||||||
// 775-LIMIT FALLBACK: API can't return latest steps.
|
// 775-LIMIT FIX: Retry with stepOffset to get latest steps
|
||||||
// Use stall detection to create a generic pending.
|
try {
|
||||||
if (consecutiveIdleCount >= 3 && lastPendingStepIndex !== currentCount) {
|
const offset = Math.max(0, currentCount - 10);
|
||||||
logToFile(`[STEP-PROBE] 775-LIMIT FALLBACK: creating generic pending for step ~${currentCount}`);
|
const offsetResp = await sdk.ls.rawRPC('GetCascadeTrajectorySteps', {
|
||||||
stallProbed = true;
|
cascadeId: bestSessionId,
|
||||||
lastPendingStepIndex = currentCount;
|
stepOffset: offset,
|
||||||
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',
|
|
||||||
});
|
});
|
||||||
|
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