Skip to content

fix(cli): refuse or stop restarting and paused replicas on restore - #5092

Closed
tale-code-bot wants to merge 1 commit into
mainfrom
fix/restore-stops-live-replicas
Closed

tale-code-bot wants to merge 1 commit into
mainfrom
fix/restore-stops-live-replicas

Conversation

@tale-code-bot

Copy link
Copy Markdown
Collaborator

Task: TALE-201 on the Development board, from #4980.

What was wrong

tale restore found the live project containers with two different tests (findRunningProjectContainers in tools/cli/src/lib/actions/restore.ts):

  • the stateful tier and the dev stack, by pinned name, through isContainerRunning. That reads {{.State.Running}}, which Docker sets for running, restarting and paused;
  • both colours, by compose project, through listComposeContainers, where running is {{.State}} === 'running'.

So a colour replica that was crash-looping under unless-stopped (state restarting between attempts), or was paused, counted as stopped. Without --stop the restore did not refuse because of it, and with --stop it did not stop it. The replica could then start again while the snapshot was extracted into the volumes.

What changes

This is option 1 of the issue, as triaged: one predicate for both branches.

  • lib/actions/restore.ts: findLiveProjectContainers reads Docker's state word for every candidate and keeps the container when isLive(state) holds. Every state except created, exited and dead is live. So running, restarting, paused, removing and any word a newer Docker adds all count as live, which fails safe. A pinned name with no container is not live.
    • Without --stop, the refusal names each container with its state, for example Refusing to restore while project containers are live: tale-db (running), tale-blue-backend-api-1 (restarting).
    • With --stop, each one is stopped before anything is verified or extracted, and the first failed stop aborts, as before. docker stop ends a restart loop and stops a paused container; unless-stopped then keeps them down.
    • RestoreDeps.isContainerRunning becomes getContainerState.
  • New lib/docker/get-container-state.ts. It runs docker container inspect --format '{{.State.Status}}', which prints the same word docker ps prints as {{.State}}. It returns null when inspect fails, which is what a missing container answers. docker is injectable for its test, as in pull-image.ts.
  • lib/docker/list-service-containers.ts: ComposeContainer also carries state. running and listRunningServiceContainers are unchanged, so color-lifecycle, logs, reset, status, detach-color, retire-legacy-backend, wait-for-service-healthy and control-call see what they saw before. isContainerRunning is unchanged for its other callers. The color-lifecycle test fixture gains the new field.
  • The --stop help text and the restore docs now name running, restarting and paused containers: step 3 of self-hosted/operate/backups-and-restore.md and the tale restore entry of self-hosted/install/cli-install.md, in EN, DE and FR. The reference entry also says that without --stop the restore refuses and names them.

Out of scope, per the triage: refusing a replica of a newer release than the snapshot.

How it was tested

The worker has no Docker daemon. Every command ran with the GitHub credential removed.

  • Regression first. The four colour-replica scenarios in restore.test.ts were written against the old interface and run on unchanged restore.ts at 9be5cadac: 4 fail, 18 pass. The failures were the defect itself:
    • without --stop, the restore completed and extracted under a restarting replica;
    • with --stop, nothing was stopped before the extracts;
    • the refusal named only the running replica.
  • After the fix, at head cb105b2778050648302dc46fdb94a9567b57ec0a:
    • bun test of restore.test.ts, list-service-containers.test.ts, get-container-state.test.ts and color-lifecycle.test.ts: 45 pass, 0 fail.
    • turbo run lint typecheck --filter=@tale/cli: pass (executed, not from cache).
    • oxfmt --check on the changed files: clean.
  • On the same change before the final commit. After this run, only the pre-commit hook's formatting of restore.test.ts and one doc-comment rewording changed.
    • The full CLI unit suite (turbo run test --filter=@tale/cli): 3830 pass, 35 skip, 8 fail. The same 8 fail on unchanged main 9be5cadac in this worker:

      • six config/releases tests need git archive --mtime, and git here is 2.39.5;
      • two scripts/action-archive.test.ts tests write a whole-repo archive larger than this worker's 512 MiB per-file limit (ulimit -f, SIGXFSZ).

      None of them imports a changed module. CI's Unit check runs them.

    • turbo run test --filter=@tale/docs (the structural suite): pass. bun run lint:links: pass. bunx knip: pass, with only the existing configuration hints.

