Skip to content

fix(QUA-577): recover partial typed input when agent finishes mid-typing#101

Closed
Desperado wants to merge 1 commit into
mainfrom
Desperado/qua-577-queue-fix
Closed

fix(QUA-577): recover partial typed input when agent finishes mid-typing#101
Desperado wants to merge 1 commit into
mainfrom
Desperado/qua-577-queue-fix

Conversation

@Desperado
Copy link
Copy Markdown
Contributor

Summary

Fixes QUA-577. The v1.13 "type while agent runs, auto-queue" feature was silently dropping the user's typed-but-not-yet-Enter-terminated input when the agent's response came back before they could press Enter.

Root cause (from e2e PTY probe)

  • StartQueueReader accumulates each typed character in an in-goroutine lineRunes buffer. On Enter the buffer is pushed onto the queue.
  • When stopQueueReader() fires (agent turn ended), the goroutine returns and lineRunes is garbage-collected — even if it contained a partial line the user was mid-typing.
  • Additionally, bytes that arrive between stopQueueReader() and the next tui.ReadInput() end up split across two prompts.

Reproduction (real keyboard, confirmed by @strazhnyk): submit a slow prompt, start typing a second one, and let the agent finish before you press Enter. Your typed text vanishes; the next prompt opens empty.

Fix

  • StartQueueReader now returns func() string. The goroutine sends its final lineRunes value through a buffered channel before exiting; the stop function returns it after wg.Wait.
  • repl.go reads the partial after the agent's turn finishes and, if non-empty after trim, pushes it onto the queue with a clear notice:
    ↩ partial input recovered → queued [N]: <text>  (type /queue clear to discard)
    
  • New /queue clear slash command (PromptQueue.Clear) lets the user discard recovered text if it was stray input.
  • Windows stub updated to match the new signature.

Verification

  • e2e PTY harness: pre-fix, the typed prefix was lost and never appeared in the queue. Post-fix, the partial is recovered, queued, and processed on the next iteration. Subsequent characters that arrived during the stopReader→ReadInput window are captured by the new queue reader and queued cleanly too.
  • go test ./... -short -count=1 is green.
  • New unit tests: TestPromptQueue_ClearReturnsCount, TestPromptQueue_ClearEmpty.

Test plan

  • Real-keyboard regression: open qmax-code, submit a slow prompt, type a few chars during thinking but don't press Enter. Confirm the agent's response is followed by ↩ partial input recovered → queued [1]: <your text>, then processing queued prompt.
  • Same flow but press Enter mid-thinking: confirm the existing ✓ queued [N]: path still works and Enter still cancels the running agent.
  • /queue clear discards queued items as expected.
  • No regression in go test ./....

🤖 Generated with Claude Code

If the agent's response races the user's typing (turn ends before the
user has pressed Enter), the typing-line buffer was silently dropped,
making the v1.13 "type while agent runs, auto-queue" feature appear
broken: the user sees `⌨  partial text` appear, agent response prints,
and the partial vanishes. Subsequent keystrokes that arrive between
stopQueueReader() and the next tui.ReadInput end up split across two
prompts, producing confusing "phantom" input.

The queue reader now exposes its in-flight line buffer via its stop
function. After the agent finishes, repl pushes any partial line onto
the queue with a clear "↩ partial input recovered" notice. Users can
discard it with the new `/queue clear` command if it was stray input.

The fix preserves the existing Enter-to-queue, Enter-cancels-agent,
and Ctrl+C-clears behaviour unchanged.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@qualitymaxapp
Copy link
Copy Markdown

qualitymaxapp Bot commented May 15, 2026

✅ QualityMax Pipeline

Gate Result
🔍 AI Review ✅ Clean
🧪 Repo Tests ✅ 287/287 passed (go)
🤖 AI Tests ✅ 28/32 passed

Powered by QualityMax — AI-Powered Test Automation

@Desperado
Copy link
Copy Markdown
Contributor Author

Included and merged via #103 (db91e5d). Closing this stale duplicate PR to avoid re-merging the same change.

@Desperado Desperado closed this May 15, 2026
@Desperado Desperado deleted the Desperado/qua-577-queue-fix branch May 15, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant