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(antigravity): avoid inner --sandbox EPERM on real turns and support --conversation resume
2BAB84696096cfd8
diff --git a/server/src/__tests__/agents-computer-engine-antigravity.test.ts b/server/src/__tests__/agents-computer-engine-antigravity.test.tsindex eaf58f7..2da1454 100644--- a/server/src/__tests__/agents-computer-engine-antigravity.test.ts+++ b/server/src/__tests__/agents-computer-engine-antigravity.test.ts@@ -60,6 +60,33 @@ rl.on('line', (line) => {} })return}+ if (process.env.FAKE_AGY_SCENARIO === 'resume-history') {+ // Simulates resuming a conversation that already accumulated 1000 input /+ // 100 output / 400 cache tokens in a previous daemon process.+ const stepUsage = turn === 1+ ? { input_tokens: 50, output_tokens: 8, thinking_tokens: 2, cache_read_tokens: 300, total_tokens: 58 }+ : { input_tokens: 40, output_tokens: 6, thinking_tokens: 1, cache_read_tokens: 350, total_tokens: 46 }+ const cumulative = turn === 1+ ? { input_tokens: 1050, output_tokens: 108, thinking_tokens: 42, cache_read_tokens: 700, total_tokens: 1158 }+ : { input_tokens: 1090, output_tokens: 114, thinking_tokens: 43, cache_read_tokens: 1050, total_tokens: 1204 }+ out({ event: 'step_update', step_update: {+ conversation_id: 'agy-conversation-resumed', step_index: turn * 2 - 1, state: 'ACTIVE', step_type: 'tool',+ tool_name: 'run_command', tool_info: { name: 'run_command' },+ } })+ out({ event: 'step_update', step_update: {+ conversation_id: 'agy-conversation-resumed', step_index: turn * 2 - 1, state: 'DONE', step_type: 'tool',+ tool_name: 'run_command', tool_info: { name: 'run_command' },+ } })+ out({ event: 'step_update', step_update: {+ conversation_id: 'agy-conversation-resumed', step_index: turn * 2, state: 'DONE', step_type: 'agent_response',+ text_delta: 'resumed:' + content, usage: stepUsage,+ } })+ out({ event: 'result', result: {+ conversation_id: 'agy-conversation-resumed', status: 'SUCCESS', response: 'resumed:' + content,+ duration_seconds: turn, num_turns: turn + 5, model: 'Gemini 3.5 Flash (High)', usage: cumulative,+ } })+ return+ }out({ event: 'step_update', step_update: {conversation_id: 'agy-conversation-1', step_index: turn, state: 'DONE', step_type: 'tool',tool_info: { name: 'run_command' },@@ -103,7 +130,7 @@ async function fakeLog(f: Fixture): Promise<Array<Record<string, unknown>>> {return (await readFile(f.log, 'utf8')).split('\n').filter(Boolean).map((line) => JSON.parse(line))}-test('antigravity persistent session uses sandboxed stream-json and bills per-turn deltas', { skip: IS_WIN }, async () => {+test('antigravity persistent session uses auto stream-json without inner --sandbox and bills per-turn deltas', { skip: IS_WIN }, async () => {const f = await fixture()const hops: EngineHopReport[] = []const session = getAdapter('antigravity').startSession?.({@@ -142,15 +169,55 @@ test('antigravity persistent session uses sandboxed stream-json and bills per-tuconst start = records.find((record) => record.type === 'start') as { argv: string[]; cwd: string }assert.ok(start.argv.includes('--input-format'))assert.ok(start.argv.includes('--output-format'))- assert.ok(start.argv.includes('--sandbox'))+ assert.ok(!start.argv.includes('--sandbox'), 'real agent turns must not enable inner --sandbox or cumora IPC outside <home> fails with EPERM')assert.ok(start.argv.includes('--dangerously-skip-permissions'))- assert.equal(start.argv[start.argv.indexOf('--mode') + 1], 'accept-edits')+ assert.equal(start.argv[start.argv.indexOf('--mode') + 1], 'auto')assert.ok(!start.argv.includes('first prompt'), 'the prompt must travel on stdin, not argv')assert.equal(start.cwd, await realpath(f.home))const prompts = records.filter((record) => record.type === 'prompt') as Array<{ event: { event: string; message: { content: string } } }>assert.deepEqual(prompts.map((record) => record.event.message.content), ['first prompt', 'second prompt'])})+test('antigravity resumed session passes --conversation and bills step usage without historical double-charging', { skip: IS_WIN }, async () => {+ const f = await fixture('resume-history')+ const hops: EngineHopReport[] = []+ const logs: string[] = []+ const session = getAdapter('antigravity').startSession?.({+ home: f.home,+ env: f.env,+ model: 'Gemini 3.5 Flash (High)',+ resumeSessionId: 'agy-conversation-resumed',+ onLog: (line) => logs.push(line),+ onHopUsage: (hop) => hops.push(hop),+ })+ assert.ok(session)++ const first = await session.send('after restart 1')+ const second = await session.send('after restart 2')+ await session.stop()++ // Turn 1's result.usage is 1050/108/700 (including 1000 historical input+ // tokens from the prior process), but its agent_response step_update carried+ // 50 fresh input / 8 output / 300 cache_read_tokens.+ assert.deepEqual(first.usage, {+ input_tokens: 50,+ output_tokens: 8,+ cache_read_input_tokens: 300,+ })+ assert.deepEqual(second.usage, {+ input_tokens: 40,+ output_tokens: 6,+ cache_read_input_tokens: 350,+ })+ assert.equal(hops.length, 2)+ assert.ok(logs.includes('[antigravity] tool run_command'))+ assert.ok(logs.includes('[antigravity] » resumed:after restart 1'))++ const records = await fakeLog(f)+ const start = records.find((record) => record.type === 'start') as { argv: string[] }+ assert.equal(start.argv[start.argv.indexOf('--conversation') + 1], 'agy-conversation-resumed')+})+test('antigravity keeps its usage baseline across a result that reports no usage', { skip: IS_WIN }, async () => {const f = await fixture('usage-gap')const hops: EngineHopReport[] = []@@ -200,6 +267,7 @@ test('antigravity triage uses plan mode and returns the current reply', { skip:assert.equal(result.text, 'echo:classify this')const records = await fakeLog(f)const start = records.find((record) => record.type === 'start') as { argv: string[] }+ assert.ok(start.argv.includes('--sandbox'))assert.equal(start.argv[start.argv.indexOf('--mode') + 1], 'plan')assert.equal(start.argv[start.argv.indexOf('--model') + 1], 'Gemini 3.5 Flash (Low)')})diff --git a/server/src/agents/computer/engine.ts b/server/src/agents/computer/engine.tsindex 96d2607..995afec 100644--- a/server/src/agents/computer/engine.ts+++ b/server/src/agents/computer/engine.ts@@ -5443,8 +5443,10 @@ interface AntigravityEvent {step_index?: numberstate?: stringstep_type?: string+ tool_name?: stringtext_delta?: stringtool_info?: unknown+ usage?: AntigravityNativeUsage}result?: {conversation_id?: string@@ -5464,15 +5466,15 @@ function antigravityCounter(value: unknown): number {/** Convert Antigravity's counters without charging cache reads twice.*- * `input_tokens` is the complete prompt, including cache reads (the documented- * examples satisfy total = input + output). Cumora's common shape wants fresh- * input and cache reads in disjoint fields. `thinking_tokens` is a subset of- * output_tokens, not an extra token class, so it is intentionally not added- * again. */+ * When `input_tokens` includes `cache_read_tokens` (`input_tokens >= cache_read_tokens`),+ * subtract `cache_read_tokens` so fresh input and cache reads stay disjoint. When+ * `agy` reports `input_tokens` already net of cache reads (`input_tokens < cache_read_tokens`,+ * where `total_tokens = input_tokens + output_tokens`), preserve `input_tokens` as-is. */function antigravityUsage(raw: AntigravityNativeUsage | undefined): EngineUsage | undefined {if (!raw) return undefinedconst cached = antigravityCounter(raw.cache_read_tokens)- const input = Math.max(0, antigravityCounter(raw.input_tokens) - cached)+ const rawInput = antigravityCounter(raw.input_tokens)+ const input = rawInput >= cached ? rawInput - cached : rawInputconst output = antigravityCounter(raw.output_tokens)if (!input && !output && !cached) return undefinedreturn {@@ -5503,6 +5505,19 @@ function antigravityUsageDelta(}}+function addAntigravityUsage(+ acc: AntigravityNativeUsage | undefined,+ step: AntigravityNativeUsage,+): AntigravityNativeUsage {+ return {+ input_tokens: antigravityCounter(acc?.input_tokens) + antigravityCounter(step.input_tokens),+ output_tokens: antigravityCounter(acc?.output_tokens) + antigravityCounter(step.output_tokens),+ thinking_tokens: antigravityCounter(acc?.thinking_tokens) + antigravityCounter(step.thinking_tokens),+ cache_read_tokens: antigravityCounter(acc?.cache_read_tokens) + antigravityCounter(step.cache_read_tokens),+ total_tokens: antigravityCounter(acc?.total_tokens) + antigravityCounter(step.total_tokens),+ }+}+function parseAntigravityLine(line: string): AntigravityEvent | null {if (!line.startsWith('{')) return nulltry { return JSON.parse(line) as AntigravityEvent } catch { return null }@@ -5515,25 +5530,32 @@ class AntigravityTurnTracker {error: string | null = nullusage: EngineUsage | undefinedprivate previousUsage: AntigravityNativeUsage | undefined+ private turnStepUsage: AntigravityNativeUsage | undefinedprivate startedAt: number | null = nullprivate toolUses = 0private readonly seenToolSteps = new Set<number>()+ private readonly seenResponseSteps = new Set<number>()private hopIndex = 0+ private awaitingResumedBaseline: booleanconstructor(pin: string | null,private readonly onHopUsage?: (report: EngineHopReport) => void,+ resumedFromDisk = false,) {this.model = pin+ this.awaitingResumedBaseline = resumedFromDisk}beginTurn(): void {this.text = ''this.error = nullthis.usage = undefined+ this.turnStepUsage = undefinedthis.startedAt = Date.now()this.toolUses = 0this.seenToolSteps.clear()+ this.seenResponseSteps.clear()}/** Feed one event. True means the current turn reached its terminal result. */@@ -5549,6 +5571,12 @@ class AntigravityTurnTracker {this.seenToolSteps.add(step.step_index)this.toolUses += 1}+ if (step?.step_type === 'agent_response' && step.state === 'DONE' && step.usage) {+ if (typeof step.step_index !== 'number' || !this.seenResponseSteps.has(step.step_index)) {+ if (typeof step.step_index === 'number') this.seenResponseSteps.add(step.step_index)+ this.turnStepUsage = addAntigravityUsage(this.turnStepUsage, step.usage)+ }+ }return false}if (event.event !== 'result' || !event.result) return false@@ -5560,15 +5588,17 @@ class AntigravityTurnTracker {? result.error: `antigravity turn ended with status ${result.status || 'UNKNOWN'}`}- const delta = antigravityUsageDelta(result.usage, this.previousUsage)- // Only a result that CARRIES usage moves the baseline. `usage` is optional- // in the protocol and an errored turn routinely omits it — overwriting the- // baseline with `undefined` there bills the next turn's whole cumulative- // session counter as one turn, which is the exact double-billing this- // tracker exists to prevent. Keeping the last known total means a- // usage-less turn bills nothing (correct: the CLI reported no spend) and- // the turn after it still bills only its own delta.- if (result.usage) this.previousUsage = result.usage+ // Prefer the sum of per-step `agent_response` usages emitted during this turn:+ // when resuming via `--conversation <id>`, `result.usage` includes historical+ // turns from prior processes, whereas `turnStepUsage` covers only the current+ // turn. Fall back to cumulative `result.usage` delta when no step usage was+ // emitted (e.g. synthetic fixtures or pre-step errors on fresh sessions).+ const delta = this.turnStepUsage+ ?? (this.awaitingResumedBaseline ? undefined : antigravityUsageDelta(result.usage, this.previousUsage))+ if (result.usage) {+ this.previousUsage = result.usage+ this.awaitingResumedBaseline = false+ }this.usage = antigravityUsage(delta)if (this.usage && this.onHopUsage) {this.hopIndex += 1@@ -5607,7 +5637,7 @@ class AntigravitySession implements EngineSession {private readonly opts: EngineSessionArgs,pin: string | null,) {- this.tracker = new AntigravityTurnTracker(pin, opts.onHopUsage)+ this.tracker = new AntigravityTurnTracker(pin, opts.onHopUsage, Boolean(opts.resumeSessionId))this.child = spawnEngineChild(command, argv, {cwd: opts.home,env: opts.env,@@ -5686,8 +5716,20 @@ class AntigravitySession implements EngineSession {const line = cleanLine(raw)if (!line) returnpushTail(this.stdoutTail, line)- this.opts.onLog(line)const event = parseAntigravityLine(line)+ if (event?.event === 'step_update' && event.step_update) {+ const step = event.step_update+ const toolName = step.tool_name ?? (step.tool_info as { name?: string } | undefined)?.name+ if (step.step_type === 'tool' && step.state === 'ACTIVE' && typeof toolName === 'string' && toolName) {+ this.opts.onLog(`[antigravity] tool ${toolName}`)+ } else if (step.step_type === 'agent_response' && step.state === 'DONE' && typeof step.text_delta === 'string' && step.text_delta.trim()) {+ this.opts.onLog(`[antigravity] » ${step.text_delta.replace(/\s+/g, ' ').trim().slice(0, 200)}`)+ } else {+ this.opts.onLog(line)+ }+ } else {+ this.opts.onLog(line)+ }if (event && this.tracker.observe(event)) {const eventError = this.tracker.errorthis.settle({@@ -5736,30 +5778,37 @@ class AntigravityAdapter implements EngineAdapter {readonly id = 'antigravity' as constreadonly bin = 'agy'- private sessionArgs(args: EngineSessionArgs, mode: 'accept-edits' | 'plan'): string[] {+ private sessionArgs(args: EngineSessionArgs, mode: 'auto' | 'plan'): string[] {const model = args.model ? ['--model', args.model] : []+ const resume = mode === 'auto' && args.resumeSessionId+ ? ['--conversation', args.resumeSessionId]+ : []+ // Only pass `--sandbox` on the read-only triage/probe ('plan') path.+ // Real agent turns ('auto') run inside Cumora's outer BYOA boundary and must+ // write IPC requests to CUMORA_AGENT_IPC_DIR (outside <home>) to invoke+ // `cumora glance/messages/reply/send` as well as read ~/.gitconfig and+ // workspace paths; `--sandbox` on real turns causes every `cumora` CLI call+ // to fail with EPERM on first attempt and waste an extra LLM turn retrying.+ const sandbox = mode === 'plan' ? ['--sandbox'] : []return ['--input-format', 'stream-json','--output-format', 'stream-json',- '--sandbox',+ ...sandbox,'--mode', mode,'--dangerously-skip-permissions','--disable-slash-commands',+ ...resume,...model,]}- private start(args: EngineSessionArgs, mode: 'accept-edits' | 'plan'): AntigravitySession {+ private start(args: EngineSessionArgs, mode: 'auto' | 'plan'): AntigravitySession {const { command, shell } = resolveSpawn(this.bin)- // Do not pass --conversation across daemon restarts yet. Its result usage is- // cumulative over the historical conversation, while Cumora persists only- // the id, not the prior counters; resuming would overbill that history as- // the first new turn. The per-agent home + memory remains durable.return new AntigravitySession(command, this.sessionArgs(args, mode), shell, args, args.model ?? null)}startSession(args: EngineSessionArgs): EngineSession | null {- return this.start(args, 'accept-edits')+ return this.start(args, 'auto')}async run(args: EngineRunArgs): Promise<EngineRunResult> {@@ -5773,7 +5822,7 @@ class AntigravityAdapter implements EngineAdapter {onLog: args.onLog,onHopUsage: args.onHopUsage,}- const session = this.start(sessionArgs, 'accept-edits')+ const session = this.start(sessionArgs, 'auto')const onAbort = (): void => { void session.stop({ force: true }) }args.signal.addEventListener('abort', onAbort, { once: true })if (args.signal.aborted) onAbort()