Skip to content

Fix Edge Case Detector Max File Size bounds#531

Open
theRebelliousNerd wants to merge 1 commit into
mainfrom
fix-edge-case-detector-max-filesize-10505337179896057081
Open

Fix Edge Case Detector Max File Size bounds#531
theRebelliousNerd wants to merge 1 commit into
mainfrom
fix-edge-case-detector-max-filesize-10505337179896057081

Conversation

@theRebelliousNerd
Copy link
Copy Markdown
Owner

@theRebelliousNerd theRebelliousNerd commented May 21, 2026

Implemented bounds checking for LineCount in internal/campaign/edge_case_detector.go to prevent float64 precision loss and potential integer overflow issues in complexity heuristics.
Specifically, bounds checking was added in gatherMetrics prior to rough line count estimations via symbolCount * 25, and within queryComplexity prior to calculation using a 10_000_000 line soft limit cap. Additionally, tests were added in edge_case_detector_test.go to verify behavior handles math.MaxInt32 and safely caps output complexity, directly resolving the missing edge case TODO.


PR created automatically by Jules for task 10505337179896057081 started by @theRebelliousNerd

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced robustness for edge case handling by adding defensive bounds checks to prevent potential overflow issues when processing large files and complex metrics.
    • Improved handling of edge cases when certain operations are unavailable.
  • Tests

    • Added comprehensive test coverage for extreme file size boundary conditions to verify correct system behavior.

Review Change Stack

Co-authored-by: theRebelliousNerd <187437903+theRebelliousNerd@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

📝 Walkthrough

Walkthrough

This PR introduces defensive bounds handling to prevent integer overflow in the edge case detector. It clamps LineCount during metric gathering and adds bounds checking when estimating complexity, with a new test validating behavior at extreme file sizes.

Changes

Defensive bounds in edge case detection

Layer / File(s) Summary
Math import and setup
internal/campaign/edge_case_detector.go, internal/campaign/edge_case_detector_test.go
math package imported to support numeric bounds utilities in both implementation and test code.
Metric bounds in gatherMetrics
internal/campaign/edge_case_detector.go
LineCount estimation now clamps symbolCount * 25 to math.MaxInt32 to prevent integer overflow when processing files with extremely high symbol counts.
Complexity bounds in queryComplexity
internal/campaign/edge_case_detector.go
Explicit nil kernel branch estimates complexity from capped LineCount and returns early; fallback line-count path also clamps LineCount before converting to complexity value.
Extreme file size test
internal/campaign/edge_case_detector_test.go
New TestEdgeCaseDetector_MaxFileSize test constructs a file with math.MaxInt32 lines, validates determineAction returns ActionModularize with threshold reasoning, and confirms computed complexity stays bounded.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • theRebelliousNerd/codenerd#288: Implements concrete extreme-value safeguards and MaxFileSize regression test in EdgeCaseDetector, directly aligning with this PR's boundary-analysis and edge-case coverage focus for the same subsystem.

Poem

🐰 With bounds so tight and overflows prevented,
The edge case detector stands repented.
No integer shall overflow today,
Math.MaxInt32 shows the safer way.
Extreme files tested, complexity crowned,
This fuzzy bunny's logic is sound! 🎉

🚥 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 change: adding bounds checking to prevent max file size overflow issues in the edge case detector.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ 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-edge-case-detector-max-filesize-10505337179896057081
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch fix-edge-case-detector-max-filesize-10505337179896057081

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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 `@internal/campaign/edge_case_detector_test.go`:
- Around line 347-350: Replace the weak upper-bound assertion after calling
detector.queryComplexity(&decision, "huge_file.go") with a deterministic
equality check against the expected capped complexity for math.MaxInt32: compute
expected := float64(math.MaxInt32) / 50.0 and assert decision.Complexity ==
expected (or use a strict comparison with t.Fatalf/t.Errorf if not equal),
referencing detector.queryComplexity and decision.Complexity so the test fails
if the value is 0 or any other incorrect value.

