Skip to content

Add isolated extension workers for native shell panes - #1089

Open
demrom wants to merge 21 commits into
holzschu:masterfrom
demrom:feature/extension-shell-workers
Open

demrom wants to merge 21 commits into
holzschu:masterfrom
demrom:feature/extension-shell-workers

Conversation

@demrom

@demrom demrom commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Native commands share a-Shell's process. This adds a public pane API (ShellWorkers/NativePane.h) that runs each command in its own Generic Non-UI extension, with separate cwd, environment and socket streams. Cancel and release terminate the worker before freeing its slot, and a lost worker reports 137.

Pool size

The mini target bundles ten workers. By default the host runs one per physical core (six on an iPhone 16 Pro). The new "Shell workers" setting changes that up to the bundled count; a request beyond the cap gets ENOSPC. ShellWorkers/generate-targets.sh [N] regenerates the targets and the setting for a different bundled count.

Testing

  • A current three-worker device build passed 11 worker-pool-check cases plus four ios_system spawn/nested-environment cases and the next ordinary command after each case, plus both redirected-input and piped-input gzip/wc gates; each pipeline counted 2,000,633 bytes, matching the thread path. The same suite passed in the Simulator with released Dash code and a login profile containing alias exit=clear.
  • iPhone 16 Pro: isolation, delayed input, capacity, cancellation, process loss, peer survival and reuse pass. The default cap is six (ENOSPC on the seventh), a setting of 10 gives ten.
  • Simulator: the same checks pass with sixteen bundled workers.
  • Idle workers use 0.0% CPU; status checks poll the socket locally. A running command no longer spins in ios_waitpid with ios_system#188.

Why one worker per core

A fixed CPU job on the phone, each run starting cold (nominal thermal state, on the charger):

Workers 1 2 4 6 8 10
Speedup 1.00 1.91 3.22 4.15 4.31 4.23

The A18 Pro has 2 performance and 4 efficiency cores, and the results fit speedup ≈ P + 0.57 × E, where P and E are the busy performance and efficiency cores. That tops out at 4.26 once all six cores are busy. More workers add nothing for CPU-bound work. Under ten minutes of continuous load the phone reached serious thermal state within 22 seconds and ran 8% below the cold rate.

Other loads peak elsewhere. Above ten, the phone rows run several threads inside each of the ten workers:

Load Phone: throughput by streams Peak
CPU-bound 6: 4.15x, 10: 4.23x, 20: 3.86x, 30: 3.74x (20 and 30 started warm) 6 to 8
File I/O (64 KiB write, fsync, read) 1: 464, 6: 2125, 10: 2258, 20: 2333 ops/s 10
Mostly idle (20 ms CPU every 200 ms) 10: 0.49, 40: 1.84, 80: 2.29, 160: 2.69 jobs/s not reached

Mostly idle jobs keep gaining, but each job slows down: 5% at 40 streams, 66% at 80 and 2.9x at 160, where the phone reached serious thermal state. That is why the setting goes above the core count.

In the Simulator on a 14-core Mac, 1,024 workers launched and finished the mostly idle job; throughput levelled off at 512 (6.07 jobs/s), and file I/O peaked at 16 workers. A 2,048-worker run stopped at 1,260 with EBADF. These numbers show the pool mechanics scale, not what an iPhone can sustain.

Dependencies

Needs ios_system#180 through #184 and dash_iOS#1 and #2, including libedit. Merge before #1091.

Limits

Workers hit the per-process memory limit early. A worker allocating 64 MiB was killed after about 27 MiB of footprint, and two idle workers that had reached about 28 MiB during a CPU run were killed later; the device log reports killed by jetsam reason per-process-limit for all three. Memory-heavy commands should stay in the app process. Background lifetime and App Store review are untested.

A worker self-probe using task_info(TASK_VM_INFO) for phys_footprint plus os_proc_available_memory() measured a 35 MiB budget. I ran the same bare codex binary (0.160.0) in the main a-Shell process and a fresh extension worker in a separate a-Shell test build on an iPhone 16 Pro; retained device receipts report iOS 27.0.1 (24A446). Xcode Activity Monitor measured a main-app startup maximum of 78.2 MiB over eight physical-footprint samples at a median interval of 1.036 seconds, with no lifetime peak available. The worker produced zero startup samples and lost its pane with synthetic status 137, without a matching jetsam record to establish the cause. Please enable Increased Memory Limit (com.apple.developer.kernel.increased-memory-limit) for each worker extension App ID and regenerate its provisioning profile; I will add the worker entitlement after those profiles support it and remeasure the resulting limit.

@demrom
demrom force-pushed the feature/extension-shell-workers branch from e3c05e2 to 71c4e4c Compare October 18, 2026 16:54
@demrom
demrom marked this pull request as ready for review October 18, 2026 16:54
demrom added 15 commits October 18, 2026 21:28
…Settings

The host runs min(worker_limit setting, hw.physicalcpu, bundled ShellWorkerCount) workers at once and returns ENOSPC beyond that. ShellWorkers/generate-targets.sh (POSIX sh and awk, like the other scripts of the repo) keeps the extension targets and the Settings list in line with ShellWorkerCount. The new Settings strings are localized in the existing Root.strings files. tests/worker-pool.m gains a limit check.
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.

1 participant