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

don't let a prompt-echoed "credit" or an unreadable ledger read as a quota block

[._.]/ Adam Eivyb146c87454a1
diff --git a/server/services/imageGenQuota.js b/server/services/imageGenQuota.js
index 1f60b88484..c3e9930300 100644
--- a/server/services/imageGenQuota.js
+++ b/server/services/imageGenQuota.js
@@ -113,10 +113,19 @@ const IMAGE_QUOTA_PATTERNS = [
];
// Categories from the shared classifier that mean "refused for quota reasons".
+//
+// QUOTA_EXCEEDED is deliberately EXCLUDED despite the name: its pattern is
+// /billing|payment|credit|insufficient funds/, and the text classified here is
+// the model's own narration, which routinely quotes the image prompt back. A
+// render of "a wizard holding a credit card" that gets declined on content
+// grounds would match on the bare word "credit" and paint a phantom 0%-left
+// meter with no reset. RATE_LIMIT and USAGE_LIMIT key on phrases no image
+// prompt produces by accident ("429", "rate limit", "hit your usage limit").
+// The genuinely-billing image phrasings are covered precisely by
+// IMAGE_QUOTA_PATTERNS above, which requires "out of credits", not "credit".
const QUOTA_CATEGORIES = new Set([
ERROR_CATEGORIES.RATE_LIMIT,
ERROR_CATEGORIES.USAGE_LIMIT,
- ERROR_CATEGORIES.QUOTA_EXCEEDED,
]);
/**
@@ -209,6 +218,23 @@ export async function getImageGenQuota({ enabledModes = [], now = Date.now() } =
if (!tracked.length) return null;
const ledger = await readLedger();
+ // A failed/corrupt read is NOT "no renders" — reporting a cheerful zero for a
+ // ledger we could not read is the sentinel-vs-empty footgun this card exists
+ // to avoid. Say so instead.
+ if (!ledger) {
+ return {
+ family: 'imagegen',
+ label: 'Image Gen',
+ supported: true,
+ burnable: false,
+ limits: [],
+ activity: [],
+ metrics: [],
+ approximate: true,
+ fetchedAt: new Date(now).toISOString(),
+ error: 'Could not read the observed image-quota ledger — render counts and any active limit are unavailable.',
+ };
+ }
const cutoff = now - ACTIVITY_WINDOW_MS;
const limits = [];
const metrics = [];
diff --git a/server/services/imageGenQuota.test.js b/server/services/imageGenQuota.test.js
index e0934a38c6..e0958ce1ff 100644
--- a/server/services/imageGenQuota.test.js
+++ b/server/services/imageGenQuota.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
-import { mkdtemp, rm } from 'fs/promises';
+import { mkdtemp, rm, writeFile } from 'fs/promises';
import { join } from 'path';
import { tmpdir } from 'os';
@@ -57,6 +57,23 @@ describe('parseImageQuotaSignal', () => {
expect(signal.exhausted).toBe(false);
});
+ it('does not treat prompt content echoed in a decline as a quota block', () => {
+ // The classified text is the model's own narration, which quotes the image
+ // prompt back. A bare "credit"/"payment" in the artwork description must
+ // never read as a billing failure and paint a phantom 0%-left meter.
+ const decline = 'Agy said: "I cannot generate that image: a wizard holding a credit card and a payment terminal."';
+ expect(parseImageQuotaSignal(decline).exhausted).toBe(false);
+ });
+
+ it('still catches a genuine out-of-credits refusal', () => {
+ // The precise phrasing survives — only the bare-word match was dropped.
+ expect(parseImageQuotaSignal('Render failed: you are out of credits.').exhausted).toBe(true);
+ });
+
+ it('inherits rate-limit phrasings the shared CLI classifier already knows', () => {
+ expect(parseImageQuotaSignal('Grok said: "too many requests, slow down"').exhausted).toBe(true);
+ });
+
it('does not treat a crashed CLI as a quota block', () => {
expect(parseImageQuotaSignal('Agy generation failed: Exit code 1').exhausted).toBe(false);
expect(parseImageQuotaSignal('Failed to spawn agy: ENOENT').exhausted).toBe(false);
@@ -192,6 +209,15 @@ describe('getImageGenQuota', () => {
expect(card.limits[0].resetsAt).toBe('2026-07-31T21:38:09.000Z');
});
+ it('reports an unreadable ledger as an error, not as zero renders', async () => {
+ // "Could not read" must never render as a reassuring "No renders · 24h" —
+ // that would also silently hide an active block.
+ await writeFile(join(TEST_ROOT, 'imagegen-quota.json'), '{ this is not json');
+ const card = await getImageGenQuota({ enabledModes: ['agy'], now });
+ expect(card.error).toContain('Could not read');
+ expect(card.metrics).toEqual([]);
+ });
+
it('ages renders out of the 24h window', async () => {
await recordImageGenOutcome({ mode: 'agy', ok: true, at: now - 25 * 60 * 60 * 1000 });
await recordImageGenOutcome({ mode: 'agy', ok: true, at: now });