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

address review (codex): run model must override a stage TIER, only lose to an explicit pin

Adam Eivydc7417903bcd
diff --git a/server/lib/stageRunner.js b/server/lib/stageRunner.js
index cff668b2a0..053b07f84b 100644
--- a/server/lib/stageRunner.js
+++ b/server/lib/stageRunner.js
@@ -84,6 +84,33 @@ export function resolveModel(provider, modelHint) {
return modelHint;
}
+// Compose the model hint for a stage with soft-default awareness (#1558).
+//
+// The model dimension is NOT symmetric with the provider dimension. A
+// `stage.provider` is opt-in — almost no stage sets one — so a run-level
+// `providerDefault` applies to the common (unpinned) case and only loses to the
+// rare deliberate `stage.provider` pin. But nearly every stage in the shipped
+// `stage-config.json` carries a `stage.model` *tier* value (`default`/`quick`/
+// `coding`/`heavy`) — that tier is the model-dimension equivalent of "no
+// provider pinned", a default mapping, NOT a deliberate per-stage model choice.
+// So a run-level `modelDefault` must OVERRIDE a stage's tier (otherwise
+// launching Series Autopilot with a model would be a no-op on ~every stage),
+// while still LOSING to a deliberate explicit-model pin (an actual model id like
+// `lmstudio:gptoss-20b`, the case #1558 set out to protect).
+//
+// Precedence, strongest first:
+// 1. modelOverride — hard per-call model id (manual "regenerate with model X")
+// 2. explicit stage.model — a deliberate pin (non-tier model id) beats the run default
+// 3. modelDefault — the run-level soft default (Series Autopilot's run model)
+// 4. stage.model tier — the stage's default tier mapping (default/quick/coding/heavy)
+// 5. provider default — resolveModel's own fallback
+function resolveModelHint(stage, options = {}) {
+ const stageModel = stage?.model;
+ const stagePin = stageModel && !isTierName(stageModel) ? stageModel : null;
+ const stageTier = isTierName(stageModel) ? stageModel : null;
+ return options.modelOverride || stagePin || options.modelDefault || stageTier || null;
+}
+
// A conservative-large window assumed for frontier CLI / cloud-API providers
// that haven't declared one. 128K is below every current frontier model's real
// ceiling (Claude/GPT/Gemini are ≥128K, often ~1M), so it means "a typical
@@ -170,7 +197,7 @@ export function effectiveContextWindow(provider, model) {
export async function resolveStageContext(stageName, options = {}) {
const stage = getStage(stageName);
const provider = await resolveProviderForStage(stage, options);
- const requestedModel = resolveModel(provider, options.modelOverride || stage?.model || options.modelDefault);
+ const requestedModel = resolveModel(provider, resolveModelHint(stage, options));
const model = resolveEffectiveModel(provider, requestedModel);
return { provider, model, contextWindow: effectiveContextWindow(provider, model) };
}
@@ -316,11 +343,13 @@ export function extractJson(text, { promptToStrip } = {}) {
* - 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 (hard), beats stage.model
- * - modelDefault: blanket run-level model id used ONLY when the stage has no
- * `model` pin of its own and no `modelOverride` was given; the model-dimension
- * analog of `providerDefault` (Series Autopilot, #1558). Precedence in
- * resolveModel: modelOverride > stage.model > modelDefault > provider default.
+ * - modelOverride: explicit model id (hard), beats everything
+ * - modelDefault: blanket run-level model id (Series Autopilot's run model,
+ * #1558). Soft: it OVERRIDES a stage's tier value (default/quick/coding/heavy)
+ * but LOSES to a deliberate explicit-model pin (a non-tier model id) and to a
+ * hard modelOverride. See resolveModelHint for the full precedence — the model
+ * dimension is deliberately NOT symmetric with providerDefault because nearly
+ * every stage carries a tier value while stage.provider is opt-in.
* - timeoutOverride: explicit ms timeout, beats stage.timeout and the provider default
* - returnsJson: parse `content` via `extractJson` before returning
* - source: free-form tag persisted on the run record (e.g. 'pipeline-text-stage',
@@ -381,7 +410,7 @@ export async function runStageScopedInlineLLM(stageName, prompt, options = {}) {
*/
async function executeStagePrompt({ stage, label, prompt, options }) {
const provider = await resolveProviderForStage(stage, options);
- const resolvedModel = resolveModel(provider, options.modelOverride || stage?.model || options.modelDefault);
+ const resolvedModel = resolveModel(provider, resolveModelHint(stage, options));
// resolveEffectiveModel gates the override per provider type and, for
// CLI providers with a baked --model/-m flag in args, extracts the
// args-pinned model id so the run record + log line reflect what
diff --git a/server/lib/stageRunner.test.js b/server/lib/stageRunner.test.js
index c5c56126d9..aa48ea0863 100644
--- a/server/lib/stageRunner.test.js
+++ b/server/lib/stageRunner.test.js
@@ -316,22 +316,43 @@ describe('stageRunner — runStagedLLM provider resolution', () => {
});
// Soft model-default tier (#1558): mirrors the providerDefault provider tests
-// above, one dimension over. Precedence is modelOverride (hard) > stage.model
-// (pin) > modelDefault (soft, Series Autopilot's run model) > provider default.
-// Each case asserts the model carried into the run record (out.model), which is
-// resolveEffectiveModel(provider, resolveModel(...)) for the api provider here.
+// above, one dimension over — but deliberately NOT symmetric. Precedence is
+// modelOverride (hard) > explicit stage.model pin > modelDefault (soft, Series
+// Autopilot's run model) > stage.model tier > provider default. The key
+// asymmetry (and the bug codex caught in review): nearly every stage carries a
+// *tier* value, which the run model MUST override — only an explicit model id is
+// a deliberate pin that beats the run model. Each case asserts the model carried
+// into the run record (out.model) = resolveEffectiveModel(provider, resolveModel(...)).
describe('stageRunner — runStagedLLM model resolution (#1558)', () => {
const onComplete = (text) => async ({ onData, onComplete: done }) => { onData(text); done({ success: true }); };
- it('lets stage.model beat a blanket modelDefault (pin wins over the autopilot run model)', async () => {
- prompts.getStage.mockReturnValue({ model: 'stage-model' });
+ it('lets an explicit stage.model pin beat a blanket modelDefault (deliberate pin wins)', async () => {
+ prompts.getStage.mockReturnValue({ model: 'pinned-model-id' });
providers.getActiveProvider.mockResolvedValue(apiProvider());
runner.executeApiRun.mockImplementation(onComplete('ok'));
const out = await runStagedLLM('s', {}, { modelDefault: 'run-model' });
- expect(out.model).toBe('stage-model');
+ expect(out.model).toBe('pinned-model-id');
});
- it('uses modelDefault when the stage has no model pin', async () => {
+ it('lets modelDefault OVERRIDE a stage TIER value (the run model applies to unpinned/tier stages)', async () => {
+ // A tier (default/quick/coding/heavy) is NOT a deliberate pin — the run model
+ // must win, else launching autopilot with a model is a no-op on ~every stage.
+ prompts.getStage.mockReturnValue({ model: 'heavy' });
+ providers.getActiveProvider.mockResolvedValue(apiProvider({ heavyModel: 'h' }));
+ runner.executeApiRun.mockImplementation(onComplete('ok'));
+ const out = await runStagedLLM('s', {}, { modelDefault: 'run-model' });
+ expect(out.model).toBe('run-model');
+ });
+
+ it('resolves a stage TIER normally when no modelDefault is set (unchanged behavior)', async () => {
+ prompts.getStage.mockReturnValue({ model: 'heavy' });
+ providers.getActiveProvider.mockResolvedValue(apiProvider({ heavyModel: 'h' }));
+ runner.executeApiRun.mockImplementation(onComplete('ok'));
+ const out = await runStagedLLM('s', {});
+ expect(out.model).toBe('h');
+ });
+
+ it('uses modelDefault when the stage has no model field at all', async () => {
prompts.getStage.mockReturnValue(null);
providers.getActiveProvider.mockResolvedValue(apiProvider());
runner.executeApiRun.mockImplementation(onComplete('ok'));
@@ -339,15 +360,15 @@ describe('stageRunner — runStagedLLM model resolution (#1558)', () => {
expect(out.model).toBe('run-model');
});
- it('lets modelOverride (hard) beat both stage.model and modelDefault', async () => {
- prompts.getStage.mockReturnValue({ model: 'stage-model' });
+ it('lets modelOverride (hard) beat an explicit pin, a tier, and modelDefault', async () => {
+ prompts.getStage.mockReturnValue({ model: 'pinned-model-id' });
providers.getActiveProvider.mockResolvedValue(apiProvider());
runner.executeApiRun.mockImplementation(onComplete('ok'));
const out = await runStagedLLM('s', {}, { modelOverride: 'hard-model', modelDefault: 'run-model' });
expect(out.model).toBe('hard-model');
});
- it('falls through to the provider default when no override, pin, or modelDefault is set', async () => {
+ it('falls through to the provider default when no override, pin, tier, or modelDefault is set', async () => {
prompts.getStage.mockReturnValue(null);
providers.getActiveProvider.mockResolvedValue(apiProvider());
runner.executeApiRun.mockImplementation(onComplete('ok'));
diff --git a/server/services/pipeline/reverseOutline.js b/server/services/pipeline/reverseOutline.js
index 7ad8fd03e9..fc8372f326 100644
--- a/server/services/pipeline/reverseOutline.js
+++ b/server/services/pipeline/reverseOutline.js
@@ -231,8 +231,8 @@ async function buildManuscriptCorpus(seriesId) {
* (#1349/#1514): loses to a per-stage pin and soft-falls-through to active
* when unavailable, unlike the hard providerId
* - modelIdDefault — Series Autopilot's run model as a SOFT default (#1558):
- * loses to a per-stage `model` pin, the model-dimension analog of
- * providerIdDefault, unlike the hard model
+ * overrides the stage's tier value but loses to a deliberate explicit-model
+ * pin (and to the hard model). See stageRunner.resolveModelHint.
* - force — re-segment even when the manuscript hash is unchanged
* - signal — AbortSignal checked before the persist
*/
diff --git a/server/services/pipeline/seriesAutopilot.js b/server/services/pipeline/seriesAutopilot.js
index 56b881f0b2..db4b01fb99 100644
--- a/server/services/pipeline/seriesAutopilot.js
+++ b/server/services/pipeline/seriesAutopilot.js
@@ -506,9 +506,12 @@ async function fileGap(record, sId, { gapKind, issueId = null, summary, context
// on stageRunner's soft channel (`providerDefault` tier 3 / `modelDefault`): it
// applies only to UNPINNED stages and soft-falls-through (to the active provider
// / the provider's default model) when unavailable, rather than throwing
-// PROVIDER_OVERRIDE_UNAVAILABLE or beating a stage's deliberate `model` pin the
-// way a hard override would. Before #1558 the model was still threaded as a hard
-// `modelOverride`, which let the run model beat a pinned stage's own model.
+// PROVIDER_OVERRIDE_UNAVAILABLE or beating a stage's deliberate pin the way a
+// hard override would. For the model dimension "unpinned" means a stage carrying
+// only a *tier* value (default/quick/coding/heavy) — the run model overrides the
+// tier but still loses to a deliberate explicit-model pin (see
+// stageRunner.resolveModelHint). Before #1558 the model was threaded as a hard
+// `modelOverride`, which let the run model beat even an explicit stage pin.
//
// Two shapes because the delegated services disagree on field names: the
// arc/episode/verify passes take `providerDefault`/`modelDefault`; the child