fix(tests): prevent engine loop from calling step() in abort/cancelation tests#1324
Open
fry69 wants to merge 1 commit into
Open
fix(tests): prevent engine loop from calling step() in abort/cancelation tests#1324fry69 wants to merge 1 commit into
fry69 wants to merge 1 commit into
Conversation
…tion tests MockModel lacks .layers attribute, causing scheduler.step() to fail with AttributeError from make_prompt_cache. Adding engine.scheduler.has_requests = lambda: False prevents the engine loop from running step() in tests that test abort/cancellation logic without needing model inference. Fixes test_abort_request_wakes_blocked_stream_outputs and test_generate_cancel_aborts_request which were failing because the engine loop error handler interfered with expected error messages and collector cleanup.
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.
This fixes two new errors when running
Please advise if this is the correct approach. For my still limited understanding about the codebase, it sounds plausible.
Below is the message from my coding agent:
MockModellacks.layersattribute, causingscheduler.step()to fail withAttributeErrorfrommake_prompt_cache. Addingengine.scheduler.has_requests = lambda: Falseprevents the engine loop fromrunning step()in tests that test abort/cancellation logic without needing model inference.Fixes
test_abort_request_wakes_blocked_stream_outputsandtest_generate_cancel_aborts_requestwhich were failing because the engine loop error handler interfered with expected error messages and collector cleanup.Update: I asked the agent:
Would it be a better approach add the new
.layersattribute to theMockModelto fix the root cause of this problem, rather than preventing the symptoms? Or is that a worse approach? Please explain.It didn't like this approach much:
Both approaches have trade-offs. Here's the analysis:
Approach A — Add
.layerstoMockModel:This fixes the
make_prompt_cachecrash atcache.py:34but doesn't stop there. The prefill pipeline immediately continues to createmx.array(prefill_tokens), callself.model(input_arr)(which returns aMagicMock), then tries to extract logits, embeddings, etc. from that mock object. You'd need to mock ``.layers, .get_input_embeddings,the forward pass return type, and potentially more — it's a deep rabbit hole with fragile, high-maintenance mocks.Approach B —
has_requests = lambda: False(current fix):These tests test abort/cancellation logic, not token generation. Preventing
step()from running is semantically correct — the engine loop shouldn't be trying to generate tokens with a mock model. The pattern is already established attest_engine_core.py:586, so it's consistent.Approach B is better here because it's simple, targeted, and doesn't require building fragile mock infrastructure that would need ongoing maintenance as the prefill pipeline evolves.