Sourced from
docs/architecture/orchestrator-live-turn.mdin the firmware repo.
Orchestrator Live-Turn Integration
This page explains how the Orchestrator's World memory (the vector store,
scratchpad, episodic history, and the memory.*/session.* tools) takes part in
one live model turn: the Orchestrator sees a composed World prompt, recalls and
writes memories, and drives sub-sessions within a single conversational turn. Read
it when you change the turn path, debug recall, or extend the turn contract.
This is the runtime that binds the portable engines to a real provider round-trip. For the engines and the context assembler themselves see orchestrator-world.md; for the field-by-field wire contract see ../reference/turn-contract.md; for the tool surface see ../reference/tool-catalog.md.
The design: World memory around one turn
A turn is still externally "one message = one turn": one owner message gets
one reply, carried by one terminal orch_turn JSON object. By default that object
ends the bounded head tool loop (NVS orchLoop, on by default): the model may
call registry tools such as memory.*, session.* and web.search over several
rounds, see each result, and then finish with orch_turn. The loop is capped at
ORCH_LOOP_MAX_ROUNDS (8) rounds and an ORCH_LOOP_DEADLINE_MS (10 minute) wall
clock, both owner-tunable (orchLoopRnds, orchLoopDlS). With the loop off, or on
a host whose wire has no tool loop (Z.ai, a custom endpoint), the LLM is called once
and returns one orch_turn. The per-provider wire for both paths is in
provider-wire.md; what the model sees is in
turn-anatomy.md.
Memory is folded around the turn on two sides, whichever path runs:
- Read side (automatic injection). Before the provider call,
runTurnpre-composes the World system prompt via the host-testedassembleContext(): the immutable rules, directive, capability manifest, running-sessions digest, scratchpad, and top-K associative recall from one embed of the user text. No LLM round-trip is spent to obtain this context. - Write side (optional turn arrays). The turn contract carries optional
mem_write[]/mem_query[]/session_ops[]arrays. After the terminalorch_turnis parsed,applyTurndispatches them in-process through the existingToolRegistry, with no extra LLM round-trip.mem_queryresults are not returned inline; they are parked and echoed into the next turn's inputs.
Both sides run on the tg_poll turn task, which is off the main-loop watchdog, so
a multi-second turn does not restart the device.
At every round boundary the turn keeps the chat alive (a typing indicator) and checks for messages that arrived mid-turn, but it sends the chat one progress line at most, and only for a turn a person started (the owner's or an approved member's message, or the serial console): a dream, routine, loop or sub-agent turn never signals the chat. The line is phrased in the assistant's own voice ("Still looking through my memory for that, a few minutes more.") and, on Telegram, is sent as a reply to the message the turn answers, so it shows with context.
Read side - recall then assemble
runTurn(inputs, chatId, userText) composes context before choosing a host:
-
Associative recall (one embed, fail-open). When
userTextis non-empty and free heap is at or aboveORCH_RECALL_MIN_HEAP(12000 bytes, the same value as the turn hard floorORCH_TURN_HARD_FLOOR: the recall embed is a second TLS handshake, but mbedTLS buffers live in PSRAM, so its only internal-heap cost is a small HTTP/JSON transient; it stays a named floor so a heavier build can raise it),memory::recall(userText)embeds the message once and runs a top-K cosinesearchover the VDB under the retrieval config. Synthesis turns (emptyuserText) skip recall. Any embed failure returns empty content and the turn proceeds - recall never blocks a reply. -
Prompt assembly.
composeInstructions(recalled)builds aContextInputsand callsassembleContext(ci, kContextBudgetMax)(kContextBudgetMax = 32768). The composed prompt, in the assembler's priority order, is:Section Source Immutable rules + output contract ORCH_ROLE(theorch_turnfield spec)Identity (device name, time, speaker) composed in compose.cppDirective (+ [RUNNING MEMORY])g_mem.directive()+g_mem.model()## CAPABILITIESrenderCapabilities(hw, memory::registry().manifest())## RUNNING SESSIONSrenderSessions(sessionInfos())Chat summary the chat's folded summary Recent conversation the per-chat window Scratchpad memory::scratchpad()## RELEVANT MEMORIESthe recalled top-K bullets ## HOW YOUR MEMORY WORKSthe static MEMORY_EXPLAINER(v1 prompt only; the v2 prompt, NVSorchPromptV2, drops this block)The capability manifest lists tools live from the MCP registry manifest, so it never drifts from what actually dispatches. The
hwdescriptor is read live each turn: the ring and touchscreen from HAL health and the fault mask, mic and speaker from the fault mask, battery from the board's battery-ADC build flag (set on every ESP32-S3 build), SD from the live mount state, the file store fromfiles::available(), Telegram fromtelegram::enabled(), and the Voice replies toggle fromstore::ttsEnabled(). Wi-Fi is always reported present (a turn only runs with Wi-Fi up) and Bluetooth always absent (it runs only in Notifier mode). The composed prompt is also stashed in the engine'slastInstructions_(read throughagent::orchestrator::lastInstructions()) so thePROMPT?console command can dump it without a provider round-trip.
The user/conversation text lives in inputs (separate from the system-prompt
budget), so message length is preserved independently of the budget.
Write side - the optional turn arrays
parseTurn accepts a turn whose only required field is reply; memory and
ask are optional strings (absent reads as "", so a turn that leaves them out
still applies its side effects). Every array is optional, and the live-integration arrays
are parsed tolerantly - a malformed item is dropped, never a whole-turn error,
so one slightly-off item can't lose a good reply. Each array is capped to
kAgentMaxJobs (6). applyTurn dispatches them after the model-memory update:
mem_write[]-{content, importance (clamped [0,1], default 0.5), permanent (default false)}. Dispatched tomemory.write(embed + store).contentis byte-capped tokMemModelMax(1200). This and thememory.writetool (mid-turn on the tool loop, or over/mcp) are the only paths that create a durable associative memory - the model must ask for it explicitly.mem_query[]- search strings. Dispatched tomemory.search; the hits are accumulated into the engine'spendingMemResults_and injected into the next turn's inputs as a[MEMORY RESULTS]block. This is the deferred-result pattern the sub-agent[FRESH RESULTS]channel already uses (takeFreshResults): the model asks in turn N and sees the answer in turn N+1, with no mid-turn network hop.session_ops[]-{op, id, task, provider, model, skill, name, project, attach}withopinspawn|tell|poll|terminate|list.spawnenqueues a sub-agent (the same enqueue path as the deprecatedspawn[]array);terminatecancels the job named byid;listis a no-op because the running-sessions digest is already injected every turn.tell/pollare not supported on this fire-and-forget fabric - the adapter'sanswer()only resumes aNeedsInputjob, it cannot inject a follow-up user message into a live sub-agent conversation. Rather than fail silently,applyTurnfeeds that boundary back through the[MEMORY RESULTS]channel so the model learns to usespawn+[FRESH RESULTS]instead.
If any mem_write ran, vectors and the scratchpad are persisted once at the end of
the dispatch. Writes run before reply is delivered, so a "remember X, ok?"
turn stores the fact and then confirms it.
Why the turn arrays still exist alongside the tool loop
The tool loop can do the same memory and session work mid-turn as tool calls, so the arrays are not the only write path. They stay because:
- One contract on every path. The arrays ride the
orch_turnobject itself, so the single-shot path (loop off, or a Z.ai or custom host with no tool loop) can still write memory, query it, and manage sub-sessions without native tool calls. On the loop path, a final answer can still carry its side effects with it. - Recall stays up front.
embeddings::embed()is a blocking TLS round-trip (1-3 s typical, up to ~20 s worst case), and every loop round is another sequential network hop through the single TLS slot. The read side spends its one embed before the first provider call, deterministically, instead of making the model ask for context it always needs. - Backward compatibility. Adding optional arrays is transparent - an old six-field turn still validates.
Episodic auto-capture
Memory has two capture paths with different triggers:
- Episodic history is automatic. Before a turn runs, the owner's message is
captured (
captureSession+captureMessage("user", …)) so the history is durable and queryable even if the turn later fails; after the turn, the assistant'sreplyandaskare captured. With an SD card mounted the store is an append-log of day streams under/mem/episodicwith uncapped history; with no card it falls back to anInMemoryEpisodicStorebounded to 500 messages and persisted whole-blob to LittleFS. Either way it is queryable viamemory.episodic. - Associative (VDB) memory is explicit. The vector store is written only by an
explicit
mem_write[]item ormemory.writecall - conversation is never auto-mirrored into the VDB.
Concurrency - a single writer on the turn task
All memory state is mutated from exactly one task: the tg_poll turn task. The web
and MCP surfaces never mutate g_mem directly. Instead they stage their intent
via flags (g_memClearReq, g_cfgReloadReq), which the turn task drains through
drainStaged() at the top of handleMessage and pollJobs - i.e. before the next
turn uses them. So directive edits and memory clears take effect at the next turn
boundary, on the writer task.
Cross-task reads are made safe without a second lock: the model-memory string
is mirrored into a fixed g_memEcho buffer (strlcpy, always NUL-terminated) that
the AsyncTCP web task reads, so the worst case is torn text, never a dangling
pointer across a realloc. Shared Config reads on the web/router side are
serialized by the ConfigLockGuard spinlock (portMUX_TYPE s_cfgMux). The lock
order, where both are held, is config → memory, matching the ConfigLockGuard
precedent.
Total concurrent TLS is bounded by the tls_arbiter work slot: Telegram holds its
own persistent session and every other TLS user (turn, dispatch, poll, STT, TTS,
media upload) must take the work slot before opening a WiFiClientSecure and give
it back immediately after close - so the single mbedTLS arena holds at most the Telegram
session plus one work session (two work sessions when Concurrent connections
is set to 2, applied at boot). The cloud relay keeps its WebSocket open between
requests, but its dial (connect, upgrade, hello) takes the slot, and so does every
response whose body is over 8 KB, its frame one 8 KB chunk at a time with the slot
released between chunks, so a turn waiting for the slot gets it within one chunk.
Heartbeats, acks and small responses, including the dashboard's 6-7 KB status polls,
take no slot, so the cloud dashboard stays live during a turn. The rule is on the
body, not the frame: base64 makes the frame about a third larger, and deciding on
the frame put every poll in the slot. Code a turn can reach takes the slot with the
arbiter::WorkSlot scope guard (nimbus/held_slot.h), which gives it back on every
path out, including a std::bad_alloc the turn catches; only the few non-turn sites
that test_held_slot lists still call acquireWork and releaseWork by hand.
tests/hil/test_l41_tls_slot_guard.py (a source check, no board) fails on any new TLS
connect that does not take the slot first, in either form.
PSRAM-backed mbedTLS - the unblock for every live turn
ESP.getFreeHeap() reports internal RAM only: ~218 KB at boot but ~63 KB by
turn time in Orchestrator mode once Wi-Fi, the web server, the World-memory
subsystem, and the always-on turn task are up. A single mbedTLS handshake wants
~40 KB contiguous and was failing with -0x7F00 (MBEDTLS_ERR_..._ALLOC_FAILED)
at ~50 KB.
The S3's 8 MB PSRAM is not in the default malloc pool, so at startup - guarded by
ESP.getPsramSize() > 0 - the firmware installs a PSRAM-backed mbedTLS allocator:
mbedtls_platform_set_calloc_free(
[](size_t n, size_t sz) -> void* { return heap_caps_calloc(n, sz, MALLOC_CAP_SPIRAM); },
free);
TLS record/session buffers are CPU-processed, never DMA, so external RAM is correct here; every driver DMA buffer keeps using the default internal allocator, untouched. This lifts the whole handshake off the scarce internal heap and unblocks every live turn - and recall's second TLS handshake within a turn.
Inbound Telegram: albums, bursts and the storm guards
Every inbound Telegram page goes through one receive cycle on the tg_poll task
(nimbus/net/tg_receive.h, host-tested end to end in test_tg_burst; the device seam
is src/agent/telegram.cpp). One cycle:
- Fetch one
getUpdatespage at the RAM offset cursor (the archive sees it as read, before anything else; an update already saved this boot costs no card read). - Settle (
nimbus/net/tg_settle.h). A phone uploads an album one photo at a time, so the first poll often holds only part of it, and an owner often sends a text and then the photo it is about a few seconds later. The page is held (re-polled with timeout 0 on the same keep-alive socket after a pause of up to 1 s, shorter at the end of the window, plus the rest of the poll loop) until it has not grown for its window, which follows the newest message: 6 s after a plain text (for the photo, file or voice note sent next) and 3 s after a photo, file or voice note (for the rest of an album). Only a message from an allowed chat that could become a turn restarts the window (a stranger's message or an edit does not). It is answered at once when it holds a slash command from an allowed chat (commands never wait) or nothing that could become a turn, when it is full (10 updates), when its newest Telegram date is older than its window plus 2 s, or once 15 s have passed since its first item was seen (the cap on a burst). The 6 s text window joins a photo sent 5 s after its text by Telegram's whole-second dates (the 25 Oct 2026 pair); a photo that arrives later runs as the next turn (step 4). While a text is held its chat sees Telegram's typing indicator: once at first sight, again if the hold outlives the indicator's 5 s, sent on the open poll socket (no handshake; a socket that does not answer within 1.5 s is closed). A plain text with nothing after it is answered when its window ends. The hold is page-wide: another allowed chat's message can extend it (up to the 15 s cap) and another allowed chat's command answers the page at once. A hold classifies, acks and stores nothing, and a re-poll that returns the same page is not handed to the archive again; local turns, job polling and reply sends keep running between re-polls. Keeping the poll socket open is safe only because every other TLS session of the task opens throughworkConnect, which closes it first. - Break duplicates and classify (
nimbus/net/tg_dup_guard.h). A message already answered (same chat, message id and date), or the same content in the same chat within 2 minutes and before its answer went out, is acked and skipped, with one owner notice per episode. Text joins its chat's turn; a photo or document becomes a media segment of that turn (its caption with it, at full length) and takes one of ten download slots (a lazily allocated PSRAM array); a voice note joins its chat's turn the same way (one per turn: a second voice note starts the next turn) and takes a slot; a command is a turn of its own. On a page that holds a command every turn is one unbroken run of update ids (so a restart re-runs at most the turn in flight), so a chat's messages split around another chat's message there. An eleventh media item waits for the next page. A photo with no caption is described with the text sent just before it in the same turn, as a caption would be. - Run each turn in order. Past the hourly ceiling (60 inbound head turns in any
rolling hour, 12 of them reserved for the owner's chat, so the other allowed chats
stop at 48; commands do not count) a turn is skipped, with one owner notice per
trip. Otherwise every photo of the turn is fetched (its 800 px size), hashed, handed
to the archive (which fetches its own largest size later) and stored, in album
order, with a typing indicator at most
once per photo and only 4 s or more after the last; then the turn runs with every
item of its bucket (
MessageBatcher::render, the one labelnimbus/orch/media_label.h). A failed item is part of the turn, never a separate reply, unless the turn has nothing else (no text, no caption, nothing fetched): then one plain reply says why, instead of a paid turn. A voice note that cannot be fetched or transcribed is named in its turn ("could not be heard"; the sender was told); alone it gets that plain reply and no turn. A turn whose first message was sent before its chat's previous answer went out (a photo that missed its text's turn) ends with a short note to the model that the previous answer is already in the chat, so it is answered with that answer in mind; the history and the memory-recall query keep what was sent, without the note. How each photo reaches the head is described under "Photos go to the head as images" below. - Commit. Only after the page's turns returned does the cursor move past it (a page holding a command checkpoints after each bucket), so a reset anywhere re-serves the page and the duplicate breaker skips what was already answered.
The owner notices this cycle raises (a repeat skipped, the hourly ceiling, work that
crashed the device twice), and the settings-storage and file-store notices the poll task
sends, go to the owner chat on Telegram with a copy in its history. A device with no
Telegram owner (a web-only setup) gets them as messages in the web chat instead
(nimbus/net/owner_notice.h), worded for the web chat's reader (a guard notice names the
Telegram message, never "you"), and a storage notice already in the web chat from the last
24 hours is not written again while the store stays full.
Photos go to the head as images. A photo is sent to the head model as an image,
not as a description of it (nimbus/orch/turn_images.h). Every photo the device can keep (the bounds below) has its bytes copied into
one PSRAM buffer held for the turn and its label reads (attached: the photo itself is in this message), whatever head is configured: the host that serves
each request decides, at that request, whether it reads images (every Claude
model; OpenAI gpt-4o, gpt-4.1, gpt-5 and newer; Mistral chat models with
vision, by one rule, headTakesImages). The provider's own model list decides
when it says yes or no for the exact model; a model it has no row for (a
-latest alias, a model newer than the last fetch) and a device with no list
fall back to the name rule, which the model catalog's vision role shares
(mistralVisionByName): a wrong guess costs one refusal, answered by re-
sending the photos as transcriptions. A seeing host gets the pixels and no
caption call is made; a blind host reads each photo's machine transcription,
made only then, once per photo, so a turn that fails over from a blind host to
a seeing one still sends the pixels.
The channel offers the turn's photos to a single slot
bound to the chat and the routed text; the engine takes them when the owner turn starts
and every head loop seeds its transcript with them. Each renderer puts them into the
seeded user message, the newest user message of the request, as its provider's image
parts (Anthropic image, OpenAI Responses input_image with detail high, Mistral
image_url), each after a one-line label naming its ref and before the turn text; an
image part never carries the cache point, so later rounds read the photos from the
provider's cache. The bytes are never a JSON string: the renderer writes a marker, the
body records a splice (http.h BodySplice), and the transport base64-encodes each
4,096 B slice from the PSRAM copy at send time, so a 2 MB album costs one 4 KB slice
buffer, never internal heap. Before each slice after the first, while the largest free
internal block is under 12 KB, the transport waits in 10 ms steps for the previous
slice's acknowledged segments to free their buffers (large bodies used to fail an
allocation now and then). It stops as soon as the block has room or has set no new
high for 100 ms (one round trip; on a fragmented heap the block never grows), at most
1.5 s per slice, and one request waits at most 2 s in all, or a tenth of its deadline
when that is less; after that every slice goes out at once (http.h SliceWait,
paceSlice, paceCapMs). On an Anthropic head with a direct key each photo is
uploaded once (the Files API, raw bytes) and every round references it by file_id.
Bounds: 10 photos, 512 KB each, 2 MB per turn (looked photos included); a photo past
them, an animated GIF, a format no head reads, a host without image input, and a
provider that refuses the image parts (for the rest of the turn on that provider; a
failover to another host still sends them) all fall back to the caption step, whose
text is labelled (transcribed by <provider>) so the head knows it has not seen the
photo. A photo
nobody could read says why, one label per cause ((not read: openai out of credit (HTTP 429)), (not read: too large), (not read: device low on memory)), never the
provider's own words; the prompt explains the family in one line.
The caption step (nimbus/harness/vision_caption.h) runs current models only
(claude-haiku-5-5, gpt-5.6-luna, mistral-small-latest), detail high and low effort, and
walks the keyed providers in priority order, sticky per page. A billing or key refusal
parks that provider through the one shared park (every seam, not just photos) and the
walk moves on in the same photo; a server error or a dropped connection moves on
without parking; the owner gets one notice per episode, shared with every seam. It is
only ever asked for a host that cannot see images: a photo the head saw gets no caption
call at all. A turn that runs as a single shot (the tool loop off, or deferred when the
device is low on memory at the turn's start) counts as such a host: it sends no photo,
so its photos are read by the caption step.
What the conversation keeps of a photo. The head writes the photo's record itself:
with its answer it calls image.note {ref, note}, one line of what matters in the photo
(a pure write: sent with the final answer it costs no extra round). The photo's stored
row is written as (kept; image.look shows it) before the turn runs and settled when the
turn ends, before it is ever sent as history: (seen; note: ...) with the head's note,
(seen in its turn; image.look shows it again) without one (an answered request
carried the photo), or a blind host's transcription when only such a host served the
turn. A history message is never rewritten after it was sent, so the cached prefix
holds; the only late rewrite left is a photo that only a blind host met and nobody could
read, read again once its provider is open after a refusal (the episodic overlay,
nimbus/orch/row_overlay.h).
Earlier photos come back as pixels. image.look {ref, question} reads the photo's
stored copy from the card (the card lock held only for that read) and puts it back in
front of the head as an image for the rest of the turn: Anthropic in the tool result
itself ([text, image]), OpenAI and Mistral in one user message right after the round's
results ([label, image]). Only a host that cannot see images reads one caption
request's answer to the question instead (made once). At most 4 photos per turn come back
this way, inside the same byte bounds; a routine, which holds no photo set, gets the
caption answer. On Anthropic with a direct key a recent photo also rides its own
history message: the file uploaded in its turn is kept for that chat (at most 16, RAM
only) and while its label is in the history window its first message carries it as a
file reference before the message text, the same bytes every turn. A kept file unused
for an hour, or 100 minutes old, is deleted (the poll task's idle step, one deletion
per cycle), and every upload asks the provider to delete it by itself two hours after
it was made, so one a restart left behind is gone by then. A refusal of a kept file
deletes the file it names (all of them when it names none) and the round is sent again
without it. Mistral and OpenAI have no file references: they view an earlier
photo through image.look only, never by re-sending it every turn. What the caption
step bills rides the next turn's per-host spend record. device.status carries
visionLastErr.
The poison guard. Media are acked only after processing, so a page whose processing
crashes the device would be served again on every boot. The work in flight is marked in
a record in RTC no-init memory (magic, build id, CRC; no settings write; a power-on
clears it): the page while it is classified, each photo while it is fetched and
described, each turn while it runs. The record is two copies with a sequence number:
every write goes to the copy not in use and seals its CRC last, and a boot takes the
newest copy that checks out, so a restart in the middle of a write keeps the previous
state instead of clearing it. A boot after a panic, watchdog or brownout counts a try
against the mark (main.cpp hands the reset reason to telegram::begin, which boots
the record and publishes its counters before the poll task starts); after two
such resets on the same work it is skipped and only the owner's chat is told to send it
again: a crashing photo becomes "could not be fetched: it made the device restart twice"
in a turn that still answers everything else, a crashing turn is acked without running,
and a page that crashes while it is classified is acked unprocessed. A page served
again keeps a mark that lies inside it, so the count survives a command page's
per-bucket checkpoints. The duplicate breaker and the hourly ceiling keep their state
in the same record, so a restart in the middle of a storm keeps it at one paid turn.
Voice and Telegram-media adapters
Speech and media share one uploader and a provider-configurable STT/TTS pair.
Shared multipart uploader (http_multipart). A tiny RFC-2388
multipart/form-data POST over WiFiClientSecure that streams one file
straight from LittleFS so a multi-KB audio/image upload never sits in internal heap.
It is HTTP/1.0 Connection: close with the Content-Length computed up front from
the field framing plus the on-disk file size. Its TLS buffers come from the PSRAM
allocator above. It backs both the STT upload and Telegram sendVoice/sendPhoto/
sendDocument.
STT (stt::transcribe). The provider is store::sttProvider, defaulting to
Mistral Voxtral (api.mistral.ai, voxtral-mini-latest), with OpenAI
selectable (api.openai.com, gpt-4o-mini-transcribe). A Cumulo-keyed device
with no provider key of its own routes through the Cumulo router instead
(/router/openai/v1/audio/transcriptions, gpt-4o-mini-transcribe). All of them
expose POST .../audio/transcriptions as multipart and return {"text": …}. Because
solide::audio::recordToFile emits headerless 16-bit mono PCM, stt::transcribePcm
wraps it in a canonical 44-byte-header WAV before upload. Transcription is
fail-open: any failure returns "" and the caller nudges the owner to send text.
TTS (tts::synthesizeToFile). The provider is store::ttsProvider, defaulting
to Mistral (voxtral-mini-tts-latest), with OpenAI selectable
(gpt-4o-mini-tts) and the Cumulo router used by a Cumulo-keyed device
(/router/openai/v1/audio/speech, gpt-4o-mini-tts); all use the audio/speech
endpoint, and the audio is streamed
straight to a LittleFS file so a clip never sits in internal heap. The response
shapes differ: OpenAI honors response_format (wav/mp3) and returns raw binary;
Mistral ignores it and always returns MP3 as base64 inside {"audio_data": …},
which is stream-decoded to the file. The device speaker plays both: the speaker
path (speakOnDevice) asks for the format the effective provider actually emits
(core::speakerTtsFormat: WAV from OpenAI and the Cumulo router, MP3 from Mistral)
and plays WAV directly or decodes MP3 with the vendored minimp3, so a Mistral-only
device speaks on its own speaker too.
Outbound media on the poll task (sendMedia). A send publishes a single
pending-media slot under the g_mediaMux spinlock; the tg_poll task drains it via
drainMedia() after closing the poll socket, so the Telegram poll session is
not resident while the upload holds a work slot. Kinds document/photo/voice/audio map to
the Bot API sendDocument/sendPhoto/sendVoice/sendAudio methods.
Spoken reply path. Speaking is the model's choice, gated by the owner's
Voice replies toggle (store::ttsEnabled(), on by default). reply.speak
calls speakOnDevice, which queues the clip on the sound task and waits (up to
10 s, on the poll task) for that task to open the speaker; it refuses with a reason
when voice replies are off, the speaker volume is 0, the text is over 1,200
characters, synthesis failed or the speaker driver would not start (every
spkOpen in music.cpp goes through one helper that logs and reports a failed
open). reply.telegram with voice:true never touches the speaker: voice_reply.cpp
splits the text into voice messages (nimbus/orch/voice_notes.h: at most 600
characters each, 2,400 per call), synthesizes each to its own LittleFS file
(/tgv-*.mp3), uploads it at once with telegram::sendMediaNow (the poll task owns
the TLS arena during a turn), reads Telegram's message_id from the answer
(nimbus/net/tg_receipt.h), logs telegram: sendAudio ok (message_id N, B bytes) or
FAIL with the reason, and deletes the file after the archive hook copied it. The
whole call has one 150 s budget (it holds the poll task), so on a slow network it stops
before a message that cannot finish and says how many arrived. The
tool's result carries those receipts, and the turn's effect ledger records a voice send as
delivered only with one. Text-to-speech gets a read window sized to its text (25 s up to
60 s), and a clip the window or a dropped connection cut short is removed and
reported as "truncated at N B", never used; a failed flash write is reported as that instead. A raw body (OpenAI, the router) that ends by
the server closing the connection with no stated length is judged by its own framing
(nimbus/orch/clip_probe.h, fed as the bytes arrive): an MP3 whose last frame is unfinished,
a WAV short of a whole sample or of its declared data size, or audio far shorter than its
text takes to say is cut; a stream the probe cannot follow gets no verdict, and a stated
length or Mistral's closing quote decides as before. The tts device action goes through the
speak sink (orchSpeakSink in main.cpp), which plays on the speaker first and
falls back to the same Telegram voice path only when the speaker could not play it. The
sink answers with how it ended (nimbus/orch/speak_outcome.h: the speaker, a Telegram
message id, or why not) and apply.cpp records exactly that: nothing is captured to
history unless it was voiced, volume 0 is refused before any synthesis, text over 400 bytes
is cut on a character boundary and the reply says so, a tts-only turn that could not be spoken
sends its text in writing with the reason, and the turn's effect ledger holds a Speak that
landed or a voice send with a receipt.
The reply tools run outside the memory card lock (handleMcp): only their history
row takes it.