Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: resolve ids the raced pass took from the index before answering a live-id tally (#3508)

[._.]/ Adam Eivy2c5d79a67418
diff --git a/server/services/brainStorage.js b/server/services/brainStorage.js
index 238b44c785..c1cc0fda65 100644
--- a/server/services/brainStorage.js
+++ b/server/services/brainStorage.js
@@ -330,7 +330,15 @@ async function resolveLiveIds(type, attempt) {
if (raced && attempt + 1 < LIVE_ID_MAX_ATTEMPTS) {
return resolveLiveIds(type, attempt + 1);
}
- if (!raced) {
+ if (raced) {
+ // Ceiling reached. The invalidation may also have dropped ids this pass
+ // took FROM the index (so they were never in `unresolved`) — read those
+ // before answering, or a record we merely stopped knowing about would be
+ // reported as not live and undercount the tally.
+ const unknown = ids.filter((id) => !verdicts.has(id) && !index.has(id));
+ const reloaded = await Promise.all(unknown.map((id) => store.loadOne(id)));
+ unknown.forEach((id, i) => verdicts.set(id, isLiveRecord(reloaded[i])));
+ } else {
for (const [id, live] of verdicts) index.set(id, live);
}