Skip to content

fix: fix selecting services on Deployment Logs tab#2181

Closed
jzsfkzm wants to merge 1 commit intoakash-network:mainfrom
jzsfkzm:bugfixes/2105-multiple-services-logs
Closed

fix: fix selecting services on Deployment Logs tab#2181
jzsfkzm wants to merge 1 commit intoakash-network:mainfrom
jzsfkzm:bugfixes/2105-multiple-services-logs

Conversation

@jzsfkzm
Copy link
Contributor

@jzsfkzm jzsfkzm commented Nov 10, 2025

closes #2105

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of deployment log streaming with enhanced connection state management.
    • Optimized service switching behavior to properly reset and reconnect log streams when changing selections.

@jzsfkzm jzsfkzm requested a review from a team as a code owner November 10, 2025 16:08
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 10, 2025

Walkthrough

The DeploymentLogs component's websocket connection and loading state management has been refactored to prevent runtime exceptions and stuck loading indicators when services are deselected. Changes include introducing an isConnecting state, adding connection guards, properly resetting state on service changes, and improving effect dependencies for more robust state transitions.

Changes

Cohort / File(s) Summary
WebSocket Connection State Management
apps/deploy-web/src/components/deployments/DeploymentLogs.tsx
Added isConnecting state tracking; extended websocket hook usage to obtain getWebSocket; implemented guards for connection initiation requiring selected services and non-connecting state; set isConnecting to false on message receipt; improved effect dependencies to include isConnecting and sendJsonMessage.
Service Selection Cleanup
apps/deploy-web/src/components/deployments/DeploymentLogs.tsx
On service changes, stop loading indicator, reset connection state flags, and close existing websocket via getWebSocket?.close(); use services.length for dependency tracking instead of optional chaining.
State Initialization
apps/deploy-web/src/components/deployments/DeploymentLogs.tsx
Changed isLoadingLogs initial state from true to false; added empty message filtering during log processing.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Component as DeploymentLogs
    participant WebSocket as WebSocket Connection
    
    User->>Component: Select services
    Component->>Component: Check guards (services selected, not connecting)
    Component->>Component: Set isConnecting = true
    Component->>WebSocket: Initiate connection
    WebSocket-->>Component: Log message received
    Component->>Component: Set isConnecting = false
    Component->>Component: Append logs
    
    User->>Component: Deselect all services
    Component->>Component: Set isLoadingLogs = false
    Component->>Component: Reset isConnectionEstablished = false
    Component->>Component: Reset isConnecting = false
    Component->>WebSocket: Close connection
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Single file with localized, consistent pattern of state management improvements
  • Changes follow a clear logical progression (new state variable, guard conditions, dependency updates, cleanup)
  • Main review focus: verify effect dependencies are exhaustive and cleanup logic properly resets all related state

Poem

🐰 A websocket fix, so swift and clean,
No more loading bars stuck in between,
When services depart, the state's now wise,
Connection closes—goodbye, surprise!
State and cleanup dance hand in paw,
No runtime errors, just smooth data flow!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: fix selecting services on Deployment Logs tab' directly addresses the main issue: fixing service selection behavior on the Deployment Logs tab, which aligns with the changeset focusing on websocket connection state management and service selection handling.
Linked Issues check ✅ Passed The changes comprehensively address issue #2105 by implementing proper connection state management (isConnecting), preventing errors on service deselection, stopping the loading indicator, and closing websocket connections when services are unselected.
Out of Scope Changes check ✅ Passed All changes in DeploymentLogs.tsx are directly related to fixing the service selection bug and websocket connection state management, with no extraneous or unrelated modifications present.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@jzsfkzm jzsfkzm force-pushed the bugfixes/2105-multiple-services-logs branch from 0729304 to 7d9ded9 Compare November 10, 2025 16:09
Copy link
Contributor

@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.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/deploy-web/src/components/deployments/DeploymentLogs.tsx (1)

41-41: Define proper TypeScript types instead of any.

The use of any type for logs.current (line 41) and parsedLog (line 184) violates the coding guideline that states: "Never use type any or cast to type any. Always define the proper TypeScript types."

As per coding guidelines.

Define proper interfaces for the log structure:

interface LogEntry {
  service: string;
  message: string;
  name?: string;
  type?: string;
  reason?: string;
  object?: {
    name?: string;
    kind?: string;
  };
  note?: string;
}

Then update the declarations:

-  // TODO Type
-  const logs = useRef<any[]>([]);
+  const logs = useRef<LogEntry[]>([]);
-    // TODO Type
-    let parsedLog: any = null;
+    let parsedLog: LogEntry | null = null;

Also applies to: 184-184

🧹 Nitpick comments (1)
apps/deploy-web/src/components/deployments/DeploymentLogs.tsx (1)

80-85: Avoid casting to any for Monaco editor events.

The type assertion to any (line 82) violates the coding guideline. Consider using a type guard or properly typing the Monaco editor event structure.

As per coding guidelines.

