3 Commits
Author SHA1 Message Date
lotherk e7e47b7f1d json: a depth limit, so a nested body cannot kill the process
The parser recurses once per container and had no limit. The OpenAI gateway and
the A2A server hand it a caller's body of up to 4 MiB, so a request of 200k
nested arrays was a remote crash: verified against a running gateway, the
process died and the client got an empty reply. 200k arrays are a 400 KB body,
well inside what both servers accept.

J_MAX_DEPTH = 64 is far past any real document (a tool schema nests four or
five deep) and far short of a stack frame budget. A deeper document is now a
parse error, which both servers already answer with 400.

Proof in tests/test_fuzz.c (test_json_depth): 200k nested arrays crash without
the limit and parse as NULL with it; an ordinary document still parses.

make check: all tests passed. make check-asan: all 45 test binaries clean.
2026-11-23 00:56:58 +00:00
lotherk a1794fb101 engine: /self-check, and tool arguments must be one JSON object
/self-check (and /selfcheck) takes the last three turns of the conversation,
every failed tool result in them and the last turn's error, and starts a turn
with them: something went wrong, check yourself instead of asking the
operator, name the cause and continue. Messages are capped per message and in
total, oldest dropped first; it is refused mid-turn like /compact and is in
the completion list.

mcp_parse() stops at the closing brace, so a tool-call argument string holding
two objects parsed as the first one and the second command disappeared without
a word -- measured in sess-1795032073, where "cat a" ran and "cat b" was
silently dropped. mcp_parse_exact() requires the whole text to be the one
value; the agent's tool-argument validation uses it, so such a reply is
retried and then fails with "model sent malformed tool arguments" instead of
running half the command.

test_engine drives both spellings and the included turn; test_agent drives the
joined-argument reply (three requests, zero tool calls). test_engine and
test_agent pass; the build is -Wall -Wextra -Werror clean.
2026-11-18 21:54:04 +00:00
Konrad 15581139d5 splinter: conversation, OpenAI adapter, end-to-end over HTTP
Splinter can now talk to a real endpoint: --endpoint plus --model shapes the
whole conversation into one chat/completions request and parses the reply back.

The seam changed from a raw string to the conversation, because a provider
adapter cannot invent history and the loop must not depend on vendor JSON:

- sp_conv: owned messages (role, name, call_id, content, raw tool_calls),
  geometric growth, trim from the front. Copy on push, so a compaction step
  must produce a new array - which is what makes it reviewable.
- sp_openai_request(): conversation + tool table -> JSON body.
- sp_openai_reply(): choices[0].message -> content + calls, and it keeps the
  provider's raw tool_calls array to hand back verbatim next round.
- provider error objects, empty choice lists, non-JSON bodies and empty bodies
  each produce a distinct, quoted error instead of a silent empty answer.
- transport_openai: curl, body through a temp file, status from curl's -w, key
  from the environment only.
- libmcp's JSON parser is vendored and instantiated exactly once (src/json.c);
  two instantiations would be a link error rather than a silent duplicate.

Proven end to end against a local stub speaking the real wire format:
request 1 (1 message, 2 tools, 448 bytes) -> tool_call for echo; splinter ran
the tool, request 2 (3 messages, 682 bytes) -> final text; the session log
holds user, observation, assistant.

Nine test binaries green, including test_openai (request shape, tool_call
parsing, raw array kept, four failing reply shapes) and test_conv.
2026-11-07 13:34:26 +00:00