fix: bridge ERR log level + n_ctx auto-retry with compressed prompt

This commit is contained in:
2026-05-07 15:43:19 +09:00
parent 47e35ab62c
commit f190ea41ff
8 changed files with 42 additions and 30 deletions
+25 -14
View File
@@ -526,28 +526,39 @@ export class AgentExecutor {
logInfo('Generation aborted by user.');
} else {
logError('Stream reading error.', { engine, apiUrl, error: err?.message || String(err) });
// LM Studio llama.cpp n_keep > n_ctx 에러 감지
// LM Studio llama.cpp n_keep > n_ctx 에러 감지 → 자동 압축 재시도
const errMsg = String(err?.message || err || '');
const nCtxMatch = errMsg.match(/n_keep\s*:\s*(\d+)\s*>=?\s*n_ctx\s*:\s*(\d+)/);
if (nCtxMatch) {
const nKeep = nCtxMatch[1];
const nCtx = nCtxMatch[2];
if (nCtxMatch && loopDepth < 1) {
// loopDepth < 1: 재시도는 최초 1회만 (무한루프 방지)
const nCtx = parseInt(nCtxMatch[2], 10);
const nKeep = parseInt(nCtxMatch[1], 10);
logInfo('n_ctx overflow → auto-retrying with compressed system prompt.', { nKeep, nCtx });
// 시스템 프롬프트를 n_ctx - 응답여유(512토큰) 범위로 강제 압축
const maxSysChars = Math.max(800, (nCtx - 512)) * 4;
const compressedSysPrompt = systemPrompt.length > maxSysChars
? systemPrompt.slice(0, maxSysChars) + `\n[System prompt compressed: n_ctx=${nCtx}]`
: systemPrompt;
this.webview?.postMessage({
type: 'streamChunk',
value: `\n⚠️ *LM Studio n_ctx=${nCtx} 감지. 컨텍스트 압축 후 재시도 중...*\n`
});
await this.handlePrompt(prompt, modelName, {
...options,
loopDepth: loopDepth + 1, // 재시도 플래그
runId,
systemPrompt: compressedSysPrompt
});
} else if (nCtxMatch) {
// 재시도 이미 했는데도 실패한 경우
this.webview?.postMessage({
type: 'error',
value: [
`Connection lost: AI Engine Error (LM Studio)`,
`시스템 프롬프트 토큰(${nKeep})이 실제 KV 캐시(${nCtx})보다 큽니다.`,
'',
'**원인:** LM Studio가 GPU 메모리 부족으로 컨텍스트 창을 축소했습니다.',
'**해결 방법 (LM Studio 재설정):**',
`1. LM Studio → 모델 설정 → GPU Offload 레이어를 줄여보세요 (현재 설정보다 낮게)`,
`2. 모델을 언로드 후 재로드하세요`,
`3. 다른 앱이 GPU 메모리를 점유하고 있다면 종료 후 재시도`,
].join('\n')
value: `LM Studio n_ctx(${nCtxMatch[2]}) 초과: 압축 재시도도 실패했습니다. LM Studio에서 모델을 재로드하세요.`
});
} else {
this.webview?.postMessage({ type: 'error', value: `Connection lost: ${err.message}` });
}
}
}
+3 -2
View File
@@ -73,15 +73,16 @@ export class BridgeServer {
// once() 사용: 중복 에러 이벤트 방지
server.once('error', (err: any) => {
if (err.code === 'EADDRINUSE') {
// INFO 레벨: ERR 콘솔 오염 방지 (Extension Host가 console.error를 ERR로 표시)
logInfo(`Bridge Port ${port} already in use. Trying port ${port + 1}...`);
// 기존 서버 참조 정리 후 다음 포트 시도
server.close();
if (this.server === server) {
this.server = null;
}
this.start(port + 1);
} else {
logError(`Bridge server error on port ${port}:`, err);
// EADDRINUSE 외 진짜 에러만 logError
logInfo(`Bridge server non-fatal error on port ${port}: ${err.code || err.message}`);
}
});