aws / aws/amazon-q-developer-cli

fs_write str_replace command frequently fails with tool cancellation

Open
#2,492 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2k
Forks
439
PR merge metrics
No merged PRs in 30d

Description

### Checks

- [x] I have searched [github.com/aws/amazon-q-developer-cli/issues](https://github.com/aws/amazon-q-developer-cli/issues?q=) and there are no duplicates of my issue
- [x] I have run `q doctor` in the affected terminal session
- [x] I have run `q restart` and replicated the issue again

### Operating system

Linux 5.15.0-91-generic - Linux Mint 21.3

### Expected behaviour

The fs_write tool with str_replace command should successfully replace text blocks, especially multi-line YAML content with proper indentation and special characters (quotes, colons, etc.)

### Actual behaviour

The fs_write tool frequently gets cancelled during execution when attempting str_replace operations on:
1. Multi-line YAML blocks with complex indentation
2. Text containing quotes and special YAML characters
3. Large text blocks requiring whitespace-sensitive matching
4. GitHub Actions workflow files with input definitions

This results in "Tool use was cancelled by the user" errors even when the replacement appears valid.

```
[chat-transcript]

## 🔍 Phase 1: Fix main-deployment.yml YAML Structure

First, let me fix the corrupted YAML structure in the workflow inputs:
[Tool uses: fs_read]

I can see the problem clearly now. Let me fix the corrupted inputs section:
[Tool uses: fs_write]

Amazon Q is having trouble responding right now:
0: failed to print tool, `fs_write`: No such file or directory (os error 2)

Location:
/codebuild/output/src3298519376/src/crates/q_chat/src/lib.rs:1019

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

> Its seems that your fs_write tool has issues under some use cases. Lets document what those use cases are, submit feedback to AWS to fix them, and then try a different approach. I'm asking for this because you've had many failures of that tool so far today, and also recently in the past.

You're absolutely right! I've had multiple failures with the `fs_write` tool today, particularly with the `str_replace` command. Let me document the problematic use cases and report this issue, then use a different approach.

## 🐛 Documenting fs_write Tool Issues

Based on today's failures, here are the problematic use cases I've encountered:

### **Issue Pattern 1: Multi-line YAML replacements**
- **Problem**: When trying to replace multi-line YAML blocks with `str_replace`
- **Failure**: Tool gets cancelled, especially with complex indentation
- **Example**: Replacing workflow input sections with proper YAML structure

### **Issue Pattern 2: Large text blocks with special characters**
- **Problem**: Replacements involving quotes, colons, and YAML syntax
- **Failure**: Tool cancellation during execution
- **Example**: YAML workflow definitions with descriptions containing quotes

### **Issue Pattern 3: Whitespace-sensitive replacements**
- **Problem**: YAML requires exact whitespace matching, but tool struggles with this
- **Failure**: Either cancellation or incorrect matching
- **Example**: Indented YAML blocks in GitHub Actions workflows
[Tool uses: report_issue]

(...truncated)
```

### Steps to reproduce

1. Attempt to use fs_write with str_replace on multi-line YAML content
2. Include text with quotes, colons, and indentation in old_str/new_str parameters
3. Try to replace GitHub Actions workflow input sections
4. Tool gets cancelled during execution

This has occurred multiple times during a single chat session when trying to fix corrupted YAML workflow files.

### Environment

```yaml
[q-details]
version = "1.9.1"
hash = "5d2c2807cab9bc6c9dc5fcd05f92c7a979e8a4f7"
date = "2025-04-29T06:25:24.357798Z (98d ago)"
variant = "full"

[system-info]
chip = "AMD Ryzen 7 4700U with Radeon Graphics"
total-cores = 8
memory = "15.04 GB"

[system-info.os.linux]
kernel_version = "5.15.0-91-generic"
id = "linuxmint"
name = "Linux Mint"
pretty_name = "Linux Mint 21.3"
version_id = "21.3"
version = "21.3 (Virginia)"

[environment]
cwd = "/home/USER"
cli-path = "/home/USER"
os = "Linux"
shell-path = "/usr/bin/bash"
shell-version = "5.1.16"
terminal = "Xfce Terminal"
install-method = "unknown"

[env-vars]
DISPLAY = ":0.0"
GTK_IM_MODULE = "ibus"
PATH = "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/USER/.nvm/versions/node/v20.4.0/bin:/home/USER/.local/bin:/home/USER/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
QT_IM_MODULE = "ibus"
SHELL = "/bin/bash"
TERM = "xterm-256color"
XDG_CURRENT_DESKTOP = "XFCE"
XDG_SESSION_DESKTOP = "xfce"
XDG_SESSION_TYPE = "x11"
XMODIFIERS = "@im=ibus"

[chat-settings]
interactive=true

[chat-trusted_tools]
execute_bash=true
fs_write=true

[chat-failed_request_ids]
none

[chat-context]
current_profile=default
profiles=
default

global_context=
.amazonq/rules/**/*.md
README.md
AmazonQ.md

profile_context=none

files=none
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.