Skip to content

perf(install): let GitLab and Azure DevOps projects replay a verified no-op - #5331

Merged
Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-perf-verdict-gitlab-ado
Nov 24, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-perf-verdict-gitlab-ado

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

#4993's verified-state record replays a repeat no-op apm install only when it can prove the run's inputs. For a project whose git remote is on GitLab or Azure DevOps, it never recorded: there was no exact proof that policy discovery would return without a fetch. Those users always took the full pipeline on repeat no-ops (about 1.1 to 1.4 s at tree-10, instead of about 0.25 s).

This PR records a GitLab or ADO project's verified no-op only when that run's discovery made no policy fetch attempt:

  • Each policy fetch channel notes its attempt in the new import-light core/policy_fetch_ledger.py. The GitHub contents, GitLab REST and ADO items channels note it before any credential lookup; policy_get notes every HTTP fetch.
  • The record writer compares the count with the run's entry (verdict_inputs.entry_stamp). Any attempt means no record.

Why this is exact: GitLab ancestry and ADO discovery are cache-first. With no attempt, every candidate discovery consulted was a fresh cached entry. The record already keys every policy_v1 file (bytes and mtime) and the remote (git config), and it expires at the earliest cached_at + capped_ttl(cache.ttl). A later run with identical keyed inputs before that expiry therefore also fetches nothing. A pinned GitLab project (policy.hash) always fetches, so it never records. GitHub projects keep #4993's first-candidate rule unchanged.

Issue and approved scope

Issue: Fixes #5075

Human scope-approval comment: confirmed by the regent under rule 23 (perf approved by default); INT posts the apm-scope record on #5075, review contact Daniel Meppiel (@danielmeppiel).

Does this PR complete the issue, or what remains? Completes it.

Type of change

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

Testing

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

New cells in tests/integration/test_verdict_record.py:

  • test_a_gitlab_or_ado_run_whose_policy_came_from_the_cache_records_and_hits[gitlab|ado]: fails on main, because main never recorded these hosts.
  • test_a_gitlab_or_ado_run_that_attempted_a_policy_fetch_never_records[gitlab|ado]: the negative control.

Commands, each run once through host_guard:

  • pytest tests/integration/test_verdict_record.py -n 0 -> 85 passed, 4 skipped (Windows-only).
  • pytest tests/unit/install/test_architecture_invariants.py tests/integration/test_cli_startup_import_budget.py tests/integration/policy/test_remote_reads.py -n 0 -> 7 passed, 5 skipped.
  • ruff 0.15.12 check and format, the architecture linter, the complexity ratchet against origin/main, and tm006: clean.

Performance (PERF VP GODSPEED rule: one final no-regression check at the final head, 9 pairs). Base main 22324e6 vs d32b14c, tree-50, CPU including children, RTT 30. Runs: Linux 45366051813, Windows 45366144596.

OS Journey Base New Paired p50 95% band
Linux install-noop 3.758 s 3.741 s 1.0019 [0.9851, 1.0190]
Linux install-warm 13.296 s 13.378 s 0.9963 [0.9479, 1.0112]
Windows install-noop 5.797 s 5.812 s 1.0000 [0.9683, 1.0859]
Windows install-warm 24.453 s 24.438 s 1.0000 [0.9888, 1.0287]

All 4 cells pass at p50 <= 1.010. The bench fixtures use a GitHub origin, so this gates against regression only; the cells above prove the GitLab/ADO path engages. An earlier 6-pair check at 1fa51f2 read Linux install-warm 1.0231 (band [0.932, 1.044]); the head then moved with source folds, and the VP ruled this one final rerun. The 15-pair 3-OS run for the release note runs after merge.

Review: W3d accepted d32b14c (R1, R2 and R3 met). Copilot took 2 rounds: 3 correctness findings folded with cells, 1 missed speedup declined to the PERF backlog, 1 test-coverage finding covered by the R1/R2 cells.

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: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

