Skip to content

ADFA-3481 | Fix editor indent OOM on Enter key event - #1465

Merged
jatezzz merged 1 commit into
stagefrom
fix/ADFA-3481-editor-indent-oom
Jul 1, 2026
Merged

jatezzz merged 1 commit into
stagefrom
fix/ADFA-3481-editor-indent-oom

Conversation

@jatezzz

@jatezzz jatezzz commented Jul 1, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR fixes a critical OutOfMemoryError that occurs when pressing the Enter key in the code editor, and it corrects the tree-sitter indentation calculation for blank lines. I updated the logic to always request both the current and next lines to calculate a relative indent delta, ensuring accuracy regardless of file indentation width mismatches. Furthermore, I added safeguard checks against sentinel values (like INDENT_AUTO) to prevent the application from attempting to allocate extremely large whitespace strings during indent generation.

Details

OutOfMemoryError: Failed to allocate a 301989904 byte allocation with 50331648 free bytes and 262MB until OOM, target footprint 311780288, growth limit 536870912
    at java.util.Arrays.copyOf(Arrays.java:4276)
    at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:301)
    at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:853)
    at java.lang.StringBuilder.append(StringBuilder.java:261)
    at io.github.rosemoe.sora.text.TextUtils.createIndent(SourceFile:32)
    at io.github.rosemoe.sora.widget.CodeEditor.commitText(SourceFile:77)
    at io.github.rosemoe.sora.widget.EditorKeyEventHandler.handleEnterKeyEvent(SourceFile:252)

Before

Screen.Recording.2026-07-01.at.9.43.31.AM.mov

After

Screen.Recording.2026-07-01.at.9.41.11.AM.mov

Ticket

ADFA-3481

Also fixes: ADFA-2544

Observation

The crash was caused by sentinel values (e.g., Int.MAX_VALUE) being passed unchecked into the createIndent utility, causing it to attempt to allocate roughly 300MB of whitespace into memory. The fallback to default advance behavior avoids this overflow.

…-advance OOM

Use a relative current/next line indent delta and treat INDENT_AUTO as a sentinel.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The getIndentAdvance method in TreeSitterLanguage.kt was changed to always compute indentation for both the current and next lines and return their difference as a relative advance, replacing prior conditional logic that skipped blank next lines and handled single-indent results. Sentinel validation was expanded, and an unused import was removed.

Changes

Indent Advance Logic

Layer / File(s) Summary
Rework indent advance computation
editor/.../TreeSitterLanguage.kt
getIndentAdvance now always requests indentation for both current and next lines, returns indentNxtLine - indentLine as the advance, treats INDENTATION_ERR/INDENT_AUTO on either value as invalid (falling back to DEF_IDENT_ADV), and drops the unused isNonBlankLine import.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A rabbit hops through lines of code,
Delta indents, a lighter load,
No more checks for blank lines near,
Just current and next, crisp and clear,
Hop, hop, hooray for tidy code! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: fixing an editor Enter-key indentation OOM.
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.
Description check ✅ Passed The description matches the code changes, explaining the indent delta fix and sentinel-value safeguards for the editor crash.
✨ 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/ADFA-3481-editor-indent-oom

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.

@jatezzz

jatezzz commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

@claude review once

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit at claude.ai/admin-settings/claude-code.

Once credits are available, comment @claude review on this pull request to trigger a review.

@jatezzz
jatezzz merged commit 75dfe19 into stage Jul 1, 2026
4 checks passed
@jatezzz
jatezzz deleted the fix/ADFA-3481-editor-indent-oom branch July 1, 2026 21: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.

2 participants