Skip to content

[Repo Assist] fix: null _gatewayClient after dispose in OnSettingsSaved - #121

Merged
shanselman merged 1 commit into
masterfrom
repo-assist/fix-settings-save-gateway-null-6bc718053d460466
Apr 1, 2026
Merged

shanselman merged 1 commit into
masterfrom
repo-assist/fix-settings-save-gateway-null-6bc718053d460466

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist.

Summary

When OnSettingsSaved switches from operator mode to node mode, _gatewayClient was disposed but not set to null. This left a dangling disposed reference that bypassed null guards in several callers:

  • ShowQuickSend — logs a warning and returns if _gatewayClient == null, but when it's non-null and disposed the guard doesn't fire
  • RunHealthCheckAsync — shows a "not connected" toast if _gatewayClient == null; without null, it calls into the disposed client
  • ToggleChannel — early-returns on null; without null, calls into the disposed client

The _nodeService field already used the correct pattern (null first, then dispose). This PR applies the same one-line fix to _gatewayClient.

Root cause

// Before (bug): disposed but still non-null
_gatewayClient?.Dispose();

// After (fix): null so guards work correctly
_gatewayClient?.Dispose();
_gatewayClient = null;

Fix rationale

The change is a single added line with no behaviour change on the gateway-mode path (where InitializeGatewayClient() reassigns the field anyway). The fix only matters on the node-mode path where InitializeNodeService() leaves _gatewayClient unreassigned.

Trade-offs

None — this is a defensive correctness fix with no observable downside.

Test Status

  • dotnet test tests/OpenClaw.Shared.Tests/ → 503 passed, 18 skipped
  • dotnet test tests/OpenClaw.Tray.Tests/ → 93 passed

Unit tests for App.xaml.cs are not feasible (WinUI startup coupling), but the fix is a single-line change to a simple field assignment.

Generated by Repo Assist · ◷

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@cbb46ab386962aa371045839fc9998ee4e97ca64

When OnSettingsSaved switches to node mode, _gatewayClient was
disposed but not set to null. This caused guards like
  if (_gatewayClient == null) return;
in ShowQuickSend, RunHealthCheckAsync, and ToggleChannel to pass
instead of short-circuiting, potentially calling into a disposed
object (ObjectDisposedException) or producing unexpected behaviour.

The _nodeService field already followed the correct pattern
(null first, then dispose). Apply the same pattern to _gatewayClient.

Co-authored-by: Copilot <[email protected]>
@shanselman
shanselman marked this pull request as ready for review April 1, 2026 06:38
@shanselman
shanselman merged commit b21ca94 into master Apr 1, 2026
@vincentkoc
vincentkoc deleted the repo-assist/fix-settings-save-gateway-null-6bc718053d460466 branch August 2, 2026 07:56
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.

1 participant