fix(drift): cap auto-remediation PR/issue body under GitHub's 65536-char limit#303
Merged
Conversation
commit: |
…har limit Root cause: truncateBody honored only its `max` arg and could return a string LONGER than intended in two ways: - Negative/marker-only overflow: when `max < marker.length`, the budget `max - marker.length` was clamped to 0, so the result was the marker alone — longer than `max`. - Hard-limit bypass: a caller passing `max >= 65536` (or above the actual GitHub ceiling) yielded a body that `gh` rejects, because the function never enforced GH_BODY_MAX. Fix: compute `effectiveMax = Math.min(max, GH_BODY_MAX)` so the postcondition `result.length <= Math.min(max, GH_BODY_MAX)` always holds. Return the input unchanged when under `effectiveMax`; hard-cut (no marker) when `effectiveMax <= marker.length`; otherwise slice to `effectiveMax - marker.length` and append the marker. Call sites (fix-drift.ts:576, :729) both use the safe default and are unchanged. Added postcondition tests covering tiny-max, over-hard-limit, under-limit passthrough, and marker presence.
… uploaded) The fix-drift log and drift-report JSON are regenerated on every run and are already uploaded as workflow artifacts, so committing them adds nothing but noise. The catch-all `git add` in the remediation flow was sweeping them into commits; ignoring them keeps the tree clean.
jpr5
force-pushed
the
fix/fix-drift-pr-body-truncation
branch
from
July 16, 2026 20:04
5e2df70 to
9d6c82e
Compare
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.
The Fix Drift workflow failed at PR creation on run 29478043559:
gh pr createrejected the body withBody is too long (maximum is 65536 characters).Root cause
buildPrBodyinscripts/fix-drift.tsinlines the entire drift report (JSON.stringify(report, null, 2)) into a<details>block. A wide-drift run produced a ~642 KB body — roughly 10× GitHub's 65536-char hard limit. No length guard existed anywhere on the path.createIssueinlines the same report plus the full Claude log and shares the identical limit.Fix
truncateBody(s, max)(safe cap 60000, under the 65536 limit): keeps the summary head, replaces the overflow tail with a truncation marker plus a pointer to the workflow run/artifacts. Applied at the two choke points —buildPrBody's return andcreateIssue's body.claude-code-output.loganddrift-report.jsonare now gitignored. The catch-allgit addwas sweeping them into the fix branch (the 1013-insertion noise), even though both are already uploaded as workflow artifacts.Testing
Red-green: pre-fix the oversized-body test fails (actual body measured at 642,426 chars); post-fix all 82 fix-drift tests pass and the body is ≤ 65536. Full suite green (4444 passed), lint / typecheck / build clean. No version bump — the release bump stays manual.