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): scope the tier-staleness gate to tiers without recent failures and label windowed rates in the Learning UI
[._.]/ Adam Eivy8745241ef840
diff --git a/client/src/components/cos/tabs/LearningTab.jsx b/client/src/components/cos/tabs/LearningTab.jsxindex 6e8d50a639..6eb1088a4a 100644--- a/client/src/components/cos/tabs/LearningTab.jsx+++ b/client/src/components/cos/tabs/LearningTab.jsx@@ -33,6 +33,15 @@ import * as api from '../../../services/api';import BrailleSpinner from '../../BrailleSpinner';import { formatDurationMin, formatDateTime } from '../../../utils/formatters';+// Evidence pairing (issue #2617): when the server classified a task type on+// its recency-windowed rate, label the percentage with the WINDOW's sample+// count — rendering "0%" beside the lifetime total ("200 attempts") would+// materially overstate the evidence behind the rate.+export const runsLabel = (item, noun = 'runs') =>+ item?.rateSource === 'windowed'+ ? `${item.windowedCompleted} recent ${noun}`+ : `${item?.completed} ${noun}`;+export default function LearningTab() {const [learning, setLearning] = useState(null);const [performance, setPerformance] = useState(null);@@ -422,7 +431,7 @@ export default function LearningTab() {<div key={t.taskType} className="px-4 py-2 flex items-center justify-between"><span className="text-sm text-gray-300 font-mono">{t.taskType}</span><div className="flex items-center gap-3">- <span className="text-xs text-gray-500">{t.completed} runs</span>+ <span className="text-xs text-gray-500">{runsLabel(t)}</span><span className={`text-sm ${textClass} font-medium`}>{t.successRate}%</span></div></div>@@ -465,7 +474,7 @@ export default function LearningTab() {<div className="flex-1 min-w-0"><div className="text-sm text-white truncate">{item.taskType}</div><div className="text-xs text-gray-500">- {item.completed} tasks • {item.avgDurationMin}m avg+ {runsLabel(item, 'tasks')} • {item.avgDurationMin}m avg</div></div><div className="flex items-center gap-3">@@ -500,7 +509,7 @@ export default function LearningTab() {<div className="flex-1 min-w-0"><div className="text-sm text-white truncate">{item.taskType}</div><div className="text-xs text-gray-500">- {item.completed} tasks • {item.avgDurationMin}m avg+ {runsLabel(item, 'tasks')} • {item.avgDurationMin}m avg</div></div><div className="flex items-center gap-3">@@ -552,7 +561,7 @@ export default function LearningTab() {<div><span className="text-sm text-white">{item.taskType}</span><span className="text-xs text-gray-500 ml-2">- ({item.completed} attempts)+ ({runsLabel(item, 'attempts')})</span></div><div className="flex items-center gap-3">diff --git a/client/src/components/cos/tabs/LearningTab.runsLabel.test.jsx b/client/src/components/cos/tabs/LearningTab.runsLabel.test.jsxnew file mode 100644index 0000000000..b4dddf1917--- /dev/null+++ b/client/src/components/cos/tabs/LearningTab.runsLabel.test.jsx@@ -0,0 +1,17 @@+import { describe, it, expect } from 'vitest';+import { runsLabel } from './LearningTab';++// Evidence pairing (issue #2617): a recency-windowed rate must be labeled with+// the window's own sample count, never the lifetime total — "0% across 200+// attempts" for a 6-sample windowed rate overstates the evidence.+describe('LearningTab runsLabel', () => {+ it('uses the windowed sample count when the rate came from the recency window', () => {+ expect(runsLabel({ rateSource: 'windowed', windowedCompleted: 6, completed: 200 })).toBe('6 recent runs');+ expect(runsLabel({ rateSource: 'windowed', windowedCompleted: 6, completed: 200 }, 'attempts')).toBe('6 recent attempts');+ });++ it('uses the lifetime count for a lifetime-sourced rate (and for legacy payloads without rateSource)', () => {+ expect(runsLabel({ rateSource: 'lifetime', windowedCompleted: 2, completed: 55 })).toBe('55 runs');+ expect(runsLabel({ completed: 55 }, 'tasks')).toBe('55 tasks');+ });+});diff --git a/server/services/taskLearning/routing.js b/server/services/taskLearning/routing.jsindex 20e64077fd..9476822d61 100644--- a/server/services/taskLearning/routing.js+++ b/server/services/taskLearning/routing.js@@ -9,7 +9,7 @@* module.*/-import { loadLearningData, emitLog, isSandboxedTaskType, computeEffectiveSuccessRate, isSkipCandidate } from './store.js';+import { loadLearningData, emitLog, isSandboxedTaskType, computeEffectiveSuccessRate, isSkipCandidate, DEFAULT_WINDOW_MAX_AGE_MS } from './store.js';import { resetTaskTypeLearning } from './metrics.js';import { computeCorrelationQuality, isCorrelationProven } from './correlationQuality.js';@@ -172,6 +172,30 @@ function mergeAvoidTiers(...lists) {return [...new Set(lists.flat().filter(Boolean))];}+/**+ * Tiers with at least one RECENT failure sample for this task type, read from+ * the enriched `failureSignatures.recent[]` rings (issue #2617). Pure.+ *+ * The task-type `recentOutcomes` ring carries no tier identity, so a healthy+ * task-wide recent window alone cannot prove that a specific tier's failure+ * evidence is stale — the recent successes may all have run on a DIFFERENT+ * tier. The failure samples DO carry `modelTier` + `recordedAt`, so this is+ * the tier-scoped recency signal: a failing tier that appears here failed+ * recently and must keep being steered away from; one that doesn't has only+ * stale (pre-window) failure evidence.+ */+function tiersWithRecentFailures(data, taskType, { now = Date.now(), maxAgeMs = DEFAULT_WINDOW_MAX_AGE_MS } = {}) {+ const tiers = new Set();+ for (const bucket of Object.values(data?.failureSignatures || {})) {+ for (const sample of bucket?.recent || []) {+ if (sample?.taskType !== taskType || !sample.modelTier) continue;+ const t = Date.parse(sample.recordedAt);+ if (Number.isFinite(t) && now - t <= maxAgeMs) tiers.add(sample.modelTier);+ }+ }+ return tiers;+}+/*** Get suggested priority boost for a task type based on historical success* Returns a multiplier: >1 for boost, <1 for demotion@@ -305,12 +329,18 @@ export async function suggestModelTier(taskType) {}// 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.+ // (issue #2617): skip this branch only when the type's recent window is+ // healthy AND none of the "failing" tiers has a recent failure on record+ // (tiersWithRecentFailures) — then the all-time tier rates are stale+ // evidence from 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. A failing tier with RECENT+ // failure samples keeps its evidence: the task-wide recovery may have+ // happened on a different tier, and the ring carries no tier identity.const failingTiers = tierResults.filter(t => t.successRate < 40);- if (failingTiers.length > 0 && !recentlyHealthy) {+ const recentFailTiers = tiersWithRecentFailures(data, taskType);+ const failingEvidenceStale = recentlyHealthy && !failingTiers.some(t => recentFailTiers.has(t.tier));+ if (failingTiers.length > 0 && !failingEvidenceStale) {const successfulTier = tierResults.find(t => t.successRate >= 60);return withFailureSignal({@@ -622,9 +652,14 @@ export async function getSkippedTaskTypes() {if (isSandboxedTaskType(taskType)) continue;// Skip if: completed >= 5 AND effective success rate < 30%if (isSkipCandidate(metrics)) {+ const { successRate, source: rateSource, windowedCompleted } = computeEffectiveSuccessRate(metrics);skipped.push({taskType,- successRate: computeEffectiveSuccessRate(metrics).successRate,+ successRate,+ // Evidence pairing (issue #2617): a windowed rate ships with its own+ // sample count so consumers never render it beside the lifetime total.+ rateSource,+ windowedCompleted,completed: metrics.completed,lastCompleted: metrics.lastCompleted});@@ -741,9 +776,12 @@ export async function getSkippedTaskTypesWithStatus(gracePeriodMs = 7 * 24 * 60? 0: gracePeriodMs - timeSinceLastAttempt;+ const { successRate, source: rateSource, windowedCompleted } = computeEffectiveSuccessRate(metrics);skipped.push({taskType,- successRate: computeEffectiveSuccessRate(metrics).successRate,+ successRate,+ rateSource,+ windowedCompleted,completed: metrics.completed,lastCompleted: metrics.lastCompleted,daysSinceLastAttempt: Math.round(timeSinceLastAttempt / (24 * 60 * 60 * 1000)),@@ -830,10 +868,12 @@ export async function getConfidenceLevels(thresholds = {}) {const levels = { high: [], medium: [], low: [], new: [] };for (const [taskType, metrics] of Object.entries(data.byTaskType)) {- const { tier, autoApprove, successRate } = classifyConfidenceTier(metrics, thresholds);+ const { tier, autoApprove, successRate, rateSource, windowedCompleted } = classifyConfidenceTier(metrics, thresholds);levels[tier].push({taskType,successRate: successRate ?? 0, // display list keeps the pre-existing 0 default+ rateSource,+ windowedCompleted,completed: metrics.completed || 0,autoApprove,lastCompleted: metrics.lastCompleteddiff --git a/server/services/taskLearning/routing.test.js b/server/services/taskLearning/routing.test.jsindex 5c0b5ec067..a666abe174 100644--- a/server/services/taskLearning/routing.test.js+++ b/server/services/taskLearning/routing.test.js@@ -326,6 +326,28 @@ describe('windowed-rate decisions (issue #2617)', () => {expect(out).toMatchObject({ suggested: 'heavy' });expect(out.avoidTiers).toContain('default');});++ it('keeps tier-failure evidence when the failing tier failed RECENTLY (recovery may be on another tier)', async () => {+ // Task-wide window is healthy, but the `default` tier has fresh failure+ // samples in failureSignatures — the recent successes may all have run on+ // a different tier (the ring carries no tier identity), so the failing+ // tier must stay steered away from, not be cleared by task-wide recovery.+ const data = learningWith({ 'self-improve:x': recoveredMetrics() });+ data.routingAccuracy = { 'self-improve:x': { default: { succeeded: 0, failed: 10 } } };+ data.failureSignatures = {+ 'tool-error': {+ count: 2,+ recent: [+ { taskType: 'self-improve:x', modelTier: 'default', recordedAt: new Date().toISOString() },+ { taskType: 'self-improve:x', modelTier: 'default', recordedAt: new Date().toISOString() }+ ]+ }+ };+ loadLearningData.mockResolvedValue(data);+ const out = await suggestModelTier('self-improve:x');+ expect(out).toMatchObject({ suggested: 'heavy' });+ expect(out.avoidTiers).toContain('default');+ });});describe('getPerformanceSummary', () => {