Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Stop choosing routes that are not model endpoints

Fei2411e176a1672f2f
diff --git a/ds-bot/src/host/models.js b/ds-bot/src/host/models.js
index ac06f9f3..10a79502 100644
--- a/ds-bot/src/host/models.js
+++ b/ds-bot/src/host/models.js
@@ -11,6 +11,11 @@ export function install(rt) {
let modelsSynced = null
let catalogCache = { at: 0, value: [] }
+ // Routes DSH serves that cannot answer a request at all — a hosted loop engine
+ // publishes one so its Sessions can be prompted. Once one refuses with
+ // HOSTED_ENGINE_ROUTE it is remembered, and nothing chooses it again this run.
+ const refused = new Set()
+ const answerable = entries => (refused.size === 0 ? entries : entries.filter(entry => !refused.has(entry.ref)))
// A model's thinking levels, resolved once and kept for a short while: they change
// only with the provider, which also drops the catalog cache.
const reasoningCache = new Map()
@@ -36,7 +41,7 @@ export function install(rt) {
// that is about to be used asks for a `fresh` one. Entries for models a Bot uses
// also carry their `reasoning`, so the picker can offer thinking levels.
async function catalog({ fresh = false } = {}) {
- if (!fresh && Date.now() - catalogCache.at < CATALOG_TTL_MS && catalogCache.value.length > 0) return catalogCache.value
+ if (!fresh && Date.now() - catalogCache.at < CATALOG_TTL_MS && catalogCache.value.length > 0) return answerable(catalogCache.value)
const entries = []
for (const provider of ctx.llm.listProviders()) {
let models = []
@@ -62,18 +67,21 @@ export function install(rt) {
if (reasoning !== undefined) entry.reasoning = reasoning
}))
catalogCache = { at: Date.now(), value: entries }
- return entries
+ return answerable(entries)
}
- // The profile default model of DSH as set, served or not.
+ // The profile default model of DSH as set, served or not, and able to answer.
const defaultRef = () => {
const selection = ctx.get?.('agentDefaultModel')?.currentSelection?.()
- return selection?.provider && selection?.model ? `${selection.provider}/${selection.model}` : undefined
+ if (!selection?.provider || !selection?.model) return undefined
+ const ref = `${selection.provider}/${selection.model}`
+ return refused.has(ref) ? undefined : ref
}
// The profile default model of DSH, when it is served; else the first served model.
function pickDefault(entries) {
const ref = defaultRef()
- return entries.find(entry => entry.ref === ref)?.ref ?? entries[0]?.ref
+ const list = answerable(entries)
+ return list.find(entry => entry.ref === ref)?.ref ?? list[0]?.ref
}
const defaultModel = async () => pickDefault(await catalog())
@@ -208,10 +216,28 @@ export function install(rt) {
}
}
+ // A route that refused a request for not being a model endpoint: it stays out of
+ // the catalog from now on, the Bots pinned to it move to what they would be given
+ // today, and the Bot whose turn failed re-selects — its group Session may carry
+ // another Bot's route, so `force` re-selects even when its record looks applied.
+ async function routeRefused(ref, bot) {
+ if (!refused.has(ref)) {
+ refused.add(ref)
+ rt.warn('ds-bot: %s is not a model endpoint, so it is not chosen again', ref)
+ const entries = await catalog()
+ for (const other of Object.values(state.bots)) {
+ if (other.model === ref) other.model = pickDefault(entries)
+ if (other.appliedModel === ref) delete other.appliedModel
+ }
+ await rt.save()
+ }
+ if (bot !== undefined) await applyModel(bot, { force: true })
+ }
+
Object.assign(rt, {
- catalog, cachedCatalog: () => catalogCache.value, cachedDefault: () => pickDefault(catalogCache.value),
+ catalog, cachedCatalog: () => answerable(catalogCache.value), cachedDefault: () => pickDefault(catalogCache.value),
defaultRef, defaultModel, defaultEffort, resolveModel, desiredModel, reasoningOf, resolveEffort, desiredEffort,
- selectSessionModel, applyModel, waitForModel, syncModels,
+ selectSessionModel, applyModel, waitForModel, syncModels, routeRefused,
dropCatalog: () => { catalogCache = { at: 0, value: [] } },
})
}
diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.js
index fbde4ebe..e9c8971d 100644
--- a/ds-bot/src/host/turns.js
+++ b/ds-bot/src/host/turns.js
@@ -616,6 +616,13 @@ export function install(rt) {
const reason = event.data?.reason
const failure = reason?.kind === 'error' && !switched ? turnFailure(reason.error) : undefined
if (failure !== undefined) noteTurnFailure(id, failure)
+ // A route that is not a model endpoint refuses every generation; the failed
+ // Session's own request names it, so it is refused everywhere from now on.
+ if (failure?.code === 'HOSTED_ENGINE_ROUTE') {
+ const config = session.requestHeader?.()?.config
+ const ref = config?.provider && config?.model ? `${config.provider}/${config.model}` : undefined
+ if (ref !== undefined) void rt.routeRefused(ref, rt.botOf(rt.selfOf(id))).catch(error => rt.warn('ds-bot: %s still failing: %s', ref, error))
+ }
const held = rt.groupOwners.has(id) ? rt.takeRoomSteps?.(id) ?? '' : ''
if (switched) break
// A model that writes its tool call as text ends the turn as if it were done,
diff --git a/ds-bot/test/diagnostics.test.js b/ds-bot/test/diagnostics.test.js
index 2ada6d01..00d906aa 100644
--- a/ds-bot/test/diagnostics.test.js
+++ b/ds-bot/test/diagnostics.test.js
@@ -228,7 +228,7 @@ function turnsHost() {
}
installTurns(rt)
let seq = 0
- const emit = (id, type, data) => listener({ id }, { type, seq: ++seq, data })
+ const emit = (id, type, data, session) => listener(session ?? { id }, { type, seq: ++seq, data })
return { rt, emit, delivered, noted }
}
@@ -263,6 +263,22 @@ test('a failed group turn fails its waiter; a stopped one counts as no answer',
assert.equal(value, null)
})
+// #637: the route a refused turn ran on is read from the Session's request header,
+// not from the Bot's record — a group Session may carry another Bot's route.
+test('a turn refused for not being a model endpoint refuses that route', () => {
+ const { rt, emit } = turnsHost()
+ const calls = []
+ rt.routeRefused = async (ref, bot) => { calls.push([ref, bot?.id]) }
+ const session = { id: 'b', requestHeader: () => ({ config: { provider: 'external', model: 'default' } }) }
+ emit('b', 'turn/start', { turn: 1 }, session)
+ emit('b', 'turn/end', { turn: 1, reason: { kind: 'error', error: { code: 'HOSTED_ENGINE_ROUTE', message: 'provider "external" is a hosted loop engine route, not a model endpoint' } } }, session)
+ assert.deepEqual(calls, [['external/default', 'b']])
+ // An ordinary failure takes no such path.
+ emit('b', 'turn/start', { turn: 2 }, session)
+ emit('b', 'turn/end', { turn: 2, reason: failed }, session)
+ assert.equal(calls.length, 1)
+})
+
test('issueUrl fills the issue form, keeps the versions when the errors are too long, and falls back to the clipboard', async () => {
const { issueUrl } = await import('../src/client/diagnostics.js')
const base = 'https://github.com/Fei2411/DS-Bot/issues/new'
diff --git a/ds-bot/test/models.test.js b/ds-bot/test/models.test.js
index 248b3b6f..c27b2237 100644
--- a/ds-bot/test/models.test.js
+++ b/ds-bot/test/models.test.js
@@ -164,6 +164,36 @@ test('the catalog attaches thinking levels to models a Bot uses', async () => {
assert.equal(entries.find(entry => entry.ref === 'stepfun/step-5')?.reasoning, undefined)
})
+// #637: a hosted loop engine publishes a route that resolves models but refuses every
+// generation with HOSTED_ENGINE_ROUTE; once it refuses, nothing chooses it again.
+test('a route refused for not being a model endpoint is chosen nowhere again', async () => {
+ const { rt, selected } = bench({ providers: { external: ['default'], deepseek: ['v4-flash'] }, fallback: { provider: 'external', model: 'default' } })
+ const pinned = { id: 'b1', model: 'external/default', appliedModel: 'external/default' }
+ const clean = { id: 'b2', model: 'deepseek/v4-flash' }
+ rt.state.bots = { b1: pinned, b2: clean }
+ await rt.routeRefused('external/default', pinned)
+ // The pinned Bot moves to what it would be given today and re-selects its Session.
+ assert.equal(pinned.model, 'deepseek/v4-flash')
+ assert.equal(pinned.appliedModel, 'deepseek/v4-flash')
+ assert.equal(clean.model, 'deepseek/v4-flash')
+ assert.deepEqual(selected, ['b1:deepseek/v4-flash'])
+ // Pickers, the deployment default and explicit naming keep it out too.
+ assert.deepEqual((await rt.catalog({ fresh: true })).map(entry => entry.ref), ['deepseek/v4-flash'])
+ assert.deepEqual(rt.cachedCatalog().map(entry => entry.ref), ['deepseek/v4-flash'])
+ assert.equal(await rt.defaultModel(), 'deepseek/v4-flash')
+ await assert.rejects(rt.resolveModel('external/default'), /Model external\/default is not available/)
+})
+
+test('a Bot on a clean record but a poisoned Session re-selects its own model', async () => {
+ const { rt, selected } = bench({ providers: { external: ['default'], deepseek: ['v4-flash'] }, fallback: { provider: 'external', model: 'default' } })
+ // Its group Session ran on another Bot's route; its own record never named it.
+ const bot = { id: 'b1', model: 'deepseek/v4-flash', appliedModel: 'deepseek/v4-flash' }
+ rt.state.bots = { b1: bot }
+ await rt.routeRefused('external/default', bot)
+ assert.equal(bot.model, 'deepseek/v4-flash')
+ assert.deepEqual(selected, ['b1:deepseek/v4-flash'])
+})
+
test('a greeting waits for the provider of its Bot model to register', async () => {
const { rt, providers, listeners } = bench({ providers: {} })
const waiting = rt.waitForModel({ model: 'stepfun/step-5' }, 5000)