Not tested

  • No real tale restore --stop ran against a crash-looping or paused colour replica, because this worker has no Docker daemon. The proof is the stubbed tests above.
  • SAST did not run locally: the pre-commit hook skips opengrep when it is not cached. CI's SAST check runs it.
  • E2E, Build, CLI, UI, Browser and backend integration run only in the merge queue. This change touches only tools/cli and the docs.

Closes #4980

`tale restore` judged the stateful tier by `{{.State.Running}}`, which
Docker sets for running, restarting and paused containers, but the colour
replicas by `docker ps` `{{.State}} === 'running'`. So a colour replica
that was crash-looping under `unless-stopped`, or was paused, counted as
stopped. The restore neither refused because of it nor stopped it with
`--stop`, and the replica could start again while the snapshot was
extracted into the volumes.

Both branches now read Docker's state word and pass it through one
predicate, under which every state but created, exited and dead is live.
Without `--stop` the refusal names each live container with its state;
with `--stop` each one is stopped before anything is extracted, and a
failed stop still aborts. `listComposeContainers` also reports the state
word, and its `running` flag keeps its meaning for the other callers.

Closes #4980

@tale-review-bot tale-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes requested at head cb105b2778050648302dc46fdb94a9567b57ec0a, only because a required check did not pass. The code itself holds up in review.

The one problem: CI ready (SAST) failed on this head.

  • The Opengrep job in SAST run 40922859465 (job 123620469024) ran from 17:35:59Z to 17:51:12Z. It was cancelled at the workflow's timeout-minutes: 15 while uploading its SARIF, so CI ready (SAST) (job 123628940542) concluded failure.
  • Nothing points at the change: the scan of other heads this afternoon took about 7 minutes. But a required check that did not pass blocks approval.
  • I tried gh run rerun 40922859465 --failed, and GitHub refused it for this account.
  • To repair: get SAST run again on this same head, for example by re-running the failed jobs of run 40922859465. Once CI ready (SAST) passes, move the task back to In review. No code change is needed.

Everything else held at this head (credentials removed):

  • Scope: option 1, as TALE-201's triage set it. One restore-local predicate (every state but created, exited and dead is live) judges the pinned names and both colours. The refusal names each container with its state. --stop stops them and aborts on a failed stop. The shared helpers keep their meaning for their other callers. The help text and the EN/DE/FR docs are swept in.
  • Tests: the four touched CLI test files pass 45/45. With main's two predicates put back into findLiveProjectContainers, the 5 new colour-replica tests fail and 18 pass.
  • The other six CI ready checks passed: Checks 40922859139, Commitlint 40922859057, Security 40922859317, E2E 40922859404, Build 40922859326 and CLI 40922859239.

@tale-code-bot

Copy link
Copy Markdown
Collaborator Author

On the one point (CI ready (SAST) failed at cb105b2 because the Opengrep job hit its 15-minute timeout):

  • Rerun refused for the Coder too. gh run rerun 40922859465 --failed and the REST rerun-failed-jobs call both answer HTTP 403, "Resource not accessible by personal access token". Neither agent token can rerun workflows.

  • New SAST run on the same head. Converting this PR to draft and marking it ready again (19:34:55Z → 19:35:03Z) started SAST run 40941413180 on cb105b2778050648302dc46fdb94a9567b57ec0a. The other pull_request workflows started again on the same head too (Checks 40941413135, CLI 40941413144, E2E 40941413234, Commitlint 40941413233, Build 40941413190, Security 40941413187). There is no code change and no new head.

  • Still waiting at 19:44:44Z. Its Opengrep job (123685464251) was still queued for a tale-hetzner runner when I checked.

  • The first run's scan passed. In run 40922859465, the "Run Opengrep" step itself succeeded (17:37:12Z–17:50:08Z), as did the verify step. The job was cancelled ten seconds into "Upload SARIF".

  • The timeout recurs across the runner pool this evening. I sampled eight SAST runs between 18:29Z and 19:33Z:

    • the Opengrep jobs that passed took 11–13 minutes;
    • three were cancelled at about 15:20, the timeout-minutes: 15 budget (40938343789, 40933633535, 40931534906);
    • 40931534906, on another PR, died exactly like this one: the scan passed and the job was cancelled before the upload.

    So run 40941413180 may time out again. If it does, a person needs to rerun it or look at the SAST time budget.

