Garbled response from Symbolics.jl variables #6
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
kahliburke/Kaimon.jl#6
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bug: Symbolics.jl expressions produce garbled binary output
Symptom
Evaluating any Symbolics.jl expression via the
exMCP tool returns garbled binary data instead of text. Example:Returns:
Analysis
The output begins with
\x07JL— Julia's native serialization magic bytes — and contains readable fragments of SymbolicUtils internals (ExceptionStack,MethodError,SmallVec,Backing). This is a serialized Julia objectleaking through as raw bytes.
There appear to be two compounding issues:
1.
gate.jl~line 547 — REPL backend error pair not checkedWhen
_eval_with_capturethrows inside the REPL backend,repl_backend_loop(REPL.jl:447) catches it and putsPair{ExceptionStack, true}on the response channel — thetrueflag signals an error.gate_evalextractsresult.firstwithout checkingresult.second:The
ExceptionStack— whose backtrace contains SymbolicUtils types (SmallVec{...},Backing{...}) — is then passed to_serialize_resultas if it were a normal result NamedTuple.2.
gate_client.jl~line 597 — cross-process deserialization fails, leaks binary as outputThe MCP/TUI server process does not have Symbolics loaded, so deserializing an
ExceptionStackcontaining SymbolicUtils types fails. The catch fallback usesstring(data)— the raw binary bytes — asvalue_repr:This is the binary blob that appears as tool output.
The specific exception visible in the binary is a
MethodErrorfor#sizeonSmallVec{...}from SymbolicUtils, occurring inside_eval_with_capturewhen called from the REPL backend. Notably, calling_eval_with_capturedirectly with a Symbolics expression works correctly — the failure is specific to the REPL backend execution context.
Hi @jeffwack, thanks for the bug report. This definitely seems strange and I'll take a look at how things are looking when using Symbolics.jl.
Root cause identified: this is a world age problem in
_eval_with_capture.When
Core.eval(Main, expr)executes something likeusing Symbolics, new methods (e.g.size(::SymbolicUtils.SmallVec)) are defined in a newer world age than the REPL backend thread's execution context. The subsequentshow(io, MIME("text/plain"), value)call runs in the older world age and fails with:This causes
showto fail, then thereprfallback also fails for the same reason, and the exception escapes_eval_with_captureentirely. The exception object contains references to Symbolics types, so when it gets serialized over ZMQ and the MCP server process (which doesn't have Symbolics loaded) tries to deserialize it, deserialization fails and the raw binary bytes leak into the output.Fix: wrap
show,repr, andshowerrorinBase.invokelatestso they always resolve methods in the latest world age. PR #8.@jeffwack I believe I have fixed this issue, would you care to give it a try?
There seems to be a dependency issue now. I get this error when running ./bin/kaimon. I tried first to update via git pull but also tried a fresh install and get the same error in both cases.
Hi you're right it's a new thing in Tachikoma which hasn't yet been released. I thought I had avoided it but it slipped in. I'm building Tachikoma 1.0.4 which will be up shortly, and I'll update the dependency in Kaimon main.
You could in the meantime use `]add https://github.com/kahliburke/Tachikoma.jl" to get it pointed at the main unreleased branch which includes this.
Sorry for the hassle, let me know if it works.
@jeffwack, the fix for that is in, I tested locally and did not get that dependency error. Hope it works for you too but let me know!
It works in my environment too, and the original issue with Symbolics is resolved. Thanks for the quick fix.