Repository navigation
tests: the image-cancel test cancels once the first encode has begun - #180
Merged
Merged
Conversation
a_request_cancelled_while_its_images_encode_ends_and_frees_its_slot slept 50 ms after starting its three-image request and then cancelled the session through the cancel registry. Nothing tied that moment to the request. A generation drops any cancel already held for its session as it registers (one meant for the session's previous generation), so on a runner where the request's thread had not registered by then the cancel was lost and the request ran to its 4 tokens: the windows-2025 failure on rc-0.2.0 at 441c3ba. On a starved Mac the same sleep ended before the first encode in 40 runs of 40, where the test passed having cancelled a request that held no image. The test now reads the mock's encode log and cancels when the first encode is in it, holding the log's lock while the cancel goes in so no further encode begins meanwhile. It also checks that the request stopped encoding.
This was referenced Nov 24, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Into
rc-0.2.1(#179).The
windows-2025job onrc-0.2.0at 441c3ba (run 44578431542) failed on one test,a_request_cancelled_while_its_images_encode_ends_and_frees_its_slot, atmedia_admission.rs:189:assert_eq!(out.tokens_generated, 0)sawleft: 4, right: 0. The test started a three-image request on a mock that takes 100 ms an image, slept 50 ms, cancelled the session throughd.cancel_registry().cancel(s)and expected no tokens.Nothing tied the cancel to the request. Two orders give 4 tokens, and both were reproduced by hand with the sleep changed and the state printed at the cancel:
tokens=4 registered_at_cancel=false encodes_begun_at_cancel=0 cancel_left_in_set=false. A generation drops any cancel held for its session as it registers (cancels.remove(&session)ingenerate_streaming_inner, "a cancel aimed at the previous generation … must not stop this one"), so the cancel is gone and the request runs to the end.tokens=4 gen_finished_at_cancel=true cancel_left_in_set=true.The Windows log has only the assertion, so it does not say which. A starved run does: under
taskpolicy -c backgroundon a Mac, in 40 runs of 40 the old test's 50 ms sleep took 115–150 ms and the request had registered but had not begun its first encode. The request falls behind the test thread, not ahead of it, which is the first order one step further; the second needs the test thread to stall past three 100 ms encodes while the request runs on. The dropped cancel itself did not reproduce on the Mac by starvation (0 of 40).This is the test's fault, not the daemon's. The daemon's own cancels from outside a generation (
Request::Cancelinapi.rs,Link::abandoninkeepalive.rs) take a session only when it is in the active set, and the rest cancel from inside the generation's event callback. The test calledCancelSet::canceldirectly, which has no such check.The same 40 starved runs show a second fault: with no encode begun at the cancel (
encodes_total=0), the test passed having cancelled a request that held no image, so "its encoded images were let go" checked nothing.What changes
EngineConfig::media_encode_log) and cancels when the log holds the first encode, instead of after a sleep. An encode is in the log only once the request has registered and is admitting, so the cancel is not dropped, and the request holds an image when it lands.max_live_media: 3.One wait is left on the clock: the test polls the log every 1 ms, and a test thread stalled for more than 200 ms between two polls, while the request's other two encodes run, could still cancel too late. The failure message names how many encodes had begun.
The CHANGELOG is left for the release commit.
Checks (macOS arm64, 18 cores)
cargo clippy -p superfluid --all-targets -- -D warnings: clean, onmainat 3240988.cargo test -p superfluid --test media_admission, 40 runs on 441c3ba: 40 passed, 5 tests each, 4.5 s a run. 10 more onmainat 3240988: 10 passed.taskpolicy -c background cargo test -p superfluid --test media_admission, 40 runs on 441c3ba: 40 passed, 16.6–19.4 s a run.left: 4, right: 0; the new test with the request started 300 ms late passes.Not run: Windows, and the whole
cargo test. This pull request's ownwindows-2025job is the check.