Skip to content

perf(paths): link-free paths resolve with one openat2, one /proc proof per process, fewer resolutions - #5372

Merged
Daniel Meppiel (danielmeppiel) merged 16 commits into
mainfrom
danielmeppiel-perf-vdt
Nov 24, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 16 commits into
mainfrom
danielmeppiel-perf-vdt

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Path resolution is still about a third of apm install CPU on Linux after #5333 and #5354: about 32,000 resolutions on a 50-package install, at about 70 us each through the /proc kernel 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.

  • Link-free paths cost one open and one close (Linux 5.6+). 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 /proc name lookup. A missing tail (ENOENT/ENOTDIR) is equally exact. A link anywhere (ELOOP) or any other error keeps the /proc form, then Path.resolve(). ENOSYS/EPERM/EINVAL/E2BIG (old kernel, seccomp) turn the form off for the process.
  • One /proc proof per process. The /proc form proves once per process, under a lock, that /proc/self/fd names reach the object the fd holds (fstat/stat identity), instead of on every call. A failed proof turns the form off for the process, and a forked child proves again.
  • Fewer calls:
    • record() passes the file and project root it already resolved into deployed_path_entry, in the same call. The architecture guard's pinned literal is updated in place.
    • report_stale_kept_copies resolves an inactive skill root only when that root holds the skill it would report.
    • Skill-bundle validation resolves skills/ once per loop.
    • Hot direct .resolve() sites go through resolve_path, and portable_relpaths takes the kernel form where it applies (Linux).
  • Supersedes perf(paths): prove the /proc view once per process and resolve fewer paths #5346, which is folded in here.

Security design: W3d OK on each form:

  • openat2: row w3d:ruling:openat2, conditions O1-O7;
  • the per-process proof and the skill-bundle loop: w3d:5346:70252829;
  • the record and skill-root counts: P1 pre-read B1-B4.

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

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

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:
    • openat2 shapes against Path.resolve(): intermediate, final and dangling links, a /proc magic link, a missing tail, ENOTDIR, EACCES, //, NUL and a non-UTF-8 name;
    • a link-free path and a missing tail take no /proc lookup, while a linked path takes one;
    • a forced ENOSYS turns the form off;
    • a failed /proc proof leaves every later call to pathlib;
    • a skill linked out of the bundle is still refused.
  • tests/integration/test_realpath_fork.py: a forked child proves the /proc view again.
  • The existing differential, loop, FIFO and containment cells, and the receipts root-count cell, stay green.

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):

journey fs.realpath_calls fs.lstat_calls
install-cold 664 6,752
install-warm 679 7,504

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour.

…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>
@danielmeppiel Daniel Meppiel (danielmeppiel) added performance Legacy classification name; prefer type/performance. Retained for history. full-integration Run the full integration suite (ci-integration.yml) on this PR before merge labels Nov 24, 2026
Copilot AI balanced review requested due to automatic review settings November 24, 2026 17:12
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 openat2 shortcut for link-free paths and a once-per-process /proc identity 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

Comment thread src/apm_cli/utils/realpath.py Resolved
Comment thread src/apm_cli/utils/realpath.py Resolved
Comment thread tests/integration/test_realpath_fork.py Resolved
Comment thread src/apm_cli/utils/paths.py Resolved
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The inherited proof lock can permanently deadlock forked children, while fallback path-resolution regressions and openat2-related test failures remain unresolved.

5 open issues

Review effort: Balanced

Comment thread tests/unit/utils/test_realpath.py Resolved
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 24, 2026
Gated to Windows: on macOS the swap measured slower (#5354 bisect); Linux
is covered by #5372. Adds a Windows call-count cell and states in the R6
rule doc that no APM subprocess mutates registered packages (W3d N3).

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread src/apm_cli/models/validation.py Resolved
Comment thread tests/unit/utils/test_realpath.py Resolved
…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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 3df7aae into main Nov 24, 2026
70 checks passed
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 24, 2026
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-perf-vdt branch November 24, 2026 23:00
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 24, 2026
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.
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 25, 2026
… (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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-integration Run the full integration suite (ci-integration.yml) on this PR before merge performance Legacy classification name; prefer type/performance. Retained for history.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants