FluidVoice icon indicating copy to clipboard operation
FluidVoice copied to clipboard

Fix: send AI enhancement instructions in system role, not user message

Open Kayaba-Attribution opened this issue 5 months ago • 2 comments

Description

Fixes a bug where AI enhancement instructions were placed in the user message instead of the system prompt, causing strict role-separation models to answer the transcript rather than apply the instructions.

Root cause — two independent sites

1. ContentView.processTextWithAI (user-facing dictation path)

The dictation branch hardcoded systemPrompt = "" and folded instructions + transcript into the user turn via renderDictationUserMessage. A comment in the code marked this as intentional ("dictation enhancement folds the prompt + transcript into a single user turn"), but it breaks any model that treats role separation strictly (e.g. Cerebras gpt-oss-120b, local models with system-prompt enforcement).

2. DictationPostProcessingService.process (local API path — /v1/postprocess)

Same pattern, same root cause. This path is called from InferenceAPIController, not from the main UI dictation flow.

Fix

Both sites now consistently put the instruction text in the system role and the transcript alone in the user role:

// Before (dictation branch in ContentView)
systemPrompt = ""
userMessageContent = SettingsStore.renderDictationUserMessage(
    promptText: promptText,
    transcript: inputText
)

// After
let systemPrompt = promptText
let userMessageContent = inputText

The isDictationCall conditional in ContentView is removed — both branches now do the same thing. DictationPostProcessingService gets the same treatment.

The no-prompt case (prompt turned off) is unaffected: effectiveDictationSystemPrompt returns "" when prompts are off, so the existing if !systemPrompt.isEmpty guard in the messages builder correctly omits the system entry.

Type of Change

  • [x] 🐞 Bug fix (non-breaking change which fixes an issue)

Related Issues

  • Closes #388

Testing

  • [x] Tested on Apple Silicon Mac
  • [x] Tested on macOS Sequoia 15
  • [x] 4 unit tests added in DictationSystemPromptTests:
    • effectiveDictationSystemPrompt returns configured instruction text (not empty)
    • effectiveDictationSystemPrompt falls back to a non-empty built-in default
    • renderDictationUserMessage("") returns transcript only (no instructions bleeding in)
    • ${transcript} placeholder substitution still works
  • [ ] Tested on Intel Mac
  • [x] Ran linter locally: swiftlint --strict --config .swiftlint.yml Sources — 0 violations
  • [x] Ran formatter locally: swiftformat --config .swiftformat Sources/Fluid/Services/DictationPostProcessingService.swift Sources/Fluid/ContentView.swift — 0 additional changes

Notes

Full end-to-end verification requires a live provider that exhibits the role-conflation failure (e.g. Cerebras gpt-oss-120b or a local model strict about system vs. user separation). The unit tests cover the message-composition logic without a network call.

Kayaba-Attribution avatar Jun 27 '26 15:06 Kayaba-Attribution

This is a tricky fix as it causes conflicts betweeen another PR about the state of system vs user prompt. Would to have a discussion before we merge this.

altic-dev avatar Jun 28 '26 01:06 altic-dev

Okay, could you provide more task reqiuremens/concerns details? @altic-dev

Kayaba-Attribution avatar Jun 29 '26 11:06 Kayaba-Attribution