Skip to content

fix(org-status): avoid ARG_MAX crash with 200+ open PRs - #258

Merged
don-petry merged 2 commits into
mainfrom
fix/org-status-argmax-large-pr-sets
May 12, 2026
Merged

fix(org-status): avoid ARG_MAX crash with 200+ open PRs#258
don-petry merged 2 commits into
mainfrom
fix/org-status-argmax-large-pr-sets

Conversation

@don-petry

Copy link
Copy Markdown
Contributor

Summary

  • Root cause: jq -n --argjson a "$ALL_PRS" --argjson b "$prs" passes the accumulated PR array as a shell argument. After 252 PRs across 8 repos the variable exceeded Linux's ARG_MAX limit (~3 MB on this runner), causing exit 126 (E2BIG: Argument list too long) in run 25736549959.
  • Fix: Both the PR and issues accumulation loops now use the NDJSON pattern already established in the Behind-Base Detection section — emit one compact JSON line per item into a string variable, slurp into an array once at the end with jq -cs '.'. No batch data ever passes through a command-line argument.
  • Issues loop also fixed pre-emptively — same pattern, same failure mode once issue counts grow.

Regression proof

Synthetic dataset: 8 repos × 35 PRs = 280 PRs (matching live scale).

=== Reproducing ARG_MAX failure with OLD pattern ===
CONFIRMED FAIL after repo=eta: Argument list too long

=== Testing NEW pattern (NDJSON accumulation) ===
SUCCESS: accumulated 280 PRs without hitting ARG_MAX
NDJSON variable size: 159076 bytes (155 KB)

Test plan

  • Confirm CI lint passes (shellcheck, actionlint)
  • Re-trigger the daily workflow manually (workflow_dispatch) or wait for next scheduled run — expect the "Generate org status report" step to succeed

🤖 Generated with Claude Code

Passing a growing JSON array via `jq --argjson` exceeds the Linux kernel's
ARG_MAX limit (~2-3 MB) once enough PR data accumulates. The daily run hit
this at 252 PRs across 8 repos (exit code 126, "Argument list too long").

Switch both the PR and issues accumulation loops to the NDJSON pattern already
used in the Behind-Base Detection section: emit one compact JSON line per item
into a string variable, then slurp into an array once at the end with
`jq -cs '.'`. No PR/issue data ever passes through a command-line argument.

Regression test (8 repos × 35 PRs = 280 synthetic PRs):
- Old pattern: Argument list too long at repo 7/8
- New pattern: 280 PRs accumulated successfully

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 12, 2026 18:20
@don-petry
don-petry requested a review from a team as a code owner May 12, 2026 18:20
@coderabbitai

coderabbitai Bot commented May 12, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@don-petry has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 10 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c692e234-4c6b-4dfd-a416-8bc12d96e519

📥 Commits

Reviewing files that changed from the base of the PR and between fea867c and 92d7fe1.

📒 Files selected for processing (1)
  • scripts/org_status.sh
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/org-status-argmax-large-pr-sets

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates scripts/org_status.sh to prevent Linux ARG_MAX failures when aggregating large numbers of open PRs/issues across many repositories by switching from “grow a JSON array via --argjson” to an NDJSON accumulation + final slurp approach.

Changes:

  • Accumulate PRs as NDJSON (one compact JSON object per line) and slurp once at the end with jq -cs '.'.
  • Apply the same NDJSON pattern to the issues aggregation loop to avoid the same failure mode as issue volume grows.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors scripts/org_status.sh to use NDJSON accumulation for pull requests and issues, effectively preventing ARG_MAX errors when handling large datasets. Feedback suggests applying this pattern to other sections of the script, such as merge activity and internal PR collection, for complete robustness. Additionally, the reviewer recommends using Bash here-strings (<<<) instead of echo or printf for more idiomatic and safer piping of variable content to jq.

Comment thread scripts/org_status.sh
Comment thread scripts/org_status.sh Outdated
Comment thread scripts/org_status.sh Outdated
Comment thread scripts/org_status.sh Outdated
Comment thread scripts/org_status.sh Outdated
…< style

Address Gemini review on PR #258:

- collect_classify_prs: replace --argjson page accumulation (all_nodes) with
  NDJSON pattern; protects against repos with many PR pages, not just large
  org totals.  Also switch echo | jq to <<< throughout the function.

