Skip to content

feat(perps): agentic lifecycle actions and multi-device support#28709

Merged
abretonc7s merged 6 commits intomainfrom
feat/perps-agentic-lifecycle-tooling
Apr 13, 2026
Merged

feat(perps): agentic lifecycle actions and multi-device support#28709
abretonc7s merged 6 commits intomainfrom
feat/perps-agentic-lifecycle-tooling

Conversation

@abretonc7s
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s commented Apr 13, 2026

Description

Add app lifecycle actions (app_background, app_foreground, app_restart) to the agentic tooling with platform-aware implementations (iOS simctl + Android adb). Enable multi-device CDP target discovery so status probes all targets across both platforms. Fix preflight to reuse a healthy Metro instance (curl /status check) and warn on platform mismatch instead of failing. Add --input key=value flag to validate-recipe.js.

Also fixes switch/end nodes bypassing when guards (caused TypeError on default config), and adds automatic run.log capture for every recipe execution.

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

Feature: Agentic lifecycle actions and multi-device support

  Scenario: run app-lifecycle recipe in dry-run mode
    Given the agentic tooling is available

    When user runs validate-recipe with app-lifecycle.json --dry-run
    Then recipe parses and validates without errors

  Scenario: CDP bridge status shows multiple targets
    Given both iOS simulator and Android emulator are running

    When user runs cdp-bridge.js status
    Then both platform targets are listed

  Scenario: lifecycle actions execute per platform
    Given the app is running on iOS simulator

    When user triggers app_background action
    Then the app moves to background via simctl

Screenshots/Recordings

Before

N/A — new tooling feature

After

  • node validate-recipe.js recipes/app-lifecycle.json --dry-run — parses OK
  • Lifecycle actions validated on both iOS simulator and Android emulator
  • Multi-device target discovery working across platforms

Validation Recipe

app-lifecycle.json (20 nodes — short background, long background, restart)
{
  "title": "App Lifecycle — validate data survives background, long background, and restart",
  "description": "Reference recipe demonstrating three lifecycle stress levels: short background (within WS grace period), long background (exceeds grace period, forces full WS reconnection), and full app restart. Use as a template for PR recipes that need lifecycle validation.",
  "inputs": {
    "symbol": { "type": "string", "default": "BTC" },
    "short_background_ms": { "type": "number", "default": 5000 },
    "long_background_ms": { "type": "number", "default": 30000 },
    "test_short_background": { "type": "boolean", "default": true },
    "test_long_background": { "type": "boolean", "default": true },
    "test_restart": { "type": "boolean", "default": false }
  },
  "validate": {
    "workflow": {
      "pre_conditions": ["wallet.unlocked", "perps.feature_enabled"],
      "entry": "nav-market-list",
      "nodes": {
        "nav-market-list": { "action": "navigate", "target": "PerpsTrendingView", "next": "wait-markets" },
        "wait-markets": { "action": "wait_for", "assert": { "operator": "gt", "field": "count", "value": 0 }, "next": "baseline-price" },
        "baseline-price": { "action": "eval_async", "description": "Baseline — confirm markets and price data loaded", "next": "short-background" },
        "short-background": { "action": "app_background", "when": "test_short_background", "duration_ms": "{{short_background_ms}}", "next": "short-foreground" },
        "short-foreground": { "action": "app_foreground", "next": "wait-post-short" },
        "wait-post-short": { "action": "wait_for", "next": "verify-post-short" },
        "verify-post-short": { "action": "eval_async", "description": "Confirm markets + price survive short background", "next": "long-background" },
        "long-background": { "action": "app_background", "description": "Exceeds WS grace period", "duration_ms": 30000, "next": "long-foreground" },
        "long-foreground": { "action": "app_foreground", "next": "wait-post-long" },
        "wait-post-long": { "action": "wait_for", "next": "verify-post-long" },
        "verify-post-long": { "action": "eval_async", "description": "Confirm markets + DEXs recover after WS reconnection", "next": "restart-app" },
        "restart-app": { "action": "app_restart", "when": "test_restart", "next": "detect-post-restart" },
        "...": "remaining restart/unlock/verify nodes",
        "done": { "action": "end", "status": "pass" }
      }
    }
  }
}

