anomalyco / anomalyco/opencode
[Bug] Long-context agent (task) calls corrupt returned content: newlines/backslashes lost, mojibake injected
@Hona is already working on this.
Since Aug 27, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Summary
In a long-context session, an agent (task/subagent) call that asked it to inspect local files produced a corrupted multi-line code payload displayed directly in the chat: newlines and backslashes were dropped (content flattened to one line), and mojibake <課 was injected at the start. The file the agent tried to write (check_cfg.py) was never created.
Environment
- OS: Windows 10 (build 19045)
- Node: v24.18.0
- Locale: Chinese (code page 936 / GBK) - suspected relevant
Corruption pattern (shown natively in the chat, not a copy-paste artifact)
Expected:
import os, glob
d = r'C:\Users\Dell.config\opencode'
print(...) on separate lines...
Actually shown:
<課 import os, glob newline d = r'C:\Users\Dell.config\opencode' print(...) for root, dirs, files in os.walk(d): ... (all flattened, \ in path lost, <課 prefix).
- \n newlines lost -> single line.
- \ backslashes lost -> C:\Users\Dell.config\opencode became C:\Users\Dell.config\opencode.
- Mojibake <課 injected before import.
check_cfg.py was never written (File not found), so failure is at content-generation/return stage, not runtime.
Correlation with context length
- Short-context earlier session: identical task (writing multi-line helper, e.g. mk_scpb.py generating scpb.ps1) succeeded with correct newlines/backslashes.
- Long-context session: failed; user observed interruptions become more frequent as context grows.
Log evidence
In ~/.local/share/opencode/log/opencode.log, the 課 codepoint is logged as U+FFFD replacement char (<�n), e.g.:
...pattern=sshpass|scpb|<�n|�n|...
That shows a UTF-8 decode failure on this codepoint in the logging/rendering pipeline. Combined with the dialog display, corruption appears to happen in streaming/assembly of agent tool-call arguments, likely interacting with the GBK (cp936) Windows locale.
Suggested investigation
- Check how task/subagent return payloads (especially large multi-line code with \n and ) are streamed/assembled into the displayed tool call.
- Verify UTF-8 handling for multibyte content on Windows with non-UTF-8 system codepage.
- The \n+\ byte loss + mojibake injection suggests byte-level truncation/transcoding, not a model artifact.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.