Repository navigation
fix(sdk): keep truncated titles within a max_length below 3 - #6583
Conversation
With max_length < 3, title[: max_length - 3] is a negative slice, so the "truncated" title came out longer than the limit. Cut to max_length without an ellipsis when there is no room for one.
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Reviewed head 9e9d9f0f4a20c32e1c6101a741201c8c95617089.
Scope gate passes: both changed files are SDK conversation title helpers owned by this repository, and the linked issue #6348 is open in this repo with bug and ready-for-dev labels, matching the PR description.
Technical assessment:
- The reported bug is real on
main: withmax_length < 3,title[: max_length - 3]is a negative slice, so the "truncated" title kept nearly all the text and grew past the limit (e.g.generate_fallback_title("hello world", 2)→"hello worl...", 13 chars). - The fix clamps to
title[:max_length]whenmax_length <= 3and keeps the ellipsis path formax_length > 3, applied consistently to bothgenerate_fallback_titleandgenerate_title_with_llm. I verified the LLM path feeds into the same truncation viagenerate_title_from_message, so fixing only one site would have left the other oversized; both are covered. - Behavior for
max_length >= 4is unchanged, so existing callers using the defaultmax_length=50are unaffected. At exactly 3 the result changes from"..."to the first 3 characters; both fit the limit, and the change is disclosed in the PR description. - No persistence, serialization, REST, or TypeScript-client surface is touched; no other call sites exist in the repo.
Verification in the workspace at this head: uv run pytest tests/sdk/conversation/test_generate_title.py → 29 passed, including the 3 new parametrized cases (max_length 0, 1, 2), which fail on main and pass here. GitHub Actions on this exact head are green (sdk-tests, agent-server-tests, cross-tests, integration-test, pre-commit, build matrix, OpenAPI checks).
No material correctness, security, or compatibility findings.
✅ APPROVED
HUMAN:
just fixing a bug
AGENT:
Why
Both title truncations do
title[: max_length - 3] + "...". Formax_lengthbelow 3 that slice is negative, so it keeps almost the whole title and the result is longer than the limit:generate_fallback_title("hello world", 2)returns"hello worl..."(13 characters).Summary
max_length <= 3), cut the title tomax_lengthinstead. Lengths of 4 and above behave exactly as before.generate_title_with_llm, which truncates the LLM's title the same way.xfailmarker.Issue Number
Part of #6348 (item: "max_length < 3 makes title[: max_length - 3] a negative slice, so the 'truncated' title is longer than max_length").
How to Test
The new
test_fallback_title_never_exceeds_tiny_max_lengthfails onmainfor 0, 1 and 2 and passes here; the whole file passes (29). For"hello world"withmax_length0, 1, 2, 3, 5 the fallback now returns'','h','he','hel','he...'(at exactly 3 it used to return'...'; both fit the limit).Type
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:9e9d9f0-pythonRun
All tags pushed for this build
About Multi-Architecture Support
9e9d9f0-python) is a multi-arch manifest supporting both amd64 and arm649e9d9f0-python-amd64) are also available if needed