Skip to content

Fail instead of acting on a truncated list of changed files - #2

Draft
djw wants to merge 1 commit into
mainfrom
claude/code-audit-roadmap-z146rn
Draft

djw wants to merge 1 commit into
mainfrom
claude/code-audit-roadmap-z146rn

Conversation

@djw

@djw djw commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Draft. One file, +15 −1.

The bug

The compare API returns at most 300 files for a comparison. The code read response.data.files with no check:

const files = response.data.files.filter(...)

So any change touching more than 300 files silently produced a short list and a green step. No warning, no error. For a workflow that gates a test suite or a deploy on changed paths, that is a silently skipped check — and it fails in the direction that looks like success.

Easy to hit in practice: lockfile regeneration, a formatter run, a codegen refresh, or a large refactor all routinely clear 300 files.

Why this fails rather than paginating

There is nothing to paginate. The endpoint's page/per_page parameters page the commits, not the files — per GitHub's own API description, "the list of changed files is only shown on the first page of results, and it includes up to 300 changed files for the entire comparison."

That is a property of the endpoint, not of the client library, so no client upgrade lifts this cap. Once the response comes back with 300 files there is no way to ask for the rest, so the only correct options are to report it or to silently return a partial list. This reports it.

The change

const changedFiles = response.data.files || []
if (changedFiles.length >= 300) {
  throw new Error(
    `The GitHub API reported ${changedFiles.length} changed files, the maximum it returns for a single ` +
      'comparison, so the list is probably incomplete. Split this change into smaller ones if a complete ' +
      'list of changed files is needed.'
  )
}

Two details worth noting:

  • throw, not setFailed. setFailed only sets process.exitCode and logs — it does not halt. Using it here would let the run continue and publish outputs built from the short list, which defeats the point. The existing catch turns the throw into a failed step, and the throw sits before all seven setOutput calls so nothing is published on this path.
  • || [] guards a compare response with no files key, which previously would have been an unhandled TypeError surfaced as an opaque API error.

Verification

tsc, eslint, prettier --check clean; existing test suite passes; dist/index.js rebuilds byte-identical so the packaging guard stays honest. Confirmed in the built bundle that the guard (line 111) precedes setOutput (line 213), and that a thrown error surfaces through the existing catch as a failed step.

Not verified against the live API — outbound calls to api.github.com don't complete from where this was built — so the 300 threshold comes from GitHub's published API description rather than an observed 301-file comparison.

Deliberately not done

  • No tests. The guard is three lines of arithmetic, and src/main.ts calls run() at import so it isn't importable without either an entry-point guard or extracting a module. Not worth that for this. Happy to add either if you'd prefer coverage.
  • No pagination for pull requests. pulls.listFiles does paginate and would return up to 3000 files, so a 400-file PR could be made to work correctly rather than fail. That's a larger change (new module, changed data source, and it surfaces the file-status issue below); this PR deliberately takes the small safe option instead. If these failures start firing in practice, that's the signal to revisit.

Follow-ups

  1. If truncation failures actually occur, add pulls.listFiles pagination for the pull request path.
  2. setFailed doesn't halt anywhere else either — the five other call sites in main.ts all fall through, and a failed run can still publish outputs built from unassigned variables. Worth fixing on its own.
  3. Guard the filter loop's core.debug calls behind core.isDebug() — currently ~90k lines / 3.3 MB of stdout per run with debug disabled, measured at 3,000 files × 10 patterns.
  4. The status switch fails on copied / changed / unchanged, which GitHub does return.

@djw
djw force-pushed the claude/code-audit-roadmap-z146rn branch 2 times, most recently from 23bf13f to 7b086b9 Compare August 21, 2026 10:06
@djw djw changed the title Paginate the changed-file list instead of silently truncating at 300 Stop silently returning a truncated list of changed files Aug 24, 2026
The compare API returns at most 300 files for a comparison. The code read
response.data.files with no check, so any change touching more than 300
files silently produced a short list and a green step. For a workflow that
gates tests or a deploy on changed paths, that is a silently skipped check
failing in the direction that looks like success.

There is no way to ask for the rest. The endpoint's page/per_page
parameters page the commits, not the files: per GitHub's API description
the file list is only returned on the first page and is capped at 300 for
the entire comparison. That is a property of the endpoint rather than of
the client library, so no client upgrade lifts it.

Since the list cannot be completed, reaching the cap now throws rather than
returning a partial set. Throwing rather than calling setFailed matters
here: setFailed only sets process.exitCode and does not halt, so the run
would otherwise continue and publish outputs built from the short list. The
existing catch turns the throw into a failed step.

Also guards against a compare response with no files key, which previously
would have been an unhandled TypeError reported as an opaque API error.
@djw
djw force-pushed the claude/code-audit-roadmap-z146rn branch from 7b086b9 to 437a7c8 Compare August 24, 2026 10:35
@djw djw changed the title Stop silently returning a truncated list of changed files Fail instead of acting on a truncated list of changed files Aug 24, 2026
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