perf(run_agent): accumulate length-continuation prefix via list+join#26237
Merged
Conversation
Replace O(n²) string concatenation of truncated_response_prefix in the length-continuation retry loop with a list + ''.join(). Functionally equivalent: same partial response on early return, same prepend on final assembly. The legacy retry path is capped at 3 iterations, so the practical wall-clock win is small, but the new idiom matches the rest of the codebase and removes a needless repeated allocation. Salvaged from PR #2717 (the run_conversation portion only — trajectory refactor dropped because it silently rewrote </tool_response> to </think>). Co-authored-by: Teknium <127238744+teknium1@users.noreply.github.com>
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
unresolved-attribute |
1 |
invalid-argument-type |
1 |
First entries
run_agent.py:15545: [unresolved-attribute] unresolved-attribute: Attribute `rstrip` is not defined on `None` in union `None | str | (Unknown & ~AlwaysFalsy)`
run_agent.py:15499: [invalid-argument-type] invalid-argument-type: Argument to function `len` is incorrect: Expected `Sized`, found `None | str | (Unknown & ~AlwaysFalsy)`
✅ Fixed issues (2):
| Rule | Count |
|---|---|
unresolved-attribute |
1 |
invalid-argument-type |
1 |
First entries
run_agent.py:15545: [unresolved-attribute] unresolved-attribute: Attribute `rstrip` is not defined on `None` in union `None | str | Unknown`
run_agent.py:15499: [invalid-argument-type] invalid-argument-type: Argument to function `len` is incorrect: Expected `Sized`, found `None | str | Unknown`
Unchanged: 4310 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
3 tasks
1 task
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.
Salvages the run_conversation portion of #2717 (@InB4DevOps).
Summary
Replace
truncated_response_prefix += contentin the length-continuation retry path with list-append +"".join(). Functionally equivalent; matches the idiom used elsewhere in the codebase.Changes
run_agent.py(3 sites inrun_conversation): rename totruncated_response_parts: List[str], switch accumulation/use to list + join.tests/run_agent/test_anthropic_truncation_continuation.py: update doc comment to match new variable name.scripts/release.py: AUTHOR_MAP entries for InB4DevOps.What was dropped from the original PR
The trajectory-builder refactor in
_convert_to_trajectory_format()contained a silent regression — it replacedtool_response += "\n</tool_response>"withtool_response_parts.append("\n</think>"), which would have produced malformed trajectory XML on every save. Trajectory section dropped; only thetruncated_response_prefixrename retained.Validation
scripts/run_tests.sh tests/run_agent/test_anthropic_truncation_continuation.py→ 7/7 pass (pre-existing tests, no regressions).py_compile.compile("run_agent.py", doraise=True)clean.grep truncated_response_prefix run_agent.py→ 0 hits (all 6 references migrated).Closes #2717.