Skip to content

👷 github: cache nx database - #1315

Open
nfmelendez wants to merge 2 commits into
codecov-searchfrom
nx-cache
Open

nfmelendez wants to merge 2 commits into
codecov-searchfrom
nx-cache

Conversation

@nfmelendez

@nfmelendez nfmelendez commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

what

cache .nx/workspace-data/*.db* next to .nx/cache, so the restored nx cache is actually usable, and add CHAIN_ID and EXPO_PUBLIC_ENV to the nx inputs of the app and e2e bundles, so a working cache never hands one job a bundle built for another chain.

stacked on #1314: with cache hits working, the stale lcov.info files restored into .nx/cache would reach codecov even more often unless uploads are already restricted to explicit files.

nx cache

since nx 19 the cache index lives in a sqlite database under .nx/workspace-data, and .nx/cache only holds outputs. the workflow persisted .nx/cache alone, so nx ignored every restored entry: the test job read 7 of 59 tasks from cache whether the restored cache was present or empty, and those 7 were the generate:* tasks written by pnpm install in the same run. the database file is named after the machine id, read from /etc/machine-id, and github runners share it: a probe on a fresh runner (runnervmlun5p) found 58b34b8c91a94400a52c175421986a53-v3.db restored from a cache saved by another runner, matching its own /etc/machine-id, so a cache saved on one runner is recognized on another.

nx inputs

a working cache exposed a gap in the task hashes. common/generated/chain.ts is produced by generate:wagmi from CHAIN_ID, but the build targets of the app and of .maestro hash ^production, which excludes generated/**, and did not list CHAIN_ID. the test job (no CHAIN_ID) and the e2e job (CHAIN_ID=31337) therefore computed the same hash for e2e:build with different contents. on the first re-run the e2e job restored the test job's getAccount.js, built against the optimism sepolia factory, and the web flow failed asserting 0x0Df0…4bA5 while the app showed 0x699F…7C6e. CHAIN_ID is now an input of both bundles, and EXPO_PUBLIC_ENV of the app, which inlines it. the expo fingerprint is unchanged: fingerprint.config.cjs ignores the root package.json and .maestro/package.json is not a source.

verification

two attempts of the same run on different runners, the second restoring the exact cache key saved by the first:

test e2e
tasks read from cache 44 of 59 5 of 13
e2e:build hit rebuilt, since the CHAIN_ID=31337 hash is absent from the test job cache
duration 2m06s, was 9m49s 11m50s, unchanged
web flow n/a passed

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved build and test caching so updates to workspace data and relevant environment settings are correctly detected.
    • Reduced the risk of stale cached results across local and end-to-end workflows.

@changeset-bot

changeset-bot Bot commented Sep 15, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 37beb58

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: cf929750-ef2a-47e1-bebc-4058c4aa3921

📥 Commits

Reviewing files that changed from the base of the PR and between 2a9d4f5 and 37beb58.

📒 Files selected for processing (3)
  • .github/workflows/test.yaml
  • .maestro/package.json
  • package.json

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

Nx now tracks additional environment variables and GitHub Actions caches Nx workspace database files for test and e2e jobs.

Changes

Nx cache tracking

Layer / File(s) Summary
Named input environment tracking
.maestro/package.json, package.json
Nx named inputs now include CHAIN_ID and EXPO_PUBLIC_ENV. The Maestro bundle input also includes CHAIN_ID.
CI cache path coverage
.github/workflows/test.yaml
The test and e2e jobs now cache .nx/workspace-data/*.db* in addition to .nx/cache.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 37beb

This change only adjusts build-cache tracking so cached bundles are not reused across different chains or environments, and extends the CI cache to include Nx workspace database files. Configuration files parse correctly and no product behavior is affected, so it is ready to merge.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding Nx database caching in GitHub Actions.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nx-cache
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch nx-cache

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 37beb585f1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread package.json
Comment on lines +335 to +337
{
"env": "EXPO_PUBLIC_ENV"
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include the e2e mnemonic in the mobile cache inputs

When EXPO_PUBLIC_E2E_MNEMONIC changes without another hashed input changing, Nx can restore a mobile bundle containing the previous value: Expo embeds this variable into the web bundle at src/utils/e2e.ts:27, while the e2e workflow supplies the current secret and server/test/anvil.ts:56-59 funds the account derived from that current value. The restored app therefore signs with an unfunded account and the web flow fails, so add EXPO_PUBLIC_E2E_MNEMONIC to these mobile inputs alongside EXPO_PUBLIC_ENV.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a56dcbeb25

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread .github/workflows/test.yaml Outdated
.nx/workspace-data/*.db*
key: nx-${{ runner.os }}-${{ github.sha }}
restore-keys: nx-${{ runner.os }}-
- run: ls -la .nx/workspace-data; cat /etc/machine-id; cat /var/lib/dbus/machine-id; hostname

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the cache inspection that fails on a cold cache

In the test job, when neither the exact key nor any restore key exists, actions/cache leaves .nx/workspace-data absent, so this first ls exits nonzero and GitHub's bash -e shell terminates the job before dependencies or tests run. GNU ls --help specifically documents status 2 for failure to access a command-line argument. Remove this diagnostic step or guard the directory access so a fresh or evicted cache can be populated.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 37beb585f1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

path: .nx/cache
path: |
.nx/cache
.nx/workspace-data/*.db*

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Invalidate restored task records when CI toolchains change

When a commit changes only a CI-provided toolchain—such as the Foundry version configured at .github/workflows/test.yaml:21-22—the exact SHA key misses, but restore-keys: nx-${{ runner.os }}- restores the preceding database because restore keys are prefix-matched (GitHub cache documentation). The restored Nx task hashes do not include this workflow or the externally installed Foundry version (sharedGlobals contains only nx.json, package.json, and pnpm-lock.yaml), so cached contract test and coverage records can cause the suite to be skipped under the newly selected toolchain. Include toolchain/workflow inputs in the cache namespace or Nx hashes before persisting the database.

Useful? React with 👍 / 👎.

Comment thread .maestro/package.json
Comment on lines +32 to +34
{
"env": "CHAIN_ID"
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include the alternate chain selector in the e2e hash

When CHAIN_ID is unset, common/wagmi.config.ts:18 selects Optimism on EAS and Optimism Sepolia otherwise based on EAS_BUILD_RUNNER. The e2e bundle imports exaAccountFactoryAddress from the generated chain module, but ^production excludes generated/**; hashing only CHAIN_ID therefore gives the two environments the same e2e:build hash even though their generated factory addresses differ. A build after changing only EAS_BUILD_RUNNER can restore getAccount.js for the wrong chain, so add EAS_BUILD_RUNNER to this bundle input as the mobile project already does.

Useful? React with 👍 / 👎.

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.

1 participant