State
What amicu records after apply, what it never records, and what happens when apply fails partway.
Where it lives
The CLI keeps state in the project directory, in .amicu/state/state.json. Writes are durable: amicu writes a uniquely named temporary file, syncs it to disk, keeps the previous version as state.json.bak, renames the new file into place, and syncs the directory. If state.json is ever missing or corrupt, amicu stops with an error that points at state.json.bak instead of silently using it. local is the only backend the CLI implements. See State and backends for locking and recovery.
What it contains
- The resource graph from the last successful apply: models, hardware profiles, deployments, and policy resources as parsed from your HCL.
- The endpoints that were started: deployment id, runtime handle id (the service label or Modal app id), the endpoint URL, and whether it is loopback or public.
- Deployments marked
pending: starts not yet confirmed, or Modal apps that a drift check could not find by name. Apply and destroy write them before a provider starts or stops anything. - Stop records: for each deployment, what is needed to stop it later (the backend and identity, plus the host uid and launchd domain, or the Modal app id and workspace). For a host service, the record also holds the path of its service file and of its log files. For a Modal app, it holds the names of the cache volumes the app mounts. A record is removed only after its stop is confirmed.
- Fingerprints: SHA-256 digests of the secret pins (the
versionof eachapi_keyreference), the container image, and the binary path, used to detect changes between plans. The raw values are not stored. - The project id, which scopes the host service labels.
The service files of a host deployment are outside state: the launchd plist, or on Linux the systemd unit file and its 0600 environment file. The environment file holds the endpoint API key. amicu destroy deletes these files after it confirms the service is stopped. See Secrets.
What it never contains
- Secret values. A secret-designated field is stored as a reference with its name (and optional scope and version), not its value.
- API keys, Modal tokens, proxy tokens, or
HF_TOKEN. - Prompts or completions. Amicu is not in the request path.
State is per machine. The lock is a local operating-system lock and does not protect state shared through version control or copied between machines, so do not commit .amicu/; amicu init adds it to .gitignore. Saves are compare-and-swap on a monotonic state serial, so a second concurrent run on the same machine fails instead of overwriting (shared or synced state is still unsupported); a shared backend is planned.
State still describes your infrastructure (URLs, hardware, ids), so treat it as sensitive and keep it out of public repositories.
When apply fails partway
Deployments are started one after another. Before a provider starts a deployment, amicu records it in state as pending, with a stop record that says how to stop it, so a failure mid-start still leaves something amicu destroy can stop. If one fails, deployments that were already started in the same run stay recorded, and the error lists them. A Modal app that is recorded but not found by name is kept in state, not forgotten. How Modal apps are named, and the one-time rename of apps made by earlier versions, is in State and backends.
- If the endpoint check fails for a new deployment, amicu stops that endpoint and exits with an error. The deployment stays in state as pending, because it may still be running.
amicu destroy --target <name>confirms its stop. - If the endpoint check fails after a Modal update, amicu rolls the app back to the previous version and checks that version again before it reports it as serving. The rollback happens only when the new deployment went into the same Modal app that was serving. If that succeeds, apply still fails, and the error says the new version was rolled back to version N and verified, and that the previous deployment (its app id) is still serving. If the rollback fails, if the previous version is not closed, if there is no previous version, or if amicu cannot read the app's version history, amicu stops the whole app (fail closed). If that stop also fails, the error gives the
modal app stop <app id>command to run by hand. - Preflight failures (unsupported provider, missing
api_key, missing Modal proxy tokens) happen before anything starts, so state is unchanged.
To recover, fix the cause and run amicu apply again. The plan is recomputed from the recorded state, so deployments that already succeeded show no change and apply finishes the rest. Use amicu plan to see what remains.
Backends
The state interface supports other backends (the hosted server uses Postgres), and init writes state.backend: local to .amicu/config.yaml. The CLI does not select another backend yet. If you run your own database for a server, encrypt it at rest; amicu does not encrypt state at the application layer by default.
Last updated