Skip to content

chore(agentic): port preflight orchestrator to TypeScript#30988

Merged
abretonc7s merged 8 commits into
mainfrom
chore/preflight-ts-port
Jun 3, 2026
Merged

chore(agentic): port preflight orchestrator to TypeScript#30988
abretonc7s merged 8 commits into
mainfrom
chore/preflight-ts-port

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Description

Ports the agentic preflight orchestrator from scripts/perps/agentic/preflight.sh (~1300-line bash) to a modular TypeScript implementation under scripts/perps/agentic/preflight/, run via ts-node and wired to the a:ios / a:android / a:setup:* scripts. preflight.sh is kept as a thin compatibility shim that forwards to the TS entrypoint so existing callers (farmslot) keep working unchanged. Dev-only agentic tooling — no app or runtime code changes.

Also includes: build-fingerprint drift reporting on cache miss, Metro health detection + recovery during start and the CDP wait, a PackageJsonScriptsAll fingerprint skip (editing a:* scripts no longer invalidates the native build cache), and a longer wallet-fixture eval timeout for large fixtures.

Changelog

CHANGELOG entry: null

Related issues

Fixes: N/A

Manual testing steps

Feature: agentic preflight (TypeScript)

  Scenario: warm a worktree from cache
    Given a booted simulator with the app already built at the current fingerprint
    When I run `yarn a:ios`
    Then it reuses the installed app with no rebuild, starts Metro + CDP, and seeds the wallet

  Scenario: full clean setup
    When I run `yarn a:setup:ios`
    Then it runs yarn setup + pods + a native rebuild, then Metro + CDP + wallet

Validation run:

  • yarn lint:tsc — passes; the new scripts/perps/agentic/preflight/**/*.ts modules are covered, 0 errors
  • yarn eslint scripts/perps/agentic/preflight/ — clean
  • .sh shim ↔ .ts parity verified byte-for-byte via --check-only
  • Live yarn a:ios on a booted simulator: cache-hit reuse, native build path, Metro health recovery, CDP connect, and wallet-fixture seeding all exercised

Screenshots/Recordings

N/A — internal CLI tooling, no UI surface.

Before

N/A

After

N/A

Pre-merge author checklist

  • I've followed MetaMask Contributor Docs and MetaMask Mobile Coding Standards.
  • I've completed the PR template to the best of my ability
  • I've included tests if applicable — orchestration scripts (no unit suite); verified via lint:tsc, eslint, byte-parity check, and live runs
  • I've documented my code using JSDoc format if applicable — each module carries a header docstring; see preflight/README.md
  • I've applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

Performance checks (if applicable)

  • I've tested on Android
  • I've tested with a power user scenario
  • I've instrumented key operations with Sentry traces for production performance metrics

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Low Risk
Dev-only agentic CLI and cache tooling; no production app code paths. Residual risk is behavioral parity with the old bash flow across iOS/Android builds and parallel worktrees.

Overview
Replaces the ~1300-line bash agentic preflight orchestrator with a modular TypeScript entrypoint under scripts/perps/agentic/preflight/, invoked by yarn a:ios / a:android / a:setup:* via ts-node with --mode auto (was fast in the old shell scripts). preflight.sh is now a thin shim that execs into preflight.ts so legacy callers keep working.

Build cache stays in bash: new build-cache-cli.sh exposes fingerprint, store/prune, snapshot/drift, and lock-hold for the TS BuildCache wrapper. On cache miss, preflight prints a drift report (compute-cache-fp.js --diff). Fingerprinting gains PackageJsonScriptsAll so editing a:* scripts no longer busts the native cache; prune also removes .sources.json.

Runtime hardening in TS: split JS install vs yarn setup:expo when setup artifacts drift, Metro /status checks with restart during start/CDP wait, and setup-wallet.sh uses a higher default CDP_TIMEOUT plus clearer apply failures. Shell tests/e2e now invoke preflight.ts instead of the old monolith.

Reviewed by Cursor Bugbot for commit 55dffb0. Bugbot is set up for automated code reviews on this repo. Configure here.

Move the preflight orchestrator to a modular TS implementation under scripts/perps/agentic/preflight/ (run via ts-node), wired to a:ios / a:android / a:setup:*. preflight.sh is now a thin compatibility shim forwarding to preflight.ts, kept temporarily so external callers (farmslot) keep working; remove once they migrate.

- dep reconcile keyed off real artifact/source drift, not package.json mtime
- build-fingerprint drift reporting on cache miss (compute-cache-fp.js --json/--diff, build-cache.sh bc_snapshot/bc_drift, build-cache-cli.sh bridges the hardened cache+lock to the .ts)
- Metro health verification + recovery on Metro start and during the CDP wait
- setup-wallet.sh: account-derivation eval cap 30s->120s, surface the error instead of a silent set -e exit
- repoint cache test scripts to preflight.ts
@abretonc7s abretonc7s added no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed team-perps Perps team labels Jun 3, 2026
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@abretonc7s abretonc7s marked this pull request as ready for review June 3, 2026 06:48
@abretonc7s abretonc7s requested a review from a team as a code owner June 3, 2026 06:48
Comment thread scripts/perps/agentic/preflight/modules/android.ts Fixed
Comment thread scripts/perps/agentic/preflight/modules/android.ts Fixed
Comment thread scripts/perps/agentic/preflight/modules/ios.ts Fixed
Comment thread scripts/perps/agentic/preflight/modules/ios.ts Fixed
@github-actions github-actions Bot added the risk:low AI analysis: low risk label Jun 3, 2026
Comment thread scripts/perps/agentic/preflight/modules/ios.ts Outdated
Comment thread scripts/perps/agentic/preflight/modules/ios.ts Outdated
Comment thread scripts/perps/agentic/preflight/modules/cache.ts
- spawn emulator/expo via argv instead of bash -c (no env interpolation)
- read build logs with fs.readFileSync instead of spawning cat
- prune honors BUILD_CACHE_RETAIN env (default 5)
- recheck shared cache under post-pod fingerprint before full native build
- distinguish simctl install failure from a missing installed app
Comment thread scripts/perps/agentic/preflight/modules/ios.ts Outdated
Comment thread scripts/perps/agentic/preflight/modules/ios.ts
@github-actions github-actions Bot added risk:medium AI analysis: medium risk and removed risk:low AI analysis: low risk labels Jun 3, 2026
…t opt-in

