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 (claude): close the gaps a fail-closed lane's alternate could slip through

Adam Eivy38f2a9cf8c9c
diff --git a/server/lib/cosValidation.js b/server/lib/cosValidation.js
index 1314503bef..52e20c9aa5 100644
--- a/server/lib/cosValidation.js
+++ b/server/lib/cosValidation.js
@@ -141,7 +141,21 @@ const orchestrationRoleSchema = z.object({
// walking the run-level fallback chain back onto the architect's provider.
fallbackProvider: z.string().trim().min(1).max(120).optional(),
fallbackModel: z.string().trim().min(1).max(300).optional(),
-}).strict();
+}).strict().superRefine((role, ctx) => {
+ // Reject here what `normalizeRoleAssignment` would silently drop, and what the
+ // resolver would refuse at spawn time. Accepting them returns 200 for a profile
+ // that is permanently inert (or that stops every run the first time its provider
+ // blinks), and the user finds out only when a task blocks days later.
+ if (role.fallbackProvider && !role.provider && !role.model) {
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['fallbackProvider'], message: 'fallbackProvider needs a provider or model pin on the same role to be an alternate to' });
+ }
+ if (role.fallbackModel && !role.fallbackProvider) {
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['fallbackModel'], message: 'fallbackModel needs a fallbackProvider on the same role' });
+ }
+ if (role.model && role.fallbackProvider && !role.fallbackModel) {
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['fallbackModel'], message: 'a role pinning a model must name the fallbackModel its fallbackProvider runs it as' });
+ }
+});
export const orchestrationProfileSchema = z.object(
Object.fromEntries(ORCHESTRATION_ROLES.map(role => [role, orchestrationRoleSchema.optional()]))
diff --git a/server/lib/cosValidation.test.js b/server/lib/cosValidation.test.js
index abb9f5d904..87d7fff6df 100644
--- a/server/lib/cosValidation.test.js
+++ b/server/lib/cosValidation.test.js
@@ -280,3 +280,39 @@ describe('createCosTaskSchema isInvestigation (#6043)', () => {
expect(parsed).not.toHaveProperty('investigationFingerprint');
});
});
+
+/**
+ * Same-role alternates (#5993). The schema rejects exactly what the normalizer
+ * would drop and what the resolver would refuse — a 200 on a permanently-inert
+ * profile is a configuration the user only discovers when a task blocks later.
+ */
+describe('cosValidation orchestration role alternates', () => {
+ const parseRole = (architect) => createCosTaskSchema.safeParse({
+ description: 'x',
+ orchestrationProfile: { architect },
+ });
+
+ it('accepts an alternate beside a provider pin', () => {
+ expect(parseRole({ provider: 'p-cheap', fallbackProvider: 'p-cheap-2' }).success).toBe(true);
+ });
+
+ it('accepts a model-pinned role whose alternate names its own model', () => {
+ expect(parseRole({
+ provider: 'p-cheap', model: 'm-cheap', fallbackProvider: 'p-cheap-2', fallbackModel: 'm-cheap-2',
+ }).success).toBe(true);
+ });
+
+ it('rejects an alternate with no pin to be an alternate to', () => {
+ expect(parseRole({ effort: 'high', fallbackProvider: 'p-cheap-2' }).success).toBe(false);
+ });
+
+ it('rejects a fallbackModel with no fallbackProvider', () => {
+ expect(parseRole({ provider: 'p-cheap', fallbackModel: 'm-cheap-2' }).success).toBe(false);
+ });
+
+ it('rejects a model-pinned role whose alternate has no model to run it as', () => {
+ // Accepting this would let the run silently land on the alternate's own
+ // default — the substitution the fail-closed lane exists to prevent.
+ expect(parseRole({ provider: 'p-cheap', model: 'm-cheap', fallbackProvider: 'p-cheap-2' }).success).toBe(false);
+ });
+});
diff --git a/server/lib/orchestrationProfile.js b/server/lib/orchestrationProfile.js
index ad50e0d96c..9daa75082c 100644
--- a/server/lib/orchestrationProfile.js
+++ b/server/lib/orchestrationProfile.js
@@ -77,16 +77,21 @@ const trimmedString = (value, maxLength) => {
* (#5993): the only substitution a configured lane accepts when its provider is
* unavailable. It is deliberately per-role rather than the run-level
* `metadata.fallbackProvider`, because the run-level chain is what silently
- * collapses a cheap cross-vendor lane back onto the architect's provider. A
- * fallback pinned with no primary `provider` is dropped — there is nothing for
- * it to be an alternate TO, and keeping it would read as a second pin.
+ * collapses a cheap cross-vendor lane back onto the architect's provider.
+ *
+ * It rides on a `provider` OR a `model` pin — the same pair the resolver treats
+ * as fail-closed. A MODEL-only role is fail-closed too (its model is what the
+ * generic chain would drop), so it needs the alternate just as much; dropping
+ * one there would leave the refusal telling the user to configure a field this
+ * normalizer discards. A fallback pinned beside neither is dropped: there is
+ * nothing for it to be an alternate TO, and keeping it would read as a lane.
*/
function normalizeRoleAssignment(raw) {
if (!isPlainObject(raw)) return null;
const provider = trimmedString(raw.provider, MAX_PROVIDER_ID_LENGTH);
const model = trimmedString(raw.model, MAX_MODEL_ID_LENGTH);
const effort = EFFORT_LEVELS.includes(raw.effort) ? raw.effort : null;
- const fallbackProvider = provider ? trimmedString(raw.fallbackProvider, MAX_PROVIDER_ID_LENGTH) : null;
+ const fallbackProvider = provider || model ? trimmedString(raw.fallbackProvider, MAX_PROVIDER_ID_LENGTH) : null;
const fallbackModel = fallbackProvider ? trimmedString(raw.fallbackModel, MAX_MODEL_ID_LENGTH) : null;
if (!provider && !model && !effort) return null;
return Object.freeze({
diff --git a/server/lib/orchestrationProfile.test.js b/server/lib/orchestrationProfile.test.js
index feb610a8e5..7474c88f7c 100644
--- a/server/lib/orchestrationProfile.test.js
+++ b/server/lib/orchestrationProfile.test.js
@@ -83,3 +83,53 @@ describe('role vocabulary', () => {
expect([...ORCHESTRATION_ROLES]).toEqual(['architect', 'implementer', 'reviewer']);
});
});
+
+/**
+ * Same-role alternates (#5993). The alternate rides on the pin it substitutes
+ * for, so what the normalizer keeps has to match what the resolver treats as a
+ * fail-closed lane — otherwise a refusal names a field that was silently dropped.
+ */
+describe('same-role alternates', () => {
+ it('keeps a fallbackProvider + fallbackModel beside a provider pin', () => {
+ const profile = normalizeOrchestrationProfile({
+ implementer: { provider: 'p-cheap', model: 'm-cheap', fallbackProvider: 'p-cheap-2', fallbackModel: 'm-cheap-2' },
+ });
+ expect(profile.implementer).toEqual({
+ provider: 'p-cheap',
+ model: 'm-cheap',
+ fallbackProvider: 'p-cheap-2',
+ fallbackModel: 'm-cheap-2',
+ });
+ });
+
+ // A model-only role is fail-closed too — the generic chain would drop its model
+ // pin — so it must be able to carry the alternate the refusal points the user at.
+ it('keeps the alternate on a model-only role', () => {
+ const profile = normalizeOrchestrationProfile({
+ implementer: { model: 'm-cheap', fallbackProvider: 'p-cheap-2', fallbackModel: 'm-cheap-2' },
+ });
+ expect(profile.implementer).toEqual({
+ model: 'm-cheap',
+ fallbackProvider: 'p-cheap-2',
+ fallbackModel: 'm-cheap-2',
+ });
+ });
+
+ it('drops an alternate on a role that pins neither a provider nor a model', () => {
+ const profile = normalizeOrchestrationProfile({
+ implementer: { effort: 'high', fallbackProvider: 'p-cheap-2', fallbackModel: 'm-cheap-2' },
+ });
+ expect(profile.implementer).toEqual({ effort: 'high' });
+ });
+
+ it('drops a fallbackModel with no fallbackProvider to attach to', () => {
+ const profile = normalizeOrchestrationProfile({
+ implementer: { provider: 'p-cheap', fallbackModel: 'm-cheap-2' },
+ });
+ expect(profile.implementer).toEqual({ provider: 'p-cheap' });
+ });
+
+ it('does not make an alternate alone enough to persist a role', () => {
+ expect(normalizeOrchestrationProfile({ implementer: { fallbackProvider: 'p-cheap-2' } })).toBeNull();
+ });
+});
diff --git a/server/services/agentManagement.js b/server/services/agentManagement.js
index 0cc731c20f..280e1bc082 100644
--- a/server/services/agentManagement.js
+++ b/server/services/agentManagement.js
@@ -623,7 +623,7 @@ async function requeuePausedTask({ task, taskType, overrides }) {
// state owned by the spent task/run so the replacement gets a new retry budget,
// lease, workspace pointer, and output-hook dispatch.
const REPLACEMENT_RUNTIME_METADATA_KEYS = new Set([
- 'blockedReason', 'blockedCategory', 'blockedAt', 'blocker', 'failureCount',
+ 'blockedReason', 'blockedCategory', 'blockedAt', 'blocker', 'orchestrationLane', 'failureCount',
'lastErrorCategory', 'lastFailureAt', 'cooldownUntil', 'totalSpawnCount',
'orphanRetryCount', 'lastOrphanedAt', 'lastOrphanedAgentId', 'worktreeBusyAttempts',
LAST_SPAWNED_AT_KEY, 'interruptedByRestart', 'lastInterruptedAt', 'lastInterruptedAgentId',
diff --git a/server/services/agentProviderResolution.js b/server/services/agentProviderResolution.js
index 54c4e54882..109c9fa2c7 100644
--- a/server/services/agentProviderResolution.js
+++ b/server/services/agentProviderResolution.js
@@ -253,12 +253,32 @@ async function resolveOrdinaryProviderAndModel(task) {
if (lane) {
const alternateId = lane.fallbackProvider;
const alternate = alternateId ? await getProviderById(alternateId) : null;
- if (!alternate || !isProviderAvailable(alternate.id)) {
+ // An `api`-type alternate is rejected HERE rather than left to the harness
+ // guard below. That guard computes its `permanent` flag from the lane's own
+ // (CLI) primary, so an api alternate reaching it returns a TRANSIENT failure
+ // with no lane detail — the task never blocks, never records the refusal,
+ // and re-dispatches into the same dead end forever. Silent re-failure is the
+ // behavior this whole path exists to end, so it cannot be the way it ends.
+ //
+ // A lane that pinned a MODEL also needs the alternate to name one. Without
+ // `fallbackModel` the pin belongs to the primary, the swap invalidates it,
+ // and the run silently lands on the alternate's own default — the same
+ // substitution this closes, moved from the provider axis to the model axis.
+ const alternateUnusable = !alternate ? 'missing'
+ : alternate.type === 'api' ? 'no-harness'
+ : !isProviderAvailable(alternate.id) ? 'unavailable'
+ : lane.model && !lane.fallbackModel ? 'no-model'
+ : null;
+ if (alternateUnusable) {
const why = !alternateId
? `${status.message} (no ${laneRole}.fallbackProvider is configured)`
- : !alternate
+ : alternateUnusable === 'missing'
? `${status.message}, and its ${laneRole}.fallbackProvider "${alternateId}" is not a configured provider`
- : `${status.message}, and its ${laneRole}.fallbackProvider "${alternateId}" is also unavailable (${getProviderStatus(alternate.id).message})`;
+ : alternateUnusable === 'no-harness'
+ ? `${status.message}, and its ${laneRole}.fallbackProvider "${alternateId}" is an HTTP API provider with no file-writing harness`
+ : alternateUnusable === 'no-model'
+ ? `${status.message}, and its ${laneRole}.fallbackProvider "${alternateId}" was given no ${laneRole}.fallbackModel to run the pinned model "${lane.model}" on`
+ : `${status.message}, and its ${laneRole}.fallbackProvider "${alternateId}" is also unavailable (${getProviderStatus(alternate.id).message})`;
return laneUnavailable({
role: laneRole,
requestedProvider: provider.id,
diff --git a/server/services/agentProviderResolution.test.js b/server/services/agentProviderResolution.test.js
index 00360da91e..7b0b1e9ba2 100644
--- a/server/services/agentProviderResolution.test.js
+++ b/server/services/agentProviderResolution.test.js
@@ -695,3 +695,89 @@ describe('resolveAgentProviderAndModel — effort-only orchestration roles', ()
});
});
});
+
+/**
+ * The same-role alternate is the ONE substitution a fail-closed lane accepts, so
+ * it has to clear every bar the primary would have: a real provider, currently
+ * available, with a file-writing harness, and — when the lane pinned a model — a
+ * model of its own to run. An alternate that fails any of these is not a lane,
+ * it is the same silent collapse one hop later.
+ */
+describe('resolveAgentProviderAndModel — what a same-role alternate must satisfy', () => {
+ const orchestrated = (architect) => ({
+ id: 'task-alt',
+ metadata: { orchestrationMode: 'orchestrated', orchestrationProfile: { architect } },
+ });
+
+ beforeEach(() => {
+ getProviderStatus.mockImplementation((id) => ({ message: `${id} down`, reason: 'down' }));
+ });
+
+ it('refuses an api-type alternate instead of leaking into the transient harness guard', async () => {
+ // The harness guard below computes `permanent` from the lane's CLI primary,
+ // so an api alternate reaching it returns a retryable failure with no lane
+ // detail — the task would never block and would re-fail forever.
+ getProviderById.mockImplementation(async (id) => (
+ id === 'p-cheap'
+ ? { id, type: 'cli', defaultModel: 'm-cheap' }
+ : { id, type: 'api', defaultModel: 'm-api' }
+ ));
+ isProviderAvailable.mockImplementation((id) => id !== 'p-cheap');
+
+ const r = await resolveAgentProviderAndModel(orchestrated({ provider: 'p-cheap', fallbackProvider: 'p-api' }));
+
+ expect(r.ok).toBe(false);
+ expect(r.permanent).toBe(true);
+ expect(r.orchestrationLane.role).toBe('architect');
+ expect(r.orchestrationLane.reason).toContain('no file-writing harness');
+ });
+
+ it('refuses when a model-pinned lane names an alternate with no fallbackModel', async () => {
+ getProviderById.mockImplementation(async (id) => ({ id, type: 'cli', defaultModel: `m-${id}` }));
+ isProviderAvailable.mockImplementation((id) => id !== 'p-cheap');
+
+ const r = await resolveAgentProviderAndModel(orchestrated({
+ provider: 'p-cheap',
+ model: 'm-cheap',
+ fallbackProvider: 'p-cheap-2',
+ }));
+
+ expect(r.ok).toBe(false);
+ expect(r.orchestrationLane.reason).toContain('no architect.fallbackModel');
+ expect(r.orchestrationLane.requestedModel).toBe('m-cheap');
+ });
+
+ it('lets a provider-only lane take an alternate that supplies its own default', async () => {
+ const alternate = { id: 'p-cheap-2', type: 'cli', models: ['alt-default'], defaultModel: 'alt-default' };
+ getProviderById.mockImplementation(async (id) => (
+ id === 'p-cheap' ? { id, type: 'cli', defaultModel: 'm-cheap' } : alternate
+ ));
+ isProviderAvailable.mockImplementation((id) => id === 'p-cheap-2');
+ selectModelForTask.mockResolvedValue({ model: 'alt-default', tier: 'medium', reason: 'default' });
+
+ const r = await resolveAgentProviderAndModel(orchestrated({ provider: 'p-cheap', fallbackProvider: 'p-cheap-2' }));
+
+ expect(r.ok).toBe(true);
+ expect(r.provider).toBe(alternate);
+ expect(r.orchestrationLane.substitution.to).toBe('p-cheap-2');
+ });
+
+ it('carries a model-pinned lane onto its alternate using the configured fallbackModel', async () => {
+ const alternate = { id: 'p-cheap-2', type: 'cli', models: ['alt-m'], defaultModel: 'alt-default' };
+ getProviderById.mockImplementation(async (id) => (
+ id === 'p-cheap' ? { id, type: 'cli', defaultModel: 'm-cheap' } : alternate
+ ));
+ isProviderAvailable.mockImplementation((id) => id === 'p-cheap-2');
+
+ const r = await resolveAgentProviderAndModel(orchestrated({
+ provider: 'p-cheap',
+ model: 'm-cheap',
+ fallbackProvider: 'p-cheap-2',
+ fallbackModel: 'alt-m',
+ }));
+
+ expect(r.ok).toBe(true);
+ // Never the alternate's own default — that is the substitution this closes.
+ expect(r.selectedModel).toBe('alt-m');
+ });
+});
diff --git a/server/services/cosTaskStore.js b/server/services/cosTaskStore.js
index 666492d61b..6c9ee68a2a 100644
--- a/server/services/cosTaskStore.js
+++ b/server/services/cosTaskStore.js
@@ -751,7 +751,7 @@ async function writeTaskUpdate(taskId, updates, taskType, { now, suppressDequeue
// agent record then read its own pause as spent and spawned a SECOND agent on a
// fresh task. The clear belongs at the transition, not at one caller.
if (updates.status && updates.status !== 'blocked' && tasks[taskIndex].status === 'blocked') {
- for (const key of ['blocker', 'blockedReason', 'blockedCategory', 'blockedAt', 'failureCount', 'lastErrorCategory', 'lastFailureAt', ...PAUSE_METADATA_KEYS]) {
+ for (const key of ['blocker', 'blockedReason', 'blockedCategory', 'blockedAt', 'orchestrationLane', 'failureCount', 'lastErrorCategory', 'lastFailureAt', ...PAUSE_METADATA_KEYS]) {
delete updatedMetadata[key];
}
}
diff --git a/server/services/cosTaskStore.test.js b/server/services/cosTaskStore.test.js
index 10b7e9324a..748a33cbf7 100644
--- a/server/services/cosTaskStore.test.js
+++ b/server/services/cosTaskStore.test.js
@@ -987,6 +987,23 @@ describe('cosTaskStore.updateTask', () => {
expect(reopened.metadata.blockedCategory).toBeUndefined();
});
+ // The structured detail of a refused orchestration lane (#5993) goes with it.
+ // The task record federates, so a stale lane naming a provider the task is no
+ // longer blocked on would travel to every peer alongside a running task.
+ it('clears the orchestration lane detail when the block ends', async () => {
+ await addTask({ description: 'lane', id: 'task-lane' }, 'user');
+ await updateTask('task-lane', {
+ status: 'blocked',
+ metadata: {
+ blockedReason: 'Orchestrated architect lane stopped',
+ blockedCategory: 'orchestration-lane-unavailable',
+ orchestrationLane: { role: 'architect', requestedProvider: 'p-cheap', requestedModel: null, reason: 'not authenticated' },
+ },
+ }, 'user');
+ const reopened = await updateTask('task-lane', { status: 'pending' }, 'user');
+ expect(reopened.metadata.orchestrationLane).toBeUndefined();
+ });
+
// The pause hold goes with it, whatever un-blocked the task. `resumeAgent` is only
// ONE of the paths back to pending — a dedupe revive, an autopilot re-dispatch, a
// cooldown expiry and a human unblocking it all land here — and every one of them
diff --git a/server/services/promptSections/orchestrationDoctrine.js b/server/services/promptSections/orchestrationDoctrine.js
index 737f7a4e67..1424832a85 100644
--- a/server/services/promptSections/orchestrationDoctrine.js
+++ b/server/services/promptSections/orchestrationDoctrine.js
@@ -34,9 +34,14 @@ function roleLine(task, role) {
// The lane's ONE permitted substitution (#5993). Named here because the
// architect otherwise has no way to know a lane is fail-closed, and would plan
// around a fallback that does not exist.
- const alternate = assignment?.fallbackProvider
+ // Gated on a provider/model pin — the SAME condition the resolver uses. An
+ // effort-only role stays on the ordinary fallback chain, so telling the
+ // architect its run would stop would be false (and reads as nonsense besides:
+ // the "target" there is a reasoning rung, not a provider).
+ const failClosed = Boolean(assignment?.provider || assignment?.model);
+ const alternate = failClosed && assignment.fallbackProvider
? ` If it is unavailable, the lane may use \`${assignment.fallbackProvider}\`${assignment.fallbackModel ? ` with model \`${assignment.fallbackModel}\`` : ''} — and nothing else.`
- : (pins.length ? ' If it is unavailable, the run STOPS — no other provider is substituted for this lane.' : '');
+ : (failClosed ? ' If it is unavailable, the run STOPS — no other provider is substituted for this lane.' : '');
return `- **${role}** — ${ROLE_DUTIES[role]}. Runs on ${target}.${alternate}`;
}
diff --git a/server/services/promptSections/orchestrationDoctrine.test.js b/server/services/promptSections/orchestrationDoctrine.test.js
index 1c2b892450..793d48eb16 100644
--- a/server/services/promptSections/orchestrationDoctrine.test.js
+++ b/server/services/promptSections/orchestrationDoctrine.test.js
@@ -71,3 +71,29 @@ describe('fail-closed lane doctrine (#5993)', () => {
expect(section.split('\n').find(l => l.startsWith('- **reviewer**'))).not.toContain('STOPS');
});
});
+
+describe('the doctrine states fail-closed only for the lanes that are', () => {
+ const orchestrated = (profile) => ({
+ metadata: { orchestrationMode: 'orchestrated', orchestrationProfile: profile },
+ });
+ const roleLineFor = (section, role) => section.split('\n').find(l => l.startsWith(`- **${role}**`));
+
+ it('says nothing about substitution for an effort-only role', () => {
+ // That role stays on the ordinary fallback chain, so promising the architect
+ // the run would stop is false — and reads as nonsense, since its only "pin"
+ // is a reasoning rung rather than a provider.
+ const section = buildOrchestrationDoctrineSection(orchestrated({
+ implementer: { effort: 'high' },
+ architect: { provider: 'p1' },
+ }));
+ expect(roleLineFor(section, 'implementer')).not.toContain('STOPS');
+ expect(roleLineFor(section, 'architect')).toContain('STOPS');
+ });
+
+ it('names the alternate a model-only lane may use', () => {
+ const section = buildOrchestrationDoctrineSection(orchestrated({
+ implementer: { model: 'm-cheap', fallbackProvider: 'p-cheap-2', fallbackModel: 'm-cheap-2' },
+ }));
+ expect(roleLineFor(section, 'implementer')).toContain('the lane may use `p-cheap-2` with model `m-cheap-2` — and nothing else');
+ });
+});