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

address review (codex): serialize multi-type cache fills

[._.]/ Adam Eivy5f9d9dfab84f
diff --git a/server/services/meatspacePostDrillCache.js b/server/services/meatspacePostDrillCache.js
index 5dfe2d5a55..ce98e8c74c 100644
--- a/server/services/meatspacePostDrillCache.js
+++ b/server/services/meatspacePostDrillCache.js
@@ -177,12 +177,21 @@ export function getCacheStats() {
* fill (0 -> MAX_PER_TYPE). Called from the drill-cache/fill route after the
* user has been prompted and picked a provider/model. See PortOS's
* no-cold-bootstrap-LLM-calls rule in CLAUDE.md.
+ *
+ * Types are filled sequentially, not in parallel — a single consented "fill
+ * all" request must not turn into several concurrent LLM batches hammering
+ * the provider at once (the old startup fill had this same rule; consent
+ * gating the request doesn't excuse spamming a slow/TUI provider once it's
+ * granted). Fire-and-forget from the caller's perspective: the requested
+ * type list is returned immediately, the fills run in the background.
*/
export function requestCacheFill(types, providerId, model) {
const requested = (types?.length ? types : CACHEABLE_TYPES).filter(t => CACHEABLE_TYPES.includes(t));
- for (const type of requested) {
- replenishType(type, providerId, model);
- }
+ (async () => {
+ for (const type of requested) {
+ await replenishType(type, providerId, model);
+ }
+ })().catch(err => console.error(`❌ POST cache: requestCacheFill failed: ${err.message}`));
return requested;
}
diff --git a/server/services/meatspacePostDrillCache.test.js b/server/services/meatspacePostDrillCache.test.js
index 294a19e4e9..a4a2325e52 100644
--- a/server/services/meatspacePostDrillCache.test.js
+++ b/server/services/meatspacePostDrillCache.test.js
@@ -86,6 +86,21 @@ describe('meatspacePostDrillCache', () => {
expect(triggered).toEqual([]);
});
+ it('requestCacheFill fills multiple types sequentially, not concurrently — avoids spamming the provider with parallel batches', async () => {
+ requestCacheFill(['compound-chain', 'bridge-word'], null, null);
+
+ // Only the first type's initial (no-delay) call should have fired yet —
+ // a second type's batch must not start until the first type's full
+ // MAX_PER_TYPE batch (up to 10 sequential calls, 2s apart) completes.
+ await vi.advanceTimersByTimeAsync(0);
+ expect(generateLlmDrill).toHaveBeenCalledWith('compound-chain', expect.anything(), null, null);
+ expect(generateLlmDrill).not.toHaveBeenCalledWith('bridge-word', expect.anything(), null, null);
+
+ await vi.advanceTimersByTimeAsync(40000);
+ expect(getCacheStats()['compound-chain'].cold).toBe(false);
+ expect(getCacheStats()['bridge-word'].cold).toBe(false);
+ });
+
it('saveCache persists primedTypes alongside the drills so a restart mid-drain stays warm', async () => {
const { atomicWrite } = await import('../lib/fileUtils.js');
requestCacheFill(['compound-chain'], null, null);