Skip to content

ci: track and enforce contract WASM sizes - #526

Open
Caneryy wants to merge 1 commit into
Stellar-Ecosystem:mainfrom
Caneryy:agent/wasm-size-ci
Open

ci: track and enforce contract WASM sizes#526
Caneryy wants to merge 1 commit into
Stellar-Ecosystem:mainfrom
Caneryy:agent/wasm-size-ci

Conversation

@Caneryy

@Caneryy Caneryy commented Jul 30, 2026

Copy link
Copy Markdown

Summary

  • validate the exact registry and agents WASM artifacts against the current 128 KiB network ceiling
  • build the PR base commit and publish per-contract size deltas in the GitHub Actions job summary
  • upload structured size metrics for 90 days so changes remain visible across workflow runs
  • cover successful reports, missing artifacts, ceiling failures, and incomplete comparisons with Node tests

Validation

  • node --test scripts/check-wasm-size.test.mjs
  • cargo test in contract (18 passed)
  • cargo test in contract/agents (17 passed)
  • stellar contract build for both contracts
  • YAML syntax and git diff --check

Current optimized sizes are 10,401 bytes for registry and 14,917 bytes for agents.

Closes #413

Summary by CodeRabbit

  • New Features

    • Added automated WASM size checks for registry and agents contracts.
    • Pull requests now report current sizes and changes compared with the base version.
    • WASM artifacts and size metrics are retained for 90 days.
    • Added a configurable 128 KiB size limit, with support for local checks and custom thresholds.
  • Documentation

    • Updated contribution guidance with details on the WASM size check and local usage.
  • Bug Fixes

    • Builds now fail when required WASM artifacts are missing or exceed the configured limit.

@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@Caneryy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a Node.js CLI to measure registry and agents WASM sizes, compare pull-request builds with base artifacts, enforce a 128 KiB ceiling, write metrics, and integrate reporting and artifact retention into contract CI.

Changes

Contract WASM size enforcement

Layer / File(s) Summary
WASM size checker and validation
scripts/check-wasm-size.mjs, scripts/check-wasm-size.test.mjs
The CLI calculates sizes and deltas, writes JSON metrics, reports status, enforces configurable limits, and tests missing artifacts, incomplete base inputs, and over-limit failures.
CI integration and developer documentation
.github/workflows/ci.yml, CONTRIBUTING.md
Contract CI builds optional base artifacts, runs the size check, uploads metrics for 90 days, and documents local usage and the default ceiling.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GitHubActions
  participant contract-build
  participant check-wasm-size.mjs
  GitHubActions->>contract-build: Set up Node.js and build contracts
  contract-build->>check-wasm-size.mjs: Run WASM size test and size check
  contract-build->>contract-build: Build base contracts on pull requests
  contract-build->>check-wasm-size.mjs: Provide current and base WASM artifacts
  check-wasm-size.mjs-->>contract-build: Print report and write wasm-size-metrics.json
  contract-build-->>GitHubActions: Upload metrics artifact
Loading

Possibly related PRs

Suggested reviewers: 10xwhoman

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the PR’s main change: adding CI checks to track and enforce contract WASM sizes.
Linked Issues check ✅ Passed The changes report per-contract WASM sizes with PR deltas, enforce a ceiling, and preserve metrics for trend tracking.
Out of Scope Changes check ✅ Passed The PR stays focused on WASM size checking, related CI wiring, tests, and docs with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (3)
scripts/check-wasm-size.mjs (1)

149-156: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

git_sha metric won't match a real commit for PR runs.

For pull_request events, GITHUB_SHA is GitHub's synthetic merge commit rather than the PR's actual head commit, so persisted metrics (line 152) can't be reliably traced back to a specific commit in the history when reviewing size trends later. Consider preferring github.event.pull_request.head.sha (passed in via env from the workflow) when available.

♻️ Proposed fix
-    git_sha: process.env.GITHUB_SHA ?? null,
+    git_sha: process.env.PR_HEAD_SHA ?? process.env.GITHUB_SHA ?? null,

