# Stable and development instances

Stable is the official App from a GitHub Release, changed only by its own updater. Commits go to `dev` and run on the development instance. A deploy does not restart stable, so a stable conversation can deploy and check `http://127.0.0.1:18200`.

|  | Stable | Development |
| --- | --- | --- |
| Code | the published release (Developer ID signed) | the commit deployed last, `dev` by default |
| Runs as | `/Applications/OpenProgram.app` | `/Applications/OpenProgram Dev.app` (macOS) or a browser; runtime in `~/.openprogram-dev/runtime` |
| Port | `18100` | `18200` |
| Browser debugging port | `9223` | `9224` |
| State | `~/.openprogram` (default profile) | `~/.openprogram-dev` (`dev` profile) |
| Updated by | its own updater: [Settings → General → Application](https://fzkuji.github.io/OpenProgram/docs/install/upgrade.html) | `openprogram dev deploy`, then `scripts/local-instances/refresh-dev-instance.sh` |

Rules: `openprogram/operations/worker/dev_instance.py`. `openprogram dev status` shows the stable App's release version and health, the development instance's commit and health, and the `dev` commits not deployed yet.

## Deploying to the development instance

`openprogram dev deploy [ref]` (default `dev`) checks the commit out into the detached worktree `~/.openprogram-dev/source` and runs `scripts/local-instances/refresh-dev-instance.sh` there. Nothing of stable is stopped or written.

1. Refuse uncommitted or untracked files. One deploy runs at a time; a second waits.
2. Sync the Git hooks and report docs findings since the last deploy, without stopping. Build the Web assets and the OpenProgram wheel; a page that breaks the format becomes a visible error page.
3. The Web export is built only when a tracked file other than Python, the documentation and the tests changed since the last deploy; otherwise the last export is staged again.
4. Install a full CPython 3.12 into the runtime once (`uv python install --install-dir`), sync the locked dependency set a release installs, reinstall the wheel.
5. macOS: build the helper `OpenProgram Dev.app` (`ai.openprogram.runtime.dev`) and point `runtime-manifest.json` at it. The worker gets its own identity, so Screen Recording, Accessibility and similar grants are separate from stable.
6. Set the `dev` profile's port and bind the Program catalog.
7. Install or restart only the `dev` worker as a login service (launchd or systemd; a plain stop and start elsewhere). Wait up to 300 seconds for `/healthz`, then record the commit in `runtime/source-revision`.
8. macOS: run `scripts/local-instances/install-dev-app.sh`.

**The development App**

| Aspect | Behaviour |
| --- | --- |
| Identity | `/Applications/OpenProgram Dev.app`, bundle id `ai.openprogram.desktop.dev`; macOS only |
| Contents | The deployed commit's Desktop shell, no runtime. `Contents/Resources/instance.json` names the `dev` profile, port, debugging port and runtime; `apps/desktop/main/instance.js` reads it. |
| Worker | Started and authenticated through the development runtime under `OPENPROGRAM_PROFILE=dev` |
| Electron data | `~/Library/Application Support/OpenProgram Dev` |
| Ignores | The stable App's install lock and release updates |
| Build | `scripts/release/build-desktop-shell.sh`: electron-builder with the release configuration minus the runtime, so the Electron pinned in `apps/desktop/package.json` runs here first. Built only when `apps/desktop` or the lockfile changed; otherwise the shell kept in `~/.openprogram-dev/desktop-shell` is named, signed and installed |
| Signing | `local-macos-signing.py sign --development`, the local identity; signs the outer App alone |
| Install | Built next to the stable App, never into it. The bundle is swapped while the App is closed and reopened if it was open, in front only when the user was in it. |
| Browser tool | `programs/applications/browser/app_endpoint.py` picks the debugging port by profile, so the development agent never drives the stable App's tabs |

### Signing in

The worker mints a new owner token on every start, so a deploy signs out browsers. The development App fetches its new token itself.

| Command | Result |
| --- | --- |
| `openprogram dev open` | Opens the default browser, signed in; the sign-out message names this command |
| `openprogram dev auth-url` | Prints a sign-in link for another browser |

### State and models

The credential store's root is the active profile's state directory, so the `dev` profile never reads or refreshes default-profile logins. `openprogram dev copy-models` brings over the model setup:

| Copied | Not copied |
| --- | --- |
| Config keys `providers`, `last_used_model`; each company's API keys | OAuth logins: their refresh tokens rotate, so two instances would sign each other out. Sign in again if needed. |
| API-key and CLI-delegated credentials (read another tool's login by reference) | Conversations, Agents, memory |

The ChatGPT login is shared: the development instance reads the Codex CLI's `~/.codex/auth.json`, and the stable instance mirrors its login of the same account into that file. Each adopts the newer login the other wrote instead of spending a used refresh token ([One ChatGPT login per machine](https://fzkuji.github.io/OpenProgram/docs/reference/design/providers/auth/unified-auth-storage.html#codex-shared-login)).

### From a conversation

In the development instance (the `dev` profile, with a source repository that has a `dev` branch), `self_update(action="prepare")` uses the `dev_deploy` backend: a change is a commit on `dev`, and deploying it is the whole update. The call saves the request and starts a detached controller; the rest runs after the calling turn is saved.

| Step | What happens | Phase |
| --- | --- | --- |
| 1 | Wait for the calling turn to be saved | `preparing` |
| 2 | Rebase the candidate onto `dev` in its worktree, then `git merge --ff-only` in the primary checkout. A moved `dev` or a held `index.lock` retries up to 10 times with backoff | `building` |
| 3 | `openprogram dev deploy <sha>`, which restarts the worker the request came from; skipped when the instance already serves the commit | `building` |
| 4 | System probe against port 18200 and the `dev` state directory, then a browser probe: open the signed-in Web app until the message box appears | `building` |
| 5 | The result reaches the origin conversation through the ordinary delivery and follow-up turn on the restarted worker | `succeeded` |

The probe compares the doctor rows with the instance's own before the change, so a row already failing, such as a login development lacks, blocks nothing. The stable App is never waited for or touched.

| Ends as | When |
| --- | --- |
| `succeeded` | The development instance serves the landed commit and passes both probes |
| `aborted` | The calling turn never ends; a rebase conflict or a dirty file in the way (lists the files); the deploy or a probe fails. A commit that landed stays on `dev`, and the result says so: the fix is the next commit, made and deployed like any other |

In the official App the same call is refused before any request is saved: the App is Developer ID signed and cannot be rebuilt here, so the refusal points to **Check for updates** in Settings.

**Controller**

| Aspect | Behaviour |
| --- | --- |
| Backend | Picked by `openprogram/operations/self_update/control/backend.py`; this one is `control/dev_deploy.py` |
| Location | A private copy of the runtime under `<state>/self-updates/<id>/controller`, outside the development runtime: the deploy replaces that runtime, and the code imports lazily |
| Runs as | A launchd job on macOS, a detached session elsewhere, with neither a session nor a profile in its environment. A worker start restarts one that died |
| Restart | Steps are idempotent. A journal in the update's directory records the landed commit, so a restart continues from its phase |
| Undo | `self_update(action="undo", target=<commit>)` makes a `git revert` in a worktree of `dev` and submits it as a normal `prepare` |
| Retry | `self_update(action="retry")` does not apply; a fix is a new `prepare` |

## Publishing

Neither instance pushes anything. See [Publishing source to GitHub](https://fzkuji.github.io/OpenProgram/docs/reference/design/distribution/github-publishing.html).

## Source checkout

`openprogram dev` and the self-update controller find the repository through `OPENPROGRAM_SOURCE_REPO`, else `~/.openprogram-dev/source-repo`, which `scripts/local-instances/refresh-dev-instance.sh` writes with the main checkout, not the build worktree.

## Implementation status

| Status | Items |
| --- | --- |
| Implemented | `scripts/local-instances/refresh-dev-instance.sh`, `openprogram dev status\|deploy\|open\|auth-url\|copy-models`, the development runtime's macOS identity and login service, per-profile credentials, in-chat self-update through the `dev_deploy` controller |
| Not yet | The development instance is reachable only from this machine |
