Skip to content

Synchronize speech input store before immediate send#1427

Closed
sena-labs wants to merge 2 commits intoagent0ai:developmentfrom
sena-labs:fix/1391-speech-input-sync-race
Closed

Synchronize speech input store before immediate send#1427
sena-labs wants to merge 2 commits intoagent0ai:developmentfrom
sena-labs:fix/1391-speech-input-sync-race

Conversation

@sena-labs
Copy link
Copy Markdown
Contributor

Summary:

  • keep the Alpine-backed input store synchronized as soon as updateChatInput() appends speech-to-text content
  • add a regression test that locks the ordering between store sync, resize/input dispatch, and the speech send flow

Root cause:

  • speech-to-text updated the textarea DOM value and then immediately sent the message, but the Alpine store could lag behind the DOM update, allowing sendMessage() to read stale input

Testing:

  • docker exec agent-zero-live /opt/venv-a0/bin/python -m pytest /a0/tests/test_speech_input_race_regression.py -q1 passed in 0.36s

Copilot AI review requested due to automatic review settings April 3, 2026 13:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a race where speech-to-text updates the chat textarea DOM value and immediately sends, while sendMessage() reads from the Alpine inputStore that may not yet reflect the DOM update.

Changes:

  • Update updateChatInput() to synchronously write the computed value into inputStore.message before resizing/dispatching an input event.
  • Add a regression test that asserts the ordering between store sync and subsequent resize/input dispatch, and validates the STT flow calls updateChatInput() before sendMessage().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
webui/index.js Synchronizes Alpine inputStore.message immediately after setting the textarea value to prevent stale reads during immediate send.
tests/test_speech_input_race_regression.py Adds a regression test that locks in the ordering to prevent reintroducing the race.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +18 to +21
next_value_marker = "const nextValue = currentValue + (needsSpace ? \" \" : \"\") + text + \" \";"
sync_marker = "inputStore.message = nextValue;"
adjust_marker = "adjustTextareaHeight();"
dispatch_marker = 'chatInputEl.dispatchEvent(new Event("input"));'
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regression test is extremely brittle because it asserts an exact, fully-formatted JS line for nextValue_marker (including quote style and spacing). That can cause unrelated refactors/formatting (e.g., Prettier changes, switching to template strings) to fail CI without changing behavior. Consider loosening the marker matching (e.g., regex for const nextValue assignment) while still using positional checks to enforce the ordering constraints.

Copilot uses AI. Check for mistakes.
Comment thread tests/test_speech_input_race_regression.py Outdated
@sena-labs
Copy link
Copy Markdown
Contributor Author

Addressed the Copilot review feedback in e231aa0: the regression test now extracts updateChatInput() via brace matching and uses semantic markers/order checks instead of depending on the next function name or an exact fully formatted nextValue line.

@sena-labs sena-labs closed this by deleting the head repository Apr 6, 2026
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.

2 participants