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

stageRunner: let a per-stage provider pin beat a blanket run-level default

[._.]/ Adam Eivy6ec88477af13
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 5eef664d5d..c7bac7e3f1 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -25,6 +25,7 @@
## Added
- **Context-window size on available-model cards (Settings → Local LLM).** The model cards in the install catalog and the Hugging Face search results now show each model's native context window (e.g. "128K ctx") alongside its size and parameter count — previously this only appeared on already-installed models, so you couldn't compare context windows before deciding what to install. Live Hugging Face results read the true value from the repo's GGUF metadata (`gguf.context_length`, backfilled from the same per-repo fetch that already supplies file sizes); curated catalog entries carry it when it's a documented spec for that build.
+- **A per-stage provider pin now beats a blanket run-level provider default.** Pin a single pipeline stage to a specific provider on the Prompts page (e.g. run *Comic Script Verification* on Codex) and it now sticks even while Series Autopilot runs everything else on a different provider. Previously the autopilot's run-wide provider was threaded as a hard *override* that sat above stage pins, so a pinned stage was silently moved onto the run's provider. Provider resolution is now three-tiered — an explicit per-call override (a route's "regenerate with provider X") still wins, then the stage pin, then a blanket run default that only applies to unpinned stages and softly falls through to the active provider when unavailable. The autopilot's script-verify gate threads its run provider as that soft default, so a `pipeline-script-verify` provider pin is honored. (`server/lib/stageRunner.js`, `server/services/pipeline/scriptVerify.js`)
- **Music studio (Create → Music).** A new home for generating and organizing music with local OSS tools, with three tabs:
- **Artists** — reusable musical personas (the audio analogue of Authors): name, genre, bio, musical style, plus a physical description + portrait style used to **generate an artist portrait** with your existing image-gen options, **upload** one, or pick from the gallery.
diff --git a/server/lib/stageRunner.js b/server/lib/stageRunner.js
index fd4102df5a..f8951b656c 100644
--- a/server/lib/stageRunner.js
+++ b/server/lib/stageRunner.js
@@ -213,10 +213,21 @@ export async function resolveStageContext(stageName, options = {}) {
return { provider, model, contextWindow: effectiveContextWindow(provider, model) };
}
-// Stage config can pin a specific provider via `stage.provider`. If set we
-// must use it (or fail) — falling back to the active provider would route
-// silently through whatever's currently selected, defeating the override.
-async function resolveProviderForStage(stage, { providerOverride } = {}) {
+// Provider resolution precedence, strongest first:
+// 1. `providerOverride` — an explicit per-call choice ("run THIS request with
+// provider X right now", e.g. a route's regenerate-with-provider button).
+// The most specific signal, so it beats even a stage pin. Throws if the
+// requested provider is unavailable — the caller asked for it by name.
+// 2. `stage.provider` — a deliberate per-stage pin (Prompts page /
+// stage-config.json). Beats a blanket run-level default so a pinned stage
+// keeps running on its chosen provider even when something sets a different
+// default for everything else (e.g. Series Autopilot's run provider).
+// 3. `providerDefault` — a blanket run-level default that applies ONLY to
+// stages without their own pin. Unlike an override it is a soft preference:
+// if it's unavailable we fall through to the active provider rather than
+// throwing, because it was never a per-call demand.
+// 4. The active provider — the system-wide fallback.
+async function resolveProviderForStage(stage, { providerOverride, providerDefault } = {}) {
if (providerOverride) {
const pinned = await getProviderById(providerOverride).catch(() => null);
if (pinned?.enabled) return pinned;
@@ -233,6 +244,12 @@ async function resolveProviderForStage(stage, { providerOverride } = {}) {
{ status: 503, code: 'STAGE_PROVIDER_UNAVAILABLE' }
);
}
+ if (providerDefault) {
+ const fallback = await getProviderById(providerDefault).catch(() => null);
+ if (fallback?.enabled) return fallback;
+ // Soft default: an unavailable run default is not a hard error — drop to the
+ // active provider below instead of throwing.
+ }
const active = await getActiveProvider().catch(() => null);
if (active?.enabled) return active;
throw new ServerError('No AI provider available', { status: 503, code: 'NO_PROVIDER' });
@@ -333,7 +350,10 @@ export function extractJson(text, { promptToStrip } = {}) {
* (or the parsed JSON in the `content` field when `returnsJson` is true).
*
* Options:
- * - providerOverride: explicit provider id, beats stage.provider
+ * - providerOverride: explicit per-call provider id, beats stage.provider
+ * - providerDefault: blanket run-level provider id used ONLY when the stage has
+ * no pin of its own; loses to stage.provider and falls through to the active
+ * provider if unavailable (see resolveProviderForStage)
* - modelOverride: explicit model id, beats stage.model
* - timeoutOverride: explicit ms timeout, beats stage.timeout and the provider default
* - returnsJson: parse `content` via `extractJson` before returning
diff --git a/server/lib/stageRunner.test.js b/server/lib/stageRunner.test.js
index 826f2ec595..45fc62b18e 100644
--- a/server/lib/stageRunner.test.js
+++ b/server/lib/stageRunner.test.js
@@ -256,6 +256,46 @@ describe('stageRunner — runStagedLLM provider resolution', () => {
expect(out.providerId).toBe('stage-pinned');
});
+ it('lets stage.provider beat a blanket providerDefault (pin wins over run default)', async () => {
+ prompts.getStage.mockReturnValue({ provider: 'stage-pinned' });
+ providers.getProviderById.mockImplementation(async (id) => (
+ id === 'stage-pinned' ? apiProvider({ id: 'stage-pinned' }) : apiProvider({ id })
+ ));
+ runner.executeApiRun.mockImplementation(async ({ onData, onComplete }) => {
+ onData('pinned');
+ onComplete({ success: true });
+ });
+ const out = await runStagedLLM('s', {}, { providerDefault: 'run-default' });
+ expect(out.providerId).toBe('stage-pinned');
+ expect(providers.getActiveProvider).not.toHaveBeenCalled();
+ });
+
+ it('uses providerDefault when the stage has no pin', async () => {
+ prompts.getStage.mockReturnValue(null);
+ providers.getProviderById.mockImplementation(async (id) => (
+ id === 'run-default' ? apiProvider({ id: 'run-default' }) : null
+ ));
+ runner.executeApiRun.mockImplementation(async ({ onData, onComplete }) => {
+ onData('defaulted');
+ onComplete({ success: true });
+ });
+ const out = await runStagedLLM('s', {}, { providerDefault: 'run-default' });
+ expect(out.providerId).toBe('run-default');
+ expect(providers.getActiveProvider).not.toHaveBeenCalled();
+ });
+
+ it('falls through to the active provider when providerDefault is unavailable (soft default)', async () => {
+ prompts.getStage.mockReturnValue(null);
+ providers.getProviderById.mockResolvedValue(null);
+ providers.getActiveProvider.mockResolvedValue(apiProvider());
+ runner.executeApiRun.mockImplementation(async ({ onData, onComplete }) => {
+ onData('active');
+ onComplete({ success: true });
+ });
+ const out = await runStagedLLM('s', {}, { providerDefault: 'gone' });
+ expect(out.providerId).toBe('mock-api');
+ });
+
it('throws STAGE_PROVIDER_UNAVAILABLE when stage.provider is set but disabled', async () => {
prompts.getStage.mockReturnValue({ provider: 'pinned-but-gone' });
providers.getProviderById.mockResolvedValue(null);
diff --git a/server/services/pipeline/scriptVerify.js b/server/services/pipeline/scriptVerify.js
index ed46c6fba8..31dff54108 100644
--- a/server/services/pipeline/scriptVerify.js
+++ b/server/services/pipeline/scriptVerify.js
@@ -193,6 +193,11 @@ function mergeVerifyIssues(first, second) {
* `{ issues:[{severity,location,problem,suggestion}], raw, runId, providerId,
* model }`, or `{ issues: [], skipped }` when there's no comic script to check.
*/
+// `providerId` here is Series Autopilot's blanket run provider, NOT a per-call
+// demand for this specific stage — so it's threaded as a `providerDefault`. That
+// lets a deliberate `pipeline-script-verify` provider pin (Prompts page) win,
+// e.g. running the craft pass on Codex while the rest of the run uses another
+// provider, while an unpinned stage still follows the run's chosen provider.
export async function verifyComicScript(issueId, { providerId, model } = {}) {
const issue = await getIssue(issueId);
const script = (issue.stages?.comicScript?.output || '').trim();
@@ -204,7 +209,7 @@ export async function verifyComicScript(issueId, { providerId, model } = {}) {
// Scale the content cap to the target model's context window — never below
// CONTENT_MAX (so we never truncate more than the historical floor), but a
// big-context model gets the whole script. Mirrors editorialAnalysis.
- const { contextWindow } = await resolveStageContext(STAGE, { providerOverride: providerId, modelOverride: model });
+ const { contextWindow } = await resolveStageContext(STAGE, { providerDefault: providerId, modelOverride: model });
const overheadTokens = 1_200 + estimateTokens([series?.name, series?.logline, issue.title].filter(Boolean).join(' '));
const budgetChars = usableInputTokens({
contextWindow,
@@ -224,7 +229,7 @@ export async function verifyComicScript(issueId, { providerId, model } = {}) {
const { content: parsed, runId, providerId: pid, model: m } = await runStagedLLM(STAGE, ctx, {
returnsJson: true,
- providerOverride: providerId,
+ providerDefault: providerId,
modelOverride: model,
source: 'pipeline-script-verify',
});