Fix: REPL Input Duplication In Amazon Q CLI

by Felix Dubois 44 views

Hey guys,

We've got a bit of a situation here with the Amazon Q Developer CLI, and I wanted to bring it to your attention. It seems like there's a bug that causes the REPL (Read-Eval-Print Loop) to duplicate input when you paste a large number of lines. Let's dive into the details and see what's going on. So, keep reading to fully understand this issue and learn more about the suggested solutions.

Checks

Before we get started, I want to assure you that I've done my due diligence:

  • [x] I've searched the github.com/aws/amazon-q-developer-cli/issues and didn't find any duplicates of my issue. It's always good to make sure we're not reporting something that's already being addressed.
  • [x] I've run q doctor in the affected terminal session to check for any underlying issues with my environment. Everything seems to be in order.
  • [x] I've also run q restart and replicated the issue again, just to be sure it wasn't a temporary glitch. Unfortunately, the problem persists.

Operating System

I'm running Amazon Linux 2, which might be a factor in this bug. It's always helpful to know the operating system when troubleshooting these kinds of issues.

Expected Behavior

Okay, so here's what I expected to happen:

STR (Steps to Reproduce):

  1. Paste input with a large number of lines into the REPL.
  2. Press Ctrl + J a few times to extend the input.

Observed Behavior

Instead of extending the input, here's what actually happened:

  • The screen flickers, which is a bit disconcerting.
  • More importantly, the terminal starts duplicating the input. It's like a copy-paste frenzy gone wild!
  • If you scroll up, you'll see that your Ctrl + V input has been duplicated multiple times. This makes it really difficult to work with the REPL.

Desired Behavior

Ideally, the input should not be duplicated when trying to extend it. We want a clean and predictable REPL experience, guys.

Suggestions

I've got a suggestion that might help, even if it doesn't completely solve the underlying bug. I recommend copying Claude Code's behavior, which is to add a placeholder like [Pasted 200 lines; Ctrl + R to review] rather than actually showing the output. The input could be stored in a buffer for later review. This approach might make the input more manageable for both users and developers/testers.

Example

To give you a clearer picture, here's an example of the kind of input that triggers the bug:

> I just performed a shaos test and I want you to anbalyse the results:

(3124) ➜  LocalAuroraSetup git:(mainline) ./chaos-test storm
πŸŒͺ️  Aurora MySQL Chaos Testing Suite
=====================================

πŸŒͺ️  Starting Chaos Storm Testing...
πŸ” Validating environment variables...
⚠️  WARNING: Some passwords are identical. Consider using different passwords for better security.
βœ… Environment validation passed!
πŸŒͺ️  CHAOS STORM TESTING SUITE πŸŒͺ️
==================================================
This creates MAXIMUM communication link failures
Rapid-fire failures every 2-5 seconds for 5 minutes
Even well-designed systems will struggle with this

⚠️  WARNING: This is EXTREME testing!
Your application WILL experience significant failures

πŸ“Š Starting enhanced monitoring...

πŸš€ Starting Chaos Storm...
Duration: 300 seconds
Failure interval: 2-5 seconds

