Skip to content

New Worker Design#44

Open
nvdtf wants to merge 65 commits intomainfrom
navid/new-worker-arch
Open

New Worker Design#44
nvdtf wants to merge 65 commits intomainfrom
navid/new-worker-arch

Conversation

@nvdtf
Copy link
Member

@nvdtf nvdtf commented Jan 30, 2026

🚀 Dual-Worker Architecture

Architecture Upgrade: Replaces single interval-based worker with dual-worker system (SchedulerHandler + WorkerHandler) enabling parallel request processing and crash recovery


✅ Issues Resolved


📋 Summary

This PR migrates the FlowYieldVaultsEVM worker design from a single interval-based worker that processed one request at a time to a dual-worker architecture. The new system enables parallel processing of multiple requests with automatic scheduling and crash recovery.


🔄 What Changed

Before

  • Single interval-based worker: Processed requests sequentially
    • One PENDING request processed per execution
    • Fixed interval between executions
    • Sequential, one-at-a-time processing
    • No panic recovery

After

  • Dual-worker architecture:
    • SchedulerHandler: Recurrent worker that runs at fixed intervals (1.0s)
      • Crash recovery for failed WorkerHandlers
      • Checks for pending requests
      • Preprocesses requests (PENDING → PROCESSING)
      • Spawns 0 to multiple WorkerHandlers based on available capacity and pending requests
      • Passes request ID to each worker as assigned work
    • WorkerHandler: Per-request worker that processes individual requests
      • Each request gets its own scheduled WorkerHandler
      • Processes request and finalizes status on EVM
      • Removes itself from tracking after completion
      • Safe to panic, will be recovered by SchedulerHandler
  • Parallel processing: Up to maxProcessingRequests (default: 3) requests processed concurrently
  • FlowTransactionScheduler: Native Flow scheduling infrastructure for automatic execution

✨ New Features

Feature Description
Parallel Processing Multiple requests processed concurrently (up to maxProcessingRequests)
🔄 Dual-Worker System SchedulerHandler orchestrates, WorkerHandler executes
🔍 Preprocessing SchedulerHandler validates requests before scheduling (PENDING → PROCESSING)
🔁 Crash Recovery Detects panicked WorkerHandlers and marks requests as FAILED
📊 Capacity Control Configurable concurrent processing limit (maxProcessingRequests: 3)
🎯 Sequential Offsetting Multiple requests from same EVM address offset sequentially to avoid randomization

🏗️ Architecture Changes

Before: Single Worker

┌─────────────────────────────────────┐
│   Single Interval-Based Worker      │
│   - Runs at fixed interval          │
│   - Processes 1 request at a time   │
│   - Sequential execution            │
└─────────────────────────────────────┘

After: Dual-Worker System

┌─────────────────────────────────────────────────────────────────────────────┐
│                              Flow EVM                                       │
│  ┌──────────────┐         ┌───────────────────────────┐                     │
│  │   EVM User   │────────▶│  FlowYieldVaultsRequests  │                     │
│  │              │◀────────│   (Request Queue + Escrow)│                     │
│  └──────────────┘         └─────────────┬─────────────┘                     │
└─────────────────────────────────────────┼───────────────────────────────────┘
                                          │ COA Bridge
