Skill metadata
Reference: full SKILL.md
The following is the complete skill definition that Mibyan loads when this skill is triggered. This is what the agent sees as instructions when the skill is active.
Mibyan s6-overlay Container Supervision
When to use this skill
Load this skill when you’re working on:- Adding or removing a static service in the Mibyan Docker image (something that should be supervised at every container start, like the dashboard)
- Diagnosing why a per-profile gateway isn’t starting, restarting, or surviving
docker restart - Understanding why the container’s CMD is
/opt/mibyan/docker/main-wrapper.shand how leading-dash args reach the user’s program - Modifying
cont-init.dboot scripts (UID remap, volume seeding, profile reconciliation) - Changing the rendered run-script for per-profile gateways (Phase 4)
website/docs/user-guide/docker.md instead.
Architecture at a glance
Key files
Why Architecture B (CMD as main program, not s6-supervised)
The original plan (v1–v3) called for main mibyan to run as a supervised s6-rc service. Two real s6-overlay v3 mechanics blocked that:- cont-init.d scripts receive no CMD args — so the stage2 hook can’t parse
docker run <image> chat -q "hi"to setmibyan_ARGSfor a servicerunscript to consume. /run/s6/basedir/bin/haltdoes NOT propagate the exit code written to/run/s6-linux-init-container-results/exitcode. Containers always exit 143 (SIGTERM) regardless. Confirmed by skarnet (s6 author) in issue #477: “if you want a container shutdown, you need to either have your CMD exit, or, if you have no CMD, write the container exit code you want then call halt”.
ENTRYPOINT ["/opt/mibyan/docker/entrypoint-dispatch.sh"], which under PID 1 exec’s /init /opt/mibyan/docker/main-wrapper.sh "$@". The wrapper is prepended to user args automatically — so docker run <image> --version becomes /init main-wrapper.sh --version, and --version doesn’t get intercepted by /init’s POSIX shell. The wrapper drops to mibyan via s6-setuidgid, then exec’s the chosen program. The program’s exit code becomes the container exit code, exactly matching the pre-s6 tini contract. When the entrypoint is NOT PID 1 (Fly Machines, docker run --init), the dispatcher skips /init entirely (it would abort with can only run as pid 1), restores the s6 helper PATH, runs stage2-hook.sh, and exec’s main-wrapper.sh directly — no supervised services on that path (#38349).
Trade-off: main mibyan is unsupervised under s6. That exactly matches its behavior under tini (the pre-s6 image). Dashboard supervision is the only new guarantee — and per-profile gateways under /run/service/ get full supervision.
Quick recipes
Verify s6 is PID 1 in a running container
Inspect a profile gateway service
Bring a service up/down manually
Watch the cont-init reconciler log
Add a new static service
- Create
docker/s6-rc.d/<name>/typewithlongrun\nanddocker/s6-rc.d/<name>/run(use#!/command/with-contenv sh+# shellcheck shell=sh). - Drop to mibyan via
s6-setuidgid mibyanat the top of run (unless you specifically need root). - Create empty
docker/s6-rc.d/<name>/dependencies.d/baseso it waits for the base bundle. - Create empty
docker/s6-rc.d/user/contents.d/<name>so it joins the user bundle. - The
COPY docker/s6-rc.d/in the Dockerfile picks it up automatically — no other changes.
Change the per-profile gateway run command
EditS6ServiceManager._render_run_script in mibyan_cli/service_manager.py. The function is also called by mibyan_cli/container_boot.py::_register_service during boot reconciliation, so it’s the single source of truth. Update the corresponding assertion in tests/mibyan_cli/test_service_manager.py::test_s6_register_creates_service_dir_and_triggers_scan.
Run the docker test harness
tests/docker/ and skips when Docker isn’t available. The per-test timeout is bumped to 180s (see tests/docker/conftest.py).
Common pitfalls
”command not found” via docker exec
/command/ (where s6-overlay puts its binaries) is on PATH only for processes spawned by the supervision tree — services, cont-init.d, main-wrapper.sh. docker exec <c> s6-svstat … will fail with “command not found”; always use the absolute path /command/s6-svstat. The mibyan binary works because the Dockerfile adds /opt/mibyan/.venv/bin to the runtime ENV PATH.
Profile directory ownership
The cont-init reconciler runs as mibyan (s6-setuidgid mibyan in 02-reconcile-profiles). If a profile dir ends up root-owned (e.g. because docker exec <c> mibyan profile create … ran as root by default), the reconciler can’t read SOUL.md and fails with PermissionError. Mitigation: stage2-hook.sh chowns $mibyan_HOME/profiles to mibyan on every boot, idempotently. Don’t remove that block.
Files written by docker exec are root-owned
docker exec defaults to root. Either pass --user mibyan or rely on the stage2 chown sweep next reboot. Don’t write files under $mibyan_HOME/profiles/<name>/ as root manually — the next reconcile pass will sweep them but in-flight operations may hit perm errors.
Service slot exists but s6-svstat says “s6-supervise not running”
The service directory is on tmpfs and was wiped on container restart. Either the cont-init reconciler hasn’t run yet (give it a moment afterdocker restart) or it failed. Check docker logs <c> | grep '02-reconcile'.
Gateway starts then immediately exits (down (exitcode 1) in svstat)
Most likely the profile has no model or auth configured. The service slot is correct — the gateway itself is unconfigured. Run mibyan -p <profile> setup first. The s6 supervisor will keep restarting it; that’s the desired behavior (when you fix the config, the next attempt succeeds and stays up).
Reconciler skipped a profile
The reconciler keys on the presence ofSOUL.md as the “real profile” marker. mibyan profile create always seeds it. If a profile dir is missing SOUL.md (stray directory, partial restore, backup-in-progress), the reconciler skips it intentionally. Add a SOUL.md (even empty) to opt back in.
”Help, the container exits 143!”
Check whether something is invokings6-svscanctl -t or /run/s6/basedir/bin/halt — both cause /init to begin stage 3 shutdown but return 143 (SIGTERM) rather than the desired exit code. This was the Phase 2 architecture pivot from A to B. For container shutdown with a real exit code, you must let the CMD (main-wrapper.sh) exit normally; do not try to control exit from a finish script.
Related skills
mibyan-agent-dev: General mibyan-agent codebase navigationmibyan-tool-quirks: Specific Mibyan-tool workarounds (sed/grep/etc.) — load when debugging the s6 stack’s interaction with mibyan built-in tools.