Validation Logs

Command:

node scripts/perps/agentic/validate-recipe.js \
  scripts/perps/agentic/teams/perps/recipes/app-lifecycle.json
Full output (11/17 passed, 6 skipped — iOS)
Running recipe: App Lifecycle — validate data survives background, long background, and restart
Team: perps
Pre-conditions: wallet.unlocked, perps.feature_enabled
Workflow nodes: 20

Pre-conditions: PASS

[nav-market-list] navigate to PerpsTrendingView
  result: {"navigated":"PerpsTrendingView",...}
  PASS

[wait-markets] wait for condition
  result: {"count":291}
  PASS

[baseline-price] Baseline — confirm markets and price data loaded
  result: {"found":true,"price":"$71,046"}
  PASS

[short-background] Short background — within WS grace period, cache should be preserved
  backgrounded for 5000ms
  PASS

[short-foreground] foreground app
  foregrounded (io.metamask.MetaMask)
  PASS

[wait-post-short] wait for condition
  result: {"count":291}
  PASS

[verify-post-short] Confirm markets + price survive short background
  result: {"found":true,"price":"$71,058"}
  PASS

[long-background] Long background — exceeds WS grace period, forces full reconnection
  backgrounded for 30000ms
  PASS

[long-foreground] foreground app
  foregrounded (io.metamask.MetaMask)
  PASS

[wait-post-long] wait for condition
  result: {"count":291}
  PASS

[verify-post-long] Confirm markets + DEXs recover after full WS reconnection
  result: {"markets":291,"dexs":9,"price":"$71,039"}
  PASS

[restart-app] restart app
  [SKIPPED - when condition did not match]

[detect-post-restart] Detect login vs wallet after restart
  [SKIPPED - when condition did not match]

[check-needs-unlock] evaluate branch
  [SKIPPED - when condition did not match]

[nav-after-restart] navigate to PerpsTrendingView
  [SKIPPED - when condition did not match]

[wait-post-restart] wait for condition
  [SKIPPED - when condition did not match]

[verify-post-restart] Confirm markets reload cleanly after full restart
  [SKIPPED - when condition did not match]

----------------------------------------
Results: 11/17 passed, 6 skipped
Recipe: PASS

Pre-merge author checklist

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
Adds new workflow actions that spawn xcrun/adb processes and changes CDP target selection/reporting, which can affect automation reliability across devices. Also introduces automatic log capture/redaction and new CLI flags that alter runner behavior.

Overview
Agentic workflows can now exercise app lifecycle events. The recipe runner adds new actions (app_background, app_foreground, app_restart) implemented via a new lib/app-lifecycle.js that uses simctl/AppleScript on iOS and adb on Android, and documents these actions plus a new teams/perps/recipes/app-lifecycle.json reference recipe.

CDP and preflight scripts now better support multi-device setups. cdp-bridge.js status probes all discovered Hermes targets (via new discoverAllTargets) and returns either a single object or an array; preflight.sh reuses an already-healthy Metro instance by probing /status and loosens the platform check to a warning when the expected platform target isn’t found.

Recipe execution UX improved. validate-recipe.js adds --input key=value for overriding recipe inputs, --no-log to disable logging, captures console output to run.log with basic redaction, and fixes when guards to apply to switch/end nodes (skipping them safely instead of executing).

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

…c tooling

Add app_background, app_foreground, app_restart actions with platform-aware
implementations (iOS simctl + Android adb). Enable multi-device CDP target
discovery. Fix preflight to reuse healthy Metro and warn (not fail) on
platform mismatch. Add --input key=value flag to validate-recipe.
@abretonc7s abretonc7s requested a review from a team as a code owner April 13, 2026 02:22
@github-actions
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.

