Skip to content

fix(runtime): honor --memory and compose mem_limit#66

Merged
us merged 1 commit into
mainfrom
fix/memory-limit-honored
Jul 4, 2026
Merged

fix(runtime): honor --memory and compose mem_limit#66
us merged 1 commit into
mainfrom
fix/memory-limit-honored

Conversation

@us

@us us commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Summary

Investigation of #62 ("Container memory hard-capped at 1 GiB, no swap; --memory ignored and compose mem_limit stripped") found three real, distinct bugs, and one architectural limitation that's now surfaced honestly instead of silently:

  • mocker update -m/--cpus was a complete no-op that looked like success. Update.run() printed the container id(s) and a stderr warning, then exited 0 — it never touched the stored config or the runtime. Apple's Containerization runtime has no container update equivalent at all (a container's VM is sized once at run time and can't be resized live or on restart), so this now fails loudly with a clear error telling the user to recreate the container instead of pretending the change took effect.
  • mocker compose config silently dropped mem_limit / deploy.resources.limits/reservations from its printed output, even though ComposeOrchestrator.startService already correctly threads service.memLimit into the container's -m flag on up. This made config misleadingly imply the value was discarded. Fixed by rendering the resolved deploy.resources block.
  • --memory/mem_limit values could be silently mis-honored by the underlying runtime due to a case mismatch. Apple's container CLI docs only mention uppercase K/M/G/T/P suffixes, while mocker's own --help text (and Docker convention) advertises lowercase (512m, 1g). Added ContainerEngine.sanitizeMemory, mirroring the existing sanitizeCpuCount helper, to normalize the value before it reaches container run -m.
  • --memory-swap/--memory-swappiness/--memory-reservation were silently accepted no-ops. Apple Containerization has no swap concept (each container is its own VM, not a cgroup), so these can never actually be honored. mocker run now surfaces them in the existing "flags not supported by Apple Containerization runtime" warning instead of pretending to accept them.

Root cause for the 1 GiB ceiling itself: that's Apple's container CLI's own documented default when no -m is passed — not something mocker can raise on its own. The real, fixable bugs were the update no-op, the compose config display gap, and the case-format mismatch risk for --memory.

Test plan

  • swift build succeeds
  • swift test — all 314 tests pass, including new coverage:
    • sanitizeMemory normalization (lowercase/uppercase/byte-suffix/invalid input)
    • buildRunArguments emits a normalized -m flag
    • mocker update --memory/--cpus now throws instead of silently succeeding
    • mocker compose config prints mem_limit/deploy.resources for limits and reservations, and omits the block when unset

Closes #62

- Normalize --memory/mem_limit to the uppercase K/M/G/T/P suffix format
  Apple's container CLI documents (mocker's own --help advertised Docker-style
  lowercase like "3g", risking silent rejection by the underlying runtime).
- mocker update -m/--cpus/--memory-reservation/--memory-swap now fails loudly
  instead of printing a warning and exiting 0: Apple Containerization has no
  update path, so the old behavior looked like success while changing nothing.
- mocker run now warns that --memory-swap/--memory-swappiness/
  --memory-reservation are unsupported (Apple Containerization has no swap
  concept), instead of silently accepting them as no-ops.
- mocker compose config no longer strips mem_limit / deploy.resources.limits
  and reservations from its printed output; ComposeOrchestrator.startService
  already threads mem_limit into the container's -m flag on `up`, so `config`
  was misleadingly implying the value was dropped.

Closes #62
Copilot AI review requested due to automatic review settings July 4, 2026 10:52

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@us us merged commit cc57399 into main Jul 4, 2026
1 check passed
@us us deleted the fix/memory-limit-honored branch July 4, 2026 11:19
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.

Container memory hard-capped at 1 GiB (no swap); --memory ignored and compose mem_limit stripped

2 participants