crewai - ✅(Solved) Fix [BUG] generate_tool_specs.py writes CRLF on Windows, causing spurious diffs [5 pull requests, 4 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
crewAIInc/crewAI#4737Fetched 2026-04-08 00:40:30
View on GitHub
Comments
4
Participants
4
Timeline
34
Reactions
0
Timeline (top)
cross-referenced ×16referenced ×14commented ×3labeled ×1

Running generate_tool_specs.py on Windows regenerates tool.specs.json with \r\n line endings instead of \n, causing every line to appear modified in git diff. Python's open() in text mode uses OS-native line endings. On Windows this means CRLF, while the committed file uses LF.

Root Cause

Running generate_tool_specs.py on Windows regenerates tool.specs.json with \r\n line endings instead of \n, causing every line to appear modified in git diff. Python's open() in text mode uses OS-native line endings. On Windows this means CRLF, while the committed file uses LF.

Fix Action

Fixed

PR fix notes

PR #4738: fix: generating tool specs on windows with correct line endings

Description (problem / solution / changelog)

resolves https://github.com/crewAIInc/crewAI/issues/4737

<!-- CURSOR_SUMMARY -->

[!NOTE] Low Risk Low risk: only changes file-writing newline behavior when generating JSON specs, with no runtime logic or schema changes.

Overview Ensures generate_tool_specs.py writes tool.specs.json with consistent LF line endings by opening the output file with newline="\n", preventing Windows from emitting CRLF in generated specs.

<sup>Written by Cursor Bugbot for commit ca48d68071da986e44925568aeb3854f61ac8899. This will update automatically on new commits. Configure here.</sup>

<!-- /CURSOR_SUMMARY -->

Changed files

  • lib/crewai-tools/src/crewai_tools/generate_tool_specs.py (modified, +1/-1)

PR #4739: fix: use LF line endings in generate_tool_specs save_to_json

Description (problem / solution / changelog)

Summary

Fixes #4737. generate_tool_specs.py's save_to_json uses open() in text mode, which on Windows writes \r\n (CRLF) line endings. Since the committed tool.specs.json uses \n (LF), running the script on Windows causes every line to appear modified in git diff.

The fix adds newline="\n" to the open() call, forcing LF output on all platforms. A regression test reads the output file in binary mode and asserts no CRLF bytes are present.

Review & Testing Checklist for Human

  • Verify the newline="\n" parameter on the open() call is the correct approach (vs. e.g., binary mode or .gitattributes)
  • Note: the new test validates LF-only output, but on Linux it would pass even without the fix since Linux already defaults to LF. To fully validate, run on Windows or inspect the open() docs to confirm the parameter's behavior.

Notes

<!-- CURSOR_SUMMARY -->

[!NOTE] Low Risk Low risk: only changes file-writing newline behavior and adds a targeted regression test; no runtime logic or schema generation behavior changes beyond consistent output formatting.

Overview Ensures ToolSpecExtractor.save_to_json always writes JSON with LF line endings by passing newline="\n" to open(), preventing Windows from producing CRLF and causing noisy diffs in committed tool.specs.json.

Adds a regression test that writes an output file and inspects raw bytes to assert \r\n is absent and at least one \n is present.

<sup>Written by Cursor Bugbot for commit 11be6989535592fa7b47ab57ed9e3fa31d74040f. This will update automatically on new commits. Configure here.</sup>

<!-- /CURSOR_SUMMARY -->

Changed files

  • lib/crewai-tools/src/crewai_tools/generate_tool_specs.py (modified, +1/-1)
  • lib/crewai-tools/tests/test_generate_tool_specs.py (modified, +25/-0)

PR #4741: fix(tools): preserve LF when generating tool.specs.json on Windows

Description (problem / solution / changelog)

Summary

Fixes CRLF churn in tool.specs.json when running generate_tool_specs.py on Windows.

What changed

  • Updated ToolSpecExtractor.save_to_json to open files with newline="\n".
  • Added a unit test to assert the file is opened with LF newline policy.

Why

Issue #4737 reports that Windows text-mode writes produce \r\n, causing noisy full-file diffs even when content is unchanged. For this generated artifact we want deterministic LF output across platforms.

Notes on validation

  • This environment does not have full project test dependencies (crewai and vcr plugins), so full pytest execution wasn’t possible here.
  • Change is localized and low-risk (single write path + assertion test).

Closes #4737

<!-- CURSOR_SUMMARY -->

[!NOTE] Low Risk Low risk: only changes file-opening parameters for a generated JSON artifact and adds a targeted test; output content/structure is unchanged.

Overview Ensures generated tool.specs.json is stable on Windows by opening the output file with newline="\n" in ToolSpecExtractor.save_to_json, preventing CRLF churn.

Adds a unit test that mocks open() to assert the LF newline policy is applied when writing the specs file.

<sup>Written by Cursor Bugbot for commit 2b7855f1ce60efdb2bc94482bd0b620a03f5418d. This will update automatically on new commits. Configure here.</sup>

<!-- /CURSOR_SUMMARY -->

Changed files

  • lib/crewai-tools/src/crewai_tools/generate_tool_specs.py (modified, +2/-1)
  • lib/crewai-tools/tests/test_generate_tool_specs.py (modified, +10/-0)

PR #4743: fix: CRLF line endings, JSON fence fallback, corrupted JSON handling

Description (problem / solution / changelog)

Summary

  • CRLF in tool.specs.json (#4737): generate_tool_specs.py opens output file without newline="", causing \r\n on Windows. Added newline="" to open() call.

  • Pydantic validation error with markdown-wrapped JSON (#4509): When a function-calling LLM returns JSON wrapped in markdown fences (```json ... ```), model_validate_json() fails. Added fallback to handle_partial_json() which extracts JSON from markdown fences via regex.

  • Corrupted JSON in lancedb_storage: _row_to_record() calls json.loads() on categories_str / metadata_str without error handling. If stored data is malformed, the entire recall/search operation crashes. Added _safe_json_loads() helper that returns default value on parse failure.

Test plan

  • All 13 converter tests pass (1 pre-existing unrelated failure in test_get_conversion_instructions_non_gpt)
  • Verify tool.specs.json uses LF line endings on Windows after regeneration
  • Verify converter handles ```json {"key": "value"} ``` response from LLM
  • Verify _row_to_record gracefully handles malformed JSON in categories/metadata columns

🤖 Generated with claude-flow

<!-- CURSOR_SUMMARY -->

[!NOTE] Medium Risk Moderate risk because it changes how LLM outputs and stored memory metadata are parsed, which could mask bad data or alter error behavior in core conversion/recall paths.

Overview Fixes Windows CRLF in generated tool.specs.json by forcing LF newlines when writing from generate_tool_specs.py.

Improves resilience to malformed/markdown-wrapped JSON: Converter.to_pydantic() now falls back to handle_partial_json() (and re-validates dict/string outputs) when model_validate_json() fails even under function-calling, and LanceDBStorage._row_to_record() now uses a _safe_json_loads() helper to tolerate corrupted categories_str/metadata_str without crashing recall/search.

<sup>Written by Cursor Bugbot for commit 8e420e0d331af5db8423e0a3ee3ccc24524ca9a9. This will update automatically on new commits. Configure here.</sup>

<!-- /CURSOR_SUMMARY -->

Changed files

  • lib/crewai-tools/src/crewai_tools/generate_tool_specs.py (modified, +1/-1)
  • lib/crewai/src/crewai/memory/storage/lancedb_storage.py (modified, +12/-2)
  • lib/crewai/src/crewai/utilities/converter.py (modified, +19/-1)

PR #4753: fix: Use LF line endings in generate_tool_specs.py on Windows (fixes #4737)

Description (problem / solution / changelog)

Problem

Running generate_tool_specs.py on Windows regenerates tool.specs.json with \r\n line endings instead of \n, causing every line to appear modified in git diff.

Solution

Add newline="\n" to the open() call to ensure consistent LF line endings across all platforms.

Changes

  • lib/crewai-tools/src/crewai_tools/generate_tool_specs.py: Add newline="\n" parameter

Testing

  • The change is minimal and only affects line ending behavior
  • On Windows, this now produces LF endings matching the committed file
  • On Unix/Linux/macOS, this is a no-op (already uses LF)

Fixes #4737

<!-- CURSOR_SUMMARY -->

[!NOTE] Low Risk Low risk: only changes file-writing newline behavior to avoid Windows CRLF diffs; no schema/content generation logic is modified.

Overview Ensures generate_tool_specs.py writes tool.specs.json using LF line endings on all platforms by opening the output file with newline="\n".

This prevents Windows runs from regenerating the JSON with CRLF and causing full-file diffs, without changing the generated JSON structure/content.

<sup>Written by Cursor Bugbot for commit 465f746c093265191b35d56a216f50ce32f4f6aa. This will update automatically on new commits. Configure here.</sup>

<!-- /CURSOR_SUMMARY -->

Changed files

  • lib/crewai-tools/src/crewai_tools/generate_tool_specs.py (modified, +2/-1)

Code Example

with open(output_path, "w", encoding="utf-8", newline="\n") as f:
    json.dump({"tools": self.tools_spec}, f, indent=2, sort_keys=True)
RAW_BUFFERClick to expand / collapse

Description

Running generate_tool_specs.py on Windows regenerates tool.specs.json with \r\n line endings instead of \n, causing every line to appear modified in git diff. Python's open() in text mode uses OS-native line endings. On Windows this means CRLF, while the committed file uses LF.

Steps to Reproduce

python generate_tool_specs.py

Expected behavior

Minimal diff

Operating System

Windows 11

Python Version

3.13.1

crewAI Version

1.10.1

crewAI Tools Version

1.10.1

Virtual Environment

Venv

Possible Solution

One solution is to pass newline="\n" to open() in save_to_json:

with open(output_path, "w", encoding="utf-8", newline="\n") as f:
    json.dump({"tools": self.tools_spec}, f, indent=2, sort_keys=True)

extent analysis

Fix Plan

To resolve the issue of \r\n line endings in tool.specs.json, modify the save_to_json method in generate_tool_specs.py as follows:

  • Open the file in write mode with newline="\n" to enforce Unix-style line endings.
  • Example code:
with open(output_path, "w", encoding="utf-8", newline="\n") as f:
    json.dump({"tools": self.tools_spec}, f, indent=2, sort_keys=True)
  • Steps:
    1. Locate the save_to_json method in generate_tool_specs.py.
    2. Update the open() function call to include newline="\n".
    3. Save the changes to generate_tool_specs.py.

Verification

  • Run generate_tool_specs.py again.
  • Check the tool.specs.json file for line endings using a text editor or git diff.
  • Verify that the line endings are now \n instead of \r\n.

Extra Tips

  • When working with files in Python, consider using the newline parameter with open() to ensure consistent line endings across platforms.
  • Use git config --global core.autocrlf false to prevent Git from automatically converting line endings on Windows.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Minimal diff

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

crewai - ✅(Solved) Fix [BUG] generate_tool_specs.py writes CRLF on Windows, causing spurious diffs [5 pull requests, 4 comments, 4 participants]