Replace the type assertion with a type guard:

      editor.onDidScrollChange(event => {
-       // TODO Verify
-       if (event.scrollTop < (event as any)._oldScrollTop) {
+       const eventWithOldScroll = event as { scrollTop: number; _oldScrollTop?: number };
+       if (eventWithOldScroll._oldScrollTop !== undefined && event.scrollTop < eventWithOldScroll._oldScrollTop) {
          setStickToBottom(false);
        }
      });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 825b24a and 7d9ded9.

📒 Files selected for processing (1)
  • apps/deploy-web/src/components/deployments/DeploymentLogs.tsx (5 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/deploy-web/src/components/deployments/DeploymentLogs.tsx
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/deploy-web/src/components/deployments/DeploymentLogs.tsx
🧠 Learnings (1)
📓 Common learnings
Learnt from: jzsfkzm
Repo: akash-network/console PR: 1994
File: apps/deploy-web/src/hooks/useListSelection/useListSelection.spec.ts:58-64
Timestamp: 2025-10-17T10:04:00.940Z
Learning: In the Akash Console deployment list multi-select feature (PR #1994, apps/deploy-web/src/hooks/useListSelection), the requirement is for additive Shift+click behavior: subsequent Shift+clicks should expand/add to the existing selection rather than replacing the previous Shift range. This differs from canonical Gmail/Finder-style replacement behavior.
🧬 Code graph analysis (1)
apps/deploy-web/src/components/deployments/DeploymentLogs.tsx (1)
apps/deploy-web/src/hooks/useProviderWebsocket.ts (2)
  • useProviderWebsocket (18-67)
  • sendJsonMessage (47-65)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test-build
🔇 Additional comments (6)
apps/deploy-web/src/components/deployments/DeploymentLogs.tsx (6)

36-37: LGTM! State initialization supports the fix.

The initial false values for both isLoadingLogs and isConnecting properly reflect the initial state before any websocket connection is established, preventing the stuck loading indicator issue.


63-63: LGTM! Proper websocket cleanup capability.

Extracting getWebSocket enables manual connection closure when services change, which is essential for the fix.


124-136: LGTM! Guards prevent the runtime exception.

The guard at line 130 (selectedServices.length === 0) directly fixes issue #2105 by preventing websocket connection attempts when no services are selected. The isConnecting check at line 131 also prevents concurrent connection attempts.


157-168: Verify dependency completeness.

The effect uses providerInfo (line 126) but doesn't include it in the dependency array. While providerInfo is derived from selectedLease (which is included), it also depends on providers from a query hook. This could cause stale closures if provider data changes without the lease changing.

Consider adding providerInfo to the dependency array:

  }, [
    providerCredentials,
    selectedLogsMode,
    selectedLease,
    selectedServices,
    services.length,
    updateLogText,
    canSetConnection,
    isConnectionEstablished,
    isConnecting,
-   sendJsonMessage
+   sendJsonMessage,
+   providerInfo
  ]);

170-175: LGTM! Proper connection state and empty message handling.

Setting isConnecting to false when the first message arrives correctly transitions the connection state. The empty message guard prevents unnecessary processing and state updates.


230-239: LGTM! Proper state and resource cleanup.

The handler correctly stops the loading indicator (line 234), resets connection states (lines 235-236), and closes the websocket (line 238). This ensures the loading bar doesn't get stuck when services are changed or unselected.

Note: There's a potential race if onLogReceived fires during cleanup and sets isConnectionEstablished(true) at line 203 after the reset. This is minor since the connection is being closed, but consider whether onLogReceived should check if the connection is still active.

@codecov
Copy link

codecov bot commented Nov 10, 2025

Codecov Report

❌ Patch coverage is 0% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.39%. Comparing base (825b24a) to head (7d9ded9).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...-web/src/components/deployments/DeploymentLogs.tsx 0.00% 24 Missing ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2181      +/-   ##
==========================================
- Coverage   46.75%   46.39%   -0.37%     
==========================================
  Files        1021     1011      -10     
  Lines       28999    28665     -334     
  Branches     7521     7477      -44     
==========================================
- Hits        13559    13299     -260     
+ Misses      15069    14998      -71     
+ Partials      371      368       -3     
Flag Coverage Δ *Carryforward flag
api 81.82% <ø> (ø) Carriedforward from 825b24a
deploy-web 25.23% <0.00%> (-0.01%) ⬇️
log-collector ?
notifications 87.94% <ø> (ø) Carriedforward from 825b24a
provider-console 81.48% <ø> (ø) Carriedforward from 825b24a
provider-proxy 85.28% <ø> (ø) Carriedforward from 825b24a

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...-web/src/components/deployments/DeploymentLogs.tsx 0.00% <0.00%> (ø)

... and 12 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@stalniy
Copy link
Contributor

stalniy commented Nov 11, 2025

@jzsfkzm unfortunately we will need to close this one because I refactored this logic in #2177 . There is no more a hook to work with websocket, this logic has been moved to service layer.

Could you please double check whether the same is reproducible in the new version?

@stalniy stalniy closed this Nov 11, 2025
@jzsfkzm
Copy link
Contributor Author

jzsfkzm commented Nov 16, 2025

@jzsfkzm unfortunately we will need to close this one because I refactored this logic in #2177 . There is no more a hook to work with websocket, this logic has been moved to service layer.

Could you please double check whether the same is reproducible in the new version?

@stalniy I just checked it and now it works as expected:

  • Unselecting one service loads logs for the other service only.
  • Unselecting all/each and every service won't end up in an infinite progress indicator.

There's however one JS error in the logs when you open the select due to a prop deprecated in MUI5, I just created a PR for that:
#2228

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.

Unselecting service in logs causes runtime exception

2 participants

Comments