mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-09-03 22:25:30 +00:00
fix: bind deploy progress, request, and health gate to the captured node (#1357)
* fix: bind deploy progress, request, and health gate to the captured node A deploy/update/install/git-apply re-read the active node from localStorage independently at three points: the progress WebSocket at mount, the POST at call time, and the health-gate poll. If the active node changed between the click and any of those, the operation, its live output, and its health verdict could target different nodes, and the socket and POST splitting across nodes broke output streaming. Capture the operation's node once when it starts and thread it through every leg. A new nodeId option on apiFetch overrides the active-node read, the progress terminal takes a nodeId prop for its socket URL, the health gate polls on the captured node, and a failed gate records its recovery entry only on the node it ran on. The surface, the request, and the gate now always agree. * fix: scope failed-gate recovery to the file list's node and harden node targeting Addresses review findings on the captured-node binding: - Track the node the stack file list was fetched for (filesNodeId) and record a failed gate's recovery entry only when it matches the gate's node. This closes a race where switching back to the gate's node could match a same-named stack from the previous node's still-loaded list before the new list lands, keying the record to the wrong file and blocking the correct one. refreshStacks now carries a sequence token so an out-of-order resolution cannot leave files and filesNodeId inconsistent. - Make an explicit apiFetch nodeId authoritative over a caller-supplied x-node-id header. - Add the missing stack-logs nodeId cases (null, and active-node fallback) to the terminal tests.
This commit is contained in:
@@ -7,6 +7,11 @@ import { buildXtermTheme } from '@/lib/terminalTheme';
|
||||
|
||||
interface TerminalComponentProps {
|
||||
stackName?: string;
|
||||
/** Node the socket connects to (a number, or null for local), captured when
|
||||
* the operation started. Binds the progress stream to that node so an
|
||||
* active-node switch mid-stream cannot split it from the deploy request.
|
||||
* Leave undefined to track the active node (the standalone stack-logs view). */
|
||||
nodeId?: number | null;
|
||||
/** Correlation id sent on the generic `connectTerminal` handshake so the
|
||||
* backend streams the matching deploy's output to this socket. */
|
||||
deploySessionId?: string;
|
||||
@@ -17,7 +22,7 @@ interface TerminalComponentProps {
|
||||
onMessage?: (text: string) => void;
|
||||
}
|
||||
|
||||
export default function TerminalComponent({ stackName, deploySessionId, onReady, onError, onMessage }: TerminalComponentProps) {
|
||||
export default function TerminalComponent({ stackName, nodeId, deploySessionId, onReady, onError, onMessage }: TerminalComponentProps) {
|
||||
const terminalRef = useRef<HTMLDivElement>(null);
|
||||
const terminalInstance = useRef<Terminal | null>(null);
|
||||
const fitAddonRef = useRef<FitAddon | null>(null);
|
||||
@@ -116,13 +121,20 @@ export default function TerminalComponent({ stackName, deploySessionId, onReady,
|
||||
|
||||
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
const cleanStackName = stackName?.replace(/\.(yml|yaml)$/, '');
|
||||
const activeNodeId = localStorage.getItem('sencho-active-node') || '';
|
||||
// A captured nodeId (number, or null for local) wins over the active
|
||||
// node; undefined falls back to the active node for standalone views.
|
||||
let resolvedNodeId: string;
|
||||
if (nodeId !== undefined) {
|
||||
resolvedNodeId = nodeId === null ? '' : String(nodeId);
|
||||
} else {
|
||||
resolvedNodeId = localStorage.getItem('sencho-active-node') || '';
|
||||
}
|
||||
|
||||
// If a stackName is provided, connect to the dedicated logs WebSocket
|
||||
// Otherwise, fall back to the generic terminal WebSocket
|
||||
const wsUrl = cleanStackName
|
||||
? `${wsProtocol}//${window.location.host}/api/stacks/${cleanStackName}/logs${activeNodeId ? `?nodeId=${activeNodeId}` : ''}`
|
||||
: `${wsProtocol}//${window.location.host}/ws${activeNodeId ? `?nodeId=${activeNodeId}` : ''}`;
|
||||
? `${wsProtocol}//${window.location.host}/api/stacks/${cleanStackName}/logs${resolvedNodeId ? `?nodeId=${resolvedNodeId}` : ''}`
|
||||
: `${wsProtocol}//${window.location.host}/ws${resolvedNodeId ? `?nodeId=${resolvedNodeId}` : ''}`;
|
||||
|
||||
const ws = new WebSocket(wsUrl);
|
||||
wsRef.current = ws;
|
||||
@@ -213,7 +225,7 @@ export default function TerminalComponent({ stackName, deploySessionId, onReady,
|
||||
searchAddonRef.current = null;
|
||||
serializeAddonRef.current = null;
|
||||
};
|
||||
}, [stackName, deploySessionId, onReady, onError, onMessage]);
|
||||
}, [stackName, nodeId, deploySessionId, onReady, onError, onMessage]);
|
||||
|
||||
const handleDownload = () => {
|
||||
if (!serializeAddonRef.current) return;
|
||||
|
||||
Reference in New Issue
Block a user