fix: compact() leaves stale thoughts, ingestBatch() is sequential, trimToBudget() iterates unnecessarily #4

Closed
opened 2026-03-06 18:09:20 +00:00 by jason.woltje · 0 comments
Owner

Code review findings — must fix before production use:

1. compact() doesn't clean up summarized thoughts
After writing summary thought, original individual thoughts remain in OpenBrain.
Unbounded storage growth over time; listRecent() returns stale messages already covered by summaries.
Fix: after writing summary, delete or mark the thoughts that were summarized.

2. ingestBatch() is sequential
Awaits each ingest() call in a for loop. Bootstrapping 50 messages = 50 serial HTTP calls.
Fix: use Promise.all (with concurrency cap e.g. p-limit or simple batching).

3. trimToBudget() skips instead of stops
Uses continue instead of break when a message exceeds budget.
Iterates full array unnecessarily when budget is exhausted early.
Fix: break on first message that won't fit (iterating newest-to-oldest).

Code review findings — must fix before production use: **1. compact() doesn't clean up summarized thoughts** After writing summary thought, original individual thoughts remain in OpenBrain. Unbounded storage growth over time; listRecent() returns stale messages already covered by summaries. Fix: after writing summary, delete or mark the thoughts that were summarized. **2. ingestBatch() is sequential** Awaits each ingest() call in a for loop. Bootstrapping 50 messages = 50 serial HTTP calls. Fix: use Promise.all (with concurrency cap e.g. p-limit or simple batching). **3. trimToBudget() skips instead of stops** Uses continue instead of break when a message exceeds budget. Iterates full array unnecessarily when budget is exhausted early. Fix: break on first message that won't fit (iterating newest-to-oldest).
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaicstack/openclaw-openbrain-context#4