Skip to content

fix(workflows): cap gate show_file line width, not just its line count - #4534

Open
jawwad-ali wants to merge 1 commit into
github:mainfrom
jawwad-ali:fix/gate-show-file-line-width
Open

jawwad-ali wants to merge 1 commit into
github:mainfrom
jawwad-ali:fix/gate-show-file-line-width

Conversation

@jawwad-ali

Copy link
Copy Markdown
Contributor

Problem

GateStep._read_show_file bounds the number of lines:

if len(lines) >= GateStep.MAX_SHOW_FILE_LINES:
    truncated = True
    break

but nothing bounds a single line's length. A file with no newlines — minified JSON, a lockfile, a base64 blob, all plausible review material to put in front of an approver — is one line of arbitrary size, so the cap never triggers and the whole file floods the prompt. That is exactly the outcome MAX_SHOW_FILE_LINES exists to prevent.

Reproduction on current main (c173bf1)

many short lines : returned 201 lines, total chars=1323    (cap=200)
one long line    : returned   1 lines, total chars=400008  <-- unbounded

The 5,000-line file is correctly clipped to 1,323 characters. The single-line 400 KB file passes through whole.

The content is also rendered inside the gate box one character at a time by _prompt, so the operator's terminal is buried and the choice prompt is pushed far off screen.

Fix

Add a per-line cap alongside the line cap, with a notice in the same style as the existing one:

MAX_SHOW_FILE_LINE_CHARS = 500
...
if len(clean) > GateStep.MAX_SHOW_FILE_LINE_CHARS:
    clean = clean[:GateStep.MAX_SHOW_FILE_LINE_CHARS] + "… (line truncated at 500 characters)"

After the fix:

many short lines : 201 lines, 1323 chars (unchanged)
one long line    :   1 lines,  536 chars
short file       : ['hello', 'world']    (untouched)

Verification

  • Fail-before / pass-after: 1 new-vs-baseline failure with the source reverted to upstream/main49 passed with the fix.
  • A companion test asserts short lines are still rendered verbatim with no notice, so the cap cannot start mangling ordinary files.
  • The existing test_read_show_file_truncates_large_file, test_read_show_file_strips_control_chars and test_read_show_file_empty all use short lines and are unaffected — they pass unchanged.
  • uvx ruff@0.15.0 check src tests → clean

Behaviour change, disclosed: a show_file line longer than 500 characters is now rendered truncated with a notice instead of in full. That is the intent; no existing test exercises such a line.

Note on overlap: this touches steps/gate/__init__.py, as does my #4529, but a different function (_read_show_file vs _prompt). They should merge independently — happy to rebase whichever lands second.


Written with assistance from Claude Code. Bug found, reproduced, and verified by me on current main.

🤖 Generated with Claude Code

`_read_show_file` bounds the number of lines with `MAX_SHOW_FILE_LINES`, but
nothing bounds a single line's length. A file with no newlines -- minified
JSON, a lockfile, a base64 blob, all plausible review material for a gate --
is one line of arbitrary size, so the cap never triggers and the entire file
floods the prompt, which is precisely what the cap exists to prevent.

Reproduced on main:

    many short lines : returned 201 lines, total chars=1323   (cap=200)
    one long line    : returned   1 lines, total chars=400008 <-- unbounded

With the per-line cap:

    many short lines : 201 lines, 1323 chars (unchanged)
    one long line    :   1 lines,  536 chars
    short file       : ['hello', 'world']    (untouched)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jawwad-ali
jawwad-ali requested a review from mnriem as a code owner September 11, 2026 16:14
@mnriem mnriem added the triage-nice-to-have Verdict: evidence-backed fix or greenlit feature — land after review label Sep 12, 2026
@mnriem
mnriem requested a balanced review from Copilot September 17, 2026 13:50

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.

🟢 Approval recommended

The focused fix correctly addresses the prompt-flooding regression with appropriate test coverage.

Pull request overview

Bounds gate show_file output by truncating oversized lines while preserving ordinary content.

Changes:

  • Adds a 500-character per-line cap with a truncation notice.
  • Adds regression and unchanged-content tests.
File summaries
File Description
src/specify_cli/workflows/steps/gate/__init__.py Implements per-line truncation.
tests/test_workflows.py Tests long-line truncation and short-line preservation.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@mnriem mnriem left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please resolve conflicts

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-nice-to-have Verdict: evidence-backed fix or greenlit feature — land after review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants