Plan, apply and state
How amicu turns configuration into running deployments and tracks what it did.
Amicu works in four steps. Each reads the same configuration; only apply changes anything.
| Step | Command | Effect |
|---|---|---|
| Validate | amicu validate | Parses every *.hcl file and reports diagnostics. Changes nothing. |
| Plan | amicu plan | Computes the actions needed to move from recorded state to the configuration. Changes nothing. |
| Apply | amicu apply | Recomputes the plan, shows it, asks for approval, then executes it and records the result. |
| Destroy | amicu destroy | Stops and removes the deployments recorded in state (or only the --targets). Asks for approval. |
| Doctor | amicu doctor | Checks the host (runtime binary, state directory) and the project. |
Validate
validate loads all *.hcl files under the project root, skipping .amicu/, hidden directories, and target/. It runs:
- Syntax and schema checks. Unknown attributes and blocks are errors, with a suggestion for near misses (
AMICU-SCHEMA-003). - Reference checks: every
model.<id>.id,hardware_profile.<id>.idand similar reference must resolve (AMICU-REF-001). - Capacity checks: the model weights plus KV cache must fit the accelerator or host memory (
AMICU-MEM-*). - Policy checks: residency, provider allowlists, secret handling, and endpoint API keys (
AMICU-POLICY-*). Budgets are recorded but not enforced.
Only diagnostics with severity error fail the command (exit code 1). Warnings and info diagnostics are printed but do not fail it. --output json emits a stable report.
Plan
plan compares the configuration with the state recorded by the last apply and lists actions per resource.
| Action | Meaning |
|---|---|
create | The deployment does not exist yet. |
update | The deployment exists and a setting changed. |
destroy | The deployment is no longer in the configuration. |
For each deployment the plan shows the hardware, the provider, the model artifact, the exact launch command, and notes such as the estimated peak memory. Secret-designated fields show as ******. A plan never reads secret values.
For remote provider deployments (Modal and RunPod), plan, apply and destroy first ask the provider whether the apps recorded in state still exist. An app that is not found by name is kept in state as pending (its stop identity is never dropped on a name lookup alone), and a drift: line is printed. apply recreates it; destroy tries to confirm its stop. If the lookup fails, plan, apply and destroy print a warning: and use local state as is.
For host services (launchd or systemd), the same three commands ask the service manager whether each recorded service is running. A service is confirmed gone when launchd print exits with status 113 or shows state = not running, or when systemd reports the unit as not found, inactive or failed. Such a deployment is kept in state as pending and a drift: line is printed: plan shows a create, apply restarts the service, and destroy stops it and confirms the stop. If the check fails (for example launchctl or systemctl returns an error, or the service was started by another user), amicu prints a warning: and uses local state as is. A service that is starting or stopping, or a launchd record with no domain, is left alone without a warning.
plan also warns, instead of failing, when the active Modal workspace cannot be determined. apply and destroy refuse in that case, because they must not act on instances they cannot place.
Change detection
plan also compares three inputs with the values recorded when each deployment was last confirmed started:
- the pinned
versionof eachapi_key = secret("...")reference; - the container image for a Modal deployment, set by
AMICU_MODAL_VLLM_IMAGEorAMICU_MODAL_LLAMACPP_IMAGE, or the amicu default image when neither is set; - the path of the
llama-serverorvllmbinary thatPATHresolves to.
A change to one of these shows the deployment as an update with a line such as reason: container image changed since it was last started. The JSON plan output carries the same text in reason.
Two cases are not detected:
- Rotating an unpinned secret. amicu records no version for it. To make a rotation restart the deployment, pin
versionin the reference and bump it. - A binary that is not on
PATH, and state written before this check existed. An unknown value never counts as a change. The firstapplyrecords a baseline silently, even when it printsNo changes to apply.
The recorded values are SHA-256 digests in the fingerprints map of state. amicu does not store the raw values. Deleting that map resets the baseline.
Provider switch
When a deployment's provider or host identity changes, plan shows a destroy old (<backend> <identity>) step before that deployment's create or update. For example, destroy old (launchd io.amicu.llama.<project_id>.<deployment>) appears when a deployment moves from a local service to Modal. The same step appears when a legacy unscoped host label is replaced by a project-scoped one.
Apply stops the old instance and confirms the stop before it starts the new one. If that stop fails, apply fails and starts nothing for that deployment. The old record stays in state. The JSON plan (--output json) lists the step as a Destroy action directly before the deployment's create or update.
Apply
apply recomputes the plan and prints it. Unless you pass --auto-approve (alias --yes) it asks for confirmation. It then:
- Runs preflight checks before anything starts: the provider must be supported by
apply, every off-machine deployment must have anapi_key, and the provider's own credentials must be present (on Modal, the proxy tokens). - Starts each deployment through its provider. If the deployment has a provider switch, the old instance is stopped and confirmed first (see Provider switch).
- Verifies that each endpoint is protected. See Endpoint auth. If a Modal update fails this check, and the new deployment went into the same Modal app that was serving, amicu rolls the app back to the previous version and checks that version again before it reports it as serving. Otherwise the app is stopped. If the rollback or the re-check fails, if there is no previous version, or if amicu cannot read the app's version history, the whole app is stopped. Either way apply fails. See Security: State.
- Stops deployments that were removed from the configuration.
- Writes state, including any deployments already started if a later action failed.
- Prints each endpoint and a ready-to-copy
curland OpenAI SDK snippet.
Apply holds a lock on the state directory for its whole run. Use --lock-timeout <secs> to wait for another amicu process instead of failing.
If the plan is empty, apply prints No changes to apply.
Destroy
destroy works like terraform destroy. It plans against an empty desired configuration, so every deployment in state is a destroy action (or only the --targets you name), shows the same plan preview as apply, and asks Destroy these deployments? [y/N]. --auto-approve (alias --yes) skips the prompt. --lock-timeout <secs> waits for the state lock, as in apply. Unknown --target names fail before anything is changed.
For each host service that is stopped, destroy also deletes its service files: the launchd plist, or on Linux the systemd unit file and the environment file that holds the endpoint API key. Destroy disables the systemd unit before it stops it, so it does not start again at login. With --purge, it also deletes the host log files recorded for the destroyed deployments. Modal cache volumes are never deleted. When a destroyed deployment mounts one, destroy lists it with the modal volume delete <name> command, for you to run yourself if no other project or app uses it.
Each deployment follows the same no-orphans rule as apply:
- Apply writes state before a provider starts anything: the deployment is marked
pendingand gets a stop record that says how to stop it (the backend and identity, plus the host uid and launchd domain, or the Modal app id and workspace). Destroy uses these records, plus records derived from the graph for state written by v1 amicu, which has none. - The instance is stopped, and the stop is confirmed.
- Only then is that stop record removed. Each record is removed on its own after its stop is confirmed. The deployment is removed from state only after every one of its records has been confirmed and removed.
So a deployment never leaves state before its stop is confirmed. If a stop fails, the deployment and its record stay in state, and the error says which instance may still be running.
destroy refuses, and changes nothing, when the instance cannot be safely acted on:
- The host user differs from the one that started the instance (launchd and systemd records keep the uid). Re-run as that user.
- The active Modal workspace differs from the one the app was deployed in. Switch
MODAL_TOKEN_IDandMODAL_TOKEN_SECRETto that workspace and retry. - A Modal app cannot be found by name and has no recorded app id. Check the Modal dashboard. If it is confirmed gone, run
amicu destroy --target <name> --forget-unconfirmed. This requires a--target, applies only to this case, and removes the record without stopping anything. It works only when the record's recorded workspace is known and matches the active Modal workspace. Otherwise it is refused; for a record with no workspace, the error points toamicu modal stop <app>. - A recorded service file, or a recorded log file when
--purgeis given, is not the file amicu writes for that deployment (wrong directory or wrong name). Nothing is stopped and the record is kept. Fix the state file and re-run.
If the service file still exists after its stop is confirmed, destroy errors and keeps the record, so a re-run retries the removal.
If destroy is interrupted or fails partway, the error lists what was stopped and what remains in state. Fix the cause and re-run the same command (amicu destroy, or amicu apply if apply was the command that stopped). Deployments already stopped are not touched again. See State and backends.
State
State is the record of the last successful apply: the resource graph and the endpoints that were started. It lets plan show a diff and lets apply and destroy stop what you removed.
- The CLI keeps state locally in
.amicu/state/state.json. - State holds secret references (names), never secret values.
- Deployments are recorded before they start, and stay recorded if a later action in the same apply or destroy fails.
Details, including what happens when an apply fails partway, are in Security: State. Locking and backends are in Operate: State and backends.
Exit codes and JSON output
| Code | Meaning |
|---|---|
0 | Success, valid, or no error-severity diagnostics |
1 | Error-severity diagnostics, or fmt --check found drift |
--output json (global flag) makes validate, plan, apply, and doctor emit machine-readable output. See CLI commands.
Last updated