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
refactor([coalesce-fallback-provider-failure-storm]): un-orphan pickFallbackProvider JSDoc + drop dead single-flight guard
[._.]/ Adam Eivy6292737da1ec
diff --git a/PLAN.md b/PLAN.mdindex 6ab84d4ca0..c102bd1e24 100644--- a/PLAN.md+++ b/PLAN.md@@ -57,6 +57,7 @@ Claimable, well-specified, no decision needed — `/claim`-able. Unordered.- [ ] [extract-use-universe-load-hook] **Extract a `useUniverse(universeId)` load hook.** `client/src/components/pipeline/stages/StoryboardsStage.jsx` (~line 57) and `NounsStage.jsx` (~line 149) now run a byte-identical `useMounted` + `let cancelled` + `getUniverse(series.universeId).then(...).catch(...)` effect to load the linked universe record. Extract a `client/src/hooks/useUniverse.js` returning `[universe, loading, error]` (handling the mount/cancel guards internally), register it in the hooks `index.js` barrel + README, and migrate both call sites. Deferred from the wardrobe-picking PR: migrating `NounsStage` is outside that diff's scope and the new module trips the barrel maintenance rule. Surfaced by /simplify (reuse, 2026-06-01).- [ ] [wardrobe-appearance-id-route-validation] **Validate `characterAppearances` ids against the linked universe at the persistence boundary.** The generic `POST /issues/:id/stages/:stageId/visual` route (`visualGenerateSchema` in `server/routes/pipeline.js`) accepts `characterAppearances` and validates only shape (`characterId`/`wardrobeId` are non-empty strings), not that the ids actually resolve to a canon character + one of its wardrobes. Today `buildScenePrompt`'s defensive read silently drops unresolved picks (matches the existing scene pass-through convention for `shots`), so this is robustness/clarity, not correctness. If tightened later, resolve the ids against `loadBibleContext(issueId).canon.characters` at the route and 400 on a dangling id rather than relying on the prompt-builder's silent drop. Surfaced by /simplify (altitude, 2026-06-01).- [ ] [create-issue-preload-series-for-batch] **`createIssue`'s renumber pass re-reads the series on every call — preload it for batch episode seeding.** `createIssue` (`server/services/pipeline/issues.js`) calls `getSeries()` inside its `renumberInline` pass on every invocation. `commitEpisodesToIssues` (`server/services/pipeline/arcPlanner.js`) creates one issue per episode in a loop, so a 12-episode season does 12 redundant `getSeries()` reads of an unchanging record (and `generateIssuesFromArc` already fetched it once). Add a `createIssueWithPreloadedSeries(series, input)` variant (or a `{ preloadedSeries }` option) that threads the already-fetched series into `renumberInline`, and route the batch loop through it. Pre-existing in `createIssue` (the Pipeline season-episodes route pays the same cost); LLM-bound batch so the realized win is small — surfaced by /simplify (efficiency) during the story-builder-issue-llm-seeding PR (2026-06-01). Deferred because it touches the `issues.js` renumber internals beyond this diff's scope.+- [ ] [extract-single-flight-map-helper] **Extract a shared single-flight / in-flight-coalescing helper.** Three sites now hand-roll the `Map<key, Promise>` "share the in-flight result, delete on settle" idiom: `server/lib/sseDownload.js` (`inFlight` keyed by repo, line ~12), `server/lib/promptRunner.js` (`_fallbackMarkAndPickInFlight` keyed by failed provider id), and the read-coalescing half of `server/lib/aiToolkit/providers.js#loadProviders` (`providersLoadInFlight`). A small `server/lib/singleFlight.js` (`createSingleFlight()` returning `run(key, fn)` that returns the shared promise and auto-clears on settle) would dedupe the boilerplate and standardize the cleanup. Note the three sites differ in shape — providers.js layers a TTL snapshot cache on top, promptRunner does keyed side-effectful work — so the helper must stay minimal (just the keyed coalesce) and not try to absorb the TTL/cache concern. Deferred from the coalesce-fallback PR: it's a new public lib module (barrel + README maintenance) that also touches an unrelated file, so it warrants its own PR. Surfaced by /simplify (reuse, 2026-06-01).## Blocked / Deferred (skip for `/claim`)diff --git a/server/lib/promptRunner.js b/server/lib/promptRunner.jsindex fc9494d8e6..7b2006ee5a 100644--- a/server/lib/promptRunner.js+++ b/server/lib/promptRunner.js@@ -315,20 +315,6 @@ export async function runPromptThroughProvider(args) {}}-/**- * Pick a fallback provider for `failed`. Honors the failed provider's- * `fallbackProvider` field first, then the toolkit's system priority- * list. Returns `{ provider, model }` (or null when no usable fallback- * exists). `model` is the configured `fallbackModel` hint for the chosen- * fallback (null for system-priority picks, meaning "use the fallback's- * own default") — never the failed provider's model.- *- * The toolkit's `getFallbackProvider` reads `providers[failed.id]` to- * look up the `fallbackProvider` field, so the primary MUST stay in the- * map. Self-loop protection (`fallbackProvider === self`) lives in- * `getFallbackProvider`; the system priority loop already excludes- * `failed.id` by construction.- */// In-flight mark-and-pick work, keyed by the failed provider id. During an// N-way failure storm (one stuck provider, many simultaneous in-flight// calls) every failure would otherwise independently re-read providers.json@@ -363,18 +349,28 @@ function coalesceFallbackMarkAndPick(failed, firstError) {return picked;})();+ // While `work` is in flight, concurrent callers return it without+ // overwriting the slot, so this entry is only ever cleared by its own+ // settle — a plain delete is safe._fallbackMarkAndPickInFlight.set(failed.id, work);- work.finally(() => {- // Only clear if no newer entry replaced ours (it can't, given the- // synchronous set above, but guard anyway so a future caller can't be- // stranded on a deleted slot).- if (_fallbackMarkAndPickInFlight.get(failed.id) === work) {- _fallbackMarkAndPickInFlight.delete(failed.id);- }- });+ work.finally(() => _fallbackMarkAndPickInFlight.delete(failed.id));return work;}+/**+ * Pick a fallback provider for `failed`. Honors the failed provider's+ * `fallbackProvider` field first, then the toolkit's system priority+ * list. Returns `{ provider, model }` (or null when no usable fallback+ * exists). `model` is the configured `fallbackModel` hint for the chosen+ * fallback (null for system-priority picks, meaning "use the fallback's+ * own default") — never the failed provider's model.+ *+ * The toolkit's `getFallbackProvider` reads `providers[failed.id]` to+ * look up the `fallbackProvider` field, so the primary MUST stay in the+ * map. Self-loop protection (`fallbackProvider === self`) lives in+ * `getFallbackProvider`; the system priority loop already excludes+ * `failed.id` by construction.+ */async function pickFallbackProvider(failed) {const toolkit = getAIToolkitInstance();const providerStatus = toolkit?.services?.providerStatus;