Skip to content

Commit 0e31ea9

Browse files
committed
fix: persist session dev snapshot cache to disk
1 parent c6f5078 commit 0e31ea9

1 file changed

Lines changed: 31 additions & 3 deletions

File tree

frontend/dev/sessionManagementDevData.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,31 @@ let snapshotCache = null;
1212
let snapshotCacheUpdatedAt = 0;
1313
let snapshotRefreshPromise = null;
1414

15+
function resolveSnapshotCachePath() {
16+
return path.join(resolveCodexHome(), '.gettokens-session-management-snapshot-cache.json');
17+
}
18+
19+
async function hydrateSnapshotCacheFromDisk() {
20+
try {
21+
const raw = await fs.readFile(resolveSnapshotCachePath(), 'utf8');
22+
const parsed = JSON.parse(raw);
23+
if (parsed && Array.isArray(parsed.projects)) {
24+
snapshotCache = parsed;
25+
snapshotCacheUpdatedAt = Date.now();
26+
}
27+
} catch {
28+
// Ignore cache hydration failures.
29+
}
30+
}
31+
32+
async function persistSnapshotCacheToDisk(snapshot) {
33+
try {
34+
await fs.writeFile(resolveSnapshotCachePath(), JSON.stringify(snapshot), 'utf8');
35+
} catch {
36+
// Ignore disk cache failures.
37+
}
38+
}
39+
1540
function resolveCodexHome() {
1641
return process.env.CODEX_HOME || path.join(os.homedir(), '.codex');
1742
}
@@ -390,6 +415,7 @@ async function refreshSnapshotCache() {
390415
.then((snapshot) => {
391416
snapshotCache = snapshot;
392417
snapshotCacheUpdatedAt = Date.now();
418+
void persistSnapshotCacheToDisk(snapshot);
393419
return snapshot;
394420
})
395421
.finally(() => {
@@ -425,6 +451,8 @@ export async function loadSessionManagementDetail(sessionID) {
425451
return (await parseSessionFile(codexHome, absolutePath)).detail;
426452
}
427453

428-
void refreshSnapshotCache().catch(() => {
429-
// Warm cache in the background for browser dev sessions.
430-
});
454+
void hydrateSnapshotCacheFromDisk()
455+
.finally(() => refreshSnapshotCache())
456+
.catch(() => {
457+
// Warm cache in the background for browser dev sessions.
458+
});

0 commit comments

Comments
 (0)