Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[BUG] `as_json` on an acts_as_chat record renders an array instead of the chat

Open Beginner friendly
#1,244 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rails, ruby
Domain
backend, databases

Research direction

Start by reading ChatMethods and the as_json implementations mentioned in the issue, especially Active Support's Enumerable behavior and Active Model's JSON behavior. Reproduce with the two examples in the issue, then check existing tests for chat serialization. Done means chat.as_json returns the chat model's attributes both with and without messages, without raising SystemStackError.

Written by the indexing model from the issue text.

Description

bug
Basic checks
  • I searched existing issues - this hasn't been reported
  • I can reproduce this consistently
  • This is a RubyLLM bug, not my application code
What's broken?

as_json on a chat record should render the Chat model's JSON (id, created_at, etc.). Instead, it renders the chat's messages as an array. With messages, that raises SystemStackError.

How to reproduce
chat = Chat.create!(model: "gpt-4.1-nano")
chat.as_json # => []

chat.add_message(role: :user, content: "Hello")
chat.add_message(role: :assistant, content: "Hi!")
chat.as_json # => SystemStackError: stack level too deep
Expected behavior
chat.as_json # => {"id" => 1, "created_at" => ..., "updated_at" => ...}
What actually happened

ChatMethods includes Enumerable, and Active Support's Enumerable#as_json (to_a.as_json) replaces Active Model's.

Environment
  • Ruby 4.0.7, Rails 8.1.4
  • RubyLLM main (76ba13b) and 2.1.0
Dominant language
Ruby
Stars
4.5k
Forks
515
Avg merge
9h 50m
Merged PRs (30d)
211

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from crmne/ruby_llm

All issues in crmne/ruby_llm

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.