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
fix: cap usage-limit provider bench + thread autopilot editorial-fix provider
[._.]/ Adam Eivy0269e169e481
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex a18d1411e8..233d6c9c87 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -17,6 +17,8 @@## Fixed+- **A usage-limited provider is no longer benched for up to a day.** When a CLI provider (e.g. Codex) hit its usage limit, PortOS parsed the provider's self-reported reset ("resets in 21h 52m") and benched it for that entire span — sidelining the primary for nearly a day even though usage limits reset on a rolling window (≈5h max) and capacity usually frees much sooner. The usage-limit bench is now a tight retry interval (default 10 minutes), hard-capped at the 5h reset window, and it still respects a genuinely *shorter* stated reset. The provider's stated reset is kept for display. (`server/lib/aiToolkit/providerStatus.js`)+- **Autopilot editorial auto-fix now honors the run's chosen provider/model.** The editorial loop passed the run's provider override to the manuscript *review* but not to fix *generation*, so auto-fixes silently ran on the active/default provider (and its runtime fallback) instead of the model selected for the run — which, when the default was rate-limited, degraded fixes onto a weak fallback. Fix generation now threads the same override as the review. (`server/services/pipeline/seriesAutopilot.js`)- **Manuscript editorial review no longer reports a fully-drafted book as "empty."** The completeness pass injected the entire universe canon (characters + places + objects JSON, which for a large universe can be 800K+ chars / 200K+ tokens) as fixed context on every call. On any model whose context window the canon exceeded, the budgeter's usable-input budget collapsed to zero and the manuscript was sliced to an empty string — so the LLM "reviewed" a blank draft and returned a wall of identical "the drafted manuscript is empty" findings that could never be resolved, hard-pausing the autopilot at editorial review. The canon is now hard-capped to a reference-sized budget and window-aware-trimmed so the manuscript always keeps a budget floor (mirroring the editorial *check* runner's #1459 protection): a frontier-window model reviews the whole book in one pass, a smaller window chunks it — but the draft is never starved to empty.## Addeddiff --git a/server/lib/aiToolkit/providerStatus.js b/server/lib/aiToolkit/providerStatus.jsindex 0b51f70ce4..9d14c76706 100644--- a/server/lib/aiToolkit/providerStatus.js+++ b/server/lib/aiToolkit/providerStatus.js@@ -16,7 +16,14 @@ export function createProviderStatusService(config = {}) {dataDir = './data',statusFile = 'provider-status.json',defaultFallbackPriority = ['claude-code', 'codex', 'lmstudio', 'local-lm-studio', 'ollama', 'antigravity-cli', 'gemini-cli'],- defaultUsageLimitWait = 24 * 60 * 60 * 1000,+ // Usage-limit bench is a SHORT retry interval, not the provider's stated+ // reset. A usage limit resets on a rolling window (≈5h max), and a CLI's+ // self-reported "resets in 21h" is unreliable + over-conservative — benching+ // that long sidelines the primary for a day even though capacity usually+ // frees much sooner. So default to a tight 10m probe and re-bench if still+ // limited; never exceed the 5h reset window (`maxUsageLimitWait`).+ defaultUsageLimitWait = 10 * 60 * 1000,+ maxUsageLimitWait = 5 * 60 * 60 * 1000,defaultRateLimitWait = 5 * 60 * 1000,onStatusChange = null} = config;@@ -205,10 +212,21 @@ export function createProviderStatusService(config = {}) {},async markUsageLimit(providerId, errorInfo = {}) {+ // Bench for a SHORT retry interval rather than the provider's stated reset.+ // Respect a parsed wait ONLY when it is shorter than the tight default (a+ // genuinely brief reset); otherwise use the default and never let any value+ // exceed the 5h reset-window ceiling. This keeps a "resets in 21h" estimate+ // from sidelining the primary for a day — it retries in 10m and re-benches+ // if still limited. The parsed value is still surfaced for DISPLAY.+ const parsed = parseWaitTime(errorInfo.waitTime);+ const benchMs = Math.min(+ parsed && parsed < defaultUsageLimitWait ? parsed : defaultUsageLimitWait,+ maxUsageLimitWait,+ );return this.markUnavailable(providerId, {reason: 'usage-limit',message: errorInfo.message || 'Usage limit exceeded',- waitTimeMs: parseWaitTime(errorInfo.waitTime) || defaultUsageLimitWait,+ waitTimeMs: benchMs,// `waitTime` is a usage-limit-only display string ("resets 5pm") —// pass via extras so it's part of the SAME persisted record and// status:changed event, not a follow-up second write.diff --git a/server/lib/aiToolkit/providerStatus.test.js b/server/lib/aiToolkit/providerStatus.test.jsindex 118e635de0..c0f68bad30 100644--- a/server/lib/aiToolkit/providerStatus.test.js+++ b/server/lib/aiToolkit/providerStatus.test.js@@ -87,6 +87,45 @@ describe('Provider Status Service', () => {});});+ describe('markUsageLimit — bench cap (tight retry, never > reset window)', () => {+ const benchMs = (status) => new Date(status.estimatedRecovery).getTime() - new Date(status.unavailableSince).getTime();++ it('benches the tight default (not the stated 21h) for an over-long reset, and never past the 5h cap', async () => {+ const svc = createProviderStatusService({+ dataDir: TEST_DATA_DIR, statusFile: 'ps-cap.json',+ defaultUsageLimitWait: 10 * 60 * 1000, maxUsageLimitWait: 5 * 60 * 60 * 1000,+ });+ await svc.init();+ const status = await svc.markUsageLimit('p', { message: 'limit', waitTime: '21 hours 52 minutes' });+ // A 21h stated reset must NOT bench 21h — it falls back to the tight 10m default.+ expect(benchMs(status)).toBe(10 * 60 * 1000);+ expect(benchMs(status)).toBeLessThanOrEqual(5 * 60 * 60 * 1000);+ // The stated reset is still surfaced for display.+ expect(status.waitTime).toBe('21 hours 52 minutes');+ });++ it('respects a genuinely short stated reset', async () => {+ const svc = createProviderStatusService({+ dataDir: TEST_DATA_DIR, statusFile: 'ps-cap2.json',+ defaultUsageLimitWait: 10 * 60 * 1000, maxUsageLimitWait: 5 * 60 * 60 * 1000,+ });+ await svc.init();+ const status = await svc.markUsageLimit('p', { message: 'limit', waitTime: '2 minutes' });+ expect(benchMs(status)).toBe(2 * 60 * 1000);+ });++ it('hard-caps even an over-long configured default at maxUsageLimitWait', async () => {+ const svc = createProviderStatusService({+ dataDir: TEST_DATA_DIR, statusFile: 'ps-cap3.json',+ defaultUsageLimitWait: 10 * 60 * 60 * 1000, // 10h default (misconfigured)+ maxUsageLimitWait: 5 * 60 * 60 * 1000,+ });+ await svc.init();+ const status = await svc.markUsageLimit('p', { message: 'limit' });+ expect(benchMs(status)).toBe(5 * 60 * 60 * 1000); // capped to 5h+ });+ });+describe('markUnavailable (generic)', () => {it('marks a provider unavailable with an arbitrary reason and explicit waitTimeMs', async () => {const status = await statusService.markUnavailable('test-provider', {diff --git a/server/services/pipeline/seriesAutopilot.js b/server/services/pipeline/seriesAutopilot.jsindex 2b680de6a1..a4871e1721 100644--- a/server/services/pipeline/seriesAutopilot.js+++ b/server/services/pipeline/seriesAutopilot.js@@ -666,7 +666,13 @@ async function runEditorial(sId, record) {const beforeFix = await budgetPause();if (beforeFix) return beforeFix;try {- if (!comment.fix) await generateManuscriptFix(sId, { commentId: comment.id });+ // Thread the run's provider/model override into fix GENERATION (an LLM+ // call) so it honors the same provider as the review — without this the+ // fix silently runs on the active/default provider (and its runtime+ // fallback), which diverges from the run's chosen model and, when the+ // default is rate-limited, degrades fixes onto a weak fallback. Accept+ // is a deterministic edit application (no LLM), so it needs no override.+ if (!comment.fix) await generateManuscriptFix(sId, { commentId: comment.id, ...providerOverrideOpts(record) });await acceptManuscriptFix(sId, { commentId: comment.id });await recordDomainUsage('cos', { actions: 1 });} catch (err) {