fix(synapbus-agent): early-exit on __coalesced__ synthetic triggers

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) <noreply@anthropic.com>
This commit is contained in:
Algis Dumbris
2026-04-15 19:19:46 +03:00
co-authored by Claude Opus 4.6
parent 42f8256df6
commit bd54aac82f
@@ -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