[BUG] `apm.lock.yaml` and compiled `AGENTS.md` are created with mode 0600, ignoring the umask
Describe the bug
Files that APM creates through atomic_write_text without an explicit new_file_mode end up
-rw------- (0600) instead of following the process umask. This hits files that are meant to be
committed and shared, notably apm.lock.yaml (apm install) and AGENTS.md (apm compile). Every
other file in the same install (apm.yml, deployed skills) is created -rw-r--r-- under umask 022, so
the modes in one project are inconsistent.
Root cause: atomic_write_text
writes to a tempfile.mkstemp file, which is always created 0600, then renames it into place. The
temp file's mode is only changed when the target already existed (its mode is preserved) or when the
caller passes new_file_mode. A brand-new file keeps mkstemp's 0600.
Callers that create shared files without passing a mode include:
deps/lockfile.py#L1324:apm.lock.yamlcompilation/output_writer.py#L94:AGENTS.mdand other compiled outputs
Other atomic_write_text call sites without a mode are probably affected in the same way, though I have
not reproduced each one. They include integration/hook_integrator.py, utils/yaml_io.py,
deps/virtual_file.py and the gemini, intellij and kiro client adapters.
Some callers already work around this by passing new_file_mode=0o644, for example
plugin_parser.py and integration/_shared.py. MCP configuration and similar secret-bearing files are
deliberately 0600, and that should stay.
To Reproduce
Under umask 022 (umask prints 0022):
- Create a minimal local package:
mkdir -p demo-pkg/.apm/skills/demo printf 'name: demo-pkg\nversion: 1.0.0\n' > demo-pkg/apm.yml printf -- '---\nname: demo\ndescription: Demo skill.\n---\n# Demo\n' > demo-pkg/.apm/skills/demo/SKILL.md - Install it into a fresh project:
mkdir p1 && cd p1 apm install --target copilot ../demo-pkg ls -l apm.yml apm.lock.yaml .agents/skills/demo/SKILL.md - Compile an instruction:
mkdir -p .apm/instructions printf -- '---\ndescription: Style\napplyTo: "**"\n---\nBe brief.\n' > .apm/instructions/style.instructions.md apm compile --target codex ls -l AGENTS.md
Expected behavior
New shared files follow the umask like every other file APM writes: -rw-r--r-- under umask 022.
Existing files keep their current mode, as they do today, and secret-bearing files stay 0600 explicitly.
A possible fix: when the target does not exist and the caller passes no new_file_mode, default the
mode to 0o666 & ~umask (the umask can be read with os.umask(0); os.umask(old) once at import or under
a lock). Callers that need 0600 keep passing it explicitly. Add a test that creates a new file through
atomic_write_text under a known umask and asserts the resulting mode.
Environment (please complete the following information):
- OS: macOS 26.7.1 (arm64)
- Python Version: the standalone release binary (
apm-darwin-arm64) - APM Version: 0.35.0 (17a2fc4), the latest release; also reproduced on 0.33.0 (18c4c43). The affected code is unchanged on
main(2920043) - VSCode Version (if relevant): n/a
Logs
$ ls -l apm.yml apm.lock.yaml .agents/skills/demo/SKILL.md
-rw-r--r-- .agents/skills/demo/SKILL.md
-rw------- apm.lock.yaml
-rw-r--r-- apm.yml
$ apm compile --target codex
...
[+] Compilation completed successfully!
$ ls -l AGENTS.md .apm/instructions/style.instructions.md
-rw-r--r-- .apm/instructions/style.instructions.md
-rw------- AGENTS.md
Additional context
The 0600 mode matters in two situations:
- Shared checkouts and CI containers where the build steps run under a different UID than the step
that wrote the files: the lockfile and
AGENTS.mdbecome unreadable to them. - Tools that wrap
apm, which have to re-chmod files after every run to keep the modes consistent.
Happy to send a PR for this once the scope is approved: default new files to 0o666 & ~umask when no new_file_mode is passed, keep explicit 0600 for secret-bearing files, and add a regression test under a fixed umask.
Decision: approve Area: project Scope: Create shared, committed APM artifacts (apm.lock.yaml and apm compile outputs such as AGENTS.md) with umask-derived permissions instead of mkstemp's 0600 by passing an explicit new-file mode at those call sites, matching existing shared-artifact writers that pass 0o644, while keeping explicit 0600 for secret-bearing files and preserving existing files' modes. Done when: A regression under a fixed umask 022 shows newly created apm.lock.yaml and compiled AGENTS.md are 0644 like apm.yml and deployed skills, existing files keep their mode, MCP and client configs and receipts stay 0600, and Windows behavior is unchanged. Out of scope: Changing the atomic_write_text default for every caller; auditing all other call sites; chmod of already existing files. Review contact: @danielmeppiel
The apm-scope:v1 record above was approved by @danielmeppiel at Gate B on 2026-11-10 in the coordinator session of the issue-reduction program. It is the scope a fix for this issue will be reviewed against.
Review contact: @danielmeppiel.
Generated by autopilot-issue-triage-worker. This comment is AI-generated and may contain errors.