┌─────────────────────────────────────────┼───────────────────────────────────┐
│                              Flow Cadence                                   │
│  ┌───────────────────────────────────────────────────────────────────────┐  │
│  │                       FlowYieldVaultsEVM (Worker)                     │  │
│  └───────────────────────────────────────────────────────────────────────┘  │
│  ┌───────────────────────────────────────────────────────────────────────┐  │
│  │     FlowYieldVaultsEVMWorkerOps (NEW)                                 │  │
│  │  ┌─────────────────────┐    ┌─────────────────────────────────────┐   │  │
│  │  │   SchedulerHandler  │───▶│         WorkerHandler               │   │  │
│  │  │   (Recurrent)       │    │   (Per-request, scheduled)          │   │  │
│  │  │   - Crash recovery  │    │   - Processes 1 request             │   │  │
│  │  │   - Checks queue    │    │   - Finalizes status                │   │  │
│  │  │   - Preprocesses    │    │                                     │   │  │
│  │  │   - Spawns 0-N      │    │                                     │   │  │
│  │  │     WorkerHandlers  │    │                                     │   │  │
│  │  └─────────────────────┘    └─────────────────────────────────────┘   │  │
│  │                                                                       │  │
│  │  State: scheduledRequests, isSchedulerPaused                          │  │
│  │  Config: schedulerWakeupInterval (1s), maxProcessingRequests (3)      │  │
│  └───────────────────────────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────────────────────────┘

Request Processing Flow:

  1. User submits request → FlowYieldVaultsRequests escrows funds (status: PENDING)
  2. SchedulerHandler (runs every 1.0s):
    • Perform crash recovery for failed WorkerHandlers
    • Calculates available capacity: maxProcessingRequests - current_in_flight
    • Fetches pending requests from EVM
    • Calls preprocessRequests() to validate and transition PENDING → PROCESSING
    • Spawns 0 to N WorkerHandlers (one per request, up to capacity limit)
  3. WorkerHandler (scheduled per request):
    • Processes single request via processRequest()
    • Executes Cadence operation (create/deposit/withdraw/close YieldVault)
    • Calls completeProcessing() to mark COMPLETED/FAILED on EVM
    • Removes itself from scheduledRequests tracking

🧪 Testing

New Test Suite: run_worker_tests.sh

Comprehensive E2E tests covering:

  • ✅ SchedulerHandler initialization and auto-scheduling
  • ✅ Automated request processing via FlowTransactionScheduler
  • ✅ Parallel processing (multiple WorkerHandlers running concurrently)
  • ✅ Capacity limits (maxProcessingRequests respected)
  • ✅ Pause/unpause scheduler functionality
  • ✅ Stop all scheduled transactions
  • ✅ Multi-user automated processing
  • ✅ Crash recovery for panicked WorkerHandlers
  • ✅ Sequential offsetting for same-user requests

Run Tests:

./local/setup_and_run_emulator.sh && ./local/deploy_full_stack.sh
./local/run_worker_tests.sh
  • ✅ New CI test added that executes ./local/run_worker_tests.sh.

📖 Documentation Updates

  • Updated README with dual-worker architecture diagram
  • Updated design document with SchedulerHandler/WorkerHandler flow
  • Added worker tests documentation
  • Updated configuration tables

@onflow onflow deleted a comment from claude bot Feb 2, 2026
@onflow onflow deleted a comment from claude bot Feb 2, 2026
@onflow onflow deleted a comment from claude bot Feb 4, 2026
nvdtf and others added 2 commits February 4, 2026 15:42
Claude was using `gh api` instead of `gh pr comment` to post reviews,
but `gh api` is not in the allowed tools list, causing the comment
to fail silently.

Changes:
- Add explicit warning to use `gh pr comment` and not `gh api`
- Clarify the command format with a proper code block

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
liobrasil and others added 13 commits February 4, 2026 20:11
Claude was using `gh api` instead of `gh pr comment` to post reviews,
but `gh api` is not in the allowed tools list, causing the comment
to fail silently.

Changes:
- Add explicit warning to use `gh pr comment` and not `gh api`
- Clarify the command format with a proper code block

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@liobrasil liobrasil force-pushed the navid/new-worker-arch branch from 077a42c to 81a66c6 Compare February 24, 2026 17:44
@liobrasil liobrasil force-pushed the navid/new-worker-arch branch from 7519e89 to c6e349f Compare February 24, 2026 22:26
@liobrasil liobrasil force-pushed the navid/new-worker-arch branch from dbb5672 to db29997 Compare February 26, 2026 02:29
Copy link
Collaborator

@liobrasil liobrasil left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants