Skip to content

fix(console): show a finished teardown without waiting for the tab - #215

Merged
dmf-cms-automerge[bot] merged 2 commits into
mainfrom
fix/862-teardown-outcome-late
Nov 7, 2026
Merged

dmf-cms-automerge[bot] merged 2 commits into
mainfrom
fix/862-teardown-outcome-late

Conversation

@znerol2

@znerol2 znerol2 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

What & why

A finished teardown took minutes to show on the workload page. The console's access log from the sandbox run settles the cause (issue comment): the page polled the operation every 3 seconds until 11:39:23Z, then sent nothing until 11:43:31Z. The job finished at 11:39:32Z.

  • Hidden tab. TanStack Query skips a refetchInterval tick while the document is hidden, and the app sets refetchOnWindowFocus: false, so returning to the tab didn't refresh the operation. useOperationStatus now polls in the background and refetches on focus until the operation settles.
  • Inventory lag. After run_complete, the catalog was read once and then only on focus. If the inventory still listed the entry as active, the review said "Teardown of X completed." next to a Teardown button. Each entry whose teardown finished is now tracked on its own: the catalog polls every 3 seconds, in the background too, until that entry stops reading active. Meanwhile the review says "The teardown job for X finished. Waiting for the inventory to confirm." and doesn't offer Teardown for it. A second teardown of another entry, whether it succeeds or fails, doesn't release the first.
  • operationTerminalStall T1's catalog mock kept the entry active forever while asserting "completed". It now moves the entry to bootstrapped after the teardown, which matches the new rule.

Closes dmfdeploy/dmfdeploy#862

How it's tested

  • npm test: Test Files 91 passed (91), Tests 1159 passed (1159). npx tsc --noEmit and npm run lint: clean.
  • The new finaliseInventoryConfirm.test.tsx has nine tests. These cover the waiting line, confirmation without a focus event, return to a hidden tab, background polling, no refetch of a settled operation, mount, pending, unmount and remount, and two entries where the second teardown succeeds or fails. They also cover a hidden-tab inventory flip. Five of the first six fail on origin/main's source; the sixth guards against over-eager focus refetching. Mutations of the fix each fail their test.
  • An adversarial review ran two rounds. Round 1 found the single pending key and the stalled catalog poll in a hidden tab; both are fixed and round 2 passed.

Follow-ups, not in this PR: "Already deployed." in the Provision stage and the catalog page have the same inventory lag; the job-id path in Finalise has no waiting line; useCatalogJobStatus and useWorkflowJobStatus still stall in a hidden tab.

The operation poll skipped its interval while the tab was hidden, and
the app turns window-focus refetching off, so returning to the tab did
not refresh it either. A teardown that finished in under a minute showed
as in progress for minutes. The operation status now polls in the
background and refetches on focus until it settles.

After the job finishes, the inventory can still list the entry as
active. The review then said the teardown completed and offered Teardown
again, and nothing re-read the catalog until the next focus. Each entry
whose teardown finished now waits on its own inventory record: the
catalog is polled every 3 s, also in the background, until that entry
stops reading active, and the review says the job finished and is
waiting for the inventory to confirm.

Closes dmfdeploy/dmfdeploy#862

Signed-off-by: znerol2 <6800371+znerol2@users.noreply.github.com>

@lkirc lkirc left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes: the valid launched-to-job-ID teardown path still has the hidden-tab and inventory-lag failure this PR is intended to fix.

  • frontend/src/pages/MediaWorkloads/stages/FinaliseStage.tsx:304: when the operation poll observes launched, this path switches to useCatalogJobStatus; handleJobComplete only invalidates the catalog. That poller (frontend/src/api/hooks.ts:410) neither runs in the background nor refetches on focus, and a successful job never adds its key to awaitingKeys. A hidden tab can therefore remain stale, and an active-but-lagging catalog entry can again offer Teardown. Apply the same polling and inventory-confirmation flow to this path and cover launched -> job-ID in the tests.

When the teardown operation hands off to its automation job, the page
polls the job instead. That poll stopped in a hidden tab, and a
successful job never waited for the inventory, so the stage could offer
Teardown again while the entry still read active.

The job status now polls in the background and refetches on focus until
it's done. A successful teardown job adds its entry to the pending
entries, as run_complete does, and a failed job releases only its own
entry. The cleanup effect also reruns when the pending entries change,
so an entry added after the inventory already caught up doesn't linger
and hold back a later redeploy.

Refs dmfdeploy/dmfdeploy#862

Signed-off-by: znerol2 <6800371+znerol2@users.noreply.github.com>
@znerol2

znerol2 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review in the latest commit: useCatalogJobStatus now polls in the background and refetches on focus until the job is done, and a successful teardown job on the job-ID path joins the per-entry inventory wait (a failed job releases only its own entry). New tests cover the job-ID path with a lagging inventory (success and failure), a hidden tab, an inventory that caught up before the job finished, and a later redeploy. npm test: 1164 passed; tsc and lint clean. useWorkflowJobStatus, the Provision stage and the catalog page's lifecycle claim stay in dmfdeploy/dmfdeploy#878.

@znerol2
znerol2 requested a review from lkirc November 7, 2026 22:24

@lkirc lkirc left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed current head 80b430f. The earlier job-ID-path concern is resolved: terminal jobs now receive the same hidden-tab polling and per-entry inventory confirmation as direct operation completions.

No blocking findings.

@dmf-cms-automerge
dmf-cms-automerge Bot merged commit b5f3266 into main Nov 7, 2026
18 checks passed
@dmf-cms-automerge
dmf-cms-automerge Bot deleted the fix/862-teardown-outcome-late branch November 7, 2026 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Console: a finished teardown takes minutes to show on the workload page

2 participants