Skip to content

perf(install): a converged install attests its state, so the next unchanged install skips the proof - #5383

Merged
Daniel Meppiel (danielmeppiel) merged 15 commits into
mainfrom
danielmeppiel-perf-attested-record
Nov 25, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 15 commits into
mainfrom
danielmeppiel-perf-attested-record

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: ddd81de152fd3888b8d24aa581d52d9595522872

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ W3d ACCEPT at every head through ddd81de, and Copilot has 0 open threads at ddd81de.
↑ Red-first cells cover ordering after #5394, executable gates (positive controls), wrapped and unprefixed warnings, and a frozen retained orphan; the real-CLI differential matches the full pipeline.
↑ Local verdict, world, invariants and quality suites pass; the lint chain is clean.
↓ Linux warm +1.4-1.9% CPU, attributed by profile to the attestation writer.
↓ Full CI and QL H8 at ddd81de were pending when assessed.
Performance gain 8/10 ↑ First re-install noop #2 reads 0.547 and 0.552 on Linux (tree-50); earlier reads were 0.431 on Windows and 0.504 on macOS.
↓ Warm cost as disclosed.

Description

Today a user's first unchanged apm install after an install pays the full no-op proof: about 2.1 s Linux and 4.4 s Windows CPU at tree-50. Only the third run replays the verified-state record (#4993, 0.30 s). The record is written only by a run the engine proved a no-op. This PR lets a successful, converged full install attest the state it committed, so the next unchanged install skips the proof.

  • Writer. At the end of a full apm install / apm install --frozen that succeeded, the record module writes an attested record. It holds no output, and it is written under the lifecycle lock over exactly the lock bytes the install committed (W3d A6). The key is the same HMAC over every live verdict input that perf(install): a no-op install replays the last verified no-op from an authenticated record #4993 uses: manifest, lock, governed listings, APM_HOME, policy cache, git config, allowlisted environment and run-read names. It also includes the build identity (A3). Nothing is attested when:
    • the target set announced by the run differs from a fresh resolution at its end (A1);
    • any warning or error line the run printed is outside the allowlist of notices the hit re-judges live, such as parked MCP servers (A2 allowlist; a kept copy, a skipped file or a retained snapshot blocks);
    • lifecycle scripts are declared (A4);
    • the lock cannot be proved.
  • Hit. diff_apply.try_apply runs every gate that precedes planning, as today: eligibility, policy discovery and target policy, the source scan and scope. It then checks the attested record. The check recomputes the HMAC from live inputs at the run's entry state, then re-hashes every deployed file and package copy no-follow, exactly as a replay hit does (A7). It still runs the lifecycle-script, executable and policy-check refusals. It then renders the no-op through the proven no-op's own path: _commit with an empty diff, then fast_output.render, so the policy gate and MCP/LSP services run live inside the apply journal. Any miss or doubt falls through to today's proof.
  • Provenance never upgrades (A5). A replay never reads an attested record. The output record a matched run writes says provenance: attested.

Equivalence

A proof of an unchanged install answers: does planning find any file or package to change, and do the gates admit the state? An attested hit answers the same question without planning:

  • Planning would find nothing. Run 1's committed state is the planner's fixed point (I2). The deployed bytes and package copies are not trusted from run 1: they are re-hashed against the HMAC'd lock on every hit. Any input the planner reads is in the HMAC, so a changed manifest, lock, governed file, planted link, approval, policy cache or environment misses.
  • The gates admit it. Every gate that re-judges a run still runs on the hit, in the same order as the proof.
  • The output is the proof's output by construction. The hit prints through the same renderer the proven no-op uses. Services and their notices are re-judged live. This is why only those notices may pass A2.

Issue and approved scope

Issue: Refs #4939

Human scope-approval comment: the #4939 install-performance scope; record-at-install accepted by the PERF VP and the regent (2026-11-24 19:38) and by W3d (attested-record ruling A1-A8, scope amendment).

Does this PR complete the issue, or what remains? No. Rendering the no-op output at install #1, so that install #2 is a byte replay, remains a follow-up.

Type of change

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

Testing

  • Tested locally (guarded: tests/integration/test_verdict_record.py, test_verdict_record_attested_world.py, tests/unit/install/test_architecture_invariants.py, tests/unit/install/test_diff_apply.py, tests/unit/test_update_notice.py, tests/unit/test_console_utils.py, tests/quality/test_quality_baselines.py -> all passed at ddd81de; ruff, architecture linter, complexity ratchet, R0801, assertion-quality, tm006 and auth-signal checks clean)
  • All existing tests pass (CI on this PR)
  • Added tests for new functionality (if applicable)

