mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-28 09:09:39 +01:00
* Helper host: video protocol types, reply rules and discovery Part of RFC-0031, phase 1. The host side of docs/video-helper-protocol.md that needs no process: the messages, what to do with each reply, and finding the program. Starting the helper and the client come next. - video::wire: encode.open/frame/flush/close, cancel, hello and the replies, as the page documents them; control lines are at most 1 MiB. - video::jobs: job and frame ids, the 8 frame / 256 MiB budget and the "What EffectCraft does with each reply" table (accept, drop, job error, protocol break) as plain logic. - video::check_hello and find_video_helper: the version and app_min checks, and the program is looked for only in helpers/ next to the executable. Effect-helper scans now skip it. * Helper host: video helper client, stand-in helper and gate tests Part of RFC-0031, phase 1. Starts a video helper and runs encode jobs on it, following docs/video-helper-protocol.md and the reply rules added in the previous commit. - video::client: VideoHelper starts the program, checks its hello, opens encode jobs, sends pictures (waiting when 8 frames or 256 MiB are out), flushes, cancels and closes. Packets are copied out of the exchange file as they arrive. A crash, hang or broken reply stops the helper and fails the export; 3 stops turn it off. A refused job ends that job only. - Stopping kills the helper process and waits at most 5 s, then drops the exchange file so a stray process can't touch a reused region. The spec no longer promises a process-group or job-object kill, which needs unsafe code; its wording follows what is implemented. - tests/it/video.rs: a stand-in helper (this test binary, driven by a scenario) and 19 gate checks: crash, hang, bad and out-of-order replies, out-of-bounds packets, version mismatch, missing helper, lost device, packet_too_large as a job error, cancel, ignored cancel, 3 stops and retry. * Helper host: harden the video client against a misbehaving helper Review fixes on the video client and its tests. - Packets in one reply may not add up to more than their region, so repeated references to the same bytes can't make the host copy them many times. The reader's queue is bounded; a helper that floods it waits on its own pipe. - A picture is sized with checked arithmetic and refused over 256 MiB before any layout or exchange file growth; an encode.open that can't be written is refused before the job, its ids and regions exist. - Waits end at their deadline even while replies keep arriving, a poll looks at a bounded number of late replies, the flush batch and encode.flushed share one timeout, and a timeout too long to represent no longer panics. - close is private: a job is closed only after encode.flushed or cancelled. An unsent frame is given back when writing its planes fails; a failed copy of packets stops the helper without counting it as a crash. - Contents/Helpers is searched only for an executable in Contents/MacOS. An incomplete base64 group is rejected. - Tests assert the protocol diagnostic of each malformed reply and cover the flood, the flush deadline, oversized pictures and an oversized encode.open. The spec table drops every reply except cancelled for a failed job that has not been cancelled yet. * Helper host: allow one encoder job at a time on a video helper open_encoder accepted a second job while the first was open. If the first job then reported an error while the client was waiting on the second, the error was dropped and its caller only saw "no such video job". A second open is now refused with a request error until the first job is finished or cancelled, so each job's error reaches its own caller. The receiver state machine still tracks several jobs; only the client API is single-job. The gate test refuses a second open while one is active and accepts a new one after finish and after cancel. * Helper host: reject malformed base64 padding, align two protocol notes base64_decode stripped every trailing "=", so "====" decoded to an empty codec configuration that open_encoder then accepted. It now accepts at most two "=" and only when the length is a multiple of 4. The protocol page said job ids are never reused even after a restart, but the counter is per process, and said nothing about replies that were already queued when the frame timeout passed. Both now describe what the client does. * Helper host: fix two code comments about job id reuse The comments on NEXT_JOB and Jobs::new said ids are never reused across helper processes or restarts. The counter is per process and a new helper starts from the highest id opened so far, so the comments now say that, matching docs/video-helper-protocol.md. * Helper host: cap the encoder delay a video helper may report A helper-reported delay sized the flush region (and the exchange file) with unchecked arithmetic. A delay over 64 is now a protocol break, the flush region uses checked arithmetic, and the protocol page says so. Also moves a test doc comment back onto the test it describes. --------- Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>