… no-op (#5075)

A GitLab or ADO project records its verified no-op only when the run's
policy discovery made no fetch attempt: every candidate it consulted came
from a fresh cached entry, which the record already keys and whose TTL
bounds the record's expiry. Each policy fetch channel notes its attempt
in core/policy_fetch_ledger before any credential lookup or request; the
writer compares the count with the run's entry. GitHub projects keep the
first-candidate rule.

apm-spec-waiver: no-op replay prints the engine's own no-op output and writes no bytes; nothing OpenAPM-observable changes

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 08:54
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

Deleting the policy cache after discovery can still permit recording, removing the policy TTL bound and allowing replay instead of refetching for up to 24 hours.

3 open issues
What changed in this PR

Extends verified no-op install replay to GitLab and Azure DevOps projects by tracking whether policy discovery attempted a fetch, building on the existing authenticated-record mechanism.

Changes:

  • Tracks policy fetch attempts before credential lookup and HTTP requests.
  • Allows GitLab and Azure DevOps records when the fetch count is unchanged during the run.
  • Adds replay eligibility tests, registers the ledger with the architecture owner, and adds a changelog fragment.
File Description
tests/​integration/​test_verdict_record.py Adds GitLab and ADO record/replay eligibility cases.
src/​apm_cli/​policy/​discovery.py Accounts for GitHub and ADO fetch attempts.
src/​apm_cli/​policy/​_policy_http.py Accounts for policy HTTP fetch attempts.
src/​apm_cli/​policy/​_gitlab.py Accounts for GitLab attempts before credential lookup.
src/​apm_cli/​install/​verdict_record.py Captures the initial fetch count alongside run time.
src/​apm_cli/​install/​verdict_policy.py Uses the fetch count to gate GitLab and ADO recording.
src/​apm_cli/​install/​verdict_inputs.py Provides the combined run-entry stamp.
src/​apm_cli/​core/​policy_fetch_ledger.py Adds an import-light, process-wide fetch ledger.
changelog.d/​5331.changed.md Announces the expanded no-op replay support.
.apm/​architecture/​owners/​contracts-tooling.json Registers the ledger in the owner inventory.

Review effort: Balanced

Comment thread src/apm_cli/install/verdict_policy.py Resolved
Comment thread src/apm_cli/install/verdict_policy.py Resolved
Comment thread src/apm_cli/install/verdict_policy.py Resolved
…record (#5075)

The record writer now also requires the policy cache's shape (every file's
path, size and mtime) at write to equal the run's entry, so a cache deleted
or changed between discovery and the write never records. Adds misses only.
Cells: a fetch that fails at the credential lookup or transport is still
counted on every channel (github, gitlab, ado, http); a pinned GitLab project
through real discovery never records; a cache changed after discovery never
records.

apm-spec-waiver: no-op replay prints the engine's own no-op output and writes no bytes; nothing OpenAPM-observable 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

A critical metadata-preserving policy-cache rewrite can authenticate an outdated successful verdict and bypass new restrictions, while snapshot errors can abort installation instead of merely disabling recording.

2 open issues
3 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/install/verdict_inputs.py Resolved
Comment thread src/apm_cli/install/verdict_record.py Resolved
…#5075)

The GitLab/ADO record now binds each policy cache file's content digest
(no-follow) as well as its mtime, so a same-size, mtime-preserving rewrite
after discovery never records. A cache the snapshot cannot read is no
record and never aborts the install (W3d R3). The repository channels
(github contents, ado items) note their attempt in _policy_auth_resolver,
before any credential lookup; discovery.py stays within the file cap.

apm-spec-waiver: no-op replay prints the engine's own no-op output and writes no bytes; nothing OpenAPM-observable changes

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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

A critical check-to-use race can authenticate a deleted policy cache with an old successful verdict and fresh expiry, allowing later installs to replay that verdict instead of fetching the missing policy.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

High severity Cache check-to-use race can authenticate a missing policy

src/​apm_cli/​install/​verdict_policy.py:154

The cache comparison finishes before _write() separately reads the cache in _inputs() and _expiry(), leaving a check-to-use race. If the cache is deleted after this guard, the writer can authenticate the empty cache with the old successful verdict and a fresh 24-hour policy expiry, allowing later installs to replay instead of fetching the missing policy. Compare the cache snapshot actually used for input hashing with the entry snapshot, derive policy expiry from that same snapshot, and add a regression that deletes the cache after this guard but before hashing.

2 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 40b9a7b into main Nov 24, 2026
75 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-perf-verdict-gitlab-ado branch November 24, 2026 10:09
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.

[FEATURE] Verified-state record: exact policy-cache proof for GitLab and Azure DevOps projects

2 participants