You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parse Markdown sections without repeated suffix list copies #1890
Follow-up from the reviewed CodeRabbit deep scan (K2). This ticket tracks one distinct fix; duplicate scan rows are consolidated here.
Reviewed evidence and scope
K2 (scan ID f1130f1a-fdd1-47fe-9b41-0cdb1ab1fd96, review A, Medium): headings[position+1:] copies suffix lists even when lookahead immediately breaks. Linear-time comment is incorrect; use indices/stack.
Source at current baseline: src/basic_memory/markdown/sections.py:190.
Fix and validation
Parse Markdown sections without repeated suffix list copies.
Recheck current callers and supported behavior before choosing the smallest complete fix.
Add a bounded regression at the affected public or service boundary; demonstrate it fails without the fix.
Preserve legitimate inputs and tenant/project boundaries. Run focused tests plus repository static/type checks.
The scan/review establishes the code-level concern described above; it does not establish production exploitation. Conditional branches and local/tooling-only exposure must retain that scope.
Type: enhancement (performance/robustness hardening; the issue carries the security label, but the scan only establishes a code-level concern, not exploitation) Priority: Medium Component: Markdown parsing (markdown/sections.py), which also feeds the note-read API's section= slicing. No Cloud-specific behavior is involved. Complexity: Simple
Findings
Confirmed at src/basic_memory/markdown/sections.py:190. For each heading, headings[position + 1 :] copies the suffix list before the loop breaks. That makes the cost O(n²) in the heading count for a large note, even when the very next heading ends the section.
The comment at lines 187-188 claims the look-ahead is linear because of the level cap of 6. That claim is wrong, because the slice copy is not bounded by the cap.
A small fix looks sufficient. Iterate with itertools.islice or an index, or use the stack that already exists to close open sections when a heading of the same or higher level arrives. The stack approach gives an O(n) single pass. Update the incorrect comment as part of the change.
A regression test with many headings should assert the output stays identical and the work stays bounded. For example, count slice or iteration steps, or use a generous time bound on a large input. Existing section tests should cover behavior preservation.
I found no duplicate issues. I didn't make any code changes, because this run was triage only.
Activity
claude commentedon Oct 28, 2026
Claude finished @phernandez's task in 22s —— View job
Triage
Type: enhancement (performance/robustness hardening; the issue carries the
securitylabel, but the scan only establishes a code-level concern, not exploitation)Priority: Medium
Component: Markdown parsing (
markdown/sections.py), which also feeds the note-read API'ssection=slicing. No Cloud-specific behavior is involved.Complexity: Simple
Findings
src/basic_memory/markdown/sections.py:190. For each heading,headings[position + 1 :]copies the suffix list before the loop breaks. That makes the cost O(n²) in the heading count for a large note, even when the very next heading ends the section.itertools.isliceor an index, or use the stack that already exists to close open sections when a heading of the same or higher level arrives. The stack approach gives an O(n) single pass. Update the incorrect comment as part of the change.I found no duplicate issues. I didn't make any code changes, because this run was triage only.