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:
Anso
2026-06-11 14:36:20 -04:00
committed by GitHub
parent a2fe58f62f
commit 48cebf9501
21 changed files with 617 additions and 51 deletions
@@ -654,6 +654,7 @@ export function useStackActions(options: UseStackActionsOptions) {
ignorePolicy: boolean,
started?: Promise<void>,
deploySessionId?: string,
opNodeId?: number | null,
): Promise<RunResult> => {
const previousStatus = stackListState.stackStatuses[stackFile];
const startedAt = Date.now();
@@ -663,7 +664,7 @@ export function useStackActions(options: UseStackActionsOptions) {
? `/stacks/${stackName}/deploy?ignorePolicy=true`
: `/stacks/${stackName}/deploy`;
if (started) await started;
const response = await apiFetch(path, withDeploySession(deploySessionId ?? '', { method: 'POST' }));
const response = await apiFetch(path, withDeploySession(deploySessionId ?? '', { method: 'POST', nodeId: opNodeId }));
if (!response.ok) {
const rawBody = await response.text();
if (response.status === 409) {
@@ -729,9 +730,12 @@ export function useStackActions(options: UseStackActionsOptions) {
const stackFile = stackListState.selectedFile;
const stackName = stackFile.replace(/\.(yml|yaml)$/, '');
stackListState.setStackAction(stackFile, 'deploy');
// Snapshot the node once so the request stays bound to it even if the active
// node changes while the operation is in flight.
const opNodeId = activeNode?.id ?? null;
try {
await runWithLog({ stackName, action: 'deploy', nodeId: activeNode?.id ?? null }, (started, ds) =>
runDeploy(stackName, stackFile, false, started, ds),
await runWithLog({ stackName, action: 'deploy', nodeId: opNodeId }, (started, ds) =>
runDeploy(stackName, stackFile, false, started, ds, opNodeId),
);
} finally {
stackListState.clearStackAction(stackFile);
@@ -764,9 +768,10 @@ export function useStackActions(options: UseStackActionsOptions) {
await rollbackStack(true);
} else {
stackListState.setStackAction(existingFile, 'deploy');
const opNodeId = activeNode?.id ?? null;
try {
await runWithLog({ stackName, action: 'deploy', nodeId: activeNode?.id ?? null }, (started, ds) =>
runDeploy(stackName, existingFile, true, started, ds),
await runWithLog({ stackName, action: 'deploy', nodeId: opNodeId }, (started, ds) =>
runDeploy(stackName, existingFile, true, started, ds, opNodeId),
);
} finally {
stackListState.clearStackAction(existingFile);
@@ -895,14 +900,17 @@ export function useStackActions(options: UseStackActionsOptions) {
const startedAt = Date.now();
stackListState.setStackAction(stackFile, action);
stackListState.setOptimisticStatus(stackFile, optimisticStatus);
// Snapshot the node once so stop/restart/update stays bound to it even if
// the active node changes while the operation is in flight.
const opNodeId = activeNode?.id ?? null;
try {
await runWithLog({ stackName, action, nodeId: activeNode?.id ?? null }, async (started, ds) => {
await runWithLog({ stackName, action, nodeId: opNodeId }, async (started, ds) => {
await started;
try {
const url = ignorePolicy
? `/stacks/${stackName}/${endpoint}?ignorePolicy=true`
: `/stacks/${stackName}/${endpoint}`;
const response = await apiFetch(url, withDeploySession(ds, { method: 'POST' }));
const response = await apiFetch(url, withDeploySession(ds, { method: 'POST', nodeId: opNodeId }));
if (!response.ok) {
const errText = await response.text();
if (response.status === 409) {