# Harness runtime The harness runtime owns the extension installation, ledger, session compositions, and Python kernels used by the daemon. The daemon's [session actor](sessions.md) coordinates turns with this runtime. ## Startup and ownership [`runtime.start_with_config`](../src/albedo/harness/runtime.gleam) opens the store, installs extensions, and starts the runtime actor. The initializer has a 60-second deadline. If installation fails, it closes the store. Extensions that fail installation can be quarantined. The runtime records and reports them. A runtime session belongs to the store that created it. `execute` and `invoke` reject a session owned by another runtime. The runtime exposes installed and quarantined extensions and the underlying ledger through its public functions. ## Preparation and kernels [`runtime.prepare_session_async`](../src/albedo/harness/runtime.gleam) prepares a session composition without starting a kernel. `open_session_async` requests a kernel and calls its answer function when startup succeeds or fails. The synchronous `open_session` waits up to 180 seconds and returns `python.Unavailable` on timeout. Both paths validate the session ID. `prepared` extracts the kernel-free composition, instructions, and context from an open session. The runtime can inspect commands from a prepared composition without opening a kernel. The [session actor](sessions.md) decides when to request and release a kernel. ## Execution and tools [`runtime.execute`](../src/albedo/harness/runtime.gleam) begins a journal cell, executes saved Python code with the supplied timeout, and settles the cell with its outcome. A journal failure is returned separately from the Python outcome. `runtime.invoke` finds a tool in the session composition. An unknown tool or an extension refusal becomes a failed tool output. An extension `Fatal` error ends the invocation with an error. Image limits are passed to the tool context. [Hooks](hooks.md) can observe or refuse calls. ## Lifecycle [`runtime.delete_session`](../src/albedo/harness/runtime.gleam) asks the runtime owner to delete a session and returns an error if the owner stops or does not confirm within 30 seconds. The module also exposes asynchronous reset and forget operations, kernel detach and resume operations, and extension reload operations. These are distinct from deleting the daemon's durable session record. See [sessions](sessions.md). ## Extension reload ownership [`reload.gleam`](../src/albedo/harness/runtime/reload.gleam) prepares and adopts a candidate composition before applying it to the kernel. The runtime retains the candidate, previous session, and reply recipient in a `ReloadApplication` through its queued or monitored work. The worker borrows these handles and closes neither composition. The worker reports a typed `ReloadOutcome`: rebound routes, a replacement kernel, no live kernel, or a reported rejection. A worker that exits without a result produces an uncertain outcome through the existing admission monitor. Both paths reach `reload.settle`, which checks the session generation before deciding publication, retention, or reconciliation. Successful application installs the candidate and retires the old composition. A reported rejection closes the candidate and retains the previous session only if its kernel still lives. If work ended without reporting, the adopted candidate becomes loaded and kernel ownership is reconciled through the stop owner. Do not restore the previous routes when the worker may already have changed them. An unconfirmed stop keeps the session fenced. A result for an obsolete generation queues its resources for retirement rather than publishing them. If the runtime dies before acknowledging a result, the reporting worker cleans up the orphaned application. Keep slow kernel cleanup in [`kernels.reconcile` and `retire`](../src/albedo/harness/runtime/kernels.gleam) so the actor stays responsive. The existing `Origin` and `handed_out` contract in [`state.gleam`](../src/albedo/harness/runtime/state.gleam) governs first-handoff namespace notices. Settlement preserves that origin for the caller and retains the handed-out session for later opens. Notice publication remains in [`session_namespace.adopt`](../src/albedo/daemon/session_namespace.gleam). ## Clocks Use [`albedo/clock`](../src/albedo/clock.gleam) for Gleam clock access. Use `system_ms` or `system_seconds` for stored timestamps and `monotonic_ms` for elapsed time and deadlines. Do not add local clock externals. The [`albedo_clock` lint rule](../tools/lint/src/albedo_lint/rules/clock.gleam) checks this boundary. See [runtime-helper guidance](contributing.md#reuse-runtime-helpers) for timer and deadline rules. ## Unicode scalar limits Use [`text_scalars.length`, `take`, `drop`, and `tail`](../src/albedo/text_scalars.gleam) for scalar-bounded names and previews. These functions scan UTF-8 and copy retained slices. Do not build a list for the entire input merely to truncate it. The [`albedo_text_scalars` rule](../tools/lint/src/albedo_lint/rules/text_scalars.gleam) checks uses of the prohibited alternatives. The [API architecture](../docs/http-api-architecture.md) explains how runtime application relates to persisted intent. [Daemon lifecycle](../docs/daemon-lifecycle.md) covers process attachment and native service ownership. ## Related pages - [All topics](README.md) - [Change guidance](contributing.md) - [Session attachment](sessions.md) - [Extensions](extensions.md)