Product knowledge · Advanced · Live control

Change a live route without switching an admitted request to another handler.

Prepare and validate a candidate first. CoAkka HTTP Runtime publishes atomically only while Core-issued generation/revision still match; old requests retain their captured binding and only new requests see the cut.

01 · Choose the operation

“Live update” is not one operation

What changesCorrect operationWhat remains stable
Implementation behind one routeHandler-only rebindRoute ID, method, path, body policy and structural generation.
Add/remove/change a route or API metadataComplete route publicationOne coherent snapshot is accepted or refused as a whole inside reserved bounds.
Listener/protocol/I/O backend, static authority or startup reservationReplacement service + traffic cutoverThe old owner serves/drains through a finite terminal lifecycle.

Do not call every change hot reload. CoAkka HTTP Runtime does not watch source, compile code or load modules for the App Host.

02 · Ownership model

Core publishes identity; the App Host owns code and lifetime

App Host / addon

Detects change, builds/loads candidates, validates dependencies, authorizes change and owns the bounded binding registry and rollback policy.

CoAkka HTTP Runtime

Captures bindings at admission, compares generation/revision, cuts over atomically, retains exact activation receipts and returns effective state.

Connector

Projects typed requests/outcomes, preserves exact integer identity and protects callback/object lifetime across the host boundary.

Deployment

Replaces services, shifts ingress, holds spare capacity and drains old instances when a live API cannot cover the change.

03 · Identity map

Each number protects a different domain

Route structural generation
Version of the complete accepted route table; not source-code version or a timestamp.
Metadata generation
Core-issued identity of coherent route/API metadata state; complete publication compares it separately from structural generation.
Binding change sequence
Service-wide cut identity preventing a structural publisher from overwriting a newer handler rebind.
Per-route binding revision
Revision of the active handler on one route; handler-only compare-and-apply checks it.
Handler binding ID
Application identity for a prepared/registered handler; a request captures this ID at admission.
Activation ID
Application-chosen idempotency identity for one control intent; exact replay retrieves the retained outcome without applying twice.

Read snapshots from Core. Never invent the next generation/revision, reuse identities across service instances or infer effective state from a local handler map.

04 · Handler-only flow

Prepare → validate → register → snapshot → activate → drain → retire

1

Prepare off the event loop

Build/load the candidate and dependencies; failure here never touches the active route.

2

Validate + register

The App Host checks contract/authorization and adds the binding to a finite registry.

3

Read the Core snapshot

Obtain current route generation, route ID, binding ID/revision and binding-change sequence.

4

Activate exact intent

Submit one activation ID with expected generation/revision and prepared binding ID.

5

Split admissions safely

Admissions after the accepted cut capture the new binding; work that captured the old binding stays on it.

6

Observe retirement

Retain old binding/code/state until Core request proof and every separate application reference converge.

Advanced · Listener V1 · Node.js + Bun

Replace the handler on the same HTTPS port

Node.js and Bun 2.3.2 provide swapHandler() for Listener V1. This replaces the callback of an existing route. Use generation-checked rebind for a standalone listener. This example keeps the URL and listener unchanged.

Prepare the development certificate and install the 2.3.2 npm package as in Lab 04. Save this file as swap-handler.mjs. Run node swap-handler.mjs or bun swap-handler.mjs in that directory.

swap-handler.mjs
import { resolve } from "node:path";
import { createInterface } from "node:readline/promises";

const connector = process.versions.bun
  ? "coakka-http-runtime-bun"
  : "coakka-http-runtime-node";
const { Builder, Response } = await import(connector);

let releaseOldRequest;
const oldRequestCanFinish = new Promise((resolve) => {
  releaseOldRequest = resolve;
});
let oldRequestEntered = false;

const service = new Builder()
  .multiProtocolListener({
    host: "127.0.0.1",
    port: 8443,
    credentialId: "portal-lab",
    credentialGeneration: 1n,
    certificateChainFile: resolve("certs/server-chain.pem"),
    privateKeyFile: resolve("certs/server-key.pem"),
  })
  .get("/hello/Ada", async () => {
    oldRequestEntered = true;
    console.log("Old handler entered; waiting for release.");
    await oldRequestCanFinish;
    return Response.text("before");
  })
  .start();

const terminal = createInterface({ input: process.stdin, output: process.stdout });
try {
  console.log(`https://127.0.0.1:${service.port}/hello/Ada`);
  await terminal.question("Start the first request; when it enters, press Enter to swap.\n");
  if (!oldRequestEntered) {
    throw new Error("Start the first curl request before swapping the handler.");
  }
  service.swapHandler("GET", "/hello/Ada", () => Response.text("after"));
  await terminal.question("Handler swapped. Check new requests, then press Enter to release the first.\n");
} finally {
  releaseOldRequest();
  terminal.close();
  await service.close();
}

In a second terminal, start the old request in the background. Wait for the server to print Old handler entered, then press Enter in its terminal to swap.

curl · before
curl --noproxy '*' --cacert certs/server-chain.pem --http3-only --max-time 30 \
  --fail --silent --show-error --write-out '\n%{http_code} %{http_version}\n' \
  https://127.0.0.1:8443/hello/Ada &

Before releasing the first request, run the 3 probes. Each must return after and 200 with its expected version. Press Enter again in the service terminal. The first request returns before with 200 3, then the service closes.

curl · after
for protocol in --http1.1 --http2 --http3-only; do
  curl --noproxy '*' --cacert certs/server-chain.pem "$protocol" --max-time 8 \
    --fail --silent --show-error --write-out '\n%{http_code} %{http_version}\n' \
    https://127.0.0.1:8443/hello/Ada
done

05 · Rebind request

Five fields form one compare-and-apply intent

FieldMeaning and law
activation_idUnique in the service control domain; retries retain the same ID and exact intent.
expected_route_generationStructural generation just read from Core; mismatch means the candidate targeted another route table.
route_idStable route whose handler changes; activation does not select it by method/path text.
expected_binding_revisionCurrent revision just read; prevents lost update between concurrent control owners.
new_handler_binding_idID of a prepared/validated/registered handler; activation does not compile or load it.

06 · Rebind outcome

Retain effective facts, not only a success boolean

Code
Stable control result. Only APPLIED confirms an accepted/replayed effective outcome.
Activation ID + operation digest
Correlation/operator evidence. A digest never replaces exact field/byte comparison and is not idempotency identity.
Route generation + binding-change sequence
Core-issued effective cut identities after the operation.
Previous/effective binding + revision
Shows the transition or the state preserved by refusal/replay.
changed / replayed
Separates the first accepted cut from exact retained replay; retain effective fields in both cases.
Request retirement
A proof domain separate from publication; activation success never permits unloading old code by itself.

07 · Control vocabulary

Stale, unresolved and refused require different action

Stable codeMeaning / next action
APPLIEDUse returned effective state; inspect changed/replayed, then continue retirement.
GENERATION_MISMATCH / REVISION_MISMATCHRead the snapshot again and reconsider intent; never blind-increment a number.
ACTIVATION_CONFLICT / EXPIRED / OUT_OF_ORDER / SEQUENCE_EXHAUSTEDIdentity/history/order is invalid; preserve current state and recover control-plane state before a new operation.
INVALID_ARGUMENT / ROUTE_NOT_FOUND / REJECTEDCandidate/contract is invalid; repair intent or prepared registry without changing active state.
TIMEOUT / WAKEUP_FAILEDDoes not prove rejection. Retry the exact activation and intent to retrieve proof; do not submit a new ID.
BUSYAnother activation is unresolved; this operation was not submitted and consumed no history. Recover the earlier operation.
CLOSED / OUT_OF_MEMORY / INTERNALFail closed, retain owner/evidence and repair the correct lifecycle/capacity/service boundary.

08 · Complete route publication

