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: throttle LLM drill cache and JIRA sync to prevent API rate limiting

Adam Eivyc4537abea680
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 9d207fc58f..163430af80 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -1,6 +1,8 @@
### Fixed
- Job scheduling now uses user's configured timezone instead of UTC — daily briefing and all scheduled jobs fire at the correct local time
- Briefing notification date uses user timezone instead of UTC date
+- Throttle LLM drill cache startup: serialize type replenishment and add 2s delay between LLM calls to prevent API spam on server restart
+- Throttle JIRA sync: add 500ms delay between project ticket fetches to prevent 429 rate limit errors
### Added
- Character Sheet page: D&D-style character tracking with XP, HP, leveling, dice-based damage, short/long rests, custom event logging, and JIRA/CoS task sync for XP
diff --git a/server/services/character.js b/server/services/character.js
index eca2ed4c02..65673acddc 100644
--- a/server/services/character.js
+++ b/server/services/character.js
@@ -179,6 +179,8 @@ export async function addEvent(event) {
return { character, event: logEntry, leveledUp };
}
+const delay = ms => new Promise(r => setTimeout(r, ms));
+
export async function syncJiraXP() {
const character = await getCharacter();
const config = await jiraService.getInstances();
@@ -195,7 +197,9 @@ export async function syncJiraXP() {
continue;
}
- for (const project of projects) {
+ for (let i = 0; i < projects.length; i++) {
+ if (i > 0) await delay(500); // Rate-limit JIRA API calls
+ const project = projects[i];
let tickets;
try {
tickets = await jiraService.getMyCurrentSprintTickets(instanceId, project.key);
diff --git a/server/services/meatspacePostDrillCache.js b/server/services/meatspacePostDrillCache.js
index c9ade50988..58c796ac3d 100644
--- a/server/services/meatspacePostDrillCache.js
+++ b/server/services/meatspacePostDrillCache.js
@@ -57,6 +57,8 @@ function replenishType(type, providerId, model) {
let consecutiveFailures = 0;
try {
for (let i = 0; i < needed; i++) {
+ // Pause between LLM calls to avoid rate limiting
+ if (i > 0) await new Promise(r => setTimeout(r, 2000));
const drill = await generateLlmDrill(type, { count: 5 }, providerId, model).catch(err => {
console.log(`⚠️ POST cache: failed to generate ${type}: ${err.message}`);
return null;
@@ -117,16 +119,25 @@ export function getCacheStats() {
}
/**
- * Initialize cache: load from disk, start background fill for empty types.
+ * Initialize cache: load from disk, start sequential background fill for low types.
*/
export async function initDrillCache(providerId, model) {
await loadCache();
const stats = CACHEABLE_TYPES.map(t => `${t}:${cache[t]?.length || 0}`).join(' ');
console.log(`📦 POST drill cache loaded: ${stats}`);
- for (const type of CACHEABLE_TYPES) {
- if ((cache[type]?.length || 0) < MIN_PER_TYPE) {
- replenishType(type, providerId, model);
- }
+ // Fill types sequentially (not in parallel) to avoid LLM API spam on startup
+ const lowTypes = CACHEABLE_TYPES.filter(t => (cache[t]?.length || 0) < MIN_PER_TYPE);
+ if (lowTypes.length > 0) {
+ console.log(`📦 POST cache: queuing startup fill for ${lowTypes.length} types`);
+ (async () => {
+ for (const type of lowTypes) {
+ replenishType(type, providerId, model);
+ // Wait for this type to finish before starting the next
+ while (replenishing.has(type)) {
+ await new Promise(r => setTimeout(r, 1000));
+ }
+ }
+ })();
}
}