| name | maintain-assistant-orchestration |
| description | Maintain correlated assistant generation, provider admission barriers, streaming callbacks, cancellation/replacement, partial-message settlement, and optional ordered speech production. Use when changing request lifetimes or Chat/Live assistant event routing. |
Maintain assistant orchestration
Role and boundary
Keep AssistantCoordinator as the single frontend owner of one active generation and its optional speech producer. It coordinates typed callbacks and request identity; provider policy belongs to native/provider skills, while transcript storage and playback remain delegated.
Source map
src/assistant-coordinator.ts: AssistantCoordinator, AssistantProviderBarrier, OrderedSpeechProducer, ReplySpeechTarget, transition/idle waiters, request registration, stream-event filtering, and terminal settlement.
src/assistant-ipc.ts, src/llm.ts: typed command argument construction,
start boundary, provider stream events, and request-scoped cancellation.
src/sentence-chunks.ts: Unicode-safe 24/240-scalar sentence/word boundaries, soft 750 ms/80-scalar emission, and successful-completion flush rules.
src/chat-turn.ts: Chat admission plus correlated generation/tool callbacks; src/chat.ts: Chat composition and UI projection; src/live.ts: Live callbacks, pinned request registration, and optional speech target; src/tts.ts/src/speech-metrics.ts: speech target and text-free timing.
src-tauri/src/llm/mod.rs: local Rig request construction, visible-text
filtering, and the local text-protocol tool loop;
src-tauri/src/llm/provider_execution.rs: shared admission, command/terminal
lifecycle, cancellation, and external-provider streaming/tool execution.
Tests live in tests/chat-turn.test.ts,
tests/assistant-coordinator.test.ts, tests/llm.test.ts,
tests/sentence-chunks.test.ts, tests/benchmark-chunks.test.ts, and
tests/live.test.ts.
Cover
- Reserve provider work and register request identity before native streaming; serialize generation replacement and await prior cancellation/settlement before admitting the replacement.
- Ignore stale events by
requestId; emit/accept the started boundary before treating a command as cancellable, and never let a pre-cancelled reservation contact the local server.
- Persist visible deltas only, keep tool callbacks separate from provider history, and settle complete/interrupted/error assistant messages with diagnostic references.
- Keep LLM completion and speech drain as separate terminal states. Start speech concurrently, keep one enqueue in flight, advance
chunkIndex only after native acknowledgement, call finish only after all accepted chunks, and discard unfinished text on cancel/error.
- Preserve local-first privacy, typed closed routes,
conversationSessionId/speechSessionId/requestId separation, bounded queues, and callback guards for Chat versus spoken Live. Inspect current source before changing event unions.
Validate and accept
- Run
bun test tests/chat-turn.test.ts tests/assistant-coordinator.test.ts tests/llm.test.ts tests/sentence-chunks.test.ts tests/benchmark-chunks.test.ts tests/live.test.ts.
- Run
git diff --check against the actual files changed; run just check when the change crosses TypeScript/Rust/build boundaries. Exercise replacement, cancellation, empty answer, stale event, tool, speech failure, and Live barge-in paths with the packaged app via $test-voice-layer-app.
- Treat real
llama-server/ChatGPT streaming, native cancellation timing, and audible drain as separate acceptance gates.
Relationships
Use $maintain-chat and $maintain-live for consumers, $maintain-assistant-providers for native provider policy, $maintain-sessions for transcript persistence, and $maintain-voice-output for playback lifecycle.