Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Harness prompt echo to IM
Background
A Harness turn (scheduled task, watch, webhook, hook, vibe agent run) carries a
stored prompt. That prompt is persisted as a harness Message row —
core/message_mirror.mirror_harness_inbound on the legacy path, the
message_deliveries.message_snapshot(...) write on the durable Delivery path — and
Workbench Chat renders it, so the Web transcript reads trigger → result.
An IM conversation had no equivalent. mirror_harness_inbound only publishes live
for platform == "avibe", and no outbound send existed for the prompt, so Slack /
Discord / Telegram / Lark / WeChat only ever received the agent's reply: an answer
to a question nobody in the channel could see. A daily digest, a watch firing, or
another agent's vibe agent run all arrived as unexplained messages.
Goal
When a background task triggers an agent turn whose session is bound to an IM conversation, post the triggering prompt to that same conversation, once, just before the turn starts — so the channel reads trigger → work → result.
Non-goals:
- changing which message the scheduled thread anchors on (still the result, via
SessionHandler.finalize_scheduled_delivery); - persisting a second Message row (the
harnessrow already exists); - a Web UI toggle (the switch is config-only, like the other
harness_*runtime knobs).
Solution
Stage in the shared turn pipeline, send at the real turn start, gate and format in the dispatcher.
core/handlers/message_handler.py::_handle_turn— forsource != human, calls_stage_harness_prompt_echo(context, control_message), which stampsHARNESS_PROMPT_ECHO_SPEC_KEY(core/message_output.py) intoplatform_specific. Placement is the design:- after every
suppress_deliveryresolution (theagent_run_targetand thefind_session_for_anchorbranches, both settled only afterget_session_info), so a backgrounded session stays silent; - before
_prepend_message_metadata, so the staged text is the prompt, not the decorated backend dispatch text; - staging
control_message, the pre-routing prompt: subagent routing rewritesmessageto the prefix-stripped body, and the echo must match what the Workbench row shows, prefix included; - outside the mirror
if, so the durable Delivery path is covered too.
- after every
modules/agents/service.py::_begin_turn_status—_emit_staged_harness_promptpops the staged key and sends it, next to the existing turn-start hooks. The send belongs here, not in the pipeline:AgentService.handle_messageblocks on the runtime turn gate first, so a pipeline-side send would show a queued task's prompt while another turn is still working — or leave a prompt behind for a turn that was cancelled on the gate. Emitted beforebegin_status_bubbleso the channel still reads trigger -> work -> result. Best-effort,getattr-guarded, and bounded atHARNESS_PROMPT_ECHO_TIMEOUT_SECONDS = 5: this await holds the runtime gate, and an adapter's own request budget is much longer than a turn start may wait (Telegram allows 60s), so an unbounded send would let a degraded transport delay the background task itself plus every turn queued behind it. Same bound, same reason as thebegin_status_bubblepost right after. The staged text is popped first, so a timeout drops that one echo instead of deferring it.core/message_dispatcher.py::emit_harness_prompt— owns the gates and the send. Deliberately not routed throughemit_agent_message: this is neither agent output nor a lifecycle event, and must not consolidate into the status bubble, settle a turn, touch anagent_runsrow, or persist a row.- skipped for
avibe(Workbench renders the row),suppress_delivery, a trigger kind outsideHARNESS_PROMPT_ECHO_TRIGGER_KINDS(HARNESS_TRIGGER_KINDSminusactivity_recovery, which is a runtime re-injection, not a user instruction), andharness_prompt_echo = false; - target is
_get_target_context(context), so the question lands where the answer lands (post_to/ deliver-key overrides included); - text depends on who wrote the prompt:
watch/webhook/hookcompose it for the agent — a watch appends the waiter's raw stdout (core/watches.py::_build_prompt), an--on-failure agentescalation appends the generated failure report (core/scheduled_tasks.py::_escalation_prompt, "read by an AGENT, not shown to a user"), a webhook its payload. Publishing that into a shared channel would leak command output (tokens, stack traces) before the agent can redact it, so forHARNESS_PROMPT_ECHO_INSTRUCTION_ONLY_KINDSthe echo shows only the definition's stored instruction (harness_display_prompt) and stays silent when none resolves. The Workbench transcript still renders the full prompt for the operator. Read per-Delivery like the snapshots below (harness_display_prompts), because an instruction edited between two firings leaves a merged batch dispatching two different ones;- otherwise the Delivery display snapshots when present, else the staged prompt:
SessionTurnGateprepends internal instructions todispatch_text(the[Avibe recovery: ...]guard on an ambiguous-start replay) that must stay backend-only. All snapshots, de-duplicated: a busy session merges the queued deliveries of one definition into a single Turn (_collect_delivery_segment) and dispatches every prompt (_segment_dispatch_text), so the singular first snapshot would announce one instruction for a result answering several — twovibe agent runcalls merge under the sharedagent_rundefinition id. Repeat firings of one scheduled task carry the same stored prompt, hence the de-dup. Both branches share_harness_echo_merged_prompt(spec, batch_key, single_key);
- mentions are neutralized in the whole body, label included: quoting does not stop
a renderer from resolving
@everyone/ a bare Telegram@username(whichTelegramFormatter.renderHTML-escapes without defusing) /<@U…>/<@&role>/<!channel>, and the Discord adapter sends withoutallowed_mentions, so an echoed broadcast would really ping the channel. The@guard is every sigil followed by a word character, deliberately platform-agnostic — one body is rendered by every adapter, so a new adapter inherits it. A zero-width space after the sigil keeps the text reading the same; - sent with
parse_mode="markdown"so the>quote renders: Slack builds aplain_textblock for anything else and would show the markers literally; Telegram resolves either value to its own HTML default; - body: an i18n label per trigger kind, optionally
label · name, then the prompt with every line>-quoted (readable on plain-text platforms too), truncated atHARNESS_PROMPT_ECHO_MAX_CHARS = 800. The name is capped too (HARNESS_PROMPT_ECHO_MAX_NAME_CHARS = 80): it is appended after the prompt cap and task/watch names are never length-validated at creation, so an unbounded one could push the body past Discord's 2,000-char limit and the adapter would reject the echo, leaving the channel with no prompt at all; - dedupe: bounded per-process FIFO keyed on target + native/delivery id
(
HARNESS_PROMPT_ECHO_MEMORY = 256), so an in-process re-dispatch of one delivery cannot read as the task having fired twice. A cross-restart replay is not covered on purpose: it writes a new Delivery anyway, a duplicate echo is cosmetic, and a missing echo defeats the feature.
- skipped for
core/session_turns.py::_hydrate_delivery_batch_contextstampsdisplay_textsandharness_display_prompts, one entry per merged Delivery in FIFO order, next to the existingdelivery_ids—_hydrate_delivery_contextset only the singulardisplay_text, from the first Delivery. Snapshots are read from the stored text, neverdispatch_text, so the replay guards prepended there stay internal; instructions come from each Delivery's own captured provenance (_scheduled_provenance(payload)["platform_specific"]["harness_display_prompt"]).core/scheduled_tasks.py::_build_contextstampstask_definition_nameandharness_display_promptnext to the existingtask_definition_id, both resolved in one best-effort lookup (_definition_display_fields: task row, else watch definition), so the label names the task instead of an id and the echo has the user-authored instruction to fall back on. A producer that composed the prompt itself can override the instruction throughmetadata["harness_display_prompt"], which_execute_requestforwards fromTaskExecutionRequest.metadata— theagent_runpath already did, so without that forward the override was unreachable for exactly the enqueued hook / watch / webhook / escalation requests whose echo depends on it. The two scheduled call sites stay unchanged on purpose: a definition'ssession_forkmetadata must not be re-applied on every fire.agent_runhas no definition. Both survive a cross-restart replay: the flush restores every provenance key that is not execution routing (_EXECUTION_ROUTING_KEYSis a blocklist).- Config:
V2Config.runtime.harness_prompt_echo(defaulttrue), mirrored ontoAppCompatConfig+to_app_config(the turn path readscontroller.config, which is the compat object) and hot-reloaded inController._refresh_config_from_disk. The gate calls that mtime-guarded reload itself (_refresh_runtime_config), because a Harness turn passes through no IM inbound handler and would otherwise read the process-start snapshot. No UI, matchingharness_run_*— but it is projected invibe/api.py::config_to_payload, which is the deep-merge base of every/api/configsave: a runtime key missing there is rebuilt from the dataclass default, so an opt-out would silently revert on any unrelated settings save. The fourharness_run_*knobs are projected for the same reason (same latent bug, fixed here rather than left next to the new field). - Copy:
harness.promptEcho.*invibe/i18n/en.jsonandzh.json.
Evidence
- unit —
tests/test_message_dispatcher_scheduled.py::HarnessPromptEchoTests(per-kind coverage, every gate, delivery override, dedupe, memory bound, truncation/quoting, silent-only prompt, send failure, hot-toggle reload, a failing reload, display-snapshot precedence over internal dispatch text, instruction-only echo for the composed kinds — with the waiter output absent from the body and no echo at all when no instruction resolves — mention neutralization for the broadcast, id, and bare-@usernameforms, markdown parse mode, a merged batch echoing every distinct prompt while repeat firings of one task collapse to one, the same for a merged batch of edited instructions, blank snapshots falling back to the singular key, a long definition name bounded before the send);tests/test_internal_server.py::test_flush_suppressed_segment_claims_each_delivery_id_in_one_turn(the merged context carries both snapshots and both stamped instructions);tests/test_api_save_config_merge.py::test_save_config_preserves_harness_runtime_knobs_on_partial_save;tests/test_message_handler_harness_echo.py(pipeline staging: raw prompt, subagent-prefixed prompt staged unstripped, human turn stages nothing, blank prompt stages nothing, backgrounded thread resolution visible to the echo, and no send from the pipeline);tests/test_agent_service.py(turn-start emission: a queued turn stays quiet until it owns the runtime gate, the key is popped, no staged prompt echoes nothing, a failing echo never breaks turn start, a hanging echo cannot hold the gate);tests/test_scheduled_tasks.py::test_build_context_carries_the_definition_name_for_display,::test_build_context_prefers_an_explicit_display_prompt_from_the_request,::test_build_context_survives_a_store_that_cannot_name_the_definition,::test_execute_request_forwards_request_metadata_into_the_contextand::test_claimed_request_hands_its_metadata_to_the_execution(the metadata reaches the context through both hops of the enqueued-request lane). - scenario —
MESSAGE-DELIVERY-018(prompt precedes result; the result still owns the anchor) andMESSAGE-DELIVERY-019(background-visibility turn echoes nothing) intests/scenarios/message_delivery/. - manual — a real scheduled task in one IM channel per platform, plus a
vibe agent runcallback, to confirm ordering and formatting against live renderers (WeChat has no markdown).
Todo
- turn-pipeline call site and dispatcher helper
- definition name in the harness context
- runtime switch through V2 config, compat config, and hot reload
- en/zh copy
- unit + scenario coverage, catalog entries
- manual IM pass in the Incus regression environment