Skip to content

llama : return 0 on invalid ON_DEVICE seq restore - #27487

Draft
xiehuanyi wants to merge 1 commit into
ggml-org:masterfrom
xiehuanyi:llama-ondevice-seq-set-data-fail
Draft

llama : return 0 on invalid ON_DEVICE seq restore#27487
xiehuanyi wants to merge 1 commit into
ggml-org:masterfrom
xiehuanyi:llama-ondevice-seq-set-data-fail

Conversation

@xiehuanyi

Copy link
Copy Markdown

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

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - used Cursor to locate the try-block gap, write the patch, and add the regression test. I reviewed the diff and can explain it.

Assisted-by: Cursor Grok 4.6
Co-authored-by: Cursor <cursoragent@cursor.com>
@xiehuanyi
xiehuanyi requested a review from ggerganov as a code owner August 21, 2026 11:03
Copilot AI lite review requested due to automatic review settings August 21, 2026 11:03
@github-actions github-actions Bot added the testing Everything test related label Aug 21, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

Hi @xiehuanyi, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ggml-gh-bot ggml-gh-bot Bot added the draft PR will be changed to draft by github-actions bot label Aug 21, 2026
@github-actions
github-actions Bot marked this pull request as draft August 21, 2026 11:08
@github-actions github-actions Bot removed the draft PR will be changed to draft by github-actions bot label Aug 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_LIBS guard, which skips it for Windows shared-library builds. Unlike the tests covered by the guard's comment, test-state-seq-on-device.cpp includes only llama.h and 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.

Comment thread src/llama-context.cpp
} else {
io = std::make_unique<llama_io_read_host>(src, size);
}
io = std::make_unique<llama_io_read_device>(src, size, it->second);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misc. bug: llama_state_seq_set_data_ext: invalid ON_DEVICE state can throw across the C API or abort

2 participants