And in the workflow step, pass PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/check-wasm-size.mjs` around lines 149 - 156, Update the metrics
construction around git_sha to prefer a workflow-provided PR_HEAD_SHA for pull
request runs, falling back to GITHUB_SHA for other events or when the PR value
is unavailable. Update the workflow step that invokes this script to pass
PR_HEAD_SHA from github.event.pull_request.head.sha.
scripts/check-wasm-size.test.mjs (1)

100-112: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Consider adding a boundary test for size === maximum.

Existing tests cover under-ceiling and over-ceiling but not the exact-boundary case, which exercises the <= comparison directly responsible for pass/fail classification.

✅ Suggested addition
test("passes when size exactly equals the ceiling", (t) => {
  const paths = fixture();
  t.after(() => rmSync(paths.directory, { recursive: true, force: true }));
  writeFileSync(paths.currentRegistry, Buffer.alloc(1024));
  writeFileSync(paths.currentAgents, Buffer.alloc(100));

  const result = run(paths, ["--max-bytes", "1024"]);

  assert.equal(result.status, 0, result.stderr);
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/check-wasm-size.test.mjs` around lines 100 - 112, Add a boundary test
alongside the existing ceiling tests that sets the primary artifact size exactly
to the configured maximum, runs the size check, and asserts a successful status.
Reuse the existing fixture setup, cleanup, and run helpers, while preserving the
current under-limit and over-limit coverage.
.github/workflows/ci.yml (1)

81-103: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Base contract build isn't cached, doubling per-PR build time.

The base build's output directories (/tmp/lodestar-base/contract/target, /tmp/lodestar-base/contract/agents/target) aren't covered by the existing Rust cache (lines 37-46), so every PR run fully recompiles both base contracts from scratch. Since github.event.pull_request.base.sha is known up front (no fetch required), a cache keyed on it would let repeated pushes against the same base commit reuse the build.

♻️ Proposed addition (before the base build step)
+      - name: Cache base contract build artifacts
+        if: github.event_name == 'pull_request'
+        uses: actions/cache@v4
+        with:
+          path: |
+            /tmp/lodestar-base/contract/target
+            /tmp/lodestar-base/contract/agents/target
+          key: rust-base-${{ runner.os }}-${{ github.event.pull_request.base.sha }}
+
       - name: Build base contracts for size comparison
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/ci.yml around lines 81 - 103, Add caching for the base
contract build before the “Build base contracts for size comparison” step, keyed
by github.event.pull_request.base.sha and covering both
/tmp/lodestar-base/contract/target and
/tmp/lodestar-base/contract/agents/target. Restore the cache for repeated pushes
against the same base commit and ensure the existing build and copy flow remains
unchanged when no cache is available.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In @.github/workflows/ci.yml:
- Around line 81-103: Add caching for the base contract build before the “Build
base contracts for size comparison” step, keyed by
github.event.pull_request.base.sha and covering both
/tmp/lodestar-base/contract/target and
/tmp/lodestar-base/contract/agents/target. Restore the cache for repeated pushes
against the same base commit and ensure the existing build and copy flow remains
unchanged when no cache is available.

In `@scripts/check-wasm-size.mjs`:
- Around line 149-156: Update the metrics construction around git_sha to prefer
a workflow-provided PR_HEAD_SHA for pull request runs, falling back to
GITHUB_SHA for other events or when the PR value is unavailable. Update the
workflow step that invokes this script to pass PR_HEAD_SHA from
github.event.pull_request.head.sha.

In `@scripts/check-wasm-size.test.mjs`:
- Around line 100-112: Add a boundary test alongside the existing ceiling tests
that sets the primary artifact size exactly to the configured maximum, runs the
size check, and asserts a successful status. Reuse the existing fixture setup,
cleanup, and run helpers, while preserving the current under-limit and
over-limit coverage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f9dddb63-3dd3-4991-ad97-4bd72f5065d9

📥 Commits

Reviewing files that changed from the base of the PR and between a3fd824 and 4187dee.

📒 Files selected for processing (4)
  • .github/workflows/ci.yml
  • CONTRIBUTING.md
  • scripts/check-wasm-size.mjs
  • scripts/check-wasm-size.test.mjs

@ritik4ever

Copy link
Copy Markdown
Collaborator

Hi @Caneryy,

This PR could not be merged because it has merge conflicts with the target branch.

Please resolve the merge conflicts, push the updated changes, and the PR can be reviewed and merged.

Thank you!

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.

CI: no contract WASM size check

2 participants