Skip to content

fix(ci): reuse build artifacts without accepting stale clean identities - #1109

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
loveRhythm1990:ci/fix-build-metadata-invalidation
Oct 21, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
loveRhythm1990:ci/fix-build-metadata-invalidation

Conversation

@loveRhythm1990

@loveRhythm1990 loveRhythm1990 commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Capability assessment: N/A: This change fixes build invalidation and artifact identity declarations; it does not introduce runtime capabilities.

Summary

A fresh checkout can rebuild astra-core and its dependents on consecutive Cargo invocations even when the source is unchanged. This PR fixes mechanisms A/B in #1106 and preserves local artifact reuse without letting an unverified binary claim a clean source identity.

  • Watch only existing Git metadata paths, avoiding perpetual invalidation from missing packed refs, reflogs, or loose refs.
  • Use GIT_OPTIONAL_LOCKS=0 for Git queries so build-time git status cannot rewrite its own watched index.
  • When a local branch is packed, watch the shared refs/heads namespace for its loose ref. Loose remote/tag changes do not invalidate core. Changes to the existing shared packed-refs file can still rebuild it.
  • Watch all tracked sources only for builds with a valid 64-hex attestation nonce. Ordinary README/docs/Web changes and downstream-only Rust edits can reuse core.
  • Make ordinary unverified builds conservatively report git_dirty=true, closing the stale clean-artifact identity gap identified in review.
  • Refresh and validate the official client release build's explicit source declaration, retaining it for subsequent Cargo tests in the same job.
  • Canonicalize paths in the macOS CI contract test to handle /var and /private/var aliases.

Refs #1106. The PR diff fix in #1107, cross-commit sccache invalidation (mechanism C), conditional dev-tty execution, and self-hosted runner migration remain outside this PR. #1106 remains open.

The branch also contains the earlier dependency update from #1104: rustls-webpki 0.103.16 and webpki-root-certs/webpki-roots 1.0.10. Current upstream main (d39864bc) now contains the identical lockfile change. No audit command or ignore rule is changed here.

User and compatibility impact

The clean-build declaration is deliberately stricter. The existing public boolean schema is unchanged: git_dirty=false means an explicitly clean build; true includes both tracked changes and an unverified source state.

Ordinary Cargo builds, including release-profile builds, report true without either:

  1. A valid ASTRA_BUILD_ATTESTATION_NONCE, enabling tracked-source invalidation and a fresh Git status check whenever those inputs change; or
  2. A complete trusted orchestrator declaration: a valid full ASTRA_BUILD_SOURCE_GIT_SHA together with ASTRA_BUILD_SOURCE_GIT_DIRTY=true|false.

Missing/malformed declarations cannot establish clean identity for ordinary builds. An orchestrator must refresh its declaration for every build and prevent source changes during compilation; a constant false in a developer shell is not verification. Existing container/manual-harness builders and the local API launcher already supply the pair. The client release workflow now verifies its selected SHA and clean tracked state before exporting the pair, failing before Cargo on an invalid checkout.

Both health responses and --build-info-json use the canonical embedded boolean. Existing clean-artifact consumers therefore reject ordinary unverified binaries without adding a second verification path or changing their schema. The API reference and harness guide document how to create identity-sensitive artifacts.

Valid-nonce builds still detect unstaged edits when a nonce is reused. Deleted tracked files conservatively invalidate those builds until restored or staged. Removing the nonce removes broad source watches and returns to an unverified identity.

The second/third build of an unchanged checkout can reuse artifacts. Git index/ref changes can still invalidate metadata. The issue's 3m48s second compilation is an example, not a guaranteed saving; controlled before/after CI timing remains outstanding.

Architecture and complexity delta

  • Canonical owner: crates/core/build.rs.
  • Existing SHA/dirty/nonce consumers and runtime attestation validation are retained.
  • No new runtime state, verification schema, or parallel identity implementation.
  • The release workflow uses the existing explicit source declaration contract.
  • Test fixtures execute the production build script. The new artifact regression also compiles unmodified production build_info.rs and invokes production scripts/harness/preflight.py::probe_build_info.

Verification

Local validation for 7bda3e33:

  • CI Python suite: 148 tests; 143 passed, 5 skipped by existing conditions.
  • make format-check: passed.
  • Standalone build-script Clippy with Rust 1.97.0 and -D warnings: passed.
  • python3 scripts/ci/validate_repository.py: passed.
  • bash scripts/dev/test_setup_contract.sh: passed.
  • Actionlint 1.7.12 for the changed release workflow: passed.
  • git diff --check: passed.

