Several patterns in src/nexus_memory/guardrails.py have the shape A.*B, and their cost grows with the cube of the command length when the command repeats the first part. The worst is \bgit\b.*clean.*-[fd] (line 97). Measured on this repository, in the run recorded below, with a command made of repeated "git clean ": 0.44 s for 8,000 characters and 3.45 s for 16,000.
The same shape appears in the pip, npm and brew install patterns, in dd ... of, in find ... -delete, and in the DELETE ... collection and drop ... collection patterns.
classify_action() runs before a terminal command is executed in every consumer: the Hermes memory plugin, the MCP server and the quick-check path. Nothing caps the length of a command that is classified, so a command shaped by a web page or by a tool result can hold the guardrail for minutes. The Claude Code hook script ships its own pattern list and does not call this module.
Fixed in 0.22.34. The eight patterns are written as (?m)^(?>.*?A).*?B, which scans each line once instead of retrying from every occurrence of A. On the same machine the 16,000 character command now takes 0.1 ms instead of 3.45 s, and a seeded generator over 480,000 commands finds no verdict difference against the old patterns. The rewrite is in commit f2f21f4 of this repository, and tests/test_guardrails_linear.py covers each of the eight patterns, including the case that used to be the worst: a repeated prefix that never reaches the terminator.
Simin Yuan (@simin-yuan) reported this issue and wrote the fix with its regression tests. He is credited as finder below; his name is on the commit and in the changelog.
Several patterns in
src/nexus_memory/guardrails.pyhave the shapeA.*B, and their cost grows with the cube of the command length when the command repeats the first part. The worst is\bgit\b.*clean.*-[fd](line 97). Measured on this repository, in the run recorded below, with a command made of repeated "git clean ": 0.44 s for 8,000 characters and 3.45 s for 16,000.The same shape appears in the pip, npm and brew install patterns, in
dd ... of, infind ... -delete, and in theDELETE ... collectionanddrop ... collectionpatterns.classify_action()runs before a terminal command is executed in every consumer: the Hermes memory plugin, the MCP server and the quick-check path. Nothing caps the length of a command that is classified, so a command shaped by a web page or by a tool result can hold the guardrail for minutes. The Claude Code hook script ships its own pattern list and does not call this module.Fixed in 0.22.34. The eight patterns are written as
(?m)^(?>.*?A).*?B, which scans each line once instead of retrying from every occurrence of A. On the same machine the 16,000 character command now takes 0.1 ms instead of 3.45 s, and a seeded generator over 480,000 commands finds no verdict difference against the old patterns. The rewrite is in commit f2f21f4 of this repository, andtests/test_guardrails_linear.pycovers each of the eight patterns, including the case that used to be the worst: a repeated prefix that never reaches the terminator.Simin Yuan (@simin-yuan) reported this issue and wrote the fix with its regression tests. He is credited as finder below; his name is on the commit and in the changelog.