Press Enter to unleash the chaos storm...
πŸ”₯ [21:11:38] Resource stress: mysql-replica4 (CPU + disk)
⏱️  [21:11:39] Failures injected: 1 | Time remaining: 300s
🌐 [21:11:43] Network isolation: mysql-replica2
a73d46a0fe46768d61bc877de2172c359e3e52f1f473e903407426a18cbe31bb
⏱️  [21:11:43] Failures injected: 2 | Time remaining: 295s
πŸ”₯ [21:11:45] Resource stress: mysql-replica1 (CPU + disk)
⏱️  [21:11:45] Failures injected: 3 | Time remaining: 293s
⏱️  [21:11:49] Failures injected: 3 | Time remaining: 289s
⏱️  [21:11:52] Failures injected: 3 | Time remaining: 286s
πŸŒͺ️  [21:11:57] SIMULTANEOUS FAILURE BURST!
πŸ›‘ [21:11:57] Container stop: mysql-replica1
mysql-replica1
πŸ’₯ [21:12:02] Connection exhaustion: mysql-primary -> 4 connections
πŸ’€ [21:12:02] PRIMARY DATABASE FAILURE
mysql-primary
πŸ›‘ [21:12:13] Container stop: mysql-replica1
mysql-replica1
⏱️  [21:12:13] Failures injected: 7 | Time remaining: 265s
πŸŒͺ️  [21:12:16] SIMULTANEOUS FAILURE BURST!
πŸ’₯πŸ’₯ [21:12:16] Multiple replica stop: 4 replicas
mysql-replica1
mysql-replica2
mysql-replica3
mysql-replica4
🌐 [21:12:27] Network isolation: mysql-replica4
b04a960cfb6b1ecbeb2de617733ddbacb6a7b2377dfb894c371f16cff658e668
πŸ”₯ [21:12:28] Resource stress: mysql-replica3 (CPU + disk)
πŸ’₯ [21:12:28] Connection exhaustion: mysql-replica4 -> 3 connections
⏱️  [21:12:28] Failures injected: 11 | Time remaining: 250s
🌐 [21:12:31] Network isolation: mysql-replica1
9dc9fa628ca75d730724302402b0ef7ec7ca6edb3d9a16de3cb4139fd1c95498
⏱️  [21:12:31] Failures injected: 12 | Time remaining: 247s
⏱️  [21:12:36] Failures injected: 12 | Time remaining: 242s
πŸ”„ [21:12:39] HAProxy restart (brief outage)
⏱️  [21:12:39] Failures injected: 13 | Time remaining: 239s
⏱️  [21:12:43] Failures injected: 13 | Time remaining: 235s
⏱️  [21:12:45] Failures injected: 13 | Time remaining: 233s
πŸ’₯ [21:12:48] Connection exhaustion: mysql-replica2 -> 2 connections
⏱️  [21:12:48] Failures injected: 14 | Time remaining: 230s
πŸ›‘ [21:12:52] Container stop: mysql-replica2
mysql-replica2
⏱️  [21:12:52] Failures injected: 15 | Time remaining: 226s
πŸ’₯ [21:12:54] Connection exhaustion: mysql-primary -> 5 connections
⏱️  [21:12:54] Failures injected: 16 | Time remaining: 224s
⏱️  [21:12:59] Failures injected: 16 | Time remaining: 219s
🌐 [21:13:03] Network isolation: mysql-replica3
8e9dd2ebbbd2cac688b4d4f172d02e97c93b076d3854342e1c39ea01c49314b8
⏱️  [21:13:03] Failures injected: 17 | Time remaining: 215s
⏱️  [21:13:06] Failures injected: 17 | Time remaining: 212s
πŸ›‘ [21:13:08] Container stop: mysql-replica2
mysql-replica2
⏱️  [21:13:08] Failures injected: 18 | Time remaining: 210s
πŸ›‘ [21:13:12] Container stop: mysql-replica1
mysql-replica1
⏱️  [21:13:12] Failures injected: 19 | Time remaining: 206s
πŸŒͺ️  [21:13:16] SIMULTANEOUS FAILURE BURST!
πŸ›‘ [21:13:16] Container stop: mysql-replica2
mysql-replica2
πŸ’₯πŸ’₯ [21:13:16] Multiple replica stop: 3 replicas
mysql-replica1
mysql-replica2
mysql-replica3
πŸ”„ [21:13:16] HAProxy restart (brief outage)
⏱️  [21:13:16] Failures injected: 23 | Time remaining: 202s
πŸ’€ [21:13:18] PRIMARY DATABASE FAILURE
mysql-primary
⏱️  [21:13:18] Failures injected: 24 | Time remaining: 200s
⏱️  [21:13:21] Failures injected: 24 | Time remaining: 197s
πŸ’€ [21:13:23] PRIMARY DATABASE FAILURE
mysql-primary
⏱️  [21:13:23] Failures injected: 25 | Time remaining: 195s
πŸŒͺ️  [21:13:27] SIMULTANEOUS FAILURE BURST!
πŸ›‘ [21:13:27] Container stop: mysql-replica1
mysql-replica1
⏱️  [21:13:27] Failures injected: 29 | Time remaining: 191s
πŸ”„ [21:13:29] HAProxy restart (brief outage)
⏱️  [21:13:29] Failures injected: 30 | Time remaining: 189s
⏱️  [21:13:31] Failures injected: 30 | Time remaining: 187s
⏱️  [21:13:35] Failures injected: 30 | Time remaining: 183s
⏱️  [21:13:39] Failures injected: 30 | Time remaining: 179s
⏱️  [21:13:41] Failures injected: 30 | Time remaining: 177s
πŸŒͺ️  [21:13:43] SIMULTANEOUS FAILURE BURST!
πŸ’₯ [21:13:43] Connection exhaustion: mysql-replica2 -> 2 connections
πŸ›‘ [21:13:43] Container stop: mysql-replica2
mysql-replica2
πŸ”„ [21:13:43] HAProxy restart (brief outage)
πŸ’₯ [21:13:43] Connection exhaustion: mysql-replica4 -> 3 connections
⏱️  [21:13:43] Failures injected: 34 | Time remaining: 175s
πŸ’₯ [21:13:47] Connection exhaustion: mysql-primary -> 2 connections
⏱️  [21:13:47] Failures injected: 35 | Time remaining: 171s
πŸ’₯ [21:13:49] Connection exhaustion: mysql-replica1 -> 1 connections
⏱️  [21:13:49] Failures injected: 36 | Time remaining: 169s
πŸ’₯ [21:13:51] Connection exhaustion: mysql-replica3 -> 5 connections
⏱️  [21:13:51] Failures injected: 37 | Time remaining: 167s
πŸ”₯ [21:13:55] Resource stress: mysql-replica2 (CPU + disk)
⏱️  [21:13:55] Failures injected: 38 | Time remaining: 163s
Error response from daemon: container bbe2a0cfcb43a3f1544dc480447bc2836c4cefd043024d4b0755ed08800a8b0e is not running
⏱️  [21:13:57] Failures injected: 38 | Time remaining: 161s
⏱️  [21:14:02] Failures injected: 38 | Time remaining: 156s
⏱️  [21:14:06] Failures injected: 38 | Time remaining: 152s
πŸ’₯ [21:14:11] Connection exhaustion: mysql-replica2 -> 2 connections
⏱️  [21:14:11] Failures injected: 39 | Time remaining: 147s
πŸŒͺ️  [21:14:16] SIMULTANEOUS FAILURE BURST!
πŸ’₯πŸ’₯ [21:14:16] Multiple replica stop: 4 replicas
mysql-replica1
mysql-replica2
mysql-replica3
mysql-replica4
πŸ’₯ [21:14:16] Connection exhaustion: mysql-replica1 -> 5 connections
πŸ’₯ [21:14:16] Connection exhaustion: mysql-replica3 -> 3 connections
⏱️  [21:14:16] Failures injected: 43 | Time remaining: 142s
πŸ’₯πŸ’₯ [21:14:19] Multiple replica stop: 4 replicas
mysql-replica1
mysql-replica2
mysql-replica3
mysql-replica4
⏱️  [21:14:19] Failures injected: 44 | Time remaining: 139s
πŸ’₯ [21:14:22] Connection exhaustion: mysql-replica3 -> 5 connections
⏱️  [21:14:22] Failures injected: 45 | Time remaining: 136s
πŸ’₯ [21:14:26] Connection exhaustion: mysql-replica4 -> 4 connections
⏱️  [21:14:26] Failures injected: 46 | Time remaining: 132s
⏱️  [21:14:28] Failures injected: 46 | Time remaining: 130s
πŸ’₯ [21:14:32] Connection exhaustion: mysql-replica4 -> 1 connections
⏱️  [21:14:32] Failures injected: 47 | Time remaining: 126s
πŸ’€ [21:14:34] PRIMARY DATABASE FAILURE
mysql-primary
⏱️  [21:14:34] Failures injected: 48 | Time remaining: 124s
⏱️  [21:14:37] Failures injected: 48 | Time remaining: 121s
⏱️  [21:14:41] Failures injected: 48 | Time remaining: 117s
⏱️  [21:14:46] Failures injected: 48 | Time remaining: 112s
πŸ’₯πŸ’₯ [21:14:49] Multiple replica stop: 4 replicas
mysql-replica1
mysql-replica2
mysql-replica3
mysql-replica4
⏱️  [21:14:49] Failures injected: 49 | Time remaining: 109s
πŸ”„ [21:14:51] HAProxy restart (brief outage)
⏱️  [21:14:51] Failures injected: 50 | Time remaining: 107s
⏱️  [21:14:55] Failures injected: 50 | Time remaining: 104s
πŸ›‘ [21:14:58] Container stop: mysql-replica2
mysql-replica2
⏱️  [21:14:58] Failures injected: 51 | Time remaining: 100s
⏱️  [21:15:00] Failures injected: 51 | Time remaining: 98s
πŸŒͺ️  [21:15:04] SIMULTANEOUS FAILURE BURST!
πŸ’₯ [21:15:04] Connection exhaustion: mysql-replica2 -> 5 connections
πŸ’€ [21:15:04] PRIMARY DATABASE FAILURE
mysql-primary
πŸ’₯ [21:15:04] Connection exhaustion: mysql-replica4 -> 4 connections
⏱️  [21:15:04] Failures injected: 55 | Time remaining: 94s
⏱️  [21:15:08] Failures injected: 55 | Time remaining: 90s
⏱️  [21:15:10] Failures injected: 55 | Time remaining: 88s
⏱️  [21:15:13] Failures injected: 55 | Time remaining: 85s
πŸ’€ [21:15:16] PRIMARY DATABASE FAILURE
mysql-primary
⏱️  [21:15:16] Failures injected: 56 | Time remaining: 82s
πŸ’₯ [21:15:20] Connection exhaustion: mysql-primary -> 4 connections
⏱️  [21:15:20] Failures injected: 57 | Time remaining: 78s
⏱️  [21:15:23] Failures injected: 57 | Time remaining: 75s
πŸ’₯ [21:15:25] Connection exhaustion: mysql-replica4 -> 1 connections
⏱️  [21:15:25] Failures injected: 58 | Time remaining: 73s
⏱️  [21:15:28] Failures injected: 58 | Time remaining: 70s
πŸ’₯ [21:15:32] Connection exhaustion: mysql-replica3 -> 1 connections
⏱️  [21:15:32] Failures injected: 59 | Time remaining: 66s
⏱️  [21:15:35] Failures injected: 59 | Time remaining: 63s
⏱️  [21:15:39] Failures injected: 59 | Time remaining: 59s
πŸ›‘ [21:15:42] Container stop: mysql-replica4
mysql-replica4
⏱️  [21:15:42] Failures injected: 60 | Time remaining: 56s
πŸ’€ [21:15:47] PRIMARY DATABASE FAILURE
mysql-primary
⏱️  [21:15:47] Failures injected: 61 | Time remaining: 51s
πŸ›‘ [21:15:50] Container stop: mysql-replica2
mysql-replica2
⏱️  [21:15:50] Failures injected: 62 | Time remaining: 48s
⏱️  [21:15:54] Failures injected: 62 | Time remaining: 44s
⏱️  [21:15:57] Failures injected: 62 | Time remaining: 41s
πŸ’€ [21:16:00] PRIMARY DATABASE FAILURE
mysql-primary
⏱️  [21:16:00] Failures injected: 63 | Time remaining: 38s
⏱️  [21:16:05] Failures injected: 63 | Time remaining: 33s
⏱️  [21:16:07] Failures injected: 63 | Time remaining: 31s
⏱️  [21:16:12] Failures injected: 63 | Time remaining: 26s
πŸŒͺ️  [21:16:14] SIMULTANEOUS FAILURE BURST!
πŸ’₯ [21:16:14] Connection exhaustion: mysql-replica3 -> 1 connections
πŸ”„ [21:16:14] HAProxy restart (brief outage)
πŸ’₯ [21:16:14] Connection exhaustion: mysql-replica3 -> 3 connections
⏱️  [21:16:14] Failures injected: 66 | Time remaining: 24s
πŸ’₯ [21:16:16] Connection exhaustion: mysql-primary -> 3 connections
⏱️  [21:16:16] Failures injected: 67 | Time remaining: 22s
⏱️  [21:16:20] Failures injected: 67 | Time remaining: 18s
πŸ’₯ [21:16:23] Connection exhaustion: mysql-primary -> 2 connections
⏱️  [21:16:23] Failures injected: 68 | Time remaining: 15s
πŸ’₯ [21:16:25] Connection exhaustion: mysql-primary -> 1 connections
⏱️  [21:16:25] Failures injected: 69 | Time remaining: 13s
⏱️  [21:16:27] Failures injected: 69 | Time remaining: 11s
⏱️  [21:16:30] Failures injected: 69 | Time remaining: 8s
⏱️  [21:16:35] Failures injected: 69 | Time remaining: 3s
πŸ’₯ [21:16:37] Connection exhaustion: mysql-primary -> 2 connections
⏱️  [21:16:37] Failures injected: 70 | Time remaining: 1s

