From e3f71936c877b514a502939c8d2c1547c73b335e Mon Sep 17 00:00:00 2001 From: Marco D'Alia Date: Sat, 27 Jun 2026 16:30:54 +0100 Subject: [PATCH] fix(codex): drop heavy host-only artifacts from codex config staging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The host `~/.codex` is ~1.1 GB and was being synced into boxes almost whole: ~485 MB of macOS aarch64 standalone release binaries (`packages/`), a ~238 MB plugin app-server runtime (`plugins/.plugin-appserver`), the macOS `Codex Computer Use.app` bundle (`computer-use/`), host session archives, and regenerable caches (`.tmp` ~213 MB, `tmp`, `cache`, `vendor_imports`, `sqlite`, `models_cache.json`). None of it is usable in a Linux box — the in-box codex is npm-installed and rebuilds these caches on demand. Exclude all of it from both codex staging paths: - `CODEX_RSYNC_EXCLUDES` (host-stage.ts) — the cloud bake path (hetzner/vercel/ e2b/daytona `stageCodexStaticForUpload`). Dry-run: staged tarball 820 MB -> 482 KB. - the docker `agentbox-codex-config` volume rsync (codex.ts), plus its `rm -rf` purge so existing shared volumes get cleaned on the next sync. Verified live: a fresh docker box's `~/.codex` dropped 1.5 GB -> 59 MB and `codex exec` still returns a real turn. Config / auth / skills / prompts / rules / memories / plugins are still synced, so codex keeps working — just without the host-only ballast. Claude-Session: https://claude.ai/code/session_019m5WHxP4vmsoXaHUhQdY9e --- packages/sandbox-docker/src/codex.ts | 16 +++++++++++++++- packages/sandbox-docker/src/host-stage.ts | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/sandbox-docker/src/codex.ts b/packages/sandbox-docker/src/codex.ts index a45130e4..7d240693 100644 --- a/packages/sandbox-docker/src/codex.ts +++ b/packages/sandbox-docker/src/codex.ts @@ -221,18 +221,32 @@ export async function ensureCodexVolume( // resumes at /workspace (Codex reads the cwd from state_*.sqlite's threads // index, which it backfills from the box's rollouts) and the host's // cross-project Codex history doesn't leak into the box. - // The trailing `rm -rf` purges any state DBs a PREVIOUS sync (before these + // The trailing `rm -rf` purges anything a PREVIOUS sync (before these // excludes) already copied into the shared volume — rsync without // --delete only adds/updates. The globs are no-ops with `-f` when absent, // and never touch box-owned `sessions/` (the teleported rollouts) or // `hooks.json`. + // Heavy host-only artifacts are also excluded (mirrors CODEX_RSYNC_EXCLUDES + // in host-stage.ts): `packages` (macOS standalone release binaries — the + // in-box codex is npm-installed), `plugins/.plugin-appserver` (the + // platform-specific plugin app-server runtime), `computer-use` (the macOS + // `Codex Computer Use.app` bundle), `archived_sessions` (host history), and + // the regenerable caches (`.tmp`, `tmp`, `cache`, `vendor_imports`, + // `sqlite`, `models_cache.json`). Without these the shared volume balloons + // to ~1.5 GB and every create's rsync crawls. 'rsync -a --exclude=sessions --exclude=log --exclude=history.jsonl --exclude=hooks.json' + skillsExclude + ' --exclude=state_*.sqlite* --exclude=logs_*.sqlite* --exclude=session_index.jsonl' + ' --exclude=external_agent_session_imports.json --exclude=shell_snapshots' + + ' --exclude=packages --exclude=plugins/.plugin-appserver --exclude=computer-use' + + ' --exclude=archived_sessions --exclude=.tmp --exclude=tmp --exclude=cache' + + ' --exclude=vendor_imports --exclude=sqlite --exclude=models_cache.json' + ' /src/ /dst/' + ' && rm -rf /dst/state_*.sqlite* /dst/logs_*.sqlite* /dst/session_index.jsonl' + ' /dst/external_agent_session_imports.json /dst/shell_snapshots' + + ' /dst/packages /dst/plugins/.plugin-appserver /dst/computer-use' + + ' /dst/archived_sessions /dst/.tmp /dst/tmp /dst/cache' + + ' /dst/vendor_imports /dst/sqlite /dst/models_cache.json' + skillsPurge + ' && chown -R 1000:1000 /dst', ]); diff --git a/packages/sandbox-docker/src/host-stage.ts b/packages/sandbox-docker/src/host-stage.ts index 515e10e6..7e63ce88 100644 --- a/packages/sandbox-docker/src/host-stage.ts +++ b/packages/sandbox-docker/src/host-stage.ts @@ -471,6 +471,20 @@ const CODEX_RSYNC_EXCLUDES = [ '--exclude=models_cache.json', '--exclude=installation_id', '--exclude=version.json', + // Heavy host-only artifacts that are useless inside a Linux box and balloon + // the staged tarball (~800 MB on a real host) — without these the codex + // static scp/extract during prepare crawls. `packages/standalone` is the + // macOS aarch64 standalone release binaries (the in-box codex is npm-installed + // anyway); `plugins/.plugin-appserver` is the platform-specific plugin + // app-server runtime; `computer-use` is the macOS `Codex Computer Use.app` + // bundle. `archived_sessions` is host session history, not config (mirrors the + // `sessions` exclude). (`plugins/cache`, the marketplace download cache, is + // already dropped by the generic `--exclude=cache` above.) This shrinks the + // staged codex tarball from ~800 MB to ~0.5 MB. + '--exclude=packages', + '--exclude=plugins/.plugin-appserver', + '--exclude=computer-use', + '--exclude=archived_sessions', ]; const CODEX_KEYCHAIN_WARNING =