Repository navigation
Request-path regexes read long input in linear time - #317
Merged
Merged
Conversation
zlareb1
force-pushed
the
sec/request-path-regexes
branch
from
November 7, 2026 07:11
fc2097e to
5aad88c
Compare
Merged
9 tasks done
zlareb1
force-pushed
the
sec/request-path-regexes
branch
from
November 7, 2026 11:30
31d114c to
09eac38
Compare
Each pattern that rescanned a run of text from every character now starts a match only where one can begin: at the first letter of a word, the start of a path's first directory, or the start of a token. Matches on ordinary input are unchanged. The rewrites that add a lookbehind return the name in group 1, and their callers read that group. - GET /assets: a file name over 255 characters is not a hashed asset. - memory.set file detection, code.verify_citations, code.search trims, code.trace, tracker.similar and tracker.duplicate_check frames, memory.ask amounts and identifiers, activity narration, conflict and value-update tokens, SCIM group filters, replay result lines, identifier tokens and registration class names. - A forget sentence over 400 characters is skipped by forget_sentences too, as forget_requests_from_messages already skips it. - tracker.similar and tracker.duplicate_check refuse a frame or symbol line over 4000 characters. Intended differences: a file or path match that began right after `@` or `+` inside a longer token is no longer read, a URL scheme is read up to 32 characters, a tracker path glued to the previous frame's line number is not read, and a memory.ask file name or a narration's path-like token over 255 characters is read in part. tests/unit/test_request_regexes_linear.py checks every fixed pattern grows under 8x from n to 4n, and checks each new bound. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…inear time - memory.ask's PascalCase handle and type patterns read the humps after the first as one run: a word could split into humps in many ways, and trying each was exponential in its length. - The failed-attempt check reads each clause once, from its first attempt word. - The file:line and pytest path::name patterns start at a path's first word; the name is group 1. - The stated-class pattern reads a run of blanks once. - tracker.duplicate_check's description drops a closing clause, so the coding listing stays under its token ceiling with the frame bounds. Matches are unchanged on ordinary input. One intended difference: a file:line glued to the previous one's line number (`a.cpp:12/b.cpp:3`) is no longer read. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…st-path regexes read in linear time - code.verify_citations: a blob URL's rev is at most four segments, so each one tried no longer re-reads the whole path after it. - memory.set file detection reads the commit cue once per text, not once per hex run. - forget_sentences adds a message's other sentences once, however many forget requests it holds. - amount_candidates reads a sentence's entities once and finds each amount's neighbours by position. - The tracker defect split, sensitivity's email shape, enumeration lines, trailing punctuation, number words and part splits start a match only where one can begin. - The pytest-id and file:line loops read group 1 for the one pattern that has it, by name. - Path-like tokens are read over at most 63 characters right after a backtick, 255 from a token's start. - loom_search's tracker leg drops a frame longer than tracker.duplicate_check accepts instead of failing the leg. Matches are unchanged on ordinary input. Intended difference: forget_sentences returns a message's other sentences once when the message holds two or more forget requests. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The sensitivity detectors' patterns are changed in a separate pull request; this one no longer edits the email shape or guards it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…nd stack-trace hints read in linear time - The forget prefix no longer lists "no wait": it is read as "no" then "wait", and as its own word too a run of them parsed in 2^n ways. - code.verify_citations does not start a qualified name at a destructor part (`::~Foo`). - knowledge.search tries an exact-key dotted path once per run, from its first letter; the term is group 1 or group 2. - A transcript cue's tags are read up to its last `>`. - The memory.set stack-trace hint reads each line's own leading blanks, and a frame's name run once. - code.bisect's fix check drops a frame longer than tracker.duplicate_check accepts, as loom_search's tracker leg does. - The new length bounds say why they are not settings. - A seeded test checks four rewrites against the patterns they replaced, and a forget test covers a message with two requests. Matches are unchanged on ordinary input. Intended difference: a qualified name starting right after `::~` inside a longer token is no longer read. 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]>
…checks six more rewrites Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… shared frame filter Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…s the hex scan Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…and file names read from a token's start Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… the other sentences, and one helper strips leading ./ 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]>
…he batch once Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… 50 premises 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]>
…rds are read only when a request needs them Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…he requests a window holds Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…those; each forget entry's words are read once Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…_requests says what it counts Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ntent helper is removed Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ntion order is tested Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…atch tests go through forget_targets Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ge's facts 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]>
…ut read plainer Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… overlap builds each suffix once Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…x check's filter is tested at its call Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… comment names symbols Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ved on disk Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… keeps each file with its tail 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]>
… on its result field 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]>
…s the stored rows 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]>
…mment states the present Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
sec/request-path-regexes
branch
from
November 8, 2026 01:38
fbd102f to
ebd03c3
Compare
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):
The regexes that read request text on the event loop (dashboard asset names,
memory.setfile detection and its stack-trace hint,code.verify_citations,code.search,code.trace,tracker.similarandtracker.duplicate_checkframes,memory.ask,memory.set_from_messages,knowledge.search,loom_search, SCIM group filters and others) run in time linear in their input.tracker.similarandtracker.duplicate_checkrefuse a frame, symbol or path over 4,000 characters, andGET /assets/treats a file name over 255 characters as not a hashed asset and answers 404 for a path over 1,024 characters.Why
A scan timed every compiled regex the server loads on long repeats of each character class, and flagged about sixty whose time grows with the square (or worse) of the input. A triage traced each to its callers. Eighteen run on the API's event loop over text a caller sends, so one request blocks every other request on that server for its duration:
GET /assets/<name>needs no token: a 64 KB name took 3.5 s, about 870 s at 1 MB.code.verify_citations(viewer, text up to 200 KB): 85 s, and 38 s at 80 KB for a GitHub blob URL.memory.setfile detection (writer, value up to the 32 MiB body): 25 s at 64 KB; its stack-trace hint, 19.9 s at 32 KB of blank lines.memory.set_from_messagesforget sentences: 35 s for a 64 KB sentence, and exponential in a repeated "no wait" (1.8 s at 20 repeats);memory.askamounts: 17.6 s at 16 KB of digits, through rows a writer stored.tracker.similar/duplicate_check(viewer, 60 frames of any length): 101 s.knowledge.searchexact-key terms (no query length cap): 5.7 s at 32 KB.code.searchqualified names; activity narration (cubic on whitespace in one clause) and its failed-attempt clause;memory.askhandle and PascalCase identifiers in the question (exponential: about 4 s at 42 characters, minutes at 50); conflict parentheticals, value-update tokens,memory.askidentifiers, SCIM/Groupsfilters (SCIM token), replay result lines, registration class names: from 1 s to 18 s on inputs a caller controls.Two more scans, of the patterns under
server/memory/domainandserver/code/domain(845) and underserver/insightsandserver/knowledge, timed at 4 KB and 16 KB and projected to 200 KB, found the rest on request paths: search and ask evidence enumeration lines, question and query trailing punctuation,memory.asknumber words and question parts, the stack-trace hint's frame lines andAssertion … failedhead,knowledge.searchterms, and the transcript cue tag and voice patterns of the recording source sync (a worker, fixed while there).Design
Each pattern that rescanned a run from every character now starts a match only where one can begin: a lookbehind at the start of a word, a path's first directory, a token or a run of blanks, or a possessive or bounded repeat where the start cannot be fixed. Where a lookbehind would change which names are read, the rewrite skips a leading run and returns the name in a group, and each caller reads that group for that pattern, so matches on ordinary input are identical. The forget prefix lists "no wait" no more: it is read as "no" then "wait", and as its own word too a run of them parsed in 2^n ways.
Some costs were in the code around a pattern:
forget_targetsreads the content words of its candidate rows and batch facts once, on the first request that needs them, not once per request;replacement_factsand its said-corrections read what was asked to forget once; the write step resolves at most the latest 50 of a window's forget requests by content (each costs a candidate read and a pass over the candidates; it logs when a window holds more, and the result'sforget_requestscounts the ones resolved), and the extractor's own forget entries are resolved as before. A window states at most 50 premises (premise_facts; each is compared with every earlier one). A forget sentence over 400 characters is skipped byforget_sentences, asforget_requests_from_messagesalready skips it. A message's other sentences are added once, not once per request in it, and a request sentence no longer counts as another request's other sentence.memory.setfile detection reads its commit cue once per text, not once per hex run../and diffa//b/prefixes are stepped past and sliced once (memory.setfile references,code.verify_citations, the code plane's path helpers, through one helper inserver/core/relative_paths.py): a slice per prefix copied the rest of the path each time.code.verify_citationsretries a name that found nothing only as its suffixes of at most 8::parts: each retry is one lookup, and a cited name has no length bound of its own.code.bisectstrips a bot's marker blocks from an issue body against closers indexed once, and its HTML comments only up to the last-->, so an opener with no closer is not a scan to the end (32 KB of unclosed comments: 1.3 s before (16x per 4x); 64 KB after: 4 ms).code.verify_citationsfinds the fence that may hold a citation by bisection over the sorted fences, not by walking every fence for every citation.memory.askamounts read a sentence's entities once and find each amount's neighbours by position.Assertion … failedhead is read once per line by a string search instead of a pattern that rescanned the line from eachAssertion.>: no tag closes after it.tracker.similarandtracker.duplicate_checkframes, symbols and paths get a 4,000-character limit per item, since the work is linear in their total;loom_search's tracker leg andcode.bisect's fix check drop a longer frame instead of failing, through one filter beside the bound.Each rewrite was fuzzed against the original on 20,000 to 100,000 random strings and on real samples; eleven of them (
TRACE_SYMBOL_RE,_TRACE_LINE_RE,_MIXED_RE,_PATHLIKE_RE,exact_keys._TERM,defect_answer._SEGMENT_SPLIT_RE,ask_threshold._NUM_REand_PART_SPLIT_RE,prompts._AMOUNT_RE,forget_requests._REPLACEMENT_CUT_RE,activity_facts._FAILED_ATTEMPT_RE) keep that check as a seeded 2,000-string unit test against the original patterns, and the rest rest on their modules' tests and the fuzz runs. Results are identical except for these intended differences on unusual input:@,+or::~inside a longer token is no longer read;<v.loud\tx Alice>namesx Alice(the recording source sync, a worker);::parts is retried only as its suffixes of at most 8 parts;test_name whose[param]holds a[is read without the param;blob/main//src/a.py) is not read as a blob URL;x/a.cpp:12/b/c.cpp:3) is not read;forget_requests(the extractor's own forget entries still resolve), a window with more than 50 assistant premises keeps the first 50, and a forget sentence over 400 characters is skipped (and kept out of the message's other sentences when it opens like a request), and a message with two or more forget requests returns each request's replacement and its other sentences once;tracker.similarandtracker.duplicate_check, and dropped byloom_search's tracker leg andcode.bisect's fix check;A regression guard,
tests/unit/test_request_regexes_linear.py, times every fixed pattern with the call its code makes at n and 4n and requires under 8x growth (a quadratic one grows 16x), and checks each new bound. Each read is capped at 10 s, so an exponential regression fails its case instead of hanging the job. With the old patterns swapped in, every timing case fails (15 to 16x, 65x for the cubic one); the exponential ones do not finish.Left as they are, each with its bound:
memory.askquestion patterns that cross lines or rescan a digit run (ask_option_guardoption and date lines,question_literalsstate tails, thesplit_partsdate line,ask_threshold's threshold and option lines): the question is at most 2,000 characters, 10 to 70 ms.ask_recount,premise_line,corpus_synthesis,ask_thresholditem heads,ask_option_guardanswer lines,extraction_specifics,extraction_temporal,session_brief): bounded by the model's output tokens.merge_guardin consolidation;session_echoesanddurable_factsin extraction): off the request path.fullmatch, linear).server/code/domain/extract/and theextractor_stampmodules (a code change there re-runs ingest stages in every repository): their input is a repository's own files, capped at 1 MB, read in the ingest worker.sql_names._STATED_CLASS_REon a line of many<…>groups or unclosed<: code chunks are capped at 6,000 characters, about 8 ms a line; its whitespace case is fixed.Scope and risk
40 server files: the regex rewrites (45 patterns) and the bounds and loops described above, their callers, the new
core/relative_paths.pyhelper, theforget_requestsandpremise_factsresult fields' comments, and one tool description said in fewer words (the frame and path bounds add about a dozen tokens to the coding listing, whose ceilingtest_mcp_listing_budget.pyholds); plus the regenerateddocs/reference/operations/memory.mdandtracker.mdrows, a clause on the forget cap indocs/features/memory/extraction.md, the asset-path case intest_frontend_asset_fallback.py, thecode.bisectfix-check case intest_dupcheck_links.py, the guard test, three cases intest_forget_and_switch.py, andtest_memory_pipeline.py's content-match tests moved offforget_targets_by_content, which no server code calls any more and is removed. The seven new bounds carry# not a setting:with their reason. No stored data or schema changes. The blacklist and sensitivity regexes are in a separate pull request.Compatibility, rollout and rollback
tracker.similarandtracker.duplicate_checkanswer 422 for aframes,symbolsorpathsitem over 4,000 characters.GET /assets/<name>with a name over 255 characters is served as a non-hashed path (no long cache), and a path over 1,024 characters answers 404.memory.set_from_messagesresolves by content, and counts inforget_requests, at most a window's latest 50 forget requests.Tests
tests/unit/test_request_regexes_linear.pyhas 57 timing cases over 44 call sites, 16 bound cases (the premise cap, asset name, forget sentence and a long request beside it, forget sentences with blank runs,forget_targetsover many requests, qualifier retries,./runs on four callers,frameson two inputs,symbols,paths, the tracker leg, the shared frame filter) and 11 seeded equivalence cases;test_forget_and_switch.pyadds a message with two forget requests (its other sentences kept once), a correction older than the latest 50 forget requests (it keeps its replacement while the per-request reads stop at 50), and a repeated request resolved at its latest mention. On the head rebased ontomain, 162 unit files run serially (3,389 tests: every MCP listing, budget and schema test,test_tunable_constants.py,test_public_copy.pyand each touched module's) pass, as domake format-check,make lint,make typecheckand the reference and SDK generator checks. Per-pattern timings before and after, on one host:frontend_assets._HASHEDcitations._BLOB_URL_REcitations._BARE_LOC_REcitations._NAME_REfacetscommit cueforget_requests._FORGET_MSG_RE_FORGET_MSG_REtail and_REPLACEMENT_CUT_RE, 1 MB of 400-character requests with blank runs (forget_requests_from_messages+forget_sentences)forget_targets, 8,000 requestspremise_facts_from_messages, 400 assistant turns of premisesidentifiers._INJECT_HANDLE_REactivity_facts._FAILED_ATTEMPT_REactivity_facts._TOOL_SUBJECT_REactivity_facts._PATHLIKE_REmentor_rules._TRACE_LINE_RESexact_keys._TERMprompts._AMOUNT_REprompts.amount_candidatesdefect_answer._SEGMENT_SPLIT_REpassage_trim._ENUM_LINE_REquery_trim._QUALIFIED_REobserve_replay._RESULT_LINEsql_names._STATED_CLASS_REAI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. Each rewrite was timed and fuzzed against the original; I read the diff and the guard test.
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.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code