# Change-request engine contract
<!--
ref: @protocol/change-request-engine-contract
version: 1
updated_at: 2026-12-01T03:53:32.028Z
-->

How an engine (the operator's "protocol intelligence" lane, or anybody's runner) works the change requests people dictate on an entry. **Intelligence is ephemeral; the record is the impulse.** An engine reads a thread, asks, proposes, and stops. It never edits the entry. A person (the entry's owner) approves, and approval is what writes the version.

Built on `@protocol/dispatch-protocol`. Read that for register, ask, claim and report; this page says only what is specific to change requests.

## 1. What a thread is

A change request is an impulse in the **entry owner's repo**:

| field | value |
|---|---|
| `type` | `change_request` |
| `entryId` | the entry it is about (`entr_…`) |
| `repoId` | the entry's repo (the owner's, never a shared comments repo) |
| `createdBy` | the requester |
| `status` | `ready` when filed, so `GET /impulse/next` offers it |
| `metadata.base_version` | the entry version when it was filed |
| `metadata.groom` | `true` when marked for grooming (owner or admin sets it); read it, do not set it |
| `metadata.suggestions[]` | proposed edits, see §4 |
| `log` | the chat: `message`, `suggested_edit`, `edit_approved`, `edit_rejected`, `edit_applied_notice` rows |

The title is the first line of what was dictated; `content` is everything, whole. Filing is instant and runs no model.

## 2. Register and ask

```
PUT /runner/<id>        {"type":"engine","lanes":["<owner>+<lane>"],"capabilities":["change_request"]}
GET /impulse/next?repoId=<owner repo>&runner=<id>&claim=true
```

- `capabilities: ["change_request"]` is an allowlist over `type`. A runner without it never receives a thread, and `X-Filtered-Type: <n>` on its 200 or 204 says how many it was kept from. `?type=change_request` on the ask does the same.
- A thread is offered only inside your assignee scope (`X-Assignee-Scope`). A thread assigned to a person is not handed to a runner that did not name that person (#268).
- **You see threads in repos your token can write.** `claim` needs write access to the repo; a 403 `REPO_ACCESS_DENIED` is "you may not", never "someone else won". An engine for one owner's entries uses that owner's token.
- `entryId` is on every candidate's row. Read the entry (`GET /@repo/slug?format=json`) and note its current `version`.

## 3. Claim and report

Exactly as the dispatch protocol: claim with `runnerId` and the candidate's `cycleKey` verbatim, renew a long lease, `complete` or release when done. A second runner cannot claim a held thread (409 `IMPULSE_CLAIM_HELD`). Completing the claim does not close the thread; the thread closes when its request is settled, by the owner or by you logging `becomes: {status:"completed"}` once every suggestion is decided.

## 4. What an engine may post

All of these go through the thread's own routes, under `/entry/<entryId>/change-requests/<threadId>`. You act as the signed-in user whose token you hold.

| act | route | notes |
|---|---|---|
| a question or a reply | `POST /messages` `{text}` | one `message` log row, attributed to you. Ask when the request is ambiguous, before proposing. |
| a status note | `POST /impulse/<threadId>/log` `{action:"note", note}` | the plain impulse log |
| a suggested edit | `POST /suggestions` `{baseVersion, content \| patch, note?}` | exactly one of `content` (the whole new body) or `patch` (a unified diff against `baseVersion`). `baseVersion` must be the entry's current version, else **409 `SUGGESTION_BASE_STALE`** and nothing is recorded: re-read and propose again. A body equal to the current one, or a patch that does not apply, is a 400. |

**Propose the body in the shape the entry stores.** `GET /@repo/slug?format=json` → `.content` is the body *without* the title heading; send the whole of it back, edited. A proposal that adds the `# Title` line shows up in the diff as an added heading (seen on the first prod run). A suggestion is stored in `metadata.suggestions` as `{id, baseVersion, content, diff, note, by, at, state:"pending"}` and logged as `suggested_edit`. The entry is **unchanged**. The panel on the entry renders the `diff`.

## 5. What an engine may NOT do

- **Edit the entry directly** (no `PUT`/`PATCH /entry/…` from a change-request run). Propose it.
- **Act without approval for someone else's request.** Approve and reject are the owner's (write access on the entry's repo) or an admin's: `POST /suggestions/<id>/approve | reject` `{note?}`. Approve writes ONE new entry version, attributed to the approver, and records it in the log; a base that moved since the proposal is refused with 409 `ENTRY_VERSION_CONFLICT`; a decided suggestion cannot be decided again. An engine holding the owner's token may approve only what the owner told it to.
- **Self-apply.** `apply: true` on a suggestion is honoured only when the owner both filed the thread and posts the edit; it is then applied with a visible `edit_applied_notice` row. On anyone else's thread it is a 403 and the suggestion stays pending.
- **Merge or regroup threads, or set `metadata.groom`.** Grouping suggestions are a separate slice; the flag is the owner's.
- **Hold state.** The thread is the memory. Re-read it (`GET /entry/<entryId>/change-requests/<threadId>`) on each run; assume nothing survives between runs.

## 6. The loop, end to end

1. Ask `GET /impulse/next` with `capabilities:["change_request"]` and claim.
2. Read the thread (`content`, the `message` rows) and the entry at its current `version`.
3. If it is unclear, `POST /messages` with one question, release the claim, and stop. A released thread is offered again; read the new messages before you ask or propose again.
4. Otherwise `POST /suggestions` against the current version, then `POST /messages` saying what you changed and why.
5. Complete your claim. The owner approves or rejects; you are not needed for that.

## Limits

A dictated request and a message may each be 100,000 characters; a proposed body 500,000. Over the cap is a 400 that says so, never a silent clip. A byte-identical request from the same person inside 60 seconds returns the existing thread (`X-Impulse-Idempotent-Replay`), so vary the text when filing test requests.

Source: #323 slices (a)–(c); behaviour proved by `backend/test/change-request`.

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*