Skip to content

fix(drift): cap auto-remediation PR/issue body under GitHub's 65536-char limit#303

Merged
jpr5 merged 2 commits into
mainfrom
fix/fix-drift-pr-body-truncation
Jul 16, 2026
Merged

fix(drift): cap auto-remediation PR/issue body under GitHub's 65536-char limit#303
jpr5 merged 2 commits into
mainfrom
fix/fix-drift-pr-body-truncation

Conversation

@jpr5

@jpr5 jpr5 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

The Fix Drift workflow failed at PR creation on run 29478043559: gh pr create rejected the body with Body is too long (maximum is 65536 characters).

Root cause

buildPrBody in scripts/fix-drift.ts inlines 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. createIssue inlines the same report plus the full Claude log and shares the identical limit.

Fix

  • Cap the body. New 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 and createIssue's body.
  • Stop committing artifact noise. claude-code-output.log and drift-report.json are now gitignored. The catch-all git add was 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.

@pkg-pr-new

pkg-pr-new Bot commented Jul 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@copilotkit/aimock@303

commit: 9d6c82e

jpr5 added 2 commits July 16, 2026 13:01
…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
jpr5 force-pushed the fix/fix-drift-pr-body-truncation branch from 5e2df70 to 9d6c82e Compare July 16, 2026 20:04
@jpr5
jpr5 merged commit 03cfa1a into main Jul 16, 2026
23 checks passed
@jpr5
jpr5 deleted the fix/fix-drift-pr-body-truncation branch July 16, 2026 20:10
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