Agents crash with Jason.EncodeError on non-ASCII WORKFLOW.md prompts — \R regex in Workflow.split_front_matter/1 splits UTF-8 multibyte characters at byte boundaries #129
ivybug-test
started this conversation in
General
Replies: 1 comment
|
We've verified and shipped this fix locally. The one-line patch plus a regression test is available on our fork:
Diff summary:
Verification: |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
With a
WORKFLOW.mdwhose prompt body contains non-ASCII text (Chinese, in our case), every agent dispatch fails and the orchestrator retries in a backoff loop forever. The agent task dies with:symphony-v0.0.3-linux_x86_64Burrito release; tracker: GitHub Issues; Codex CLI 0.154.0.Root cause
elixir/lib/symphony_elixir/workflow.ex:86:~r/\R/compiles without theu(unicode) flag, so Erlang's:re(PCRE) runs in byte mode. In byte mode,\Rmatches the single byte0x85(NEL). But0x85is also a legal UTF-8 continuation byte — e.g. 待 U+5F85 =E5 BF 85, 内 U+5185 =E5 86 85. The regex split cuts those characters apart mid-sequence, and the subsequentEnum.join(prompt_lines, "\n")glues the halves back together with a literal newline, producing invalid UTF-8. Later,Jason.encode!validates the rendered prompt as UTF-8 and raises.Byte-level confirmation on our template: it contains 21 occurrences of byte
0x85, each inside a CJK character, and the rendered prompt's first invalid position isE5 BF 0A— i.e. 待 with its final byte0x85replaced by\n(the text was "…不要等待人工执行…" from the unattended-session instructions). ASCII-onlyWORKFLOW.mdfiles are unaffected, which is why the bundled one works.Minimal reproduction
Reproduced standalone with the same pinned deps (solid 1.2.2, jason 1.4.4), replicating
Workflow.parse→PromptBuilder.build_prompt→AppServer.start_turn1:1. Any Elixir ≥ 1.14:Rendering this template and encoding it like
start_turndoes (Jason.encode!(%{"input" => [%{"type" => "text", "text" => rendered}]})) raises the exact error above.Verified fix
Either add the unicode flag:
or (preferred — binary patterns are codepoint-safe and faster):
Both variants produce valid UTF-8 through the whole pipeline and
Jason.encode!succeeds end-to-end (verified with the same deps, using a ChineseWORKFLOW.mdand Chinese issue fields).Scope
WORKFLOW.mdcontaining characters whose UTF-8 encoding includes the byte0x85— very common in CJK text, also possible in emoji and some other scripts.grep -rn '\\R' elixir/lib/showsworkflow.ex:86is the only occurrence of this pattern.Current workaround for affected users: keep
WORKFLOW.mdASCII-only (English prompt body), since ASCII contains no0x85bytes.All reactions