Skip to content

Fix 4 runtime bugs: crash, streaming None, discarded replace, memory leak#258

Open
sanjibani wants to merge 1 commit intoThe-OpenROAD-Project:masterfrom
sanjibani:fix/issue-243-runtime-bugs
Open

Fix 4 runtime bugs: crash, streaming None, discarded replace, memory leak#258
sanjibani wants to merge 1 commit intoThe-OpenROAD-Project:masterfrom
sanjibani:fix/issue-243-runtime-bugs

Conversation

@sanjibani
Copy link
Copy Markdown

Summary

Fixes #243 — four bugs, two of which cause runtime crashes or corrupt client output.

  • Bug 1 (crash): UnboundLocalError in retriever_rag.pytool_calls referenced before assignment when LLM response lacks tool_names. Also fixes list mutation during iteration (.remove() while looping).
  • Bug 2 (user-visible): Streaming endpoint yields literal "None\n\n" to clients when message_content is not an AIMessageChunk. Moved yield inside the if msg: guard.
  • Bug 3 (minor): str.replace() result discarded in rag_initialize() — tool descriptions sent to LLM were never actually cleaned.
  • Bug 4 (memory leak): In-memory chat_history dict grows unboundedly when DB is disabled. Replaced with OrderedDict capped at 1000 entries, evicting oldest on overflow.

Test plan

  • All 18 unit tests pass (pytest -m unit)
  • All 40 retriever/graph/API tests pass
  • Manual test: trigger non-inbuilt-tool-calling path — should no longer crash
  • Manual test: streaming endpoint — should no longer show "None" in output
  • Manual test: run with USE_DB=false for 1000+ conversations — oldest should be evicted

🤖 Generated with Claude Code

…ace, memory leak

Fixes The-OpenROAD-Project#243

- Fix UnboundLocalError in rag_agent fallback path by initializing
  tool_calls before the if/else block. Also replace list mutation
  during iteration with a filter pattern.
- Fix streaming endpoint yielding literal "None" to clients by
  moving yield inside the `if msg:` guard.
- Fix discarded str.replace() result so tool descriptions are
  actually cleaned before being sent to the LLM.
- Fix unbounded in-memory chat_history growth by using OrderedDict
  with a cap of 1000 conversations, evicting oldest on overflow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Bug: UnboundLocalError crash in RAG fallback path + streaming endpoint yields None to clients

1 participant