diff --git a/open-sse/executors/freebuff.js b/open-sse/executors/freebuff.js index 891a44a0..8bbf8d7b 100644 --- a/open-sse/executors/freebuff.js +++ b/open-sse/executors/freebuff.js @@ -369,6 +369,16 @@ export function resetSessionCache() { inflight.clear(); } +// Snapshot sizes of in-memory freebuff state (for the dashboard memory panel). +export function sessionStateSize() { + return { + sessions: sessionCache.size, + inflight: inflight.size, + modelLocks: modelLockCooldowns.size, + poolLimits: poolLimitCooldowns.size, + }; +} + // Periodic sweeper: drop stale session rows + expired cooldowns so long-running // servers never accumulate state for accounts/models no longer in use. // Returns how many entries were removed. diff --git a/src/app/(dashboard)/dashboard/profile/page.js b/src/app/(dashboard)/dashboard/profile/page.js index 4df8cbef..b28d547e 100644 --- a/src/app/(dashboard)/dashboard/profile/page.js +++ b/src/app/(dashboard)/dashboard/profile/page.js @@ -10,6 +10,16 @@ import { APP_CONFIG } from "@/shared/constants/config"; import { LOCALE_COOKIE, normalizeLocale } from "@/i18n/config"; import { LOCALE_FLAGS } from "@/shared/constants/locales"; +function memoryLine(m) { + if (!m) return ""; + const fb = m.inMemory?.freebuff || {}; + return [ + `DB: ${m.dbPath || "-"} (${m.dbSizeMB || "-"})`, + `Data dir: ${m.dataDirSizeMB || "-"}`, + `In-memory: fitness=${m.inMemory?.fitnessPools ?? 0} pool(s) · geo=${m.inMemory?.geoPools ?? 0} pool(s) · freebuff sessions=${fb.sessions ?? 0}, locks=${fb.modelLocks ?? 0}, pool-limits=${fb.poolLimits ?? 0}`, + ].join("\n"); +} + function getLocaleFromCookie() { if (typeof document === "undefined") return "en"; const cookie = document.cookie @@ -49,6 +59,8 @@ export default function ProfilePage() { const [oidcRedirectUri, setOidcRedirectUri] = useState("/api/auth/oidc/callback"); const [oidcExpanded, setOidcExpanded] = useState(false); const importFileRef = useRef(null); + const [memoryInfo, setMemoryInfo] = useState(null); + const [memoryLoading, setMemoryLoading] = useState(false); const [proxyForm, setProxyForm] = useState({ outboundProxyEnabled: false, outboundProxyUrl: "", @@ -563,6 +575,19 @@ export default function ProfilePage() { setShutdownOpen(false); }; + const handleMemoryCheck = async () => { + setMemoryLoading(true); + try { + const res = await fetch("/api/system/memory", { cache: "no-store" }); + if (!res.ok) throw new Error(`HTTP ${res.status}`); + setMemoryInfo(await res.json()); + } catch (err) { + setMemoryInfo({ error: err.message }); + } finally { + setMemoryLoading(false); + } + }; + const handleLogout = async () => { try { const res = await fetch("/api/auth/logout", { method: "POST" }); @@ -649,6 +674,24 @@ export default function ProfilePage() { {dbStatus.message}
)} +
+ {memoryInfo.error
+ ? `Error: ${memoryInfo.error}`
+ : memoryLine(memoryInfo)}
+
+ )}
+