cotabby icon indicating copy to clipboard operation
cotabby copied to clipboard

[Bug] Mid-word completion inserts an extra space (master tracking issue)

Open FuJacob opened this issue 5 months ago • 2 comments

Summary

Multiple bug reports describe the same defect: when a user starts typing a word and accepts the inline suggestion with Tab, Cotabby inserts the completion with an extra space in the middle of the word (e.g. typing after and accepting afternoon yields after noon). The ghost text renders correctly, but the inserted text does not match what was shown.

What occurred

The model's first token is the boundary signal: it emits a leading space when it intends a new word, and emits none when it intends to continue the current word. Real generations in llm-io.jsonl confirm the model gets this right consistently (e.g. prompt ending ...its hrd to kn produces raw w wht to say..., correctly continuing kn → knw). The overlay also renders this correctly, so the ghost text reads afternoon.

The defect is at accept time. SuggestionSessionReconciler.insertionChunk Rule 2 (Cotabby/Support/SuggestionSessionReconciler.swift:451) unconditionally inserts a space whenever the live preceding character is a word character and the accepted chunk's first character is a word character:

guard let firstChunkChar = chunk.first, firstChunkChar.isAcceptanceWordCharacter,
      let lastPrecedingChar = precedingText.last, lastPrecedingChar.isAcceptanceWordCharacter
else { return chunk }
return " " + chunk

Its own doc comment admits the gap: "we don't try to distinguish a fresh new word from a partial-word completion." This single accept-time heuristic overrules the model's correct boundary decision and breaks the WYSIWYG invariant (ghost shows afternoon, Tab inserts after noon).

Cause

Cotabby was originally designed to only trigger after the user typed a space, so every completion was treated as a fresh word and accept-time space injection was safe. Users have come to rely on mid-word completions, but the accept-time space-injection rule was never updated. The model's leading-space signal is correct and is preserved through normalization; it is only at the final insertion step that the boundary information is discarded.

Fix

PR #622 makes insertion render-faithful: the model's leading-space signal is treated as part of the first chunk and accept-time space injection is removed, so Tab inserts exactly the ghost text. New-word boundaries (e.g. I went to the | store) remain correct because the model emits the leading space itself, which is now preserved end-to-end.

Fixed by #622.

Related issues

Bug reports:

  • #621 [Bug] Auto-Complete Bug
  • #620 [Bug] Extra space added
  • #617 [Bug] auto complete sometimes has a space in the middle of a word
  • #615 [Bug] Mid-Word Completions
  • #614 [Bug] partial word auto complete
  • #559 [Bug] incorect input (Russian mid-word completion)
  • #557 [Bug] Extra space
  • #553 [Bug] Space in words
  • #548 [Bug] Inputs a space when autofilling
  • #547 [Bug] Weird gaps of the text suggestions
  • #525 [Bug] completing a partial word adds a space
  • #491 [Bug] Every mid-word completion always adds space between the letters already typed and the rest of the word
  • #479 [Bug] Word suggestions insert spaces in the middle of words
  • #395 [Bug] Space before a paste when Tabbing

Feature requests describing the same underlying defect:

  • #549 [Feature Request] Space after premature tab
  • #543 [Feature Request] Mid word completions
  • #507 [Feature Request] Better word completion / detection if word ended

Note

Some of the issues linked above (#559, #557, #553, #491, #395) were accidentally closed by me in a triage sweep with a comment claiming they were addressed in 0.5.0-beta. They are not yet fixed in any released build. Those issues have been reopened and the misleading comments removed.

FuJacob avatar Jun 06 '26 02:06 FuJacob

Hi guys!

@BNoiZe, @Cr0wTom, @creativetags, @EzraCerpac, @fxPPC, @idiked, @join3r, @justinjakull, @lukas-runge, @Marcelony, @neominik, @salmanuc, @tiekuhn

Just released a proper fix for this extra-space bug in 0.5.1-beta! Please go update in Cotabby or redownloading.

We were injecting a space at accept time whenever a completion landed against a word character, which overrode the model's own boundary signal. The fix removes that injection so the model's leading-space token can dedicate.

For transparency, I had accidentally closed and commented on a couple of the connected issues here, so I apologize for any confusion (was working on Cotabby at 4am 😭)

If you guys still find issue with this, please let me know, I will fix urgently since I know this has impacted Cotabby for a while.

Thanks for all the support :)

FuJacob avatar Jun 06 '26 03:06 FuJacob

This indeed seems to be fixed now. 🥳 Thank you @FuJacob! 🙏

lukas-runge avatar Jun 06 '26 08:06 lukas-runge