Repository navigation
fix(core): reject a page selection that matches no page - #61
Merged
JJJYmmm merged 1 commit intoOct 1, 2026
Merged
Conversation
parse_pages fell back to the default page window whenever a selection produced no indices, but five of its six callers only reach it with a spec the user supplied, and save_view substitutes "1" first. An out-of-range page, a 0 (the API is 1-based) or a reversed range therefore rendered the first pages of the document and reported those pages back as the selection. The fallback now applies only to a blank spec, and a non-blank spec that matches nothing raises ValueError, which visualize already turns into a tool error and which save_view now catches. save_view's own guard, reachable now only for a blank spec on a zero-page document, gets the same wording.
Collaborator
|
ty! |
3 tasks done
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.
What changed
parse_pages(src/capabilities/core/qwen_mm_plugins_core/renderers/__init__.py:175) ended by returning the firstDEFAULT_MAX_PAGESpages whenever a selection produced no indices. It reads as the default for a missing spec, but five of the six callers only callparse_pageswhen the user supplied one (pdf.py:32,data.py:42,drawio.py:29,nifti.py:143,web.py:87), and the sixth,save_view.py:66, substitutes"1"for an omittedpagesbefore calling it. So it only ever fired for a selection that matched no page, and answered with the first pages of the document.What a user sees: on a 4-D NIfTI holding 3 volumes,
visualize(file_path=vol.nii, pages="9")returned all 3 volumes under the lineSelected volumes: pages (1, 2, 3); indices (0, 1, 2) (of 3), with nothing to say the request had been dropped.pages="0"and the reversed rangepages="3-1"did the same. Throughsave_viewon a PDF, the same kind of input wrote PNGs for pages nobody asked for.A blank spec still returns the default page window. A non-blank spec that matched no page now raises
ValueError.visualize.handlewraps the renderer call for a local file (visualizers/visualize.py:93), so the model readsError rendering .nii file: no pages selected from '9' (document has 3 page(s))instead of a substitution that contradictedsave_view's own error string andsrc/capabilities/core/skill/SKILL.md:42.save_viewhad written that error string but could not reach it for a non-blank spec:parse_pagessubstituted the default window first, and only a zero-page document reached theif not indices:guard.producers/save_view.py:91-97now catches theValueError, and that guard stays for a blank spec on a zero-page document, with its wording aligned to the new message.One path lets the new
ValueErrorout ofvisualize.handle, and it is the only behavior change a caller cannot predict. The web renderer always runs throughrun_isolated, and for a local.htmlfile thetryatvisualizers/visualize.py:93still catches what comes back. The URL branch returns atvisualizers/visualize.py:52, before thattry, so there the error arrives asIsolatedWorkerError("ValueError: no pages selected ..."), the shapetests/test_isolated_worker.py::test_isolated_worker_returns_structured_errorpins, and FastMCP reports it as a tool error (Error executing tool visualize: IsolatedWorkerError: ...) rather than crashing. The web page count comes from slicing the screenshot (renderers/web.py:70-83), sopages="3"against a page that split into 2 now errors rather than returning both slices.Scope. I left the rest of
web.pyalone: line 90 passeslen(pages)after the truncation at line 83, and line 95 printsTotal pages: {len(pages)}after selection has shrunk it again. Line 95 is a mislabel and line 90 selects against the truncated count, so a URL whose screenshot split into 30 slices withmax_pages=20now reportsdocument has 20 page(s). Both are a different defect and belong in their own PR.Regression tests
tests/test_renderers.py::test_parse_pages_keeps_selections_that_match_a_pagepins what must not change against a 10-page document:1-5,3,1,3,5-8and9-99.::test_parse_pages_rejects_a_selection_that_matches_no_pageasserts that99,0,3-1and11-20each raise.::test_parse_pages_without_a_selection_returns_the_default_windowcovers a blank and a whitespace-only spec.tests/test_nifti.py::test_visualize_nifti_4d_reports_a_page_selection_that_matches_no_volumeis the NIfTI case above end to end, withpagesof9,0and3-1.7 of those 12 cases fail on main with this branch's two test files checked out onto it; the 5 pinning unchanged behavior pass:
The only other tests pinning a
pagesargument pass1-3or1(test_visualize_nifti_4d_defaults_and_selects_pages_lazily,tests/test_native_mode.py:169,tests/test_api_reachability.py:120), all in range.Verification
macOS 26.2, Python 3.11.15, pytest 9.1.1, ruff 0.16.7, from the repo root:
The NIfTI case end to end, which the new
test_nifti.pytest asserts. On main the last three return 9 images each:The project's own command is
python3 -m pytest -m "not reachability" tests/. I added--ignore=tests/omni_chatcutbecause 3 of those tests fail here for unrelated reasons, the same 3 as on main:The two
test_music_to_mv.pyfailures runburn_lyrics_subtitles.py, which exits 1 because the local ffmpeg 8.1.1 has no libass. The third is unrelated to ffmpeg: a child dies withSIGABRTwhile probing a venv it creates. This change touches none of them.python3 scripts/check_manifests.pyreports the 12 capabilities consistent acrossmarketplace.json, the plugin manifests andpyproject.toml, plus its usual note about theexampletemplate.Neither ruff command is clean repo-wide on main, so I ran both scoped to the four touched files. They are clean on main and on this branch alike:
All checks passed!and4 files already formatted.Not run: the opt-in reachability tests, the Ubuntu CI leg, the
save_viewPDF path end to end, sincepypdfium2is not installed here, and the web renderer end to end, sinceplaywrightis not installed here either.Compatibility
pagesnever reachesparse_pagesin the renderers, so their defaults are unchanged (one volume for NIfTI, asSKILL.mdsays), andsave_viewstill substitutes its"1"default. A spec that matched no page now errors, which is the fix.SKILL.mdalready describespagesas a selector.