llama : return 0 on invalid ON_DEVICE seq restore - #27487
Draft
xiehuanyi wants to merge 1 commit into
Draft
Conversation
Assisted-by: Cursor Grok 4.6 Co-authored-by: Cursor <cursoragent@cursor.com>
|
Hi @xiehuanyi, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens ON_DEVICE sequence-state restoration against malformed input and adds CPU regression coverage.
Changes:
- Handles invalid headers and sequence IDs through the existing error path.
- Adds valid and malformed restore tests.
- Registers the new test with generated-model fixtures.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Summary |
|---|---|
tests/test-state-seq-on-device.cpp |
Adds valid round-trip and malformed-buffer regression tests. |
tests/CMakeLists.txt |
Builds and registers the regression test. |
src/llama-context.cpp |
Adds ON_DEVICE validation, but malformed payload cleanup can still assert; the failure path must be made non-fatal and covered by a truncation test. |
Suppressed comments (1)
tests/CMakeLists.txt:229
- This test is registered inside the
NOT WIN32 OR NOT BUILD_SHARED_LIBSguard, which skips it for Windows shared-library builds. Unlike the tests covered by the guard's comment,test-state-seq-on-device.cppincludes onlyllama.hand exercises exported C APIs, so the new C API regression remains untested on that configuration; register it in an applicable cross-platform test block and provide the model fixture there.
llama_test(
test-state-seq-on-device
LABEL main
ARGS "${MODEL_DIR}/llama-dense.gguf"
)
set_tests_properties(test-state-seq-on-device PROPERTIES
FIXTURES_REQUIRED generate-models
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| } else { | ||
| io = std::make_unique<llama_io_read_host>(src, size); | ||
| } | ||
| io = std::make_unique<llama_io_read_device>(src, size, it->second); |
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.
Overview
Fixes #27439
ON_DEVICE seq restore was reading magic/seq_id before the existing try/catch, so a bad buffer could throw out of the C API or hit GGML_ASSERT. Invalid input now returns 0. Added a CPU test
on the generated llama-dense model: valid round-trip plus the four malformed cases.
Additional information
CPU-only. Did not add a second catch on llama_state_seq_set_data_ext(); the inner try covers the reporter cases.
Requirements