Skip to content

fix(copilot): make the state folder usable without a per-repo step (copilot 0.5.0, copilot-home-writable) - #285

Merged
nabil-becker merged 2 commits into
mainfrom
fix/copilot-home-writable/1
Dec 2, 2026
Merged

nabil-becker merged 2 commits into
mainfrom
fix/copilot-home-writable/1

Conversation

@nabil-becker

@nabil-becker nabil-becker commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

What

The copilot Feature (0.4.1 → 0.5.0) makes Copilot's state folder usable on its own, so a consuming repo needs no hand-written ~/.copilot step. A new copilot-home (in src/copilot/copilot-home.sh) makes the folder exist, belong to the remote user and be mode 700. Three things run it:

  • copilot-setup, the post-create hook (also task copilot:setup);
  • a new login-shell snippet, /etc/profile.d/copilot-home.sh;
  • and install.sh pre-creates the folder for the build's remote user.

Why

copilot failed on first run in a toolshed built by Envbuilder (the-boardroom, user uid 1000):

Failed to initialize session: Error: session construction failed: failed to register ownership for session '<id>': Permission denied (os error 13)

containerEnv points COPILOT_HOME at /var/lib/devcontainer-features/copilot. Envbuilder honours containerEnv but ignores Feature mounts and runs no Feature hook (ADR 0095). So that path was missing, its parent was root's, and copilot-setup never ran. The error reproduces with no login: COPILOT_HOME=<missing root-owned path> copilot -p hi prints Failed to initialize session: Error: Permission denied (os error 13). With a usable folder, the same command gets past it to No authentication information found. The new scenario uses this to test the real failure.

Where the state goes now

Case COPILOT_HOME Done by copilot-home
A repo sets its own COPILOT_HOME (peitho does) that path created, the user's, 700
Feature path mounted (devcontainer CLI: the volume, or a bind mount) the Feature path chown -R to the user (root or sudo), 700. ~/.copilot is linked to it; a real ~/.copilot is copied in without overwriting and kept as ~/.copilot.before-copilot-feature
Not mounted (Envbuilder), root or passwordless sudo the Feature path, now a link to ~/.copilot ~/.copilot is made 700 and gets what the image folder held. The image folder is replaced by the link, so every process that reads containerEnv agrees
Not mounted, no root ~/.copilot in login shells copilot-setup prints one line: set "COPILOT_HOME": "<home>/.copilot" in remoteEnv, or mount a volume
Mounted but someone else's, no root ~/.copilot in login shells one line on stderr with the exact sudo chown -R <user> … && sudo chmod 700 …
  • User resolution: the caller, or, when run as root, the remote user that install.sh recorded from _REMOTE_USER/_CONTAINER_USER, else uid 1000.
  • Run as root: copilot-setup prepares the folder for that user, then re-runs itself as that user (runuser, else su), so nothing is left root-owned.
  • Safety: idempotent and never fatal. It never prints a token. It deletes the image folder only when it is not a mount, and only after its contents have been copied.

Validation

