Skip to content

fix(lakeview): avoid IndexError when LLM omits the <tags> block - #428

Open
nankingjing wants to merge 1 commit into
bytedance:mainfrom
nankingjing:fix-lakeview-tag-indexerror
Open

fix(lakeview): avoid IndexError when LLM omits the <tags> block#428
nankingjing wants to merge 1 commit into
bytedance:mainfrom
nankingjing:fix-lakeview-tag-indexerror

Conversation

@nankingjing

Copy link
Copy Markdown

Summary

LakeView.extract_tag_in_step (in trae_agent/utils/lake_view.py) indexes matched_tags[0] unconditionally right after tags_re.findall(content). When the Lakeview model returns a response that does not contain a well-formed <tags>...</tags> block, findall returns an empty list and matched_tags[0] raises IndexError: 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 method extract_task_in_step already degrades gracefully in the same situation (it returns ("", "")); this makes the two paths consistent.

Impact

extract_tag_in_step is called from create_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 continue the retry loop instead of indexing into an empty list:

matched_tags: list[str] = tags_re.findall(content)
if not matched_tags:
    # The model did not return a well-formed <tags>...</tags> block.
    # Retry instead of crashing with an IndexError.
    retry += 1
    continue
tags: list[str] = [tag.strip() for tag in matched_tags[0].split(",")]

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.
  • Reproduced the original IndexError and 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.)

…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.
@nankingjing

Copy link
Copy Markdown
Author

Reviewed — the retry-on-empty-tags guard correctly prevents the IndexError when the model output is malformed. Ready for review.

@nankingjing

Copy link
Copy Markdown
Author

Ready for review. Prevents IndexError when LLM omits the <tags> block in lakeview output — retries instead of crashing. @chao-peng PTAL.

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.

1 participant