Repository navigation
Commit cb59e37
authored
fix(chat): 修复历史回放时代码块末行越界崩溃 (#15)
Root cause of the recurring "StringIndexOutOfBoundsException: begin 0,
end 376, length 375" during retryLast/runAgentLoop. fenceSegments in the
reasoning-tag history stripper built the closing-fence range with
`until lineEnd + 1`. When the closing fence is the LAST line and the text
has no trailing newline, lineEnd == text.length, so the range's last index
became text.length — and the downstream text.substring(range) in
transformProtectingCode asked for end = length + 1 (note: end is exactly
length+1 in the report, not a byte/char mixup). Coerce the upper bound to
the text end.
The loop it created: the turn crashed during effectiveAgentHistory()'s
per-message cleanup, the exception text was persisted as an inline error,
and replaying that same assistant message on the next retry hit the same
out-of-bounds slice again. A DeepSeek/QwQ reply whose closing ``` sits on
the final line with no trailing newline triggers it reliably.
Also add a defensive per-transformer fallback in MessageTransformerChain:
a cosmetic cleanup that throws must neither kill the agent loop nor leave
its own exception text persisted as turn content — it now logs the
offending shape and replays the untransformed text.
Regression test: fence closing on the final line without a trailing
newline, including one whose body looks like a reasoning tag.
Co-authored-by: tall-1997 <278631348+tall-1997@users.noreply.github.com>1 parent a507a88 commit cb59e37
2 files changed
Lines changed: 49 additions & 2 deletions
File tree
- src/android/app/src
- main/java/com/openminis/app/agent
- test/java/com/openminis/app/agent
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
52 | 73 | | |
53 | 74 | | |
54 | 75 | | |
| |||
193 | 214 | | |
194 | 215 | | |
195 | 216 | | |
196 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
197 | 229 | | |
198 | 230 | | |
199 | 231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
80 | 95 | | |
0 commit comments