Guard all prompt_async paths against empty bodies

This commit is contained in:
Rebase Agent
2026-05-14 15:56:03 +00:00
committed by Forgejo
parent cb6986c8f9
commit 6f2c4de113
+23
View File
@@ -254,6 +254,14 @@ send_message_capture() {
local body="$2"
local out_file="$3"
# Refuse to send empty bodies — the server logs them as
# "No user message found in stream. This should never happen."
if [[ -z "$body" ]]; then
log_warn "send_message_capture: refusing to send empty body to ${sid}"
: > "$out_file" 2>/dev/null || true
return 1
fi
# Use prompt_async — fire-and-forget; server returns 204 immediately.
# The synchronous /message endpoint would block until the agent finishes
# its full response (potentially many minutes for a busy worker).
@@ -640,6 +648,13 @@ Evaluate the health of this session."
printf '%s' "$eval_prompt" > "$eval_tmp"
local eval_body
eval_body=$(jq -nc --arg a "worker-health-evaluator" --rawfile t "$eval_tmp" '{agent: $a, parts: [{type: "text", text: $t}]}')
if [[ -z "$eval_body" ]]; then
# jq failed (likely couldn't read eval_tmp) — bail rather than send empty
rm -f "$eval_tmp"
delete_session "$eval_sid"
echo "ok"
return
fi
curl -sf -X POST "${BASE}/session/${eval_sid}/prompt_async" -H "Content-Type: application/json" -d "$eval_body" >/dev/null 2>&1
local eval_deadline=$(( $(date +%s) + 120 ))
while [[ $(date +%s) -lt $eval_deadline ]]; do
@@ -1204,6 +1219,14 @@ main_loop() {
printf '%s' "$prompt_text" > "$tmp_prompt"
# Belt-and-braces: confirm the file actually has content on disk
# before launching the session.
if [[ ! -s "$tmp_prompt" ]]; then
log_warn "[pool:${prefix}] prompt file empty after write for ${kind} ${work_num} (${agent}) — skipping launch"
rm -f "$tmp_prompt"
continue
fi
$SESSION_START --server "${BASE}" --tag "$worker_tag" --agent "$agent" --prompt-file "$tmp_prompt" --restart \
>/dev/null 2>&1 &
pids+=($!)