small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo

Harness runtime #

The harness runtime owns the extension installation, ledger, session compositions, and Python kernels used by the daemon. The daemon's session actor coordinates turns with this runtime.

Startup and ownership #

runtime.start_with_config 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 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 decides when to request and release a kernel.

Execution and tools #

runtime.execute 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 can observe or refuse calls.

Lifecycle #

runtime.delete_session 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.

Extension reload ownership #

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 so the actor stays responsive.

The existing Origin and handed_out contract in 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.

Clocks #

Use albedo/clock 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 checks this boundary. See runtime-helper guidance for timer and deadline rules.

Unicode scalar limits #

Use text_scalars.length, take, drop, and tail 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 checks uses of the prohibited alternatives.

The API architecture explains how runtime application relates to persisted intent. Daemon lifecycle covers process attachment and native service ownership.