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
run quota-burn agents on the TUI provider so a burn can be watched and steered
[._.]/ Adam Eivy64434fa5252f
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 5c354683df..b13e328878 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -52,3 +52,4 @@- **Quota Burn opens instantly, and the claude family can finally burn.** Two bugs, both on the page's critical path. (1) `normalizeResetAt` fed the provider's reset string straight to `Date.parse`, which claude's `Aug 4 at 1:59pm` (an " at " separator, a meridiem glued to the minutes, and sometimes no minutes at all — `Jul 7 at 2pm`) returns `NaN` for, so EVERY claude window read as "no window states a reset time" and the family was permanently unburnable — invisibly, since that reason looks like a provider fault. A year-less reset (grok's `August 10, 06:07`) had the mirror problem: `Date.parse` resolves it to **2001**, so the roll-forward fired against a date 25 years back and landed on 2002, leaving grok reporting "window already reset" forever. The string is now reshaped before parsing and the year stamped from `now` in the provider's own zone — before the DST offset lookup, which is a per-year table. (2) A status read blocked on a live quota reading: measured **30s** to open the page after five idle minutes and **21s** on the first load after a restart, for a 10-20s PTY spawn per provider family, over percentages that move by single digits an hour. Page load is now ~9ms in both cases. Every cycle also logs its verdict now — "Evaluate now" previously left no trace in the server log at all, so a cycle that correctly declined was indistinguishable from one that never ran. (Follow-up #3433: the two adapters that emit a raw CLI reset string rather than ISO should normalize in the adapter, which is also why the Usage page still prints `Aug 4 at 1:59pm` unlocalized.)- **Slow provider readings are stale-while-revalidate, in one place.** `server/lib/staleWhileRevalidate.js` — `createStaleWhileRevalidate({ ttlMs, failureBackoffMs?, isComplete?, partialTtlMs? })` → `read(key, produce, { wait })` — replaces the hand-rolled TTL+in-flight caches in `providerUsage.js` (TUI scrapes) and `claudeCodeUsage.js`, which had drifted into two shapes of the same tricky async contract. A cached reading is served immediately and refreshed behind the caller; only a cold cache waits. Three things the naive version got wrong are now handled once: a background revalidation resolves `{value}|{error}` so an unawaited rejection can't kill the process; a failure keeps the last good value AND records `failedAt`, so a broken producer backs off instead of being respawned by every caller (serve-stale without that degrades into one subprocess per request exactly when the subprocess is broken); and `PENDING` is terminal — a cold cache whose producer already failed throws rather than promising a reading that is never coming, which a poller would wait on forever. `wait` is one three-state enum (`fresh` / `cached` / `never`) rather than the two booleans it started as, because "give me a live reading but don't wait for one" has no meaning and encoding it as flags forces a precedence rule at every layer that threads them.- **A quota status read never blocks — on either page.** `/api/quota-burn` and `/api/usage/providers` answer a cold cache with `pending: true` cards; the UI renders "reading quota…" and polls (via the shared `useAutoRefetch`, so it pauses on a hidden tab) until the readings land. `pending` is its own state ahead of the verdict everywhere it is rendered: on a Quota Burn family card, and on the Usage page's `ProviderQuotaCard`, which would otherwise have shown a pending provider as "No rate-limit data reported" — a verdict about the provider rather than a statement about a scrape still in flight. It fails closed in the burn gate ladder, ahead of the error branch and holding even under force, so a card with no numbers on it can never become a burn candidate. `?refresh=1` — the Refresh button, and every runner cycle about to spend real quota — still waits for a live reading.+- **Quota-burn agents run as TUI, so a burn can be watched and steered.** A burn runs unattended for minutes on the user's own subscription, and the family's provider was picked with a plain `find` over the enabled CLI/TUI providers — which returns the CLI, because that is what sorts first. Every dispatch therefore went to a headless run that could only be read after it finished. The picker now prefers the TUI (the same preference `pickScrapeProvider` applies when reading `/usage`), so the agent shows up in Active Agents with a live terminal. Two selection bugs came out with it: the whole **`agy` family was unreachable** — its providers ship as `antigravity-cli`/`antigravity-tui`, neither of which contains "agy", so a configured Antigravity plan reported "no enabled CLI/TUI provider" forever while the quota card above it showed a healthy window (the card's matcher checks the *command*; the burn picker only checked the id, and now checks both) — and an **ollama-backed wrapper was eligible**: `claude-ollama-tui` matches the claude family and is a TUI, but it runs a local model, so burning through it spends nothing and lets the window it was meant to drain expire unused. `resolveEnabledFamilies` already excludes those from the quota cards for the same reason; the burn picker now excludes them too, explicit pin included.diff --git a/server/services/quotaBurnJobs/agentPrompt.js b/server/services/quotaBurnJobs/agentPrompt.jsindex f585fe9266..2df27ad2e6 100644--- a/server/services/quotaBurnJobs/agentPrompt.js+++ b/server/services/quotaBurnJobs/agentPrompt.js@@ -14,22 +14,59 @@import { addTask } from '../cosTaskStore.js';import { getAppById } from '../apps.js';import { getAllProviders } from '../providers.js';+import { commandBasename } from '../../lib/providerModels.js';/*** An agent-capable provider in the burning family. An explicit `providerId`* (job first, then family) wins; otherwise match the family id against the- * enabled CLI/TUI providers. API-type providers are excluded on purpose — this- * job exists to spend a SUBSCRIPTION window, and an API provider bills per- * token instead.+ * enabled providers, PREFERRING the TUI.+ *+ * Preferring the TUI is the point: a burn runs unattended for minutes on the+ * user's own subscription, and a TUI agent is watchable in Active Agents and can+ * be steered mid-run, where a headless CLI run can only be read after it has+ * finished. Most families have both registered (`claude-code` + `claude-code-tui`,+ * `codex` + `codex-tui`, …) and the CLI sorts first, so a plain `find` silently+ * picked the unobservable one every time. `pickScrapeProvider` applies the same+ * preference when reading `/usage`.+ *+ * Two exclusions, both about what a burn is FOR — spending a subscription window+ * that would otherwise expire unused:+ * - API-type providers bill per token rather than drawing down a window.+ * - Ollama-backed wrappers run a LOCAL model, so there is no window to spend and+ * burning through one accomplishes nothing. `resolveEnabledFamilies` drops+ * them from the quota cards for exactly this reason; a `claude-ollama-tui`+ * would otherwise be a perfectly good match for the `claude` family.*/export function providerForFamily(providers, { familyId, providerId }) {const available = (providers || []).filter((provider) =>- provider?.enabled && (provider.type === 'cli' || provider.type === 'tui'));+ provider?.enabled && provider.ollamaBacked !== true+ && (provider.type === 'cli' || provider.type === 'tui'));if (providerId) return available.find((provider) => provider.id === providerId) || null;- const needle = String(familyId || '').toLowerCase();- return available.find((provider) => String(provider.id || '').toLowerCase().includes(needle)) || null;+ const inFamily = available.filter((provider) => matchesFamily(provider, familyId));+ return inFamily.find((provider) => provider.type === 'tui') || inFamily[0] || null;}+/**+ * Does this provider belong to `familyId`?+ *+ * The BINARY is what actually identifies the family — the provider id is a+ * user-facing label and does not have to contain the family name. Matching on+ * the id alone silently stranded the whole `agy` family: its providers ship as+ * `antigravity-cli` / `antigravity-tui`, neither of which contains "agy", so a+ * configured Antigravity burn plan reported "no enabled CLI/TUI provider" and+ * could never dispatch — while the quota card sat right above it showing a+ * healthy window, because `providerUsage`'s own matcher checks the command.+ *+ * The id substring stays as a fallback for a provider registered under a wrapper+ * script whose basename isn't the family name.+ */+const matchesFamily = (provider, familyId) => {+ const needle = String(familyId || '').toLowerCase();+ if (!needle) return false;+ return commandBasename(provider.command) === needle+ || String(provider.id || '').toLowerCase().includes(needle);+};+async function resolve({ params, job, family }) {const appId = typeof params?.appId === 'string' ? params.appId.trim() : '';const prompt = typeof params?.prompt === 'string' ? params.prompt.trim() : '';diff --git a/server/services/quotaBurnJobs/agentPrompt.test.js b/server/services/quotaBurnJobs/agentPrompt.test.jsindex 1b3f116236..7a7e0ef0c3 100644--- a/server/services/quotaBurnJobs/agentPrompt.test.js+++ b/server/services/quotaBurnJobs/agentPrompt.test.js@@ -35,6 +35,59 @@ describe('providerForFamily', () => {expect(providerForFamily([{ id: 'grok-api', type: 'api', enabled: true }], { familyId: 'grok' })).toBeNull();expect(providerForFamily([{ id: 'grok-cli', type: 'cli', enabled: false }], { familyId: 'grok' })).toBeNull();});++ // A burn runs unattended for minutes on the user's own subscription — the TUI+ // is the one that can be watched in Active Agents and steered mid-run. Most+ // families register both, and the CLI sorts first, so a plain `find` picked+ // the unobservable one every time.+ it('prefers the TUI provider over the CLI in the same family', () => {+ const providers = [+ { id: 'grok-cli', type: 'cli', enabled: true },+ { id: 'grok-tui', type: 'tui', enabled: true },+ ];+ expect(providerForFamily(providers, { familyId: 'grok' })?.id).toBe('grok-tui');+ // Registry order must not decide it either way.+ expect(providerForFamily([...providers].reverse(), { familyId: 'grok' })?.id).toBe('grok-tui');+ // CLI-only families still resolve — the preference is not a requirement.+ expect(providerForFamily([{ id: 'grok-cli', type: 'cli', enabled: true }], { familyId: 'grok' })?.id).toBe('grok-cli');+ // An explicit pin still outranks the preference.+ expect(providerForFamily(providers, { familyId: 'grok', providerId: 'grok-cli' })?.id).toBe('grok-cli');+ });++ // The whole `agy` family was unreachable: its providers ship as+ // `antigravity-cli` / `antigravity-tui`, neither of which contains "agy", so a+ // configured Antigravity plan reported "no enabled CLI/TUI provider" forever —+ // under a quota card that was showing a healthy window, because that card's+ // matcher checks the command.+ it('matches on the provider BINARY, not just the id — the agy/antigravity case', () => {+ const providers = [+ { id: 'antigravity-cli', type: 'cli', enabled: true, command: 'agy' },+ { id: 'antigravity-tui', type: 'tui', enabled: true, command: 'agy' },+ ];+ expect(providerForFamily(providers, { familyId: 'agy' })?.id).toBe('antigravity-tui');+ // An absolute path still resolves by basename.+ expect(providerForFamily([{ id: 'custom', type: 'tui', enabled: true, command: '/opt/tools/agy' }], { familyId: 'agy' })?.id).toBe('custom');+ // And the id substring still works for a wrapper whose basename differs.+ expect(providerForFamily([{ id: 'grok-tui', type: 'tui', enabled: true, command: 'grok-wrapper.sh' }], { familyId: 'grok' })?.id).toBe('grok-tui');+ // An unrelated family must not be dragged in by either signal.+ expect(providerForFamily(providers, { familyId: 'codex' })).toBeNull();+ });++ it('never selects an ollama-backed wrapper — a local model has no window to burn', () => {+ // `claude-ollama-tui` matches the `claude` family and IS a TUI, so the+ // preference above would reach for it. It runs a local model: nothing+ // expires, nothing is spent, and the window it was supposed to drain goes+ // unused. Same exclusion `resolveEnabledFamilies` applies to the cards.+ const providers = [+ { id: 'claude-ollama-tui', type: 'tui', enabled: true, ollamaBacked: true },+ { id: 'claude-code-tui', type: 'tui', enabled: true },+ { id: 'claude-code', type: 'cli', enabled: true },+ ];+ expect(providerForFamily(providers, { familyId: 'claude' })?.id).toBe('claude-code-tui');+ // Not even by explicit pin — it cannot do the one thing the job is for.+ expect(providerForFamily(providers, { familyId: 'claude', providerId: 'claude-ollama-tui' })).toBeNull();+ expect(providerForFamily([providers[0]], { familyId: 'claude' })).toBeNull();+ });});describe('countPending', () => {