Repository navigation
code.search, tracker.ask and the decision extractor match identifier regexes in linear time - #342
Merged
Merged
Conversation
zlareb1
force-pushed
the
fix/identifier-regexes-linear
branch
from
November 7, 2026 10:26
22d4a70 to
0f54a3d
Compare
…in linear time Five patterns repeated a group whose body could also continue the previous repetition, such as (?:[A-Z][a-zA-Z0-9]+)+, so a run of capitals or digits ending in a word character backtracked through every split: 'Ab' + 'A' * 40 + '_' blocked memory.ask for seconds, code.search's embedded identifiers doubled per character, and tracker.ask's anchors took 21 s on 28 digits. Each is rewritten as the same language with one way to match, e.g. [A-Z][a-z]+[A-Z][a-zA-Z0-9]+; old and new give the same matches on 300,000 random strings each. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…tern in seconds, not hang Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…path regex change Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…s the shape it tests Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
fix/identifier-regexes-linear
branch
from
November 7, 2026 12:00
cc36b71 to
e105a37
Compare
This was referenced Nov 7, 2026
Merged
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.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
code.search(and the code grounding ofmemory.ask),tracker.askand the decision extractor read identifiers in linear time, so a query holding a long run of capitals or digits no longer blocks them for seconds or minutes.memory.ask's own identifier patterns are fixed in #317.Why
Five patterns (two in
EMBEDDED_IDENT_RE, one each in the tracker, the decision extractor and the fake model) repeated a group whose body could also continue the previous repetition. In(?:[A-Z][a-zA-Z0-9]*)+a capital can end one hump or start the next, so on a run of capitals followed by a word character (where the trailing\bfails) the engine tries every way to split the run: about 2ⁿ for n characters. The calls run synchronously on the request's event loop.mainEMBEDDED_IDENT_RE(server/code/domain/idents.py)code.searchquery (no length limit) andmemory.askcode grounding (question and excerpts)"Ab" + "A" * n + "_","ab" + "A" * n + "_"_CAMEL_RE(server/tracker/domain/catalogue.py)tracker.askanchor extraction"Ab" + "0" * n + "_"_BARE_CAMEL(server/memory/domain/decision_extract.py)The same shape is in the fake model's
_CAMEL_RE(server/llm/fake.py), fixed with them.Each pattern is rewritten as the same language with one way to match. A repeated hump that may contain capitals absorbs every later hump, so
X(?:[A-Z][a-zA-Z0-9]+)+isX[A-Z][a-zA-Z0-9]+. The tracker's[A-Z][a-z0-9]+(?:[A-Z0-9][a-z0-9]*)+is "a capital, a lowercase letter or digit, then any letters and digits holding at least one capital or digit", written[A-Z][a-z0-9][a-z]*[A-Z0-9][A-Za-z0-9]*.Scope and risk
memory.ask's_INJECT_HANDLE_REand_TECH_PASCAL_RE(server/memory/app/ask/identifiers.py) have the same shape; open PR #317 rewrites them, so this PR leaves them out.Matches are unchanged: for each pattern here, old and new give the same spans and groups on 300,000 random strings of 1 to 14 characters over capitals, lowercase, digits,
_,:,~,-, space and a non-ASCII letter (the script is below). Recall and ranking are therefore untouched, so no benchmark is needed.idents.pyandcatalogue.pyare not in the code-index extractor stamp, so no index stage re-runs.Equivalence check
Compatibility, rollout and rollback
Tests
tests/unit/test_identifier_regexes_linear.py(new): each caller on a capital, camel or digit run sized to take the old pattern 2 to 10 s (25 to 40 characters) must take under 1 s of CPU, so a regression fails in seconds rather than hanging the job. Onmainevery case fails; here they take microseconds. A second test pins what the shapes still match.make format-check,ruff,mypyon the touched modules: pass.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code; the timings, the language equivalence and the fuzz check were verified by hand.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed.main; no merged migration is edited.frontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code