Skip to content

Remove waves refresh logs#2292

Merged
simo6529 merged 2 commits intomainfrom
remove-waves-refresh-logs
Apr 20, 2026
Merged

Remove waves refresh logs#2292
simo6529 merged 2 commits intomainfrom
remove-waves-refresh-logs

Conversation

@simo6529
Copy link
Copy Markdown
Collaborator

@simo6529 simo6529 commented Apr 17, 2026

Summary by CodeRabbit

  • Refactor
    • Removed debug logging infrastructure to reduce console output noise
    • Simplified WebSocket error handling, stream synchronization, and browser resume logic
    • Enhanced error resilience by preventing individual subscriber callback failures from blocking subsequent subscribers

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

📝 Walkthrough

Walkthrough

This PR removes debug logging infrastructure from the WebSocket module system. It deletes the webSocketDebug.ts module entirely and removes all logWebSocketDebug calls from WebSocket providers, context, hooks, and their tests. Error handling is simplified to suppress console output while maintaining identical control flow and behavioral logic.

Changes

Cohort / File(s) Summary
Debug Module Removal
services/websocket/webSocketDebug.ts
Entire module deleted that previously exported logWebSocketDebug function for development-only console warnings.
WebSocket Provider & Health
services/websocket/WebSocketProvider.tsx, services/websocket/useWebSocketHealth.ts
Removed debug logging and refactored error/reconnection handling. WebSocketProvider message parsing now uses guarded try/catch, silently swallows subscriber callback errors, and refactored reconnection to accept a connectSocket function. useWebSocketHealth collapsed parameterized health checks into single performHealthCheck() callback with simplified source-based behavior.
Stream Context & Tests
contexts/wave/MyStreamContext.tsx, __tests__/contexts/wave/MyStreamContext.resume.test.tsx
Removed logWebSocketDebug imports and all sync/resume/connect debug logging. Simplified helper hooks by removing source parameters; syncActiveWaveAndRefetch and runBrowserResumeSync now accept no arguments and always perform the same behavior.
Hooks
hooks/useWaveIsTyping.ts, hooks/useWaveWebSocket.ts
Removed debug logging and simplified import statements. useWaveIsTyping now silently returns on JSON parse errors; useWaveWebSocket error handler removed logging and immediately closes the socket on errors.
Test Suite
__tests__/services/websocket/WebSocketProvider.test.tsx
Removed all console.error/console.warn spy assertions for malformed messages, subscriber failures, reconnect exhaustion, constructor errors, and WebSocket error events. Provider state validation via result.current.status retained.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • refactor: modernize wave typing hook with shared websocket #1515: Modifies the same WebSocket hooks (useWaveIsTyping, useWaveWebSocket) with refactoring of message handling and error logic alongside this PR's logging removal.
  • Update on tab change #2235: Directly modifies the same WebSocket modules (WebSocketProvider, useWebSocketHealth, MyStreamContext) with concurrent changes to debug logging and handler logic.
  • wip #1525: Changes the same WebSocket-related hook and provider test files, requiring coordination with this PR's test assertion removals.

Suggested reviewers

  • ragnep

Poem

🐰 Hop, hop! The debug logs take flight,
No more console whispers in the night,
WebSocket streams run clean and lean,
Silent yet sturdy—best we've seen! ✨
A rabbit's work is never quite done,
But cleaner logs? That's tons of fun!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main objective: removing debug logging related to waves refresh across multiple files and modules.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch remove-waves-refresh-logs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

@simo6529
Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
services/websocket/useWebSocketHealth.ts (1)

74-104: Nit: reuse the tokenChanged variable instead of recomputing on line 99.

currentToken !== previousToken on line 99 is exactly the tokenChanged value already computed on line 76. Reusing it makes the third branch's intent clearer and avoids drift if the comparison is ever extended (e.g., to consider whitespace or length).

