-
Notifications
You must be signed in to change notification settings - Fork 546
Fix duplicate connection verification logs: add debounce and state-ch… #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix duplicate connection verification logs: add debounce and state-ch… #413
Conversation
…ange-only logging
WalkthroughAdds debounce to the editor window refresh and introduces a concurrency guard plus explicit health-state tracking in the connection UI to avoid overlapping verifications and redundant health-status logs. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)MCPForUnity/Editor/Windows/Components/Connection/McpConnectionSection.cs (2)
🔇 Additional comments (3)
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. Comment |
There was a problem hiding this 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
🧹 Nitpick comments (4)
MCPForUnity/Editor/Windows/Components/Connection/McpConnectionSection.cs (3)
47-48: New verification state fields are appropriate; enums could further tighten status handling
verificationTaskandlastHealthStatuscleanly capture “one in‑flight verification” and “last logged health state” without changing the public API. Consider, optionally, using an enum (or constants) instead of raw strings for states like"Disconnected","Healthy","Ping Failed", and"Unhealthy"to avoid future typos and make refactors safer.
412-422: Concurrency guard on verification effectively debounces overlapping checksThe guard on
verificationTaskprevents overlapping calls toVerifyBridgeConnectionInternalAsync, which should materially reduce log spam from rapid triggers. Note that callers that hit the early‑return path won’t wait on the in‑flight verification; they simply no‑op. If you ever need later callers to observe the result of the already‑running verification, you could instead await the existing task:public async Task VerifyBridgeConnectionAsync() { if (verificationTask != null && !verificationTask.IsCompleted) { await verificationTask; return; } verificationTask = VerifyBridgeConnectionInternalAsync(); await verificationTask; }Right now, the current behavior aligns well with the “debounce repeated checks” goal.
427-441: Health-state logging de‑dupe looks good; align comments and status stringsThe use of
lastHealthStatusto gate logging in all branches (success, ping‑failed, unhealthy, not‑running) nicely eliminates duplicate messages when repeated verifications yield the same state.A couple of small follow‑ups you may want to address:
- The comments
// Always log warnings/errorsno longer match behavior, since warnings and errors now log only on state change. Consider updating them to something like “Log once per distinct warning/error state” or removing them.- When the bridge is not running, this method sets
healthStatusLabel.text = "Disconnected"whileUpdateConnectionStatus()uses"Unknown"for the disconnected case. BecauseUpdateConnectionStatus()runs every editor update, the"Disconnected"text will be very transient. For consistency in the UI copy (and to makelastHealthStatusvalues more self‑evident), it might be worth standardizing on a single string for the “not running” state.- Minor nit: removing then immediately re‑adding
"unknown"tohealthIndicatoris redundant; you can safely drop theRemoveFromClassList("unknown")call here.None of these affect correctness, but they’ll keep behavior and comments in sync with the new log‑deduping semantics.
Also applies to: 450-489
MCPForUnity/Editor/Windows/MCPForUnityEditorWindow.cs (1)
24-25: RefreshAllData debounce is simple and effective; confirm the 0.5s window matches UX expectationsUsing
EditorApplication.timeSinceStartupwithlastRefreshTimeto short‑circuitRefreshAllDatacalls withinRefreshDebounceSecondsshould eliminate the rapid double‑refresh fromCreateGUIandOnFocuswithout adding complexity. The only behavioral change to be aware of is that very quick re‑focuses (<0.5s) won’t trigger a refresh, which seems like a reasonable trade‑off.If you later find this too aggressive or too lax, you could promote
RefreshDebounceSecondsto a more discoverable constant (or setting), but the current hard‑coded value is fine for now.Also applies to: 186-193
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
MCPForUnity/Editor/Windows/Components/Connection/McpConnectionSection.cs(3 hunks)MCPForUnity/Editor/Windows/MCPForUnityEditorWindow.cs(2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-10-13T13:27:23.040Z
Learnt from: msanatan
Repo: CoplayDev/unity-mcp PR: 316
File: TestProjects/UnityMCPTests/Assets/Tests/EditMode/Resources.meta:1-8
Timestamp: 2025-10-13T13:27:23.040Z
Learning: UnityMcpBridge is a legacy project kept for backwards compatibility; MCPForUnity is the only active Unity plugin project. GUID collisions between UnityMcpBridge and MCPForUnity are acceptable.
Applied to files:
MCPForUnity/Editor/Windows/Components/Connection/McpConnectionSection.csMCPForUnity/Editor/Windows/MCPForUnityEditorWindow.cs
📚 Learning: 2025-09-04T01:01:11.927Z
Learnt from: dsarno
Repo: CoplayDev/unity-mcp PR: 260
File: UnityMcpBridge/UnityMcpServer~/src/server_version.txt:1-1
Timestamp: 2025-09-04T01:01:11.927Z
Learning: The UnityMcpBridge project is not maintaining changelogs yet, so don't suggest adding changelog entries for version bumps.
Applied to files:
MCPForUnity/Editor/Windows/MCPForUnityEditorWindow.cs
🧬 Code graph analysis (1)
MCPForUnity/Editor/Windows/Components/Connection/McpConnectionSection.cs (1)
MCPForUnity/Editor/Helpers/McpLog.cs (4)
McpLog(7-52)Warn(43-46)Debug(31-35)Error(48-51)
…ve redundant code
|
Small cleanup of previous PR to reduce duplicate logs from toggline window (when debug logs is on) |
…ange-only logging
Summary by CodeRabbit
Bug Fixes
Performance
✏️ Tip: You can customize this high-level summary in your review settings.