Skip to content

Your team of AI agents, on your Mac, Windows or Linux. Agents that talk in channels, write code, review each other and use your tools, on the Claude Code, Codex, OpenCode or Pi you already have. Anything that touches the real world waits for your yes.

Stop at once when an agent's computer is down, instead of trying every tool (#112)

Diasa64a88e56249
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e22863a..e9a9d5e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ What changed in each version of Tucano. The format follows [Keep a Changelog](ht
- **Claude replies finish about 2 seconds sooner, at times 10.** After each reply Claude Code made one more model call, a summary of the turn that Tucano never reads, and only then said it was done and exited. That call is now off for the Claude Code that Tucano runs, so a reply ends when its text does, and what waits on it (the next agent in line, a team's report) starts right away. Your own Claude Code in the terminal isn't touched.
- **Agents see what a connector returns, even when it's long.** A result over Claude Code's own cut (about 50 KB, like the comments of a big merge request) was saved to a file the agent can't read, so it called again and again and answered without the data. Tucano now cuts a result at 40 KB, counted in bytes so accents don't push it over, and tells the agent to ask again with pagination or a filter if it needs the rest.
- **Connectors stay connected.** A local connector whose process ended (a crash, or one that quits when idle) stayed **Disconnected** for good, and its tools went away from the agents, so nothing ever brought it back; and a remote one whose server forgot an idle session failed every call while still showing **Connected**. Now a connection that drops on its own comes back by itself, after a wait that grows from 2 seconds to 5 minutes, and a call on a forgotten session opens a new one and goes through. A connector that's only reconnecting keeps its tools; one that needs you (a refused token, a sign-in to finish) doesn't, and isn't retried.
+- **An agent stops at once when its computer can't run.** With Docker off, out of reach or not installed, every command and file read failed, and the agent tried tool after tool, spending tokens to find out the same thing. Now the first call that finds Docker down ends the reply, which says what to do (start Docker, join the docker group, install it) and can be tried again. While Docker stays off, the next replies don't get the computer's tools at all: the agent is told it's down and says so in a sentence, answering what it can without it. A Docker that doesn't answer at all counts as down too, like one that's off.
## [0.2.10] - 2026-11-04
diff --git a/src/core/computer.ts b/src/core/computer.ts
index 758fdc3..b0f3430 100644
--- a/src/core/computer.ts
+++ b/src/core/computer.ts
@@ -186,8 +186,19 @@ export const noDocker = (): string =>
// On Linux, a user outside the docker group gets "permission denied" on its socket.
export const noDockerAccess = (): string =>
L('Seu usuário não tem acesso ao Docker. Rode sudo usermod -aG docker $USER, saia e entre de novo na sessão.', "Your user has no access to Docker. Run sudo usermod -aG docker $USER, then log out and back in.")
-// What a failed docker call says about Docker itself, if anything.
-export function dockerProblem(stderr: string): string | undefined {
+// No docker command at all: spawn fails before Docker can say anything.
+export const dockerMissing = (): string =>
+ L('O Docker não está instalado neste computador. Instale o Docker (docs.docker.com/get-docker).', "Docker isn't installed on this computer. Install Docker (docs.docker.com/get-docker).")
+// A quick docker call that never answered (`late`): the daemon is stuck (on Linux, a service that fails to
+// start behind its socket leaves every docker command waiting).
+export const dockerStuck = (): string =>
+ osOf() === 'linux'
+ ? L('O Docker não está respondendo. Reinicie o serviço (sudo systemctl restart docker) ou o Docker Desktop.', "Docker isn't answering. Restart the service (sudo systemctl restart docker) or Docker Desktop.")
+ : L('O Docker não está respondendo. Reinicie o Docker Desktop.', "Docker isn't answering. Restart Docker Desktop.")
+// What a failed docker call says about Docker itself, if anything. `late`: it was killed by its timeout.
+export function dockerProblem(stderr: string, late = false): string | undefined {
+ if (late) return dockerStuck()
+ if (/spawn docker ENOENT/i.test(stderr)) return dockerMissing()
if (/permission denied[^\n]*docker\.sock/i.test(stderr)) return noDockerAccess()
if (/daemon|connect to the docker/i.test(stderr)) return noDocker()
return undefined
@@ -315,7 +326,7 @@ const q = (s: string): string => `'${s.replace(/'/g, `'\\''`)}'`
// ---------- docker ----------
-type Exec = { code: number; stdout: string; stderr: string }
+type Exec = { code: number; stdout: string; stderr: string; late?: boolean } // late: killed by its timeout
function docker(args: string[], opts: { stdin?: string | Buffer; timeoutMs?: number; signal?: AbortSignal } = {}): Promise<Exec> {
return new Promise((resolve) => {
@@ -325,7 +336,13 @@ function docker(args: string[], opts: { stdin?: string | Buffer; timeoutMs?: num
child.stdout.setEncoding('utf8').on('data', (d: string) => (stdout = (stdout + d).slice(-2_000_000)))
child.stderr.setEncoding('utf8').on('data', (d: string) => (stderr = (stderr + d).slice(-200_000)))
const kill = (): void => void child.kill('SIGKILL')
- const timer = opts.timeoutMs ? setTimeout(kill, opts.timeoutMs) : null
+ let late = false // killed by the timeout, not by the caller
+ const timer = opts.timeoutMs
+ ? setTimeout(() => {
+ late = true
+ kill()
+ }, opts.timeoutMs)
+ : null
opts.signal?.addEventListener('abort', kill, { once: true })
child.on('error', (e) => {
stderr += e.message
@@ -333,7 +350,7 @@ function docker(args: string[], opts: { stdin?: string | Buffer; timeoutMs?: num
child.on('close', (code) => {
if (timer) clearTimeout(timer)
opts.signal?.removeEventListener('abort', kill)
- resolve({ code: code ?? -1, stdout, stderr })
+ resolve({ code: code ?? -1, stdout, stderr, ...(late ? { late } : {}) })
})
child.stdin.on('error', () => {})
child.stdin.end(opts.stdin ?? '')
@@ -344,6 +361,9 @@ export interface ToolOutcome {
result: CallToolResult
artifact?: Artifact
service?: string
+ // The computer can't run at all (Docker is off or out of reach): what the person has to do. No other
+ // call will work either, so the turn ends here instead of trying tool after tool.
+ down?: string
}
export interface ComputerDeps {
@@ -397,13 +417,23 @@ export class Computers {
this.deps.emit({ type: 'computer', computer: next })
}
+ // Before a turn: when Docker was last seen off, whether it still is (what the person has to do), read
+ // again now. A quick `docker inspect`, which fails at once with the daemon down; nothing when it was fine,
+ // so a turn never waits on Docker for nothing.
+ async unavailable(agent: Agent): Promise<string | undefined> {
+ if (agent.computerKind === 'mac' || this.infos.get(agent.id)?.state !== 'no_docker') return undefined
+ await this.refresh(agent)
+ const info = this.infos.get(agent.id)
+ return info?.state === 'no_docker' ? info.detail : undefined
+ }
+
// Reads the container's real state, for the agent page.
async refresh(agent: Agent): Promise<void> {
if (agent.computerKind === 'mac') return this.mac.refresh(agent)
if (!agent.computer) return this.set(agent.id, { state: 'off', services: [] })
const r = await docker(['inspect', '-f', '{{.State.Running}}', this.name(agent.id)], { timeoutMs: 10_000 })
if (r.code !== 0) {
- const problem = dockerProblem(r.stderr)
+ const problem = dockerProblem(r.stderr, r.late)
return this.set(agent.id, { state: problem ? 'no_docker' : 'stopped', detail: problem, services: [] })
}
if (r.stdout.trim() !== 'true') return this.set(agent.id, { state: 'stopped', services: [] })
@@ -468,7 +498,7 @@ export class Computers {
if (this.infos.get(agentId)?.state !== 'running') this.set(agentId, { state: 'running', services: await this.serviceStatus(agentId) })
return
}
- const problem = dockerProblem(state.stderr)
+ const problem = dockerProblem(state.stderr, state.late)
if (problem) {
this.set(agentId, { state: 'no_docker', detail: problem })
throw new Error(L(`O Docker não está disponível neste computador: ${problem} Peça pro usuário resolver.`, `Docker isn't available on this computer: ${problem} Ask the user to fix it.`))
@@ -836,7 +866,9 @@ export class Computers {
try {
await this.ensure(agent.id)
} catch (e) {
- return { result: textResult(e instanceof Error ? e.message : String(e), true) }
+ const info = this.infos.get(agent.id)
+ const down = info?.state === 'no_docker' ? info.detail : undefined
+ return { result: textResult(e instanceof Error ? e.message : String(e), true), ...(down ? { down } : {}) }
}
switch (name) {
case 'bash': {
diff --git a/src/core/context.ts b/src/core/context.ts
index dc32693..31340c6 100644
--- a/src/core/context.ts
+++ b/src/core/context.ts
@@ -17,6 +17,7 @@ export function systemPrompt(opts: {
memories?: { aboutMe: Memory[]; own: Memory[]; searchable?: number }
canRemember?: boolean
hasComputer?: boolean
+ computerOff?: string // it has a computer, but Docker is off right now: what the person has to do
offline?: string[] // connectors it has access to that aren't connected right now
macFolder?: string // a computer on this Mac (spec §23): where its commands start in this conversation
web?: boolean
@@ -28,7 +29,7 @@ export function systemPrompt(opts: {
builder?: string // the Tuca's view of the workspace: models, connectors, the team
wiki?: { pages: number; kinds: string[] } // the wiki it may read
}): string {
- const { agent, settings, conversation, peers, memories, canRemember, hasComputer, macFolder, offline, web, browser, apps, routines, skills, publish, builder, wiki } = opts
+ const { agent, settings, conversation, peers, memories, canRemember, hasComputer, computerOff, macFolder, offline, web, browser, apps, routines, skills, publish, builder, wiki } = opts
const me = settings.workspaceName || L('o usuário', 'the user')
const where =
conversation.kind === 'dm'
@@ -44,6 +45,14 @@ export function systemPrompt(opts: {
settings.context.trim() && `## ${L('Sobre', 'About')} ${me}\n${settings.context.trim()}`,
agent.instructions.trim() && `## ${L('Suas instruções', 'Your instructions')}\n${agent.instructions.trim()}`,
hasComputer && macFolder && macSection(me, macFolder),
+ computerOff &&
+ [
+ L('## Seu computador', '## Your computer'),
+ L(
+ `Está fora do ar agora: ${computerOff} Nesta resposta você não tem comandos nem arquivos dele. Se o pedido precisar do computador, diga isso a ${me} em uma frase, com o que fazer, e não tente outro caminho; o que der pra responder sem ele, responda.`,
+ `It's down right now: ${computerOff} In this reply you have none of its commands or files. If the request needs the computer, tell ${me} so in one sentence, with what to do, and don't try another way; what you can answer without it, answer.`
+ )
+ ].join('\n'),
hasComputer &&
!macFolder &&
[
diff --git a/src/core/runs.ts b/src/core/runs.ts
index b362f77..2e60b74 100644
--- a/src/core/runs.ts
+++ b/src/core/runs.ts
@@ -70,7 +70,7 @@ export interface RunnerDeps {
gateway?: Gateway // without it, agents get no tools at all
connectors?: Connectors
memory?: Memories // without it, agents get no memory and see the last HISTORY_LIMIT messages
- computers?: Pick<Computers, 'call'> & Partial<Pick<Computers, 'mac'>> // without it, no agent has a computer
+ computers?: Pick<Computers, 'call'> & Partial<Pick<Computers, 'mac' | 'unavailable'>> // without it, no agent has a computer
browser?: Pick<Browser, 'call' | 'approved'> // without it, no agent has a browser
apps?: Pick<DesktopApps, 'call' | 'approved'> // without it, no agent uses the person's apps
routines?: Pick<Routines, 'schedule' | 'cancel' | 'forAgent'> // without it, agents can't schedule
@@ -135,7 +135,7 @@ export interface RoutineEvent {
}
// msg is the live reply: a decision taken mid-run must land on it, or the run's last save overwrites it.
-type Control = { ctl: AbortController; msg: Message; reason?: 'stopped' | 'limit' | 'budget' | 'loop' | 'errors' | 'stall' }
+type Control = { ctl: AbortController; msg: Message; reason?: 'stopped' | 'limit' | 'budget' | 'loop' | 'errors' | 'stall' | 'computer' }
export class Runner {
private queue: (() => Promise<unknown>)[] = []
@@ -570,7 +570,12 @@ export class Runner {
const myConversations = (): Conversation[] => db.conversations().filter((c) => c.members.includes(agent.id))
// The Tuca proposes agents; nobody else does.
const builds = !!this.deps.gateway && agent.kind === 'tuca'
- const computers = this.deps.gateway && agent.computer ? this.deps.computers : undefined
+ let computers = this.deps.gateway && agent.computer ? this.deps.computers : undefined
+ // Docker was off last time: asked again now. Still off, the agent gets no computer tools and is told
+ // why, so it says so in a sentence instead of spending a call on each tool to find out.
+ const computerOff = computers ? await computers.unavailable?.(agent) : undefined
+ if (computerOff) computers = undefined
+ let computerDown: string | undefined // found off in the middle of the turn: what the person has to do
const browser = this.deps.gateway && agent.browser ? this.deps.browser : undefined
const apps = this.deps.gateway && agent.apps?.length ? this.deps.apps : undefined
const routines = this.deps.gateway ? this.deps.routines : undefined
@@ -854,6 +859,11 @@ export class Runner {
msg.run = { ...msg.run!, steps: [...closeThinking('done', THOUGHT()), step] }
save()
const out = await computers.call(current, name, args, { conversationId: conv.id, messageId: msg.id, signal: control.ctl.signal })
+ // No tool of the computer can work: the turn ends here, before the model tries the next one.
+ if (out.down) {
+ computerDown = out.down
+ halt('computer')
+ }
if (out.artifact) artifactIds.push(out.artifact.id)
if (out.service && !services.includes(out.service)) services.push(out.service)
msg.run = {
@@ -1185,6 +1195,7 @@ export class Runner {
memories: promptMemories,
canRemember,
hasComputer: !!computers,
+ computerOff,
browser: !!browser,
apps: apps ? agent.apps : undefined,
offline: (this.deps.connectors?.list() ?? []).filter((c) => (c.status === 'error' || c.status === 'needs_auth') && (agent.grants[c.id] ?? 'none') !== 'none').map((c) => c.name),
@@ -1303,6 +1314,17 @@ export class Runner {
text: msg.text ? `${msg.text} …` : '',
run: { ...base, ...again, status: 'failed', steps: closeThinking('error', L('Parou', 'Stopped')), error: L(`Parei: ${why}.`, `I stopped: ${why}.`) }
})
+ } else if (control.reason === 'computer') {
+ save({
+ text: msg.text ? `${msg.text} …` : '',
+ run: {
+ ...base,
+ ...again,
+ status: 'failed',
+ steps: closeThinking('error', L('Parou', 'Stopped')),
+ error: L(`Parei: meu computador não está funcionando. ${computerDown ?? ''} Depois é só mandar de novo.`, `I stopped: my computer isn't working. ${computerDown ?? ''} Then just send it again.`)
+ }
+ })
} else if (overBudget && control.reason !== 'limit') {
// Wrapped up at the budget, or cut past it: either way it can go on from here.
save({
diff --git a/test/computer-down.test.ts b/test/computer-down.test.ts
new file mode 100644
index 0000000..2524395
--- /dev/null
+++ b/test/computer-down.test.ts
@@ -0,0 +1,110 @@
+import { mkdtempSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+import type { Agent, EngineId, Settings } from '../src/shared/types'
+import { dockerProblem, formatExec } from '../src/core/computer'
+import { Db } from '../src/core/db'
+import { callTool, fakeEngine } from '../src/core/engines/fake'
+import type { Engine, Turn } from '../src/core/engines/types'
+import { Gateway, textResult } from '../src/core/gateway'
+import { Runner } from '../src/core/runs'
+
+const ready = { installed: true, loggedIn: true }
+const NO_DOCKER = 'O Docker não está rodando. Abra o Docker Desktop.'
+
+let db: Db
+let gateway: Gateway
+let settings: Settings
+let turns: Turn[]
+let calls: string[]
+let off: string | undefined // what `unavailable` says before a turn
+
+function runner(): Runner {
+ turns = []
+ calls = []
+ const fake = fakeEngine('claude', { delayMs: 1 })
+ const claude: Engine = { id: 'claude', run: (t) => (turns.push(t), fake.run(t)) }
+ const engines: Record<EngineId, Engine> = { claude, codex: fakeEngine('codex'), opencode: fakeEngine('opencode'), pi: fakeEngine('pi'), gemini: fakeEngine('gemini'), cursor: fakeEngine('cursor') }
+ // Docker is off: every call fails the same way, and says so.
+ const computers = {
+ call: async (_a: Agent, name: string) => (calls.push(name), { result: textResult(`O Docker não está disponível neste computador: ${NO_DOCKER}`, true), down: NO_DOCKER }),
+ unavailable: async () => off
+ }
+ return new Runner({ db, engines, settings: async () => settings, emit: () => {}, workDir: mkdtempSync(join(tmpdir(), 'cd-w-')), gateway, computers })
+}
+
+const reply = () => db.messages().filter((m) => m.author.kind === 'agent').at(-1)!
+
+beforeEach(async () => {
+ db = new Db(join(mkdtempSync(join(tmpdir(), 'cd-db-')), 'test.db'))
+ settings = { workspaceName: 'Edu', context: '', engines: { claude: ready, codex: ready, opencode: ready, pi: ready, gemini: ready, cursor: ready }, routerModel: 'haiku', memoryModel: 'haiku', memoryLearning: 'approve', defaultLimit: 1000, approvalTtlHours: 24, theme: 'system', language: 'pt' }
+ db.saveAgent({ id: 'lia', name: 'Lia', handle: 'lia', role: '', color: 'sky', instructions: '', modelId: 'sonnet', effort: 'low', limit: 1_000_000, used: 0, grants: {}, memory: 'auto', computer: true, archived: false })
+ db.createConversation({ id: 'dm', kind: 'dm', name: 'lia', members: ['lia'] })
+ off = undefined
+ gateway = new Gateway()
+ await gateway.start()
+})
+afterEach(() => gateway.stop())
+
+describe('a computer whose Docker is off', () => {
+ it('knows Docker is off, out of reach or not installed from what the docker command says', () => {
+ expect(dockerProblem('Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?')).toContain('não está rodando')
+ expect(dockerProblem('permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock')).toContain('usermod')
+ expect(dockerProblem('spawn docker ENOENT')).toContain('não está instalado')
+ expect(dockerProblem('', true)).toContain('não está respondendo') // a quick check that never answered: stuck, every docker command waits
+ expect(dockerProblem('Error: No such container: tucano-lia')).toBeUndefined() // Docker is fine: the box just isn't there yet
+ })
+
+ it('ends the turn at the first call, and tells the person what to do', async () => {
+ const r = runner()
+ await r.send('dm', 'rode `echo hi`')
+ await r.idle()
+ expect(calls).toEqual(['bash']) // one call, not one per tool
+ expect(reply().run).toMatchObject({ status: 'failed' })
+ expect(reply().run!.error).toContain('meu computador não está funcionando')
+ expect(reply().run!.error).toContain(NO_DOCKER)
+ })
+
+ it('searching where nothing matches is no failure: commands that find nothing keep going', async () => {
+ // A grep with no match exits 1 and prints nothing, the same text from every one: not a sign that
+ // something around them is broken, so the reply goes on to its answer.
+ const tries: Engine = {
+ id: 'claude',
+ async *run(turn) {
+ for (const command of ['grep -rn TODO src', 'grep -rn FIXME src', 'grep -rn XXX src', 'grep -rn HACK src', 'ls src']) {
+ if (turn.signal.aborted) return
+ await callTool(turn.mcpUrl!, 'bash', { command }).catch(() => null)
+ yield { type: 'text', delta: '.' }
+ }
+ if (!turn.signal.aborted) yield { type: 'done', text: 'Nenhum TODO, FIXME, XXX ou HACK no projeto.', usage: { inputTokens: 1, cacheReadTokens: 0, outputTokens: 1 } }
+ }
+ }
+ const engines: Record<EngineId, Engine> = { claude: tries, codex: fakeEngine('codex'), opencode: fakeEngine('opencode'), pi: fakeEngine('pi'), gemini: fakeEngine('gemini'), cursor: fakeEngine('cursor') }
+ const ran: string[] = []
+ const computers = {
+ call: async (_a: Agent, _n: string, args: Record<string, unknown>) => {
+ const command = String(args['command'])
+ ran.push(command)
+ const ls = command.startsWith('ls')
+ return { result: textResult(formatExec({ code: ls ? 0 : 1, stdout: ls ? 'app.ts' : '', stderr: '' }, 120), !ls) }
+ }
+ }
+ const r = new Runner({ db, engines, settings: async () => settings, emit: () => {}, workDir: mkdtempSync(join(tmpdir(), 'cd-w-')), gateway, computers })
+ await r.send('dm', 'tem algum TODO, FIXME, XXX ou HACK no projeto?')
+ await r.idle()
+ expect(ran).toHaveLength(5)
+ expect(reply().run).toMatchObject({ status: 'done' })
+ })
+
+ it('still off at the next message: no computer tools, and the agent is told why', async () => {
+ off = NO_DOCKER
+ const r = runner()
+ await r.send('dm', 'rode `echo hi`')
+ await r.idle()
+ expect(calls).toEqual([]) // never reached the computer
+ expect(turns[0]!.system).toContain(`Está fora do ar agora: ${NO_DOCKER}`)
+ expect(turns[0]!.system).not.toContain('Você tem um computador Linux só seu')
+ expect(reply().run!.status).toBe('done')
+ })
+})