Skip to content

fix(stdlib): clock pending Escape with escapeCodeTimeout - #9639

Closed
proggeramlug wants to merge 1 commit into
PerryTS:mainfrom
proggeramlug:fix/9593-escape-code-timeout
Closed

fix(stdlib): clock pending Escape with escapeCodeTimeout#9639
proggeramlug wants to merge 1 commit into
PerryTS:mainfrom
proggeramlug:fix/9593-escape-code-timeout

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • replace tick-based PENDING_ESCAPE flushing with a 500 ms deadline
  • expose the stdlib deadline to the native event pump, keeping bare Escape timing independent of idle and JS timers
  • cancel the deadline when completing bytes arrive so split and complete arrow sequences still coalesce
  • add focused unit coverage and a real-PTY regression test
  • no version bump

Verification

  • cargo fmt --all -- --check
  • cargo test -p perry-stdlib readline:: -- --nocapture (22 passed)
  • cargo test -p perry-runtime event_pump::tests -- --nocapture (6 passed)
  • cargo test -p perry --test issue_9593_readline_escape_timeout -- --nocapture (1 passed; all four PTY scenarios)
  • cargo clippy -p perry-runtime -p perry-stdlib --lib --no-deps (passed with pre-existing warnings)

Fixes #9593

Summary by CodeRabbit

  • Bug Fixes
    • Fixed raw-mode readline handling for the Escape key by applying a consistent 500 ms timeout.
    • Preserved split ANSI escape sequences, such as arrow keys, as a single keypress.
    • Ensured complete escape sequences are delivered immediately.
    • Made Escape timing consistent whether the event loop is idle or handling other timers.

Hold incomplete ANSI escape prefixes against an explicit 500 ms deadline registered with the event pump. Unrelated loop turns no longer flush early, idle waits no longer flush late, and completing bytes cancel the one-shot.\n\nCover bare Escape under idle and interval-driven schedules plus split and complete arrow sequences on a real PTY.
@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: fc8c2efb-14c6-4329-be82-ad02d272d948

📥 Commits

Reviewing files that changed from the base of the PR and between ed7019e and 9c5d0ac.

📒 Files selected for processing (9)
  • changelog.d/9593-readline-escape-timeout.md
  • crates/perry-runtime/src/event_pump.rs
  • crates/perry-runtime/src/lib.rs
  • crates/perry-stdlib/src/common/async_bridge.rs
  • crates/perry-stdlib/src/readline/mod.rs
  • crates/perry-stdlib/src/readline/mod_tests.rs
  • crates/perry-stdlib/src/readline/pump.rs
  • crates/perry-stdlib/src/readline/test_support.rs
  • crates/perry/tests/issue_9593_readline_escape_timeout.rs

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

Changes

Readline escape timeout

Layer / File(s) Summary
Runtime deadline registration
crates/perry-runtime/src/lib.rs, crates/perry-runtime/src/event_pump.rs, crates/perry-stdlib/src/common/async_bridge.rs
The runtime registers a stdlib wake-deadline callback and includes it with timer deadlines when calculating event-pump waits.
Readline timeout behavior
crates/perry-stdlib/src/readline/mod.rs, crates/perry-stdlib/src/readline/pump.rs, crates/perry-stdlib/src/readline/mod_tests.rs, crates/perry-stdlib/src/readline/test_support.rs
Readline holds incomplete escape prefixes for 500 ms, cancels the deadline when sequence bytes arrive, and flushes expired prefixes as bare Escape input.
PTY regression validation
crates/perry/tests/issue_9593_readline_escape_timeout.rs, changelog.d/9593-readline-escape-timeout.md
The PTY test checks timing under idle and interval schedules, split arrow sequences, and complete arrow sequences. The changelog records the behavior change.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: ⚪ Minimal · up to 9c5d0

The readline escape timeout implementation and its runtime wake integration are ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 8 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: replacing tick-based pending Escape handling with an escapeCodeTimeout deadline.
Description check ✅ Passed The description explains the change, lists the implementation scope, identifies issue #9593, and records relevant verification commands and results. It omits the template headings for Changes, Test pl…
Linked Issues check ✅ Passed The implementation satisfies issue #9593 by adding a 500 ms deadline, holding torn escape prefixes, cancelling the deadline on completion, flushing bare Escape on expiry, integrating the deadline into…
Out of Scope Changes check ✅ Passed The changes remain within the linked issue scope. Runtime registration, event-pump deadline integration, readline handling, and regression tests directly support the requested timeout behavior.
Full details: Description check

Explanation

The description explains the change, lists the implementation scope, identifies issue #9593, and records relevant verification commands and results. It omits the template headings for Changes, Test plan, and Checklist, but the required information is mostly present.

Full details: Linked Issues check

Explanation

The implementation satisfies issue #9593 by adding a 500 ms deadline, holding torn escape prefixes, cancelling the deadline on completion, flushing bare Escape on expiry, integrating the deadline into event-pump waits, and testing bare Escape plus split and complete arrow sequences.

Full details: Docstring Coverage

Explanation

Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 8 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug

Copy link
Copy Markdown
Contributor Author

Landed via merge train #9650 (rebase-merge, authorship preserved).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bare ESC waits out the loop budget (up to 1s): PENDING_ESCAPE needs a real escapeCodeTimeout timer, not tick-granularity flushing

1 participant