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): report the refusal at pairing and reconnect, not only on rescan

Xialie Zhuangaf2c58cc2588
diff --git a/server/src/__tests__/agents-computer-blocked-engines.test.ts b/server/src/__tests__/agents-computer-blocked-engines.test.ts
index dcbe7dc..f012ea0 100644
--- a/server/src/__tests__/agents-computer-blocked-engines.test.ts
+++ b/server/src/__tests__/agents-computer-blocked-engines.test.ts
@@ -130,3 +130,36 @@ test('a blocked engine the daemon reported nothing about still gets a row', () =
const out = sanitizeDetectedEngines(null, ['codex'], ['claude'])
assert.deepEqual(out.map((e) => e.id), ['codex', 'claude'])
})
+
+// --- every path that stores a snapshot, not just the rescan ---
+
+test('the reason travels on the pairing snapshot, not only the rescan', () => {
+ // The first version of this feature wired only the periodic PATH rescan, so a
+ // freshly paired computer showed nothing for minutes — exactly the window in
+ // which someone asks why their Claude Code is missing. pairComputer() and the
+ // reconnect branch sanitize their own snapshots, so they need the same list.
+ const out = sanitizeDetectedEngines(
+ [
+ { id: 'codex', bin: 'codex', path: '/bin/codex' },
+ { id: 'claude', bin: 'claude', path: '/bin/claude', blockedReason: OLD_CLAUDE },
+ ],
+ ['codex'],
+ ['claude'],
+ )
+ assert.equal(out.find((e) => e.id === 'claude')?.blockedReason, OLD_CLAUDE)
+})
+
+test('a blocked engine never reaches the runnable list it is derived from', () => {
+ // The invariant stated as the caller sees it: whatever this returns for
+ // display, `available_engines` is built from the runnable ids alone, so a
+ // blocked engine cannot become the adapter an agent runs on.
+ const runnable = ['codex']
+ const out = sanitizeDetectedEngines(
+ [{ id: 'claude', bin: 'claude', path: '/bin/claude', blockedReason: OLD_CLAUDE }],
+ runnable,
+ ['claude'],
+ )
+ assert.deepEqual(runnable, ['codex'], 'the runnable list must not be mutated')
+ assert.ok(out.some((e) => e.id === 'claude' && e.blockedReason))
+ assert.ok(!runnable.includes('claude'))
+})
diff --git a/server/src/agents/computer/daemon.ts b/server/src/agents/computer/daemon.ts
index ae0eb8e..c4c9822 100644
--- a/server/src/agents/computer/daemon.ts
+++ b/server/src/agents/computer/daemon.ts
@@ -45,7 +45,7 @@ import {
} from '../runtime/wake-options.js'
import { SKYPE_EMOTICONS_GUIDE } from '../skype-emoticons.js'
import { finalizeTriage, isRateLimited, parseTriage } from '../triage-core.js'
-import { allowUnsandboxedByoa, detectEnginesWithStatus, ENGINE_IDS, type EngineHopReport, type EngineId, type EngineRunResult, type EngineSession, type EngineUsage, enrichDetectedEngines, evaluateRunnableEngines, getAdapter, runEngineDoctor, snapshotDetectedEngines } from './engine.js'
+import { allowUnsandboxedByoa, detectEnginesWithStatus, ENGINE_IDS, type DetectedEngineSnapshot, type EngineHopReport, type EngineId, type EngineRunResult, type EngineSession, type EngineUsage, enrichDetectedEngines, evaluateRunnableEngines, getAdapter, runEngineDoctor, type RunnableEngineEvaluation, snapshotDetectedEngines } from './engine.js'
export { conversationHeader }
@@ -736,7 +736,27 @@ function helpText(): string {
].join('\n')
}
-async function requireLocalEngine(): Promise<EngineId[]> {
+/** Snapshot rows for refused engines, each carrying the reason it was refused.
+ * Reported alongside the runnable ones so the card can explain an absence;
+ * they never enter the `engines` list, which is what picks an adapter. */
+async function blockedSnapshotRows(
+ blocked: RunnableEngineEvaluation['blocked'],
+): Promise<DetectedEngineSnapshot[]> {
+ const rows = await snapshotDetectedEngines(blocked.map(({ id }) => id))
+ return rows.map((row) => ({
+ ...row,
+ blockedReason: blocked.find(({ id }) => id === row.id)?.reason,
+ }))
+}
+
+/** The engines this machine can run, plus the ones it cannot and why.
+ *
+ * The refusals used to stop at the console.warn below. Pairing then reported
+ * only the runnable list, so a fresh computer's card said nothing about the
+ * engine that was skipped until the first PATH rescan minutes later — which is
+ * precisely the window in which someone asks why their Claude Code is not
+ * listed. */
+async function requireLocalEngine(): Promise<RunnableEngineEvaluation> {
const detected = await detectEnginesWithStatus()
if (!detected.reliable) {
throw new Error('could not scan PATH (`which` / `where` failed). Fix that, then retry pairing.')
@@ -750,7 +770,7 @@ async function requireLocalEngine(): Promise<EngineId[]> {
if (evaluated.blocked.length > 0) {
console.warn(`[computer] secure engine(s) disabled: ${evaluated.blocked.map(({ id, reason }) => `${id} (${reason})`).join('; ')}`)
}
- return evaluated.runnable
+ return evaluated
}
/** Resolve the engine a daemon can actually run from its LIVE PATH inventory. */
@@ -1238,7 +1258,8 @@ async function detectHostName(): Promise<string> {
}
async function doPair(code: string, serverUrl: string, preferredEngine?: string): Promise<void> {
- const detected = await requireLocalEngine()
+ const evaluated = await requireLocalEngine()
+ const detected = evaluated.runnable
// The chosen engine becomes this computer's DEFAULT — it's sent first in the
// engines list, which the server stores as available_engines[0] and uses as
// the engine for the starter team and any agent assigned here without an
@@ -1253,12 +1274,16 @@ async function doPair(code: string, serverUrl: string, preferredEngine?: string)
}
engines = [preferredEngine as EngineId, ...detected.filter((e) => e !== preferredEngine)]
}
- const snapshot = await snapshotDetectedEngines(engines)
+ const blockedIds = evaluated.blocked.map(({ id }) => id)
+ const snapshot = [
+ ...await snapshotDetectedEngines(engines),
+ ...await blockedSnapshotRows(evaluated.blocked),
+ ]
const paired = await api<{ computerId: string; deviceToken: string }>(
serverUrl, '/api/computers/pair',
{ method: 'POST', body: JSON.stringify({
code, hostName: await detectHostName(), engines, detected: snapshot,
- version: CURRENT_VERSION, supervised: SUPERVISED,
+ blocked: blockedIds, version: CURRENT_VERSION, supervised: SUPERVISED,
}) },
)
await saveConfig({ serverUrl, computerId: paired.computerId, deviceToken: paired.deviceToken })
@@ -2982,7 +3007,7 @@ async function doRun(serverOverride?: string): Promise<void> {
if (serverOverride) cfg.serverUrl = serverOverride
let initialEngines: EngineId[]
try {
- initialEngines = await requireLocalEngine()
+ initialEngines = (await requireLocalEngine()).runnable
} catch (err) {
console.error(`[computer] ${err instanceof Error ? err.message : String(err)}`)
process.exitCode = 70
@@ -3103,14 +3128,12 @@ async function doRun(serverOverride?: string): Promise<void> {
// anywhere they could see. They stay OUT of `next`: that list becomes
// available_engines and picks an agent's adapter.
const blockedIds = evaluated.blocked.map(({ id }) => id)
- const blockedRows = (await snapshotDetectedEngines(blockedIds)).map((row) => ({
- ...row,
- blockedReason: evaluated.blocked.find(({ id }) => id === row.id)?.reason,
- }))
- const snapshot = [
- ...await enrichDetectedEngines(await snapshotDetectedEngines(next)),
- ...await enrichDetectedEngines(blockedRows),
- ]
+ // One enrich over the whole list: it maps entry-by-entry, so splitting it
+ // bought nothing and only risked the two halves drifting apart.
+ const snapshot = await enrichDetectedEngines([
+ ...await snapshotDetectedEngines(next),
+ ...await blockedSnapshotRows(evaluated.blocked),
+ ])
// Report on version drift too, not just install/uninstall — upgrading an
// engine in place leaves the engine *list* identical, and that is exactly
// when the card's version line goes stale. The blocked reasons are part
diff --git a/server/src/agents/computer/registry.ts b/server/src/agents/computer/registry.ts
index 7a7f138..dbac382 100644
--- a/server/src/agents/computer/registry.ts
+++ b/server/src/agents/computer/registry.ts
@@ -345,6 +345,11 @@ export async function pairComputer(args: {
engines?: string[]
/** Optional PATH snapshot from the daemon (bin + resolved path). */
detected?: unknown
+ /** Installed engines the daemon refused to run, so the card can say why from
+ * the very first pairing rather than only after the next PATH rescan — which
+ * is minutes later, and right after pairing is exactly when "why is only
+ * codex here?" gets asked. Display-only; never joins available_engines. */
+ blocked?: string[]
/** The daemon's running version, stored so the app can flag outdated daemons. */
version?: string
/** Whether the daemon runs supervised (service) vs. as a foreground command. */
@@ -356,7 +361,8 @@ export async function pairComputer(args: {
deferBroadcast?: boolean
}): Promise<{ computerId: string; companyId: string; deviceToken: string } | null> {
const engines = (args.engines ?? []).filter((e) => PAIRABLE_ENGINES.has(e))
- const detected = sanitizeDetectedEngines(args.detected, engines)
+ const blocked = args.blocked ?? []
+ const detected = sanitizeDetectedEngines(args.detected, engines, blocked)
const detectedJson = JSON.stringify(detected)
const version = typeof args.version === 'string' && args.version ? args.version.slice(0, 32) : null
const supervised = typeof args.supervised === 'boolean' ? args.supervised : null
@@ -376,7 +382,7 @@ export async function pairComputer(args: {
// the existing default first while it is still installed; if it vanished,
// mergeDetectedEngines naturally falls back to the daemon's scan order.
const orderedEngines = mergeDetectedEngines(currentEngines ?? [], engines) ?? (currentEngines ?? [])
- const reconnectDetectedJson = JSON.stringify(sanitizeDetectedEngines(args.detected, orderedEngines))
+ const reconnectDetectedJson = JSON.stringify(sanitizeDetectedEngines(args.detected, orderedEngines, blocked))
await pool.query(
`UPDATE computers
SET credential_hash = $1, available_engines = $2::jsonb,
diff --git a/server/src/api/router.ts b/server/src/api/router.ts
index f781c18..0b5df71 100644
--- a/server/src/api/router.ts
+++ b/server/src/api/router.ts
@@ -1186,6 +1186,11 @@ api.post('/computers/pair', safe(async (req, res) => {
? (req.body.engines as unknown[]).filter((e): e is string => typeof e === 'string')
: []
const detected = req.body?.detected
+ // Same separation as /computers/me/engines: display-only, never merged into
+ // the engines list that picks an adapter.
+ const blockedAtPair = Array.isArray(req.body?.blocked)
+ ? (req.body.blocked as unknown[]).filter((e): e is string => typeof e === 'string')
+ : []
const hostName = typeof req.body?.hostName === 'string' ? req.body.hostName : undefined
const version = typeof req.body?.version === 'string' ? req.body.version : undefined
const supervised = typeof req.body?.supervised === 'boolean' ? req.body.supervised : undefined
@@ -1193,7 +1198,7 @@ api.post('/computers/pair', safe(async (req, res) => {
// its onboarding gate on that event and immediately reloads its roster, so the
// starter team + "Everyone" group must already exist when it fires — otherwise
// the user lands on an empty Conversations list that fills in a beat later.
- const paired = await pairComputer({ code, hostName, engines, detected, version, supervised, deferBroadcast: true })
+ const paired = await pairComputer({ code, hostName, engines, detected, blocked: blockedAtPair, version, supervised, deferBroadcast: true })
if (!paired) throw new HttpError(400, 'invalid pairing token')
// Free-tier BYOA onboarding on pair. The daemon sends the engines list with
// the user's CHOSEN engine first (`cumora agent computer --pair … --engine X`),