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 truncated memory and double script execution issues

Adam Eivy780ef4e7de39
diff --git a/server/services/memoryExtractor.js b/server/services/memoryExtractor.js
index 534c82ed9f..f95c73c163 100644
--- a/server/services/memoryExtractor.js
+++ b/server/services/memoryExtractor.js
@@ -131,11 +131,15 @@ function extractPatterns(output) {
}
// Pattern: "already well-optimized" / "already has excellent" / "already implemented"
- const alreadyWorkingRegex = /(?:already|currently)\s+(?:has\s+)?(?:excellent|good|great|proper|well[- ]?optimized|well[- ]?implemented|working\s+well|fully\s+implemented)\s+([^\n.]+)/gi;
+ // Exclude colons to prevent truncated memories like "Already has excellent responsive design:"
+ const alreadyWorkingRegex = /(?:already|currently)\s+(?:has\s+)?(?:excellent|good|great|proper|well[- ]?optimized|well[- ]?implemented|working\s+well|fully\s+implemented)\s+([^\n.:]+)/gi;
while ((match = alreadyWorkingRegex.exec(output)) !== null) {
+ const captured = match[1].trim();
+ // Skip if capture is too short or empty
+ if (captured.length < 5) continue;
memories.push({
type: 'fact',
- content: `Already has excellent ${match[1].trim()}`,
+ content: `Already has excellent ${captured}`,
confidence: 0.85,
category: 'codebase',
tags: ['existing-feature', 'no-action-needed']
diff --git a/server/services/scriptRunner.js b/server/services/scriptRunner.js
index 4715158382..0bcd3b993c 100644
--- a/server/services/scriptRunner.js
+++ b/server/services/scriptRunner.js
@@ -22,6 +22,9 @@ const SCRIPTS_STATE_FILE = join(__dirname, '../../data/cos/scripts-state.json');
// Active scheduled jobs
const scheduledJobs = new Map();
+// Execution lock to prevent duplicate runs (tracks last execution time)
+const executionLock = new Map();
+
// Allowlist of safe commands for scripts (mirrors commands.js allowlist)
const ALLOWED_SCRIPT_COMMANDS = new Set([
'npm', 'npx', 'pnpm', 'yarn', 'bun',
@@ -306,10 +309,20 @@ export async function listScripts() {
* Execute a script
*/
export async function executeScript(scriptId) {
+ // De-duplication: prevent duplicate execution within 5 seconds
+ const now = Date.now();
+ const lastExecution = executionLock.get(scriptId);
+ if (lastExecution && (now - lastExecution) < 5000) {
+ console.log(`⏭️ Skipping duplicate execution of ${scriptId} (last run ${now - lastExecution}ms ago)`);
+ return { success: false, error: 'Duplicate execution prevented', skipped: true };
+ }
+ executionLock.set(scriptId, now);
+
const state = await loadScriptsState();
const script = state.scripts[scriptId];
if (!script) {
+ executionLock.delete(scriptId);
return { success: false, error: 'Script not found' };
}
@@ -318,6 +331,7 @@ export async function executeScript(scriptId) {
const validation = validateScriptCommand(script.command);
if (!validation.valid) {
console.error(`❌ Script ${script.name} has invalid command: ${validation.error}`);
+ executionLock.delete(scriptId);
return { success: false, error: `Invalid command: ${validation.error}` };
}
@@ -359,6 +373,9 @@ export async function executeScript(scriptId) {
state.scripts[scriptId] = script;
await saveScriptsState(state);
+ // Clear execution lock after completion
+ executionLock.delete(scriptId);
+
console.log(`✅ Script ${script.name} completed with code ${code} in ${duration}ms`);
// Handle trigger action
@@ -407,6 +424,9 @@ export async function executeScript(scriptId) {
state.scripts[scriptId] = script;
await saveScriptsState(state);
+ // Clear execution lock on error
+ executionLock.delete(scriptId);
+
cosEvents.emit('script:error', { scriptId, error: err.message });
resolve({