Repository navigation
perf(paths): link-free paths resolve with one openat2, one /proc proof per process, fewer resolutions - #5372
Conversation
…ng hot resolves Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
portable_relpaths resolves through resolve_path only when the kernel form is active (Linux); elsewhere it calls Path.resolve() directly, as before. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ed_path_entry; skip resolving skill roots that hold no kept copy - record() passes the file and project root it resolved into deployed_path_entry (same call); the arch guard's pinned literal is updated in place. - report_stale_kept_copies resolves an inactive skill root only when the root holds the skill it would report, instead of every root per skill. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…RESOLVE_NO_SYMLINKS) On Linux 5.6+, one openat2(O_PATH, RESOLVE_NO_SYMLINKS) proves no component of a normalized absolute path is a link, so the path is its own realpath: one open and one close, no /proc name lookup. A link anywhere (ELOOP), an unsupported kernel or seccomp, or any other error keeps the /proc form, then Path.resolve(). Nothing is cached. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… and fallback cells Folds W3d O1-O6: absolute, normalized, NUL-free text only; close in finally; differential cells for links (intermediate, final, dangling, /proc magic), missing tail, ENOTDIR, EACCES, '//', NUL and a non-UTF-8 name, and a forced ENOSYS that turns the form off. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Forked children can inherit a locked mutex and hang indefinitely, while openat2 paths also cause regression tests to fail before verifying the intended behavior.
4 open issues
What changed in this PR
This PR continues #4939’s install-performance work by reducing Linux path-resolution overhead and repeated filesystem resolutions across deployment and validation.
Changes:
- Add an
openat2shortcut for link-free paths and a once-per-process/procidentity proof. - Reuse resolved roots and candidates, and route more hot callers through the shared resolver.
- Add resolver and fork regression coverage, update the receipt architecture guard, and document the performance change.
| File | Description |
|---|---|
tests/unit/utils/test_realpath.py |
Add fast-path, fallback, and containment cases. |
tests/integration/test_realpath_fork.py |
Check proof-state reset after fork. |
tests/integration/test_architecture_materialization_receipts.py |
Update the expected receipt-owner call. |
src/apm_cli/utils/realpath.py |
Implement openat2 resolution and per-process proof state. |
src/apm_cli/utils/paths.py |
Select kernel resolution for batched relative paths. |
src/apm_cli/models/validation.py |
Resolve the skill-bundle root once per validation loop. |
src/apm_cli/integration/skill_preflight.py |
Use the shared resolver for package roots. |
src/apm_cli/integration/skill_adoption.py |
Avoid resolving inactive roots without matching skills. |
src/apm_cli/integration/instruction_integrator.py |
Use the shared resolver for plan identities. |
src/apm_cli/integration/base_integrator.py |
Route deployment and local-package checks through the resolver. |
src/apm_cli/install/deployed_paths.py |
Accept resolved inputs and optimize skill-path resolution. |
src/apm_cli/core/deployment_ledger.py |
Pass same-call resolved inputs into compatibility-path generation. |
scripts/architecture_linter/checks/install_base_integrator_and_contraction.py |
Update the pinned receipt-routing expression. |
changelog.d/5372.changed.md |
Describe the install-performance improvement. |
Review effort: Balanced
apm-spec-waiver: internal path-resolution performance change; resolution results are identical to Path.resolve and no OpenAPM-observable behaviour changes Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…proc form Folds Copilot review on #5372: - the at-fork reset recreates _proof_lock (a thread holding it at fork() does not exist in the child); cell forks while the lock is held - portable_relpaths keeps the instance's resolve() off Linux - the receipts root-count cell also counts the openat2 form; the refusal and fork cells take a linked path or turn openat2 off so the /proc proof itself runs apm-spec-waiver: internal path-resolution performance change with identical results; no OpenAPM-observable behaviour changes Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
# Conflicts: # src/apm_cli/utils/paths.py # src/apm_cli/utils/realpath.py
There was a problem hiding this comment.
🟡 Changes recommended
An integration test still mocks the replaced containment helper and now fails, while an optimization test can also fail on systems where openat2 is unavailable.
2 open issues
5 resolved since last review
Review effort: Balanced
…utside links The skill-bundle cell now patches ensure_path_within_resolved (the helper _validate_skill_bundle calls), and two unpatched cells prove a SKILL.md symlink and a skills/<name> dir symlink to outside still fail validation. The openat2 readlink-count cell skips when openat2 cannot prove a plain path link-free (seccomp or kernel). Refs #4939 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Security-owner validation is needed because containment and receipt authorization now rely on a process-wide /proc identity proof whose validity across mount/chroot changes and foreign or detached mounts is not established by the supplied tests.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
portable_relpaths takes main's form unchanged (fast forms on Linux and Windows, each path's own resolve elsewhere). The receipts root-count oracle counts the openat2 fsencode and the Windows final-path call.
… (with #5372) #5372's openat2 proves a Linux path link-free in one syscall, so Linux now keeps no proofs either (no faster with them, and their lstats moved the update count budget). K stays default-on on macOS and other POSIX. portable_relpaths keeps resolve_path, which defers to a subclass's own resolve(). K cells force the no-kernel branch with #5372's refused state; the platform cell checks Linux and Windows keep no proofs without patching. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>


Description
Path resolution is still about a third of
apm installCPU on Linux after #5333 and #5354: about 32,000 resolutions on a 50-package install, at about 70 us each through the/prockernel form (caller-attributed count, run 45436809952). This PR cuts both the per-call cost and the number of calls. Every resolution still observes the filesystem when it is made; nothing is cached across calls except two per-process capability flags.openat2(O_PATH, RESOLVE_NO_SYMLINKS)refuses any symlink in the walk. When it opens a normalized absolute path (no empty,.or..parts, no NUL, no leading//), no component is a link, so the path is its own realpath. There is no/procname lookup. A missing tail (ENOENT/ENOTDIR) is equally exact. A link anywhere (ELOOP) or any other error keeps the/procform, thenPath.resolve().ENOSYS/EPERM/EINVAL/E2BIG(old kernel, seccomp) turn the form off for the process./procproof per process. The/procform proves once per process, under a lock, that/proc/self/fdnames reach the object the fd holds (fstat/statidentity), instead of on every call. A failed proof turns the form off for the process, and a forked child proves again.record()passes the file and project root it already resolved intodeployed_path_entry, in the same call. The architecture guard's pinned literal is updated in place.report_stale_kept_copiesresolves an inactive skill root only when that root holds the skill it would report.skills/once per loop..resolve()sites go throughresolve_path, andportable_relpathstakes the kernel form where it applies (Linux).Security design: W3d OK on each form:
Issue and approved scope
Issue: Refs #4939
Human scope-approval comment: the fresh-install speed lane was ordered by the CEO (2026-11-23 22:21). Maintainer approval of the scope is pending before merge.
Does this PR complete the issue, or what remains? One slice of #4939; further levers follow from the next profile.
Type of change
Testing
Local runs were suspended (shared-host load), so validation is on CI. Ruff check and format (0.15.12) are clean locally. New cells:
tests/unit/utils/test_realpath.py:Path.resolve(): intermediate, final and dangling links, a/procmagic link, a missing tail,ENOTDIR,EACCES,//, NUL and a non-UTF-8 name;/proclookup, while a linked path takes one;ENOSYSturns the form off;/procproof leaves every later call to pathlib;tests/integration/test_realpath_fork.py: a forked child proves the/procview again.Pre-declared fast check (one run per OS, base = merge-base on main, new = this head, 6 pairs): install-warm and install-cold at tree-50. The gate is paired CPU p50 < 1.0 on Linux cold and <= 1.010 on every other cell, with identical requests and no errors.
Linux result at 9e90a67 vs merge-base c0296fa (45446064609): install-cold 6.07 -> 5.23 s (0.876), install-warm 0.883, requests identical, 0 errors. That is about the ceiling of this path-resolution lane on Linux; the remaining resolutions are inside write loops that keep per-file checks. Windows (45446072173) and macOS (45446081238) are no-regression cells. Since that head there is only an empty commit carrying the spec waiver.
Counted filesystem calls on the lifecycle smoke journeys at this head (Lifecycle Smoke shard 3, job 138639372239), against main after #5354 (1,648 realpath and about 20k lstat on install-cold):
Changelog
changelog.d/<pr>.<section>.md, holdingone line: user-visible effect first, 25 words or fewer, ending with
(#PR); breaking changes only under upgrade notes; no Highlights; nonew lines under
## [Unreleased]. Seechangelog.d/README.mdand.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regenerated