nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] user prompt submits twice in new-ui redesign

Open akramcodez opened this issue 3 months ago • 5 comments

Description

When submitting a message in the TUI, the prompt is duplicated and sent twice upon the first submission. Note: This issue only exists in our feature/new-ui branch because we are actively redesigning Nanocoder's UI and handling inputs more responsively in this branch. Please ensure any fixes are targeted strictly at feature/new-ui and not main.

Environment

  • OS: Ubuntu (WSL)
  • Node version: v22.20.0
  • Nanocoder version: (latest feature/new-ui branch)
  • Provider: Any
  • Model: Any

Steps to Reproduce

  1. Switch to the feature/new-ui branch and start the application (pnpm run start).
  2. Type a message into the chat input box (e.g., "hi").
  3. Press Enter to submit.

Expected Behavior

The prompt should appear once in the chat queue, and the application should send a single API request to the LLM.

Actual Behavior

The user's input bubble is printed twice into the chat history, and the system attempts to process the prompt concurrently due to rapid duplicate keystroke events bypassing the React isBusy lock.

Logs/Screenshots

Image

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder

akramcodez avatar Sep 01 '26 06:09 akramcodez

Hi i was working on that issue and have implemented a fix. i will open a PR shortly

Forzun avatar Sep 02 '26 20:09 Forzun

Dug into this, found the exact mechanism by driving real keystrokes against UserInput with ink-testing-library.

Root cause: handleSubmit (source/components/user-input.tsx:444-517) closes over currentState from its own render. resetInput() only clears the composer on the next render, so a second Enter landing before that commit still sees the old text and resubmits it.

Timed sweep of the gap between two Enters: [sync/1ms/5ms] onSubmit calls = ["msg", "msg"] [16ms] onSubmit calls = ["msg"]

Below ~16ms it double-fires. Also happens while busy, a double Enter queues the same message twice. No dedupe exists downstream either.

Fix: add a submittingRef latch set before onSubmit and cleared only once state confirms the reset, and read the input via a ref instead of the closed-over render state.

Happy to open a PR if useful.

addyCooks avatar Sep 12 '26 06:09 addyCooks

  • https://github.com/Nano-Collective/nanocoder/issues/1174
  • https://github.com/Nano-Collective/nanocoder/issues/1167

Duplicates it seems, do we have a github action to auto de-dupe?

coralsundy avatar Sep 17 '26 01:09 coralsundy

Correcting my earlier comment: @coralsundy is right about #1174, but #1167 is a different bug.

#1111 looks like the same bug as #1174. One Enter is enough. While the model hasn't streamed a token yet, the submitted prompt renders live (recallableSubmittedDraft, interactive-app.tsx:186). When the first chunk arrives it moves into <Static>, and in inline mode Ink prints it again into scrollback. It's one request, but the prompt shows twice. #1164 changes exactly this split, not submission.

The double-Enter race I described is real but needs two Enters within ~16ms, so it isn't the cause here. Happy to file it separately.

#1167 is unrelated: it's caused by terminal resize and traces to Ink's line-erase miscount (ink#907).

Also: feature/new-ui is now merged into main (#1261), and #1164 (base feature/new-ui) and #1182 (base main) both change the same code. It's probably worth picking one and closing this as a duplicate of #1174.

addyCooks avatar Sep 17 '26 05:09 addyCooks

Fixed by #1182, which stopped the prompt being rendered twice when it moves into scrollback.

Closing as part of a backlog tidy-up. Reopen it if anything here is still broken.

will-lamerton avatar Oct 07 '26 10:10 will-lamerton