This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

fix: preserve summaries + strata across cache rebuilds

On rebuild, compute the new lexmin-hash ID for each old island
and carry forward its summary and strata data to the new row.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>

author
nandi
co-author
Letta Code
date (May 13, 2026, 5:30 AM UTC) commit 221079b7 parent 8f6c8a8d
+27 -12
+27 -12
src/worker.ts
··· 231 231 }); 232 232 } 233 233 234 - // Preserve existing summaries across rebuild 234 + // Preserve existing summaries + strata across rebuild 235 + // Match by lexmin vertex: since the ID is sha256(lexmin)[:16], we can 236 + // match old rows to new islands by computing the new ID from the old data. 235 237 const existing = await db 236 - .prepare("SELECT id, summary FROM island_cache") 237 - .all<{ id: string; summary: string | null }>(); 238 - const summaries = new Map<string, string>(); 238 + .prepare("SELECT id, data, summary, strata FROM island_cache") 239 + .all<{ id: string; data: string; summary: string | null; strata: string | null }>(); 240 + 241 + const preserved = new Map<string, { summary: string | null; strata: string | null }>(); 239 242 for (const row of existing.results || []) { 240 - if (row.summary) summaries.set(row.id, row.summary); 243 + try { 244 + const oldIsland = JSON.parse(row.data); 245 + const oldLexmin = oldIsland.vertices?.sort()?.[0]; 246 + if (!oldLexmin) continue; 247 + // Compute the new ID for this old island 248 + const hash = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(oldLexmin)); 249 + const newId = Array.from(new Uint8Array(hash)).map(b => b.toString(16).padStart(2, "0")).join("").slice(0, 16); 250 + if (row.summary || row.strata) { 251 + preserved.set(newId, { summary: row.summary, strata: row.strata }); 252 + } 253 + } catch {} 241 254 } 242 255 243 256 const now = Date.now() * 1000; ··· 245 258 // Clear old cache and write new 246 259 await db.prepare("DELETE FROM island_cache").run(); 247 260 248 - const stmts = enriched.map(island => 249 - db 261 + const stmts = enriched.map(island => { 262 + const saved = preserved.get(island.id); 263 + return db 250 264 .prepare( 251 - `INSERT INTO island_cache (id, vertex_count, edge_count, data, summary, updated_at) 252 - VALUES (?, ?, ?, ?, ?, ?)`, 265 + `INSERT INTO island_cache (id, vertex_count, edge_count, data, summary, strata, updated_at) 266 + VALUES (?, ?, ?, ?, ?, ?, ?)`, 253 267 ) 254 268 .bind( 255 269 island.id, 256 270 island.vertices.length, 257 271 island.edges.length, 258 272 JSON.stringify(island), 259 - summaries.get(island.id) || null, 273 + saved?.summary || null, 274 + saved?.strata || null, 260 275 now, 261 - ), 262 - ); 276 + ); 277 + }); 263 278 264 279 // D1 supports batched statements 265 280 if (stmts.length > 0) {