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: fix eviction index bug, timer cleanup, JSON extraction

Adam Eivy4684c051f04d
diff --git a/server/services/moltworldQueue.js b/server/services/moltworldQueue.js
index 06b36f8283..ebfd7a2b21 100644
--- a/server/services/moltworldQueue.js
+++ b/server/services/moltworldQueue.js
@@ -29,18 +29,10 @@ function getOrCreateQueue(agentId) {
function evictCompleted(queue) {
if (queue.length <= MAX_ITEMS_PER_AGENT) return;
- // Remove oldest completed/failed items first
- const completedIndices = [];
- for (let i = 0; i < queue.length; i++) {
+ // Remove oldest completed/failed items first, iterating in reverse to avoid index shifting
+ for (let i = queue.length - 1; i >= 0 && queue.length > MAX_ITEMS_PER_AGENT; i--) {
if (queue[i].status === 'completed' || queue[i].status === 'failed') {
- completedIndices.push(i);
- }
- }
- while (queue.length > MAX_ITEMS_PER_AGENT && completedIndices.length > 0) {
- queue.splice(completedIndices.shift(), 1);
- // Adjust remaining indices
- for (let j = 0; j < completedIndices.length; j++) {
- completedIndices[j]--;
+ queue.splice(i, 1);
}
}
}
diff --git a/server/services/pm2.js b/server/services/pm2.js
index bb050246da..633c65fb58 100644
--- a/server/services/pm2.js
+++ b/server/services/pm2.js
@@ -187,8 +187,7 @@ export async function getAppStatus(name, pm2Home = null) {
// pm2 jlist may output ANSI codes and warnings before JSON
let jsonStart = stdout.indexOf('[{');
if (jsonStart < 0) {
- const emptyMatch = stdout.match(/\[\](?![0-9])/);
- jsonStart = emptyMatch ? stdout.indexOf(emptyMatch[0]) : -1;
+ jsonStart = stdout.lastIndexOf('[]');
}
const pm2Json = jsonStart >= 0 ? stdout.slice(jsonStart) : '[]';
const processes = JSON.parse(pm2Json);
diff --git a/server/services/pm2Standardizer.js b/server/services/pm2Standardizer.js
index 5e637a6477..d93969a6d4 100644
--- a/server/services/pm2Standardizer.js
+++ b/server/services/pm2Standardizer.js
@@ -168,11 +168,12 @@ async function executeCliAnalysis(provider, prompt, cwd) {
const args = [...(provider.args || []), prompt];
let output = '';
let settled = false;
+ let timer = null;
const settle = (fn, value) => {
if (settled) return;
settled = true;
- clearTimeout(timer);
+ if (timer) clearTimeout(timer);
fn(value);
};
@@ -201,7 +202,7 @@ async function executeCliAnalysis(provider, prompt, cwd) {
child.on('error', (err) => settle(reject, err));
const timeoutMs = provider.timeout || 180000;
- const timer = setTimeout(() => {
+ timer = setTimeout(() => {
console.log(`⏰ CLI analysis timed out after ${timeoutMs / 1000}s for: ${provider.command}`);
child.kill();
settle(reject, new Error(`Standardization analysis timed out after ${timeoutMs / 1000}s`));