fix(comment): bound errored-project rendering to prevent comment-generation hang - #21
Merged
Merged
Conversation
…ration hang formatErroredProject built its output with `s += ...` while splitting the diagnostic message on ": " and applying a per-piece growing indent via strings.Repeat. A large critical diagnostic (e.g. a multi-MB Terraform HCL parse error, which also contains many ": " separators) turned this into an O(n^2) string build, spinning a single goroutine on-CPU indefinitely. This runs inside GenerateComment, before renderWithTruncation, so the 64KB comment cap never kicked in. Fixes: - formatErroredProject uses strings.Builder, caps each diagnostic message to 4KB before splitting, caps indent depth, and caps the number of critical diagnostics rendered per project (10) with a summarised remainder. - processProjectCostDetails caps the combined errored-projects section (32KB), since the whole section is built before truncation. Adds a regression test that hangs on the old implementation and completes instantly with the fix.
vdmgolub
approved these changes
Jul 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A production run hung indefinitely after logging
Total after diff: 182 project(s). A goroutine dump showed the single run goroutine[runnable](on-CPU, not blocked on I/O or locks) spinning in:formatErroredProjectbuilt its output withs += ...while splitting the diagnostic message on": "and applying a per-piece growing indent viastrings.Repeat. A large critical diagnostic — e.g. a multi-MB Terraform HCL parse error, which also contains many": "separators — turns this into an O(n²) string build (quadratic in both concatenation and cumulative indent). Because this runs insideGenerateComment, beforerenderWithTruncation, the 64 KB comment cap never gets a chance to kick in.Fix
pkg/vcs/comment/cost_details.go:formatErroredProject: usestrings.Builder; cap each diagnostic message to 4 KB (rune-safe, viaprefixWithin) before splitting; cap indent depth at 8; cap the number of critical diagnostics rendered per project at 10, with a… and N more error(s)summary.processProjectCostDetails: cap the combined errored-projects section at 32 KB (built before truncation), with a… and N more project(s) with errorsnote.Both quadratic terms are removed; total work is now linear and bounded regardless of diagnostic size or error count.
Test
Adds
errored_project_test.go:TestFormatErroredProject_Pathological— a ~6 MB diagnostic with ~2M": "separators. Verified it hangs (5s guard trips, ~4 cores pinned) on the old implementation and completes in ~0s with the fix, output bounded.TestFormatErroredProject_LimitsErrorCount— asserts the per-project error cap + summary.go build ./...,go vet, and the fullpkg/vcs/commentsuite pass.