# Upgrade source checkouts

A gated `git pull` and restart: a bad commit fails in a throwaway process rather than in the service you would use to fix it. For Desktop and managed releases, including v0.6.6 to v0.7.0: [Upgrade](https://fzkuji.github.io/OpenProgram/docs/install/upgrade.html).

| Goal | Command |
| --- | --- |
| What would change? Read-only | `openprogram upgrade status` (`--json`: `head_sha`, `target_sha`, `update_available`) |
| Print the plan | `openprogram upgrade --dry-run` |
| Do it | `openprogram upgrade` |

## Steps

| Step | Does | Fails with |
| --- | --- | --- |
| 1 preflight | Refuses a dirty tree, resolves the target, asks before a downgrade | `dirty-worktree`, `downgrade-needs-confirmation` |
| 2 checkout | Fast-forwards to the target | `checkout-failed` |
| 3 deps | `pip install -e .` if `pyproject.toml` or `setup.py` changed; `npm ci` if `package-lock.json` changed | `deps-failed` |
| 4 build | Rebuilds `apps/web` or `apps/cli` if that workspace or `package-lock.json` changed | `build-failed` |
| 5 probe | Boots the new code on a scratch port under an isolated profile, waits for `/healthz`, runs doctor, kills it | `probe-failed` |
| 6 restart | Restarts the real service | `restart-failed` |
| 7 verify | Polls until the service reports the new commit | `verify-failed` |

The running service is untouched before step 6. The first failure stops the chain, prints the code and exits non-zero. Progress: `~/.openprogram/upgrade-state.json`.

## When a step fails

| Code | What to do |
| --- | --- |
| `dirty-worktree` | Commit your changes |
| `downgrade-needs-confirmation` | The target is older, and old code may not read config written by new code. `--yes` if you mean it |
| `probe-failed` | The new code does not boot. Nothing restarted; the fix belongs upstream |
| `verify-failed` | The restart happened but the service does not report the new commit. No automatic rollback; run the printed command: `git -C <repo> checkout <previous-sha> && openprogram restart` |

## Flags

| Flag | Effect |
| --- | --- |
| `--dry-run` | Plans only; changes no checkout, worker or upgrade state. An explicit `--channel` is still persisted |
| `--no-restart` | Stops after the probe. The checkout moves; the service keeps old code until you restart it |
| `--yes`, `-y` | Allows a downgrade |
| `--channel NAME` | Follows another line and persists it as `update.channel`. Only `stable`, which here tracks `origin/main`, is built in. It is not the stable GitHub Release |
| `--json` | Machine-readable result with every step |

**Sample output**

```
$ openprogram upgrade status
  channel        stable (origin/main)
  head           f5671fd25e4c6ae89e6d77f3fcffc4d4a2c0570a
  target         a2d7f95633527e182ac850e40aca727aa0f6a3e6
  update         available

$ openprogram upgrade --dry-run
  [OK  ] preflight  stable → origin/main: 80d77d1ed44c → 1a4101433b13
  [OK  ] checkout   planned (dry run)
  [OK  ] deps       planned (dry run)
  [OK  ] build      planned (dry run)
  [OK  ] probe      planned (dry run)
  [OK  ] restart    planned (dry run)
  [OK  ] verify     planned (dry run)
```

`openprogram update` (`--check`, `--force`) is a leftover that raises `ImportError`. Use `openprogram upgrade`.

[Troubleshooting](https://fzkuji.github.io/OpenProgram/docs/server/troubleshooting.html)
