anomalyco / anomalyco/opencode

[Bug] Long-context agent (task) calls corrupt returned content: newlines/backslashes lost, mojibake injected

Open
#45,429 1 comment 0 reactions 1 assignee View on GitHub

@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).

  1. \n newlines lost -> single line.
  2. \ backslashes lost -> C:\Users\Dell.config\opencode became C:\Users\Dell.config\opencode.
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.