Skip to content

fix(sync): force host static-config stages user-writable (read-only source → EACCES)#177

Merged
madarco merged 1 commit into
madarco:nightlyfrom
afterthought:fix/stage-writable-chmod
Jul 8, 2026
Merged

fix(sync): force host static-config stages user-writable (read-only source → EACCES)#177
madarco merged 1 commit into
madarco:nightlyfrom
afterthought:fix/stage-writable-chmod

Conversation

@afterthought

Copy link
Copy Markdown
Contributor

Problem

agentbox prepare (and the docker/cloud seeds) fail for anyone whose agent config is managed declaratively — Nix/home-manager, Ansible, chezmoi, or just root-owned/read-only dotfiles:

prepare failed: EACCES: permission denied, unlink
  '/var/folders/.../agentbox-claude-static-stage-wV1H1q/skills/1password/SKILL.md'

Root cause

The static-config stages (stage{Claude,Codex,Agents,Opencode}StaticForUpload in packages/sandbox-core/src/sync/host-stage.ts) rsync ~/.claude, ~/.codex, ~/.agents, and ~/.local/share/opencode into a throwaway scratch dir, then rewrite it in place (filter settings.json, sanitize config.toml, rewrite plugin paths) and finally rm it.

Every one of those rsyncs runs rsync -a, which implies -p and preserves the source's modes. When the source is read-only — skill/plugin symlinks into the Nix store (0444/0555), or any root-owned / 0444 dotfile — the scratch copy is read-only too. That breaks the stage two ways:

  1. the in-place writeFile rewrites fail with EACCES; and
  2. cleanup's rm can't unlink a child of a 0555 directory → the unlink .../skills/*/SKILL.md above.

A normal writable ~/.claude never hits it, which is why it only bites declaratively-managed hosts.

Fix

A scratch dir has no business inheriting the source's perms. Add --chmod=Du+rwx,Fu+rw (via a shared, documented STAGE_WRITABLE_CHMOD constant) to each of the 5 stage rsyncs. GNU rsync honors it; macOS's openrsync ignores it and doesn't hit the read-only-source case in practice, so it's a safe no-op there.

Scoped to the static-config stages only — the workspace export rsync is untouched, so its -i itemized output (parsed by parseItemizedChanges) is unchanged.

Reproduce

On a host where ~/.claude/skills/* are read-only symlinks into a read-only store (e.g. home-manager), or synthetically:

mkdir -p /tmp/ro/skills/x && echo hi > /tmp/ro/skills/x/SKILL.md
chmod -R a-w /tmp/ro/skills
rsync -a /tmp/ro/ /tmp/stage/ && rm -rf /tmp/stage   # EACCES on the rm
rsync -a --chmod=Du+rwx,Fu+rw /tmp/ro/ /tmp/stage2/ && rm -rf /tmp/stage2   # clean

🤖 Generated with Claude Code

The static-config stages (`stage{Claude,Codex,Agents,Opencode}StaticForUpload`)
rsync the host's ~/.claude, ~/.codex, ~/.agents, and ~/.local/share/opencode
into a throwaway scratch dir, then rewrite it in place (filter settings.json,
sanitize config.toml, rewrite plugin paths) and finally `rm` it.

Every one of those rsyncs runs `rsync -a`, which implies `-p` and preserves the
*source's* modes. When the source is read-only — skill/plugin symlinks into the
Nix store (0444/0555), or any root-owned / mode-0444 dotfiles — the scratch copy
comes out read-only too. That breaks the stage two ways:

  - the in-place `writeFile` rewrites fail with EACCES, and
  - cleanup's `rm` can't unlink children of a 0555 dir:
    `EACCES: permission denied, unlink '.../skills/1password/SKILL.md'`

which aborts `agentbox prepare` (and the docker/cloud seeds) for anyone whose
agent config is managed declaratively (Nix/home-manager, Ansible, chezmoi, ...).

A scratch dir has no business inheriting the source's perms, so add
`--chmod=Du+rwx,Fu+rw` to each stage rsync. GNU rsync honors it; macOS's
openrsync ignores it and doesn't hit the read-only-source case in practice, so
it's a safe no-op there.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
agentbox-web Skipped Skipped Jul 8, 2026 4:36pm

Request Review

@madarco

madarco commented Jul 8, 2026

Copy link
Copy Markdown
Owner

thanks for the PR

@madarco madarco changed the base branch from main to nightly July 8, 2026 20:45
@madarco madarco merged commit 384a692 into madarco:nightly Jul 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants