A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Keep the rejection's RemoteError identity and clean its reason
Fei2411f90151abe389
diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.jsindex 59a34207..fdb726b2 100644--- a/ds-bot/src/host/turns.js+++ b/ds-bot/src/host/turns.js@@ -3,6 +3,7 @@//// Turn tracking: which turns were triggered by another Bot, and what they said.import { HANDOFF_ACK, MESSAGE_INLINE_MAX, REFERENCE_KIND, REPLY_KIND, SOURCE_KIND, STEER_CUT } from './constants.js'+import { cleanText } from './diagnostics.js'import { absoluteLinks } from './links.js'import { textOf } from './text.js'import { reminderText } from './schedules.js'@@ -901,7 +902,11 @@ export function install(rt) {} catch (error) {const id = request?.sessionIdif (id === undefined || (rt.roomOf(id) === undefined && !rt.isBotSession(id))) throw error- const reason = typeof error?.details?.reason === 'string' && error.details.reason !== '' ? error.details.reason : undefined+ // The reason can name local paths or carry tokens, so the same cleaning the+ // diagnostics get applies before it reaches the client.+ const reason = typeof error?.details?.reason === 'string' && error.details.reason !== ''+ ? cleanText(error.details.reason, { redact: rt.redactSecrets })+ : undefinedrt.noteFailure({source: 'prompt',text: `prompt rejected for ${placeOf(id)}${reason === undefined ? '' : `: ${reason}`}`,@@ -909,11 +914,12 @@ export function install(rt) {where: placeOf(id),sessionId: id,})+ // The gateway passes a RemoteError's code and details on as they are, but+ // wraps a fresh plain Error as 'gateway/internal': the reason is written on+ // the rejection itself, keeping its identity.if (reason !== undefined) {- const enriched = new Error(`${error?.message ?? 'prompt rejected'} — ${reason}`)- enriched.code = error.code- enriched.details = error.details- throw enriched+ error.message = `${error?.message ?? 'prompt rejected'} — ${reason}`+ error.details = { ...error.details, reason }}throw error}diff --git a/ds-bot/test/work-dir.test.js b/ds-bot/test/work-dir.test.jsindex 75ed8d35..dac7c8c6 100644--- a/ds-bot/test/work-dir.test.js+++ b/ds-bot/test/work-dir.test.js@@ -610,17 +610,45 @@ test('the user moves the team workspace, and Bots without a folder of their own// #424: DSH's prompt admission wraps any unexpected failure as 'session/agent-busy'// with the cause in details.reason. For a Session this team owns the reason reaches-// the user and the diagnostics log.+// the user and the diagnostics log — on the same error, so the gateway still sees a+// RemoteError and passes its code and details on instead of 'gateway/internal'.test('a prompt rejected with a hidden reason shows the reason and logs it', async (t) => {const { ctx, call, stop } = await start()t.after(stop)- ctx.__promptError = Object.assign(new Error('prompt rejected'), { code: 'session/agent-busy', details: { reason: 'Error: Could not load the "sharp" module' } })- const denied = await ctx.sessionController.prompt({ sessionId: 'r1', content: [] }).then(() => 'ok', error => `${error.message} (${error.code})`)- assert.match(denied, /prompt rejected — Error: Could not load the "sharp" module \(session\/agent-busy\)/)+ ctx.__promptError = Object.assign(new Error('prompt rejected'), {+ code: 'session/agent-busy',+ isDSHRemoteError: true,+ details: { reason: 'Error: Could not load the "sharp" module', rest: 1 },+ })+ const failure = await ctx.sessionController.prompt({ sessionId: 'r1', content: [] }).then(() => undefined, error => error)+ assert.equal(failure, ctx.__promptError)+ assert.match(failure.message, /prompt rejected — Error: Could not load the "sharp" module/)+ assert.equal(failure.code, 'session/agent-busy')+ assert.deepEqual(failure.details, { reason: 'Error: Could not load the "sharp" module', rest: 1 })const log = (await call('diagnostics-log', {})).valueassert.match(log, /sharp/)})+// #424: the hidden reason can name a local path or carry a token; what reaches the+// user is cleaned like the diagnostics, not the raw reason.+test('a rejected prompt reason reaches the user cleaned of paths and tokens', async (t) => {+ const { ctx, call, stop } = await start()+ t.after(stop)+ ctx.__promptError = Object.assign(new Error('prompt rejected'), {+ code: 'session/attachment-invalid',+ isDSHRemoteError: true,+ details: { reason: `Cannot read ${join(homedir(), 'key.pem')} or https://hook.example/in?token=t0ken123` },+ })+ const failure = await ctx.sessionController.prompt({ sessionId: 'r1', content: [] }).then(() => undefined, error => error)+ assert.equal(failure.code, 'session/attachment-invalid')+ assert.ok(!failure.message.includes('t0ken123'), failure.message)+ assert.ok(!failure.message.includes(homedir()), failure.message)+ assert.match(failure.message, /token=\[hidden\]/)+ assert.equal(failure.details.reason, `Cannot read ~${join(homedir(), 'key.pem').slice(homedir().length)} or https://hook.example/in?token=[hidden]`)+ const log = (await call('diagnostics-log', {})).value+ assert.ok(!log.includes('t0ken123'), log)+})+test('the team workspace holds no DeepSeek Harness data, apart from the plugin\'s own default', async (t) => {const { root, dsh, home, team, state, call, stop } = await start()t.after(stop)