Skip to content

CI: reclaim this run's artifact storage once the release is published - #82

Merged
danielhanchen merged 1 commit into
masterfrom
ci/reclaim-artifact-storage-after-publish
Aug 8, 2026
Merged

danielhanchen merged 1 commit into
masterfrom
ci/reclaim-artifact-storage-after-publish

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Stacked on #81 -- base it there so the diff shows only this change. Retarget to master once #81 merges.

Deletes this run's app-* artifacts as the final step of assemble, after the release is published and verified.

Why

Every prebuilt is stored twice: as an Actions artifact (billed against the Actions storage quota) and as a release asset (not billed against it). Measured on b10297-mix-b1e9972:

count size
Actions artifacts 37 7.42 GiB
Release assets 42 7.81 GiB

Same payload. On 2026-08-07 that duplication stalled Actions across the whole org: artifact storage hit ~492 GiB, 449 GiB of it here, and GitHub stopped scheduling runs for unslothai/* while personal-account repos ran the same workflows normally. Deleting artifacts restored scheduling within ~45 seconds. Repo retention was already 1 day -- volume alone did it.

Reclaims 7.37 of 7.42 GiB per run (99.3%), so the repo settles near zero between runs instead of ~450 GiB.

Why inside assemble, not a separate job

assemble already holds its runner for the whole run (it starts alongside the matrix and waits), so appending ~13 seconds of work costs nothing. A separate job would have to queue after assemble finishes -- and during a queue backlog that is exactly when it would be delayed or cancelled, i.e. cleanup fails precisely when storage pressure is highest.

permissions.actions goes read -> write. This job already publishes releases with contents: write, so deleting its own build artifacts is a smaller power than it already holds.

Safety

Published assets cannot break: release assets live in different storage from Actions artifacts.

  1. Last step in the job, deliberately. unsloth-prebuilt-retry.yml calls rerun-failed-jobs on the same run id. If anything after this failed, a rerun of assemble would restart at "Download built bundles" and find the bundles gone -- turning a trivial failure into an unrecoverable one. Nothing may fail after this point.
  2. No if:, so the default success() applies. A failed publish is exactly when the artifacts are still the only copy.
  3. Release must exist and be non-draft, else it exits having deleted nothing.
  4. Only this run's artifacts are listed (/actions/runs/$GITHUB_RUN_ID/artifacts) -- it cannot reach another run's, including a concurrent build's.
  5. Each artifact is deleted only if its payload is already a release asset (<name>.tar.gz or <name>.zip). Anything unproven is KEPT.
  6. continue-on-error: true -- a cleanup hiccup never fails an already-published release.

Gate 5 deliberately keeps the macOS bundles (published as llama-<tag>-bin-macos-*, not app-...) and the source tarball: 56 MiB of the 7.42 GiB. Cheap price for never deleting something early.

Artifacts stay load-bearing during the run and nothing here changes that -- build children download the source artifact, assemble downloads pattern: app-*. Verified there are no cross-run artifact downloads (no run-id:/repository: on any download-artifact), which is what makes post-publish deletion provably safe.

Testing

Script extracted from the YAML and run against fixtures:

  • happy path: 2 artifacts with matching assets deleted, 1 macOS artifact correctly KEPT, step summary renders
  • release is a draft -> no delete call
  • release missing -> no delete call
  • empty tag -> no delete call
  • bash -n clean

Throughput is measured, not estimated: a real purge ran 1,745 deletes in 617 s (2.9/s, ~344 ms each, 0 failures), so 35 deletes is ~13 seconds on a job that has already been alive 3-6 hours.

Test plan

  • First nightly after merge: confirm the step summary reports ~35 deleted / ~7.3 GiB freed
  • Confirm the release assets are all still downloadable afterwards
  • Confirm a failed-publish run deletes nothing

@danielhanchen
danielhanchen force-pushed the ci/reclaim-artifact-storage-after-publish branch from ed9e581 to 50a35ca Compare August 8, 2026 02:08
@danielhanchen

Copy link
Copy Markdown
Member Author

Review round 1 applied. One genuine blocker, plus two latent bugs. Rebuilt on the updated #81 head.

BLOCKER: the step had no if:, so a dispatch that skips publishing would still delete that run's artifacts.

Publish GitHub release is itself conditional ((schedule || inputs.publish) && exists != 'true'), but the reclaim step was relying only on the job reaching it. Three reachable states break that:

  1. workflow_dispatch with exists == 'true' -- the ordinary "rebuild this tag to test a CI change" flow.
  2. workflow_dispatch with publish: false (the input default) on an already-released tag.
  3. A concurrent scheduled run publishing the tag mid-flight. Not theoretical: concurrency.group is keyed on github.event.inputs.tag || 'scheduled', so a scheduled run and a dispatch sit in different groups and overlap.

Artifact names are keyed only on the tag, so a rebuild of tag T produces byte-different artifacts with byte-identical names to T's existing assets. Every app-* artifact would have matched and been deleted -- and after #81 makes the debug bundle failure()-only, those artifacts are that run's only output.

This also falsified a claim in the original description: the check is on name, not payload. Fixed by giving the publish step an id: and gating on its actual outcome:

- name: Publish GitHub release
  id: publish
...
- name: Reclaim artifact storage
  if: ${{ steps.publish.outcome == 'success' }}

outcome is skipped in states 1 and 2, and in state 3 gh release create fails on the already-published tag so the step is never reached.

grep -qx was treating the artifact name as a regex. Every . matched any character. Demonstrated: artifact app-y. matched asset app-yXYtar.gz and was deleted. Latent today, but gfx_target and only_profile are free-text workflow_dispatch inputs that flow into artifact names. Now grep -qxF, and the same fixture now correctly reports KEEP app-y..

gh inside the while read loop could consume the loop's stdin. Real gh api only reads stdin with --input -, so this was safe, but it is one flag away from silently sweeping a single artifact and reporting success. Added < /dev/null to the delete call.

Also: a failed counter with a ::warning:: (delete failures were previously counted in neither deleted nor kept, so the summary under-reported silently), and scratch files moved to $RUNNER_TEMP instead of sitting next to dist/.

Correction to the reclaim figures. The description said 99.3% of 7.42 GiB. Measured on the completed run 31218133438, total live artifact storage is 15.48 GiB across 40 artifacts, of which this step deletes 36 totalling 7.67 GiB, i.e. 49.5% on its own. The gap is the 8.33 GiB unsloth-prebuilt-<tag> debug bundle, which only stops being written once #81 lands. The near-zero steady state needs both PRs; merging this one alone still accrues ~8 GiB per run. My earlier 7.42 GiB number came from a snapshot taken mid-run, before the debug bundle was uploaded.

Independently confirmed and unchanged:

  • Asset-name mapping holds for every platform. Replaying gate 3 over all 40 real artifacts of 31218133438 against the 42 real assets of b10310-mix-b1e9972 gives 36 DELETE / 4 KEEP, covering linux x64+arm64, windows x64+arm64, all 7 CUDA profiles x 2 OSes, all 7 ROCm gfx targets x 2 OSes, vulkan x3, cpu x4. Every mismatch errs toward KEEP.
  • No cross-run or cross-repo artifact consumption anywhere; whisper.cpp does not read the run_id in the dispatch payload and pulls via gh release download.
  • Nothing runs after this step; the alert job reads only toJSON(needs) and gh run view --log-failed.
  • Published release assets are separate storage and cannot be touched -- the script only ever calls DELETE /actions/artifacts/{id}.

Known residual, documented rather than fixed: a cancellation landing inside the ~13 second window leaves artifacts partially deleted, and the retry workflow would then rerun assemble into an incomplete app-* set. It fails closed -- the bundle-coverage gate catches it and gh release create would fail on the already-published tag -- so no partial release is possible; the cost is a rebuild.

Fixture tests re-run against the rebuilt step: happy path 2 delete / 1 keep, draft release 0 deletes, missing release 0 deletes, empty tag 0 deletes, regex-metachar case now KEEP. bash -n clean, all workflows parse.

@danielhanchen
danielhanchen force-pushed the ci/reclaim-artifact-storage-after-publish branch from 50a35ca to 958e4a9 Compare August 8, 2026 02:51
@danielhanchen

Copy link
Copy Markdown
Member Author

Round 2 applied. The reviewer found no path that deletes a still-needed artifact -- on real data the matcher is exact in both directions (36/36 deletions have a byte-identical release asset) -- but did find one real interaction bug, and I have reversed an earlier design decision because of it.

The reclaim now runs as its own job, not as the last step of assemble.

I originally argued against a separate job on the grounds that it has to queue for its own runner. That reasoning was incomplete: I weighed the cost of the separate job without weighing the cost of the in-step version, which turns out to be higher.

As a trailing step, a cancellation landing inside the ~13 second window left assemble cancelled with a partial app-* set. I verified what follows: unsloth-prebuilt-retry.yml only bails out on a cancelled run when FAILED is non-empty, so a cancel with no failed job falls through to rerun-failed-jobs, which re-runs assemble itself. That restarts at Download built bundles, survives the fingerprint gate, and dies at the coverage gate -- so the run goes red and alert reports "Nothing was published; the previous release remains Latest" for a release that had already published, while the failure()-gated debug upload re-uploads a partial dist/ measured at 7.94 GiB, re-inflating the quota this PR exists to reclaim.

This is not hypothetical: cancel-in-progress: ${{ github.event_name == 'schedule' }} makes a superseding nightly cancel a live run, and the retry workflow was itself written for a real 08-05 incident where the publish job was cancelled 15 seconds in.

As a separate job, assemble has already succeeded, so a rerun re-runs only the reclaim job -- and re-running it is a no-op, since deleted artifacts are simply absent from the second listing. Verified with a fixture: 0 artifacts, 0 deletions, exit 0.

Weighing it properly: if the reclaim job never gets a runner, artifacts age out on the existing 1-day retention, which is exactly today's behaviour. The in-step failure mode is a false alert plus an 8 GiB re-upload. The separate job is clearly the better trade.

It also fixes a privilege problem I had underweighted. actions: write grants Actions cache deletion, so holding it across assemble's unzip/tar/python steps put every ccache the pipeline depends on within reach of that job. assemble is back to actions: read, and the write scope is confined to a job whose only action is deleting artifacts.

Gating is now needs.assemble.outputs.published == 'true', with assemble exposing published: ${{ steps.publish.outcome == 'success' }}.

Correction to my previous comment. I wrote that the steps.publish.outcome gate closed the concurrent-publish race. It does not, quite. published proves this run's publish step succeeded, not that the release object is this run's: a same-tag dispatch can delete a scheduled run's draft and create its own, after which the scheduled run's gh release edit --draft=false succeeds against the dispatch's release. The payloads are equivalent -- the resolve guard pins every publish run to the full default matrix and the tag encodes base plus pr-set hash -- so the assets match whichever run wrote them. Accepted and now stated in the comment rather than claimed as closed.

Nits also applied:

  • delete failures now report the HTTP reason (403 from a permissions regression and a transient blip needed different responses, and the step is continue-on-error so nothing else surfaces it)
  • artifact names printed via printf rather than echo, so a name can never be read as a workflow command
  • the header count now uses grep -c ., so it agrees with deleted + kept + failed when the tsv has a blank line
  • the run block re-indented to the file's normal depth

Round-1 fixes all confirmed by the reviewer, two of them load-bearing: without < /dev/null the sweep truncated to 1 of 36 deletions under a stdin-draining stub, and under grep -qx the name app-...-rocm-gfx.03X matched the real gfx103X asset and was deleted.

Re-tested after the rework: happy path, idempotent re-run, draft gate, missing release, empty tag, delete-failure reporting. bash -n clean, all workflows parse.

@danielhanchen
danielhanchen force-pushed the ci/reclaim-artifact-storage-after-publish branch from 958e4a9 to 289128d Compare August 8, 2026 03:02
@danielhanchen
danielhanchen changed the base branch from ci/artifact-storage-and-ccache-fixes to master August 8, 2026 05:27
@danielhanchen
danielhanchen force-pushed the ci/reclaim-artifact-storage-after-publish branch from 289128d to 958558b Compare August 8, 2026 05:28
@danielhanchen
danielhanchen marked this pull request as ready for review August 8, 2026 05:28
@danielhanchen
danielhanchen merged commit 2bba58d into master Aug 8, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 958558b32a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# assets match whichever run wrote them.
reclaim:
name: Reclaim artifact storage
needs: [resolve, assemble]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Exclude the reclaim job from the assemble waiter

The Wait for the build matrix step builds SIBS from every run job except Assemble metadata + publish and Report pipeline health, then waits until every sibling is completed. This new job depends on assemble, so while it is queued in the run's job list, assemble counts it as pending even though reclaim cannot start until assemble completes. Publish-intent runs therefore deadlock until the waiter's 330-minute timeout and publish nothing; filter Reclaim artifact storage out alongside the alert job.

Useful? React with 👍 / 👎.

# Gate 2: only THIS run's artifacts are even considered, so the step
# cannot reach another run's -- including a concurrent build's.
gh api "repos/$repo/actions/runs/$GITHUB_RUN_ID/artifacts" --paginate \
-q '.artifacts[] | select(.expired==false) | "\(.id)\t\(.size_in_bytes)\t\(.name)"' > "$arts" || true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Surface failures while listing artifacts

If the run-artifacts request fails because of a transient API, authentication, or pagination error, || true discards the failure and leaves an empty or partial $arts file; the step then reports a successful cleanup with zero or too few artifacts and never warns that this run retained most of its storage. gh help exit-codes documents that a failed command exits with status 1, and the step already has continue-on-error, so preserve or explicitly report this error rather than converting it into an apparent successful sweep.

Useful? React with 👍 / 👎.

Comment on lines +926 to +930
# Every prebuilt is stored TWICE: as an Actions artifact (billed against the
# Actions storage quota) and as a release asset (not billed against it).
# Measured on run 31218133438: 36 of its 40 artifacts, 7.67 GiB, are byte-for
# -byte already on the release. On 2026-08-07 that duplication reached ~492
# GiB org-wide, 449 GiB of it here, and GitHub stopped scheduling Actions runs

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Condense the reclaim job commentary

This begins a roughly 40-line operational postmortem, followed by further long, hard-wrapped explanations throughout the job that repeat the implementation and commit rationale. Keep only concise comments for non-obvious safety invariants and move incident history or measurements to documentation; the repository explicitly requires comments to remain concise, avoid excessive commentary, and avoid fixed-column wrapping.

AGENTS.md reference: AGENTS.md:L74-L77

Useful? React with 👍 / 👎.

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.

1 participant