- WorkerPool thread pool deleted; RenderManager defaults to the Processes backend (oak-worker children), Threads kept as a test-only inline dispatcher; audio tickets stay in-process until S3. - Onscreen path reads worker shm slots directly: BGRA8 slot format, RenderedFrame::Shm wrapped into the display buffer (single disclosed GPU-staging memcpy), scopes analyze BGRA8; the long-lived full-res / thumbnail paths take the counted slot_to_vec copy and release. - Playback pre-render window: forward 120 frames (configurable) fed to the PreviewScheduler at Playback priority, interleaved across workers, cached in shm slots until the playhead consumes them; generation-based invalidation cancels and releases on edits. - oaktask export and oak-cli run on private ProcessDispatchers (fixed a pump-while-locked self-deadlock in the export loop); facade get_frame handles ShmFrame payloads. - Acceptance: preview path main_heap_frame_copies == 0 with spawned workers, CLI transcode/render verified end to end.
oak-worker (Rust)
Headless render worker process — the Rust rewrite of worker/workermain.cpp
(contract: engine/include/oakengine/worker.h and
engine/include/oakengine/ipc.h).
Build and test
cargo build --release # binary: target/release/oak-worker
cargo test # unit + integration tests
The worker is self-contained (M14 R2): the whole runtime is compiled
into this binary and links the module crates directly — no liboakengine
dylib is needed at build or run time.
src/worker.rsis the port ofengine/src/capi/worker.cppoakengine_worker_main()and owns the whole runtime: render backend selection through the oakrender crate's direct Rust API (dynamic → OpenGL fallback), the startup handshake and the NDJSON control loop. Since M15 S1 it also renders for real:load_graphdeserializes the snapshot throughoaknode::serializer, andrender_frame/render_batchrender throughoakrender::eval(generated frames, footage decode via oakcodec/ffmpeg, montage compositing) directly into the main-assigned shared-memory slots.src/ipc.rsis a shim re-exportingoakrender::ipc(M15 S1): the NDJSON protocol and the shared-memory frame-slot transport moved to the oakrender crate so both ends of the pipe link one copy (the main-process dispatcher inoakrender::procpoolcreates the segments; this worker attaches to them).
The oakrender module crate (../oakrender) is a plain Rust dependency;
it depends on ocio-rs with the bundled feature, whose first-time build
fetches a vendored OpenColorIO dependency (sse2neon) from github.com. On
networks without github access, build with a shared target directory that
already contains a completed oakrender build tree, e.g.:
CARGO_TARGET_DIR=/path/to/oak/crates/oakrender/target cargo build --release
What the worker does
Same flow as the C++ main, in the same order:
- parse
--backend <name>(defaultopengl;noneskips renderer creation and the process exits 1, like the C++ main;cpuis the M15 headless render mode — no renderer, but the session stays fully operational and renders through the CPU evaluation path). - initialize the render backend (inside
src/worker.rs): the oakrenderDisplayRendererdirect Rust API, falling back to the direct OpenGL renderer exactly like the C++create_renderer()fallback chain. Then the runtime services load (color-manager default config, the oakplugin render executor). - write the startup handshake (protocol version 1, empty shared-memory geometry — same as the C++ worker's startup handshake; the parent creates the segments and announces their geometry in its reply).
- serve the NDJSON control loop on stdin/stdout until a
shutdownmessage or EOF:handshakeattaches the announced shared-memory frame-slot pools through the real transport and answershello_caps(protocol v2: supported slot formats + max slot size);load_graphdeserializes the graph snapshot;render_framerenders one frame into an acquired slot;render_batchrenders a batch of main-assigned-slot tickets (batch_acceptedclaim confirmation, then oneframe_ready/frame_failedper ticket);cancel/shutdownare dispatched by the session. Responses are one compact JSON line per message.
Implemented vs stubbed (nothing is faked)
Real: argument parsing, render backend initialization (real wgpu
renderer, dynamic → OpenGL fallback), runtime initialization (color
config + oakplugin render executor), startup handshake, NDJSON framing,
message validation (protocol version, handshake geometry, load_graph
file existence/size), the shared-memory frame-slot transport
(oakrender::ipc — POSIX shm_open/mmap/munmap/shm_unlink, the
SPSC ring buffer and the frame-slot pool with the exact version-1 shared
layout; a handshake genuinely attaches the output and input pools),
graph deserialization (oaknode::serializer::load, plus the minimal
{"project_copy":N} identity payload), frame rendering into shm
slots (render_frame v1 + render_batch v2: generated frames,
footage decode, montage compositing, end-of-pipe F32→BGRA8 conversion),
unknown-type/malformed-message errors, shutdown/EOF termination.
Deferred to M15 S2/S3 (documented in src/worker.rs): the loaded
project's node-graph render path (plugin-node evaluation per graph
snapshot update) — today tickets render from their wire spec
(montage/footage/generate), which covers the preview pipeline.
Deviation from the C++: the startup handshake omits gl_major/
gl_minor — the oakrender module exposes no GL context version (the C++
worker reads them off its QOpenGLContext).
Crash-isolation test hooks
The batch render path honors two environment variables used by the
crash-isolation integration tests (tests/procpool_integration.rs):
OAK_WORKER_CRASH_ON_TICKET=<n>— raiseSIGSEGVwhile rendering ticketn(like a real plugin crash).OAK_WORKER_CRASH_MARKER=<path>— when the marker file exists the crash is skipped; the hook writes the marker before dying, making the crash one-shot so the restarted worker renders the re-queued frame.
They are test-only; unset in production.
Layout
src/
main.rs argv --backend scanning (default opengl; last flag wins);
forwards to worker::worker_main
worker.rs the real worker runtime: backend selection (oakrender
DisplayRenderer, dynamic -> OpenGL fallback), WorkerSession,
handshake + NDJSON loop, real load_graph + render_frame +
render_batch (M15 S1)
ipc.rs shim re-exporting oakrender::ipc (M15 S1: both pipe ends
link one copy of the protocol + shm transport)
tests/worker.rs binary-level tests (--backend none exit 1;
--backend cpu handshake + clean exit)
tests/procpool_integration.rs M15 S1 end-to-end: real workers spawned by
oakrender::procpool::ProcessDispatcher — batch
renders into shm slots, crash isolation with
restart + re-dispatch, zero-copy assertions
The NDJSON control-loop behavior is exercised in-process in src/worker.rs
against the local real shared memory (--backend none / --backend cpu
sessions, no GPU needed); tests/procpool_integration.rs drives real
worker processes end-to-end through the main-process dispatcher. Run the
binary against a created segment to see the real attach path:
target/release/oak-worker --backend cpu <<< '{"type":"shutdown"}'
M15 S2 status
The process-isolated backend is now the default RenderManager
backend; the in-process render thread pool was deleted (the app drives the
dispatcher from its UI tick and from blocking ticket waits, and the
pre-render window feeds the scheduler ahead of the playhead). The worker
binary is located at target/debug/oak-worker next to the main executable
during development (or via OAK_WORKER_BIN / DispatcherConfig::worker_bin),
and bundled alongside the main binaries by the packager (root Cargo.toml).