Bound and scope the run checks of the cache

Closed
YO
9d ago
+151-25

Summary

The step dialog asks the server whether the runs that cached outputs name still exist. Three bugs: each pass could send five more requests while earlier ones waited; an answer that arrived after a switch to another workflow or remote node was read in the new one; and a 200 answer with no run left the check waiting forever, so the dialog never offered Step only.

Split out of #4136 (whose first version carried these fixes), carved from #3829 and #3833 (SCcagg5), part of #4002.

Changes

  • At most five run checks wait for an answer at one time (before: five new requests per pass, with no cap on those in flight).
  • Answers belong to one workflow on one remote node; a late answer of another is dropped (before: it was read in the new scope).
  • A 200 answer with no dagRunDetails counts as unknown and leaves the decision to the server (before: the check stayed pending and was never asked again).

Core change

The record of requested runs carries its scope, and the effect counts the requests still waiting before sending more. An answer is written only while its scope is current.

// ui/src/features/workflow-workspace/step/useReuseSource.ts:285
useEffect(() => {
  if (requested.current.scopeKey !== scopeKey) {
    requested.current = { scopeKey, ids: new Set() };
  }
  if (history.isLoading) return;
  const sent = requested.current.ids;
  // At most `MAX_RUN_CHECKS` requests wait for an answer at one time.
  const inFlight = [...sent].filter((id) => asked[id] === undefined).length;
  const toSend = runIds
    .filter((id) => !sent.has(id) && runOfId(id) === undefined)
    .slice(0, Math.max(0, MAX_RUN_CHECKS - inFlight));
  const answer = (id: string, value: RunAnswer) => {
    if (requested.current.scopeKey !== scopeKey) return;
    setAnswers((held) => ({ scopeKey, runs: { ...(held.scopeKey === scopeKey ? held.runs : NO_ANSWERS), [id]: value } }));
  };
  ...
        answer(id, data?.dagRunDetails ? data.dagRunDetails : response.status === 404 ? 'gone' : 'unknown');

Testing

  • useReuseSource.test.tsx: "keeps at most five requests in flight", "ignores a late answer of another remote node", "leaves the decision to the server when a 200 answer holds no run".
  • These tests passed Frontend CI on the first version of #4136 (b15561201). Not run locally; CI runs them.

Performance

No new request, poll or timer. Run checks stay one per distinct run that the cache entries name, per dialog, now capped at five in flight instead of five per pass, so a burst of answers no longer fans out more requests. A scope switch drops the old record.


Summary by cubic

Fixes three bugs in the step dialog's run checks for cached outputs: requests could pile up without a cap, late answers from a previous workflow or remote node were read in the new scope, and a 200 answer with no run left the check waiting forever.

  • Caps run checks at five requests in flight; before, each pass could send five more while earlier ones waited.
  • Drops answers that arrive after the dialog moves to another workflow or remote node.
  • Treats a 200 answer with no run as unknown, leaving the decision to the server.