- Merge activity: write ORG_MERGES/PERSONAL_MERGES to DATA_DIR/merges.json via
  printf (bash builtin, no exec, no ARG_MAX) so MERGE_DAILY and
  MERGE_BY_REPO_DAY read from a file descriptor instead of --argjson args.

- All remaining echo "$x" | jq and printf | jq replaced with <<< herestrings
  as suggested (more idiomatic, avoids echo flag interpretation edge case).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@don-petry
don-petry enabled auto-merge (squash) May 12, 2026 18:57
@don-petry
don-petry merged commit 8558fa5 into main May 12, 2026
20 checks passed
@don-petry
don-petry deleted the fix/org-status-argmax-large-pr-sets branch May 12, 2026 19:00
don-petry added a commit that referenced this pull request Jun 8, 2026
* fix(org-status): avoid ARG_MAX crash when org has 200+ open PRs

Passing a growing JSON array via `jq --argjson` exceeds the Linux kernel's
ARG_MAX limit (~2-3 MB) once enough PR data accumulates. The daily run hit
this at 252 PRs across 8 repos (exit code 126, "Argument list too long").

Switch both the PR and issues accumulation loops to the NDJSON pattern already
used in the Behind-Base Detection section: emit one compact JSON line per item
into a string variable, then slurp into an array once at the end with
`jq -cs '.'`. No PR/issue data ever passes through a command-line argument.

Regression test (8 repos × 35 PRs = 280 synthetic PRs):
- Old pattern: Argument list too long at repo 7/8
- New pattern: 280 PRs accumulated successfully

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* fix(org-status): address review comments — full ARG_MAX coverage + <<< style

Address Gemini review on PR #258:

- collect_classify_prs: replace --argjson page accumulation (all_nodes) with
  NDJSON pattern; protects against repos with many PR pages, not just large
  org totals.  Also switch echo | jq to <<< throughout the function.

- Merge activity: write ORG_MERGES/PERSONAL_MERGES to DATA_DIR/merges.json via
  printf (bash builtin, no exec, no ARG_MAX) so MERGE_DAILY and
  MERGE_BY_REPO_DAY read from a file descriptor instead of --argjson args.

- All remaining echo "$x" | jq and printf | jq replaced with <<< herestrings
  as suggested (more idiomatic, avoids echo flag interpretation edge case).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
don-petry added a commit that referenced this pull request Jun 10, 2026
* fix(org-status): avoid ARG_MAX crash when org has 200+ open PRs

Passing a growing JSON array via `jq --argjson` exceeds the Linux kernel's
ARG_MAX limit (~2-3 MB) once enough PR data accumulates. The daily run hit
this at 252 PRs across 8 repos (exit code 126, "Argument list too long").

Switch both the PR and issues accumulation loops to the NDJSON pattern already
used in the Behind-Base Detection section: emit one compact JSON line per item
into a string variable, then slurp into an array once at the end with
`jq -cs '.'`. No PR/issue data ever passes through a command-line argument.

Regression test (8 repos × 35 PRs = 280 synthetic PRs):
- Old pattern: Argument list too long at repo 7/8
- New pattern: 280 PRs accumulated successfully

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* fix(org-status): address review comments — full ARG_MAX coverage + <<< style

Address Gemini review on PR #258:

- collect_classify_prs: replace --argjson page accumulation (all_nodes) with
  NDJSON pattern; protects against repos with many PR pages, not just large
  org totals.  Also switch echo | jq to <<< throughout the function.

- Merge activity: write ORG_MERGES/PERSONAL_MERGES to DATA_DIR/merges.json via
  printf (bash builtin, no exec, no ARG_MAX) so MERGE_DAILY and
  MERGE_BY_REPO_DAY read from a file descriptor instead of --argjson args.

- All remaining echo "$x" | jq and printf | jq replaced with <<< herestrings
  as suggested (more idiomatic, avoids echo flag interpretation edge case).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
don-petry added a commit that referenced this pull request Jun 11, 2026
* fix(org-status): avoid ARG_MAX crash when org has 200+ open PRs

Passing a growing JSON array via `jq --argjson` exceeds the Linux kernel's
ARG_MAX limit (~2-3 MB) once enough PR data accumulates. The daily run hit
this at 252 PRs across 8 repos (exit code 126, "Argument list too long").

