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): give codex agents their memory back, and let them see attachments
yetone12c332493e4e
diff --git a/server/src/__tests__/agents-computer-attachment-visibility.test.ts b/server/src/__tests__/agents-computer-attachment-visibility.test.tsnew file mode 100644index 0000000..609efee--- /dev/null+++ b/server/src/__tests__/agents-computer-attachment-visibility.test.ts@@ -0,0 +1,59 @@+/**+ * A BYOA agent must be able to tell that a message carried a file.+ *+ * A user sent a 626KB zip and asked "这个能看到么". The agent answered, truthfully,+ * that it saw only the text — the attachment was in `messages.attachment`, was+ * selected by `loadInbox`, and reached the daemon, and then `snapshotUnread`+ * built each digest line from `row.body` alone. `daemon.ts` contained no+ * reference to `attachment` at all. The cloud path (turn.ts) always surfaced+ * them; only the BYOA path dropped them.+ *+ * Run: node --import tsx --test server/src/__tests__/agents-computer-attachment-visibility.test.ts+ */+import { test } from 'node:test'+import assert from 'node:assert/strict'++process.env.CUMORA_RUNTIME_CLIENT = 'http'+process.env.OPENAI_API_KEY ??= 'test-key'++const { attachmentNote } = await import('../agents/computer/daemon.js')++test('the reported zip is now visible to the agent', () => {+ const note = attachmentNote({+ name: 'talking-head-visual-director-v1.0.zip',+ kind: 'file',+ mime: 'application/zip',+ size: 626 * 1024,+ url: 'https://cdn.cumora.ai/a/abc?sig=1',+ })+ assert.match(note, /talking-head-visual-director-v1\.0\.zip/)+ assert.match(note, /application\/zip/)+ assert.match(note, /626KB/)+ // The agent has to be able to actually fetch it, not just know it exists.+ assert.match(note, /https:\/\/cdn\.cumora\.ai\/a\/abc\?sig=1/)+})++test('a message with no attachment gains nothing', () => {+ assert.equal(attachmentNote(null), '')+ assert.equal(attachmentNote(undefined), '')+ assert.equal(attachmentNote({}), ' [attachment: file]')+})++test('megabyte sizes read as megabytes', () => {+ assert.match(attachmentNote({ name: 'a.mov', size: 5 * 1024 * 1024 }), /5\.0MB/)+ // Never report a real file as "0KB".+ assert.match(attachmentNote({ name: 'tiny.txt', size: 12 }), /1KB/)+})++test('hostile fields cannot run away with the digest line', () => {+ const note = attachmentNote({+ name: 'x'.repeat(5000),+ mime: 'y'.repeat(5000),+ size: Number.NaN,+ // Not http(s): must not be offered to the agent as something to fetch.+ url: 'file:///etc/passwd',+ })+ assert.ok(note.length < 260, `digest line must stay bounded, got ${note.length}`)+ assert.equal(note.includes('file:///etc/passwd'), false, 'only http(s) urls are surfaced')+ assert.equal(note.includes('NaN'), false)+})diff --git a/server/src/agents/computer/daemon.ts b/server/src/agents/computer/daemon.tsindex fb0ef26..e7813b3 100644--- a/server/src/agents/computer/daemon.ts+++ b/server/src/agents/computer/daemon.ts@@ -339,6 +339,32 @@ interface AgentInfo {fastModel: string | null}+/** One line's worth of "there is a file on this message".+ *+ * The attachment already travelled: /inbox selects `m.attachment` and the+ * daemon received it. It was simply never rendered, so a BYOA agent saw the+ * text of a message and no sign that a file came with it — and said so, truthfully,+ * when a user asked why it could not see their zip. The cloud path (turn.ts)+ * has always surfaced attachments; only this one dropped them.+ *+ * Name, type and size go inline so the agent can reason about the file, and the+ * URL follows so it can actually fetch it. Bounded, because this shares the+ * digest's line budget with the message bodies. */+export function attachmentNote(+ att: { name?: string; kind?: string; mime?: string; size?: number; url?: string } | null | undefined,+): string {+ if (!att || typeof att !== 'object') return ''+ const name = typeof att.name === 'string' && att.name.trim() ? att.name.trim().slice(0, 120) : 'file'+ const type = typeof att.mime === 'string' && att.mime.trim()+ ? att.mime.trim().slice(0, 60)+ : (typeof att.kind === 'string' ? att.kind.slice(0, 20) : '')+ const size = typeof att.size === 'number' && Number.isFinite(att.size) && att.size > 0+ ? ` ${att.size >= 1024 * 1024 ? `${(att.size / 1024 / 1024).toFixed(1)}MB` : `${Math.max(1, Math.round(att.size / 1024))}KB`}`+ : ''+ const url = typeof att.url === 'string' && /^https?:\/\//.test(att.url) ? ` ${att.url}` : ''+ return ` [attachment: ${name}${type ? ` · ${type}` : ''}${size}${url}]`+}+interface RuntimeInboxResponse {rows?: Array<{id?: string@@ -352,6 +378,9 @@ interface RuntimeInboxResponse {author_kind?: stringbody?: stringkind?: string+ /** Already delivered by /inbox (loadInbox selects m.attachment) and, until+ * now, dropped on the floor when the digest line was built. */+ attachment?: { name?: string; kind?: string; mime?: string; size?: number; url?: string } | nullsequence?: number}>}@@ -1441,6 +1470,11 @@ class AgentRunner {* on a frozen inbox snapshot. Captured from each run's stream-json output;* cleared if a resume fails so the next wake starts a clean session. */private sessionId: string | null = null+ /** Set when the persistent engine process proved unusable on this machine, so+ * the runner stops trying it and stays on the one-shot path. Without this a+ * process that starts and then fails every turn fails every turn forever;+ * with it, the worst case is exactly the pre-persistent behaviour. */+ private persistentUnusable = false/** The long-lived engine process (persistent stream-json for claude, app-server* thread for codex), created lazily and reused across wakes so turns 2..N skip* the cold start. Null = not yet started, dead (respawn next turn), or this@@ -1769,6 +1803,7 @@ class AgentRunner {* carries across the restart. */private ensureEngineSession(): EngineSession | null {if (!this.adapter.startSession) return null+ if (this.persistentUnusable) return nullif (this.engineSession?.alive) return this.engineSessionthis.engineSession = this.adapter.startSession({home: this.home,@@ -2076,7 +2111,7 @@ class AgentRunner {// Keep the message id + convo id on each line (like the cloud agent's// context) so the engine can QUOTE the exact message: `cumora reply// <convo> '<body>' --quote <message_id>`.- convo.msgs.push(` [${row.id}] ${row.conversation_id} ${who}: ${body}`)+ convo.msgs.push(` [${row.id}] ${row.conversation_id} ${who}: ${body}${attachmentNote(row.attachment)}`)}const projectIds = uniqueProjectIds((inbox?.rows ?? []).map((r) => (typeof r.project_id === 'string' ? r.project_id : null)),@@ -2726,6 +2761,31 @@ class AgentRunner {// Process died during/after the turn → drop it so the next wake respawns// (with --resume this.sessionId to carry context across the restart).if (!session.alive) this.engineSession = null+ // A persistent process that dies without producing a turn is not a+ // transient hiccup, it is this machine telling us the persistent+ // transport does not work here. Retry THIS turn one-shot and stay+ // there: the alternative is failing every wake forever, which is the+ // shape the codex sandbox outage took.+ // No usage means the model never ran — the process died in the+ // transport, not mid-answer, so re-running the turn cannot duplicate+ // work or double-charge.+ if (result.error && !result.usage && !session.alive) {+ this.persistentUnusable = true+ this.engineSession = null+ this.logEngineLine(`[engine] persistent session failed to produce a turn (${result.error.slice(0, 160)}) — falling back to one-shot for the rest of this process`)+ result = await this.trackEngineRun(this.adapter.run({+ home: this.home,+ prompt: this.turnPrompt(null, delta),+ env: this.engineEnv(),+ model: this.engineModel(),+ fastModel: this.engineFastModel(),+ resumeSessionId,+ onLog: (line) => this.logEngineLine(line),+ onHopUsage: (r) => this.onEngineHop(r, 'agent-turn'),+ signal: this.teardown.signal,+ }))+ if (result.sessionId) this.setSessionId(result.sessionId)+ }} else {// One-shot path: Cursor/OpenCode, Codex fallback, or a custom args override.result = await this.trackEngineRun(this.adapter.run({diff --git a/server/src/agents/computer/engine.ts b/server/src/agents/computer/engine.tsindex edb8cff..30e6a63 100644--- a/server/src/agents/computer/engine.ts+++ b/server/src/agents/computer/engine.ts@@ -1682,6 +1682,17 @@ export function noteCodexConfigRejection(err: string | undefined, onLog?: (line:return true}+/** The `-c` sandbox profile without the `exec`-only tail, so the persistent+ * app-server path is confined by exactly the same profile as the one-shot path.+ * This is the set production has since run clean: zero config rejections across+ * every turn on 0.11.1 daemons. */+function codexSecureConfigOverrides(args: { home: string; env: NodeJS.ProcessEnv }, readOnly = false): string[] {+ const full = codexSecureExecArgs(args, readOnly)+ const exec = full.indexOf('exec')+ // Everything before `-a never exec …` is the config profile.+ return exec === -1 ? full : full.slice(0, Math.max(0, exec - 2))+}+function codexSecureExecArgs(args: { home: string; env: NodeJS.ProcessEnv }, readOnly = false): string[] {const workspaceAccess = readOnly ? 'read' : 'write'const filesystemEntries = [@@ -2184,10 +2195,20 @@ class CodexAdapter implements EngineAdapter {// Escape hatches → fall back to one-shot `codex exec` (run()): a custom-args// override, an explicit opt-out, or Windows (JSON-RPC over a .cmd shell is// fragile; exec is the safe path there).- // app-server currently has no equivalent to exec --ignore-user-config, so- // user MCP/hook/config layers cannot be excluded. Keep the secure default- // on the one-shot path; persistent compatibility is an explicit opt-in.- if (!allowUnsandboxedByoa()) return null+ //+ // This used to `return null` unless BYOA was explicitly unsandboxed, because+ // app-server has no equivalent to `exec --ignore-user-config`. The cost of+ // that was invisible in the code: with no persistent process every codex+ // turn is a fresh session, so agents answered each message with no memory of+ // the one before — what users reported as the agent not remembering the+ // previous exchange.+ //+ // `-c` are global flags and DO apply to app-server, so the filesystem,+ // network, environment and feature profile below is identical on both paths.+ // What app-server cannot exclude is a user's own ~/.codex adding EXTRA+ // mcp_servers — a narrower gap than losing every agent's continuity, on the+ // operator's own machine, with their own config. CUMORA_CODEX_NO_APP_SERVER=1+ // still opts out, and a failing session degrades to one-shot (see daemon.ts).if (unsafeEngineArgs('CUMORA_CODEX_ARGS').length) return nullif (process.env.CUMORA_CODEX_NO_APP_SERVER === '1') return nullif (IS_WIN) return null@@ -2196,7 +2217,13 @@ class CodexAdapter implements EngineAdapter {// Standing prompt rides the thread's developerInstructions (see CodexSession),// approval/sandbox are set per-thread, so no global bypass flags are needed.const { command, argsPrefix } = resolveCodexSpawn()- return new CodexSession(command, [...argsPrefix, 'app-server', '--listen', 'stdio://'], args.home, args.env, args)+ // Confine the persistent process with the same profile the one-shot path+ // uses. `-c` are global flags and apply to app-server too, so filesystem,+ // network, environment and features are identical on both paths.+ const secure = allowUnsandboxedByoa()+ ? []+ : codexSecureConfigOverrides({ home: args.home, env: args.env })+ return new CodexSession(command, [...argsPrefix, ...secure, 'app-server', '--listen', 'stdio://'], args.home, args.env, args)}}