Skip to content

Where agent teams gather. Cross-platform team chat where AI agents are first-class teammates — with cloud or bring-your-own (Claude Code / Codex) brains.

TypeScript

fix(byoa): --doctor said healthy on machines the daemon refuses to start on

zhuangxialie6cfc4594d6c7
diff --git a/server/src/__tests__/agents-computer-doctor-verdict.test.ts b/server/src/__tests__/agents-computer-doctor-verdict.test.ts
new file mode 100644
index 0000000..6a5176a
--- /dev/null
+++ b/server/src/__tests__/agents-computer-doctor-verdict.test.ts
@@ -0,0 +1,73 @@
+/**
+ * `--doctor`'s verdict has to mean "the daemon will start here".
+ *
+ * The doctor probes every adapter on PATH and scored itself on brain health
+ * alone: `if (r.big?.ok && r.small?.ok) anyUsable = true`. But
+ * `requireLocalEngine` also refuses to start the daemon when no installed
+ * engine can enforce the BYOA boundary — an unsandboxed engine without
+ * CUMORA_BYOA_ALLOW_UNSANDBOXED, or a secure one below its version floor.
+ *
+ * On a machine in that state the two disagreed completely. Measured on the
+ * machine this was found on, minutes apart:
+ *
+ * --doctor → exit 0, "✓ at least one engine is fully healthy"
+ * evaluateRunnableEngines → runnable: [], blocked: [
+ * claude — version 2.1.207 is older than the secure minimum 2.1.248,
+ * codex — version 0.134.0 is older than the secure minimum 0.138.0 ]
+ *
+ * The only engine scoring green was one secure BYOA refuses categorically, and
+ * the version floor actually blocking the machine was never mentioned. That is
+ * the worst possible answer for someone who ran the diagnostic precisely
+ * because something was already wrong.
+ */
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { readFile } from 'node:fs/promises'
+import { doctorUsableEngines } from '../agents/computer/daemon.js'
+
+const healthy = (id: string) => ({ id: id as never, installed: true, big: { ok: true }, small: { ok: true } })
+const halfDead = (id: string) => ({ id: id as never, installed: true, big: { ok: true }, small: { ok: false } })
+const absent = (id: string) => ({ id: id as never, installed: false })
+
+test('an engine the gate blocks does not count, however healthy its brains', () => {
+ // The exact shape of the machine this was found on: both secure engines
+ // below the floor, one unsandboxed engine working perfectly.
+ const results = [healthy('claude'), healthy('codex'), healthy('grok')]
+ assert.deepEqual(
+ doctorUsableEngines(results, { runnable: [] }), [],
+ 'the doctor would report green on a machine where the daemon exits 70',
+ )
+})
+
+test('a runnable engine with healthy brains counts', () => {
+ const results = [healthy('claude'), healthy('grok')]
+ assert.deepEqual(doctorUsableEngines(results, { runnable: ['claude'] }), ['claude'])
+})
+
+test('runnable is not enough on its own — the brains still have to answer', () => {
+ // The guard rail in the other direction: this must not become "the gate says
+ // yes, so we are fine".
+ assert.deepEqual(doctorUsableEngines([halfDead('claude')], { runnable: ['claude'] }), [])
+ assert.deepEqual(doctorUsableEngines([absent('claude')], { runnable: ['claude'] }), [])
+})
+
+test('an unevaluable gate degrades to the brain-only answer, not to zero', () => {
+ // A PATH scan can fail. A diagnostic that reports "nothing works" because it
+ // could not run its own check is worse than the answer it used to give.
+ assert.deepEqual(doctorUsableEngines([healthy('claude')], null), ['claude'])
+})
+
+test('the verdict is drawn from the gate-aware helper, not from brains alone', async () => {
+ // The four tests above exercise the helper. They would all still pass against
+ // a runDoctor that computed its own verdict and never called it — which is
+ // exactly the state being fixed. Read the source.
+ const source = await readFile(new URL('../agents/computer/daemon.ts', import.meta.url), 'utf8')
+ const doctor = source.slice(source.indexOf('async function runDoctor'))
+ const body = doctor.slice(0, doctor.indexOf('\n}\n') + 2)
+
+ assert.match(body, /doctorUsableEngines\(/, 'runDoctor no longer asks the gate')
+ assert.doesNotMatch(
+ body, /if \(r\.big\?\.ok && r\.small\?\.ok\) anyUsable = true/,
+ 'the brain-only verdict is back — the doctor will report green on machines where --pair exits 70',
+ )
+})
diff --git a/server/src/agents/computer/daemon.ts b/server/src/agents/computer/daemon.ts
index dc14cbc..cbabafc 100644
--- a/server/src/agents/computer/daemon.ts
+++ b/server/src/agents/computer/daemon.ts
@@ -4329,11 +4329,47 @@ async function tailLogs(): Promise<void> {
// ─── doctor ─────────────────────────────────────────────────────────────
+/** Which engines could actually carry a wake right now.
+ *
+ * Brain health is necessary but not sufficient. `requireLocalEngine` also
+ * refuses to start the daemon when no installed engine can enforce the BYOA
+ * boundary — an unsandboxed engine without the opt-in, or a secure one below
+ * its version floor. Scoring the doctor on brain health alone printed a green
+ * verdict and exit 0 on machines where `--pair` exits 70.
+ *
+ * `runnable` is null when the gate could not be evaluated at all (PATH scan
+ * failed). The diagnostic must not become a crash, so that degrades to the
+ * older brain-only answer rather than declaring everything unusable. */
+export function doctorUsableEngines(
+ results: ReadonlyArray<{
+ id: EngineId
+ installed: boolean
+ big?: { ok: boolean } | null
+ small?: { ok: boolean } | null
+ }>,
+ runnable: { runnable: readonly EngineId[] } | null,
+): EngineId[] {
+ return results
+ .filter((r) => r.installed && r.big?.ok === true && r.small?.ok === true)
+ .map((r) => r.id)
+ .filter((id) => runnable === null || runnable.runnable.includes(id))
+}
+
/** `cumora agent computer --doctor`: diagnose every local engine on this
* machine — is it installed, and are its BIG brain (main reasoning) and SMALL
* brain (the triage cerebellum) reachable + authed? Each tier gets a trivial
- * one-shot probe over the SAME spawn path real wakes use, so green here means
- * real wakes will work. Pure local: no cloud, no DB, no pairing required. */
+ * one-shot probe over the SAME spawn path real wakes use. Pure local: no
+ * cloud, no DB, no pairing required.
+ *
+ * Brain health is necessary but NOT sufficient, and the verdict used to be
+ * drawn from it alone. `requireLocalEngine` also refuses to start the daemon
+ * when no installed engine can enforce the BYOA boundary — an unsandboxed
+ * engine without the opt-in, or a secure one below its version floor. On a
+ * machine in that state the doctor printed a green verdict and exit 0 while
+ * `--pair` exited 70, which is the worst possible advice for the person who
+ * ran the diagnostic precisely because something was already wrong. So the
+ * verdict now asks the same gate the daemon does, and an engine only counts
+ * when it is both healthy AND runnable. */
async function runDoctor(providerId?: string): Promise<void> {
const provider = providerId !== undefined
? readProviderProfiles(join(CONFIG_DIR, 'providers.json')).find((p) => p.id === providerId) : undefined
@@ -4353,11 +4389,28 @@ async function runDoctor(providerId?: string): Promise<void> {
}
console.log('')
+ // Ask the same gate the daemon does. A healthy brain on an engine this
+ // machine is not allowed to run is not a machine that can run an agent.
+ const runnable = await (async () => {
+ try {
+ const detected = await detectEnginesWithStatus()
+ if (!detected.reliable || detected.engines.length === 0) return null
+ return await evaluateRunnableEngines(detected.engines)
+ } catch {
+ // The gate is advisory HERE — never let it turn a diagnostic into a
+ // crash. Falling back to null keeps the old brain-only verdict.
+ return null
+ }
+ })()
+
let anyUsable = false
for (const r of results) {
if (!r.installed) {
console.log(`✖ ${r.id} — not found on PATH`)
- console.log(` install the \`${r.id}\` CLI and run it once to sign in, then re-run --doctor\n`)
+ // The binary is not always the engine id — cursor ships `cursor-agent`,
+ // antigravity ships `agy`. missingEngineMessage() in this file gets that
+ // right; this line used to contradict it.
+ console.log(` install the \`${getAdapter(r.id)?.bin ?? r.id}\` CLI and run it once to sign in, then re-run --doctor\n`)
continue
}
console.log(`● ${r.id} — ${r.path}`)
@@ -4383,17 +4436,31 @@ async function runDoctor(providerId?: string): Promise<void> {
console.log(` → persistent-session path unavailable; agents will fall back to one-shot exec`)
}
}
- if (r.big?.ok && r.small?.ok) anyUsable = true
+ const blockedReason = runnable?.blocked.find((b) => b.id === r.id)?.reason
+ if (blockedReason) {
+ console.log(` ✖ not runnable ${blockedReason}`)
+ console.log(' → healthy brains, but the daemon will refuse to start on this engine')
+ }
console.log('')
}
+ anyUsable = doctorUsableEngines(results, runnable).length > 0
if (!anyUsable) {
- console.log('✖ no engine has BOTH brains healthy — this machine cannot currently run a BYOA agent.')
+ console.log('✖ no engine is both healthy and runnable — this machine cannot currently run a BYOA agent.')
+ if (runnable && runnable.runnable.length === 0) {
+ // Print exactly what `--pair` would print, so the two never disagree.
+ const why = runnable.blocked.length > 0
+ ? incapableEngineMessage(runnable.blocked)
+ : sandboxedEngineMessage(ENGINE_IDS.filter((id) => results.some((r) => r.id === id && r.installed)))
+ console.log('')
+ for (const line of why.split('\n')) console.log(` ${line}`)
+ console.log('')
+ }
console.log(' fix the failures above (usually: open the engine\'s app and sign in / refresh quota), then re-run:')
console.log(' cumora agent computer --doctor')
process.exitCode = 1
} else {
- console.log('✓ at least one engine is fully healthy — BYOA agents on this machine can wake their brains.')
+ console.log('✓ at least one engine is healthy and runnable — BYOA agents on this machine can wake their brains.')
}
}