Skip to content

fix(agentic): harden preflight launch and fixture setup#31011

Merged
abretonc7s merged 12 commits into
mainfrom
fix/agentic-preflight-codesign-race
Jun 3, 2026
Merged

fix(agentic): harden preflight launch and fixture setup#31011
abretonc7s merged 12 commits into
mainfrom
fix/agentic-preflight-codesign-race

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes regressions in the TypeScript agentic preflight flow after #30988 where yarn a:ios could reuse a broken Metro process, fail to keep the iOS app launched, or stall during wallet fixture import.

The preflight now uses a dedicated ts-node config, preserves the root tsconfig.json, requires Metro /status to report packager-status:running, retries stale Metro launches, wipes/reinstalls cached apps before fixture setup, and fails immediately when launch/setup subprocesses fail instead of drifting into CDP timeouts.

The wallet fixture path was also hardened so HD fixture accounts are created through deterministic batched multichain account groups instead of the all-provider account creation path.

Changelog

CHANGELOG entry: null

Related issues

Fixes: N/A - dev-only agentic tooling regression from #30988.

Manual testing steps

Feature: agentic preflight launches iOS and imports wallet fixtures

  Scenario: clean iOS preflight reuses a healthy Metro and imports fixtures
    Given simulator mm-2 is booted
    And the cached iOS app artifact exists
    When I run yarn a:ios
    Then Metro is verified through /status
    And the app launches and exposes CDP on port 8062
    And wallet fixture setup reaches "=== Wallet Ready ==="
    And the run reaches "=== Preflight complete ==="

  Scenario: repo setup noise is not left behind
    When preflight runs through yarn a:ios
    Then root tsconfig.json has no diff

Validation evidence:

  • yarn a:ios passed end to end
  • Final CDP status: WalletView, platform ios, selected account dev1
  • Root tsconfig.json: no diff
  • yarn tsc --noEmit --project scripts/perps/agentic/preflight/tsconfig.json
  • yarn tsc --noEmit --pretty false --skipLibCheck
  • bash -n scripts/perps/agentic/start-metro.sh scripts/perps/agentic/preflight.sh scripts/perps/agentic/setup-wallet.sh
  • yarn prettier --check on touched app/preflight files
  • yarn jest --runTestsByPath app/core/AgenticService/AgenticService.test.ts -t "setupWallet"

Screenshots/Recordings

Before

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

After

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

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

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

Medium Risk
Changes touch vault unlock fallbacks and multichain account creation in DEV AgenticService, but they are confined to agentic tooling and test harness paths, not production user flows.

Overview
This PR hardens dev-only agentic preflight and wallet fixture flows after regressions from the TypeScript preflight migration.

Preflight / Metro / install: yarn a:* now runs preflight through a dedicated tsconfig.json so expo run:ios rewriting the repo-root tsconfig no longer breaks ts-node. Preflight snapshots and restores root tsconfig.json on exit (including signals). Metro health checks require packager-status:running on /status, with retries when start-metro.sh fails or the bundler is bound but hung. iOS installs wait for codesign (with ad-hoc fallback) and treat stale Expo/Metro port holders more gracefully than hard-failing. With --wallet-setup, a fingerprint cache hit uninstalls and reinstalls from the cached artifact so app data is wiped instead of skipping native work.

Wallet fixtures (AgenticService + setup-wallet.sh): Fixture apply adds unlockFixtureVault (real Authentication.unlockWallet, then keyring + onboarding Redux recovery when auth leaves the vault locked). Missing HD accounts are created in one createMultichainAccountGroups batch (not per-account loops), with timeouts and polling until accounts exist. CDP setup can validate wallet state after eval timeouts instead of failing immediately on slow large fixtures.

Tests / scripts: New unit coverage for vault recovery and batched HD groups; shell tests updated for the preflight tsconfig and wallet-setup cache wipe path.

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

