Skip to content

llms/googleai: return error instead of panicking on system-only message list#1508

Closed
SAY-5 wants to merge 1 commit into
tmc:mainfrom
SAY-5:fix-googleai-system-only-panic
Closed

llms/googleai: return error instead of panicking on system-only message list#1508
SAY-5 wants to merge 1 commit into
tmc:mainfrom
SAY-5:fix-googleai-system-only-panic

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jun 18, 2026

Copy link
Copy Markdown

Fixes #1507

When a message list contains only system messages, generateFromMessages builds an empty history (every system message is consumed into model.SystemInstruction and continued), then indexes history[n-1] with n == 0 and panics with index out of range [-1].

This adds a length check that returns a new ErrNoRequestMessage sentinel before the index, so callers get an error rather than a panic. Covered by a unit test that drives a system-only list through generateFromMessages.

PR Checklist

  • Read the Contributing documentation.
  • Read the Code of conduct documentation.
  • Name your Pull Request title clearly, concisely, and prefixed with the name of the primarily affected package you changed according to Good commit messages (such as memory: add interfaces for X, Y or util: add whizzbang helpers).
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. Fixes #123).
  • Describes the source of new concepts.
  • References existing implementations as appropriate.
  • Contains test coverage for new functions.
  • Passes all golangci-lint checks.

…ge list

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@SAY-5

SAY-5 commented Jun 20, 2026

Copy link
Copy Markdown
Author

Superseded by #1509, which folds the regression test into the existing googleai_unit_test.go instead of adding a separate file. Closing this one to avoid a duplicate.

@SAY-5 SAY-5 closed this Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

googleai: panic on system-only message list in GenerateContent

1 participant