The new regression builds a clean fixture, changes actual downstream Rust behavior without staging, rebuilds, restores the source without rebuilding, verifies that the checkout is clean and the binary still executes the changed behavior, then calls the production identity probe. At e737a2ec, ordinary and invalid-nonce cases incorrectly pass that probe. With this fix, both are rejected while core remains Fresh. Valid-nonce and refreshed explicit-declaration controls accept clean artifacts and reject edited artifacts.

Other fixtures cover cold checkout/index immutability with Git status enabled; second/third-build reuse; detached HEAD; packed/loose refs; linked worktrees; loose remote/tag changes; staged edits; nonce changes; source archives; incomplete declarations; unrelated tracked edits; and attested deletion/restoration. Release shell contracts use real Git fixtures and a stubbed Cargo command under Bash and sh, covering clean, dirty, wrong-revision, and unavailable-Git cases, plus declaration persistence between steps.

The public-probe fixture seeds dependency resolution from the repository lockfile and verifies the resolved registry versions/checksums against it. A cold environment may fetch the small serde dependency closure; subsequent fixture builds are locked and offline.

The broader scripts.harness.test_preflight suite could not import locally because the harbor Python dependency is absent. This does not affect the new regression's direct execution of the production probe, which passed. Full workspace Rust tests and actual release builds were not run locally; fresh PR CI remains required. No final CI success is claimed.

Earlier dependency validation at 0e1eb6ff passed locked metadata resolution and cargo-audit 0.22.1 against fixed advisory database 4b587f00996ebe5c05a73eaef105ef241e876414, with zero blocking vulnerabilities and existing allowed warnings retained.

Read-only merge-tree validation against current upstream main d39864bc found no conflicts. No merge was performed. Database verification is not applicable: no schema or query changes.

Final checklist

  • Regression reproduces the reported artifact-identity gap before the fix.
  • Local development reuse and strict attestation correctness are both covered.
  • Public documentation explains conservative unknown/dirty semantics.
  • Official release artifacts retain a checked source declaration.
  • The diff contains no credentials, private endpoints, or generated artifacts.

@loveRhythm1990 loveRhythm1990 changed the title fix(ci): 避免 Git 构建元数据导致重复编译 fix(ci): 避免重复编译并修复依赖安全审计 Oct 21, 2026
@loveRhythm1990 loveRhythm1990 changed the title fix(ci): 避免重复编译并修复依赖安全审计 fix(ci): avoid redundant builds and resolve dependency audit failures Oct 21, 2026
@XuPeng-SH
XuPeng-SH marked this pull request as ready for review October 21, 2026 12:05
@XuPeng-SH
XuPeng-SH self-requested a review as a code owner October 21, 2026 12:05

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed commit e737a2e. Requesting changes for the clean-artifact identity gap below.

The A/B invalidation fixes otherwise have appropriate ownership and avoid additional runtime state or compatibility paths. Local validation passed all 146 CI Python tests, formatting, standalone build-script Clippy, repository checks, dev setup contracts, and locked offline dependency resolution.

The current-head live harness completed 17/18; the remaining case reports InfraVerificationUnavailable because its hard judger was unavailable. That failed check is not sufficient evidence of a behavioral regression caused by this PR, and its underlying failure remains unproven.

Comment thread crates/core/build.rs Resolved
@loveRhythm1990 loveRhythm1990 changed the title fix(ci): avoid redundant builds and resolve dependency audit failures fix(ci): reuse build artifacts without accepting stale clean identities Oct 21, 2026

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed commit 7bda3e3. The previous P2 finding is fixed; no new blocking findings.

The canonical build script now conservatively marks ordinary unverified artifacts as dirty. Valid-nonce source tracking and complete trusted source declarations retain their existing responsibilities, and existing identity consumers reject unverified artifacts without another verification schema or state machine. The client release workflow validates its selected source and supplies the existing declaration pair.

Independently reran the prior reproduction using production build_info.rs and the production identity probe: the rebuilt artifact executes the edited behavior after source restoration, but is now rejected while ordinary core reuse is preserved. Clean attested controls still pass. Additional checks covered declaration removal, Git query failures, and source archives without Git metadata.

Local validation passed all 148 CI Python tests, 32 harness preflight tests, formatting, standalone build-script Clippy, Actionlint, repository checks, and dev setup contracts. Implementation, test, and documentation changes were reviewed separately. A read-only merge-tree check against main at d39864b found no conflicts.

This approves the reviewed source. Full local workspace Rust tests, actual release builds, and macOS execution were not performed; full CI timing savings remain unmeasured. CI completion remains a separate merge gate.

@mergify

mergify Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@XuPeng-SH
XuPeng-SH merged commit cd4580e into matrixorigin:main Oct 21, 2026
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.

2 participants