Synchronize speech input store before immediate send#1427
Synchronize speech input store before immediate send#1427sena-labs wants to merge 2 commits intoagent0ai:developmentfrom
Conversation
There was a problem hiding this comment.
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 intoinputStore.messagebefore 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()beforesendMessage().
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.
| next_value_marker = "const nextValue = currentValue + (needsSpace ? \" \" : \"\") + text + \" \";" | ||
| sync_marker = "inputStore.message = nextValue;" | ||
| adjust_marker = "adjustTextareaHeight();" | ||
| dispatch_marker = 'chatInputEl.dispatchEvent(new Event("input"));' |
There was a problem hiding this comment.
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.
|
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. |
Summary:
updateChatInput()appends speech-to-text contentRoot cause:
sendMessage()to read stale inputTesting:
docker exec agent-zero-live /opt/venv-a0/bin/python -m pytest /a0/tests/test_speech_input_race_regression.py -q→1 passed in 0.36s