fix(dialog): raise permission-guard quiet period to survive natural typing pauses - #3393
Open
albatrossflyon-coder wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3383.
The bug
#3055added a grace period so an in-flight keystroke can't act on a permission dialog before the user sees it:Overlay.Updateabsorbs keystrokes untilgraceQuietPeriod(200ms) of silence, up to agraceMaxDelay(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'shandleKeyPressMsgroutes all keys tom.handleDialogMsg→Overlay.Updatewhenever a dialog is open, which is the correct path (no separate leak point).Overlay.inGracePeriod()(internal/ui/dialog/dialog.go) arms as soon asgraceQuietPeriodelapses since the last absorbed key — 200ms, shorter than a typical inter-word pause.Fix
Raised
graceQuietPeriodfrom 200ms to 700ms — comfortably past an ordinary composing pause, while still arming quickly once the user genuinely stops typing. LeftgraceMaxDelay(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 currentmain(the resumed keystroke reaches the dialog), green after the fix.go test ./internal/ui/dialog/...— 32 passedgo test ./internal/ui/...— 722 passedgo build ./...— clean