Command Result
bash test/copilot/unit/home_test.sh (new, Docker-free, also in task test:copilot-unit) 37 passed, 0 failed
devcontainer features test -f copilot --filter home_as_user --skip-autogenerated --skip-duplicated . (new scenario, remote user vscode: uid 1000 in the image, remapped to the runner's uid in CI) 21/21 checks passed
task test FEATURE=copilot (autogenerated test plus every scenario, in the devhost's docker-in-docker) passed: all 8 scenarios (copilot autogenerated, official_listed, with_gh, participants, participants_only_copilot, attach, no_taskfile, home_as_user), 0 failed checks; the dind was pruned afterwards
task lint CI lint passed. Locally, four suites that this change does not touch (test:ssh-agent-unit, test:cloud-folder-unit, test:claude-unit, test:facilitator-unit) fail the same way on untouched origin/main in the devhost: an environment issue, tracked in the backlog
task docs only src/copilot/README.md changed

The home_as_user scenario checks, as the non-root vscode (CI run 46890731292 passed it, after 131396a dropped a fixed-uid check that failed on GitHub's uid-1001 runners):

  • the folder exists, is vscode's, mode 700 and writable;
  • copilot --version runs;
  • a first copilot -p gets past the folder, and the old error still shows on an unusable path (so the check can fail);
  • copilot-setup run as root leaves nothing root-owned;
  • a folder handed to root is handed back;
  • the two Envbuilder cases, played with an unmounted image folder: one with sudo (the link), one as a user with no sudo (the login shell gets ~/.copilot, and copilot runs).

Envbuilder: this repo's CI runs only the devcontainer CLI path; there is no Envbuilder job, so Envbuilder is played inside the scenario rather than built. The first real Envbuilder check is a rebuild of the-boardroom on 0.5.0.

Consumers (not touched here)

Consumer Today Needs
the-boardroom copilot:0 No version edit (the major tag floats); a rebuild after the release. Then drop any manual mkdir ~/.copilot. To keep the login across Envbuilder rebuilds without a persistent home, mount a volume at /var/lib/devcontainer-features/copilot in the template
the-stockroom copilot:0 Rebuild after the release; nothing else
peitho copilot:0, sets COPILOT_HOME=/home/metis/.copilot Rebuild; its own path is kept and now created 700 by the Feature
the-workshop the official copilot-cli Feature plus its own post-create step No bump (it does not use this Feature). Switching to copilot:0 would let it drop the ~/.copilot lines of post-create.sh; that is its own change

The release is the Operator's to start: it would publish copilot 0.5.0.

Checklist

  • Every commit is signed off (Signed-off-by:, DCO)
  • version bumped in src/copilot/devcontainer-feature.json (0.5.0; ghcr's highest is 0.4.1) and its ## [0.5.0] entry added to src/copilot/CHANGELOG.md
  • Downloads remain checksum-verified; nothing unverified is piped into a shell (nothing is downloaded)
  • install.sh is idempotent and does not assume a remoteUser (it uses the remote user only when that account exists at build)
  • Tests updated (test/copilot/home_as_user.sh, scenarios.json, test/copilot/unit/home_test.sh) and task test FEATURE=copilot passes (8/8 scenarios)
  • taskfile.yml present and registered via installTaskfile (existing; setup's description updated)
  • task lint passes (CI; the devhost-only failures are in Validation)
  • NOTES.md updated (a new "The state folder" section) and task docs run

devhost agent and others added 2 commits December 2, 2026 13:12
…opilot 0.5.0, copilot-home-writable)

A first copilot run failed with "failed to register ownership for session ...
Permission denied" where the Feature's volume is not mounted (Envbuilder ignores
Feature mounts and hooks), because COPILOT_HOME named a missing, root-owned path.

copilot-home, run by copilot-setup and a new /etc/profile.d snippet, makes the
folder exist, belong to the remote user and be mode 700: the volume when it is
mounted (~/.copilot linked to it), else ~/.copilot with the Feature path linked
to it when root or sudo is there, else COPILOT_HOME=~/.copilot in login shells
plus a one-line hint. install.sh pre-creates the folder for the build's remote
user; a root-run copilot-setup leaves nothing root-owned. New unit suite
(home_test.sh) and scenario home_as_user (uid 1000).

Co-Authored-By: Claude Opus 5.5 <claude-opus-5-5@noreply.invalid>
Signed-off-by: devhost agent <devhost-agent@noreply.invalid>
…me-writable)

The devcontainer CLI remaps vscode to the runner's uid (1001 on GitHub), so the
fixed uid failed the home_as_user scenario in CI and stopped its other checks.

Co-Authored-By: Claude Opus 5.5 <claude-opus-5-5@noreply.invalid>
Signed-off-by: devhost agent <devhost-agent@noreply.invalid>
@nabil-becker
nabil-becker marked this pull request as ready for review December 2, 2026 13:37
@nabil-becker
nabil-becker merged commit ce6dd61 into main Dec 2, 2026
10 checks passed
@nabil-becker
nabil-becker deleted the fix/copilot-home-writable/1 branch December 2, 2026 13:52
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.

1 participant