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

feat(cos): add auto-rehabilitation for skipped task types

Adam Eivyf297f42a39e4
diff --git a/.changelog/v0.10.x.md b/.changelog/v0.10.x.md
index ed886b7c4f..d1960abc9a 100644
--- a/.changelog/v0.10.x.md
+++ b/.changelog/v0.10.x.md
@@ -131,6 +131,13 @@ This release introduces a structured changelog documentation system for creating
- **API Endpoint**: New `POST /api/cos/learning/reset/:taskType` endpoint for programmatic access
- **Test Coverage**: 9 new unit tests covering reset logic, metric subtraction, error pattern cleanup, and edge cases
+### CoS Auto-Rehabilitation for Skipped Task Types
+- **Automatic Retry of Fixed Tasks**: Task types that were auto-paused due to poor performance (<30% success rate after 5+ attempts) are now automatically given a fresh chance after a configurable grace period (default: 7 days)
+- **Grace Period Configuration**: New `rehabilitationGracePeriodDays` config option allows tuning how long skipped tasks wait before being retried
+- **Periodic Rehabilitation Check**: During task evaluation, CoS checks every ~100 evaluations (~2 hours) for task types eligible for rehabilitation
+- **Learning Data Reset**: When a task type is rehabilitated, its historical learning data is reset, giving it a clean slate to prove the underlying issue was fixed
+- **Status Visibility**: New `getSkippedTaskTypesWithStatus()` function provides detailed info about skipped tasks including days until rehabilitation eligibility
+
## 🔧 Improvements
### Release Process
diff --git a/server/services/cos.js b/server/services/cos.js
index 29f5c999d5..9ac9eaa64c 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -17,7 +17,7 @@ import { getActiveProvider } from './providers.js';
import { parseTasksMarkdown, groupTasksByStatus, getNextTask, getAutoApprovedTasks, getAwaitingApprovalTasks, updateTaskStatus, generateTasksMarkdown } from '../lib/taskParser.js';
import { isAppOnCooldown, getNextAppForReview, markAppReviewStarted, markIdleReviewStarted } from './appActivity.js';
import { getAllApps } from './apps.js';
-import { getAdaptiveCooldownMultiplier, getSkippedTaskTypes, getPerformanceSummary } from './taskLearning.js';
+import { getAdaptiveCooldownMultiplier, getSkippedTaskTypes, getPerformanceSummary, checkAndRehabilitateSkippedTasks } from './taskLearning.js';
const execAsync = promisify(exec);
@@ -101,6 +101,7 @@ const DEFAULT_CONFIG = {
comprehensiveAppImprovement: true, // Use comprehensive analysis for managed apps (same as PortOS self-improvement)
immediateExecution: true, // Execute new tasks immediately, don't wait for interval
proactiveMode: true, // Be proactive about finding work
+ rehabilitationGracePeriodDays: 7, // Days before auto-retrying skipped task types (learning-based)
autoFixThresholds: {
maxLinesChanged: 50, // Auto-approve if <= this many lines changed
allowedCategories: [ // Categories that can auto-execute
@@ -593,6 +594,18 @@ export async function evaluateTasks() {
}
}
+ // Periodically check for task types eligible for auto-rehabilitation (every 100 evaluations, ~2 hours)
+ // This gives previously-failing task types a fresh chance after their grace period expires
+ if (evalCount % 100 === 0 && evalCount > 0) {
+ const gracePeriodMs = (state.config.rehabilitationGracePeriodDays || 7) * 24 * 60 * 60 * 1000;
+ const rehabilitationResult = await checkAndRehabilitateSkippedTasks(gracePeriodMs).catch(() => ({ count: 0 }));
+ if (rehabilitationResult.count > 0) {
+ emitLog('success', `Auto-rehabilitated ${rehabilitationResult.count} skipped task type(s) for retry`, {
+ rehabilitated: rehabilitationResult.rehabilitated?.map(r => r.taskType) || []
+ });
+ }
+ }
+
// Update evaluation count
await withStateLock(async () => {
const s = await loadState();
diff --git a/server/services/taskLearning.js b/server/services/taskLearning.js
index e54b3e32d1..c631813399 100644
--- a/server/services/taskLearning.js
+++ b/server/services/taskLearning.js
@@ -589,6 +589,108 @@ export async function shouldSkipTaskType(taskType) {
return result.skip;
}
+/**
+ * Check if any skipped task types are eligible for automatic rehabilitation
+ * Task types that have been skipped for a grace period get a "fresh start" opportunity
+ *
+ * Auto-rehabilitation rules:
+ * - Task must have been skipped (success rate < 30% with 5+ attempts)
+ * - Must have been at least rehabilitationGracePeriodMs since last completion
+ * - Reset the task type's learning data to give it a fresh chance
+ *
+ * This allows CoS to automatically retry previously-failing task types
+ * after enough time has passed for fixes to be applied.
+ *
+ * @param {number} gracePeriodMs - Minimum time since last attempt (default: 7 days)
+ * @returns {Object} Summary of rehabilitated task types
+ */
+export async function checkAndRehabilitateSkippedTasks(gracePeriodMs = 7 * 24 * 60 * 60 * 1000) {
+ const data = await loadLearningData();
+ const rehabilitated = [];
+ const now = Date.now();
+
+ for (const [taskType, metrics] of Object.entries(data.byTaskType)) {
+ // Only consider task types that would be skipped (< 30% success with 5+ attempts)
+ if (metrics.completed < 5 || metrics.successRate >= 30) {
+ continue;
+ }
+
+ // Check if enough time has passed since last attempt
+ const lastCompletedTime = metrics.lastCompleted
+ ? new Date(metrics.lastCompleted).getTime()
+ : 0;
+ const timeSinceLastAttempt = now - lastCompletedTime;
+
+ if (timeSinceLastAttempt >= gracePeriodMs) {
+ // This task type is eligible for rehabilitation
+ emitLog('info', `Auto-rehabilitating ${taskType} (was ${metrics.successRate}% success, ${Math.round(timeSinceLastAttempt / (24 * 60 * 60 * 1000))} days since last attempt)`, {
+ taskType,
+ previousSuccessRate: metrics.successRate,
+ previousAttempts: metrics.completed,
+ daysSinceLastAttempt: Math.round(timeSinceLastAttempt / (24 * 60 * 60 * 1000))
+ }, '📚 TaskLearning');
+
+ // Reset this task type's data
+ await resetTaskTypeLearning(taskType);
+
+ rehabilitated.push({
+ taskType,
+ previousSuccessRate: metrics.successRate,
+ previousAttempts: metrics.completed,
+ daysSinceLastAttempt: Math.round(timeSinceLastAttempt / (24 * 60 * 60 * 1000))
+ });
+ }
+ }
+
+ if (rehabilitated.length > 0) {
+ emitLog('success', `Auto-rehabilitated ${rehabilitated.length} skipped task type(s)`, {
+ rehabilitated: rehabilitated.map(r => r.taskType)
+ }, '📚 TaskLearning');
+ }
+
+ return { rehabilitated, count: rehabilitated.length };
+}
+
+/**
+ * Get all skipped task types with their rehabilitation eligibility status
+ * Useful for UI display and debugging
+ * @param {number} gracePeriodMs - Grace period for rehabilitation eligibility
+ * @returns {Array} List of skipped task types with status info
+ */
+export async function getSkippedTaskTypesWithStatus(gracePeriodMs = 7 * 24 * 60 * 60 * 1000) {
+ const data = await loadLearningData();
+ const skipped = [];
+ const now = Date.now();
+
+ for (const [taskType, metrics] of Object.entries(data.byTaskType)) {
+ // Only include task types that would be skipped
+ if (metrics.completed < 5 || metrics.successRate >= 30) {
+ continue;
+ }
+
+ const lastCompletedTime = metrics.lastCompleted
+ ? new Date(metrics.lastCompleted).getTime()
+ : 0;
+ const timeSinceLastAttempt = now - lastCompletedTime;
+ const eligibleForRehabilitation = timeSinceLastAttempt >= gracePeriodMs;
+ const timeUntilEligible = eligibleForRehabilitation
+ ? 0
+ : gracePeriodMs - timeSinceLastAttempt;
+
+ skipped.push({
+ taskType,
+ successRate: metrics.successRate,
+ completed: metrics.completed,
+ lastCompleted: metrics.lastCompleted,
+ daysSinceLastAttempt: Math.round(timeSinceLastAttempt / (24 * 60 * 60 * 1000)),
+ eligibleForRehabilitation,
+ daysUntilEligible: Math.ceil(timeUntilEligible / (24 * 60 * 60 * 1000))
+ });
+ }
+
+ return skipped;
+}
+
/**
* Reset learning data for a specific task type
* Used when a previously-failing task type has been fixed and should be retried