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
address review (codex): gate stale tier routing on the recent window and pair windowed rates with their sample counts
[._.]/ Adam Eivya5ea85176b0f
diff --git a/server/services/proactiveAlerts.js b/server/services/proactiveAlerts.jsindex a4ff6d025d..e9d8b389df 100644--- a/server/services/proactiveAlerts.js+++ b/server/services/proactiveAlerts.js@@ -74,9 +74,14 @@ async function checkSuccessRates() {type: 'success_drop',severity: item.successRate < 30 ? 'high' : 'medium',title: `Low success rate: ${item.taskType}`,- detail: `${item.successRate}% success across ${item.completed} tasks`,+ // Evidence pairing (issue #2617): a recency-windowed rate is quoted with+ // the WINDOW's sample count — "0% success across 200 tasks" (lifetime+ // count next to a 6-sample windowed rate) would overstate the evidence.+ detail: item.rateSource === 'windowed'+ ? `${item.successRate}% success across the last ${item.windowedCompleted} runs`+ : `${item.successRate}% success across ${item.completed} tasks`,link: '/cos/learning',- metadata: { taskType: item.taskType, successRate: item.successRate, completed: item.completed }+ metadata: { taskType: item.taskType, successRate: item.successRate, completed: item.completed, rateSource: item.rateSource, windowedCompleted: item.windowedCompleted }}));}diff --git a/server/services/taskLearning/insights.js b/server/services/taskLearning/insights.jsindex 155823cefb..1635ade176 100644--- a/server/services/taskLearning/insights.js+++ b/server/services/taskLearning/insights.js@@ -31,12 +31,16 @@ export async function getLearningInsights() {? Math.round((data.totals.succeeded / data.totals.completed) * 100): 0;- // Find best and worst performing task types+ // Find best and worst performing task types on the EFFECTIVE rate (issue+ // #2617: windowed when the outcome ring has enough samples, else lifetime) —+ // otherwise a type that recovered from a since-fixed failure burst keeps+ // ranking "worst" and generating a prompt-improvement warning forever, right+ // next to the windowed performance/confidence views that call it healthy.const taskTypes = Object.entries(data.byTaskType)- .map(([type, metrics]) => ({- type,- ...metrics- }))+ .map(([type, metrics]) => {+ const { successRate, source: rateSource, windowedCompleted } = computeEffectiveSuccessRate(metrics);+ return { type, ...metrics, successRate: successRate ?? 0, rateSource, windowedCompleted };+ }).filter(t => t.completed >= 3) // Only include types with enough data.sort((a, b) => b.successRate - a.successRate);@@ -92,12 +96,16 @@ export async function getLearningInsights() {bestPerforming: bestPerforming.map(t => ({type: t.type,successRate: t.successRate,+ rateSource: t.rateSource,+ windowedCompleted: t.windowedCompleted,avgDurationMin: Math.round(t.avgDurationMs / 60000),completed: t.completed})),worstPerforming: worstPerforming.map(t => ({type: t.type,successRate: t.successRate,+ rateSource: t.rateSource,+ windowedCompleted: t.windowedCompleted,avgDurationMin: Math.round(t.avgDurationMs / 60000),completed: t.completed})),diff --git a/server/services/taskLearning/insights.test.js b/server/services/taskLearning/insights.test.jsindex 3b2f4f6f3a..8d3b4eaa50 100644--- a/server/services/taskLearning/insights.test.js+++ b/server/services/taskLearning/insights.test.js@@ -102,6 +102,45 @@ describe('insights.getLearningInsights — standing learnings surfacing (issue #});});+describe('insights.getLearningInsights — 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('ranks performers on the effective rate and drops the stale worst-perf warning for a recovered type', async () => {+ loadLearningData.mockResolvedValue(learningData({+ byTaskType: {+ 'recovered': {+ completed: 55, succeeded: 15, failed: 40, successRate: 27,+ avgDurationMs: 60000, recentOutcomes: ring(Array(15).fill(true))+ },+ 'steady': { completed: 10, succeeded: 8, failed: 2, successRate: 80, avgDurationMs: 60000, recentOutcomes: [] }+ }+ }));+ const view = await getLearningInsights();+ // Recovered ranks best (windowed 100% > steady's lifetime 80%) and carries+ // its evidence pairing.+ expect(view.insights.bestPerforming[0]).toMatchObject({+ type: 'recovered', successRate: 100, rateSource: 'windowed', windowedCompleted: 15+ });+ // No "may need prompt improvements" warning for the recovered type.+ const worstWarning = view.recommendations.find(r => r.id === 'worst-perf:recovered');+ expect(worstWarning).toBeUndefined();+ });++ it('still warns on a genuinely failing type', async () => {+ loadLearningData.mockResolvedValue(learningData({+ byTaskType: {+ 'still-broken': {+ completed: 20, succeeded: 2, failed: 18, successRate: 10,+ avgDurationMs: 60000, recentOutcomes: ring(Array(8).fill(false))+ }+ }+ }));+ const view = await getLearningInsights();+ expect(view.recommendations.find(r => r.id === 'worst-perf:still-broken')).toBeDefined();+ });+});+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 }));diff --git a/server/services/taskLearning/routing.js b/server/services/taskLearning/routing.jsindex 46c4c98ad2..20e64077fd 100644--- a/server/services/taskLearning/routing.js+++ b/server/services/taskLearning/routing.js@@ -264,6 +264,16 @@ export async function suggestModelTier(taskType) {return failureAvoidance.avoidTiers.length > 0 ? avoidanceOnlySuggestion() : null;}+ // Effective (windowed-when-available) task-type rate (issue #2617). Used both+ // to gate the all-time failing-tier branch below and in the low-success+ // fallback: routingAccuracy's per-tier counters have no recency window of+ // their own, so after a since-fixed failure burst a tier reads "failing"+ // forever — when the type's recent window is healthy, that all-time evidence+ // is stale and must not steer routing (to `heavy`, or away from the very tier+ // that is currently succeeding).+ const effective = computeEffectiveSuccessRate(metrics);+ const recentlyHealthy = effective.source === 'windowed' && effective.successRate >= 60;+// Check routing accuracy for tier-specific signalsconst routingData = data.routingAccuracy?.[taskType];if (routingData) {@@ -294,9 +304,13 @@ export async function suggestModelTier(taskType) {);}- // If current default tier is failing, find a better one+ // If current default tier is failing, find a better one. Recency gate+ // (issue #2617): skip this branch entirely when the type's recent window is+ // healthy — the all-time tier rates are stale after a since-fixed burst, and+ // acting on them would route a currently-working type to `heavy` (and steer+ // selection off the tier it is presently succeeding on) indefinitely.const failingTiers = tierResults.filter(t => t.successRate < 40);- if (failingTiers.length > 0) {+ if (failingTiers.length > 0 && !recentlyHealthy) {const successfulTier = tierResults.find(t => t.successRate >= 60);return withFailureSignal({@@ -312,11 +326,10 @@ export async function suggestModelTier(taskType) {// 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) {+ if (effective.successRate !== null && effective.successRate < 60) {return withFailureSignal({suggested: 'heavy',- reason: `${taskType} has ${effectiveRate}% success rate - heavier model may help`+ reason: `${taskType} has ${effective.successRate}% success rate - heavier model may help`});}@@ -435,10 +448,15 @@ export async function getPerformanceSummary() {for (const [taskType, metrics] of Object.entries(data.byTaskType)) {if (metrics.completed < 3) continue;- const { successRate } = computeEffectiveSuccessRate(metrics);+ const { successRate, source: rateSource, windowedCompleted } = computeEffectiveSuccessRate(metrics);const entry = {taskType,successRate,+ // Evidence pairing (issue #2617): a windowed rate must travel with its+ // own sample count — "0% success across 200 tasks" (lifetime completed+ // next to a 6-sample windowed rate) materially overstates the evidence.+ rateSource,+ windowedCompleted,completed: metrics.completed,avgDurationMin: Math.round(metrics.avgDurationMs / 60000)};@@ -753,7 +771,7 @@ function classifyConfidenceTier(metrics, { highThreshold = 80, lowThreshold = 50// 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 };+ const result = { successRate: effective.successRate, rateSource: effective.source, windowedCompleted: effective.windowedCompleted };if (completed < minSamples) return { tier: 'new', autoApprove: true, ...result };if (rate >= highThreshold) return { tier: 'high', autoApprove: true, ...result };@@ -771,17 +789,19 @@ function classifyConfidenceTier(metrics, { highThreshold = 80, lowThreshold = 50export async function getTaskTypeConfidence(taskType, thresholds = {}) {const data = await loadLearningData();const metrics = data.byTaskType[taskType];- const { tier, autoApprove, successRate, rateSource } = classifyConfidenceTier(metrics, thresholds);+ const { tier, autoApprove, successRate, rateSource, windowedCompleted } = classifyConfidenceTier(metrics, 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.+ // annotated when it came from the recency window — and paired with the+ // WINDOW's sample count, not the lifetime one, so "100% recent success+ // across 15 recent runs" never overstates its evidence as 200 lifetime runs.const rateLabel = rateSource === 'windowed' ? `${successRate ?? 0}% recent success` : `${successRate ?? 0}% success`;+ const attemptsLabel = rateSource === 'windowed' ? `${windowedCompleted} recent runs` : `${metrics?.completed} runs`;const reasons = {new: `Fewer than ${thresholds.minSamples ?? 5} completions — auto-approve by default`,- high: `${rateLabel} across ${metrics?.completed} runs — high confidence`,+ high: `${rateLabel} across ${attemptsLabel} — high confidence`,medium: `${rateLabel} — acceptable confidence`,- low: `${rateLabel} after ${metrics?.completed} attempts — requires approval`+ low: `${rateLabel} after ${attemptsLabel} — requires approval`};return {@@ -792,6 +812,7 @@ export async function getTaskTypeConfidence(taskType, thresholds = {}) {// bucket without a stored rate and a thin window) instead of a fake 0.successRate,rateSource,+ windowedCompleted,completed: metrics?.completed ?? 0,reason: reasons[tier]};diff --git a/server/services/taskLearning/routing.test.js b/server/services/taskLearning/routing.test.jsindex 5eb4d85102..5c0b5ec067 100644--- a/server/services/taskLearning/routing.test.js+++ b/server/services/taskLearning/routing.test.js@@ -307,6 +307,25 @@ describe('windowed-rate decisions (issue #2617)', () => {expect(out).toMatchObject({ suggested: 'heavy' });expect(out.reason).toContain('27%');});++ it('gates the all-time failing-tier branch on the recent window (populated routingAccuracy)', async () => {+ // The issue's scenario with REAL routing data: all 55 runs on one tier →+ // that tier's all-time routingAccuracy is 27% (<40 "failing"), which+ // pre-fix returned `heavy` before the effective-rate fallback ever ran.+ const data = learningWith({ 'self-improve:x': recoveredMetrics() });+ data.routingAccuracy = { 'self-improve:x': { default: { succeeded: 15, failed: 40 } } };+ loadLearningData.mockResolvedValue(data);+ expect(await suggestModelTier('self-improve:x')).toBeNull();+ });++ it('still escalates on failing tier data when the window is too thin (lifetime behavior preserved)', async () => {+ const data = learningWith({ 'self-improve:x': thinWindowMetrics() });+ data.routingAccuracy = { 'self-improve:x': { default: { succeeded: 15, failed: 40 } } };+ loadLearningData.mockResolvedValue(data);+ const out = await suggestModelTier('self-improve:x');+ expect(out).toMatchObject({ suggested: 'heavy' });+ expect(out.avoidTiers).toContain('default');+ });});describe('getPerformanceSummary', () => {@@ -321,6 +340,21 @@ describe('windowed-rate decisions (issue #2617)', () => {expect(summary.skipped.map(e => e.taskType)).not.toContain('recovered');expect(summary.skipped.map(e => e.taskType)).toContain('still-broken');});++ it('pairs a windowed rate with its own sample count (evidence pairing for alerts/UI)', async () => {+ // Healthy lifetime (200 runs) hit by a 6-failure burst: the windowed 0%+ // must travel with windowedCompleted=6, not the 200 lifetime completions.+ loadLearningData.mockResolvedValue(learningWith({+ 'healthy-burst': {+ completed: 200, succeeded: 190, failed: 10, successRate: 95,+ lastCompleted: new Date().toISOString(), avgDurationMs: 60000,+ recentOutcomes: ring(Array(6).fill(false))+ }+ }));+ const summary = await getPerformanceSummary();+ const entry = summary.needsAttention.find(e => e.taskType === 'healthy-burst');+ expect(entry).toMatchObject({ successRate: 0, rateSource: 'windowed', windowedCompleted: 6, completed: 200 });+ });});describe('confidence null sentinel', () => {