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

fix: keep parseGoDuration private to its only caller

Stephen Hilderbrandedb79ee2c54a
diff --git a/server/lib/README.md b/server/lib/README.md
index de041e1457..321119b3a8 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -46,7 +46,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `generationModes.js` | Shared immutable image/video render-backend alphabets (`IMAGE_GEN_MODE[S]`, `QUEUEABLE_IMAGE_MODES`, `VIDEO_GEN_MODE[S]`, and cloud subsets) plus `mediaJobExecutionLane({ kind, mode, remote })` / `MEDIA_JOB_EXECUTION_LANES` — THE media-queue lane rule the scheduler and the public job projection share, kept below both validation and generation services so schemas never import orchestration modules. |
| `mediaJobPreparation.js` | `createMediaJobPreparation()` tracks per-job cancellation before cloud providers install a render handle; `run`, `cancel`, `take`, and `ids` cover preparation, handoff, and bulk cancellation. |
| `imageGenCapabilities.js` | Per-backend image-gen capability literals, a dependency-free leaf beside `generationModes.js`: `EDIT_INCAPABLE_IMAGE_MODES`/`isEditCapableMode` and the derived `I2I_CAPABLE_MODES`, the shipped defaults (`CODEX_IMAGEGEN_DEFAULT_MODEL`/`_EFFORT`, `AGY_IMAGEGEN_DEFAULT_MODEL`, `AGY_IMAGEGEN_IMAGE_MODEL`), the `AGY_`/`GROK_ASPECT_RATIOS` alphabets, and `IMAGE_GEN_PROVIDER_CAPABILITIES` (`supportsModelOverride`, `maxInputImages`, `promptRequiredWithInputImage`) with its `supportsCloudModelOverride`/`maxInputImages`/`cloudPromptRequired` readers. The `services/imageGen/*` modules re-export these, and `client/src/lib/imageGenModes.js` imports them instead of copying them (#6590). |
-| `imageQuotaSignal.js` | `parseQuotaDeferral(text, { now })` — read a provider quota exhaustion that states its own reset out of a failed render's error text, returning `{ resumeAt, resetsInMs }` or `null`. Requires BOTH an exhaustion marker and a parseable Go-style duration (`2h26m1s`), because the text embeds the agent's own prose about the page being rendered. Plus `parseGoDuration`, `formatDeferral`, and `MAX_QUOTA_DEFERRAL_MS`. Consumed by `services/mediaJobQueue` to hold queued renders for a cooling backend instead of burning them against the same wall. |
+| `imageQuotaSignal.js` | `parseQuotaDeferral(text, { now })` — read a provider quota exhaustion that states its own reset out of a failed render's error text, returning `{ resumeAt, resetsInMs }` or `null`. Requires BOTH an exhaustion marker and a parseable Go-style duration (`2h26m1s`), because the text embeds the agent's own prose about the page being rendered. Plus `formatDeferral` and `MAX_QUOTA_DEFERRAL_MS`. Consumed by `services/mediaJobQueue` to hold queued renders for a cooling backend instead of burning them against the same wall. |
| `falImageModels.js` | Curated fal.ai image model catalog, a dependency-free leaf the client imports: `FAL_IMAGE_FAMILIES` (text + `/edit` endpoint per family, per-model reference cap, sizing alphabet, pricing), `FAL_IMAGE_DEFAULT_MODEL`, `FAL_IMAGE_MODEL_IDS` (the only ids a fal `cloudModel` may name), `falImageFamily`/`isFalImageModel`, `falImagePriceLabel`, `buildFalImageRequest` (routes to `/edit` when input images are present; maps width/height to aspect-ratio + resolution tier or pixel `image_size`) and `estimateFalImageCostUsd` (with `FAL_MEGAPIXEL`, fal.ai's binary megapixel). |
| `imageRuntimeRemedies.js` | Local image-runtime vocabulary, a dependency-free leaf beside `imageGenCapabilities.js`: `IMAGE_RUNTIME_READINESS` (ready/unavailable/unknown), `IMAGE_RUNTIME` + `IMAGE_RUNTIME_LABELS` (the shared torch venv vs. the configurable mflux interpreter), `IMAGE_RUNTIME_REMEDY` (the one action that fixes each unavailable state), and `IMAGE_RUNTIME_UNAVAILABLE_CODE`. `services/imageGen/localRuntime.js` builds the diagnosis from these, `services/imageGen/local.js` tags its pre-flight render refusal with the same remedy, and `client/src/lib/imageGenModes.js` re-exports them so no component hand-copies a remedy kind. |
| `renderModeLadder.js` | `resolveRenderPins` and `resolveRenderTargetPins` share backend-scoped model candidate inheritance across browser and server. Image-gen mode resolution ladder (#6815), a dependency-free leaf beside `generationModes.js`/`renderTargets.js` so the client imports it directly instead of hand-copying it: `isModeUsable(settings, mode)` (queueable + enabled gate, no per-provider spec lookup), `pickUsableMode(settings, candidates)` (first usable candidate, falling through disabled pins to the cloud-then-local tail), `renderTargetDefaults(settings, target)` (the normalized `settings.renderDefaults[target]` pin), and `imageModeCandidates(settings, target, record)` (the shared `[recordPin, targetPin, installDefault]` candidate order, declared once so a UI's own "what will Auto resolve to" display can't drift from the resolver). `services/imageGen/cloudProviderConfig.js` re-exports the first three for its existing callers. |
diff --git a/server/lib/imageQuotaSignal.js b/server/lib/imageQuotaSignal.js
index 00c0883a6b..75017caee1 100644
--- a/server/lib/imageQuotaSignal.js
+++ b/server/lib/imageQuotaSignal.js
@@ -49,8 +49,12 @@ const DURATION_PART = /(\d+)\s*([hms])/gi;
/**
* Parse a Go-style compound duration into milliseconds.
* Returns null when the string carries no recognizable unit.
+ *
+ * Module-private: `parseQuotaDeferral` is the only caller, and it is the
+ * contract worth pinning — a duration is only ever meaningful here when it is
+ * anchored to reset wording.
*/
-export function parseGoDuration(text) {
+function parseGoDuration(text) {
if (typeof text !== 'string' || !text.trim()) return null;
// Reject anything beyond digits and h/m/s so a bare number or a stray token
// cannot be read as a duration.
diff --git a/server/lib/imageQuotaSignal.test.js b/server/lib/imageQuotaSignal.test.js
index 6d3d54b2e7..7e55106531 100644
--- a/server/lib/imageQuotaSignal.test.js
+++ b/server/lib/imageQuotaSignal.test.js
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest';
import {
- parseQuotaDeferral, parseGoDuration, formatDeferral, MAX_QUOTA_DEFERRAL_MS,
+ parseQuotaDeferral, formatDeferral, MAX_QUOTA_DEFERRAL_MS,
} from './imageQuotaSignal.js';
// Verbatim shapes recorded by this install on 2026-10-17. Antigravity relays
@@ -57,18 +57,23 @@ describe('parseQuotaDeferral', () => {
});
});
-describe('parseGoDuration', () => {
+// Duration shapes are exercised through the public contract rather than the
+// private helper: a duration only means anything here when it is anchored to
+// reset wording, so that is what is worth pinning.
+describe('reset duration shapes', () => {
+ const withReset = (duration) => `RESOURCE_EXHAUSTED: Your quota will reset after ${duration}.`;
+
it.each([
['2h26m1s', 8_761_000],
['45m10s', 2_710_000],
['30s', 30_000],
['1h', 3_600_000],
- ])('parses %s', (text, expected) => {
- expect(parseGoDuration(text)).toBe(expected);
+ ])('accepts %s', (duration, expected) => {
+ expect(parseQuotaDeferral(withReset(duration), { now: 0 })?.resetsInMs).toBe(expected);
});
- it.each(['12', 'soon', '', '2 hours', '2h30'])('rejects %s', (text) => {
- expect(parseGoDuration(text)).toBeNull();
+ it.each(['12', 'soon', '2 hours', '2h30'])('rejects %s as a duration', (duration) => {
+ expect(parseQuotaDeferral(withReset(duration), { now: 0 })).toBeNull();
});
});