- wrap runIos/runAndroid bodies in try/finally so the per-fingerprint build
  lock is released on every failure path (logger.fail throws), instead of
  leaking it and blocking other worktrees until the stale-lock timeout
- post-pod cache recheck now fails loud in --mode fast (lock/install failure)
  instead of silently falling through to a native build
- IOS_BUILD_TIMEOUT defaults to 0 (no timeout); a ceiling is enforced only when
  set explicitly (e.g. from farmslot) — overloaded machines no longer time out
@abretonc7s abretonc7s enabled auto-merge June 3, 2026 07:31
michalconsensys
michalconsensys previously approved these changes Jun 3, 2026
@abretonc7s abretonc7s added this pull request to the merge queue Jun 3, 2026
@abretonc7s abretonc7s removed this pull request from the merge queue due to a manual request Jun 3, 2026
Comment thread scripts/perps/agentic/preflight/modules/env.ts
loadJsEnv merged .js.env only into ctx.env, so spawned children (expo run:ios,
Gradle, the google-services decode) inherited bare process.env and could not see
vars defined only in .js.env (e.g. GOOGLE_SERVICES_B64_ANDROID). Export each
newly-introduced key into process.env, mirroring bash 'set -a; source .js.env'.
Caller-set vars still win (keys already in process.env are untouched).
Comment thread scripts/perps/agentic/preflight/modules/ios.ts
Comment thread scripts/perps/agentic/preflight/modules/ios.ts
Comment thread scripts/perps/agentic/preflight/modules/ios.ts
- always release the pre-pod lock and re-probe the shared cache after pod
  install, even when the fingerprint is unchanged (another worktree may have
  stored an artifact during the pod-install wait)
- release the pre-pod lock before acquiring the post-pod lock, so a failed
  re-acquire never strands a stale mutex on the old fingerprint
- store the build under the pre-pod source fingerprint as an alias and record
  the install under it, so worktrees that compute the pre-pod hash hit the
  cache instead of rebuilding (restores maybe_store_ios_source_cache_alias)

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3d63499. Configure here.

Comment thread scripts/perps/agentic/preflight/modules/ios.ts
Comment thread scripts/perps/agentic/preflight/modules/ios.ts
- killTree returns early on a non-positive pid; process.kill(0, sig) would
  otherwise signal the whole process group (including the orchestrator) when a
  spawned child's pid is missing
- post-build storeArtifact now acquires a build lock when none is held (the
  lockless build path), so concurrent worktrees can't corrupt the shared
  fingerprint cache — matches bash bc_with_lock (iOS + Android)
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: None (no tests recommended)
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 95%
click to see 🤖 AI reasoning details

E2E Test Selection:
All 20 changed files are developer tooling scripts for the agentic/perps local development environment. The changes include:

  1. package.json: Only 4 a:* npm scripts updated — these are developer convenience commands that invoke the preflight tooling. Changed from calling preflight.sh to directly calling preflight.ts via ts-node, and --mode fast changed to --mode auto. No production app code, no test infrastructure, no CI workflows affected.

  2. scripts/perps/agentic/: All files are internal developer tooling:

    • preflight.sh → converted to a compatibility shim forwarding to the new TypeScript implementation
    • preflight/preflight.ts + preflight/modules/*.ts → TypeScript rewrite of the preflight orchestrator (sets up local dev environment: builds app, starts Metro, connects CDP, configures wallet)
    • lib/compute-cache-fp.js → Enhanced build cache fingerprint computation with diff/JSON modes
    • lib/build-cache*.sh, lib/test-*.sh → Build cache management shell scripts
    • setup-wallet.sh → Wallet setup script for local development via CDP

None of these changes affect:

  • App source code (no changes to app/ directory)
  • E2E test files (no changes to e2e/ or tests/ directories)
  • CI/CD workflows (no changes to .github/ directory)
  • Production app functionality
  • Any shared components used by E2E tests

These are purely internal developer productivity tools for the Perps team's local development workflow. No E2E tests need to run to validate these changes.

Performance Test Selection:
All changes are developer tooling scripts for local development setup. No app source code, UI components, state management, or performance-sensitive code paths were modified. No performance tests are warranted.

View GitHub Actions results

@abretonc7s abretonc7s enabled auto-merge June 3, 2026 10:04
@abretonc7s abretonc7s added this pull request to the merge queue Jun 3, 2026
Merged via the queue into main with commit 7e435be Jun 3, 2026
156 of 159 checks passed
@abretonc7s abretonc7s deleted the chore/preflight-ts-port branch June 3, 2026 11:03
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 3, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.81.0 Issue or pull request that will be included in release 7.81.0 label Jun 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed release-7.81.0 Issue or pull request that will be included in release 7.81.0 risk:medium AI analysis: medium risk size-XL team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants