Skip to content

ADR-064: Serve mode: one app per deployment, runs before chat, and an HTTP API that is a profile of existing standards ​

Date: 2026-11-29 Status: proposed Deciders: Milan Pavel

Context ​

golem runs on your Mac, for you. Phase 21 (#2010) runs the same daemon and gateway in a Linux container behind an application. The app's backend calls an HTTP API to start workflow runs and chats for its own users, and golem returns results. The idea is in the vision.

Three things were open before any gateway code:

  • Who a run belongs to. On a Mac the answer is "you". In serve mode there are many people, and golem does not know them.
  • What the first API is. newmonday, the reference application, which lives in its own repository (Phase 22), is the first caller. It needs workflow runs with a review. Chat comes second.
  • What the API looks like. There is no single standard for an agent gateway (checked 2026-11-29). There is one common shape for chat, several competing protocols for runs, and solid standards for plain HTTP.

The gateway today (ADR-028) serves one browser on 127.0.0.1 and passes protocol lines to the daemon. A workflow run today is a headless session with a workflow_run_id (ADR-050, ADR-062). Both are reused. This record adds no code and no protocol change. The API is written down in docs/api/serve-v1.yaml and shown on the Serve API page. Both say that it is planned.

Decision ​

One app per deployment ​

  • One deployment serves one app. A second app is a second container.
  • The definition of the app (agents, workflows, skills, settings) ships in the image under /app and is read only.
  • State lives on a volume under /data: SQLite, one replica. Postgres comes only when something pays for the port.
  • Models are endpoints, reached by URL. The image holds the agent, never the model.
  • Serve is a row in a table of capabilities (step 21.1), not if serve spread over the code. The command is golem serve.

The principal ​

A run and a session belong to a principal: the app's id for a person, such as u_8f2c.

  • The app's key proves the app. The user in the request is trusted, because the app authenticated that person.
  • The daemon enforces it, not the gateway alone. Every run, session and usage row carries the principal, and every read and write on the daemon side filters by it. A bug in the gateway cannot show one user's run to another.
  • A run of another key or another user answers 404, never 403. The two cases look the same, so a caller cannot find out which ids exist.
  • DELETE /v1/users/{user} removes everything held about one user.
  • A key belongs to the app. A person never holds one. The principal of a call without user (a listing, for example) is "the whole app".

Runs before chat ​

The first API is workflow runs with a review, because newmonday needs that. Chat completions follow in the same version of the document. They are in the contract now, so nobody builds a second shape later. Their tickets come after the runs tickets (21.9, 21.10, then 21.11).

A run is a resource, not a held-open request. POST answers 202 with Location, and the caller polls GET /v1/runs/{id} or follows the events. A model can take minutes and a review can take days, and neither fits one HTTP request.

Asking: ask = "deny" | "app" | "owner" ​

On a Mac, golem asks you. In serve mode nobody is at the terminal, so [serve] ask says who answers:

ValueWhat happensVersion 1
denyNothing waits. An ask is answered "no" at once. A run.review gets the verdict reject and the run goes on, so no run is ever input-required.yes
appThe run waits. The open question is on the run as an interrupt, and the app's own user answers through POST /v1/runs/{id}/resume.yes
ownerThe call waits in a queue for someone on the app's team, in an admin console.no. Later. golem serve check refuses it.

The default is deny. A deployment has to choose app to let a run wait. golem informs and does not refuse in silence: in deny the run's events say that a review was answered reject and why.

The gateway is on a private network first ​

The gateway does not face the internet in the first versions. The app's backend calls it on a private network, with a key. So:

  • No CORS and no cookies. A browser never calls it.
  • No TLS in golem. A proxy in front does that if the network needs it. mTLS is left to the proxy too.
  • Auth is a bearer key, gk_ plus a random body plus a checksum. A secret scanner can find it. It is stored as a digest, shown once and revocable. A missing or bad key is 401. A method list per kind of key says what a key may call (step 21.7).
  • /healthz and /readyz need no key. SIGTERM drains: /readyz answers 503 and running work finishes.

A public listener is a later decision and gets its own record.

The standards profile ​

The API is a profile of existing standards. Where one exists, golem follows it and names it. The survey is dated 2026-11-29.

Areagolem followsSource
ChatOpenAI Chat Completions with SSE. An agent is a model. End user in safety_identifier, or in userOpenAI safety identifiers
Runs202 and Location, and a status resource to pollAIP-151, long-running operations; OpenAI background mode for starting_after
Run statesThe names submitted, working, input-required, completed, failed, canceledA2A 1.0
ReviewThe run pauses with a list of open questions, and a resume answers each by idAG-UI interrupts
StreamsSSE, event id is the sequence number, resume with Last-Event-ID or ?starting_after=WHATWG SSE
RetriesIdempotency-Key on every creating POSTIETF draft-ietf-httpapi-idempotency-key-header (draft-09)
Errorsapplication/problem+json, a stable code, and X-Request-IdRFC 9457
Limits429 with Retry-AfterRFC 9110
AuthBearer keys with a prefix and a checksumCloudflare token formats
Webhookswebhook-id, webhook-timestamp, webhook-signature, HMAC-SHA256 (step 21.13)Standard Webhooks 1.0
Tracingtraceparent accepted and passed on. Prometheus /metrics (step 21.15)W3C Trace Context; Prometheus exposition format
ContractOne OpenAPI 3.1 document, versioned by the /v1 path, changed only by addingOpenAPI
Container/healthz, /readyz, drain on SIGTERM, non-root, config from the environment, OCI labelsOCI image annotations

OpenAPI is written at 3.1, not the newest 3.2, because the tools for 3.1 are common.

What was left out, and why ​

Left outWhy not now
A2A as the API (A2A)It is the best match for a run's life, so its state names are used. The wire (JSON-RPC, agent cards, push) is bigger than newmonday needs. An adapter can sit on top later, because the states already match.
LangChain Agent Protocol (repo)One vendor, no stability statement, and resume is not specified. Its resource shapes were read, not copied.
Open Responses (/v1/responses, spec)A second chat surface later. It has no human review and leaves background undefined.
MCP as a server surface (MCP)golem stays an MCP client. An app wants to call golem, not to give it tools.
OAuth 2.1 (draft)Still a draft, and the caller is a backend that holds a key.
RateLimit headers (draft)The draft is not settled. 429 and Retry-After first.
CloudEvents (spec)No signature. Standard Webhooks signs.
OpenTelemetry gen_ai.* spans (conventions)Still in development and names change. Maybe behind a flag.
WebSocketSSE is enough for a one-way stream and works through every proxy.
Date-header versionsThe /v1 path is enough.
Kubernetes Gateway API, Envoy AI GatewayThey route to model servers. golem only has to behave behind any proxy.
Model text deltas in the run streamA step's result is the unit in version 1. A client that wants deltas uses chat.
Tools the client runs (OpenAI tools)A request with tools is refused with a clear error (tools_not_supported).

The contract ​

The full contract is in docs/api/serve-v1.yaml. Here are its main points.

CallMeaning
POST /v1/workflows/{name}/runsStart a run. Body {input, user, metadata?}. Idempotency-Key. 202, Location: /v1/runs/{id}, and the run. The same key and body returns the same run, another body is 409.
GET /v1/runs/{id}The run: id, workflow, user, status, created_at, updated_at, output?, error?, interrupts[], usage, metadata.
GET /v1/runs?user=&status=&after=&limit=List, newest first, cursor in after.
GET /v1/runs/{id}/eventsSSE. id: is the sequence number, event: the type, data: JSON. Resume with Last-Event-ID or ?starting_after=. Ends after the terminal event.
POST /v1/runs/{id}/cancelIdempotent.
POST /v1/runs/{id}/resumeBody {answers: [{id, verdict, text?}]}. Must answer every open interrupt, else 422. ?user= as the other calls. No Idempotency-Key: a repeat is 409 run_not_waiting.
POST /v1/chat/completionsOpenAI shape, streamed and not. model is an agent. A request with tools is refused.
GET /v1/modelsThe agents.
DELETE /v1/users/{user}Delete everything held about one user.
GET /healthz, GET /readyzNo key.
GET /metricsPrometheus text, off unless [serve] metrics = true. Needs a key. Counted in the gateway process, no id in any label.

Event types in version 1: run.status, step.started, step.finished, run.interrupt, run.output, run.error.

How the daemon serves these calls (step 21.9):

  • Each workflow.* notification of a run is also written to workflow_events, with the next number of its run. That number is the SSE id:. A failed run logs workflow.run.error before workflow.run.failed, so each logged event is one API event and the terminal run.status comes last. workflow.events reads a run's log after a number and, with subscribe, sends the run's later events as workflow.run.event to that one connection, after the same principal check as every run call. It stops after the run's end or when the connection ends. App connections still get no broadcast.
  • The key of Idempotency-Key, a digest of the request and the run are written in one transaction with the run, in the daemon (table idempotency_keys, 24 hours, per app key). The gateway would need its own store to do the same, and two gateways would race. A second request with the key waits on the first one's write and gets the first run, so idempotency_in_progress is not answered today.
  • GET /v1/runs/{id}, /events and /cancel take the user as a required user query parameter, since the daemon looks a run up for one principal.

From golem's run states to the API's ​

golem's states are in WorkflowRunStatus (packages/protocol/golem_protocol/commands.py) and are set by packages/daemon/golem/workflows/engine.py. The API never shows golem's names. The map is one function in the gateway, and it is total.

golem (workflow_runs.status)API statusNotes
pendingsubmittedSaved, not yet started.
runningworking
waiting, with an open reviewinput-requiredThe run holds no task, slot or model while it waits. interrupts[] lists the open reviews.
waiting, with no open reviewworkingThis is on_restart = "ask" after a restart. Serve mode sets on_restart = "resume", so it should not happen. If it does, the caller has nothing to answer, so it sees working.
donecompletedoutput is the workflow's result and what it marked with run.output.
failedfailederror has the reason.
cancelledcanceledOne l in the API, as in A2A. golem keeps its own spelling.

Reading it the other way: submitted, working and input-required are not final. completed, failed and canceled are final, and the events stream ends after the one that gets there.

Steps have their own states in the events (done, failed, skipped, in_doubt, from WorkflowStepStatus). They are not mapped. step.finished carries golem's name as it is, and a step that is in_doubt (a keyed step that may have had its effect before a restart) stays visible to the app.

golem event (workflow.*)API event
workflow.run.started, .waiting, .resumed, .done, .failed, .cancelledrun.status with the mapped status. workflow.run.failed also sends run.error.
workflow.step.startedstep.started
workflow.step.done, .failed, .in_doubt (and a skipped step)step.finished
workflow.step.waiting of a review steprun.interrupt
workflow.output.addedrun.output
workflow.step.progressnot sent (no model text in version 1)

A review, and its answers ​

golem's run.review(draft, ask=) makes an open review: a step key, the ask text, the draft as JSON. Over the API it is an interrupt:

json
{"id": "review:reply", "kind": "review", "title": "Send this reply?", "ask": "Look at the reply before it goes out.", "draft": "Hello Ana, ..."}

id is the review's step key (key= of run.review, else review:<ask>), so an answer names the same thing in both. ask is the question the workflow asked. It is the text of the review and has nothing to do with the [serve] ask setting above, which says who answers.

An answer is {id, verdict, text?}. The verdict names are golem's own (WorkflowReviewVerdict), not A2A's or AG-UI's:

VerdictMeaningtextWhat the workflow gets
approveThe draft as it is.Optional. The draft when left out.{"verdict": "approve", "text": <draft>}
editThe person's version.Required.{"verdict": "edit", "text": <text>}
rejectNo.Optional, for a reason.{"verdict": "reject", ...}. The workflow decides what that means.

POST /v1/runs/{id}/resume must answer every open interrupt in one call. The daemon applies all the answers with one method, workflow.review.answer_all: it checks every answer first, saves them in one transaction (a review answered meanwhile undoes the lot), and the run continues once none of its reviews waits (the rule of ADR-062, reused as it is). A run that waits on no review is 409 run_not_waiting; a second identical resume finds the run no longer waiting, so it is 409 too. resume takes no Idempotency-Key: the table idempotency_keys ties a key to the run it started, and a key for a resume would need a second meaning in it. So a run with two reviews resumes once. An answer that misses an open id is 422 answers_incomplete, and the run stays as it was. An edit without text, an unknown id, or a verdict that is not one of the three is 422 answer_invalid.

Errors and codes ​

Every error is application/problem+json with type, title, status, detail, and two more members: code, a stable short string, and request_id. A client branches on code. The set only grows. Every response, success or not, carries X-Request-Id. A caller's own X-Request-Id is kept, and a traceparent is kept and passed on.

The codes are listed in ProblemCode of the YAML. They are: invalid_request, invalid_key, not_found, workflow_not_found, model_not_found, input_invalid, idempotency_conflict, idempotency_in_progress, run_not_waiting, answers_incomplete, answer_invalid, user_required, tools_not_supported, unsupported_parameter, payload_too_large, unsupported_media_type, events_expired, rate_limited, budget_exceeded, upstream_error, draining, not_ready, internal_error.

Polish from the first caller (step 21.18) ​

The first real caller found some things awkward. Each is now in the contract, and the choice between the two options the ticket gave is the simpler one for a caller.

  • Cancel says what happened. The answer is the run plus canceled_by_this_call, always 200. A 409 for a run that has ended would make every retry an error to handle.
  • The events stream starts with the state. A fresh connection (no Last-Event-ID, no starting_after) first gets a synthetic run.status with the run's current state, with no id: line. With no id it never moves the client's resume point, so a drop before the first stored event is a fresh connection again, and a drop after one resumes after that event's id. The cost is that the state may be sent twice.
  • Step events. step.started means the step is running; step.finished carries its final state. No new event type.
  • Events expire. [serve] keep_events_days (default 30, 0 keeps for ever). The daemon trims a run that has ended to its end events. A resume before the first kept event is 410 events_expired with first_seq; the recovery is to connect with no position and take the state plus what is kept.
  • Required inputs. @workflow(required=[...]) names them, so an older declaration keeps its meaning (nothing required). A start that misses one is 422 input_invalid with field, and an error with the same words on the socket.
  • traceparent is a field of workflow.start and serve.chat.run, stored with the run (workflow_runs.traceparent) or in session.created, and shown by the run's info and by trace.get.

How the YAML is kept honest ​

The docs job has no OpenAPI linter and this adds no dependency. packages/daemon/tests/test_serve_api_spec.py parses the YAML (PyYAML is already a dependency of the daemon) and checks that every $ref resolves, every operation has a unique operationId and a problem response, every secured call can answer 401, and the run states, verdicts and event types are the ones this record names. A ticket that changes the YAML changes this record or says why not.

Alternatives Considered ​

Alternative 1: Chat first, runs later ​

  • Pros: The OpenAI shape is known, and every SDK speaks it.
  • Cons: newmonday needs a run with a review. A chat completion cannot pause for days, and golem's workflow engine already does.
  • Why not: Build what the first caller needs. Chat is in the contract, so its shape is not an afterthought.

Alternative 2: Adopt A2A as the API ​

  • Pros: A standard, with the right states and a push channel.
  • Cons: JSON-RPC, agent cards and its own task model. The app would learn A2A to start one workflow.
  • Why not: Use its state names. Leave an adapter for later.

Alternative 3: Trust the user id at the gateway only ​

  • Pros: Less work in the daemon.
  • Cons: One bug in the gateway shows one user's run to another. The daemon would be unaware of users.
  • Why not: The daemon holds the data, so the daemon enforces the principal.

Alternative 4: Hold the request open until the run ends ​

  • Pros: One call, no polling.
  • Cons: A model call takes minutes, and a review takes days. Proxies cut idle requests.
  • Why not: 202 and a status resource is the standard pattern for this.

Alternative 5: Use golem's own state names on the API ​

  • Pros: No map to keep.
  • Cons: golem's pending, waiting and done mean what they mean to golem. waiting is not always a question for the app. A client that knows A2A would not recognise them.
  • Why not: One small, total map is cheaper than a second vocabulary for every client.

Consequences ​

Positive ​

  • The gateway tickets (21.7, 21.9, 21.10, 21.11) and newmonday (22.10) build against one document.
  • A run that waits on a review survives a restart, because the workflow engine already does.
  • A client that speaks OpenAI, A2A's state names or Standard Webhooks finds nothing new to learn.
  • The app is the only caller, and a key is the only credential, so there is no login code to write.

Negative ​

  • The API is a profile, so it is not a drop-in for any one standard.
  • cancelled in golem and canceled in the API are two spellings of one thing.
  • ask means two things in two places (a review's question, and the [serve] ask setting). The names are kept because each is the natural one where it is used.

Risks ​

RiskHandling
The draft standards move (idempotency key, rate limits, OAuth 2.1)Only the settled parts are used: the header name, 429 and Retry-After. The rest is left out.
A workflow with a state that does not fit the mapThe map is total over WorkflowRunStatus, and a test in step 21.9 covers each value. A new golem state fails that test.
The contract and the code driftThe YAML is checked in CI. Each serve ticket runs its calls against it, and the contract changes only by adding.
deny hides a review a workflow needsA run in deny says why in its events. Step 21.5's golem serve check can warn about a workflow that has a run.review.
usage has no token counts todayThe workflow journal keeps cost_usd for llm steps only. Step 21.9 sends usage.cost_usd as recorded and leaves the token counts out (absent, not zero) until a step keeps them.

References ​