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: track executor listener reference (not just flag) so tests can reset cleanly

Adam Eivy12bb7ec232f7
diff --git a/server/services/agentActionExecutor.js b/server/services/agentActionExecutor.js
index 543bf8a613..2d6904314f 100644
--- a/server/services/agentActionExecutor.js
+++ b/server/services/agentActionExecutor.js
@@ -568,16 +568,16 @@ async function executeMoltworldInteract(client, account, params) {
* Initialize the action executor
* Listens to scheduler events and executes actions
*/
-let executeListenerRegistered = false;
+let executeListener = null;
export function init() {
- // Prevent duplicate listeners from THIS module specifically; a plain
- // listenerCount check would false-positive if another module also subscribes
- // to the `execute` event.
- if (executeListenerRegistered) return;
- executeListenerRegistered = true;
+ // Prevent duplicate listeners from THIS module specifically. Tracking our
+ // own handler (rather than counting all `execute` listeners) avoids both
+ // a false-positive skip when another module subscribes to the same event
+ // and a stale-flag skip when tests call `removeAllListeners()` between cases.
+ if (executeListener && scheduleEvents.listeners('execute').includes(executeListener)) return;
- scheduleEvents.on('execute', ({ scheduleId, schedule, timestamp }) => {
+ executeListener = ({ scheduleId, schedule, timestamp }) => {
(async () => {
console.log(`⚡ Executing scheduled action: ${schedule.action.type} (${scheduleId})`);
@@ -669,7 +669,8 @@ export function init() {
})().catch(err => {
console.error(`❌ Unhandled error in execute listener for schedule ${scheduleId}: ${err.message}`);
});
- });
+ };
+ scheduleEvents.on('execute', executeListener);
console.log('⚡ Agent action executor initialized');
}