#2791·ag-ui

[Bug]: C++ SDK parses event JSON with no recursion depth limit

Author: NathanTarbertCreated Sep 18, 2026Updated Oct 1, 2026

The C++ SDK reads agent responses with nlohmann::json::parse at two points: parseSseEventData in src/agent/http_agent.cpp:389, which turns each SSE data: payload into an event, and the activity-delta path in src/core/subscriber.cpp:746, which re-reads a stored message's content before applying a patch.

Neither call sets a depth limit, and nlohmann's parser descends recursively, so nesting depth is bounded by the thread's stack rather than by anything the SDK controls. Both sites sit inside handlers written for nlohmann::json::parse_error, and that is the part worth knowing: a depth failure is not a parse_error, so those handlers never run and the caller gets no catchable error.

This is the remaining half of #2440. The byte-budget half landed in #2501, which counts the per-event accumulator against the SSE buffer cap. A byte cap does not bound depth though, since a payload comfortably under the cap can still nest far enough to matter, so the two need different mechanisms. That is why this is worth its own issue rather than reopening #2440.

Thanks @ez-lbz — the original report kept these two apart clearly, which is what made it obvious that fixing one would not cover the other.

What a fix looks like

nlohmann exposes no depth option, so the parse has to be bounded from outside it: either a SAX handler that tracks nesting and rejects past a configured depth, or a pre-scan of the payload before the full parse. Either way the limit is worth putting next to the existing buffer cap so both bounds are configured in one place rather than drifting apart.

Both call sites need it. subscriber.cpp:746 is easy to miss because the content it re-parses was stored by the SDK itself, but that content originated with the agent.

Scope

sdks/community/c++ only. The other community SDKs parse through different libraries and are worth checking separately, but not as part of this.

Tests

sdks/community/c++/tests/test_sse_parser.cpp, run through ctest, which is where #2501's byte-cap coverage already lives.