Skip to content

fix(parser): guard raw-string hash lookahead at EOF (re-applied from #3867) - #4005

Merged
rossirpaulo merged 4 commits into
canaryfrom
paulo/parser-raw-string-eof-guard
Jul 13, 2026
Merged

fix(parser): guard raw-string hash lookahead at EOF (re-applied from #3867)#4005
rossirpaulo merged 4 commits into
canaryfrom
paulo/parser-raw-string-eof-guard

Conversation

@rossirpaulo

@rossirpaulo rossirpaulo commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Stacked on #4002 (retargets to canary when it merges). Re-applies the one change in #3867 that was a standalone bug fix rather than part of the semantic-tokens feature, so the revert doesn't reintroduce it — addressing CodeRabbit's Critical finding on #4002.

find_token_after_hashes could return the one-past-the-end index after a hash run at EOF, and parse_raw_string indexed tokens with it directly — a panic on incomplete input like a bare ## at end of file, present on canary long before #3867. Under the new LSP core (#4000) a parser panic on the source path additionally poisons the project into a terminal broken state, so this class matters more now.

Both hunks are byte-for-byte @codeshaunted's fix from #3867 (credited as co-author). New here: the regression test the original lacked — verified to panic (index out of bounds: the len is 15 but the index is 15) with the guards removed, and covering bare #/## at top level, inside expression bodies, and after let.

Validation: cargo test -p baml_compiler_parser 140/140 (139 pre-existing + the new test), clippy -D warnings clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VEMxti5WQ8bCgJUuX9AQvo

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of incomplete raw-string syntax at end-of-file.
    • Prevented unexpected parser crashes when inputs end with standalone hash characters.
    • Malformed inputs (including truncated bare-hash sequences) now return parse errors instead of failing.

rossirpaulo and others added 2 commits July 13, 2026 14:18
Re-applies the parser hardening from #3867 (reverted wholesale in #4002
for sequencing): find_token_after_hashes could return the one-past-the-
end index after a hash run at EOF, and parse_raw_string indexed tokens
with it directly — a panic on incomplete input like a bare `##` at end
of file. Return None at EOF and index the call site through get().

Adds the regression test the original fix lacked; verified it panics
("index out of bounds: the len is 15 but the index is 15") without the
two guards.

Co-authored-by: Avery Townsend <avery@boundaryml.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VEMxti5WQ8bCgJUuX9AQvo
@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Jul 13, 2026 10:44pm
promptfiddle Ready Ready Preview, Comment Jul 13, 2026 10:44pm
promptfiddle2 Ready Ready Preview, Comment Jul 13, 2026 10:44pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9ee0446d-31e3-4ef2-80fd-897da1175aa4

📥 Commits

Reviewing files that changed from the base of the PR and between f30da44 and 06aea8d.

📒 Files selected for processing (1)
  • baml_language/crates/baml_compiler_parser/src/parser.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • baml_language/crates/baml_compiler_parser/src/parser.rs

📝 Walkthrough

Walkthrough

Raw-string parsing now handles incomplete hash delimiters at EOF without out-of-bounds indexing. Token lookup returns no position when EOF is reached, quote validation uses safe access, and regression tests cover bare hashes and truncated contexts.

Changes

Raw-string EOF handling

Layer / File(s) Summary
Safe token navigation
baml_language/crates/baml_compiler_parser/src/parser.rs
Raw-string token lookup skips trailing trivia, returns None for EOF positions, and validates candidate quotes through safe token access.
Bare-hash regression coverage
baml_language/crates/baml_compiler_parser/src/parser.rs
Tests confirm incomplete hash delimiters produce parse diagnostics without panicking.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

I’m a rabbit with hashes, thump-thump at the door,
Bare ones meet EOF and cause crashes no more.
Safe quotes peek gently,
Diagnostics hop plenty,
While panics sleep soundly on the floor.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main parser EOF raw-string safety fix and is specific enough for history scans.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch paulo/parser-raw-string-eof-guard

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown

Binary size checks passed

7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
baml-cli Linux 🔒 21.9 MB 9.4 MB file 21.5 MB +356.2 KB (+1.7%) OK
packed-program Linux 🔒 15.8 MB 6.7 MB file 15.6 MB +138.7 KB (+0.9%) OK
baml-cli macOS 🔒 16.8 MB 8.1 MB file 16.6 MB +283.0 KB (+1.7%) OK
packed-program macOS 🔒 12.2 MB 5.9 MB file 12.1 MB +83.9 KB (+0.7%) OK
baml-cli Windows 🔒 18.4 MB 8.3 MB file 18.1 MB +271.9 KB (+1.5%) OK
packed-program Windows 🔒 13.1 MB 6.0 MB file 13.0 MB +65.0 KB (+0.5%) OK
bridge_wasm WASM 14.6 MB 🔒 4.1 MB gzip 4.1 MB +72.4 KB (+1.8%) OK

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.


Generated by cargo size-gate · workflow run

Base automatically changed from paulo/revert-3867-semantic-tokens to canary July 13, 2026 22:10

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@baml_language/crates/baml_compiler_parser/src/parser.rs`:
- Around line 8054-8072: Update the bare_hashes_at_eof_do_not_panic test to
assert that parse_source returns at least one diagnostic for every malformed
input, while retaining the existing no-panic coverage. Use the returned _errors
value and preserve the current source cases.
- Around line 1802-1808: Update the hash-handling flow around
looks_like_config_expression, parse_config_value, and parse_config_block so an
EOF-terminated hash sequence cannot retry the same Hash token indefinitely;
ensure malformed values consume the offending token or otherwise guarantee
parser progress while preserving valid hash parsing. Add a regression case
covering an input such as client<llm> C { key ##.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7642208b-8ae8-4560-8fb4-53fd1f474553

📥 Commits

Reviewing files that changed from the base of the PR and between 4a9ffe3 and f30da44.

📒 Files selected for processing (1)
  • baml_language/crates/baml_compiler_parser/src/parser.rs

Comment thread baml_language/crates/baml_compiler_parser/src/parser.rs
Comment thread baml_language/crates/baml_compiler_parser/src/parser.rs
…locks

Review follow-ups: every malformed case now asserts at least one
diagnostic (a silent-accept regression would previously pass), and two
config-block cases pin that hash values at EOF neither panic nor loop —
config-value recovery leaves the hashes unconsumed and the next
config-item iteration consumes them as a malformed key (error + bump).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VEMxti5WQ8bCgJUuX9AQvo
@rossirpaulo
rossirpaulo added this pull request to the merge queue Jul 13, 2026
Merged via the queue into canary with commit cf3cbd3 Jul 13, 2026
53 checks passed
@rossirpaulo
rossirpaulo deleted the paulo/parser-raw-string-eof-guard branch July 13, 2026 23:14
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.

1 participant