Skip to content

fix(core): avoid quadratic section heading suffix copies - #1920

Merged
phernandez merged 1 commit into
mainfrom
codex/security-section-scanning
Oct 28, 2026
Merged

phernandez merged 1 commit into
mainfrom
codex/security-section-scanning

Conversation

@phernandez

Copy link
Copy Markdown
Member

Why

Heading-heavy notes cause quadratic reference copying in section scanning: each heading copies the remaining heading list before looking for its boundary. A bounded 600-heading regression counts 179,700 copied references. Fixes #1890.

What Changed

Walk the original heading list by index instead of copying suffixes. Preserve heading paths, duplicate indexes, line ranges, and canonical byte offsets.

Implementation Details

Markdown headings have six levels, so each later heading participates in at most six open section lookaheads. Removing the suffix allocation restores linear aggregate boundary work without changing the existing boundary algorithm. Tests count accessed/copied references rather than relying on wall-clock thresholds, and compare every resulting boundary with its definition.

Follows #1915 and #1916, which have now merged. Based on current main; only section scanning and its regression tests are new here.

Testing

  • Before the fix: all three bounded work regressions failed.
  • uv run pytest tests/markdown/test_section_scan_work.py tests/markdown/test_sections.py tests/services/test_note_section_edits.py -q --no-cov: 91 passed.
  • just fast-check: passed, including repository type checking.
  • just doctor: passed sandboxed write/index/search self-test.
  • git diff --check: passed.

Risks / Follow-ups

No input limits or public API changes. This fixes the reported Core scanning cost; it does not establish production exploitation. Other parser and resource-budget findings remain separate issues. Cloud will need a Core dependency update after merge.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T20:27:12.855669Z 945da03 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@phernandez
phernandez merged commit 5f8a030 into main Oct 28, 2026
52 checks passed
@phernandez
phernandez deleted the codex/security-section-scanning branch October 28, 2026 22:15
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.

Parse Markdown sections without repeated suffix list copies

1 participant