⏰ Chaos storm duration complete!

πŸ›‘ Chaos storm complete!
Total failures injected: 70

Actual Behavior

As I mentioned earlier, the actual behavior is that the input gets duplicated in the terminal when you try to extend it. This makes it really hard to work with the REPL, especially when dealing with large inputs.

Steps to Reproduce

To reproduce the bug, just follow these steps:

  1. Paste the code snippet above (or any large chunk of text) into the REPL.
  2. Press Ctrl + J a few times to try and extend the input. You should see the duplication occur.

Environment

I'm not sure if this is relevant, but here's my environment configuration:


Conclusion

So, that's the bug in a nutshell. It's a bit annoying, but hopefully, we can find a solution or workaround soon. Let me know if you guys have any thoughts or suggestions! I hope that suggested solution of showing a placeholder and storing the input in a buffer can help solve this issue. This will definitely improve the user experience when working with large inputs in the REPL. We need reliable and efficient tools that can handle complex tasks without glitching. By addressing this bug, we can make the Amazon Q Developer CLI more user-friendly and productive for developers.

Also, let’s not forget the importance of thorough testing. Running chaos tests, as demonstrated in the example, is crucial for identifying potential weaknesses in our systems. It’s better to find these issues in a controlled environment than to have them surface in production. So, keep testing, keep reporting, and let’s make our tools better together!