Skip to content

fix: status buffer split and missing binding-site lines - #3027

Open
mondalaci wants to merge 3 commits into
masterfrom
fix/status-buffer-split-and-binding-lines
Open

fix: status buffer split and missing binding-site lines#3027
mondalaci wants to merge 3 commits into
masterfrom
fix/status-buffer-split-and-binding-lines

Conversation

@mondalaci

Copy link
Copy Markdown
Member

Summary

  • Drain the full status/shell buffer (up to 100 USB transfers) instead of stopping after ~1260 bytes, which left leftovers that later overwrote the UI
  • Only re-fetch the status buffer when the device newly becomes available (or when dirty), not on every connection-state field change
  • Preserve binding-site / nested location-stack lines in the status buffer error panel

Fixes #3025

Test plan

  • Run diagnose usb on UHK 60 with a long status buffer and confirm Agent shows the full message (not a short leftover fragment)
  • Trigger a macro validation error that includes a binding-site line and confirm that line stays visible in the error panel
  • Reconnect the keyboard and confirm the status buffer is still shown after subsequent connection-state updates (e.g. zephyr log flag changes)

Made with Cursor

Drain the full firmware status buffer instead of stopping after 20 USB
transfers, avoid re-reading on every connection-state flicker, and keep
binding-site lines in the error panel (#3025).

Co-authored-by: Cursor <cursoragent@cursor.com>
@mondalaci

Copy link
Copy Markdown
Member Author

@kareltucek This fix works for me. How about you?

@kareltucek

Copy link
Copy Markdown
Collaborator

Yes, seems to work fine.

@mondalaci
mondalaci requested a review from ert78gb August 4, 2026 11:40
// Only pull the status buffer when the device newly becomes available.
// Re-reading on every connection-state field change drains leftovers from
// a previous partial read (or an empty buffer) and overwrites the UI (#3025).
if (becameAvailable) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The getDeviceConnectionStateAsync is definitely overloaded. It worth to split and refactor but it bigger task.
But I am not sure we have to read the status buffer only connecting the right half to the computer.

@kareltucek Please validate my knowledge?

As far as I know the firmware could generate status buffer content when left half oscillating or modules are connecting or disconnecting to each half.
Maybe worth to extend the response of GetDeviceState (0x09) with a status buffer has content flag like isMacroStatusDirty. Or use the isMacroStatusDirty to indicate the status buffer has value.
If in introduce a status buffer flag indicator then we could delete the direct status buffer checks after the user configuration has been saved.

@kareltucek What do you think about it

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe worth to extend the response of GetDeviceState (0x09) with a status buffer has content flag like isMacroStatusDirty.

I believe the isMacroStatusDirty (GetDeviceState (0x09) byte 7) does exactly that.

I.e., changes to 1 whenever Agent has started reading the buffer but has not finished, and whenever a new content is added into the buffer.

But I am not sure we have to read the status buffer only connecting the right half to the computer.

We definitely have to read it whenever isMacroStatusDirty becomes true.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(I.e., this code is probably wrong and introduces a bug.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Later in this function the

if (state.isMacroStatusDirty) {
line handle the isMacroStatusDirty.

So this condition does not introduce bug. But based on what you wrote this condition does not need. Enough to check the isMacroStatusDirty byte.

thx

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe the isMacroStatusDirty (GetDeviceState (0x09) byte 7) does exactly that.

I deleted this code and I run the diagnose usb macro and the isMacroStatusDirty was false so we need to check the status buffer every time when the connection changing.

I reverted the becameAvailable the iteration read was that fixed the original bug.
I left the name of isMacroStatusDirty as is. because looks like it set the value only when macro invalid.

@kareltucek If you will have time please test again. I tested but double check is better :)


const url = `#/macro/${macro.id}?actionIndex=${macroActionIndex}&lineNr=${lineNr}&columnNr=${columnNr}&inlineEdit=true`;
const newLine2 = `${escapeHtml(line1Result[1])}<a href="${url}">${escapeHtml(line1Result[2])}</a>`;
// Keep binding-site lines and nested location-stack lines (firmware may emit more than 3).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As a future plan would be nice to write some test for these usecases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Status buffer issues

3 participants