Skip to content

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

burn every eligible quota family per cycle, not just the soonest to reset

[._.]/ Adam Eivy0472550a7bc2
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 7b43a63541..01c1bfcc61 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -24,6 +24,8 @@
## Fixed
+- **Quota burn stopped after the first family it dispatched, so a longer-windowed provider never burned at all.** A cycle selected every family whose window was inside its reset horizon, sorted them soonest-reset-first — and then returned after the first successful dispatch. Families do not share a budget: each draws down its own subscription window, against its own reserve and its own `maxDispatchesPerWindow`, so stopping early protected nothing. It just meant the soonest-resetting family took every cycle. A `claude` window resetting in 2h beat an `agy` window resetting in 21h on every tick, and the Antigravity plan sat at "93% left · 0/5 used" indefinitely while its eight configured audits never ran. A cycle now dispatches one job per *family*, records a run-log row per dispatch (so no family is hidden from the audit list), charges each window against its own key, and continues past a family whose job declines. When several plans are walked, every skip reason is prefixed with the family it came from.
+
- **The `ignore-scripts` supply-chain guard was silently inactive for every workspace install, including CI.** The repo-root `.npmrc` has pinned `ignore-scripts=true` for a while, but npm resolves the project `.npmrc` from the *local prefix* and never walks up the directory tree — so it never applied to `cd client && npm install`, `cd server && npm install`, or `npm ci --prefix server` / `--prefix client`, which is exactly what CI runs and what the documented per-workspace test workflow uses. In those paths every dependency kept an install-time code-execution slot: the same slot the August 2026 keyv/cacheable (Shai-Hulud) worm used, via a `preinstall` hook, to harvest credentials before any application code ran. `client/`, `server/`, `autofixer/`, and `browser/` now each carry their own `.npmrc`, so the guard holds in every workspace install path — whether entered by `cd`ing in or via `--prefix`.
Closing the hole made the trusted-rebuild allowlist load-bearing for the first time, and it had drifted across its five copies (the root `setup` script, `scripts/ensure-deps.js`, `update.sh`, `update.ps1`, `setup.ps1`): the `esbuild` entries were dead — vite 8 dropped that dependency — while `onnxruntime-node` and `protobufjs` were missing entirely, so CI ran install hooks that the local setup skipped. All five now read one allowlist from `scripts/trusted-rebuilds.js`, and CI rebuilds it explicitly after installing server dependencies so `node-pty`'s native binding is still present for the smoke-boot. `scripts/trusted-rebuilds.test.js` fails if any workspace `.npmrc` loses the setting, or if a dependency shows up with an install hook nobody has decided about — the second case being how a missing native build otherwise surfaces much later as a confusing runtime crash.
diff --git a/client/src/pages/QuotaBurn.jsx b/client/src/pages/QuotaBurn.jsx
index a36416712e..db48e7456f 100644
--- a/client/src/pages/QuotaBurn.jsx
+++ b/client/src/pages/QuotaBurn.jsx
@@ -258,9 +258,9 @@ export default function QuotaBurn() {
</div>
</div>
<p className="text-xs text-gray-400">
- One loop for this install. Each provider family burns only inside its reset window, above its reserve, and within its
- dispatch cap — running the first job in its plan that has work waiting. Turning this on is explicit consent to spend
- those subscriptions on a schedule.
+ One loop for this install, but each provider family burns independently: every family whose window is inside its reset
+ horizon, above its reserve, and under its dispatch cap runs the first job in its plan that has work waiting — one job
+ per family per cycle. Turning this on is explicit consent to spend those subscriptions on a schedule.
</p>
{lastRun && (
<p className="text-[11px] text-gray-500">
diff --git a/server/services/quotaBurnRunner.js b/server/services/quotaBurnRunner.js
index 97d8e4452e..5942ca1148 100644
--- a/server/services/quotaBurnRunner.js
+++ b/server/services/quotaBurnRunner.js
@@ -5,8 +5,16 @@
* what this replaced): every `checkIntervalMinutes` it reads the burn plan,
* takes a zero-token quota reading, and — only when a family's window is inside
* its reset horizon with headroom above its reserve — runs the first job in that
- * family's ordered plan that reports pending work. At most ONE dispatch per
- * cycle, so a cycle can never blow through several windows' budgets at once.
+ * family's ordered plan that reports pending work.
+ *
+ * At most one dispatch per FAMILY per cycle. Families do not share a budget:
+ * each one draws down its own subscription window, against its own reserve and
+ * its own `maxDispatchesPerWindow`. Stopping the whole cycle after the first
+ * dispatch (which is what this used to do) therefore didn't protect anything —
+ * it just meant the soonest-resetting family took every cycle, and a family with
+ * a longer window never burned at all while it was enabled. A `claude` window
+ * resetting in 2h beat an `agy` window resetting in 21h on every single tick, so
+ * the agy plan sat at "93% left · 0/5 used" indefinitely.
*
* AI-policy posture (CLAUDE.md): this is a sanctioned scheduled automation —
* disabled by default, armed only by an explicit opt-in on the Quota Burn page,
@@ -175,6 +183,11 @@ async function evaluate({ trigger = 'scheduled', familyId = null, jobId = null,
}
const attempts = [];
+ const dispatched = [];
+ // Every eligible family gets its own dispatch — see the module header. The
+ // loop does NOT break on the first success: `candidates` is already the set
+ // that passed the full gate ladder, and each entry spends a different
+ // provider's window.
for (const candidate of candidates) {
const outcome = await dispatchFromCandidate(candidate, { jobId, force });
attempts.push(...outcome.attempts.map((entry) => ({ familyId: candidate.family.id, ...entry })));
@@ -184,7 +197,10 @@ async function evaluate({ trigger = 'scheduled', familyId = null, jobId = null,
// the cap bounds real burns, not attempts. `charge` is false for a forced
// run, which the user asked for outside the automatic budget.
if (candidate.charge) await recordQuotaBurnDispatch(candidate.dispatchKey);
- return finish({
+ // One run-log entry PER dispatch, recorded as it happens: the page's
+ // "Recent runs" list is how the user audits what their subscriptions were
+ // spent on, and folding three families into one row would hide two of them.
+ dispatched.push(await finish({
dispatched: true,
familyId: candidate.family.id,
jobId: outcome.job.id,
@@ -195,7 +211,19 @@ async function evaluate({ trigger = 'scheduled', familyId = null, jobId = null,
percentRemaining: candidate.limit?.percentRemaining ?? null,
summary: outcome.result.summary || 'dispatched',
detail: outcome.result.detail || null,
- });
+ }));
+ }
+
+ // Single dispatch keeps the flat entry shape the route, the run log, and the
+ // tests already speak. Several come back as one aggregate so the caller's
+ // toast names all of them rather than an arbitrary first.
+ if (dispatched.length === 1) return dispatched[0];
+ if (dispatched.length > 1) {
+ return {
+ dispatched: true,
+ summary: `Dispatched ${dispatched.length} jobs — ${dispatched.map((entry) => `${entry.familyId}: ${entry.summary}`).join('; ')}`,
+ dispatches: dispatched,
+ };
}
// Report what each job actually said. Collapsing every non-dispatch to "no
@@ -203,13 +231,17 @@ async function evaluate({ trigger = 'scheduled', familyId = null, jobId = null,
// work and declined ("an identical burn task is already running", "managed
// app app-x no longer exists", "no enabled CLI/TUI provider in the grok
// family") is the actionable case, and it was the one being thrown away.
- const detail = attempts.map((entry) => `${entry.jobId}: ${entry.skipped}`).join('; ');
+ // Prefix each reason with its family once more than one was evaluated —
+ // "j: no managed app selected" is unactionable when three plans were walked.
+ const label = (entry) => (candidates.length > 1 ? `${entry.familyId}/${entry.jobId}` : entry.jobId);
+ const detail = attempts.map((entry) => `${label(entry)}: ${entry.skipped}`).join('; ');
+ const plans = candidates.map((candidate) => candidate.family.id).join(', ');
return finish({
dispatched: false,
familyId: candidates[0].family.id,
reason: detail
? `nothing dispatched — ${detail}`
- : `no enabled job in the ${candidates[0].family.id} plan`,
+ : `no enabled job in the ${plans} plan${candidates.length > 1 ? 's' : ''}`,
});
}
diff --git a/server/services/quotaBurnRunner.test.js b/server/services/quotaBurnRunner.test.js
index 5466d06257..a099d4028d 100644
--- a/server/services/quotaBurnRunner.test.js
+++ b/server/services/quotaBurnRunner.test.js
@@ -167,6 +167,71 @@ describe('runQuotaBurnCycle', () => {
expect(state.recorded).toEqual([]);
});
+ it('burns EVERY eligible family in one cycle, not just the soonest to reset', async () => {
+ // Families don't share a budget — each draws down its own window against its
+ // own reserve and cap. Stopping the cycle at the first dispatch meant the
+ // soonest-resetting family took every tick and a longer-windowed one
+ // (claude at 2h vs agy at 21h) never burned at all while claude was enabled.
+ state.config = normalizeQuotaBurnConfig({
+ enabled: true,
+ families: {
+ claude: { enabled: true, resetWithinHours: 24, jobs: [{ id: 'soon', enabled: true, jobType: 'agent-prompt' }] },
+ agy: { enabled: true, resetWithinHours: 24, jobs: [{ id: 'later', enabled: true, jobType: 'agent-prompt' }] },
+ },
+ });
+ state.quotas = [
+ { family: 'claude', label: 'claude', supported: true, limits: [{ key: 'session', scope: 'session', resetsAt: new Date(now + 2 * 3600_000).toISOString(), percentRemaining: 90 }] },
+ { family: 'agy', label: 'agy', supported: true, limits: [{ key: 'day', scope: 'day', resetsAt: new Date(now + 21 * 3600_000).toISOString(), percentRemaining: 93 }] },
+ ];
+ state.pending = { soon: { count: 1 }, later: { count: 1 } };
+
+ const result = await runQuotaBurnCycle();
+ expect(result.dispatched).toBe(true);
+ expect(state.ran.map((entry) => entry.familyId)).toEqual(['claude', 'agy']);
+ // Both windows charged — each against its OWN dispatch key.
+ expect(state.recorded).toHaveLength(2);
+ expect(new Set(state.recorded).size).toBe(2);
+ // One run-log row per dispatch, so neither family is hidden from the audit.
+ expect(state.runs.filter((entry) => entry.dispatched)).toHaveLength(2);
+ expect(result.dispatches).toHaveLength(2);
+ expect(result.summary).toMatch(/agy/);
+ });
+
+ it('still dispatches the healthy family when another one\'s job declines', async () => {
+ state.config = normalizeQuotaBurnConfig({
+ enabled: true,
+ families: {
+ claude: { enabled: true, resetWithinHours: 24, jobs: [{ id: 'broken', enabled: true, jobType: 'agent-prompt' }] },
+ agy: { enabled: true, resetWithinHours: 24, jobs: [{ id: 'good', enabled: true, jobType: 'agent-prompt' }] },
+ },
+ });
+ state.quotas = [card('claude'), card('agy')];
+ state.pending = { broken: { count: 1 }, good: { count: 1 } };
+ const { runBurnJob } = await import('./quotaBurnJobs/index.js');
+ runBurnJob.mockImplementationOnce(async () => ({ dispatched: false, reason: 'no managed app selected' }));
+
+ const result = await runQuotaBurnCycle();
+ expect(result.dispatched).toBe(true);
+ expect(result.familyId).toBe('agy');
+ // Only the family that actually started work is charged.
+ expect(state.recorded).toHaveLength(1);
+ });
+
+ it('names the family in every skip reason when several plans were walked', async () => {
+ state.config = normalizeQuotaBurnConfig({
+ enabled: true,
+ families: {
+ claude: { enabled: true, resetWithinHours: 24, jobs: [{ id: 'a', enabled: true, jobType: 'agent-prompt' }] },
+ agy: { enabled: true, resetWithinHours: 24, jobs: [{ id: 'b', enabled: true, jobType: 'agent-prompt' }] },
+ },
+ });
+ state.quotas = [card('claude'), card('agy')];
+ state.pending = { a: { count: 0, detail: 'no app' }, b: { count: 0, detail: 'no app' } };
+ const result = await runQuotaBurnCycle();
+ expect(result.reason).toMatch(/claude\/a: no app/);
+ expect(result.reason).toMatch(/agy\/b: no app/);
+ });
+
it('releases the re-entrancy guard even when a cycle throws', async () => {
// Without the finally, an ENOSPC on the ledger write (or any other throw)
// would leave `running` stuck true and wedge the loop for the life of the