Repository navigation
Do not crash when a Python TextParserStreamer has no write() override - #4549
Conversation
TextParserStreamer is documented as a base class, but it can be constructed and passed to generate() as is. Its C++ write(JsonContainer&) then called the missing Python override through a null handle and segfaulted in the streaming thread. Without an override it now only collects the parsed message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Constructing TextParserStreamer itself now raises TypeError, since write() is pure virtual. A subclass that does not implement write() raises TypeError when it is called, instead of the silent no-op. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a05052f to
2983e4c
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new exception can still escape the streaming worker thread and terminate the process.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Prevents unsafe direct construction of Python TextParserStreamer and reports missing write() overrides.
Changes:
- Adds subclass-aware pybind11 construction.
- Adds override validation and regression tests.
| File | Description |
|---|---|
src/python/py_streamers.cpp |
Adds constructor and override checks. |
tests/python_tests/test_parsers.py |
Tests missing write() behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…the caller An exception thrown by StreamerBase::write() on the worker thread had no handler and terminated the process, e.g. for a TextParserStreamer subclass without write() passed to a continuous batching pipeline. Catch it in the worker, stop streaming and rethrow it from end() on the calling thread. The destructor swallows it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
@Wovchena, since your approval I pushed 6fd2d01, which addresses the Copilot finding ( Could you take another look at the |
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Wovchena
left a comment
There was a problem hiding this comment.
In addition to Copilot's comment
ThreadedStreamerWrapper's destructor logs the error it swallows with GENAI_ERR(). end() is idempotent and, when write() failed on the worker thread, rethrows that error without calling StreamerBase::end(): TextStreamer::end() would flush the cached text through the failed write() again and could replace the original error.
|
build_jenkins |
ff212f9
## Description Reworks `.github/copilot-instructions.md` so that Copilot code review gives fewer noisy comments and catches the issues human reviewers keep raising. Before this change, the file mixed persona text, vague style rules and rules that Copilot can't check from a diff. The review section also sat at the end of the file, past the 4,000-character limit that code review used until June 2026. The rules were checked against Copilot's comments on the last 100 PRs: about 610 inline comments, of which authors accepted about 45%. The noise patterns found there are removed or scoped below. **Removed** - Persona and "Expertise Areas" block: it gives the reviewer nothing to check. - "Follow C++ Core Guidelines strictly" and "Include C++ Core Guidelines references in review comments": too broad to act on, and the model tends to cite wrong rule numbers. GitHub also lists comment-format instructions as unsupported. - "Descriptive names" and "avoid pronouns": vague, so they lead to wording nitpicks. **Fixed** - "Pass by const ref wherever possible" clashed with taking moved-from arguments as `&&`. The rule now says: `ov::Tensor` and other non-trivial objects by `const&`, moved-from arguments as `&&`. This matches the codebase (693 `const ov::Tensor&` parameters, 131 by value) and review practice (openvinotoolkit#4501, openvinotoolkit#4573). - "ABI stability isn't required" is now an action: don't flag ABI breaks, but flag public API that is removed, renamed or loses a default argument (openvinotoolkit#4541). - "Reject GPU tests" is merged with a rule about tests gated on env vars or models that CI never enables. Both kinds never run. - Rules are grouped by topic, numbered without restarts, and use imperative wording. **Added**, from repeated reviewer comments on recent PRs: - C++/Python API parity, including the C and JS bindings (openvinotoolkit#4247). Tests already enforce the `.pyi` stubs, so review doesn't comment on them. - An output tensor from `get_tensor()` is a view into the request buffer, so one kept past the next `infer()` needs a deep copy of its data. Reusing input tensors is fine. - Don't drop existing error paths (openvinotoolkit#4356, openvinotoolkit#4549). Reuse existing helpers (openvinotoolkit#4241, openvinotoolkit#3881, openvinotoolkit#4338). Keep the public API small (openvinotoolkit#4310). Use model-neutral public names. Don't use deprecated APIs in new code. Comment every `const_cast`. - Tests: exact equality for repeated and greedy CPU runs, a test that shows each new option's effect, `parametrize` instead of near-duplicates, a ticket for every skip/xfail, cheap tests (openvinotoolkit#4247, openvinotoolkit#4592). - CI wiring: new test files in the matching `test_matrices` file for each OS, `-m` filters that match markers, exact pins, and labeler/components/CODEOWNERS entries when a new use case is introduced (openvinotoolkit#4247, openvinotoolkit#4575, openvinotoolkit#4090). `!=` instead of a new upper cap when a release breaks something (openvinotoolkit#2858). - One purpose per PR (openvinotoolkit#4310). Comment hygiene and permalinks to commits (openvinotoolkit#4452). Copyright header in new files. Complete removals. C++ and Python samples and docs updated together. **Scoped to avoid false positives** - API rules apply only to the public API in `src/cpp/include` and the bindings. The unused-function and unused-return-value rules apply only to non-public code. - Error-message rules apply only to checks on user input. - No test requests for documentation, CI, sample-only or xfail-only changes, or for test utilities and tokenizer behavior (openvinotoolkit#4592). Tests marked `real_models` or `nightly` are not flagged as "never run in CI". A missing `tiny-random` model may be a ticketed follow-up (openvinotoolkit#4591). - Exempt: override parameters, performance options, catch-all blocks at the C and JS binding boundaries, the `device` argument and sibling flags in samples, and the dependabot-managed `<=` caps in `tools/`, `samples/` and the root. - Samples are minimal demos, so no requests for edge-case handling there (openvinotoolkit#4670). Planned follow-ups: openvinotoolkit#4716 splits the rules into path-scoped files and adds the rules that need discussion. **Copilot configuration PRs:** 1. openvinotoolkit#4714 Rework Copilot review instructions. Merge first. 2. openvinotoolkit#4716 Split Copilot rules into path-scoped files. Stacked on openvinotoolkit#4714; merge after it. 3. openvinotoolkit#4715 Fix Copilot agent and skill metadata. Independent; merge in any order. ## Checklist: - [x] This PR follows [GenAI Contributing guidelines](https://github.com/openvinotoolkit/openvino.genai?tab=contributing-ov-file#contributing). - [ ] N/A Tests have been updated or added to cover the new code. - [ ] N/A This PR fully addresses the ticket. - [ ] N/A I have made corresponding changes to the documentation.

Description
ConstructableTextParserStreamer::write(JsonContainer&)called the Pythonwriteoverride without checking that there is one. ATextParserStreamerconstructed directly in Python, with no subclass, then crashed the interpreter (SIGSEGV) on the first chunk. That happens in the streaming thread ofLLMPipelineandVLMPipeline, or on_write.Following review, a missing override is now an error, raised on the calling thread. Raising from
write()itself would not do, because it runs on the streamer's worker thread, where an exception terminates the process.TextParserStreameritself raisesTypeError, sincewrite()is pure virtual. This uses a pybind11 dualpy::initfactory: the base class factory throws, and Python subclasses construct as before.write()raisesTypeErrorwhen it is called, instead of calling a null override.Fixes #4548
Tests
test_text_parser_streamer_without_write_overrideintests/python_tests/test_parsers.py. It checks that constructingTextParserStreamerdirectly raisesTypeError(on master this constructs, then segfaults on the first chunk), and that a subclass withoutwrite()raisesTypeErrorwhen called.test_parsers.py -m "not nightly": 25 passed after rebasing on master. Stubs regenerated with pybind11-stubgen 2.5.5 are unchanged.TextParserStreamerpassed toVLMPipeline.generate()with a real Qwen3.5-family model on an Intel Arc GPU. Master crashes. This was the first version of this PR; with the current version, construction raisesTypeErrorinstead.Found while testing #4547.
AI assistance used: yes
If yes: Claude (an AI coding assistant) debugged the crash with gdb, drafted the fix and the test, and ran the checks under my direction.
Human validation performed: local build (OpenVINO 2026.5 nightly, GCC 16,
-DCMAKE_CXX_STANDARD=17, see #4531), the parser tests above with the new test failing before and passing after, and the manual VLMPipeline run.Checklist:
tests/python_tests/test_parsers.py::test_text_parser_streamer_without_write_override.🤖 Generated with Claude Code