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
prefer the lightest proven model tier in learning-based routing
[._.]/ Adam Eivy2f85fd5cd039
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 638c190ddb..86cef5b3cb 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -1,5 +1,9 @@# Unreleased+## CoS / task learning++- **Learning-based model routing now prefers the lightest tier that succeeds, instead of the marginally-highest-success tier.** `suggestModelTier` sorted candidate tiers by success rate and returned the top one, so a `heavy` tier at 85% would beat a `light` tier at 82% — silently over-allocating compute for the same outcome, despite an inline comment that said "if a lighter tier has high success, no need to upgrade." It now picks the **lightest** tier among all that clear the high-success threshold (≥80%), realizing that intent and saving the heavier model for task types that actually need it. Failing-tier avoidance and the insufficient-data short-circuit are unchanged. (`server/services/taskLearning/routing.js`)+## Local model stack- **[issue-1329] Pinned a validated mlx/mlx-metal trio for LoRA training so the GPU-watchdog stack can't silently drift back to the known-bad build.** The three M5 Max kernel panics during FLUX.2 LoRA training all happened on mlx/mlx-metal 0.30.6, but `setup-image-video.sh` installed `mflux>=0.17` as a *floor* and let pip resolve mlx under mflux's `mlx<0.32` cap — so a reinstall could land back on a panicking build. The setup script now pins the bisect-validated trio **mflux 0.17.5 · mlx 0.31.2 · mlx-metal 0.31.2**, proven by run `d36562a0` completing a full LoRA training to adapter extraction (flux2-klein-4b, bf16, 768px, segmentation on) on the panicking M5 Max with no panic or reboot. The runtime-fingerprint half shipped earlier (#1406). (`scripts/setup-image-video.sh`, `docs/research/2026-06-13-mflux-training-watchdog-panic.md`)diff --git a/server/services/taskLearning.test.js b/server/services/taskLearning.test.jsindex f3d70dae9f..632fd191a8 100644--- a/server/services/taskLearning.test.js+++ b/server/services/taskLearning.test.js@@ -585,6 +585,33 @@ describe('TaskLearning - suggestModelTier with routing signals', () => {const result = await suggestModelTier('new-task');expect(result).toBeNull();});++ it('should prefer the lightest tier when several clear the high-success threshold', async () => {+ // heavy has the marginally-higher success rate, but light also clears 80% —+ // we should route to light to avoid spending a heavier model for the same outcome.+ const data = makeLearningData({+ byTaskType: {+ 'docs-task': {+ completed: 20, succeeded: 17, failed: 3,+ totalDurationMs: 2000000, avgDurationMs: 100000,+ successRate: 85+ }+ },+ routingAccuracy: {+ 'docs-task': {+ light: { succeeded: 9, failed: 2, lastAttempt: '2026-01-26T00:00:00.000Z' }, // 82%+ heavy: { succeeded: 8, failed: 1, lastAttempt: '2026-01-25T00:00:00.000Z' } // 89%+ }+ }+ });+ readFile.mockResolvedValue(JSON.stringify(data));++ const result = await suggestModelTier('docs-task');++ expect(result).not.toBeNull();+ expect(result.suggested).toBe('light');+ expect(result.reason).toMatch(/lightest of 2 proven tiers/);+ });});describe('TaskLearning - recalculateModelTierMetrics', () => {diff --git a/server/services/taskLearning/routing.js b/server/services/taskLearning/routing.jsindex 47eaa695e1..4c63a6ad40 100644--- a/server/services/taskLearning/routing.js+++ b/server/services/taskLearning/routing.js@@ -12,6 +12,18 @@import { loadLearningData, emitLog } from './store.js';import { resetTaskTypeLearning } from './metrics.js';+/**+ * Relative resource cost of each model tier, lightest → heaviest.+ * Used to break ties between tiers that both clear the high-success+ * threshold: prefer the cheapest tier that still works well.+ * (Mirrors the tier ordering in agentModelSelection.js.)+ */+const TIER_WEIGHT = { light: 0, default: 1, medium: 2, heavy: 3 };+const tierWeight = (tier) => TIER_WEIGHT[tier] ?? TIER_WEIGHT.default;++/** Minimum success rate (%) for a tier to count as "proven" for a task type. */+const HIGH_SUCCESS_THRESHOLD = 80;+/*** Get suggested priority boost for a task type based on historical success* Returns a multiplier: >1 for boost, <1 for demotion@@ -59,12 +71,21 @@ export async function suggestModelTier(taskType) {}).sort((a, b) => b.successRate - a.successRate);- // If a lighter tier has high success, no need to upgrade- const bestTier = tierResults[0];- if (bestTier && bestTier.successRate >= 80) {+ // Among tiers that clear the high-success threshold, prefer the LIGHTEST+ // (cheapest) one — there's no reason to spend a heavier model when a+ // lighter tier already succeeds reliably. tierResults is sorted by success+ // rate, so without this a heavy tier at 85% would beat a light tier at 82%+ // and silently over-allocate compute for the same outcome.+ const provenTiers = tierResults.filter(t => t.successRate >= HIGH_SUCCESS_THRESHOLD);+ if (provenTiers.length > 0) {+ const lightest = provenTiers.reduce((a, b) =>+ tierWeight(b.tier) < tierWeight(a.tier) ? b : a);+ const reason = provenTiers.length > 1+ ? `${taskType} succeeds with ${lightest.tier} tier (${lightest.successRate}%) — using lightest of ${provenTiers.length} proven tiers`+ : `${taskType} has ${lightest.successRate}% success with ${lightest.tier} tier`;return {- suggested: bestTier.tier,- reason: `${taskType} has ${bestTier.successRate}% success with ${bestTier.tier} tier`,+ suggested: lightest.tier,+ reason,avoidTiers: tierResults.filter(t => t.successRate < 40).map(t => t.tier)};}