[BUG] `as_json` on an acts_as_chat record renders an array instead of the chat
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
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
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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from crmne/ruby_llm
-
[FEATURE] Continue Gemini long-decode responses as one generationPossibly taken @yorzi claimed this today. Openenhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
crmne/ruby_llm#1246 · 1 reaction ·
Maintainers usually reply within 1 day
-
[FEATURE] Preserve native client-toolset identity and resultsPossibly taken @yorzi claimed this today. Openenhancement
Difficulty 5/5 Over a week Newbie friendliness 20/100
crmne/ruby_llm#1245 · 1 reaction ·
Maintainers usually reply within 1 day
Similar issues
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
DataDog/datadog-lambda-rb#167 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
alphagov/public-asset-checker#378 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
betagouv/acces-cible#786 ·
Maintainers usually reply within 1 day
-
data error
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
riscv/riscv-unified-db#2749 ·
Maintainers usually reply within 1 day