# Run the operator services

> Start the services, configure credentials, and inspect their HTTP APIs, events and error codes.


Each domain service owns a PostgreSQL schema and exposes an HTTP API. The customer gateway composes account views on demand. The Desk reads those APIs, and signed events carry contract changes between services.

| Service | Port | Owns | You can replace it with |
|---|---|---|---|
| **contractd** | 9401 | Customers, billing accounts, contracts, subscriptions, identifiers; the renewal and ending passes; the renewal notice | Your CRM or order system |
| **billd** | 9402 | Price books, usage, the open bill, sealed bills and their documents, Stornorechnungen and staged booking commands | Another billing engine |
| **usaged** | 9403 | Outbound voice classification, switch receipts, itemisation and its retention | Your mediation platform |
| **accountingd** | 9404 | Invoice balances, bank receipts and journal | Your ERP |
| **chargingd** | 9405 | Network quota, settlement and session evidence | Your charging function |
| **portald** | 9406 | Customer API, combined overview and mailbox | A compatible customer gateway |
| **agentd** (optional) | 9408 | Read-only investigations and their local run journal | An operator assistant |

Commands and queries are REST. Facts cross as [CloudEvents](https://cloudevents.io) over
[Standard Webhooks](https://www.standardwebhooks.com): contractd delivers each event,
signed and in order, to billd's `/inbox`; billd reads the resource's current state from
contractd and bills from its own copy. A late fact is corrected by the next bill, never
by re-opening a sealed one.

## Run them

```bash
just demo         # Docker Compose: the estate from one image, a year of bills, the Desk on :9400
just dev          # Local services and the Desk on port 5179, with PostgreSQL in Docker
just seed         # a year of bills into just dev
just listen       # every event as it happens
just conformance contractd http://127.0.0.1:9401
```

Compose binds the [Desk](../docs/desk/) to loopback on port 9400 and the headless customer API on 9406. The service binaries in the Compose demo support the `healthcheck` command for container probes.

Use `GET /health/live` for liveness and `GET /health/ready` for readiness. A domain service returns 503 when its database is unavailable. Its `GET /health` endpoint reports service-specific status.

Service configuration:

| Variable | Meaning |
|---|---|
| `TELCO_LISTEN` | Default `127.0.0.1:9401` (contractd), `127.0.0.1:9402` (billd), `127.0.0.1:9403` (usaged), `127.0.0.1:9404` (accountingd), `127.0.0.1:9405` (chargingd), `127.0.0.1:9406` (portald). agentd reads `AGENTD_LISTEN` (default `127.0.0.1:9408`) |
| `TELCO_DATABASE_URL` | The runtime role's connection: `contractd_app`, `billd_app`, `usaged_app`, `accountingd_app` or `chargingd_app`, DML on its own schema only |
| `TELCO_MIGRATION_URL` | The owner's connection (`contractd_owner`, `billd_owner`, `usaged_owner`, `accountingd_owner`, `chargingd_owner`). When set, the schema is applied and the runtime role granted |
| `TELCO_RUNTIME_ROLE` | Defaults to the service name plus `_app` |
| `TELCO_API_KEYS` / `TELCO_API_KEYS_FILE` | Named keys, `;`- or line-separated: `name role secret [patterns]`. Use secrets of at least 16 characters. Optional patterns limit visible events. See [Keys and roles](#keys-and-roles) |
| `TELCO_WEBHOOK_KEY` | The master key webhook secrets are derived from (≥ 32 bytes); webhooks need it |
| `TELCO_CLOCK` | `system` (the Europe/Berlin date) or `test:YYYY-MM-DD` |
| `TELCO_ENVIRONMENT` | `production` (the default: refuses a test clock and plain-http links), `development` or `test`. usaged requires named API credentials in every environment |
| `TELCO_PASS_INTERVAL_SECS` | Default 3600 |
| `TELCO_OPERATOR` | **Required.** A TOML file with the operator every document names ([example](../examples/operator.example.toml)); a field § 62 TKG or § 14 UStG requires that is missing stops the start |
| `TELCO_PUBLIC_PLANS` | Exact pinned tariffs served by billd’s anonymous `/mcp/public` checker, comma-separated. Empty by default. |
| `TELCO_MCP` | `on` enables the authenticated read tools and billd’s scoped proposal tools. Defaults to off. |

contractd also reads:

| Variable | Meaning |
|---|---|
| `TELCO_RENEWAL_NOTICE_LEAD_DAYS` | Default 30 |
| `TELCO_SUBSCRIBERS` | Where events go: `billd=https://billd.example/inbox,crm=…` |
| `TELCO_SUBSCRIBER_<NAME>_SECRET` (or `…_SECRET_FILE`) | The signing secret per subscriber: `whsec_` + base64, or at least 32 bytes |
| `TELCO_SUBSCRIBER_<NAME>_TYPES` | Optional type patterns, e.g. `de.telco.contract.*` |

billd also reads:

| Variable | Meaning |
|---|---|
| `TELCO_SOURCE_URL` | Where contract facts are read: contractd, or what stands in its place |
| `TELCO_SOURCE_TOKEN` (or `…_FILE`) | billd's own token for those reads |
| `TELCO_INBOX_SECRETS` (or `…_FILE`) | The secrets a delivery may be signed with, comma-separated (rotation: list old and new) |
| `TELCO_PRICEBOOKS` | A directory of price-book directories; a plan assignment pins `id@version` |
| `TELCO_ACCOUNTING_URL` | Accounting service or ERP base URL |
| `TELCO_BOOKING_TOKEN` (or `…_FILE`) | Dedicated booking credential for that service |

usaged reads `TELCO_VOICE_PLAN`, `TELCO_BILLD_URL` and `TELCO_MEDIATION_TOKEN`. For subscriber itemisation it also reads `TELCO_EVN_PROTECTED_FILE`. [Configure switch intake](../docs/voice-imports/) · [Configure itemisation](../docs/voice-itemisation/)

For the standalone OpenAPI contract and mailbox read receipts, see [Build on the customer portal API](../docs/portal-api/). For customer sign-in, scoped service credentials, the cancellation form and verification links, see [Host the fibre customer portal](../docs/selfcare/).

For chargingd peer URLs, named network clients, quota and operator routes, see [Online charging](../docs/online-charging/).

accountingd configuration and operations are described in [Reconcile bank payments](../docs/payments/).

| Variable | Meaning |
|---|---|
| `TELCO_LEDGER_ID` | The ledger's id (default `telco.local/books`); the ledger lives in schema `ledger` |

Outside development, every URL must be `https` (loopback excepted). Each service checks
its configuration before starting and lists every problem at once, never a secret.

## Guarantees

- **Each domain service owns its data.** One schema and one role pair per domain service; a runtime
  role has no right on the other's schema, so a cross-service query is a permission
  error, not a convention.
- **One transaction per change.** Every state change commits with an append-only fact
  and its event, or none of them does — the event is the outbox.
- **History is append-only.** Facts, events, bills, their charges and files, and the
  inbox refuse UPDATE and DELETE, even to the owner.
- **Nothing lost, nothing applied twice.** A subscriber's cursor moves only after a 2xx;
  billd takes each event id once, in the transaction of its effect.
- **No full IBAN in billd.** contractd's reads serve it masked; billd stores and prints
  only `DE…3000`.
- **No overlaps.** The database refuses overlapping plan assignments and an identifier
  held twice, also when two requests race.
- **One clock.** Business dates come from the injected clock; a guard refuses
  `now()`/`current_date` in the services' SQL.

## Replace a service

Domain services publish their HTTP operations in OpenAPI. Event producers also publish a catalogue with each event’s meaning and source. To stand where **contractd** stands, a CRM:

1. emits the contract facts — `de.telco.customer.*`, `de.telco.billing-account.*`,
   `de.telco.contract.*`, `de.telco.subscription.*` — as signed CloudEvents to billd's
   `/inbox`, subject `contract/{id}` and so on;
2. serves four reads billd calls with its own token: `GET /customers/{id}`,
   `/billing-accounts/{id}` (IBAN masked), `/contracts/{id}`, `/subscriptions/{id}`
   (with the plan assignments).

Then hold it to the boundary:

```bash
just conformance contractd https://crm.example --ids <customer>,<account>,<contract>,<subscription>
just conformance billd https://billd.example --secret "$TELCO_INBOX_SECRET"
```

Every check prints `✓` or `✗` with what was expected. The reference services pass the
same kit in `just test-db`. To skip a service altogether, embed the crates
(`telco-core`, `telco-render`, `telco-events`) and call the domain directly.

## Delivery and the inbox

A delivery is `POST <subscriber>` with `content-type: application/cloudevents+json`
and the headers `webhook-id` (the event id), `webhook-timestamp` and
`webhook-signature` (`v1,` + base64 HMAC-SHA256 of `{id}.{timestamp}.{body}`).

| The receiver answers | contractd does |
|---|---|
| 2xx | Moves the cursor past the event |
| 410 | Pauses the subscriber (health shows it) |
| anything else, or no answer | Stops that subscriber and retries after 1 s, doubling to 5 min |

Events reach a subscriber in sequence order; a type filter skips but still moves on.
contractd's `GET /health` shows each subscriber's pending events, attempts and last
error.

billd's `POST /inbox` refuses a body over 64 KiB, then a signature that does not verify
or a timestamp more than five minutes off (`401 inbox.unauthenticated`) — before
reading or writing anything. A subject other than `customer|billing-account|contract|
subscription` + `/` + a UUID is taken as `ignored` and never requested. It answers
`{"outcome": "applied" | "ignored" | "gone" | "duplicate"}`, or `503
inbox.source-unavailable` when the source cannot be read, so the sender tries again.

## The test clock

Advance the test clocks in service order. Set contractd first with `PUT /clock`. Its response reports the events it delivered and lists any subscribers still behind. Set accountingd next to reevaluate prepaid month boundaries. Advance chargingd to expire outstanding grants. Advance billd to seal invoices with the delivered facts, then usaged for traffic-data retention. Zeitreise, `telco demo` and `just demo-signup` advance all five clocks.

## API

Private routes require `Authorization: Bearer <key>`. Each domain service documents its public and signed-ingress routes. portald publishes its contract at `/api/v1/portal/openapi.yaml`. Bodies refuse unknown fields. Each
service's OpenAPI 3.1 document is `services/<service>/openapi.yaml`; a test keeps it
equal to the router's route table and to every problem code the service can return.

### Keys and roles

Each caller has its own named key, so the log, the webhooks and a revocation name *who*:

```sh
TELCO_API_KEYS="desk operator $DESK_KEY; crm integration $CRM_KEY contract,customer; bi read $BI_KEY"
```

| Role | May |
|---|---|
| `operator` | The Desk, carrier order registration and oversight, every webhook, the test clock, credit notes and sealed rating case exports |
| `integration` | Read, and the business operations an integration performs (sign-up, approval, termination, usage, its own webhooks) — not `PUT /clock`, not `POST /bills/{id}/credit-note` |
| `field` | Submit field evidence on assigned appointment cases |
| `booking` | Submit accounting bookings, statutory credits, validated prepaid enrollments and rated charge revisions. Read the account receivable and reviewed credit basis. Execute approved goodwill and tariff changes. |
| `fault-desk` | Supply timestamped outage and repair observations. Each managed incident binds to the original sender. |
| `investigator` | Read the paired invoice evidence from billd for the private Desk investigator. |
| `billing-source` | Read the four contract resources and approved appointment and outage awards from contractd as billd. |
| `outage-receipt` | Read the posted outage receipt from accountingd as contractd. |
| `read` | General read APIs and MCP's read-only tools |
| `finance` | Preview, issue, list and retrieve DATEV batches on accountingd. A separate credential on billd reads the period’s pending booking count. [Finance export](../docs/finance-export/) |
| `mediation` | Deliver classified fixed-line batches to billd and read the frozen invoice facts needed for itemisation and deletion. |
| `switch` | Import mobile batches at billd or outbound voice CSV and JSON at usaged as the named source. Read its voice receipts. [Mobile usage](../docs/mobile-usage/) · [Voice imports](../docs/voice-imports/) |
| `bill-reader:<account-uuid>` | List and retrieve sealed bills for the account through TMF678. [Partner bills](../docs/tmf-bills/) |
| `usage-reader:<account-uuid>` | List and retrieve accepted mobile traffic records for the account through TMF635. [Partner usage](../docs/mobile-usage/) |
| `reviewer` | Inspect the queue and approve or reject a proposal under a personal identity. |
| `proposer:<account-uuid>` | Capture evidence, draft checked answers and propose remedies for one account. |
| `reply-delivery` | Poll approved customer replies and acknowledge delivery. |
| `prepaid-oss` | Poll prepaid network proposals and acknowledge one revision. [Network controls](../docs/prepaid/) |
| `customer:<account-uuid>` | Access the account’s portal, invoices, eligible itemisation, prepaid wallet and mobile meters. The authenticated customer portal holds the credential. [Customer meter](../docs/mobile-usage/) |
| `carrier` | Read its own orders and submit S/PRI messages. The two carrier routes are restricted to the permissions described in [Open-access provisioning](../docs/open-access/). |

A missing or invalid bearer token receives `401 auth.missing` with a Bearer challenge. A valid key with insufficient permissions receives `403 auth.forbidden`, identifying the configured key name, its role and the route. The optional
patterns (`contract,customer.moved`; a bare aggregate means all its types) limit which
events the key sees — on `GET /events` and on every webhook it owns. Keys are compared in
constant time and never logged. A test holds the role table against every route in the contract, billing and accounting services.

### Rotate an API credential

Keep the caller name when replacing a secret. For example, during a CRM rotation the
following command adds a replacement to an existing inline configuration. It assumes
that the current CRM entry uses the role and patterns shown above:

```sh
export TELCO_API_KEYS="${TELCO_API_KEYS:?existing entries required}; crm integration ${CRM_NEW:?replacement required} contract,customer"
```

1. Add the replacement entry alongside the existing entries in your deployment. Roll
   out the configuration to every contractd and billd replica that accepts this caller.
   Both secrets authenticate as `crm`.
2. Switch clients to the replacement secret. Check a protected request such as
   `GET /webhooks` on each service. Existing subscriptions still belong to `crm`, and
   retrying a POST with its original idempotency key returns its original response.
3. Remove the old entry and roll out the configuration again. A replica rejects the
   retired secret with `401 auth.missing` once it has restarted with the new configuration.

The same procedure works with one entry per line in `TELCO_API_KEYS_FILE`. Put the
actual secret values in that file. The inline and file entries are validated together.
Each secret must be unique. Entries sharing a name must have the same role and event
patterns after shorthand expansion, sorting and deduplication. Empty entries inside
a comma-separated pattern list are refused. Omitting the pattern field grants all events.

### Retrying safely

On contractd and billd, a retriable business `POST` may carry `Idempotency-Key: <1–255 visible characters>`. A retry with the same
key gets the first answer again, with `Idempotent-Replayed: true` — never a second
customer, contract or credit note. Keys belong to the caller (two callers may use the same
string) and to the request: the same key with another method, path or body is `422
idempotency.mismatch`; a retry while the first is still running is `409
idempotency.in-progress`. A `5xx` answer is not kept, so it can be retried; everything
else is kept 24 hours.

### Webhooks

`POST /webhooks`, `GET /webhooks`, `GET|DELETE /webhooks/{name}`,
`POST /webhooks/{name}/test`, `GET /webhooks/{name}/deliveries`,
`POST /webhooks/{name}/replay` — an integration registers and runs its own subscriber; see
[Webhooks](../docs/webhooks/).

For resource paths, parameters and response schemas, open the service’s `GET /openapi.yaml`. The [sales guide](../docs/selling/) covers signup and quotes. The [billing guide](../docs/billing/) covers invoice holds, sealing and usage.

## MCP

With `TELCO_MCP=on`, contractd and billd expose stateless read tools at `/mcp` on their own ports. Each uses the same service function as its REST counterpart. billd also exposes `propose_credit`, `propose_plan_switch` and `propose_dispute_answer` at `/agent/mcp`. These tools create Desk items for human review. [Review a proposal](../docs/agent-assistance/)

The anonymous `/mcp/public` endpoint exposes only quotes and receipt checks over the configured public catalog. [Publish a tariff](../docs/public-checks/)

| Service | Tools |
|---|---|
| contractd | `get_customer`, `get_contract`, `get_contract_dates` (the § 4 block and when a termination arriving on a day would take effect, with the rule), `get_subscription` |
| billd | `get_bill`, `explain_bill` (every line with its „Warum?" — quote it, never recompute it), `list_bills`, `get_open_bill`, `list_price_books`, `quote_plan` (what a plan will cost from a day) |

## Problems

Errors are `application/problem+json` (RFC 9457) with `code`, `detail`, and `rule` and
`fix` where they apply, and `pointer` — a JSON pointer into the request
(`/account/iban`) — where the problem is about one part of it. Each problem's `type`
links to its row here. They never echo personal data from the request.

| Code | Status | Meaning |
|---|---|---|
| <a id="auth.missing"></a>`auth.missing` | 401 | No token, or a wrong one |
| <a id="auth.forbidden"></a>`auth.forbidden` | 403 | The key's role may not do this ([Keys and roles](#keys-and-roles)) |
| <a id="request.invalid"></a>`request.invalid` | 422 | Unknown field, wrong type, missing reference, or a value out of range |
| <a id="request.too-large"></a>`request.too-large` | 413 | Body over 64 KiB |
| <a id="not-found"></a>`not-found` | 404 | No such resource |
| <a id="internal"></a>`internal` | 500 | Something failed that the request did not cause; the log has the detail |
| <a id="idempotency.invalid"></a>`idempotency.invalid` | 422 | An `Idempotency-Key` that is not 1–255 visible ASCII characters |
| <a id="idempotency.mismatch"></a>`idempotency.mismatch` | 422 | The key was used for another request; use a new key |
| <a id="idempotency.in-progress"></a>`idempotency.in-progress` | 409 | The first request with this key is still running; retry in a moment |
| <a id="webhook.url-forbidden"></a>`webhook.url-forbidden` | 422 | Not `https`, credentials in the URL, or a host that is not public |
| <a id="webhook.exists"></a>`webhook.exists` | 409 | A webhook or configured subscriber has this name |
| <a id="webhook.configured"></a>`webhook.configured` | 409 | A configured subscriber is changed in the configuration, not the API |
| <a id="webhook.limit"></a>`webhook.limit` | 409 | A key owns at most 20 webhooks |
| <a id="webhook.unconfigured"></a>`webhook.unconfigured` | 503 | The service has no `TELCO_WEBHOOK_KEY` |
| <a id="webhook.orphaned"></a>`webhook.orphaned` | 409 | The key that owns the webhook is not configured |
| <a id="signup.conflict"></a>`signup.conflict` | 409 | The order reference was already signed up with another request; the same request again answers the first answer |
| <a id="contract.term-too-long"></a>`contract.term-too-long` | 422 | § 56 Abs. 1 TKG |
| <a id="contract.notice-too-long"></a>`contract.notice-too-long` | 422 | § 309 Nr. 9 lit. c BGB |
| <a id="contract.invalid-terms"></a>`contract.invalid-terms` | 422 | Out of range |
| <a id="contract.awaiting-approval"></a>`contract.awaiting-approval` | 409 | § 54 Abs. 3 TKG: activation before approval |
| <a id="contract.state"></a>`contract.state` | 409 | The contract's state does not allow this |
| <a id="contract.not-effective"></a>`contract.not-effective` | 409 | Not an effective contract |
| <a id="contract.already-terminated"></a>`contract.already-terminated` | 409 | A termination is already recorded |
| <a id="contract.no-transparency-block"></a>`contract.no-transparency-block` | 404 | A business contract, or a term of one month or less |
| <a id="contract.addon-extends-term"></a>`contract.addon-extends-term` | 409 | § 66 Abs. 3 TKG |
| <a id="subscription.transition"></a>`subscription.transition` | 409 | A lifecycle step that is not allowed |
| <a id="subscription.plan-overlap"></a>`subscription.plan-overlap` | 409 | The database refused an overlapping assignment |
| <a id="identifier.taken"></a>`identifier.taken` | 409 | Another subscription holds this identifier in that period |
| <a id="account.parent-mismatch"></a>`account.parent-mismatch` | 422 | The parent account must belong to the same customer |
| <a id="account.customer-mismatch"></a>`account.customer-mismatch` | 422 | The billing account must belong to the customer |
| <a id="account.invalid-iban"></a>`account.invalid-iban` | 422 | The IBAN fails its check digits or national format |
| <a id="account.mandate-incomplete"></a>`account.mandate-incomplete` | 422 | A direct debit without mandate reference, signature date or IBAN |
| <a id="account.no-creditor-id"></a>`account.no-creditor-id` | 409 | The operator has no creditor id, so it cannot collect by direct debit |
| <a id="letter.not-applicable"></a>`letter.not-applicable` | 409 | No renewal notice: business, non-renewing or terminated contract, or past the last day to cancel |
| <a id="voice.delivery-pending"></a>`voice.delivery-pending` | 503 | Retry the same batch identity and bytes after billing recovers. |
| <a id="evn.preference"></a>`evn.preference` | 422 | Record the subscriber’s choice and required declaration evidence. |
| <a id="evn.timestamp"></a>`evn.timestamp` | 422 | Supply an offset-aware answer time. |
| <a id="evn.billing-unavailable"></a>`evn.billing-unavailable` | 503 | Restore access to the sealed invoice facts at billd and retry. |
| <a id="evn.protection-unavailable"></a>`evn.protection-unavailable` | 503 | Load the confidential current-quarter list in usaged before retrying. |
| <a id="evn.render"></a>`evn.render` | 500 | Retry the itemisation PDF and inspect the service logs if rendering continues to fail. |
| <a id="bill.replay-expired"></a>`bill.replay-expired` | 410 | Underlying fixed-line call evidence has expired. Use the sealed invoice and its line-level explanation. |
| <a id="bill.dispatch-conflict"></a>`bill.dispatch-conflict` | 409 | A different dispatch receipt already exists. Check the original delivery evidence. |
| <a id="voice.batch-conflict"></a>`voice.batch-conflict` | 409 | Retry with the original batch UUID, source credential and bytes. Use a fresh UUID for a corrected export |
| <a id="online.source-unavailable"></a>`online.source-unavailable` | 503 | Retry the grant after the authoritative contract service is reachable. |
| <a id="online.entitlement"></a>`online.entitlement` | 409 | Check the active prepaid subscription, service date and prior offline activity in the month. |
| <a id="online.conflict"></a>`online.conflict` | 409 | An online report or observation already uses this identifier with different facts. Compare the original receipt. |
| <a id="usage.conflict"></a>`usage.conflict` | 409 | A known usage id arrived with other content |
| <a id="usage.period-closed"></a>`usage.period-closed` | 409 | The record's month is already billed |
| <a id="usage.unknown-subscription"></a>`usage.unknown-subscription` | 422 | No such subscription |
| <a id="input.invalid"></a>`input.invalid` | 422 | A value the core cannot read: a plan reference that is not `book@version/plan`, a date that is not `YYYY-MM-DD` |
| <a id="rate.unknown-plan"></a>`rate.unknown-plan` | 422 | The book has no such plan |
| <a id="bill.unknown-book"></a>`bill.unknown-book` | 422 | The open bill needs a price-book version that is not loaded |
| <a id="bill.mixed-prices"></a>`bill.mixed-prices` | 422 | Gross and net books on one account |
| <a id="bill.already-credited"></a>`bill.already-credited` | 409 | The bill already has a credit note |
| <a id="bill.not-creditable"></a>`bill.not-creditable` | 409 | A credit note cannot be credited |
| <a id="bill.no-einvoice"></a>`bill.no-einvoice` | 409 | A consumer bill has no e-invoice |
| <a id="bill.einvoice-invalid"></a>`bill.einvoice-invalid` | 422 | A credit note's e-invoice would not validate (a seal is held instead) |
| <a id="document.issuer-invalid"></a><a id="document.payment-invalid"></a>`document.issuer-invalid`, `document.payment-invalid` | 422 | The document could not be built |
| <a id="quote.busy"></a>`quote.busy` | 503 | Both anonymous tariff calculation slots are busy. Retry the tool call. |
| <a id="render.busy"></a>`render.busy` | 503 | Every typesetting slot is busy; retry |
| <a id="render.failed"></a>`render.failed` | 500 | Typesetting failed |
| <a id="agent.evidence-stale"></a>`agent.evidence-stale` | 409 | The wallet snapshot has changed. Capture fresh evidence and verify a new answer before approval or dispatch. |
| <a id="datev.selection"></a>`datev.selection` | 422 | Supply the booking month, journal, adviser and client. Use a page size between 1 and 100. |
| <a id="datev.cursor"></a>`datev.cursor` | 422 | Continue with the cursor and fiscal scope from the preceding page, or restart the list. |
| <a id="datev.month"></a>`datev.month` | 422 | Select the current or a past month in YYYY-MM format. |
| <a id="datev.unconfigured"></a>`datev.unconfigured` | 503 | Install an approved fiscal profile and configure the billing-close peer. |
| <a id="datev.peer-unavailable"></a>`datev.peer-unavailable` | 503 | Check billing readiness, its origin and the finance read credential. |
| <a id="datev.reconciliation"></a>`datev.reconciliation` | 409 | Check the currency, precision and source entries against the EUR journal. |
| <a id="datev.stale"></a>`datev.stale` | 409 | Journal or profile changed. Review a fresh preview. |
| <a id="datev.not-found"></a>`datev.not-found` | 404 | Check the issued batch UUID and one-based file number. |
| <a id="datev.pending"></a>`datev.pending` | 409 | Resolve pending bookings or finish opening-balance reconciliation. |
| <a id="datev.limit"></a>`datev.limit` | 422 | Selected journal exceeds the supported position limit. Contact the deployment owner. |
| <a id="datev.busy"></a>`datev.busy` | 409 | A close operation is running. Retry the preview. |
| <a id="datev.digest"></a>`datev.digest` | 422 | Use the SHA-256 digest returned by the preview. |
| <a id="datev.conflict"></a>`datev.conflict` | 409 | Retrieve the receipt for this UUID or issue a new reviewed command. |
| <a id="datev.empty"></a>`datev.empty` | 409 | All eligible entries are already issued or the month has no postings. |
| <a id="datev.tax"></a>`datev.tax` | 422 | Obtain adviser approval for the gross prepaid tax treatment. |
| <a id="datev.mapping"></a>`datev.mapping` | 422 | Check the journal entry against the client’s approved account mappings. |
| <a id="datev.control"></a>`datev.control` | 409 | Reconcile the mapped rows against both sides of the original posting. |
| <a id="datev.format"></a>`datev.format` | 422 | A posted entry or date cannot be represented by the selected DATEV format. |
| <a id="ledger.unavailable"></a>`ledger.unavailable` | 503 | The ledger cannot be read |
| <a id="inbox.unauthenticated"></a>`inbox.unauthenticated` | 401 | A delivery whose signature, headers or timestamp do not verify |
| <a id="inbox.source-unavailable"></a>`inbox.source-unavailable` | 503 | billd cannot read the source; deliver again later |

## Events

Poll `GET /events` on contractd and billd, and `GET /usage/events` on usaged. Keep a cursor per service. Deduplicate by event ID and order by sequence within each source. See [Events](../docs/events/) for payloads, filtering and signed deliveries.

## Passes

Every hour, and whenever the test clock is set:

- **contractd — renewals**: emits the renewal notice once on its due date (§ 56 Abs. 3
  TKG), and records the renewal once after the initial term ends without a termination.
- **contractd — endings**: ends contracts whose termination took effect, and
  non-renewing contracts after their term, together with their subscriptions.
- **billd — seal**: seals every due month of every billing account, in order
  ([Bills](../docs/billing/)).
- **billd — posting**: sends staged documents to accountingd, idempotently.

Each pass runs behind an advisory lock, so a second instance skips. Each change carries
a dedup key, so re-running inserts nothing. Due dates are compared as "on or before
today", so a missed day is caught up.

### Carrier provisioning problems

<a id="carrier.binding"></a>
An unknown carrier principal or invalid S/PRI order identifier returns `carrier.binding` (422).
<a id="carrier.conflict"></a>
An incompatible binding, out-of-order milestone or conflicting service date returns `carrier.conflict` (409).
<a id="carrier.message"></a>
An unsupported payload returns `carrier.message` (422). Send the operation body with media type `application/xml` (415 for other types).

### Mobile usage and billing holds

| Code | Result | Operator action |
|---|---|---|
| <a id="mobile.roaming-control"></a>`mobile.roaming-control` | 409 | A serving-network control conflicts with its earlier approval or starts before its approval date. |
| <a id="mobile.coverage-conflict"></a>`mobile.coverage-conflict` | 409 | A different completion receipt already covers this subscription and service day. Check the source controls. |
| <a id="mobile.usage-held"></a>`mobile.usage-held` | Billing held | Review the affected account’s held mobile measurements before sealing the usage period. |
| <a id="mobile.warning-conflict"></a>`mobile.warning-conflict` | 409 | Compare the delivery reference and outcome with the warning’s recorded attempts before retrying. |

### Accounting refusals

| Code | HTTP | Operator action |
|---|---|---|
| `bank.body` | 400 or 413 | Send readable UTF-8 XML within the 2 MiB limit. |
| `bank.invalid` | 422 | Check the message version, individual EUR amount, booking date and bank reference. |
| `bank.account` | 422 | Select the statement for the configured receiving IBAN. |
| `bank.conflict` | 409 | Compare both bank records for the same account-servicer reference. The import rolled back. |
| `booking.invalid` | 422 | Inspect the staged invoice booking, including balanced legs and document identity. |
| `booking.conflict` | 409 | Reconcile the conflicting document identity with the producer. |
| `booking.original-pending` | 503 | billd retries the credit after accounting receives its original invoice. |
| <a id="outage.asserted-money"></a>`outage.asserted-money` | 422 | Submit timing and service evidence for the managed incident. Finance supplies the posting. |
| <a id="outage.invalid"></a>`outage.invalid` | 422 | Check the report and repair timestamps, review evidence and settlement basis. |
| <a id="outage.conflict"></a>`outage.conflict` | 409 | Reopen the case and inspect the current evidence revision or original request. |
| <a id="outage.invalid-credit"></a>`outage.invalid-credit` | 422 | Verify the positive award, approval date and outage rule. |
| <a id="outage.credit-refused"></a>`outage.credit-refused` | 409 | Compare the frozen award with the retained accounting record before retrying. |
| <a id="outage.credit-conflict"></a>`outage.credit-conflict` | 409 | Finance already has a different booking for this incident. Reconcile the original receipt. |
| <a id="appointment.invalid-credit"></a>`appointment.invalid-credit` | 422 | Check the approved amount, date and rule in the case record. |
| <a id="appointment.credit-conflict"></a>`appointment.credit-conflict` | 409 | Compare the existing journal receipt with the approved case. A case can fund one credit. |
| <a id="migration.pending"></a>`migration.pending` | 503 | Accounting is reconciling the opening journal. Resume the approved cutover before retrying the financial command. |
| <a id="appointment.credit-refused"></a>`appointment.credit-refused` | 409 | The accounting service refused the approval. Reconcile the case with its journal receipt before replaying delivery. |

### Prepaid refusals and holds

| Code | Result | Operator action |
|---|---|---|
| <a id="agent.contact-not-found"></a>`agent.contact-not-found` | 404 | Check the account scope and open the contact first. |
| <a id="agent.customer-confirmation"></a>`agent.customer-confirmation` | 403 | Use the credential of the customer who received the answer. |
| <a id="agent.answer-mismatch"></a>`agent.answer-mismatch` | 422 | Confirm the retained answer for this contact. |
| <a id="agent.contact-open"></a>`agent.contact-open` | 422 | Only a confirmed contact can be reopened. |
| <a id="agent.invalid"></a>`agent.invalid` | 422 | Check the proposed effect, reason and evidence. |
| <a id="agent.stale"></a>`agent.stale` | 409 | Refresh the source and submit a new proposal. |
| <a id="agent.unavailable"></a>`agent.unavailable` | 503 | Retry when the source service is available. |
| <a id="agent.proposal-conflict"></a>`agent.proposal-conflict` | 409 | Reuse a proposal ID only for the original request. |
| <a id="agent.already-decided"></a>`agent.already-decided` | 409 | Read the recorded decision and receipt. |
| <a id="agent.command-conflict"></a>`agent.command-conflict` | 409 | Reconcile the command with the retained execution. |
| <a id="agent.credit-stale"></a>`agent.credit-stale` | 409 | Check the remaining invoice and line amounts. |
| <a id="agent.switch-stale"></a>`agent.switch-stale` | 409 | Refresh the subscription and quote before review. |
| <a id="prepaid.online-budget"></a>`prepaid.online-budget` | 409 | Recheck available funds, monthly headroom and outstanding holds. |
| <a id="prepaid.online-conflict"></a>`prepaid.online-conflict` | 409 | Compare the posting identity, revisions and original receipt. |
| <a id="prepaid.invalid"></a>`prepaid.invalid` | 422 | Check identifiers, EUR cents, service month, effective date and required reason. |
| <a id="prepaid.not-found"></a>`prepaid.not-found` | 404 | Check the wallet account and the portal credential mapped to it. |
| <a id="prepaid.conflict"></a>`prepaid.conflict` | 409 | Compare the immutable command with its receipt or enrollment. Verify the settlement reference before crediting funds. |
| <a id="prepaid.revision"></a>`prepaid.revision` | 409 | Deliver the missing predecessor for this subscription and service month, then replay. |
| <a id="prepaid.ineligible"></a>`prepaid.ineligible` | 409 | Verify that the account owns every active subscription and the enrollment window is open. |
| <a id="prepaid.future"></a>`prepaid.future` | 422 | Verify the service date against the configured business date. |
| <a id="prepaid.amount"></a>`prepaid.amount` | 422 | Review the cumulative rated charge and its EUR cent range. |
| <a id="prepaid.pending"></a>`prepaid.pending` | Billing held | Resolve pending enrollment or charge delivery and repeat the billing pass. |
| <a id="prepaid.stale-proposal"></a>`prepaid.stale-proposal` | 409 | Poll again and apply the latest revision for the account. |
| <a id="prepaid.confirmed-proposal"></a>`prepaid.confirmed-proposal` | 409 | The network already confirmed this revision. Check the acknowledgement receipt. |
| <a id="prepaid.dispute-conflict"></a>`prepaid.dispute-conflict` | 409 | Reconcile the dispute identifier with the account that first reported it. |
| <a id="prepaid.invalid-month"></a>`prepaid.invalid-month` | 422 | Request the first calendar day of a current or past Berlin business month. |

### Appointment case refusals

| Code | HTTP | Meaning |
|---|---|---|
| <a id="appointment.cancelled"></a>`appointment.cancelled` | 422 | A cancelled visit is not evidence; support decides on the case whether it counts as missed. |
| <a id="appointment.conflict"></a>`appointment.conflict` | 409 | The visit binding, report identity or proposed decision conflicts with the recorded evidence. |
| <a id="appointment.dataschema"></a>`appointment.dataschema` | 422 | Send `dataschema` `urn:open-utility-stack:appointment:1` with `appointment@1` data. |
| <a id="appointment.ineligible"></a>`appointment.ineligible` | 422 | The workflow covers consumer contracts with a verified fixed monthly fee. |
| <a id="appointment.invalid"></a>`appointment.invalid` | 422 | Check the binding, tariff reference, or the `appointment@1` member the pointer names. |
| <a id="appointment.sender"></a>`appointment.sender` | 403 | The reporting credential is assigned to a different visit. |
| <a id="appointment.subject"></a>`appointment.subject` | 422 | `subject` and `data.client_reference` must both be the case ID in the path. |
| <a id="appointment.zone"></a>`appointment.zone` | 422 | Give the visit day in `Europe/Berlin`. |

### Online quota refusals

| Code | HTTP | Operator action |
|---|---|---|
| <a id="charging.invalid"></a>`charging.invalid` | 422 | Check the unit type, group, container and sequence fields. |
| <a id="charging.binding"></a>`charging.binding` | 409 | Verify the named gateway and subscription mapping. |
| <a id="charging.sequence"></a>`charging.sequence` | 409 | Compare the sequence and body with the retained invocation. |
| <a id="charging.tariff"></a>`charging.tariff` | 409 | Check the pinned price book and effective service period. |
| <a id="charging.ineligible"></a>`charging.ineligible` | 409 | Check enrollment, current subscription status and ownership of the service month. |
| <a id="charging.budget"></a>`charging.budget` | 409 | Refresh wallet headroom and outstanding holds. |
| <a id="charging.quota"></a>`charging.quota` | 403 | Honor the refusal and inspect the wallet or session discrepancy. |
| <a id="charging.unavailable"></a>`charging.unavailable` | 503 | Retry the original invocation when the peer is available. |

### Customer documents, service status and cancellation

| Code | HTTP | Customer or operator action |
|---|---|---|
| <a id="method-not-allowed"></a>`method-not-allowed` | 405 | Use the HTTP method declared for the resource. |
| <a id="portal.account-mismatch"></a>`portal.account-mismatch` | 403 | Correct the customer credential mapping at the two owners before retrying. |
| <a id="portal.unavailable"></a>`portal.unavailable` | 503 | Retry the customer resource after the relevant source recovers. |
| <a id="portal.invalid"></a>`portal.invalid` | 422 | Use the operation and parameters in the portal OpenAPI contract. |
| <a id="auth.required"></a>`auth.required` | 401 | Sign in or supply the bearer for the current account. |
| <a id="selfcare.invalid"></a>`selfcare.invalid` | 422 | Check the invoice line, reason, plan, date, financial evidence or reviewed contract. |
| <a id="selfcare.conflict"></a>`selfcare.conflict` | 409 | Use the retained receipt identifier only for an identical submission. |
| <a id="selfcare.busy"></a>`selfcare.busy` | 429 | Retry verification after a short wait. |
| <a id="selfcare.replay-format"></a>`selfcare.replay-format` | 422 | Open the original document or request a supported replay format. |
| <a id="selfcare.intake-limit"></a>`selfcare.intake-limit` | 429 | Retry the declaration after the ten-minute intake window. An identical accepted submission still returns its receipt. |