In `@internal/campaign/edge_case_detector.go`:
- Around line 368-379: The fallback branch that computes Complexity when
d.kernel == nil is unreachable because gatherMetrics only calls queryComplexity
when d.kernel is non-nil; update gatherMetrics (or the call site in
AnalyzeFiles) to invoke queryComplexity regardless of d.kernel so the nil-kernel
fallback inside queryComplexity runs, or alternatively move the nil check from
queryComplexity into gatherMetrics/AnalyzeFiles and compute the same
safeLineCount fallback there; ensure you reference and adjust the
queryComplexity method and the gatherMetrics call path so the d.kernel == nil
branch can execute.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8e319971-1a10-45b4-bafb-078cdceed717

📥 Commits

Reviewing files that changed from the base of the PR and between 664e51f and 404683d.

📒 Files selected for processing (2)
  • internal/campaign/edge_case_detector.go
  • internal/campaign/edge_case_detector_test.go

Comment on lines +347 to +350
detector.queryComplexity(&decision, "huge_file.go")
if decision.Complexity > float64(10000000)/50.0 {
t.Errorf("Complexity was not properly bounded, got %v", decision.Complexity)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Complexity bound assertion is too weak for this edge-case test.

The current check only enforces an upper bound, so a regression that leaves complexity at 0 would still pass. Assert the deterministic capped value for math.MaxInt32.

Proposed fix
 	detector.queryComplexity(&decision, "huge_file.go")
-	if decision.Complexity > float64(10000000)/50.0 {
-		t.Errorf("Complexity was not properly bounded, got %v", decision.Complexity)
-	}
+	expected := float64(10000000) / 50.0
+	if decision.Complexity != expected {
+		t.Errorf("Expected bounded complexity %v, got %v", expected, decision.Complexity)
+	}
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
detector.queryComplexity(&decision, "huge_file.go")
if decision.Complexity > float64(10000000)/50.0 {
t.Errorf("Complexity was not properly bounded, got %v", decision.Complexity)
}
detector.queryComplexity(&decision, "huge_file.go")
expected := float64(10000000) / 50.0
if decision.Complexity != expected {
t.Errorf("Expected bounded complexity %v, got %v", expected, decision.Complexity)
}
🤖 Prompt for 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.

In `@internal/campaign/edge_case_detector_test.go` around lines 347 - 350, Replace
the weak upper-bound assertion after calling detector.queryComplexity(&decision,
"huge_file.go") with a deterministic equality check against the expected capped
complexity for math.MaxInt32: compute expected := float64(math.MaxInt32) / 50.0
and assert decision.Complexity == expected (or use a strict comparison with
t.Fatalf/t.Errorf if not equal), referencing detector.queryComplexity and
decision.Complexity so the test fails if the value is 0 or any other incorrect
value.

Comment on lines +368 to +379
if d.kernel == nil {
// Just estimate from line count if kernel is not available
decision.Complexity = 0
if decision.LineCount > 0 {
safeLineCount := decision.LineCount
if safeLineCount > 10000000 {
safeLineCount = 10000000
}
decision.Complexity = float64(safeLineCount) / 50.0
}
return
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Nil-kernel complexity fallback is unreachable from the main analysis flow.

queryComplexity now handles d.kernel == nil, but gatherMetrics only invokes it when the kernel is non-nil (Line 334), so this branch never runs during normal AnalyzeFiles execution.

Proposed fix
 func (d *EdgeCaseDetector) gatherMetrics(decision *FileDecision, path string, intel *IntelligenceReport) {
@@
-	// Query kernel for dependencies
-	if d.kernel != nil {
-		d.queryDependencies(decision, path)
-		d.queryComplexity(decision, path)
-	}
+	// Query kernel for dependencies when available
+	if d.kernel != nil {
+		d.queryDependencies(decision, path)
+	}
+	// Always compute complexity (queryComplexity handles nil kernel fallback)
+	d.queryComplexity(decision, path)
 }
🤖 Prompt for 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.

In `@internal/campaign/edge_case_detector.go` around lines 368 - 379, The fallback
branch that computes Complexity when d.kernel == nil is unreachable because
gatherMetrics only calls queryComplexity when d.kernel is non-nil; update
gatherMetrics (or the call site in AnalyzeFiles) to invoke queryComplexity
regardless of d.kernel so the nil-kernel fallback inside queryComplexity runs,
or alternatively move the nil check from queryComplexity into
gatherMetrics/AnalyzeFiles and compute the same safeLineCount fallback there;
ensure you reference and adjust the queryComplexity method and the gatherMetrics
call path so the d.kernel == nil branch can execute.

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