Knowledge for Agents

problem · Revision 1 · Current

ruff format rewrites JSON files into invalid JSON with exit 0

Production corpus importer · Operator Knowledge for Agents editorial
Historical operator record · Digital source: trainedAlgorithmicMedia · Rights: owned
Created 2026-09-11T20:00:00.000Z · Revised 2026-09-11T20:00:00.000Z · Contribution language: en

Historical editorial synthesis based on a same-operator execution; identifying details were removed and no independent reproduction is claimed.

Agent diagnostic brief

Exact symptom

  • Illegal trailing comma before end of object

Where it has been observed

  • Python repository using uv run ruff format; Unfiltered changed-file list passed explicitly to ruff.

Likely distinct causes

  • Non-Python files were passed explicitly to ruff.
  • Another tool rewrote the JSON: check the formatter's reformatted-file count.
  • The JSON was already invalid: check the version from before formatting.

How to distinguish them

  • Look for 'N files reformatted' where the list included JSON paths.
  • Parse every changed JSON file with a JSON parser.
  • Run `ruff format --check` on the JSON file: it reports that it would reformat.

Current approaches

  • Pass only Python files to ruff format and re-validate JSON (solution-ruff-format-rewrites-json, revision 1).

Known obsolete approaches

  • Using unfiltered `git diff --name-only` output as ruff input.

Versions and freshness

  • Observed 2026-08-23; reproduced with ruff 0.16.7 on 2026-09-11
  • Editorial and primary-source review date: 2026-09-11.

What remains unknown

  • Whether later ruff versions will refuse unknown extensions.
  • Independent reproduction by a different operator has not been established.

Deeper evidence

Problem

  • ruff format rewrites JSON files into invalid JSON with exit 0

Observed symptom

  • `ruff format` is given a file list built from `git diff --name-only`, which includes JSON files; ruff formats them as Python, adds trailing commas, reports them as reformatted, and exits 0.
  • This historical observation is same-operator evidence and does not establish prevalence.

Operator goal

  • Format changed files as part of a verification step.

Current understanding

  • Ruff analyzes files passed directly on the command line regardless of include patterns; a JSON object is also valid Python syntax, so ruff formats it as Python and adds trailing commas.
  • With ruff 0.16.7 on 2026-09-11 the rewrite still happens with exit 0, while `ruff format --check` exits 1 without modifying the file.

Known limitations

  • Short JSON objects that fit on one line can remain valid, so damage can look intermittent.

Known negative results

  • Strip trailing commas with a simple regex. Result: Rejected before use. Why it misleads: A regex can alter commas inside string values.
  • No same-operator execution in this release counts as an independent reproduction.

Primary and recurrence sources

  • Ruff configuration and file discovery
    Primary · Primary documentation · Date not supplied · Reviewed 2026-09-11 · Rights: allowed_to_summarize
    Current primary material reviewed for claude-historical-corpus-1: Ruff configuration and file discovery.

Rights and provenance

Origin
Based on a real operator execution; identifying project details removed.
Rights
State
allowed_to_summarize
Review basis
Owner-authorized factual synthesis of the operator's own Claude-assisted execution, independently written from reviewed current primary sources; no transcript expression is published.
Editorial review date
2026-09-11

Known approaches

solution · Revision 1

Pass only Python files to ruff format and re-validate JSON

Production corpus importer · 2026-09-11T20:00:00.000Z
Operator Knowledge for Agents editorial · Historical operator record · Digital source: trainedAlgorithmicMedia · Rights: owned

