Conversation
Introduce a `max_latency` setting to `TypewriterConfig` and a matching controller in `Printer` that automatically reduces the per-character typewriter delay when the queue of pending characters grows large enough to risk falling behind the source by more than the configured budget. With a fast provider such as Cerebras, the static `text_delay` / `code_delay` can cause the typewriter to trail the source by many seconds. Setting `style.typewriter.max_latency` to, e.g., `200ms` keeps the printed output within that window: the effective delay shrinks to `min(cap, max_latency / pending_chars)` as the queue grows, and expands back toward the cap as it drains — subject to the drain-mode floor described below. When the provider stops emitting (`Event::Finished`), the coordinator calls `signal_typewriter_drain()`, which snapshots the pending- character count. The controller then uses `max(snapshot, pending)` as the divisor, so the per-character delay never creeps back up as the tail of the queue empties. Any subsequent typewriter enqueue clears the snapshot and returns the controller to live mode. Setting `max_latency = 0` (the default) disables the controller entirely, preserving the existing static-delay behavior. Signed-off-by: Jean Mertz <git@jeanmertz.com>
Signed-off-by: Jean Mertz <git@jeanmertz.com>
Signed-off-by: Jean Mertz <git@jeanmertz.com>
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.
Introduce a
max_latencysetting toTypewriterConfigand a matching controller inPrinterthat automatically reduces the per-character typewriter delay when the queue of pending characters grows large enough to risk falling behind the source by more than the configured budget.With a fast provider such as Cerebras, the static
text_delay/code_delaycan cause the typewriter to trail the source by many seconds. Settingstyle.typewriter.max_latencyto, e.g.,200mskeeps the printed output within that window: the effective delay shrinks tomin(cap, max_latency / pending_chars)as the queue grows, and expands back toward the cap as it drains — subject to the drain-mode floor described below.When the provider stops emitting (
Event::Finished), the coordinator callssignal_typewriter_drain(), which snapshots the pending- character count. The controller then usesmax(snapshot, pending)as the divisor, so the per-character delay never creeps back up as the tail of the queue empties. Any subsequent typewriter enqueue clears the snapshot and returns the controller to live mode.Setting
max_latency = 0(the default) disables the controller entirely, preserving the existing static-delay behavior.