Prepare off the event loop
Build/load the candidate and dependencies; failure here never touches the active route.
Product knowledge · Advanced · Live control
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
| What changes | Correct operation | What remains stable |
|---|---|---|
| Implementation behind one route | Handler-only rebind | Route ID, method, path, body policy and structural generation. |
| Add/remove/change a route or API metadata | Complete route publication | One coherent snapshot is accepted or refused as a whole inside reserved bounds. |
| Listener/protocol/I/O backend, static authority or startup reservation | Replacement service + traffic cutover | The 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
Detects change, builds/loads candidates, validates dependencies, authorizes change and owns the bounded binding registry and rollback policy.
Captures bindings at admission, compares generation/revision, cuts over atomically, retains exact activation receipts and returns effective state.
Projects typed requests/outcomes, preserves exact integer identity and protects callback/object lifetime across the host boundary.
Replaces services, shifts ingress, holds spare capacity and drains old instances when a live API cannot cover the change.
03 · Identity map
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
Build/load the candidate and dependencies; failure here never touches the active route.
The App Host checks contract/authorization and adds the binding to a finite registry.
Obtain current route generation, route ID, binding ID/revision and binding-change sequence.
Submit one activation ID with expected generation/revision and prepared binding ID.
Admissions after the accepted cut capture the new binding; work that captured the old binding stays on it.
Retain old binding/code/state until Core request proof and every separate application reference converge.
Advanced · Listener V1 · Node.js + Bun
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.
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 --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.
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
done05 · Rebind request
| Field | Meaning and law |
|---|---|
activation_id | Unique in the service control domain; retries retain the same ID and exact intent. |
expected_route_generation | Structural generation just read from Core; mismatch means the candidate targeted another route table. |
route_id | Stable route whose handler changes; activation does not select it by method/path text. |
expected_binding_revision | Current revision just read; prevents lost update between concurrent control owners. |
new_handler_binding_id | ID of a prepared/validated/registered handler; activation does not compile or load it. |
06 · Rebind outcome
APPLIED confirms an accepted/replayed effective outcome.changed / replayed07 · Control vocabulary
| Stable code | Meaning / next action |
|---|---|
APPLIED | Use returned effective state; inspect changed/replayed, then continue retirement. |
GENERATION_MISMATCH / REVISION_MISMATCH | Read the snapshot again and reconsider intent; never blind-increment a number. |
ACTIVATION_CONFLICT / EXPIRED / OUT_OF_ORDER / SEQUENCE_EXHAUSTED | Identity/history/order is invalid; preserve current state and recover control-plane state before a new operation. |
INVALID_ARGUMENT / ROUTE_NOT_FOUND / REJECTED | Candidate/contract is invalid; repair intent or prepared registry without changing active state. |
TIMEOUT / WAKEUP_FAILED | Does not prove rejection. Retry the exact activation and intent to retrieve proof; do not submit a new ID. |
BUSY | Another activation is unresolved; this operation was not submitted and consumed no history. Recover the earlier operation. |
CLOSED / OUT_OF_MEMORY / INTERNAL | Fail closed, retain owner/evidence and repair the correct lifecycle/capacity/service boundary. |
08 · Complete route publication
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 removedPublication 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
| Request field | Meaning |
|---|---|
activation_id | Exact publication identity used for idempotent replay. |
expected_route_generation | Prevents publication over a changed structural snapshot. |
expected_metadata_generation | Prevents overwriting newer coherent API metadata state. |
expected_binding_change_sequence | Prevents a complete snapshot from losing a handler rebind accepted after the read. |
route_count + routes | The 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| State | Retirement law |
|---|---|
UNKNOWN | No complete proof; a partial source count never permits release. |
CAPTURED | The cut captured participating request owners but is not quiescent; retain the old binding. |
QUIESCENT | Every Core request source for the publication acknowledged the cut. Only request captures are proven; callbacks/sessions/app references converge separately. |
STILL_ROUTABLE | The old handler identity remains reachable through the active snapshot; never retire it. |
NOT_APPLICABLE | The 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
A binding can roll back only while code/state remains loaded, valid and inside registry capacity.
Never reuse expected generation/revision from before the cut.
Use a new activation ID, current compare fields and the prepared old binding ID.
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
| Change | Safe path |
|---|---|
| Listener address/port, HTTP protocol or I/O backend | Create/start/handshake a new service, shift ingress, then drain the old service. |
| Static mounts, file authorities or startup resource/thread/queue reservations | Build a new validated service; live control never expands immutable reservation. |
| Unreserved capability, such as WebSocket when startup did not reserve it | Replacement service with feature/capability validated before readiness. |
| TLS/mTLS credentials in the same live mode | Use 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 support | Replacement service plus real handshake evidence before traffic cutover. |
| Application binary/module that cannot load/unload safely | Process/service rollout; never force the handler primitive beyond loader lifetime law. |
13 · Failure law
The candidate never became active; discard it in the App Host and preserve the current handler.
Core preserves the entire previous effective state; read returned/current snapshot and reconsider.
Timeout/wakeup failure does not reveal apply result; exact-retry the same intent to recover proof.
Keep old code/state reachable; timeout never permits unload or free.
14 · Bounds and evidence
max_routes, total segments/route bytes/metadata and required feature capacity before start.15 · Integration checklist