Skip to content

fix(archdocs): guard against start_line > end_line in source snippet extraction#90

Merged
greynewell merged 1 commit intomainfrom
fix-pssg-slice-bounds
Apr 9, 2026
Merged

fix(archdocs): guard against start_line > end_line in source snippet extraction#90
greynewell merged 1 commit intomainfrom
fix-pssg-slice-bounds

Conversation

@greynewell
Copy link
Copy Markdown
Contributor

@greynewell greynewell commented Apr 9, 2026

Summary

  • In pssg/build/build.go, when extracting source code snippets from entity pages, the code does lines[sl-1:el] after checking sl <= len(lines) && el <= len(lines)
  • If sl > el (start_line > end_line in the API response), this creates a reversed slice range and panics with slice bounds out of range
  • Add sl <= el to the bounds guard so malformed line numbers skip the extraction instead of crashing the supermodel docs build

Test plan

  • go build ./... passes
  • Manual: supermodel docs on a repo with normal source data still shows source snippets correctly

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed source-code extraction validation to prevent invalid line ranges where the start line exceeds the end line, improving reliability.

…extraction

When API data has start_line > end_line, lines[sl-1:el] panics with
"slice bounds out of range" because sl-1 > el creates a reversed range.
Add sl <= el to the bounds check so malformed line numbers are skipped
rather than crashing the build.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e5dceda2-3cc5-4abe-b2c3-b435708cae20

📥 Commits

Reviewing files that changed from the base of the PR and between b8d16ff and 58e05ce.

📒 Files selected for processing (1)
  • internal/archdocs/pssg/build/build.go

Walkthrough

A boundary validation fix in the source-code extraction logic: the slice range check now verifies that the start line doesn't exceed the end line (sl <= el), preventing invalid extraction ranges where the indices are reversed.

Changes

Cohort / File(s) Summary
Boundary Validation
internal/archdocs/pssg/build/build.go
Added validation condition sl <= el to the renderEntityPage function's slice bounds check, ensuring start line never exceeds end line in source-code extraction.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A line of defense, now standing tall,
Where start must not exceed the call,
No more reversed ranges in the night,
One tiny check sets bounds just right! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and specifically describes the main change: adding a guard to prevent start_line > end_line in source snippet extraction, which matches the actual code change.
Description check ✅ Passed The description covers the what, why, and test plan sections from the template, explaining the bug, the root cause, the fix, and the testing approach clearly.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 fix-pssg-slice-bounds

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

@greynewell greynewell merged commit 343b81f into main Apr 9, 2026
7 checks passed
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