@metamaskbot metamaskbot added the team-perps Perps team label Apr 13, 2026
@github-actions github-actions bot added size-L risk-low Low testing needed · Low bug introduction risk labels Apr 13, 2026
@abretonc7s abretonc7s added the skip-e2e skip E2E test jobs label Apr 13, 2026
@github-actions github-actions bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Apr 13, 2026
Switch and end nodes bypassed the when-guard check because
executeWorkflowNode dispatched them directly to executeSwitchNode/
executeEndNode, skipping runExecutableNode which handles when.
This caused a TypeError when test_restart=false (default) because
the switch tried to read result from a skipped node.

Also adds automatic run.log capture — console output is teed to
a log file in the artifacts directory by default. Use --no-log
to disable.
@github-actions github-actions bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Apr 13, 2026
@github-actions github-actions bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Apr 13, 2026
Copy link
Copy Markdown

@cursor cursor bot left a comment

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 44d4fe4. Configure here.

Redact tokens, secrets, passwords, and bearer strings before writing
to run.log to satisfy CodeQL clear-text-logging rule. Also wrap
when-guard skip stats in shouldCountNode check so end nodes don't
inflate total/skipped counts.
@github-actions github-actions bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Apr 13, 2026
Pass formatArgs through origLog/origError too, not just logStream.
CodeQL traces taint from sensitive sources through console.log — by
sanitizing before origLog the taint path is fully broken.
@github-actions github-actions bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Apr 13, 2026
@github-actions
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: 97%
click to see 🤖 AI reasoning details

E2E Test Selection:
All 10 changed files are exclusively within scripts/perps/agentic/ — the perps team's agentic workflow toolkit for CDP-based automated validation. These are developer tooling scripts, not application source code:

  1. README.md: Pure documentation
  2. cdp-bridge.js: Added multi-target 'status' command for CDP
  3. lib/app-lifecycle.js: New file with iOS/Android app background/foreground/restart helpers using xcrun/adb
  4. lib/config.js: Minor fix for IOS_SIMULATOR/ANDROID_DEVICE env var handling (empty string vs undefined)
  5. lib/target-discovery.js: Added discoverAllTargets() for multi-device CDP discovery
  6. lib/workflow.js: Added app_background/app_foreground/app_restart to EXECUTABLE_ACTIONS set
  7. preflight.sh: Improved Metro detection (reuse running Metro) and CDP platform verification
  8. teams/perps/evals/core.json: Added available-dexs eval ref for PerpsController
  9. teams/perps/recipes/app-lifecycle.json: New recipe for app lifecycle stress testing
  10. validate-recipe.js: Added --input/--no-log CLI flags, app lifecycle action handlers, log capture with secret redaction

None of these files affect:

  • The React Native application source code (app/, src/)
  • The Detox E2E test suite (e2e/, tests/)
  • CI/CD workflows (.github/workflows/)
  • Any shared components, controllers, or navigation
  • Performance-sensitive code paths

These are standalone Node.js/bash scripts used by the perps team for agentic validation workflows. They have zero impact on the Detox test suite and no E2E tags need to run.

Performance Test Selection:
No performance-sensitive code is touched. All changes are in scripts/perps/agentic/ which is developer tooling for CDP-based agentic validation workflows. No UI components, state management, data loading, or app initialization code was modified.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

@abretonc7s abretonc7s enabled auto-merge April 13, 2026 07:06
@abretonc7s abretonc7s added this pull request to the merge queue Apr 13, 2026
Merged via the queue into main with commit 6b7f6d2 Apr 13, 2026
63 checks passed
@abretonc7s abretonc7s deleted the feat/perps-agentic-lifecycle-tooling branch April 13, 2026 07:30
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2026
@metamaskbot metamaskbot added the release-7.74.0 Issue or pull request that will be included in release 7.74.0 label Apr 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.74.0 Issue or pull request that will be included in release 7.74.0 risk-low Low testing needed · Low bug introduction risk size-L skip-e2e skip E2E test jobs team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants