fix: use stepOffset to bypass 775-step API limit with full details

This commit is contained in:
2026-03-10 08:08:36 +09:00
parent 2361aa7558
commit 628b5ae2fa
3 changed files with 104 additions and 33 deletions

View File

@@ -1559,24 +1559,63 @@ 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}`);
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 = currentCount;
lastPendingStepIndex = actualIndex;
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',
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)
let foundWaiting = false;

File diff suppressed because one or more lines are too long

View File

@@ -1539,24 +1539,56 @@ 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}`);
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 = currentCount;
lastPendingStepIndex = actualIndex;
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',
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)}`);
}
}
// Scan last 5 steps backwards to find WAITING (RUN_COMMAND may not be last)