everydaycats commited on
Commit
06bf72a
·
verified ·
1 Parent(s): f422954

Update stateManager.js

Browse files
Files changed (1) hide show
  1. stateManager.js +28 -1
stateManager.js CHANGED
@@ -171,6 +171,33 @@ export const StateManager = {
171
  const FOUR_HOURS = 4 * 60 * 60 * 1000;
172
  let count = 0;
173
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  for (const [id, data] of activeProjects.entries()) {
175
  if (now - (data.lastActive || 0) > FOUR_HOURS) {
176
  activeProjects.delete(id);
@@ -179,5 +206,5 @@ export const StateManager = {
179
  }
180
  console.log(`[StateManager] 🧹 Memory Cleanup: Removed ${count} inactive projects.`);
181
  return count;
182
- }
183
  };
 
171
  const FOUR_HOURS = 4 * 60 * 60 * 1000;
172
  let count = 0;
173
 
174
+ for (const [id, data] of activeProjects.entries()) {
175
+ // FIX: If lastActive is missing/undefined/0, reset it to NOW.
176
+ // This prevents the "54 year old project" bug where (now - 0) > 4 hours.
177
+ if (!data.lastActive) {
178
+ console.warn(`[StateManager] ⚠️ Project ${id} missing timestamp. Healing data...`);
179
+ data.lastActive = now;
180
+ continue; // Skip deleting this round
181
+ }
182
+
183
+ if (now - data.lastActive > FOUR_HOURS) {
184
+ console.log(`[StateManager] 🧹 Removing expired project: ${id}`);
185
+ activeProjects.delete(id);
186
+ count++;
187
+ }
188
+ }
189
+
190
+ if (count > 0) {
191
+ console.log(`[StateManager] 🗑️ Cleaned ${count} projects from memory.`);
192
+ }
193
+ return count;
194
+ }
195
+
196
+ /* cleanupMemory: () => {
197
+ const now = Date.now();
198
+ const FOUR_HOURS = 4 * 60 * 60 * 1000;
199
+ let count = 0;
200
+
201
  for (const [id, data] of activeProjects.entries()) {
202
  if (now - (data.lastActive || 0) > FOUR_HOURS) {
203
  activeProjects.delete(id);
 
206
  }
207
  console.log(`[StateManager] 🧹 Memory Cleanup: Removed ${count} inactive projects.`);
208
  return count;
209
+ } */
210
  };