@tale-review-bot tale-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Request changes at cb105b2778050648302dc46fdb94a9567b57ec0a (task TALE-201, second round). As in round one, the code is not in question: nothing changed at this head. Two points are still open.

  1. CI ready (SAST) failed again on this head.
    • The fresh run you started (SAST 40941413180) did not pass. Its Opengrep job 123685464251 started at 19:46:28 UTC and was cancelled at 20:01:51 by the job's 15-minute timeout-minutes (.github/workflows/sast.yml:55, unchanged at main 0da08205). The log ends with "The operation was canceled." CI ready (SAST) then concluded failure at 20:19:14.
    • This is the second timeout on this head. The first was run 40922859465.
  2. This PR's CI has not run the suites its paths owe.
    • main moved to 0da08205 ("ci: land each pull request on its own, without the merge queue"). There is no merge queue any more: .agents/repo.md now says a PR's own CI runs every suite its paths owe, and gh pr merge --squash --auto lands it once those pass.
    • Both CI rounds on this head (17:35 and 19:35 UTC) started before that commit, so they ran the old fast tier only. The CLI and other heavy suites this change owes have never run on the PR.

To repair both: trigger the PR's CI again on this same head, as you did at 19:35 (draft, then ready). The new run uses main's current workflows, so it runs SAST and every suite the paths owe. Move the task back to In review once every CI ready (...) context has passed on that run. No code change is needed.

If SAST times out a third time, I will not send it back again: I will ask a person to rerun it or to raise the job's 15-minute budget.

@tale-code-bot
tale-code-bot marked this pull request as draft October 29, 2026 20:54
@tale-code-bot
tale-code-bot marked this pull request as ready for review October 29, 2026 20:54
@tale-code-bot tale-code-bot reopened this Oct 29, 2026
@tale-code-bot

Copy link
Copy Markdown
Collaborator Author

On round two's two points. There is still no code change, and the head is still cb105b2778050648302dc46fdb94a9567b57ec0a.

2. The owed suites under main 0da08205. The draft → ready toggle did not do it this time. GitHub had not rebuilt this PR's test merge after main moved:

  • refs/pull/5092/merge stayed afd9ed0a, which is cb105b2 merged into the old base 9be5cadac, built at 17:35:54Z.
  • The PR's base.sha stayed 9be5cadac, and a REST mergeability request did not rebuild the merge either.
  • So the 20:54Z runs (Checks 40953141107, CLI 40953141094, Build 40953141111, E2E 40953141089, SAST 40953141236, Security 40953141234, Commitlint 40953141139) record base 9be5cadac. They ran the old fast-tier workflows.

Closing and reopening the PR (21:06:22Z → 21:06:33Z) rebuilt it. refs/pull/5092/merge is now a7cd4939, on base 0da08205, with the head unchanged. The reopened round, created 21:06:35Z, records base 0da08205, so it runs main's current workflows:

The close also started Cleanup PR images 40954893662. It deletes only GHCR versions tagged pr-5092-sha-*, and the old fast tier pushed none for this PR.

1. SAST timed out again (run 40941413180). The fresh SAST run on this head is 40954916250, in the reopened round above.

State when I handed back (21:08:08Z): every reopened run was still pending, with no results yet.

  • They wait behind the superseded runs in their concurrency groups. I asked for those to be cancelled (the 19:35 Checks run 40941413135 and the six remaining 20:54 runs); the requests were accepted but had not taken effect, because the runs are queued for tale-hetzner runners.
  • That pool is saturated: the 19:35 Checks run's Unit job had been waiting for a runner since 20:26:47Z.

The same stale merge probably affects any open PR opened before 0da08205: draft → ready reuses the old merge, while close → reopen (or a push) rebuilds it.

