fix(panel): harden SQLite ledger concurrency, LRU sizing, and recovery

- Preserve step detail_json and peer-appended rows during cold metadata flushes, slim-step spreads, and mixed-case UUID re-keying without triggering case-insensitive self-deletion
- Raise default hot session LRU limit to 64 and prime stepSigs during on-demand hydration to avoid cyclic read thrashing across 30-session quick stats plus active subagents
- Quarantine corrupt SQLite images to .corrupt.<ts> with automatic .json.bak recovery and defer latching loadedOnce until initial hydration succeeds
- Flush pending throttled endpoint caches on worker/standalone stop, isolate unscoped node --test runs from live user data, and transitively retain nested subagents and side questions on cache rebuilds
This commit is contained in:
fish
2026-11-24 15:04:14 +09:00
parent 030d894988
commit 173e21c607
8 changed files with 381 additions and 49 deletions
@@ -20,7 +20,7 @@ import {
} from './trajectory-sqlite-ledger.mjs';
export const CACHE_RUNNING_SAVE_INTERVAL_MS = 30_000;
export const DEFAULT_HOT_SESSION_LRU_LIMIT = 24;
export const DEFAULT_HOT_SESSION_LRU_LIMIT = 64;
const TCS_WAL_SYNC_MIN_INTERVAL_MS = 250;
function tcsMarkColdSlimSteps(steps) {
@@ -242,18 +242,22 @@ export function createTrajectoryCacheStore({
function ensureLoaded() {
if (loadedOnce) return;
loadedOnce = true;
if (useSqlite && sqliteLedger) {
const hydrated = sqliteLedger.openAndHydrateInitial();
cacheObj = hydrated.cacheObj;
loadedOnce = true;
rebuildLowerIndexFromCacheObj(true);
lastWalSyncCheckMs = Date.now();
return;
}
if (!cacheFilePath || typeof loadJsonFn !== 'function') return;
if (!cacheFilePath || typeof loadJsonFn !== 'function') {
loadedOnce = true;
return;
}
const loaded = loadJsonFn(cacheFilePath, {});
const hydrated = hydrateTrajectoryCacheObject(loaded);
cacheObj = hydrated.cacheObj;
loadedOnce = true;
for (const key of Object.keys(cacheObj)) {
byLower.set(key.toLowerCase(), key);
}