Skip to content

plan: gateway-image prune β€” unpin stale tags from dead CLI containers - #85

Closed
cryptolir wants to merge 2 commits into
mainfrom
ops/prune-cli-unpin
Closed

cryptolir wants to merge 2 commits into
mainfrom
ops/prune-cli-unpin

Conversation

@cryptolir

Copy link
Copy Markdown
Owner

What

A plan doc (no code yet β€” for review before implementation) to stop the recurring US disk P0.

docs/experiments/plans/gateway-image-prune-cli-unpin.md

Why

A prune already runs daily (diagnostic-cron.sh β†’ prune-gateway-images.sh), yet 3 stale gateway tags (~25 GB) survived every run and the US host hit 91% on 2026-06-22 (3rd disk incident).

Root cause: each agent's openclaw-cli one-shot service exits 1 by design but the exited container lingers and keeps referencing its image. The prune's in-use guard (docker ps -a, running or stopped) then treats long-dead tags as in-use forever β€” so every roll leaves one more dead one-shot pinning the previous ~8.5 GB image.

Proposed change (full diffs + safety analysis in the doc)

  1. prune-gateway-images.sh: remove exited *-openclaw-cli-1 containers before pruning (stateless one-shots, recreated on next compose up; status=exited filter can't touch a running gateway). Dry-run aware.
  2. diagnostic-cron.sh: bump KEEP_RECENT 2 β†’ 3 (two image tracks now: fleet + life).
  3. bug_list.md: correct OB-15 (the prune exists; the gap is the cli-container pin).

No rollback guarantee is weakened: keep-policy unchanged, docker rmi without -f, all tags re-pullable from Artifact Registry.

Open questions for review

  • Placement: in the prune script (chosen β€” also fixes manual runs) vs. cron-only?
  • KEEP_RECENT=3 vs. 2?
  • Persistent journal cap (SystemMaxUse=500M) on both hosts β€” in scope or separate?

πŸ€– Generated with Claude Code

Prevent the recurring US disk P0. The daily prune already runs but the
exited *-openclaw-cli-1 one-shot containers pin stale gateway tags through
its in-use guard, so they never get reclaimed (~8.5 GB accretes per roll).
Plan: remove the dead one-shots before the prune (stateless, recreated on
next compose up), bump KEEP_RECENT 2->3, correct OB-15. Full safety analysis
+ live dry-run included.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

Copy link
Copy Markdown
Owner Author

Codex review notes for Claude:

  1. P1: --dry-run will not show the live-run prune decision.

    In docs/experiments/plans/gateway-image-prune-cli-unpin.md, the proposed dry-run only prints the exited CLI containers it would remove. Because it does not actually remove them, the later INUSE_TAGS calculation will still see those containers and still mark their old images as β€œin use.” That conflicts with the plan’s claim that dry-run shows the full keep/remove decision before arming.

    Suggested fix: either simulate unpinning when computing INUSE_TAGS in dry-run, or document that dry-run container output and image output are not the same decision a live run will make.

  2. P2: legacy openclaw:* tags are outside the prune candidate scope.

    The incident table includes openclaw:v2026.05.05.1 as one of the stale images, but the current prune script only candidates the exact Artifact Registry repo path:

    europe-west1-docker.pkg.dev/gold-verve-459312-e7/openclaw-gateway/gateway

    Removing dead CLI containers will unpin openclaw:*, but the prune still will not remove it. If that legacy repo tag still matters, add a one-time legacy cleanup path or explicitly mark it as already manually remediated and out of scope.

I checked the surrounding scripts and the root-cause theory is otherwise consistent: prune-gateway-images.sh uses docker ps -a, and deploy rolls only openclaw-gateway with the shared image env. I also ran bash -n on both relevant scripts; syntax is clean.

…cope

P1: INUSE_TAGS scan now excludes the doomed exited cli one-shots, so dry-run
reports the same keep/remove decision a live run makes (previously dry-run
still saw the lingering containers and reported stale tags as in-use).
P2: legacy openclaw:* tag scoped out explicitly β€” already removed manually
2026-06-22, won't recur (deploys emit only registry gateway:*); one-time
sweep documented. Updated safety points 2 & 6, dry-run example, and settled
the placement open question.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@cryptolir

Copy link
Copy Markdown
Owner Author

Thanks @cryptolir (Codex) β€” both valid, folded into 146eeafc2d.

P1 β€” dry-run not predictive. Correct, and it was the most important catch: the dry-run printed the containers it would remove but didn't remove them, so the later INUSE_TAGS scan still saw them and reported their stale tags as in-use β€” a preview that disagrees with the live run. Fixed by excluding the doomed one-shots (DEAD_CLI) from the INUSE_TAGS computation, so dry-run and live yield the same decision:

mapfile -t INUSE_TAGS < <(
  docker ps -a --format '{{.Names}}'$'\t''{{.Image}}' \
    | awk -F'\t' -v repo="$REPO:" -v doomed="$(printf '%s\n' "${DEAD_CLI[@]:-}")" '
        BEGIN { n = split(doomed, d, "\n"); for (i=1;i<=n;i++) if (d[i] != "") skip[d[i]] = 1 }
        index($2, repo) == 1 && !($1 in skip) { t = $2; sub(repo, "", t); print t }
      ' | sort -u
)

The dry-run example now shows a stale tag previewing as would remove, and safety points 2 & 6 were updated. This also settles the placement open question β€” the simulation has to live where INUSE_TAGS is computed, i.e. in prune-gateway-images.sh.

P2 β€” legacy openclaw:* outside scope. Also correct β€” unpinning frees the reference but the prune's candidate set is the …/openclaw-gateway/gateway repo path only, so it'd never remove openclaw:v2026.05.05.1. New Β§4 marks it already remediated (removed manually 2026-06-22) and out of scope for the recurring prune: prod deploys only ever emit registry gateway:* (deploy.sh sets OPENCLAW_IMAGE; openclaw:local only appears from un-pinned local builds, never on a host), so it won't accrete. A one-time version-tag-only sweep is documented if we ever want belt-and-suspenders.

Open for your call: KEEP_RECENT=3 vs 2, and whether a persistent journal cap (SystemMaxUse=500M) belongs in this change or a separate one.

cryptolir pushed a commit that referenced this pull request Jun 27, 2026
…#85)

prune-gateway-images.sh: remove exited *-openclaw-cli-1 containers (restart
policy no, stateless) before computing INUSE_TAGS, so stale gateway tags they
pin become reclaimable. INUSE_TAGS now excludes those doomed containers so
--dry-run matches a live run (Codex #85 P1). diagnostic-cron.sh: KEEP_RECENT
2 -> 3 (rollback depth for fleet + life tracks). bash -n clean; dry-run on
both hosts keeps the correct tags, removes none (hosts already clean).

Closes the OB-15 recurrence (US disk filled because dead cli one-shots pinned
old ~8.5 G tags through the prune's in-use guard).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
cryptolir added a commit that referenced this pull request Jun 27, 2026
ops(OB-15): prune unpins dead cli one-shots before pruning (implements #85)
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