Repository navigation
fix(dialog): raise permission-guard quiet period to survive natural typing pauses - #3393
Merged
taciturnaxolotl merged 3 commits intoAug 2, 2026
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.
Member
|
halo! just tested with some typing data from myself. I think somewhere around 400-450 ms would be the sweet spot. We aren't really looking to account for pauses / rereading in this just preventing the period of time where the hands are still typing something but the brain hasn't reacted to the popup yet. |
Member
|
i think the test and comment could be removed as well |
Per taciturnaxolotl's review: 400-450ms is the sweet spot -- we're only covering the window where hands are still mid-keystroke but the brain hasn't reacted to the dialog yet, not accounting for a genuine pause to think or reread. Split the difference at 425ms. Also removed TestOverlay_NaturalTypingPauseArmsMidSentence and its comment as requested -- the existing grace-period tests already cover the mechanism this test was duplicating. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Contributor
Author
|
Thanks for testing this against real typing data! Pushed both changes:
Ready for another look whenever you have a chance. |
Member
|
can you revert the comment change too? |
taciturnaxolotl asked to drop the comment change too, not just the test.
Contributor
Author
|
Reverted the comment back to the original one-liner, keeping
|
taciturnaxolotl
enabled auto-merge (squash)
August 2, 2026 21:35
taciturnaxolotl
disabled auto-merge
August 2, 2026 21:36
taciturnaxolotl
enabled auto-merge (squash)
August 2, 2026 21:36
Alsan
pushed a commit
to Alsan/crush
that referenced
this pull request
Aug 5, 2026
XBoy-352
pushed a commit
to XBoy-352/crush
that referenced
this pull request
Aug 8, 2026
hirochimi
pushed a commit
to hirochimi/crush-study
that referenced
this pull request
Sep 5, 2026
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