revert: 지서버 서버측 keep-alive 제거 — 지서버 자체 10초 하트비트로 대체

효과가 불확실했다. 로그로 보면 2분 핑이 도는 동안에도 한 번은 실제로
잠들었고("방금 또 잠들었던거 같으네"), 다른 구간에선 40분 연속 안
잤는데 그게 핑 덕분인지 그 시간 내내 실사용 채팅이 있었기 때문인지
분리할 수 없었다.

사용자가 지서버 쪽에 직접 10초 간격 하트비트를 새로 걸었다 — 원격에서
2분마다 찔러보는 것보다 훨씬 촘촘하고, 무엇보다 지서버 자체에서 도는
메커니즘이라 신뢰도를 판단하기 쉽다. 서버 쪽 것은 이제 중복이라
사용자 결정으로 제거.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Opus 5 committed 2026-08-10 15:19:13 +09:00
1 parent 6a4e333822
commit f972b184d6
2 files changed
-67

No files matched your search

-64
View File
@@ -1,64 +0,0 @@
/**
* ollama-local-keepalive.ts
*
* Periodically pokes 지서버's Ollama endpoint while it's the active model AND someone
* has the app open, so it doesn't drop to sleep mid-session.
*
* Why this exists (2026-08-10): 지서버 (Windows) sleeps much faster than its own 30-minute
* idle setting because Windows' idle timer counts user input (keyboard/mouse), not inbound
* network requests — a headless box that's only ever touched via WOL+Ollama API traffic
* looks "idle" to Windows no matter how many chat turns are running. This was investigated
* on 08-09 and the user decided the fast-sleep behavior was fine (power savings, wol-gate
* absorbs the ~23s wake delay) — see [[project_wol_gate]]. It stopped being fine once the
* user was relying on it while away from home (08-10): the wake delay repeating mid-session
* was disruptive enough that they asked for an explicit keep-alive signal ("지서버가 안자게
* 신호를 계속 보내자") rather than reopening the whole "why does it sleep early" investigation.
*
* This is a signal to keep it FROM sleeping, not a wake trigger — it hits the endpoint
* directly (never through wol-gate), so if 지서버 is already asleep this just fails silently
* and does nothing. Forcing a wake here would undo the power-saving behavior the user chose
* to keep for the other 95% of the time this box isn't actively in use.
*
* Gated on two conditions so it can't run unattended and quietly cancel out the power
* savings the user explicitly kept:
* 1. llm.provider === 'ollama_local' — someone has actually selected 지서버 as the active
* model right now (getProvider()'s single-instance cache means this is also the only
* condition under which any real chat traffic would even reach it).
* 2. At least one WebSocket client is connected — the app is actually open, not just left
* selected on ollama_local from a previous session while the gateway keeps running.
*/
import { getConfig } from '../config/config';
const KEEPALIVE_INTERVAL_MS = 2 * 60 * 1000;
const PING_TIMEOUT_MS = 4_000;
let lastWasAwake: boolean | null = null;
async function pingIfActive(hasConnectedClient: () => boolean): Promise<void> {
if (!hasConnectedClient()) return;
let endpoint = '';
try {
const raw = getConfig().getConfig() as any;
if (raw?.llm?.provider !== 'ollama_local') return;
endpoint = String(raw?.llm?.providers?.ollama_local?.endpoint || '').trim();
} catch { return; }
if (!endpoint) return;
try {
const res = await fetch(`${endpoint}/api/tags`, { signal: AbortSignal.timeout(PING_TIMEOUT_MS) });
const text = await res.text();
const awake = !text.trimStart().startsWith('<'); // wol-gate's "waking up" page is HTML
if (awake !== lastWasAwake) {
console.log(`[ollama-local-keepalive] ${awake ? '지서버 응답 확인 (깨어있음)' : '지서버 무응답 — 절전 상태로 추정'}`);
}
lastWasAwake = awake;
} catch {
if (lastWasAwake !== false) console.log('[ollama-local-keepalive] ping failed — 지서버 무응답');
lastWasAwake = false;
}
}
export function startOllamaLocalKeepAlive(hasConnectedClient: () => boolean): NodeJS.Timeout {
return setInterval(() => { pingIfActive(hasConnectedClient); }, KEEPALIVE_INTERVAL_MS);
}
-3
View File
@@ -107,7 +107,6 @@ import {
import { getPaths } from '../config/paths';
import { getVault, SecretValue } from '../security/vault';
import { getOllamaClient } from '../agents/ollama-client';
import { startOllamaLocalKeepAlive } from './ollama-local-keepalive';
import { spawnAgent } from '../agents/spawner';
import { getSession, addMessage, getHistory, getHistoryForApiCall, getWorkspace, setWorkspace, clearHistory, setContextTokens, cleanupSessions, cleanupEmptySessions, migrateGlobalSessionsToUser, listAllSessions, resolveNumCtx, activeOllamaEndpoint } from './session';
import { hookBus } from './hooks/hooks';
@@ -4708,8 +4707,6 @@ const wsPingInterval = setInterval(() => {
});
}, 30000);
const ollamaLocalKeepAliveInterval = startOllamaLocalKeepAlive(() => !!wss && wss.clients.size > 0);
server.on('error', (err: any) => {
if (err?.code === 'EADDRINUSE') {
console.error(`[Gateway] Port ${HOST}:${PORT} is already in use.`);