Skip to content

fix(faq-bot): reject catastrophic regex patterns + LRU fallback cooldown (v0.1.2) - #1

Merged
rmyndharis merged 1 commit into
mainfrom
faq-bot-regex-safety-cooldown-lru
Jun 23, 2026
Merged

fix(faq-bot): reject catastrophic regex patterns + LRU fallback cooldown (v0.1.2)#1
rmyndharis merged 1 commit into
mainfrom
faq-bot-regex-safety-cooldown-lru

Conversation

@rmyndharis

Copy link
Copy Markdown
Owner

Summary

Two robustness improvements to faq-bot, released as v0.1.2.

Regex rule safety

Operator-authored regex rules are now screened for catastrophic-backtracking risk at parse time. A pattern that nests an unbounded quantifier inside another quantified group (e.g. (a+)+, (\w+\s?)*) can blow up exponentially on a short crafted input and stall message handling. Such patterns are now skipped with a warning, exactly like a syntactically invalid pattern — one bad rule never takes down the rest.

Accepted patterns are compiled with the native engine unchanged, so ordinary regexes, lookahead, and backreferences keep working. The screen is conservative and fails closed.

Fallback cooldown eviction

The per-chat fallback cooldown map evicted by first-seen order, so a continuously-active chat could be evicted ahead of idle ones and have its cooldown reset under high chat volume. The map now evicts least-recently-used (re-inserting a chat on each touch), so an active chat's cooldown survives the cap.

Tests

  • New: catastrophic patterns are skipped; safe patterns (incl. lookahead, {2,5}, a*b*c*, (abc)+) are kept and still match.
  • New: re-touching a cooldown key protects it from eviction; the genuinely-oldest entry is dropped.
  • Full suite green (97 tests), tsc --noEmit clean, bundle packages cleanly (no new dependency).

…own (v0.1.2)

- Validate regex rules at parse time for nested-quantifier backtracking risk
  (e.g. (a+)+, (\w+\s?)*); such patterns are skipped with a warning like any
  other unusable pattern. Accepted patterns run on the native engine unchanged,
  so lookahead and backreferences still work.
- Fallback cooldown map now evicts least-recently-used entries (re-insert on
  touch) so an active chat's cooldown is preserved when the map hits its cap.
@rmyndharis
rmyndharis merged commit eb1ba1e into main Jun 23, 2026
1 check passed
@rmyndharis
rmyndharis deleted the faq-bot-regex-safety-cooldown-lru branch June 23, 2026 09:35
rmyndharis added a commit that referenced this pull request Jun 23, 2026
…ooting (#7)

Expand the terse 4-line Setup into numbered steps, emphasizing "Enable the Google
Sheets API" (off by default — the #1 cause of a 403 SERVICE_DISABLED), with the exact
console path, the log symptom, propagation note, and the auto-retry behavior. Add the
"share the sheet with client_email" step prominently (the other common 403) and a
troubleshooting table. Also refresh stale v0.2.1 references to v0.2.2.
rmyndharis added a commit that referenced this pull request Jun 23, 2026
…eshooting (#8)

Rewrite the Setup flow to a professional standard: a prerequisites line, an
"at a glance" overview, six numbered steps with GitHub callouts, and the key
insight that setup grants TWO independent authorizations (enable the Sheets API
AND share the sheet) that each fail with a different 403 — the #1 source of
confusion. Add a "Verify it works" section (health buffer count + log grep) and
a Troubleshooting table covering both 403s, a partial JSON, a wrong sheet/tab,
and the rotated-key case.
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.

1 participant