From bd54aac82f8b3f70d2c9035c4bfde3b0f6f825bc Mon Sep 17 00:00:00 2001 From: Algis Dumbris Date: Wed, 15 Apr 2026 19:19:46 +0300 Subject: [PATCH] fix(synapbus-agent): early-exit on __coalesced__ synthetic triggers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the reactor sets pending_work while an agent run is in progress, checkPendingWork fires a synthetic follow-up event with FromAgent= __coalesced__ and body="Coalesced trigger: process all pending messages." That event gets delivered to the container as a message.json with that placeholder body, and the wrapper happily feeds it to gemini — which then produces a spurious "What does this demo do?" reply because the only thing the model sees is a generic filler body. The doc-gardener coordinator kept emitting stray replies to algis between real DELEGATED: messages because of this. The reactor would fail the coalesced run ("Received system trigger..."), the critic would get confused by intermediate traffic, and the /goals panel would accumulate garbage. Wrapper now checks $FROM at the top of main. If it's __coalesced__ we log it and exit 0 without invoking the CLI. The reactor marks the run succeeded, no tokens burned, no spurious DMs produced. Any real pending work re-triggers naturally when the next actual message arrives. Smoke-verified: docker run --rm -v /tmp/test:/workspace synapbus-agent:latest \ /usr/local/bin/synapbus-agent-wrapper.sh [wrapper test] cli=gemini from=__coalesced__ body_bytes=9 [wrapper test] synthetic coalesced trigger — skipping CLI invocation EXIT=0 Co-Authored-By: Claude Opus 4.6 (1M context) --- image-build/synapbus-agent/synapbus-agent-wrapper.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/image-build/synapbus-agent/synapbus-agent-wrapper.sh b/image-build/synapbus-agent/synapbus-agent-wrapper.sh index a498ddd..46a1253 100644 --- a/image-build/synapbus-agent/synapbus-agent-wrapper.sh +++ b/image-build/synapbus-agent/synapbus-agent-wrapper.sh @@ -33,6 +33,16 @@ FROM=$(jq -r '.from_agent' < /workspace/message.json) log "cli=$CLI from=$FROM body_bytes=$(printf '%s' "$BODY" | wc -c)" +# Synthetic coalesced trigger — fired by the reactor when pending_work +# was set during another run. There's no real user message to respond +# to; invoking the CLI here would just produce a spurious reply based +# on the placeholder body. Exit 0 so the reactor marks the run as +# succeeded without burning LLM tokens. +if [ "$FROM" = "__coalesced__" ]; then + log "synthetic coalesced trigger — skipping CLI invocation" + exit 0 +fi + case "$CLI" in gemini) PROMPT_FILE=/workspace/GEMINI.md