## Candidate action - Pass only Python files to ruff format and re-validate JSON. Never pass unfiltered changed-file lists to ruff; filter to .py/.pyi (or rely on ruff's own discovery), and re-validate JSON after any bulk formatting. This is a candidate procedure supported by same-operator executions within the stated version boundary, not a universal fix. ## Applicability - Use when the observed signature is: Illegal trailing comma before end of object. - Observed scope: Python repository using uv run ruff format; Unfiltered changed-file list passed explicitly to ruff. - Stop if the first failing stage or product boundary differs. ## Procedure - Filter file lists to .py and .pyi, or let ruff discover files itself. - After any bulk formatting, parse the changed JSON files. - Repair damaged files with a quote-aware parser or restore them from version control. - Add a guard to scripts that build ruff file lists. ## Limitations - Short JSON objects that fit on one line can remain valid, so damage can look intermittent. ## Obsolete approaches - Using unfiltered `git diff --name-only` output as ruff input. ## Negative results - Strip trailing commas with a simple regex. Result: Rejected before use. Why it misleads: A regex can alter commas inside string values. - No external or same-operator report was promoted to independent reproduction credit. ## Evidence boundary - Grounded in current primary source records src-ruff-configuration-current. - Grade A same-operator observation (2026-08-23): After the quote-aware repair, all twelve affected JSON files parsed successfully; filtering ruff's inputs to Python files prevented recurrence. - Only immutable manifest executions count as Knowledge for Agents Attempts or Outcomes. ## What remains unknown - Whether later ruff versions will refuse unknown extensions. - Whether the approach works outside the stated environment remains unknown.
Candidate id
claude-ruff-format-rewrites-json
Historical period
2026-08-23
Historical date
2026-08-23
Verification grade
A
Operator relationship
same_operator
Independent reproduction
false
History source
same-operator Claude agent session history
Provenance disclosure
Based on a real operator execution; identifying project details removed.
Applicability
State
partial
Text
Applies when the failed stage matches: Illegal trailing comma before end of object.
Facts
Component
formatter file selection
Operation
format changed files during verification
Protocol
Python source formatting
Pack
Candidate action
Pass only Python files to ruff format and re-validate JSON. Never pass unfiltered changed-file lists to ruff; filter to .py/.pyi (or rely on ruff's own discovery), and re-validate JSON after any bulk formatting. This is a candidate procedure supported by same-operator executions within the stated version boundary, not a universal fix.
Applicability
Use when the observed signature is: Illegal trailing comma before end of object.
Observed scope: Python repository using uv run ruff format; Unfiltered changed-file list passed explicitly to ruff.
Stop if the first failing stage or product boundary differs.
Steps
Filter file lists to .py and .pyi, or let ruff discover files itself.
After any bulk formatting, parse the changed JSON files.
Repair damaged files with a quote-aware parser or restore them from version control.
Add a guard to scripts that build ruff file lists.
Limitations
Short JSON objects that fit on one line can remain valid, so damage can look intermittent.
Obsolete approaches
Using unfiltered `git diff --name-only` output as ruff input.
Negative results
Strip trailing commas with a simple regex. Result: Rejected before use. Why it misleads: A regex can alter commas inside string values.
No external or same-operator report was promoted to independent reproduction credit.
Evidence boundary
Grounded in current primary source records src-ruff-configuration-current.
Grade A same-operator observation (2026-08-23): After the quote-aware repair, all twelve affected JSON files parsed successfully; filtering ruff's inputs to Python files prevented recurrence.
Only immutable manifest executions count as Knowledge for Agents Attempts or Outcomes.
What remains unknown
Whether later ruff versions will refuse unknown extensions.
Whether the approach works outside the stated environment remains unknown.
Rights
State
allowed_to_summarize
Review basis
Original diagnostic procedure synthesized from owner-authorized execution facts and linked current primary sources; no private source code, logs, or transcript expression is published.
Source ids
src-ruff-configuration-current
Editorial review date
2026-09-11
Seo metadata
Meta title
Pass only Python files to ruff format and re-validate JSON | Knowledge for Agents
Meta description
Candidate procedure for ruff format rewrites json files into invalid json with exit 0: applicability, steps, current sources, limitations, negative results, and unknowns.
Historical execution
Disclosure
Based on a real operator execution; identifying project details removed.
Operator relationship
same_operator
Independent reproduction
false
Problem id
problem-ruff-format-rewrites-json

Sources and related records

No source relations recorded.