The TS preflight installed the DerivedData .app the moment the build log
printed "Build Succeeded", racing xcodebuild's CodeSign phase. The result was
an unsigned bundle, which iOS 26+ simulators refuse to launch ("denied by
service delegate (SBMainWorkspace)"), so the app never started and CDP never
connected.

- ios.ts: ensureSigned() verifies the .app signature before install, waits
  briefly for codesign to finish, and ad-hoc signs as a fallback.
- preflight.ts: restore tsconfig.json / Podfile.lock in a finally (plus
  SIGINT/SIGTERM) so a run that fails before the end no longer leaves a
  polluted tsconfig.json that bricks the next ts-node run (TS5098).
@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 added team-perps Perps team type-bug Something isn't working labels Jun 3, 2026
@mm-token-exchange-service mm-token-exchange-service Bot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Jun 3, 2026
@abretonc7s abretonc7s marked this pull request as ready for review June 3, 2026 12:32
@abretonc7s abretonc7s requested a review from a team as a code owner June 3, 2026 12:32
@github-actions github-actions Bot added size-M risk:low AI analysis: low risk labels Jun 3, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.84%. Comparing base (c24bb5f) to head (24ee8cf).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #31011      +/-   ##
==========================================
- Coverage   82.84%   82.84%   -0.01%     
==========================================
  Files        5574     5574              
  Lines      143873   143873              
  Branches    33409    33409              
==========================================
- Hits       119187   119185       -2     
- Misses      16693    16695       +2     
  Partials     7993     7993              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@abretonc7s abretonc7s changed the title fix(agentic): sign iOS build before install; always restore setup-noise fix(agentic): harden preflight launch and fixture setup Jun 3, 2026
@github-actions github-actions Bot added size-L and removed size-M labels Jun 3, 2026
Comment thread scripts/perps/agentic/preflight/modules/ios.ts
Comment thread scripts/perps/agentic/preflight/preflight.ts Fixed
Comment thread scripts/perps/agentic/start-metro.sh
@github-actions github-actions Bot added risk:medium AI analysis: medium risk and removed risk:low AI analysis: low risk labels Jun 3, 2026
Comment thread scripts/perps/agentic/preflight/modules/runtime.ts Outdated
Comment thread app/core/AgenticService/AgenticService.ts
@mm-token-exchange-service mm-token-exchange-service Bot removed the INVALID-PR-TEMPLATE PR's body doesn't match template label Jun 3, 2026

@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 1 potential issue.

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 f1945a3. Configure here.

Comment thread scripts/perps/agentic/preflight/modules/runtime.ts
@abretonc7s abretonc7s enabled auto-merge June 3, 2026 16:13
@abretonc7s abretonc7s added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Jun 3, 2026
@github-actions github-actions Bot added size-XL and removed size-L labels Jun 3, 2026
@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: 90%
click to see 🤖 AI reasoning details

E2E Test Selection:
All 14 changed files are confined to developer/agentic tooling infrastructure with no impact on production app code or E2E test flows:

  1. AgenticService.ts/test.ts: The AgenticService is a developer-only fixture setup service (used in dev/debug builds for E2E test wallet initialization). Changes improve reliability of fixture vault unlock (fallback keyring unlock for interrupted setups), batch HD account creation, and add timeout wrappers. These are internal fixture plumbing improvements - they don't change any production app UI, navigation, controllers, or user flows. The service is only imported by App.tsx (conditionally for dev mode) and its own test files.

  2. package.json: Only changes are to a:ios, a:android, a:setup:ios, a:setup:android script aliases - adding --project tsconfig.json to ts-node commands. These are developer convenience scripts, not app build configuration.

  3. scripts/perps/agentic/: All changes are to developer tooling scripts (preflight orchestrator, Metro startup, wallet setup, build cache tests). These are not part of the app bundle and don't affect any E2E test execution paths.

No production app code was modified. No E2E test selectors, page objects, or test flows were changed. No controllers, Engine, navigation, or UI components were touched. The changes are purely developer tooling improvements for the agentic/perps development workflow.

Since the AgenticService changes improve fixture setup reliability (fixing interrupted vault state), they could actually make existing E2E tests MORE reliable, but don't require specific test tags to validate - the unit tests in AgenticService.test.ts cover the new logic.

Performance Test Selection:
No production app code was changed. All changes are confined to developer tooling scripts and the AgenticService fixture setup infrastructure. No UI components, data loading, state management, or critical user flows were modified. No performance impact expected.

View GitHub Actions results

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

Approving. The branch addresses the preflight/cache and fixture race paths with focused changes and adds targeted coverage for the cache reinstall behavior.

@abretonc7s abretonc7s added this pull request to the merge queue Jun 3, 2026
Merged via the queue into main with commit 0bffa7a Jun 3, 2026
160 of 163 checks passed
@abretonc7s abretonc7s deleted the fix/agentic-preflight-codesign-race branch June 3, 2026 17:37
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

risk:medium AI analysis: medium risk size-XL skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-perps Perps team type-bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants