Worker Process Manager

This part manages a pool of background worker processes. It sends test files to these workers for execution and handles their results.

Columns are parts of the code, grouped by process. Read top to bottom. Solid arrow: hands work over. Dashed: the reply. Purple: crosses between processes. Hook: work inside one part. Dashed boxes repeat. Hover a column name or a step for its full text.

MAIN PROCESSWORKER-FILE PROCESSMAIN PROCESSWORKER-FILE PROCESSLoop for each typecheck batchProcess test files in parallelExecute VM threads in parallelReinitialize around dev serverCreate thread poolBuild Tinypool worker threadsCreate fork pool factoryCreate child process poolBuild Tinypool child processesCreate threads pool factoryCreate standard threads poolBuild standard threads poolCreate forks pool factoryCreate standard forks poolBuild standard forks poolRun typecheck batchesSubmit VM fork jobSend log messageHandle user console logProcess console logQue…Store queued fileEmit enqueue lifecy…Fin…Save snapshot resultsAdd snapshot to man…Fin…Pass coverage metadataReport coverage to…Submit VM thread job
Pool Factories
VM Threads
VM Forks
Standard Pools
Typecheck
Worker Log
RPC Handlers
Worker Final
1Reinitialize test runner around dev server — The system reinitializes the test runner around a development server, clearing any previous state and preparing for a fresh run. It unregisters watchers, clears timers, and creates the necessary state, cache, and snapshot managers. Reporters are initialized and server callbacks are awaited before proceeding.
2Create worker thread pool — A worker pool is created using threads to run test files in virtual machine contexts. Thread counts are determined by available processors, with options to force single-threaded execution if needed. The pool is set up with communication channels and error handling for worker termination.
3Create child process pool — A separate worker pool is created using child processes to run tests in isolated forks. The default worker count adjusts based on watch mode, typically using half the available processors. Each worker is configured with experimental flags and memory limits for recycling.
4Create standard thread pool — Standard pool creators build a thread-based worker pool for general test execution. This pool handles the common case of running tests in parallel threads. Configuration options are passed through and cached for efficiency.
5Create standard fork pool — Standard pool creators build a fork-based worker pool using child processes. This provides an alternative execution environment for tests that need process isolation. The pool is configured with the same options as other pools.
6Run typecheck batches for projects — The typecheck manager runs type checking batches across all projects, waiting briefly to detect if a watcher triggered the run. Results are either replayed from existing checks or new checks are started. Type checking runs in parallel with test execution.
7Submit VM fork job with channel — A test file job is submitted to the virtual machine fork pool with a communication channel. The worker ID is incremented and context is sent to the worker process. Any termination or cancellation issues are recorded for error handling.
8Send log message to main process — Log messages from the worker process are sent back to the main process through the communication channel. This includes console output and other diagnostic information from the running tests. The log sender packages messages for transmission.
9Handle user console log — The main process receives and handles user console log messages from workers. These messages are processed and made available for reporting and output. The handler stores the log information for later display.
10Queue file for test run — When a worker starts collecting tests, the file is queued for the test run lifecycle. In collect mode, the file is stored directly in state. In run mode, the test run enqueue lifecycle event is emitted.
11Store queued file in state — The main process stores the queued file information in its state or emits the test run lifecycle event. This tracks which files are being processed by workers. The state is updated to reflect the current queue.
12Finalize snapshots and restore state — After a suite run completes, the worker records heap usage and finalizes file snapshots. Snapshot results are sent to the main process for storage. The current task state is restored to its parent context.
13Add snapshot result to manager — The main process adds the worker's saved snapshot result to the main snapshot manager summary. Coverage metadata from the worker suite is passed to the coverage provider. No file input or output occurs during this snapshot storage.
14Submit VM thread job with port — A test file job is submitted to the virtual machine thread pool with a transferred communication port. Files are converted to path strings and sent with the pool type identifier. Both communication ports are closed after the job completes.
STEP · hover for full text