fix(lakeview): avoid IndexError when LLM omits the <tags> block - #428
Open
nankingjing wants to merge 1 commit into
Open
fix(lakeview): avoid IndexError when LLM omits the <tags> block#428nankingjing wants to merge 1 commit into
nankingjing wants to merge 1 commit into
Conversation
…tput extract_tag_in_step indexed matched_tags[0] unconditionally, so a malformed LLM response with no well-formed <tags>...</tags> block raised IndexError instead of retrying. Guard for an empty match and retry, matching the graceful behavior of extract_task_in_step.
Author
|
Reviewed — the retry-on-empty-tags guard correctly prevents the IndexError when the model output is malformed. Ready for review. |
Author
|
Ready for review. Prevents IndexError when LLM omits the |
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
LakeView.extract_tag_in_step(intrae_agent/utils/lake_view.py) indexesmatched_tags[0]unconditionally right aftertags_re.findall(content). When the Lakeview model returns a response that does not contain a well-formed<tags>...</tags>block,findallreturns an empty list andmatched_tags[0]raisesIndexError: list index out of range.The surrounding
while retry < 10:loop was clearly written to retry on malformed model output (and fall back to returning[]after 10 attempts), but this path never runs because the code crashes before it can retry. The sibling methodextract_task_in_stepalready degrades gracefully in the same situation (it returns("", "")); this makes the two paths consistent.Impact
extract_tag_in_stepis called fromcreate_lakeview_step, which the simple CLI console runs as a background asyncio task. The stored exception surfaces when the task is awaited in_print_lakeview_summary, so a single malformed model completion crashes the Lakeview summary at the end of a run.The regex is
<tags>([A-Z_,\s]+)</tags>, so any completion without a closing tag, with lowercase tags, or with stray punctuation produces no match and triggers the crash.Fix
Guard for an empty match and
continuethe retry loop instead of indexing into an empty list:Minimal, behavior-preserving on the happy path; only the previously-crashing branch changes (now it retries, then returns
[]after 10 attempts).Verification
python -m py_compile trae_agent/utils/lake_view.py— passed.IndexErrorand confirmed the fixed loop returns[]for all-malformed output and the correct tags when a later attempt is well-formed, using a standalone script mirroring the loop body. (Full end-to-end run against a live model was not executed.)