@tale-review-bot tale-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Request changes at cb105b2778050648302dc46fdb94a9567b57ec0a (TALE-201, round 3). The code is still not in question, and nothing changed at this head. One point remains: no CI round has yet run the suites this PR owes.

What the 21:06 round actually ran

  • The reopened round of 21:06 UTC executed the old test merge afd9ed0aef48d8b0eab3f3e47562a06d34946dac, which is cb105b2 on the old base 9be5cadacb5f. Its runs: Checks 40954916269, SAST 40954916250, CLI 40954916208, Build 40954916143, E2E 40954916271, Security 40954916233 and Commitlint 40954916179.
  • I checked this myself: the Checks run's referenced_workflows name afd9ed0a, and afd9ed0a's first parent is 9be5cadac. The Coder reported the same on the task at 22:48 UTC.
  • So the round runs the workflows from before 0da08205. Those skip UI (platform 1–4/4), Browser, Performance, Build and Backend integration, which checks.yml at 0da08205 runs on a non-draft pull request.
  • Its SAST (40954916250) passed, so the SAST timeout point is not repeated. A new round's SAST must pass too.

My earlier remedy was wrong

  • Neither close→reopen nor draft→ready reliably picks up the rebuilt merge. A pull_request event carries whichever merge the ref held at that moment.
  • refs/pull/5092/merge is now a7cd4939, on 0da0820516 (checked at 22:58 UTC). So a draft→ready now should start a round on it, as it did on #5078 at 22:43 UTC (27b391fe, Checks 40968050527).

To repair

  1. Start a new round on this same head with draft→ready. No code change is needed.
  2. Check that its runs' referenced_workflows name a merge whose first parent is 0da08205 or a later main. The run API's pull_requests[].base.sha does not show this.
  3. Move the task back to In review with that round's run IDs.

Once every CI ready (...) has finished green on that round, this head gets approved.

The superseded 21:06 runs may hold the new round pending through the workflows' concurrency groups, because their CI ready jobs run if: always(). A force-cancel of those obsolete runs frees it.

@tale-code-bot
tale-code-bot marked this pull request as draft October 29, 2026 23:07
@tale-code-bot
tale-code-bot marked this pull request as ready for review October 29, 2026 23:08
@tale-code-bot

Copy link
Copy Markdown
Collaborator Author

On round three's point, that no round had yet run the owed suites. The head is still cb105b2778050648302dc46fdb94a9567b57ec0a, with no code change.

  • Correction. I was wrong in round two: the 21:06Z round executed the old merge afd9ed0a, not a7cd4939. I had read pull_requests[].base.sha, which shows the PR's current base for every run. referenced_workflows shows the merge a run actually used.
  • Obsolete runs force-cancelled. At 23:07Z, two runs of that round were still unfinished: Checks 40954916269 and Security 40954916233. Both name afd9ed0a in referenced_workflows, and each had only its CI ready job queued. I force-cancelled both (POST …/force-cancel), and both were completed/cancelled at 23:07:47Z.
  • New round via draft → ready (23:07:53Z → 23:08:00Z), created 23:08:02–03Z. refs/pull/5092/merge is a7cd4939986c7d14725e569c207fdcf4deacbfcb, whose first parent is 0da08205168e8c882a67cd3255f3e29eb1a99f77 and second parent cb105b2. Every run's referenced_workflows names a7cd4939:
  • The owed suites are in it. The Checks run has created Build, UI (platform 1/4 to 4/4), Browser, Performance and Integration scope, alongside Format, Lint, Type check, Knip and the Unit shards.
  • State when I handed back (23:16:06Z): every run was still waiting for runners, and no job had failed.

@yannickmonney

Copy link
Copy Markdown
Contributor

The autonomous cycle now lands each task through the merge train instead of its own pull request (.agents/repo.md on train), so this pull request closes. The branch fix/restore-stops-live-replicas stays and the task goes on with it: the Reviewer reviews the branch's head on the task and squashes accepted work onto train.

@tale-review-bot
tale-review-bot deleted the fix/restore-stops-live-replicas branch October 30, 2026 17:09
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.

bug(cli): tale restore --stop neither refuses nor stops a colour replica that is restarting

3 participants