bd94cc9bbf
The previous commit moved the pi-agent repo mount from /workspace to
/home/user/{repo_name}. This exposed a permission bug: the Dockerfile
creates /workspace as a root-owned symlink in the image, and the
non-root entrypoint could not replace it because / is owned by root.
- Update compile_entrypoint to recreate /workspace via sudo when running
as the container user, or directly when running as root
- Add unit test covering sudo/root symlink creation
- Update OpenSpec change docs with the additional root cause
Quality gates:
- pytest tests/unit: 208 passed
- ruff: clean on changed files
- mypy: clean on changed files
- alembic heads: single head
2.8 KiB
2.8 KiB
Fix pi container repo mount and npm update permissions
Problem
After implementing configurable tool container home directories, new pi-agent containers still bind-mount the git repository at /workspace instead of under /home/user/{repo_name}. In addition, users cannot run npm update -g @earendil-works/pi-coding-agent inside the container because the global npm prefix (/usr/lib/node_modules) is owned by root.
Root cause
- The built-in
pi-agentmanifest intool_definition_manifestsstill declares an explicit repo mount with"target": "/workspace"and"working_dir": "/workspace". This masks the generated/workspace → /home/user/{repo}compatibility symlink. manifest_compiler.pydoes not substitute the instance-specific{{WORKSPACE_NAME}}placeholder in explicit mount targets, andinstance_service.pydoes not passWORKSPACE_NAME/REPO_NAMEtocompile_composefor manifest-based tools.- The generated entrypoint hardcodes the literal string
{{WORKSPACE_NAME}}as the symlink target. npm_globalpackages are installed withRUN npm install -g ...as root into the system npm prefix, so the non-root container user cannot update them.- Once the repo mount moves out of
/workspace, the generated/workspacecompatibility symlink is created in the image as root. The non-root entrypoint cannot replace it (write permission is required on/), so container startup fails.
Fix
- Add an Alembic data migration that updates the built-in
pi-agentmanifest:- Change the repo mount target to
~/{{WORKSPACE_NAME}}. - Keep
runtime.working_diras/workspace(the compatibility symlink). - Update the startup script to chown the real mount path (
$HOME/$WORKSPACE_NAME).
- Change the repo mount target to
- Update
manifest_compiler.py:- Substitute
{{WORKSPACE_NAME}}in mount targets incompile_compose. - Pass
WORKSPACE_NAMEas a container environment variable. - Generate the entrypoint symlink from the runtime
WORKSPACE_NAMEenvironment variable. - Install
npm_globalpackages into a user-writable prefix ({home_dir}/.npm-global) and add it toPATH. - Use
sudoor root to create the/workspacecompatibility symlink, because/is owned by root and the non-root entrypoint cannot replace a root-owned symlink.
- Substitute
- Update
instance_service.pyto passREPO_NAMEandWORKSPACE_NAMEinto manifest compilation. - Update unit tests for the new behavior.
Affected files
apps/api/alembic/versions/<new>_fix_pi_agent_home_directory_mount.pyapps/api/src/services/build/manifest_compiler.pyapps/api/src/services/tool/instance_service.pyapps/api/tests/unit/test_manifest_compiler.py
Verification
pytest apps/api/tests/unit/test_manifest_compiler.pypytest apps/api/tests/unit/test_alembic_migrations.pyruff,mypy,npm run typecheck,npm run lint