Change structure with one complete snapshot, never per-route patches

prepare every referenced handler binding
  → read Core route identity
  → build complete candidate route array
  → publish against expected route + metadata + binding-change identities
  → accepted: entire candidate becomes effective
  → refused/stale: entire previous snapshot remains effective

route omitted from an accepted candidate = route removed

Publication can add/remove/change route structure and API metadata within accepted capability and construction-time reservations. Handler-only rebind remains the smaller operation while method/path/body policy stays unchanged.

09 · Publication fields

A structural publisher protects route, metadata and binding cuts

Request fieldMeaning
activation_idExact publication identity used for idempotent replay.
expected_route_generationPrevents publication over a changed structural snapshot.
expected_metadata_generationPrevents overwriting newer coherent API metadata state.
expected_binding_change_sequencePrevents a complete snapshot from losing a handler rebind accepted after the read.
route_count + routesThe complete candidate with route ID, binding ID, method, encoded pattern, body policy and optional metadata; caller storage need survive only the synchronous call.

The outcome returns previous/effective route, metadata and binding-change identities; actual/limit, rejected_route_index, changed/replayed and request-retirement proof. Branch on typed fields, never diagnostic prose.

10 · Request retirement

QUIESCENT proves only Core request captures for that cut

StateRetirement law
UNKNOWNNo complete proof; a partial source count never permits release.
CAPTUREDThe cut captured participating request owners but is not quiescent; retain the old binding.
QUIESCENTEvery Core request source for the publication acknowledged the cut. Only request captures are proven; callbacks/sessions/app references converge separately.
STILL_ROUTABLEThe old handler identity remains reachable through the active snapshot; never retire it.
NOT_APPLICABLEThe operation produced no applicable retirement target; never reinterpret it as general permission to free an object.

Only code OBSERVED accompanies an observed proof. UNAVAILABLE, BUSY, CONFLICT, EXPIRED, TIMEOUT, WAKEUP_FAILED, publication/observation failures and other error codes all require retained ownership. Exact cold replay can retrieve newer Core proof without resubmitting route intent.

11 · Rollback

Rollback is a newly accepted change, not a reversed clock

1

Retain the old candidate when policy requires it

A binding can roll back only while code/state remains loaded, valid and inside registry capacity.

2

Read current Core state

Never reuse expected generation/revision from before the cut.

3

Submit a new activation

Use a new activation ID, current compare fields and the prepared old binding ID.

4

Drain the replaced binding

The same retirement law applies; rollback cannot magically cancel admitted work.

Exact replay of the prior activation returns its retained prior outcome; it is not rollback.

12 · Replacement service

Construction-time boundaries still require a new instance

ChangeSafe path
Listener address/port, HTTP protocol or I/O backendCreate/start/handshake a new service, shift ingress, then drain the old service.
Static mounts, file authorities or startup resource/thread/queue reservationsBuild a new validated service; live control never expands immutable reservation.
Unreserved capability, such as WebSocket when startup did not reserve itReplacement service with feature/capability validated before readiness.
TLS/mTLS credentials in the same live modeUse the separate TLS reload contract when the exact target supports it; never attach it to route publication.
Security mode/protocol or a package without reload supportReplacement service plus real handshake evidence before traffic cutover.
Application binary/module that cannot load/unload safelyProcess/service rollout; never force the handler primitive beyond loader lifetime law.

13 · Failure law

Refusal never partially publishes; uncertainty never permits guessing

Prepare/validate failure

The candidate never became active; discard it in the App Host and preserve the current handler.

Stale/refused apply

Core preserves the entire previous effective state; read returned/current snapshot and reconsider.

Observation uncertainty

Timeout/wakeup failure does not reveal apply result; exact-retry the same intent to recover proof.

Drain/retirement timeout

Keep old code/state reachable; timeout never permits unload or free.

14 · Bounds and evidence

Prepared, active, draining and history are all finite

15 · Integration checklist

Before choosing a language API