♻️ Proposed tidy-up
     } else if (
       currentToken &&
       currentStatus !== WebSocketStatus.DISCONNECTED &&
-      currentToken !== previousToken
+      tokenChanged
     ) {
       currentConnect(currentToken);
       action = "connect";
       reason = "token-changed";
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@services/websocket/useWebSocketHealth.ts` around lines 74 - 104, Replace the
direct comparison currentToken !== previousToken in the third conditional with
the already-computed tokenChanged variable to avoid duplicate logic; update the
condition that now reads (currentToken && currentStatus !==
WebSocketStatus.DISCONNECTED && currentToken !== previousToken) to use
tokenChanged (i.e., tokenChanged instead of currentToken !== previousToken) so
the branch uses the single source of truth and preserves the existing calls to
currentConnect(currentToken) and the action/reason assignments.
__tests__/services/websocket/WebSocketProvider.test.tsx (1)

349-379: Optional: strengthen this test to verify subscriber isolation, not just "doesn't throw".

With the console.error assertion gone, this test now only proves the faulty callback was invoked. The real behavioral guarantee of the new for..of + per-subscriber try/catch in handleMessage is that a subsequent subscriber on the same message type still fires even if an earlier one throws. Adding a second subscriber would make that guarantee regression-proof:

🧪 Proposed test enhancement
       const faultyCallback = jest.fn(() => {
         throw new Error("Callback error");
       });
+      const healthyCallback = jest.fn();

       act(() => {
         result.current.subscribe(WsMessageType.DROP_UPDATE, faultyCallback);
+        result.current.subscribe(WsMessageType.DROP_UPDATE, healthyCallback);
       });

       act(() => {
         ws.triggerMessage({ type: WsMessageType.DROP_UPDATE, data: { id: 1 } });
       });

       expect(faultyCallback).toHaveBeenCalledWith({ id: 1 });
+      expect(healthyCallback).toHaveBeenCalledWith({ id: 1 });

Same spirit applies to "handles malformed messages gracefully" — asserting that a subscribed callback was not invoked would meaningfully verify the parse-failure early return.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@__tests__/services/websocket/WebSocketProvider.test.tsx` around lines 349 -
379, The test currently only asserts the faulty subscriber was called; update
"handles subscriber callback errors gracefully" to also register a second
subscriber (e.g., a jest.fn named successCallback) for the same WsMessageType
after subscribing faultyCallback, trigger the message via
MockWebSocket.triggerMessage, and assert both that faultyCallback was called and
that successCallback was also called with the same payload to verify subscriber
isolation in handleMessage; similarly, for the "handles malformed messages
gracefully" test, add a subscribed callback and assert it was NOT called after
sending a malformed message so the early-return on parse failure is enforced.
services/websocket/WebSocketProvider.tsx (1)

130-136: Consider preserving observability when swallowing subscriber errors.

Removing the console.error here is consistent with the PR goal, but it now leaves production subscriber bugs completely invisible — no breadcrumb, no counter, no sampling. If there is an existing error-reporting/telemetry sink (Sentry, a logger service, etc.), forwarding the caught error through it (even at debug/info level) would retain diagnostic value without re-introducing the noisy console.error the PR is trying to remove. Same consideration applies to the silent parse failure at line 114 and the non-string guard.

Not a blocker — flagging as an observability trade-off to weigh against the logging cleanup.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@services/websocket/WebSocketProvider.tsx` around lines 130 - 136, The loop
over subscribers currently swallows exceptions from individual handlers (for
subscriber(message.data)) with no observability; modify the catch to forward the
caught error to the project's telemetry/logging facility (e.g., call the
existing error reporter or logger) with context about the failing subscriber and
message.data, so one subscriber failure doesn't block others but is recorded.
Also apply the same pattern to the earlier silent parse failure and the
non-string guard: when JSON.parse or the type check fails, log/forward the error
and contextual info (raw payload) to the telemetry sink at a low/noise level
rather than completely dropping it.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@__tests__/services/websocket/WebSocketProvider.test.tsx`:
- Around line 349-379: The test currently only asserts the faulty subscriber was
called; update "handles subscriber callback errors gracefully" to also register
a second subscriber (e.g., a jest.fn named successCallback) for the same
WsMessageType after subscribing faultyCallback, trigger the message via
MockWebSocket.triggerMessage, and assert both that faultyCallback was called and
that successCallback was also called with the same payload to verify subscriber
isolation in handleMessage; similarly, for the "handles malformed messages
gracefully" test, add a subscribed callback and assert it was NOT called after
sending a malformed message so the early-return on parse failure is enforced.

In `@services/websocket/useWebSocketHealth.ts`:
- Around line 74-104: Replace the direct comparison currentToken !==
previousToken in the third conditional with the already-computed tokenChanged
variable to avoid duplicate logic; update the condition that now reads
(currentToken && currentStatus !== WebSocketStatus.DISCONNECTED && currentToken
!== previousToken) to use tokenChanged (i.e., tokenChanged instead of
currentToken !== previousToken) so the branch uses the single source of truth
and preserves the existing calls to currentConnect(currentToken) and the
action/reason assignments.

In `@services/websocket/WebSocketProvider.tsx`:
- Around line 130-136: The loop over subscribers currently swallows exceptions
from individual handlers (for subscriber(message.data)) with no observability;
modify the catch to forward the caught error to the project's telemetry/logging
facility (e.g., call the existing error reporter or logger) with context about
the failing subscriber and message.data, so one subscriber failure doesn't block
others but is recorded. Also apply the same pattern to the earlier silent parse
failure and the non-string guard: when JSON.parse or the type check fails,
log/forward the error and contextual info (raw payload) to the telemetry sink at
a low/noise level rather than completely dropping it.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: be7c4823-e067-46f6-ae74-4d4ffa934b4c

📥 Commits

Reviewing files that changed from the base of the PR and between 7b94e57 and 5839fed.

📒 Files selected for processing (8)
  • __tests__/contexts/wave/MyStreamContext.resume.test.tsx
  • __tests__/services/websocket/WebSocketProvider.test.tsx
  • contexts/wave/MyStreamContext.tsx
  • hooks/useWaveIsTyping.ts
  • hooks/useWaveWebSocket.ts
  • services/websocket/WebSocketProvider.tsx
  • services/websocket/useWebSocketHealth.ts
  • services/websocket/webSocketDebug.ts
💤 Files with no reviewable changes (2)
  • tests/contexts/wave/MyStreamContext.resume.test.tsx
  • services/websocket/webSocketDebug.ts

@simo6529 simo6529 merged commit 2ec138b into main Apr 20, 2026
8 checks passed
@simo6529 simo6529 deleted the remove-waves-refresh-logs branch April 20, 2026 05:37
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