Skip to content

fix: initialize nil Messages and Tools in Chat via ensureDefaults#31

Merged
x2d7 merged 2 commits intodevfrom
30-init-chat-fix
Feb 22, 2026
Merged

fix: initialize nil Messages and Tools in Chat via ensureDefaults#31
x2d7 merged 2 commits intodevfrom
30-init-chat-fix

Conversation

@x2d7
Copy link
Owner

@x2d7 x2d7 commented Feb 22, 2026

Closes #30

Summary

Chat struct allows partial initialization — omitting Messages or Tools is valid Go, but caused a nil pointer panic on the first call to Session. Since the zero value of a struct should be as useful as possible, the fix initializes missing fields lazily at the entry point rather than forcing callers to provide them.

Changes

ensureDefaults() added to chat.go, called at the top of Session()
Unit tests covering nil Messages, nil Tools, both nil, and preservation of existing values

@x2d7 x2d7 changed the base branch from dev to chat-consistent-constructor February 22, 2026 12:31
@x2d7 x2d7 changed the base branch from chat-consistent-constructor to dev February 22, 2026 12:33
@x2d7 x2d7 merged commit eddb909 into dev Feb 22, 2026
1 check passed
@x2d7 x2d7 deleted the 30-init-chat-fix branch February 22, 2026 12:49
@x2d7 x2d7 added the bug label Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant