Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix(voice): form-fill turns stop misrouting to brain_capture; prevent TTS echo from round-tripping as duplicate captures

Adam Eivycbf84939ff59
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index bd17e5dc75..ebaa48709e 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -42,6 +42,8 @@
## Fixed
+- **Voice agent wrote to the brain inbox instead of filling the target form field, then captured its own TTS summary as a second brain entry** — two coupled bugs. (1) `brain_capture` was always-on in the per-turn tool list, so on UI form-fill turns ("fill description with X", "type Y in the title", "put Z in the body") the LLM saw both `ui_fill` and `brain_capture`. Because `brain_capture`'s description emphasizes "note/save/remember/jot" — words that overlap with field content — the model frequently picked capture over fill. Moved `brain_capture` into the `brain` group, expanded the brain intent regex to still catch natural phrasings ("remember to buy milk", "jot down", "note that…", "save this/that", "file this", "add this to my brain inbox"), and added a `UI_FILL_INTENT_RE` that detects form-fill verbs near a field-word ("description/name/title/subject/body/content/field/input/textarea/form/label/placeholder/caption") and forcibly suppresses `brain_capture` + `daily_log_append` for that turn (also force-activates the `ui` group so `ui_fill` reaches the LLM even when the verb wasn't already in the UI regex, e.g. "put Y in the body"). System prompt gains a CRITICAL section that explicitly forbids capture tools on field-fill turns regardless of content words. (2) In hands-free mode the VAD used `bargeInMul=1.15` and `ttsTailMs=300ms` — too permissive for typical speaker→mic coupling. The bot's TTS output crossed the raised threshold, VAD transitioned to "speaking", captured the bot's own voice, submitted it as a new `voice:turn`, and the LLM processed its own paraphrased summary as a user command — creating a duplicate brain entry. Raised `bargeInMul` to 2.5, extended `ttsTailMs` to 700ms for typical room reverb, and added `bargeInOnsetConfirmMs=220` so during TTS playback + echo tail the VAD requires sustained signal (not a brief echo spike) before confirming speech-onset. Deliberate barge-in still works (sustained speech above the raised threshold). 10 new tests cover the tool-filter behavior (fill patterns drop brain_capture; natural capture phrases keep it; UI-only turns exclude brain_capture; expanded brain regex matches "remember"/"jot"/"note that").
+
- **Voice agent lost context after `ui_navigate`, couldn't chain "go to tasks and create a new one"** — the tool-calling loop only paused for a client UI-refresh push when a `ui:*` side effect fired (`ui_click`, `ui_fill`, etc.). `ui_navigate` emits a `navigate` side effect, so the next LLM iteration ran against the old page's UI summary — it couldn't see the new page and effectively ended the turn without acting on the user's next step. `pipeline.js` now treats `navigate` as UI-mutating too and awaits the post-navigation `voice:ui:index` push (1500ms timeout since a full React route change + lazy-loaded bundle is slower than a ~120ms post-click DOM mutation). The fresh page summary is attached to the tool result so the LLM can chain follow-up `ui_click`/`ui_fill`/etc. in the same turn. System prompt updated to include `ui_navigate` in the CHAINED UI FLOWS guidance with a worked "go to tasks and add a task" example.
- **Daily Log unusable on mobile** — the tab split into a fixed 256px history sidebar plus a desktop-only toolbar (back/forward/date/today/read-back/dictate/save/delete all on one non-wrapping row), so on phones the history ate most of the screen and the action buttons overflowed offscreen. Sidebar now collapses into a slide-in drawer (hamburger in the toolbar opens it, tap outside to dismiss), toolbar wraps with the full date label breaking to its own row, and action-button text hides below `sm` leaving icon-only buttons with tooltips + aria-labels. All interactive targets bumped to 40px minimum height per the mobile touch-target rule, banner/form paddings tightened for narrow viewports.
diff --git a/client/src/services/voiceClient.js b/client/src/services/voiceClient.js
index 192d587fa3..919605320d 100644
--- a/client/src/services/voiceClient.js
+++ b/client/src/services/voiceClient.js
@@ -288,12 +288,21 @@ const VAD = {
minSpeechMs: 250, // ignore utterances shorter than this (noise blips)
preRollMs: 250, // audio kept before detected speech start
onsetConfirmMs: 80, // frames required above onRms before firing speech-start
+ bargeInOnsetConfirmMs: 220, // during TTS + echo tail, require longer
+ // sustained signal before confirming barge-in — a
+ // brief leak from the bot's own voice shouldn't
+ // look like the user starting to speak.
calibrationMs: 600, // ambient-noise sampling window at startup
- bargeInMul: 1.15, // small bump over onRms during TTS to dampen echo
- // bleed. Higher blocks real speech with calibrated
- // thresholds; lower trusts echoCancellation alone.
- ttsTailMs: 300, // echo-tail window: keep bargeInMul active for this
- // long after the last TTS chunk ends to ignore reverb.
+ bargeInMul: 2.5, // multiplier applied to onRms during TTS + echo
+ // tail. Was 1.15 which let loud TTS re-trigger the
+ // VAD; 2.5 still allows deliberate barge-in while
+ // rejecting speaker-to-mic bleed. Lower this only
+ // if users complain barge-in is unresponsive.
+ ttsTailMs: 700, // echo-tail window: keep bargeInMul active for this
+ // long after the last TTS chunk ends to ignore
+ // room reverb. 300ms was too short for typical
+ // rooms — the bot's final syllable kept trailing
+ // back through the mic and getting transcribed.
maxSpeechMs: 15000, // runaway-speech watchdog: if silence never registers
// (noisy env, stuck state), force submit/discard.
debug: false, // window.__portosVadDebug = true to enable logging
@@ -428,11 +437,13 @@ const handleFrame = (frame) => {
if (vadState === 'idle') {
// Raise the bar while TTS plays AND during the echo tail so neither the
// bot's live audio nor reverb through the mic trigger a false barge-in.
- const effectiveOnRms = isInTtsEchoWindow() ? onRms * VAD.bargeInMul : onRms;
+ const inEcho = isInTtsEchoWindow();
+ const effectiveOnRms = inEcho ? onRms * VAD.bargeInMul : onRms;
+ const effectiveConfirmMs = inEcho ? VAD.bargeInOnsetConfirmMs : VAD.onsetConfirmMs;
if (rms > effectiveOnRms) {
onsetFrames += 1;
const frameMs = (frame.length / (continuousCtx?.sampleRate || 48000)) * 1000;
- if (onsetFrames * frameMs >= VAD.onsetConfirmMs) {
+ if (onsetFrames * frameMs >= effectiveConfirmMs) {
// Confirmed speech onset — barge-in + start capturing
vadState = 'speaking';
speechStartedAt = now;
diff --git a/server/services/voice/pipeline.js b/server/services/voice/pipeline.js
index 820b4fafb6..33e9a557f2 100644
--- a/server/services/voice/pipeline.js
+++ b/server/services/voice/pipeline.js
@@ -119,6 +119,7 @@ const buildSystemPrompt = (cfg) => {
'Trigger phrases that REQUIRE a tool call: ' +
'"open"/"go to"/"take me to"/"show me"/"navigate to" X → call ui_navigate with page=X (NOT daily_log_open — that tool is ONLY for the Daily Log / dictation). "Take me to tasks" → ui_navigate page="tasks". "Chief of staff agents" → ui_navigate page="agents". "Open calendar" → ui_navigate page="calendar". Only pick daily_log_open when the user explicitly says "daily log", "log entry", or "journal". ' +
'"Select X tab"/"switch to the X tab"/"click X"/"press the X button"/"pick Y from the Z dropdown"/"fill X with Y"/"check/uncheck X" — the LLM receives a compact "Current UI state" summary at the start of UI-driving turns listing Tabs, Buttons, Links, Inputs, Selects, Checkboxes. Use ui_click for tabs/buttons/links, ui_fill for text inputs, ui_select for dropdowns, ui_check for checkboxes. Pass the EXACT label shown in the UI summary. Prefer the `kind` argument when you have it (tab vs button). If the label isn\'t in the current UI summary, call ui_list_interactables OR ui_navigate first — do NOT guess. Active tab is marked with * in the summary; don\'t click it again. ' +
+ 'FORM FILL vs CAPTURE — CRITICAL: When the user directs content INTO a visible field ("fill description with X", "type X in the name field", "put X in the body", "enter X into title", "set the subject to X"), the target is the FIELD and X is the new value. ALWAYS call ui_fill with label=<field> and value=<X>. NEVER call brain_capture or daily_log_append for these turns — even when X contains words like "remember", "note", "save", or "jot", those are field content, not a request to capture to the inbox. Only use brain_capture when the user captures without referring to a page field ("remember to buy milk", "add this to my brain inbox", "save that for later"). ' +
'CHAINED UI FLOWS: after a ui_navigate / ui_click / ui_fill / ui_select / ui_check succeeds, its tool result includes a `ui` field with the FRESH page state (a new page has loaded, a modal may have opened, a tab may have switched, new fields may be visible). Always re-read this `ui` field before choosing the next action — don\'t rely on the original per-turn UI summary after an action has fired. For multi-step flows like "create a task called Foo with description Bar": ui_click New Task → read result.ui → ui_fill Name=Foo → read result.ui → ui_fill Description=Bar → ui_click Save. Do it all in ONE turn, not one action per turn. Same for cross-page flows like "go to tasks and add a task called Foo": ui_navigate page="tasks" → read result.ui → ui_click New Task → read result.ui → ui_fill Name=Foo → ui_click Save, all in ONE turn. ' +
'INTENT TO CREATE / WRITE in the daily log — phrases like "let\'s make a daily log", "let\'s make a new daily log", "start a daily log", "I want to make a log entry", "let me log something today", "new daily log", "let me add to my log" → call daily_log_open with startDictation=true. After this single tool call, STOP TALKING and let the user dictate freely — the dictation system handles every following utterance automatically without you. Do NOT say "I\'ll append it" or "what would you like to add" — the user already knows. Just confirm in one short sentence ("Daily log open, dictating now.") and stay quiet. ' +
'When the user is asking you to write something specific into the daily log right now — phrases like "add to my daily log: X", "note in today\'s log that X", "write in my log: X", "log this in my daily log: X", "for my daily log: X" — you MUST call daily_log_append with the exact X text (everything AFTER the leading "add … to my log" / "note that" / "for my log" phrasing). NEVER reply with just a paraphrased "add to my daily log: …" line — that\'s narration; CALL daily_log_append. ' +
diff --git a/server/services/voice/tools.js b/server/services/voice/tools.js
index f7120c806e..ba128feeff 100644
--- a/server/services/voice/tools.js
+++ b/server/services/voice/tools.js
@@ -165,6 +165,7 @@ export const UI_KINDS = ['tab', 'button', 'link', 'input', 'textarea', 'select',
// matches the user's utterance, plus the always-on set. "open the tasks
// page" sees ~8 tools instead of 25; "I had a beer" sees ~8 instead of 25.
const TOOL_GROUPS = {
+ brain_capture: 'brain',
brain_search: 'brain',
brain_list_recent: 'brain',
meatspace_log_drink: 'meatspace',
@@ -186,15 +187,29 @@ const TOOL_GROUPS = {
ui_fill: 'ui',
ui_select: 'ui',
ui_check: 'ui',
- // UNGROUPED = always-on: time_now, brain_capture, daily_log_append,
- // ui_navigate. These cover the highest-frequency intents.
+ // UNGROUPED = always-on: time_now, daily_log_append, ui_navigate.
+ // brain_capture used to be always-on, but that caused form-fill turns
+ // ("fill description with X") to be misrouted to brain_capture because
+ // "note/save/remember" in the tool description overlaps with field
+ // content. Gating on the brain regex keeps capture available for every
+ // natural phrasing without tempting the LLM on UI-driving turns.
};
// Loose on purpose — false positives are cheap (one extra tool), false
// negatives are expensive (LLM guesses wrong or can't act).
export const UI_INTENT_RE = /\b(click|press|tap|hit|open|go to|take me|show me|navigate|select|pick|switch|choose|tab|button|dropdown|field|input|fill|enter|type|write|check|uncheck|toggle|link|option|on (?:this|the) page|what(?:'s)? (?:on|here))\b/i;
+// Strong form-fill signal: when the user is clearly directing content INTO
+// a specific field, brain_capture/daily_log_append must be suppressed even
+// if capture verbs appear inside the value (e.g. "fill description with
+// 'remember to buy milk'"). Matches a UI-fill verb within ~60 chars of a
+// form-field word in either order — "fill the description with X", "type X
+// in the body", "set the title to X", "put Y in description".
+export const UI_FILL_INTENT_RE = /\b(?:fill|type|enter|put|write|set)\b[^.!?\n]{0,60}?\b(?:description|name|title|subject|body|content|field|input|textarea|form|label|placeholder|caption)\b/i;
const GROUP_INTENT = {
- brain: /\b(search|find|look ?up|recall|what did I (?:say|write|note)|brain|inbox|capture)\b/i,
+ // Expanded to cover natural capture verbs — "remember", "note", "save",
+ // "jot", "file" — without which moving brain_capture out of the always-on
+ // set would break "remember to buy milk" style turns.
+ brain: /\b(search|find|look ?up|recall|what did I (?:say|write|note)|brain|inbox|capture|remember|remind me|jot|note (?:that|to|down)|save (?:this|that)|file (?:this|that|it)|add (?:this|that|it) to (?:my )?(?:brain|inbox|notes?))\b/i,
meatspace: /\b(drink|drank|beer|wine|whiskey|shot|cocktail|cigarette|vape|pouch|nicotine|weigh|pound|kilo|kg|smoke|smoking|how am I|summary today|log (?:a|my) (?:drink|weight|nicotine))\b/i,
goals: /\b(goals?|progress|objective)\b/i,
system: /\b(restart|crash(?:ed)?|pm2|process|service|is.*(?:running|down|up)|status)\b/i,
@@ -1062,9 +1077,16 @@ export const classifyIntent = (userText) => {
export const getToolSpecsForIntent = (userText) => {
if (!userText) return { specs: getToolSpecs(), activeGroups: new Set() };
- const activeGroups = classifyIntent(userText);
+ // Form-fill turns ("put Y in the body") may use verbs not in UI_INTENT_RE,
+ // so compose a fresh group set: classifier result ∪ {ui, if form-fill}.
+ // Mutating classifyIntent's returned set would conflate "classified" with
+ // "overridden", which matters when the caller inspects activeGroups.
+ const classified = classifyIntent(userText);
+ const suppressCapture = UI_FILL_INTENT_RE.test(userText);
+ const activeGroups = suppressCapture ? new Set([...classified, 'ui']) : classified;
const specs = TOOLS
.filter((t) => {
+ if (suppressCapture && (t.name === 'brain_capture' || t.name === 'daily_log_append')) return false;
const group = TOOL_GROUPS[t.name];
return !group || activeGroups.has(group);
})
diff --git a/server/services/voice/tools.test.js b/server/services/voice/tools.test.js
index 739d168d46..9c52e906be 100644
--- a/server/services/voice/tools.test.js
+++ b/server/services/voice/tools.test.js
@@ -31,7 +31,7 @@ vi.mock('../feeds.js', () => ({
getFeeds: vi.fn(async () => []),
}));
-const { dispatchTool, getToolSpecs } = await import('./tools.js');
+const { dispatchTool, getToolSpecs, getToolSpecsForIntent, classifyIntent } = await import('./tools.js');
describe('getToolSpecs', () => {
it('returns OpenAI-format function specs', () => {
@@ -137,3 +137,65 @@ describe('pm2_restart type guard', () => {
await expect(dispatchTool('pm2_restart', { name: ' ' })).rejects.toThrow(/name is required/);
});
});
+
+// Bug: "Instead of entering what I asked into the description form field,
+// it created a brain entry." Form-fill utterances were seeing brain_capture
+// in the tool list because brain_capture used to be always-on; the LLM
+// picked it over ui_fill because the tool description emphasizes
+// note/save/remember/jot, words that overlap with field content.
+describe('getToolSpecsForIntent — form fill suppresses capture', () => {
+ const names = (specs) => specs.map((s) => s.function.name);
+
+ it('drops brain_capture for "fill description with X"', () => {
+ const { specs } = getToolSpecsForIntent('fill the description with remember to buy milk');
+ expect(names(specs)).toContain('ui_fill');
+ expect(names(specs)).not.toContain('brain_capture');
+ expect(names(specs)).not.toContain('daily_log_append');
+ });
+
+ it('drops brain_capture for "type X into the name field"', () => {
+ const { specs } = getToolSpecsForIntent('type my new idea into the name field');
+ expect(names(specs)).toContain('ui_fill');
+ expect(names(specs)).not.toContain('brain_capture');
+ });
+
+ it('drops brain_capture for "put X in the body"', () => {
+ const { specs } = getToolSpecsForIntent('put save this for later in the body');
+ expect(names(specs)).toContain('ui_fill');
+ expect(names(specs)).not.toContain('brain_capture');
+ });
+
+ it('drops brain_capture for "enter X into title"', () => {
+ const { specs } = getToolSpecsForIntent('enter a note about yesterday into the title');
+ expect(names(specs)).toContain('ui_fill');
+ expect(names(specs)).not.toContain('brain_capture');
+ });
+
+ it('keeps brain_capture for "remember to buy milk"', () => {
+ const { specs } = getToolSpecsForIntent('remember to buy milk on the way home');
+ expect(names(specs)).toContain('brain_capture');
+ });
+
+ it('keeps brain_capture for "add this to my brain inbox"', () => {
+ const { specs } = getToolSpecsForIntent('add this to my brain inbox: finish the review');
+ expect(names(specs)).toContain('brain_capture');
+ });
+
+ it('drops brain_capture for UI-only turns (no capture verbs)', () => {
+ const { specs } = getToolSpecsForIntent('click the new task button');
+ expect(names(specs)).not.toContain('brain_capture');
+ expect(names(specs)).toContain('ui_click');
+ });
+});
+
+describe('classifyIntent — brain regex expansions', () => {
+ it('matches "remember"', () => {
+ expect(classifyIntent('remember to call mom').has('brain')).toBe(true);
+ });
+ it('matches "jot down"', () => {
+ expect(classifyIntent('jot down an idea for dinner').has('brain')).toBe(true);
+ });
+ it('does not match plain UI turns', () => {
+ expect(classifyIntent('click the save button').has('brain')).toBe(false);
+ });
+});