Cells:

  • tests/integration/test_verdict_record.py:
    • attested, then hit, with no byte replay (A5);
    • every input changed after run 1 never hits: manifest, lock, deployed bytes, package copy, unmanaged file, planted link, approvals, policy cache, allowlisted env, lifecycle script;
    • a widened target set (A1), a deferral warning (A2) and lifecycle scripts (A4) are never attested;
    • a parked MCP notice still attests;
    • a lock changed after commit is never attested (A6);
    • the output recorded after an attested hit stays attested (A5).
  • tests/integration/test_verdict_record_attested_world.py, real CLI on the tree-10 offline world:

Performance at bc3512d against merge-base c0296fa (tree-50, paired CPU including children, 6 pairs; JH's replay harness):

install #2 (attested hit) cold warm
Linux 3.41 -> 1.73 s (0.515) 1.008 0.998 (9-pair)
Windows 5.53 -> 2.34 s (0.431) 0.997 0.999
macOS 3.10 -> 1.40 s (0.504) 0.991 see below
  • Replay reads "attested hit, recorded" on 12/12 samples on every OS. Spawns and requests are unchanged.
  • Runs: L 45464326641 / 45466147122, W 45464401759, M 45464458778 / 45466213508.
  • Disclosure: macOS warm install read 1.022 and 1.048 on two runs (9-pair band 0.987-1.110, shard-dependent). The record path adds one HMAC and one file write at the end of a full install, with no spawn or request change.
  • The head after bc3512d only moves code verbatim (LOC budget): verdict_write.py and verdict_attest.py.

Since the #5394 re-merge (head ddd81de)

  • Merge with fix(claude): keep install-only projects on the 0.37 .claude/rules layout #5394. _refuse_claude_carried_rules runs before the attested branch in try_apply. Cell test_a_valid_attestation_never_skips_the_claude_carried_rules_refusal (tree-10-claude plus a root AGENTS.md) is red when the refusal is moved after the attested branch.
  • First no-op of the day records. A run whose daily update check printed nothing records; a run that printed the new-version notice never does, so the notice stays out of the replay surface.
  • Fail-safe attestation (Copilot round 3). Every warning or error message _rich_warning/_rich_error printed is judged unwrapped (console.EMITTED, O(1) per call). An unprefixed warning refuses the attestation, and the update notice is caught before any terminal wrap. A frozen install that retains a dependency apm.yml dropped is never attested (the audit's no-orphan baseline), so the next frozen install prints its notice again.
  • perf: strict no-op fast path for apm install / --frozen (1 s target) #4770 cells. For executable gates, the record's key is the only control, since install re-judges the lock's recorded exec_status. Ten cells, each with a positive control, cover both the output replay and the attested hit: user exec deny, project exec deny, revoked approval, user deny after approval, and org deny_all. A real-CLI differential checks that the attested hit and the output replay print what the full pipeline prints with every fast path off, and that no project byte moves.
  • Verbatim move. attested_gates and release_attested moved into verdict_attest.py (diff_apply.py LOC budget).

Performance at the re-merge (Linux, tree-50, vs merge-base 1e4a208, paired CPU including children):

run head pairs noop #2 cold warm
45514821064 1a5cc0c 6 0.547 0.988 1.018 [0.958, 1.042]
45516702102 693df21 9 1.019 [0.969, 1.036]
45518809497 ddd81de 9 0.552 [0.544, 0.560] 1.014 [1.010, 1.021]
45520450154 attestation off vs on 9 0.994 [0.970, 1.018]
  • Disclosure: Linux warm (fresh-lock) install costs +1.4-1.9% CPU, about 0.1 s at t50.
    • Three reads: 1.018 [0.958-1.042], 1.019 [0.969-1.036], 1.014 [1.010-1.021].
    • A profile at ddd81de (run 45521204838) attributes it to the attestation written at the end of every full install, about 0.14 s profiled: the lockfile parsed twice (0.045 + 0.053 s) and the key digest (0.040 s).
    • An A/B with the writer off read 0.994 [0.970-1.018], inside its noise.
    • In exchange, the first re-install is about 1.8x faster (noop Integrate copilot runtime #2 0.552).
    • Spawns and requests are identical. The shave (reuse the install's parsed lock and manifest, key the inputs it already read) is tracked in [backlog] Install performance: parked cars and hygiene follow-ups #5384.
  • Runs (all Linux): 45514821064, 45516702102, 45518809497, 45520450154, 45521204838.

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.

…nchanged install skips the proof

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…tics read; cells

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… key the update notice; cells

W3d attested-record ruling: a full install attests only when every warning or
error line it printed is a notice the attested hit re-judges live (parked MCP
servers). An attested record holds no output, so the update-check output guard
does not apply; the update-check file stays keyed and the record expires when
the check falls due. Component cells for A1, A2, A4-A6 and the tamper set; an
end-to-end cell for the hit, the stdout differential and an edited deployed file.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@danielmeppiel Daniel Meppiel (danielmeppiel) added the full-integration Run the full integration suite (ci-integration.yml) on this PR before merge label Nov 24, 2026
Copilot AI balanced review requested due to automatic review settings November 24, 2026 18:34
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

Critical attestation flaws allow stale records to bypass updated validation and unresolved-file warnings to disappear, while broken integration tests leave the new path unverified.

5 open issues
What changed in this PR

This PR extends the authenticated install-record mechanism so a successful, converged install can attest its committed state. The next unchanged install can skip planning while still checking live inputs, deployed content, and runtime gates.

Changes:

  • Adds attested records with provenance tracking and convergence checks.
  • Routes attested hits through the existing journaled commit and no-op renderer.
  • Adds invalidation and real-CLI tests, plus a user-facing changelog entry.
File Description
tests/​integration/​test_verdict_record.py Tests attestation eligibility, invalidation, and provenance.
tests/​integration/​test_verdict_record_attested_world.py Adds real-CLI output-parity and edited-file scenarios.
src/​apm_cli/​install/​verdict_record.py Creates and verifies attested records alongside output records.
src/​apm_cli/​install/​verdict_inputs.py Adjusts update-notice scheduling for records without output.
src/​apm_cli/​install/​verdict_attest.py Marks successful full installs as candidates for attestation.
src/​apm_cli/​install/​phases/​targets.py Records announced targets for convergence checks.
src/​apm_cli/​install/​diff_apply.py Adds the attested no-op path before planning.
src/​apm_cli/​commands/​install.py Connects successful install completion to attestation.
changelog.d/​5383.changed.md Announces faster subsequent unchanged installs.

Review effort: Balanced

Comment thread src/apm_cli/install/verdict_record.py Resolved
Comment thread src/apm_cli/install/verdict_record.py Resolved
Comment thread src/apm_cli/install/diff_apply.py Resolved
…writes nothing; traces never recorded

The attested record MACs the exact lock bytes and the build, which passed the
lockfile-generator gate when they were committed, so a matching run skips
that gate (it composes the whole lock with the bounded YAML loader). Decide
mode on an attested match reports and returns without writing. Trace lines
are filtered from the stderr a record replays. verdict_attest.py joins the
install-deployment owner; the real-CLI cells are component cells.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
apm-spec-waiver: install fast-path internals only; no OpenAPM-observable behaviour, output or lockfile shape 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.

🔵 Needs a closer look

Critical attestation flaws let colored warnings evade convergence checks and changed APM code reuse stale records, potentially suppressing unresolved-state diagnostics and bypassing planning and validation.

4 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Test that attested hits actually bypass planning

tests/​integration/​test_verdict_record_attested_world.py:132

The attested hit trace is emitted after record authentication, before _attested_gates and the planning bypass execute, so this test still passes if the bypass is removed and the ordinary planner runs. Assert that the attested branch completed, for example by running this scenario in fast-path trace mode and checking no-op (attested record), or by detecting entry into planning/staging. This makes the test protect the optimization rather than only record authentication.

1 resolved since last review

Review effort: Balanced

…f verdict_record (LOC budget)

A verbatim move: verdict_write.py holds the writer (_record_locked, _record_after,
_committed_lock, _write_at_entry, _write and the A1/A2 helpers), verdict_attest.py
the attested API (note_run_targets, note_attested_install, attested_state).
Module state stays in verdict_record, which a replay imports alone.

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

Critical flaws allow colored warnings to evade attestation checks, stale-build records to bypass updated validation, and post-commit output failures to restart installation and potentially repeat service side effects.

3 open issues
1 previously missed issue

In code that hasn't changed since last review

High severity ANSI styling can hide warnings from attestation checks

src/​apm_cli/​install/​verdict_write.py:95

On a colored terminal, _Tee captures ANSI styling before [!], so this anchored regex misses skipped-file and retained-state warnings. This allows an unsettled install to be attested, and the next attested hit can suppress its unresolved warning. Strip recognized styling before applying both matchers, fail closed on unrecognized escapes, and add a colored-output regression test.

1 resolved since last review

Review effort: Balanced

… styled warnings, release outside the fallback

- The record keys the APM implementation, not only sys.executable: a frozen
  binary's own stat, an installed distribution's RECORD, or a source/editable
  tree's per-file stat, so changed code at the same version never reuses a record.
- Terminal styling (SGR) is stripped before the A2 allowlist judges a line; any
  other escape sequence blocks the attestation.
- An attested no-op releases its held output outside the fallback handlers, so
  an output failure after commit exits non-zero and never re-runs the pipeline.
Each with a cell that fails on the previous code.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ackage, and an unreadable tree declines

QL v2 / W3d: size and mtime miss an edit that keeps both; the implementation
identity of a source or editable tree now hashes every package file's content.
Any file that cannot be read raises, so neither a record nor a replay proceeds
(never a version-only key). Installed distributions keep the RECORD hash and
frozen binaries the executable stat.

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

Human assessment is needed because successive frozen installs can attest despite retained undeclared packages or obsolete files, then omit retention notices from replayable output.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

…es refusal (#5394)

Red-first: with _refuse_claude_carried_rules moved after the attested branch,
install #2 commits the attested no-op (traces: attested hit, recorded); at
this head the fast path declines and the full pipeline re-attests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…s its verdict

The record refused any run that ran the daily update check, so the first
unchanged install of each day never recorded. With nothing new that run prints
nothing, and so does the next run while the check is fresh; only a run that
printed the new-version notice stays unrecorded. The notice text is one
constant shared by its printer and the record.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ted record

Verbatim move of _attested_gates and _release_attested from diff_apply.py to
verdict_attest.py (now attested_gates / release_attested; imports stay
function-level): the #5394 merge put diff_apply.py over its 1000-LOC budget.
The call order in try_apply is unchanged; the claude carried-rules refusal
still runs before the attested branch.

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 attestation fast path can bypass the baseline audit gate and suppress retained-dependency notices and unresolved-hook warnings on subsequent installs.

3 open issues

Review effort: Balanced

Comment thread src/apm_cli/install/diff_apply.py Resolved
Comment thread src/apm_cli/install/verdict_write.py Resolved
Comment thread src/apm_cli/install/verdict_write.py Resolved
…nts the full run's output (#4770)

W3d R1 / QL: install re-judges the lock's recorded exec_status, so the
record's key is the only control for executable gates. Ten cells, each with a
positive control (run 2 hits first), for both the output replay and the
attested hit: user exec deny (config.json), project exec deny (apm.yml), a
revoked user approval, a user deny after approval, and an org deny_all in the
policy cache. Plus the #4770 differential over the real CLI: the attested hit
and the output replay print what the full pipeline (APM_INSTALL_FAST_PATH=0)
prints, timings aside, and no answer moves a project byte.

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

Output checks miss wrapped update notices and unprefixed hook warnings, allowing repeated notice replay and attestation of installs with unresolved warnings.

3 open issues

Review effort: Balanced

…or a retained orphan

Copilot #5383 round 3 (PERF VP ruling 02:55, fail-safe: refuse, never skip):
- console._rich_warning/_rich_error keep every message they print, unwrapped
  (console.EMITTED, O(1) per call). The record clears it at entry only when
  console is already loaded (the replay path imports nothing new) and the
  writer judges those messages: an unprefixed warning (a hook file with no
  entries) refuses the attestation, and the update notice is detected before
  any terminal wrap.
- The writer refuses to attest when the audit's no-orphan baseline fails: a
  frozen install that retains a dependency apm.yml dropped would otherwise let
  the next hit skip its notice.
Red-first on 693df21: the wrapped notice records, the unprefixed warning
attests, and a frozen install retaining an orphan attests. The unit fixture
now declares its locked package (it was an orphan world).

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

Human assessment is needed because stale files retained during frozen installs can evade attestation checks and suppress the migration notice on a subsequent install.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants