# Self-update verification plans

`self_update(action="prepare")` takes an optional `verification_plan`, included in the owner approval and stored with the immutable request. Omitting it keeps the HTTP-only verifier and grants nothing new.

```
{"schema":1,"checks":[{"id":"diagnostics","assertion_id":"acceptance-1","entry":"/api/diagnostics","timeout_seconds":10,"max_output_bytes":65536}]}
```

| Field | Rule |
| --- | --- |
| `schema` | Integer `1` |
| `checks` | 1–32, exactly one per assertion (`acceptance-1`, `acceptance-2`, …) |
| `id` | Unique, letters, digits, underscore, hyphen; starts alphanumeric; at most 64 characters |
| `timeout_seconds` | Integer 1–60 |
| `max_output_bytes` | Integer 1–262144; 1–1572864 for `ui:main` |
| `entry` | `/api/commands`, `/api/diagnostics`, `/api/doctor`, `/healthz`, `/chat`, an installed docs page such as `/docs/install/upgrade.html`, `cli:version`, `cli:help`, `test:python`, `ui:main` |

Every field is required. Arbitrary URLs, query strings and unknown fields are rejected before the update is created.

## How checks run

| Aspect | Rule |
| --- | --- |
| Verifier call | `self_update_observe(check_id="diagnostics")`, with no entry or execution arguments. The execution layer applies the approved limits and the original overall deadline. Signed evidence must match the check and assertion. |
| Models | Any conversational model. Without native structured output the answer is still checked against the stage's schema; a failed check makes the verdict inconclusive and the update rolls back. A request ending with no outcome stops the stage at once. |
| Jobs | Verification, diagnosis and repair get the same plan, iteration policy and attempt timeout. A repaired child keeps goal, assertions, check IDs, limits, model and authority, and cannot refresh the deadline. Diagnosis and repair keep only their read tools. |

## `cli:version`, `cli:help`

| Aspect | Rule |
| --- | --- |
| Runs | The installed App's Python with `-I -B -m openprogram` and `--version` or `--help`; never a model-supplied command or PATH lookup. |
| Needs | The native sandbox, a compatible runtime manifest and matching package and App build-revision markers. |
| Access | Private temporary directories; no network, no App or source writes, no owner-home reads outside required runtime and scratch paths. |
| Processes | Single process: the sandbox denies process creation, including detached subprocesses, `fork` and `posix_spawn`. Also for `test:python`; not for source-repair tests or builds. |
| Evidence | Binds runtime identity, invocation and exit status. Nonzero exit, timeout, cancellation, changed identity, excess output or failed cleanup cannot pass. Proves startup and help only. |

## `test:python`

```
{"id":"source-test","assertion_id":"acceptance-1","entry":"test:python","argv":["tests/verify_feature.py","expected"],"timeout_seconds":30,"max_output_bytes":65536}
```

| Aspect | Rule |
| --- | --- |
| `argv` | 1–32 strings, at most 4096 characters, no NUL. Required only for this entry |
| First item | Committed regular `.py` file relative to the candidate root; no symlink, absolute path, parent traversal or interpreter option. Starts with an ASCII letter, digit or underscore, then letters, digits, underscore, slash, dot or hyphen, at most 511 characters |
| Other items | Literal arguments approved up front |
| Runs as | Installed candidate Python, `-I -B SCRIPT ARGS`, from the registered worktree root. Isolated mode does not add that root to the import path; a test importing candidate code must do so itself |
| Access | Registered candidate path readable even under HOME, read-only; other owner-home data not. Temporary data in the private `TMPDIR` or `HOME`. No dependencies installed. The CLI limits above apply |
| Evidence | Missing, dirty or unregistered source or a changed script blocks verification. Records source revision, script digest and invocation. A `candidate_test` result proves source-test execution, not installed-App behavior |

## `ui:main`

```
{"id":"main-capture","assertion_id":"acceptance-1","entry":"ui:main","timeout_seconds":30,"max_output_bytes":1048576}
{"id":"scroll-history","assertion_id":"acceptance-1","entry":"ui:main","timeout_seconds":30,"max_output_bytes":1048576,"interaction":{"kind":"scroll","delta_y":-400}}
{"id":"context-view","assertion_id":"acceptance-1","entry":"ui:main","timeout_seconds":30,"max_output_bytes":1048576,"interaction":{"kind":"view","target":"dag"}}
```

| UI protocol | Capability | Rule |
| --- | --- | --- |
| 1 | Capture | Read-only PNG and accessibility tree of the original session's main window |
| 2 | Capture after scroll | `delta_y`: nonzero integer, −1200 to 1200 CSS pixels; always the original conversation; no selector or script |
| 3 | Perspective | `target`: exactly `session` or `dag` |
| 4 | Readable for rollback only | `test_object` plans and requests are rejected; new packages advertise only the three above |

Both candidate and rollback packages need the protocol, with matching capture, backend and frontend bindings, before installation.

| Aspect | Rule |
| --- | --- |
| Needs | A packaged UI-verification descriptor, runtime identity and exactly one connected main Desktop window. Older packages cannot use this plan. |
| Output | The verifier gets the image and tree, not a path. The limit covers the whole capture JSON with base64 data. PNGs are non-interlaced 8-bit RGB or RGBA, at most 16384 per side and 32 million pixels. |
| Model | Must declare image input. Preparation rejects text-only models; restart recovery and queued Jobs check again; lost support records an error rather than running text-only. |
| Bound to | The active Job, candidate revision, worker, session route and main-window connection. |
| Fails on | Expired, cancelled, replayed or mismatched requests, user input, navigation, window changes, conflicting capture resources, excess output or incomplete cleanup. |
| Not allowed | Arbitrary URL, JavaScript, target window, click, navigation, data change or other side effects. |
| During capture | That window's new network requests, native IPC and external navigation are rejected. Marked HTTP requests are refused by the backend, including authentication bootstrap and stale markers. Its WebSocket accepts only observation replies and cancelling the exact verifier Job. |
| Released | Before evidence upload, even on failure. Other windows and running requests are unaffected. |
| Scroll | The capture shows the after-scroll state; evidence records before, after and restored metrics. Position is restored before success and never persisted. Failed attempts restore their own scroll while target and deadline hold; user interruption cancels without restoring. Target change or failed restoration cannot pass. Unmoved at a boundary proves nothing alone. |
| Perspective | Starts on the visible original conversation, uses the real control, captures, restores conversation and scroll before success. Already selected DAG, missing or replaced control, interruption or failed restoration cannot pass. `session` does not switch and cannot prove a switch. |
| Perspective state | Nothing is persisted, including through background tab updates. On interruption the user's selection is kept. Failed restoration may leave the requested view showing and reports failure. |
| Proves | Only claims about the captured state; unobserved interactions stay inconclusive. HTTP responses, including `/chat` HTML, do not prove rendered behavior. |

[Update from chat](https://fzkuji.github.io/OpenProgram/docs/install/conversational-self-update.html) · [Self-update rollback](https://fzkuji.github.io/OpenProgram/docs/install/self-update-rollback.html)
