[GH-ISSUE #161] FilesystemBackend.edit returns success with occurrences = -1 when both file content and oldString are empty #41

Closed
opened 2026-02-16 06:16:57 -05:00 by yindo · 1 comment
Owner

Originally created by @sunsunmonkey on GitHub (Feb 1, 2026).
Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/161

Originally assigned to: @christian-bromann on GitHub.

When the target file is empty (content is empty) and oldString is an empty string (""), FilesystemBackend.edit returns a successful result with occurrences = -1. Expected behavior is to return an error (e.g., “oldString cannot be empty”) instead of a success response.

Steps to Reproduce

  1. Create an empty file (0 bytes).

  2. Run the following script with oldString = "".
    Image

  3. Actual Result
    Image

Maybe Expected Result

Return an error indicating oldString cannot be empty (or otherwise reject empty-string replacements).

Notes / Suspected Cause

performStringReplacement uses content.split(oldString) to count occurrences. When both content and oldString are empty, this yields an invalid occurrences = -1 and a success response.

Originally created by @sunsunmonkey on GitHub (Feb 1, 2026). Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/161 Originally assigned to: @christian-bromann on GitHub. When the target file is empty (content is empty) and oldString is an empty string (""), FilesystemBackend.edit returns a successful result with occurrences = -1. Expected behavior is to return an error (e.g., “oldString cannot be empty”) instead of a success response. ## Steps to Reproduce 1. Create an empty file (0 bytes). 2. Run the following script with oldString = "". <img width="800" height="1119" alt="Image" src="https://github.com/user-attachments/assets/34b644a9-4fff-4627-baa6-71777be82057" /> 3. Actual Result <img width="800" height="1143" alt="Image" src="https://github.com/user-attachments/assets/436d4847-155b-4107-b3ea-e992f1c82ad9" /> ## Maybe Expected Result Return an error indicating oldString cannot be empty (or otherwise reject empty-string replacements). ## Notes / Suspected Cause performStringReplacement uses content.split(oldString) to count occurrences. When both content and oldString are empty, this yields an invalid occurrences = -1 and a success response.
yindo closed this issue 2026-02-16 06:16:57 -05:00
Author
Owner

@christian-bromann commented on GitHub (Feb 2, 2026):

Thanks for raising the issue. I have pushed a PR with a fix.

@christian-bromann commented on GitHub (Feb 2, 2026): Thanks for raising the issue. I have pushed a PR with a fix.
yindo changed title from FilesystemBackend.edit returns success with occurrences = -1 when both file content and oldString are empty to [GH-ISSUE #161] FilesystemBackend.edit returns success with occurrences = -1 when both file content and oldString are empty 2026-06-05 17:21:08 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#41