DEV Community

orca forge
orca forge

Posted on Originally published at forge.workstyle.tech

How to Find Missing Usage Records Across 4 WebSocket Paths

📝 Originally published (in Japanese) at forge.workstyle.tech.

TL;DR Usage messages were sent, but records were missing across 3 surfaces for about 2 months. Only 1 of the 4 WebSocket paths handled the message. The other 3 either returned "Unknown message type" or silently discarded it.

The Conclusion First

Usage messages from speech recognition were not recorded in three areas because three of the four WebSockets had no receive handling. Two returned “Unknown message type,” while the other silently discarded the messages. I consolidated the receive handling into one place, called it from all four WebSockets, and confirmed that removing any path causes the tests to fail.

Why the Usage Messages Were Not Recorded

The audio relay server sent a usage message over WebSocket after each speech recognition request. Looking only at the sender, it appeared that the reports were being sent.

But only one of the four WebSockets had a receiver. The other three did not process the messages. Each endpoint—the entry point for its connection—handled them differently.

Two returned “Unknown message type.” The third returned nothing and discarded the message.

That difference changed how the problem appeared. On the paths that returned “Unknown message type,” it was clear that an unrecognized type had arrived. On the path that silently discarded the message, there was almost no immediate clue that anything was wrong. In the UI, all that appeared was a single line in the browser console.

Having code that sends a message does not mean every endpoint can handle its type. When adding a message type, fixing only the sender does not verify the entire path.

How I Verified the Four Inbound Paths

Usage messages were being sent, but they went unrecorded across three surfaces for about two months. A path that returns “Unknown message type” makes it clear that it received an unrecognized type. But when a path silently discards a message, the difference is harder to spot in the logs. In this case, all that appeared on screen was a single line in the browser console.

I realized I needed to check all four inbound handlers, not just the sending logic. Endpoints with similar roles don’t necessarily accept the same message types. In this case, I found that only one of the four had a handler for the message.

What Can We Test by Consolidating Receive Handling?

The fix consolidated receive handling in one place and made all four WebSockets call it.

We also verified that the test fails when we remove, one at a time, each of the three endpoints that previously had no receive handling. This means the test now checks that all three connections are covered.

It’s important to verify these two things separately: that the receive logic lives in one place, and that every endpoint can reach it. The test will also catch it if a call is missing from any of those three endpoints.

We haven’t confirmed whether usage was recorded during real conversations after the fix. We also don’t know how much usage went unrecorded. What we have confirmed is that receive handling was consolidated and is called by all four WebSockets, and that the test fails when we remove each of the three endpoints that previously had no receive handling.

Key takeaways

  • Check that the sender emits the usage message.
  • Verify that all 4 WebSocket paths handle that message.
  • Distinguish paths that return "Unknown message type" from those that discard the message without a response.
  • Centralize the receive handling and call it from all 4 paths.
  • Remove each of the 3 previously unhandled endpoints in turn and confirm the test fails.

Top comments (0)