Skip to content

fix(dialog): raise permission-guard quiet period to survive natural typing pauses - #3393

Open
albatrossflyon-coder wants to merge 1 commit into
charmbracelet:mainfrom
albatrossflyon-coder:fix/permission-guard-typing-ceiling
Open

fix(dialog): raise permission-guard quiet period to survive natural typing pauses#3393
albatrossflyon-coder wants to merge 1 commit into
charmbracelet:mainfrom
albatrossflyon-coder:fix/permission-guard-typing-ceiling

Conversation

@albatrossflyon-coder

Copy link
Copy Markdown

Fixes #3383.

The bug

#3055 added a grace period so an in-flight keystroke can't act on a permission dialog before the user sees it: Overlay.Update absorbs keystrokes until graceQuietPeriod (200ms) of silence, up to a graceMaxDelay (1.5s) ceiling.

That correctly handles a single stray keystroke or a fast burst. It doesn't handle the case in #3383: a user composing their next message while a permission dialog is open from a prior tool call. Ordinary typing has natural pauses between words/thoughts that regularly exceed 200ms — nothing like a stuck key or auto-repeat — so the dialog arms mid-sentence, and the very next character the user types lands on the permission dialog instead of the editor.

Root cause, traced

  • internal/ui/model/ui.go's handleKeyPressMsg routes all keys to m.handleDialogMsgOverlay.Update whenever a dialog is open, which is the correct path (no separate leak point).
  • Overlay.inGracePeriod() (internal/ui/dialog/dialog.go) arms as soon as graceQuietPeriod elapses since the last absorbed key — 200ms, shorter than a typical inter-word pause.
  • The original PR's own description says the grace period should let "a sustained burst of fast typing [be] fully absorbed," but a paused sentence isn't a burst — it's exactly the case that falls through.

Fix

Raised graceQuietPeriod from 200ms to 700ms — comfortably past an ordinary composing pause, while still arming quickly once the user genuinely stops typing. Left graceMaxDelay (1.5s) untouched; it's a separate, already-tested safety net for a truly stuck key.

The exact number is a judgment call — happy to tune it if you have a preference or telemetry on real typing cadences.

Testing

Added TestOverlay_NaturalTypingPauseArmsMidSentence, which reproduces the bug deterministically (no live terminal needed, unlike #3373): types a few characters, backdates a 400ms pause (a normal thinking-pause, well under the old 200ms and comfortably under the new 700ms), then resumes typing. Confirmed red against current main (the resumed keystroke reaches the dialog), green after the fix.

  • go test ./internal/ui/dialog/... — 32 passed
  • go test ./internal/ui/... — 722 passed
  • go build ./... — clean

…yping pauses

Fixes charmbracelet#3383.

graceQuietPeriod (200ms) armed the permission dialog's keystroke guard
after any pause shorter than a normal mid-sentence thinking pause, so a
user composing their next message while a permission dialog was open
would have a keystroke land on the dialog instead of the editor as soon
as they paused between words. Raised to 700ms, comfortably clear of
ordinary typing pauses while still arming promptly once the user
actually stops typing.

Added a regression test (TestOverlay_NaturalTypingPauseArmsMidSentence)
that reproduces the exact race deterministically without needing a live
terminal: a 400ms pause mid-sentence used to leak the next keystroke to
the dialog; it no longer does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The "writing while permission modal appears" guard does not work

1 participant