You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(agentic): improve preflight visibility and CDP discovery resilience (#28785)
## **Description**
Improve the mobile agentic preflight scripts so they are more reliable
on slower environments and easier for humans to follow during
long-running stages.
### Why
- CDP discovery could fail too early while polling Metro `/json/list`.
- Long-running preflight steps were noisy and hard to debug from the
main console output alone.
### What changed
- `scripts/perps/agentic/lib/target-discovery.js`
- retry `/json/list` discovery before failing
- support `CDP_TIMEOUT`
- support `CDP_DISCOVERY_RETRIES`
- `scripts/perps/agentic/preflight.sh`
- add per-stage logs under `PREP_LOG_DIR` (default:
`.agent/preflight-logs`)
- log deps, pod install, CDP, and wallet setup separately
- print each stage log path when the stage starts
- keep stdout concise while preserving detailed logs
- `scripts/perps/agentic/app-state.sh`
- `scripts/perps/agentic/setup-wallet.sh`
- inherit the same CDP retry knobs
## **Changelog**
CHANGELOG entry: null
## **Related issues**
Fixes: N/A
## **Manual testing steps**
```gherkin
Feature: Mobile preflight reliability and observability
Scenario: Clean preflight succeeds in a fresh environment
Given a MetaMask Mobile worktree prepared for iOS development
When I run `bash scripts/perps/agentic/preflight.sh --platform ios --clean --wallet-setup`
Then the app build/install succeeds
And Metro is reachable on the configured port
And CDP connects successfully
And wallet setup completes successfully
Scenario: Warm preflight succeeds in a reused environment
Given the same worktree is already prepared
When I run `bash scripts/perps/agentic/preflight.sh --platform ios --wallet-setup`
Then CDP connects successfully
And wallet setup completes successfully
Scenario: Cross-environment validation succeeds
Given the same script changes are applied in more than one environment
When I run the clean and warm preflight flows
Then the preflight output remains readable
And the stage logs are written consistently
And CDP discovery remains stable
```
## **Screenshots/Recordings**
### **Before**
- N/A — script/logging change
### **After**
- N/A — script/logging change
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **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.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Low risk: changes are confined to local developer/agentic shell and
Node scripts, mainly adding logging and retry/timeout knobs. Main risk
is regressions in preflight automation due to altered timeouts, paths,
or command output handling.
>
> **Overview**
> Improves the `agentic` preflight flow by adding **per-stage log
files** (deps install, CocoaPods, builds, CDP polling, wallet setup)
with a configurable `PREP_LOG_DIR`, keeping console output concise while
surfacing where to look for full details.
>
> Makes CDP target discovery more resilient by adding configurable
**fetch timeouts and retries** (`CDP_TIMEOUT`, `CDP_DISCOVERY_RETRIES`)
for Metro `/json/list` polling, and propagates these env knobs through
`app-state.sh` and `setup-wallet.sh`. Preflight’s CDP wait loop now
captures each status attempt to a log and prints more actionable
diagnostics on timeout (including probing 8081 vs the configured port).
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
4684576. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
0 commit comments