Skip to content

Commit 74604ae

Browse files
bkudiessCopilotCopilotshanselman
authored
Fix connection snapshot truth (#918)
* Fix connection snapshot truth Make GatewayConnectionManager snapshots the lifecycle source of truth for connection surfaces. Capture node intent/blockers before startup can silently skip, make MCP startup failures visible, and keep legacy status consumers derived from manager state while preserving operator-live behavior. Co-authored-by: Copilot App <[email protected]> * Block node snapshot when connector throws Publish a blocked node snapshot if node connector startup throws before status events can transition the manager. Add a focused regression test for the throwing connector path. Co-authored-by: Copilot App <[email protected]> * Expose blocked node truth through MCP Publish blocked node snapshots when previous node connector retirement fails. Include manager-owned overall/node fields in MCP app.status and app.menu so MCP clients can see degraded or blocked node truth instead of only legacy connected status. Co-authored-by: Copilot App <[email protected]> --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Copilot App <[email protected]> Co-authored-by: Scott Hanselman <[email protected]>
1 parent f89a88a commit 74604ae

33 files changed

Lines changed: 1913 additions & 181 deletions

‎docs/CONNECTION_ARCHITECTURE.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ Idle → Connecting → Connected
118118
| Connected | Error/Rejected | Degraded |
119119
| Connected | PairingRequired | PairingRequired |
120120
| Connected | Connecting | Connecting |
121-
| Connected | Disabled/Off | Connected |
121+
| Connected | Idle while Node mode is intended | Degraded |
122+
| Connected | Disabled/Off | Ready |
123+
124+
`GatewayConnectionSnapshot.NodeConnectionIntended` records the Node mode intent used by the manager's state machine. If Node mode is enabled but node startup is skipped, blocked, or missing a node credential, the manager publishes a blocked node snapshot (`NodeState=Error`, `NodeError=...`) instead of leaving the node idle and letting tray surfaces report a healthy connection.
122125

123126
## Gateway registry and persistence
124127

‎docs/MCP_MODE.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ Settings UI exposes both toggles in the Advanced section, with the live MCP endp
111111

112112
A legacy `McpOnlyMode` field is migrated automatically on load and never re-written.
113113

114+
MCP startup is reported from the actual listener state. `NodeService.McpStartupError` is populated when capability registration or the HTTP listener fails, and MCP-only startup is not treated as successful unless the loopback MCP server is running. Tray, Permissions, and Command Center surfaces show local MCP-only separately from gateway connectivity so a working local MCP listener is never presented as a gateway connection.
115+
114116
## Why this matters
115117

116118
### Testing

‎src/OpenClaw.Connection/ConnectionStateMachine.cs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,16 @@ public void SetNodeEnabled(bool enabled)
123123
{
124124
_nodeEnabled = enabled;
125125
if (!enabled)
126+
{
126127
_nodeState = RoleConnectionState.Disabled;
128+
_nodeError = null;
129+
_nodeCredentialSource = null;
130+
}
127131
else if (_nodeState == RoleConnectionState.Disabled)
132+
{
128133
_nodeState = RoleConnectionState.Idle;
134+
_nodeError = null;
135+
}
129136
RebuildSnapshot();
130137
}
131138

@@ -199,6 +206,15 @@ internal void SetNodeCredentialSource(string? source)
199206
RebuildSnapshot();
200207
}
201208

209+
internal void BlockNodeStart(string detail)
210+
{
211+
_nodeEnabled = true;
212+
_nodeState = RoleConnectionState.Error;
213+
_nodeError = detail;
214+
_nodeCredentialSource = null;
215+
RebuildSnapshot();
216+
}
217+
202218
/// <summary>Update the operator pairing request ID in the snapshot.</summary>
203219
internal void SetOperatorPairingRequestId(string? requestId)
204220
{
@@ -304,6 +320,7 @@ private void ApplyTransition(ConnectionTrigger trigger, string? detail)
304320

305321
case ConnectionTrigger.NodePairingRequired:
306322
_nodeState = RoleConnectionState.PairingRequired;
323+
_nodeError = null;
307324
break;
308325

309326
case ConnectionTrigger.NodePaired:
@@ -340,6 +357,7 @@ private void RebuildSnapshot()
340357
// Clear requestId when no longer in PairingRequired to prevent stale reads
341358
OperatorPairingRequestId = _operatorState == RoleConnectionState.PairingRequired
342359
? Current.OperatorPairingRequestId : null,
360+
NodeConnectionIntended = _nodeEnabled,
343361
NodeState = _nodeState,
344362
NodeError = _nodeError,
345363
NodeCredentialSource = _nodeCredentialSource,

0 commit comments

Comments
 (0)