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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix(cos): deduplicate consecutive identical decisions in decision log
Adam Eivyb8284707812a
diff --git a/.changelog/v0.18.x.md b/.changelog/v0.18.x.mdindex 3905afb879..ac52cba093 100644--- a/.changelog/v0.18.x.md+++ b/.changelog/v0.18.x.md@@ -16,3 +16,13 @@ Continued reliability improvements and codebase hardening.### Fix parseInt missing radix parameter (S10 complete)- Added explicit radix (base 10) to all `parseInt()` calls across the codebase — prevents subtle bugs when parsing strings with leading zeros or unexpected prefixes- Fixed 45+ call sites across 18 files: routes (notifications, detect, logs, genome, brain, scripts, cos, ports, agents, apps, history, memory), services (streamingDetect, digital-twin), client components (Apps, CreateApp, SchedulesTab, WorldTab, AIProviders, ConfigRow, ProductivityTab, DocumentsTab, OverviewTab), and tests++### Deduplicate consecutive identical decisions in CoS decision log+- Consecutive identical decisions (same type + reason) are now collapsed into a single entry with an incrementing `count` field — previously, repetitive idle/not_due entries every 60 seconds filled the 200-entry buffer within ~100 minutes, pushing out meaningful decisions+- UI shows repeat count (e.g., "142x") on collapsed entries so the user can still see how often a decision recurred+- Summary counts now reflect actual decision occurrences, not just collapsed entry count+- Meaningful decisions (task_selected, task_skipped, task_switched, rehabilitation) survive much longer in history since they're no longer evicted by noise++### Mark S8 and S9 as complete in PLAN.md+- S8 (cron parser iteration limit) was already implemented: `MAX_CRON_ITERATIONS`, `validateCronFieldRange()`, early null return+- S9 (validation boilerplate extraction) was already implemented: `validateRequest()` helper used across 80 call sites in 12 route filesdiff --git a/PLAN.md b/PLAN.mdindex 028a7341e0..307a92b162 100644--- a/PLAN.md+++ b/PLAN.md@@ -185,17 +185,15 @@ PortOS is an internal/VPN app so auth, CORS, rate limiting, and HTTPS are out of- Fixed: replaced bare `JSON.parse` with `safeJSONParse` from `lib/fileUtils.js` in 7 files (8 call sites): `agentContentGenerator.js`, `pm2Standardizer.js`, `automationScheduler.js`, `git.js` (2), `aiDetect.js`, `memoryClassifier.js`, `clinvar.js`- `digital-twin.js` and `cos.js` were already using `safeJSONParse`-### S8: Add iteration limit to cron parser-- `eventScheduler.js` loops minute-by-minute for up to 2 years — invalid cron expressions cause CPU spin-- Add max iteration count and validate cron fields upfront-- **File:** `server/services/eventScheduler.js:53-62`-- **Complexity:** Simple--### S9: Extract validation boilerplate to helper-- Same 6-line validation-error block duplicated 74+ times across all route files-- Extract to `lib/validation.js` `validateRequest(schema, data)` helper-- **Files:** All `server/routes/*.js`-- **Complexity:** Simple (but wide)+### ~~S8: Add iteration limit to cron parser~~ ✅ COMPLETE+- ~~`eventScheduler.js` loops minute-by-minute for up to 2 years — invalid cron expressions cause CPU spin~~+- Fixed: `MAX_CRON_ITERATIONS = 525960` iteration counter, `validateCronFieldRange()` upfront validation, early `null` return on invalid expressions+- **File:** `server/services/eventScheduler.js`++### ~~S9: Extract validation boilerplate to helper~~ ✅ COMPLETE+- ~~Same 6-line validation-error block duplicated 74+ times across all route files~~+- Fixed: `validateRequest(schema, data)` helper in `lib/validation.js` now used across 80 call sites in 12 route files+- **Files:** `server/lib/validation.js`, all `server/routes/*.js`### ~~S10: Fix parseInt missing radix~~ ✅ COMPLETE (v0.18.x)- ~~Several parseInt calls lack explicit radix 10~~diff --git a/client/src/components/DecisionLogWidget.jsx b/client/src/components/DecisionLogWidget.jsxindex 9e9728c004..bf93b336db 100644--- a/client/src/components/DecisionLogWidget.jsx+++ b/client/src/components/DecisionLogWidget.jsx@@ -185,7 +185,12 @@ const DecisionLogWidget = memo(function DecisionLogWidget() {{decision.reason}</p><div className="text-xs text-gray-500 mt-0.5">- {formatRelativeTime(decision.timestamp)}+ {formatRelativeTime(decision.lastTimestamp || decision.timestamp)}+ {(decision.count || 1) > 1 && (+ <span className="ml-2 text-gray-400">+ ({decision.count}x)+ </span>+ )}{decision.context?.successRate !== undefined && (<span className="ml-2">Success rate: {decision.context.successRate}%diff --git a/server/services/decisionLog.js b/server/services/decisionLog.jsindex da452af8ca..15078444a8 100644--- a/server/services/decisionLog.js+++ b/server/services/decisionLog.js@@ -76,6 +76,11 @@ async function saveDecisions(data) {/*** Record a decision+ * Consecutive identical decisions (same type + reason) are collapsed into a+ * single entry with an incrementing `count` field. This keeps the 200-entry+ * buffer focused on meaningful decisions instead of flooding it with+ * repetitive idle/not_due entries every evaluation cycle.+ ** @param {string} type - Decision type from DECISION_TYPES* @param {string} reason - Human-readable reason* @param {Object} context - Additional context (taskType, successRate, etc.)@@ -83,11 +88,29 @@ async function saveDecisions(data) {export async function recordDecision(type, reason, context = {}) {const data = await loadDecisions();+ // Collapse consecutive identical decisions (same type + reason)+ const prev = data.decisions[0];+ if (prev && prev.type === type && prev.reason === reason) {+ prev.count = (prev.count || 1) + 1;+ prev.lastTimestamp = new Date().toISOString();+ // Keep context from latest occurrence+ prev.context = context;++ // Update stats+ data.stats.totalDecisions++;+ data.stats.byType[type] = (data.stats.byType[type] || 0) + 1;++ await saveDecisions(data);+ cosEvents.emit('decision', { ...prev });+ return prev;+ }+const decision = {id: `dec-${Date.now().toString(36)}-${Math.random().toString(36).substr(2, 4)}`,type,reason,context,+ count: 1,timestamp: new Date().toISOString()};@@ -135,16 +158,17 @@ export async function getRecentDecisions(limit = 20, type = null) {export async function getDecisionSummary() {const data = await loadDecisions();- // Get decisions from last 24 hours+ // Get decisions from last 24 hours (use lastTimestamp for collapsed entries)const oneDayAgo = Date.now() - 24 * 60 * 60 * 1000;- const recentDecisions = data.decisions.filter(- d => new Date(d.timestamp).getTime() > oneDayAgo- );+ const recentDecisions = data.decisions.filter(d => {+ const ts = new Date(d.lastTimestamp || d.timestamp).getTime();+ return ts > oneDayAgo;+ });- // Group by type+ // Group by type, using collapsed countconst byType = {};for (const d of recentDecisions) {- byType[d.type] = (byType[d.type] || 0) + 1;+ byType[d.type] = (byType[d.type] || 0) + (d.count || 1);}// Get impactful decisions (skips, switches, capacity issues, cooldowns)@@ -168,9 +192,12 @@ export async function getDecisionSummary() {? Math.round((explainedCount / totalRecent) * 100): 100;+ // Total is the sum of collapsed counts, not just entry count+ const totalOccurrences = recentDecisions.reduce((sum, d) => sum + (d.count || 1), 0);+return {last24Hours: {- total: recentDecisions.length,+ total: totalOccurrences,byType,skipped: byType[DECISION_TYPES.TASK_SKIPPED] || 0,switched: byType[DECISION_TYPES.TASK_SWITCHED] || 0,