Repository navigation
Conversation
…rate_summary_from_files Fix three related runtime crash paths in generate_summary_from_files: 1. When agent has no indexed entries (file_objects is None) but query_files is provided, default file_objects to an empty list to avoid TypeError: 'NoneType' object is not iterable at lines 785 and 793. 2. Guard send_status_func invocation with 'if send_status_func:' to prevent TypeError when caller passes send_status_func=None (matching sibling handlers). 3. In the outer exception handler, yield response_log instead of unbound result variable to avoid UnboundLocalError during error reporting.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix three related runtime crash paths in
src/khoj/routers/helpers.py::generate_summary_from_files:TypeError: 'NoneType' object is not iterableon empty-agent file summaries:When an agent has no existing indexed entries (
file_objectsisNone) but the user uploads/provides a file to summarize (query_filesis set), the outer guard at line 780 passes as intended:However, lines 785 and 793 attempt to iterate over
file_objectsdirectly:This causes a runtime
TypeError: 'NoneType' object is not iterable. Initializingfile_objects = file_objects or []resolves this.TypeError: 'NoneType' object is not callablewhensend_status_funcis None:send_status_funchas defaultNonein the function signature, but line 801 called it unconditionally without checkingif send_status_func:. Aligned with sibling functions inhelpers.py(lines 835, 853, 1083, 1101, 1364) by wrapping withif send_status_func:.UnboundLocalErrorin outer exception handler:Line 818 attempted to
yield result.resultis only defined within theasync for result in send_status_func(...)loop. When an exception occurs prior to or without status streaming,resultis unbound, raisingUnboundLocalError: cannot access local variable 'result' where it is not associated with a value. Corrected toyield response_log.Verification
query_fileswhenfile_objectsis None -> passes and generates summary cleanly.send_status_func-> properly streams status events.query_files-> returns early with"Sorry, I couldn't find anything to summarize.".response_logwithout raisingUnboundLocalError.python3 -m py_compile src/khoj/routers/helpers.pypasses cleanly.