The `ask` tool asks and the answer -- or "nobody answered" -- becomes the observation. Read class: it changes nothing on the machine, and the authority is the operator, not a gate. Front ends: the chat draws a dialog (options to pick, typed words still count), the protocol carries it as an `ask` event and an `answer` command, MCP returns it from splinter_say and resumes with splinter_answer, the Telegram gateway sends it as a message and takes the next message from an allowed user. What the review of the WIP found, and what this fixes: - -p hung for the full 900 s ask wait: sp_engine_prompt installed engine_ask, but nobody polls events on the synchronous path. cfg.ask now stays NULL there, so the tool answers at once with "nobody can be asked here". Measured: 3 s instead of 900 s (was rc=124 after 20 s). - splinter_say over MCP hung the same way, because tool_say only looked at st.waiting. It now looks at st.asking and returns the question; the client timed out at 15 s before, and the turn was lost. - protocol.c read the question buffer uninitialized when sp_engine_ask returned 0. - turn_ask answered nothing when the window could not be opened, which parked the turn for the full wait. - pick_run computed the list height without the question's rows, so the highlighted row scrolled out of the window (reproduced: after nine Downs no ">" row was on the screen). pick_draw and pick_run now share pick_listtop(). - the Telegram gateway was dead for this tool: it runs its turns on a copy of e->base, where ask was never set, so the model was told "nobody can be asked" while the operator sat in the chat. New tg_ask, verified against a running daemon and covered in test_gateway.sh. - tests/test_ask_ui.sh was untracked and not in make check, so it never ran. A2A keeps no ask channel on purpose: there an approval pauses the task into INPUT_REQUIRED, and the ask signature cannot express a pause -- saying "nobody can be asked" is the honest answer there. Tests: make check green (327 s), including the new test_ask_mcp.sh and test_ask_ui.sh, both wired into make check. test_ask_mcp.sh was verified to fail against the unfixed code (client times out, no result written). make check-asan: 46 binaries clean. make check-tsan: 46 binaries, no races.
73 lines
2.2 KiB
Bash
Executable File
73 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# splinter -- A2A multi-turn: a contextId keeps the conversation.
|
|
#
|
|
# The fake model answers with the number of user messages it received. A fresh
|
|
# context must see 1, the same context again 2, another context 1. A request
|
|
# without a contextId gets one generated by the server, and continuing with
|
|
# that id also reaches 2.
|
|
set -u
|
|
cd "$(dirname "$0")/.." || exit 1
|
|
. "$(dirname "$0")/sh/port.sh"
|
|
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-a2a-ctx-XXXXXX") || exit 1
|
|
# Two servers, so two ports out of one call: asking twice returns the same
|
|
# number (see free_ports).
|
|
set -- $(free_ports 2)
|
|
P0=$1
|
|
P1=$2
|
|
F0=
|
|
F1=
|
|
cleanup() {
|
|
[ -n "$F0" ] && kill "$F0" 2>/dev/null
|
|
[ -n "$F1" ] && kill "$F1" 2>/dev/null
|
|
rm -rf "$D"
|
|
}
|
|
trap cleanup EXIT
|
|
mkdir -p "$D/home"
|
|
|
|
fails=0
|
|
check() { if "$@"; then :; else echo "FAIL $*"; fails=$((fails + 1)); fi; }
|
|
send() { # send <context-json-or-empty> <text>
|
|
ctx=$1
|
|
if [ -n "$ctx" ]; then
|
|
params="\"contextId\":\"$ctx\","
|
|
else
|
|
params=""
|
|
fi
|
|
curl -s -H 'Content-Type: application/json' --data \
|
|
"{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"method\":\"SendMessage\",\"params\":{\"message\":{\"messageId\":\"m\",\"role\":\"ROLE_USER\",$params\"parts\":[{\"text\":\"$2\"}]}}}" \
|
|
"http://127.0.0.1:$P1/a2a"
|
|
}
|
|
answer() { printf '%s' "$1" | grep -o 'users=[0-9]*' | head -1; }
|
|
context_of() {
|
|
printf '%s' "$1" | python3 -c \
|
|
'import json,sys; print(json.load(sys.stdin)["result"]["task"]["contextId"])'
|
|
}
|
|
|
|
python3 -I tests/fake_openai_count.py "$P0" &
|
|
F0=$!
|
|
check wait_listen "$P0" "$F0"
|
|
HOME="$D/home" ./splinter --no-config --endpoint \
|
|
"http://127.0.0.1:$P0/v1/chat/completions" --model m \
|
|
--a2a-server-listen 127.0.0.1 --a2a-listen-port "$P1" \
|
|
>"$D/out" 2>"$D/err" &
|
|
F1=$!
|
|
check wait_listen "$P1" "$F1"
|
|
|
|
r=$(send "ctx-multi" "eins")
|
|
check test "$(answer "$r")" = "users=1"
|
|
r=$(send "ctx-multi" "zwei")
|
|
check test "$(answer "$r")" = "users=2"
|
|
r=$(send "ctx-other" "eins")
|
|
check test "$(answer "$r")" = "users=1"
|
|
|
|
# no contextId: the server makes one and returns it
|
|
r=$(send "" "eins")
|
|
check test "$(answer "$r")" = "users=1"
|
|
ctx=$(context_of "$r")
|
|
check test -n "$ctx"
|
|
r=$(send "$ctx" "zwei")
|
|
check test "$(answer "$r")" = "users=2"
|
|
|
|
if [ "$fails" -eq 0 ]; then echo "test_a2a_context: ok"; exit 0; fi
|
|
exit 1
|