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

address review (claude): align skip-mirroring surfaces and guard destructive rehab on windowed skips

[._.]/ Adam Eivy8e7bc973ba05
diff --git a/server/services/taskLearning/index.js b/server/services/taskLearning/index.js
index 28af8f2f68..181310da7a 100644
--- a/server/services/taskLearning/index.js
+++ b/server/services/taskLearning/index.js
@@ -35,6 +35,7 @@ export {
appendRecentOutcome,
computeWindowedStats,
computeEffectiveSuccessRate,
+ isSkipCandidate,
EFFECTIVE_RATE_MIN_WINDOW_SAMPLES,
RECENT_OUTCOMES_CAP,
DEFAULT_WINDOW_MAX_COUNT,
diff --git a/server/services/taskLearning/insights.js b/server/services/taskLearning/insights.js
index 8d10f6f732..155823cefb 100644
--- a/server/services/taskLearning/insights.js
+++ b/server/services/taskLearning/insights.js
@@ -13,7 +13,9 @@ import {
loadDismissedRecommendations,
saveDismissedRecommendations,
summarizeFailureSignatures,
- appendInsight
+ appendInsight,
+ computeEffectiveSuccessRate,
+ isSkipCandidate
} from './store.js';
import { computeCorrelationQuality, isCorrelationProven, CORRELATION_QUALITY_THRESHOLD } from './correlationQuality.js';
@@ -306,16 +308,22 @@ export async function getLearningSummary() {
let criticalCount = 0;
let skippedCount = 0;
+ // Health tiers read the EFFECTIVE rate (issue #2617) and the skipped count
+ // uses the shared skip predicate, so this dashboard summary — and the
+ // proactive "task types skipped" alert built on it — reflects what the
+ // scheduler actually does. On lifetime rates alone, a type that recovered
+ // in its recent window would be alerted as "skipped" forever.
for (const [, metrics] of Object.entries(data.byTaskType)) {
if (metrics.completed < 3) continue; // Insufficient data
- if (metrics.successRate >= 70) {
+ const { successRate } = computeEffectiveSuccessRate(metrics);
+ if (successRate >= 70) {
healthyCount++;
- } else if (metrics.successRate >= 40) {
+ } else if (successRate >= 40) {
warningCount++;
} else {
criticalCount++;
- if (metrics.completed >= 5 && metrics.successRate < 30) {
+ if (isSkipCandidate(metrics)) {
skippedCount++;
}
}
diff --git a/server/services/taskLearning/insights.test.js b/server/services/taskLearning/insights.test.js
index 1769868a59..3b2f4f6f3a 100644
--- a/server/services/taskLearning/insights.test.js
+++ b/server/services/taskLearning/insights.test.js
@@ -10,7 +10,7 @@ vi.mock('./store.js', async (importOriginal) => {
});
import { loadLearningData, loadDismissedRecommendations } from './store.js';
-import { getLearningInsights } from './insights.js';
+import { getLearningInsights, getLearningSummary } from './insights.js';
const learningData = (overrides = {}) => ({
lastUpdated: '2026-07-09T00:00:00Z',
@@ -101,3 +101,42 @@ describe('insights.getLearningInsights — standing learnings surfacing (issue #
expect(view.standingLearnings).toEqual([]);
});
});
+
+describe('insights.getLearningSummary — effective (windowed) rates (issue #2617)', () => {
+ const ring = (results, now = Date.now()) =>
+ results.map((s, i) => ({ t: new Date(now - (results.length - i) * 60000).toISOString(), s }));
+
+ it('does not count a windowed-recovered type as skipped (no false "critical" alert)', async () => {
+ // Lifetime 27% after a since-fixed bug, 15 recent successes → the
+ // scheduler no longer skips it, so the dashboard/alert summary must not
+ // claim it is skipped either.
+ loadLearningData.mockResolvedValue(learningData({
+ totals: { completed: 55, succeeded: 15, avgDurationMs: 60000 },
+ byTaskType: {
+ 'recovered': {
+ completed: 55, succeeded: 15, failed: 40, successRate: 27,
+ recentOutcomes: ring(Array(15).fill(true))
+ }
+ }
+ }));
+ const summary = await getLearningSummary();
+ expect(summary.skipped).toBe(0);
+ expect(summary.healthy).toBe(1); // windowed 100% ≥ 70
+ expect(summary.status).not.toBe('critical');
+ });
+
+ it('still counts a genuinely failing type as skipped', async () => {
+ loadLearningData.mockResolvedValue(learningData({
+ totals: { completed: 20, succeeded: 2, avgDurationMs: 60000 },
+ byTaskType: {
+ 'still-broken': {
+ completed: 20, succeeded: 2, failed: 18, successRate: 10,
+ recentOutcomes: ring(Array(8).fill(false))
+ }
+ }
+ }));
+ const summary = await getLearningSummary();
+ expect(summary.skipped).toBe(1);
+ expect(summary.status).toBe('critical');
+ });
+});
diff --git a/server/services/taskLearning/routing.js b/server/services/taskLearning/routing.js
index 5734b9cb2f..46c4c98ad2 100644
--- a/server/services/taskLearning/routing.js
+++ b/server/services/taskLearning/routing.js
@@ -9,7 +9,7 @@
* module.
*/
-import { loadLearningData, emitLog, isSandboxedTaskType, computeEffectiveSuccessRate } from './store.js';
+import { loadLearningData, emitLog, isSandboxedTaskType, computeEffectiveSuccessRate, isSkipCandidate } from './store.js';
import { resetTaskTypeLearning } from './metrics.js';
import { computeCorrelationQuality, isCorrelationProven } from './correlationQuality.js';
@@ -308,11 +308,15 @@ export async function suggestModelTier(taskType) {
}
}
- // Fallback: if overall success rate is low, suggest heavier model
- if (metrics.successRate < 60) {
+ // Fallback: if the overall EFFECTIVE success rate is low (issue #2617:
+ // windowed when the ring has enough samples, else lifetime), suggest a
+ // heavier model. On the lifetime rate alone, a type that recovered from a
+ // since-fixed failure burst would be routed to `heavy` forever.
+ const { successRate: effectiveRate } = computeEffectiveSuccessRate(metrics);
+ if (effectiveRate !== null && effectiveRate < 60) {
return withFailureSignal({
suggested: 'heavy',
- reason: `${taskType} has ${metrics.successRate}% success rate - heavier model may help`
+ reason: `${taskType} has ${effectiveRate}% success rate - heavier model may help`
});
}
@@ -424,23 +428,27 @@ export async function getPerformanceSummary() {
skipped: []
};
- // Analyze each task type
+ // Analyze each task type on the EFFECTIVE rate (issue #2617) so this
+ // summary — logged during evaluation and served to the Learning UI — agrees
+ // with the actual cooldown/skip decisions instead of resurrecting the
+ // "punished forever" lifetime view they just stopped using.
for (const [taskType, metrics] of Object.entries(data.byTaskType)) {
if (metrics.completed < 3) continue;
+ const { successRate } = computeEffectiveSuccessRate(metrics);
const entry = {
taskType,
- successRate: metrics.successRate,
+ successRate,
completed: metrics.completed,
avgDurationMin: Math.round(metrics.avgDurationMs / 60000)
};
- if (metrics.successRate >= 80) {
+ if (successRate >= 80) {
summary.topPerformers.push(entry);
- } else if (metrics.successRate < 50 && metrics.completed >= 5) {
+ } else if (successRate !== null && successRate < 50 && metrics.completed >= 5) {
summary.needsAttention.push(entry);
- // Also mark as skipped if very low
- if (metrics.successRate < 30) {
+ // Also mark as skipped if very low (same predicate as getSkippedTaskTypes)
+ if (isSkipCandidate(metrics)) {
summary.skipped.push(entry);
}
}
@@ -570,18 +578,17 @@ export async function getAdaptiveCooldownMultiplier(taskType) {
}
/**
- * Shared skip predicate (issue #2617): a task type is a skip candidate when it
- * has ≥5 lifetime completions AND its EFFECTIVE success rate is <30%. Using the
- * effective rate (windowed when the ring has enough samples, else lifetime)
- * keeps this decision, `getAdaptiveCooldownMultiplier`'s skip branch, and the
- * rehabilitation/status views agreeing — a type that recovered in its recent
- * window is no longer skipped, so it must not be listed as skipped or have its
- * lifetime data auto-reset either.
+ * True when a skip is LIFETIME-driven (the stored all-time rate itself is
+ * below the skip bar), as opposed to a windowed-driven skip caused by a recent
+ * failure burst on an otherwise-healthy type. Rehabilitation is a DESTRUCTIVE
+ * reset (`resetTaskTypeLearning` deletes the whole bucket — duration/ETA
+ * stats, routing accuracy, error patterns), which only makes sense when the
+ * lifetime data itself is what's poisoned; a windowed-driven skip self-heals
+ * as the window rolls off, so resetting would wipe hundreds of good runs of
+ * learning for a type that was never structurally broken.
*/
-function isSkipCandidate(metrics) {
- if (!metrics || (metrics.completed ?? 0) < 5) return false;
- const { successRate } = computeEffectiveSuccessRate(metrics);
- return successRate !== null && successRate < 30;
+function isLifetimeDrivenSkip(metrics) {
+ return Number.isFinite(metrics?.successRate) && metrics.successRate < 30;
}
/**
@@ -643,7 +650,10 @@ export async function checkAndRehabilitateSkippedTasks(gracePeriodMs = 7 * 24 *
// Only consider task types that would be skipped (effective rate < 30% with
// 5+ attempts, issue #2617) — a type that recovered in its recent window is
// no longer skipped, so resetting its lifetime data would be pointless churn.
- if (!isSkipCandidate(metrics)) {
+ // And only reset when the skip is LIFETIME-driven: a windowed-driven skip
+ // (recent failure burst on a healthy lifetime record) self-heals as the
+ // window rolls, so the destructive reset would wipe good learning data.
+ if (!isSkipCandidate(metrics) || !isLifetimeDrivenSkip(metrics)) {
continue;
}
@@ -706,8 +716,10 @@ export async function getSkippedTaskTypesWithStatus(gracePeriodMs = 7 * 24 * 60
? new Date(metrics.lastCompleted).getTime()
: 0;
const timeSinceLastAttempt = now - lastCompletedTime;
- const eligibleForRehabilitation = timeSinceLastAttempt >= gracePeriodMs;
- const timeUntilEligible = eligibleForRehabilitation
+ // Mirrors checkAndRehabilitateSkippedTasks: only a lifetime-driven skip is
+ // ever rehabilitation-eligible (a windowed-driven skip self-heals instead).
+ const eligibleForRehabilitation = timeSinceLastAttempt >= gracePeriodMs && isLifetimeDrivenSkip(metrics);
+ const timeUntilEligible = timeSinceLastAttempt >= gracePeriodMs
? 0
: gracePeriodMs - timeSinceLastAttempt;
@@ -737,12 +749,16 @@ export async function getSkippedTaskTypesWithStatus(gracePeriodMs = 7 * 24 * 60
function classifyConfidenceTier(metrics, { highThreshold = 80, lowThreshold = 50, minSamples = 5 } = {}) {
const completed = metrics?.completed ?? 0;
const effective = computeEffectiveSuccessRate(metrics);
- const successRate = effective.successRate ?? 0;
-
- if (completed < minSamples) return { tier: 'new', autoApprove: true, successRate, rateSource: effective.source };
- if (successRate >= highThreshold) return { tier: 'high', autoApprove: true, successRate, rateSource: effective.source };
- if (successRate >= lowThreshold) return { tier: 'medium', autoApprove: true, successRate, rateSource: effective.source };
- return { tier: 'low', autoApprove: false, successRate, rateSource: effective.source };
+ // Compare on a 0-defaulted value, but RETURN the raw nullable rate — the
+ // null sentinel ("no rate recorded") must survive to callers (repo
+ // absent-vs-empty rule), not collapse into a fabricated 0%.
+ const rate = effective.successRate ?? 0;
+ const result = { successRate: effective.successRate, rateSource: effective.source };
+
+ if (completed < minSamples) return { tier: 'new', autoApprove: true, ...result };
+ if (rate >= highThreshold) return { tier: 'high', autoApprove: true, ...result };
+ if (rate >= lowThreshold) return { tier: 'medium', autoApprove: true, ...result };
+ return { tier: 'low', autoApprove: false, ...result };
}
/**
@@ -760,7 +776,7 @@ export async function getTaskTypeConfidence(taskType, thresholds = {}) {
// Reasons quote the EFFECTIVE rate the tier was classified on (issue #2617),
// annotated when it came from the recency window so "82% success" next to a
// depressed lifetime rate is explainable.
- const rateLabel = rateSource === 'windowed' ? `${successRate}% recent success` : `${successRate}% success`;
+ const rateLabel = rateSource === 'windowed' ? `${successRate ?? 0}% recent success` : `${successRate ?? 0}% success`;
const reasons = {
new: `Fewer than ${thresholds.minSamples ?? 5} completions — auto-approve by default`,
high: `${rateLabel} across ${metrics?.completed} runs — high confidence`,
@@ -772,7 +788,9 @@ export async function getTaskTypeConfidence(taskType, thresholds = {}) {
taskType,
tier,
autoApprove,
- successRate: metrics ? successRate : null,
+ // Nullable: preserves the "no rate recorded" sentinel (absent bucket OR a
+ // bucket without a stored rate and a thin window) instead of a fake 0.
+ successRate,
rateSource,
completed: metrics?.completed ?? 0,
reason: reasons[tier]
@@ -794,7 +812,7 @@ export async function getConfidenceLevels(thresholds = {}) {
const { tier, autoApprove, successRate } = classifyConfidenceTier(metrics, thresholds);
levels[tier].push({
taskType,
- successRate,
+ successRate: successRate ?? 0, // display list keeps the pre-existing 0 default
completed: metrics.completed || 0,
autoApprove,
lastCompleted: metrics.lastCompleted
diff --git a/server/services/taskLearning/routing.test.js b/server/services/taskLearning/routing.test.js
index 6b0a5b63ae..5eb4d85102 100644
--- a/server/services/taskLearning/routing.test.js
+++ b/server/services/taskLearning/routing.test.js
@@ -5,7 +5,10 @@ import {
getSkippedTaskTypes,
getTaskTypeConfidence,
getTaskTypePriorityMultiplier,
- checkAndRehabilitateSkippedTasks
+ checkAndRehabilitateSkippedTasks,
+ getSkippedTaskTypesWithStatus,
+ suggestModelTier,
+ getPerformanceSummary
} from './routing.js';
import { loadLearningData } from './store.js';
import { resetTaskTypeLearning } from './metrics.js';
@@ -256,6 +259,28 @@ describe('windowed-rate decisions (issue #2617)', () => {
expect(resetTaskTypeLearning).not.toHaveBeenCalled();
});
+ it('does not reset a healthy-lifetime type skipped by a recent failure burst (windowed-driven skip)', async () => {
+ // 200 runs at 95% lifetime, then a transient outage: 6 recent failures →
+ // windowed 0% → the type IS skipped. But the skip is windowed-driven, so
+ // the destructive lifetime reset must NOT fire — the window self-heals.
+ const tenDaysAgo = Date.now() - 10 * 24 * 60 * 60 * 1000;
+ const healthy = {
+ completed: 200, succeeded: 190, failed: 10, successRate: 95,
+ lastCompleted: new Date(tenDaysAgo).toISOString(),
+ recentOutcomes: ring(Array(6).fill(false), tenDaysAgo)
+ };
+ loadLearningData.mockResolvedValue(learningWith({ 'healthy-burst': healthy }));
+ // Confirm it is indeed currently skipped…
+ const skipped = await getSkippedTaskTypes();
+ expect(skipped.map(s => s.taskType)).toContain('healthy-burst');
+ // …but never rehabilitated/reset, and the status view says not eligible.
+ const out = await checkAndRehabilitateSkippedTasks(7 * 24 * 60 * 60 * 1000);
+ expect(out.count).toBe(0);
+ expect(resetTaskTypeLearning).not.toHaveBeenCalled();
+ const status = await getSkippedTaskTypesWithStatus(7 * 24 * 60 * 60 * 1000);
+ expect(status[0]).toMatchObject({ taskType: 'healthy-burst', eligibleForRehabilitation: false });
+ });
+
it('still rehabilitates a genuinely skipped type past the grace period', async () => {
const broken = stillFailingMetrics();
// Push BOTH the ring and lastCompleted outside any recency concern for the
@@ -269,4 +294,43 @@ describe('windowed-rate decisions (issue #2617)', () => {
expect(resetTaskTypeLearning).toHaveBeenCalledWith('still-broken');
});
});
+
+ describe('suggestModelTier', () => {
+ it('no longer suggests heavy for a recovered type (effective rate in the low-success fallback)', async () => {
+ loadLearningData.mockResolvedValue(learningWith({ 'self-improve:x': recoveredMetrics() }));
+ expect(await suggestModelTier('self-improve:x')).toBeNull();
+ });
+
+ it('still suggests heavy on the lifetime rate when the window is too thin', async () => {
+ loadLearningData.mockResolvedValue(learningWith({ 'self-improve:x': thinWindowMetrics() }));
+ const out = await suggestModelTier('self-improve:x');
+ expect(out).toMatchObject({ suggested: 'heavy' });
+ expect(out.reason).toContain('27%');
+ });
+ });
+
+ describe('getPerformanceSummary', () => {
+ it('classifies a recovered type as a top performer, not needs-attention/skipped', async () => {
+ loadLearningData.mockResolvedValue(learningWith({
+ 'recovered': recoveredMetrics(),
+ 'still-broken': stillFailingMetrics()
+ }));
+ const summary = await getPerformanceSummary();
+ expect(summary.topPerformers.map(e => e.taskType)).toContain('recovered');
+ expect(summary.needsAttention.map(e => e.taskType)).not.toContain('recovered');
+ expect(summary.skipped.map(e => e.taskType)).not.toContain('recovered');
+ expect(summary.skipped.map(e => e.taskType)).toContain('still-broken');
+ });
+ });
+
+ describe('confidence null sentinel', () => {
+ it('preserves null (not a fabricated 0) for a bucket with no stored rate and a thin window', async () => {
+ loadLearningData.mockResolvedValue(learningWith({
+ 'legacy': { completed: 6, lastCompleted: new Date().toISOString() } // no successRate field, no ring
+ }));
+ const out = await getTaskTypeConfidence('legacy');
+ expect(out.successRate).toBeNull();
+ expect(out.tier).toBe('low'); // comparisons treat the absent rate as 0
+ });
+ });
});
diff --git a/server/services/taskLearning/store.js b/server/services/taskLearning/store.js
index 7d89c3edfc..21b7779d30 100644
--- a/server/services/taskLearning/store.js
+++ b/server/services/taskLearning/store.js
@@ -162,6 +162,24 @@ export function computeEffectiveSuccessRate(metrics, opts = {}) {
return { successRate: metrics?.successRate ?? null, source: 'lifetime', windowedCompleted };
}
+/**
+ * Shared skip predicate (issue #2617): a task type is a skip candidate when it
+ * has ≥5 lifetime completions AND its EFFECTIVE success rate is <30%. Pure.
+ *
+ * This is THE definition of "skipped" — used by the scheduling decision
+ * (`getAdaptiveCooldownMultiplier`'s skip branch mirrors it), the skip list
+ * (`getSkippedTaskTypes`), the rehabilitation/status views, AND the health
+ * summaries (`getPerformanceSummary`, `getLearningSummary`). Keeping every
+ * consumer on one predicate is what stops a dashboard/alert surface from
+ * claiming a type is skipped after the actual decision path stopped skipping
+ * it (or vice versa).
+ */
+export function isSkipCandidate(metrics) {
+ if (!metrics || (metrics.completed ?? 0) < 5) return false;
+ const { successRate } = computeEffectiveSuccessRate(metrics);
+ return successRate !== null && successRate < 30;
+}
+
/**
* Default learning data structure
*/
diff --git a/server/services/taskLearning/store.test.js b/server/services/taskLearning/store.test.js
index 853d5b1411..71d023657a 100644
--- a/server/services/taskLearning/store.test.js
+++ b/server/services/taskLearning/store.test.js
@@ -14,6 +14,7 @@ import {
appendRecentOutcome,
computeWindowedStats,
computeEffectiveSuccessRate,
+ isSkipCandidate,
EFFECTIVE_RATE_MIN_WINDOW_SAMPLES,
RECENT_OUTCOMES_CAP,
DEFAULT_WINDOW_MAX_COUNT
@@ -553,3 +554,35 @@ describe('store.computeEffectiveSuccessRate (issue #2617)', () => {
expect(computeEffectiveSuccessRate(metrics)).toMatchObject({ successRate: 0, source: 'windowed' });
});
});
+
+describe('store.isSkipCandidate (issue #2617)', () => {
+ const ring = (results, now = Date.now()) =>
+ results.map((s, i) => ({ t: new Date(now - (results.length - i) * 60000).toISOString(), s }));
+
+ it('is false for a recovered type (poor lifetime, ≥5 recent successes)', () => {
+ expect(isSkipCandidate({
+ completed: 55, succeeded: 15, failed: 40, successRate: 27,
+ recentOutcomes: ring(Array(15).fill(true))
+ })).toBe(false);
+ });
+
+ it('is true for a still-failing type (poor lifetime AND poor window)', () => {
+ expect(isSkipCandidate({
+ completed: 20, succeeded: 2, failed: 18, successRate: 10,
+ recentOutcomes: ring(Array(8).fill(false))
+ })).toBe(true);
+ });
+
+ it('falls back to the lifetime rate on a thin window (acceptance criterion 2)', () => {
+ expect(isSkipCandidate({
+ completed: 55, succeeded: 15, failed: 40, successRate: 27,
+ recentOutcomes: ring([true, true, true])
+ })).toBe(true);
+ });
+
+ it('is false below the 5-completion threshold or for a missing bucket', () => {
+ expect(isSkipCandidate({ completed: 4, successRate: 0 })).toBe(false);
+ expect(isSkipCandidate(undefined)).toBe(false);
+ expect(isSkipCandidate(null)).toBe(false);
+ });
+});