Skip to content

fix(tui): live dictation can panic when the caret is not at the end #965

Description

@PierrunoYT

Version / branch / commit

Audited on main at 903e3d13 (2026-08-23).

Problem

Live dictation anchors its region on the full composer text but later compares and slices only the prefix before regionStart. When the caret is inside existing text, the external-delete adjustment can make regionStart negative. The next partial transcript slices []rune(text)[:regionStart] and panics.

Reproduction

  1. Put hello world in the composer.
  2. Move the caret to column 5, after hello.
  3. Start live dictation and receive successive partial updates.

The first update can compute anchor = "hello world", prefix = "hello", and delta = 6, moving regionStart from 5 to -1. A subsequent partial slices with the negative index.

Expected behavior

Dictation updates remain bounded to a valid composer range regardless of caret position or concurrent typing/deletion.

Actual behavior

A negative slice index panics the TUI process and can lose the in-flight run.

Relevant code

  • internal/tui/dictation_stream.go:103,115,120-132

This is related to #936's voice-mode/typing collision but distinct: #936 concerns swallowed spaces and stray transcription, while this issue is a negative-index process crash.

Suggested fix

Clamp and validate regionStart and regionEnd before every read and slice, then add a regression test with the caret in the middle of existing text and at least two partial updates.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue-approvedReviewed and approved by the core team; community PRs may implement this issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions