Skip to content

feat(custom-app): disk admission at the digest pull (Feature 4 — HLD §9) - #148

Merged
omarsy merged 1 commit into
mainfrom
feat/custom-disk-admission
Oct 23, 2026
Merged

omarsy merged 1 commit into
mainfrom
feat/custom-disk-admission

Conversation

@omarsy

@omarsy omarsy commented Oct 23, 2026

Copy link
Copy Markdown
Member

Custom-app-deploy foundation Feature 4, disk-admission slice (HLD §9: "a precondition, a cap, and a cleanup").

What

Enforcement lives at the preflight's digest pull — the one pull the platform controls (catalog pulls ride docker-compose up without us; the start path re-pulls the same digest with layers cached).

  • Free-space precondition: statvfs on greffon_path (the heartbeat's existing disk-free signal — a real filesystem call; docker df() walks every volume on the host and is the most expensive call in the design). Refuse when image_size + keep_free > free. On the standard single-disk install the data volume and the engine share a disk; split-disk hosts should rely on the size cap (documented).
  • Per-image size cap and count cap, both judged after pull/inspect (attrs['Size'] — exact, not estimated).
  • Cleanup pass: a refused image this pull introduced is removed — pre-existence is checked before pulling, and when existence is unreadable the safe reading is "pre-existing" (doubt means "not ours to delete"). Cleanup failure is logged, never raised, so it cannot mask the refusal.
  • All refusals are the preflight's existing 422 row shape (key: "image", message naming image, size, cap, and the env knob) — the manager relays them at create time.

Knobs (operator-owned, app/settings.py, typo-must-not-crash coercion like the limits feature):

Env Default Meaning
GREFFER_IMAGE_MAX_BYTES 20 GiB per-image cap; 0 = off
GREFFER_IMAGE_MIN_FREE_BYTES 2 GiB keep-free margin; 0 = off
GREFFER_IMAGE_COUNT_MAX 0 (off) count cap

The count cap defaults OFF deliberately: images already on the node are mostly the catalog tier's pulls, and charging those to a custom create would refuse tenants for usage they did not cause. Free-space read failures fail open (logged) — a transient statvfs error must not become a wrong create refusal.

run_preflight(..., settings=None) keeps the unit-callable default (no admission) — the router passes the app settings; the route test proves the wiring.

Tests

Six admission unit tests (size refusal + cleanup, pre-existing never removed, free-space refusal, read-failure fail-open, count refusal before any pull, settings-absent = old behavior), two settings tests (protective defaults, junk→default), one route test (knobs reach the pull, 422 shape). Conftest neutralizes the knobs for the shared app so route tests stay machine-independent.

Boundary

Failed pulls (as opposed to refused ones) leave no image object to remove; orphan layer blobs are the daemon's own GC territory — pruning dangling images globally would touch other tenants' state. Named in the PR rather than left implied.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T20:46:31.192895Z 5da67ae PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 5da67aee7f

ℹ️ 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".

Comment on lines +215 to +217
free = _disk_free_bytes(settings)
if free is not None and (
size + settings.greffer_image_min_free_bytes > free):

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 Avoid counting image bytes twice in the free-space check

_admit_image runs after images.pull, so the reported free space already excludes the pulled image's storage. Adding its full size again incorrectly refuses images even when the configured keep-free margin is satisfied, including fully cached images that require no additional disk space. For example, a cached 4 GiB image on a node with 3 GiB free is refused with the default 2 GiB margin. Compare post-pull free space against the margin alone; any pre-pull capacity check should separately account for additional bytes required.

Useful? React with 👍 / 👎.

Comment thread apps/utils/greffon/preflight.py Outdated
Comment on lines +240 to +242
if settings is not None and settings.greffer_image_count_max:
try:
count = len(compose_mod.client.images.list())

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 Enforce the image-count cap throughout the service loop

When GREFFER_IMAGE_COUNT_MAX is enabled, the image count is checked only once before processing all services. A node holding one image with a cap of two therefore accepts a compose containing multiple distinct new images, pulls all of them, and exceeds the configured cap. Recheck or track the count as new images are introduced so later services cannot bypass admission within the same request.

Useful? React with 👍 / 👎.

@omarsy
omarsy force-pushed the feat/custom-disk-admission branch from 5da67ae to 44dea76 Compare October 23, 2026 21:04
A precondition, a cap, and a cleanup, enforced at the preflight's
digest pull — the one pull the platform controls. Free space reads
statvfs on greffon_path (the heartbeat's existing disk-free signal;
docker df() is the most expensive call in the design and has no place
in a request path). Size and count judge attrs['Size'] after the pull
(exact, not estimated). A refused image this pull INTRODUCED is
removed BY IMAGE ID; pre-existence is probed by identity (a moved
mutable tag introduces a new image under the same name) and doubt
reads as "not ours to delete". All refusals are the preflight's 422
rows naming image, size, cap and the env knob.

Knobs are operator-owned with typo-must-not-crash coercion that also
accepts the platform's size syntax ("50g", like the limits knobs):
MAX 20 GiB and MIN_FREE 2 GiB default ON (protective without
refusing legitimate apps); COUNT defaults OFF — node images are
mostly the catalog tier's pulls, and charging those to a custom
create refuses tenants for usage they did not cause. Free-space read
failures fail open, logged.

Review folds:
- codex P1: the headroom precondition runs BEFORE each pull — with
  the disk already at/below the margin the refusal happens without
  pulling (a multi-GiB pull on an exhausted disk would run to ENOSPC,
  bypassing admission AND cleanup); the exact size-vs-margin judgment
  still runs post-pull.
- codex P2: count-cap slot accounting — the snapshot cannot see this
  request's own additions, so each image the loop introduces consumes
  a slot and the second new image is refused before it is pulled.
- codex P2: cleanup keyed on image IDENTITY — tag presence lies when
  a mutable tag is cached at digest A but the registry serves B; the
  refusal removes B by ID, never A.
- adversarial P2s: the count reads the low-level one-call API
  (images.list() inspects every image — an N+1 storm on the shared
  threadpool token); the knobs accept parse_size units (a "50g" that
  silently landed on the 20 GiB default was a trap 2.5x off intent).
- Grain notes documented: cleanup is per-image (a multi-service
  refusal keeps earlier images as warm layer cache); Size is virtual,
  so a fully-cached image can still trip the margin on purpose.

Suites: preflight 28 OK incl. 9 admission; settings 19 OK; full 1125
passed with only the pre-existing oracle/catalog-pin artifact.
@omarsy
omarsy force-pushed the feat/custom-disk-admission branch from 44dea76 to bc92baa Compare October 23, 2026 21:14
@omarsy
omarsy merged commit a46f879 into main Oct 23, 2026
1 check failed
@omarsy
omarsy deleted the feat/custom-disk-admission branch October 23, 2026 21:15
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