Repository navigation
fix: forward large bodies to gh via temporary file to avoid argv limits - #259
Conversation
[Medium impact] The change affects how several GitHub content commands send long bodies. The release-note forwarding gap should be fixed before merging. Reviews (3) · Last reviewed commit: "no-mistakes(document): Format large-body..." · Reviewed by Greptile |
|
Speaking as Kun's firstmate: thanks @EnesKartal, this is the right shape for #257, and I checked it with a stub There are a few things to sort out before we can merge:
VISION.md (read in full on
contract-class: Once no-mistakes is green and points 2–3 are handled (and 4 is either covered or scoped), I'll take another look. |
Reuse the temporary body file for gh api --field body=@file in the --match-head-commit review path, and create the file inside the try block so a failed write still removes the temporary directory.
26e7670 to
89a45f8
Compare
|
Thanks for the detailed review. Re-raised through no-mistakes (check is green now). Addressed: (2) |
|
Speaking as Kun's firstmate: thanks @EnesKartal, this addresses everything from the last pass. Rechecked on tip
VISION.md (read in full on
contract-class: Merging. |
|
Speaking as Kun's firstmate: this is merged. Thank you @EnesKartal — really appreciate you taking the time on this. |
| appendValueFlag(optionArgs, remaining, "--title", ["--title", "-t"]); | ||
| appendValueFlag(optionArgs, remaining, "--notes", ["--notes", "-n"]); | ||
| appendNotesFileFlag(optionArgs, remaining); | ||
| const notes = appendNotesFileFlag(optionArgs, remaining) ?? body; |
There was a problem hiding this comment.
Both release handlers put --notes and -n values directly into optionArgs. The new withBodyArgs call receives only body aliases or notes read from stdin, so native notes still bypass the temporary file. Sufficiently large values can exceed the OS command-line limit and prevent the release command from starting.
Take the native notes value separately and pass it through withBodyArgs in both handlers.
Intent
Fix gh-axi issue 257: bodies passed to --body or --body-file that exceed the OS argument limit fail with spawn E2BIG or ENAMETOOLONG. Forward bodies over 30000 characters to gh through a temporary file (--body-file, or gh api --field body=@file for pr review --match-head-commit) and clean the file up. Addresses maintainer review: large body on the matched-head review path, writeFileSync inside the try block. project item-create and item-edit are out of scope because gh project has no --body-file option.
What Changed
withBodyArgsandLARGE_BODY_THRESHOLD(30,000 chars) tosrc/body.ts. A body at or under the threshold still goes to gh as--body. A larger body is written to a temporary UTF-8 file, passed to gh as--body-file(or another file flag the caller names), and the temp directory is removed once the call finishes. Cleanup is best-effort and never hides the gh call's result or error.issue create/edit/comment,pr create/edit/merge/review/comment, anddiscussion commentbehindwithBodyArgs. This stops large bodies from failing withspawn E2BIG/ENAMETOOLONG. On the matched-head path,pr review --match-head-commitnow sends the body throughgh api --field body=@<file>.release create/editpass--notes/--notes-fileto the same helper. This covers notes from--body,--notesand--notes-file -(stdin). Added tests for the inline and temp-file cases in body, issue, pr, discussion, and release.AI-assisted; reviewed and tested by me.
Risk Assessment
✅ Low: The fix is narrow. Bodies over 30,000 characters go to gh through a temporary file that is removed in a
finallyblock, and bodies at or under the limit still go inline as before. Every body path named in the intent is covered: issue and pr create, edit and comment, pr merge, pr review including the matched-head path, discussion comment, and release create and edit (including stdin notes). The installed gh 2.103.3 supports each forwarded flag:--body-file,--notes-file, andgh api --field body=@file, which reads the file without type coercion. Both fixes from round 1 hold, and their tests check the temp file's content against the input body and confirm the file is deleted afterwards.Testing
I built gh-axi and ran it as an end user would, with a disposable fake
ghbinary onGH_BIN. A 242,903-character UTF-8 body went through every changed path: issue create/edit/comment (also via stdin), pr create/edit/comment/merge/review, the matched-head review, discussion comment, and release create/edit (through the--body-filealias and--notes-file -). Each time gh received a temp file whose length and sha256 matched the input. Smaller bodies stayed inline. The cutoff is exact: 30,000 characters stays inline and 30,001 goes to a file. No temp files were left behind, even when gh failed. The base commit reproducedspawn E2BIGon the same command and the fix resolved it. Real gh 2.103.3 turns--field body=@fileinto the file's text as the JSON body. The five changed test files pass. Everything passed; temporary fixtures were removed and only the transcripts and fake-gh scripts were kept as evidence.gh api --field body=@<tmp>; a small body stays--raw-field body=...--field body=@fileas the file's text in the JSON request body (local gh, unreachable host, GH_DEBUG=api)Evidence: Before/after: base fails with spawn E2BIG, fix succeeds
Evidence: Issue paths transcript (create/edit/comment/stdin, small inline)
Evidence: PR, discussion, release and threshold boundary transcript
Evidence: Temp file cleanup when gh fails
Evidence: Real gh sends --field body=@file contents as JSON body
Evidence: Fake gh used as disposable gh stand-in
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed ✅
src/commands/release.ts:291- Release create and edit still put large bodies on the command line, so issue 257 still happens forgh-axi release create|edit --body/--body-file.takeReleaseBodyAliasreads the gh-axi--body/--body-filealias and then pushesoptionArgs.push("--notes", body)(src/commands/release.ts:291 create, :342 edit). A 35,000-character--body-file notes.mdtherefore still reaches spawn as one argv entry and can fail with E2BIG or ENAMETOOLONG. The intent says the fix covers bodies "passed to --body or --body-file" and excludes onlyproject item-create/item-edit; release is not excluded, andgh releasehas--notes-file. Same remaining path:appendNotesFileFlagturns--notes-file -stdin into--notes <content>(src/commands/release.ts:188-193). Fix: wrap createRelease and editRelease in a withBodyArgs-style helper that emits--notes-file <tmp>for bodies over 30000 characters. The simplest way is to give withBodyArgs a flag-name parameter.test/commands/issue.test.ts:1322- The new issue create and pr create regression tests only check that argv[4] is--body-fileand argv[5] is some string. Nothing checks that the file holds the body or that it is deleted afterward. A wrong implementation would still pass, for example one that writes an empty or truncated temp file, never cleans up, or forwards the user's original file path unchanged. Fix: read the temp file inside the ghExec mock, compare it with the input body (the input is the independent oracle), and assert it no longer exists after the command, the way the matched-head review test already does (test/commands/pr.test.ts:1444-1484). Applies to test/commands/issue.test.ts:1322 and test/commands/pr.test.ts:1972. The changed issue edit, issue comment, pr edit, pr comment, pr merge, plain pr review and discussion comment paths have no command-level large-body test.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
gh api --field body=@<tmp>; a small body stays--raw-field body=...--field body=@fileas the file's text in the JSON request body (local gh, unreachable host, GH_DEBUG=api)pnpm run build, thennode dist/bin/gh-axi.jswithGH_BINset to a disposable fake gh (fake-gh.mjs). The fake logs argv and the length and sha256 of any--body-file/--notes-file/body=@file while it still exists. Each run used an isolatedTMPDIRto count leftover temp files.gh-axi issue create|edit|comment --body-file big.mdandissue comment --body-file - < big.mdgh-axi pr create|edit|comment|merge --squash|review --comment --body-file big.mdgh-axi pr review 7 --approve --match-head-commit abc123 --body-file big.md|small.mdgh-axi discussion comment 3 --body-file big.mdgh-axi release create|edit v1 --body-file big.md,release create --notes-file - < big.md, andrelease create --notes-file big.mdThreshold boundary:issue comment --body-filewith 30000- and 30001-character bodiesgh failure cleanup:issue comment,pr editandrelease editwith a fake gh that exits 1 (HTTP 422)Before/after regression: built base commit 911a086 fromgit archiveand ranissue comment --body-file big.mdagainst both buildsRealgh2.103.3:GH_DEBUG=api gh api --hostname ghe.invalid ... --field body=@field.mdwith an isolatedGH_CONFIG_DIR, to see the request payloadpnpm exec vitest run test/body.test.ts test/commands/{issue,pr,release,discussion}.test.ts✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.