refactor: hoist regexes into LazyLock statics (+ fix handle_reply init bug)#604
Merged
Conversation
Compiles each regex exactly once instead of on every `MentionParameters::default()` / handler invocation, and isolates the remaining `expect`s to single constant-initializer sites (they can only fire on a developer typo, never at runtime), which sets up the no-panic lint in a later iteration. - boot.rs: the five MentionParameters regexes now clone from `LazyLock<Regex>` statics. - chat_gpt_handler.rs: `BOT_PROFILES` and `CHAT_SUMMARY_REQUEST_REGEX` move from `OnceLock` (+ `get_or_init`) to `LazyLock`. Also fixes a latent bug: `handle_reply` read `BOT_PROFILES.get()` and silently did nothing if a reply arrived before the first `handle_chat_gpt_question` had initialized the profiles. With `LazyLock` the profiles are always populated, so the guard is gone. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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.
Iteration 3/8 of the hardening plan (§1/§4 — regex init cleanup).
MentionParametersregexes and the twochat_gpt_handlerstatics (BOT_PROFILES,CHAT_SUMMARY_REQUEST_REGEX) now useLazyLockinstead of eagerRegex::new(...)perdefault()/OnceLock+get_or_init. Each pattern compiles exactly once.expects are now isolated to single constant-initializer sites — they can only fire on a developer typo, never at runtime — which sets up the strict no-panic lint (Iteration 8).Bug fix (free):
handle_replypreviously readBOT_PROFILES.get()and silently no-op'd if a reply arrived before the firsthandle_chat_gpt_questionhad lazily initialized the profiles. WithLazyLockthe profiles are always populated, so theif let Some(...)guard is removed and replies work regardless of ordering.Pure refactor — no happy-path behavior change. Local gate green (fmt, clippy
-D warnings, 8 unit tests). e2e (real handler tree) is the CI backstop.🤖 Generated with Claude Code