Switch both the PR and issues accumulation loops to the NDJSON pattern already
used in the Behind-Base Detection section: emit one compact JSON line per item
into a string variable, then slurp into an array once at the end with
`jq -cs '.'`. No PR/issue data ever passes through a command-line argument.

Regression test (8 repos × 35 PRs = 280 synthetic PRs):
- Old pattern: Argument list too long at repo 7/8
- New pattern: 280 PRs accumulated successfully

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* fix(org-status): address review comments — full ARG_MAX coverage + <<< style

Address Gemini review on PR #258:

- collect_classify_prs: replace --argjson page accumulation (all_nodes) with
  NDJSON pattern; protects against repos with many PR pages, not just large
  org totals.  Also switch echo | jq to <<< throughout the function.

- Merge activity: write ORG_MERGES/PERSONAL_MERGES to DATA_DIR/merges.json via
  printf (bash builtin, no exec, no ARG_MAX) so MERGE_DAILY and
  MERGE_BY_REPO_DAY read from a file descriptor instead of --argjson args.

- All remaining echo "$x" | jq and printf | jq replaced with <<< herestrings
  as suggested (more idiomatic, avoids echo flag interpretation edge case).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
don-petry added a commit that referenced this pull request Jun 11, 2026
* fix(org-status): avoid ARG_MAX crash when org has 200+ open PRs

Passing a growing JSON array via `jq --argjson` exceeds the Linux kernel's
ARG_MAX limit (~2-3 MB) once enough PR data accumulates. The daily run hit
this at 252 PRs across 8 repos (exit code 126, "Argument list too long").

Switch both the PR and issues accumulation loops to the NDJSON pattern already
used in the Behind-Base Detection section: emit one compact JSON line per item
into a string variable, then slurp into an array once at the end with
`jq -cs '.'`. No PR/issue data ever passes through a command-line argument.

Regression test (8 repos × 35 PRs = 280 synthetic PRs):
- Old pattern: Argument list too long at repo 7/8
- New pattern: 280 PRs accumulated successfully

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* fix(org-status): address review comments — full ARG_MAX coverage + <<< style

Address Gemini review on PR #258:

- collect_classify_prs: replace --argjson page accumulation (all_nodes) with
  NDJSON pattern; protects against repos with many PR pages, not just large
  org totals.  Also switch echo | jq to <<< throughout the function.

- Merge activity: write ORG_MERGES/PERSONAL_MERGES to DATA_DIR/merges.json via
  printf (bash builtin, no exec, no ARG_MAX) so MERGE_DAILY and
  MERGE_BY_REPO_DAY read from a file descriptor instead of --argjson args.

- All remaining echo "$x" | jq and printf | jq replaced with <<< herestrings
  as suggested (more idiomatic, avoids echo flag interpretation edge case).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
don-petry added a commit that referenced this pull request Jun 11, 2026
* fix(org-status): avoid ARG_MAX crash when org has 200+ open PRs

Passing a growing JSON array via `jq --argjson` exceeds the Linux kernel's
ARG_MAX limit (~2-3 MB) once enough PR data accumulates. The daily run hit
this at 252 PRs across 8 repos (exit code 126, "Argument list too long").

Switch both the PR and issues accumulation loops to the NDJSON pattern already
used in the Behind-Base Detection section: emit one compact JSON line per item
into a string variable, then slurp into an array once at the end with
`jq -cs '.'`. No PR/issue data ever passes through a command-line argument.

Regression test (8 repos × 35 PRs = 280 synthetic PRs):
- Old pattern: Argument list too long at repo 7/8
- New pattern: 280 PRs accumulated successfully

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* fix(org-status): address review comments — full ARG_MAX coverage + <<< style

Address Gemini review on PR #258:

- collect_classify_prs: replace --argjson page accumulation (all_nodes) with
  NDJSON pattern; protects against repos with many PR pages, not just large
  org totals.  Also switch echo | jq to <<< throughout the function.

- Merge activity: write ORG_MERGES/PERSONAL_MERGES to DATA_DIR/merges.json via
  printf (bash builtin, no exec, no ARG_MAX) so MERGE_DAILY and
  MERGE_BY_REPO_DAY read from a file descriptor instead of --argjson args.

- All remaining echo "$x" | jq and printf | jq replaced with <<< herestrings
  as suggested (more idiomatic, avoids echo flag interpretation edge case).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
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.

2 participants