small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
albedo robot-docs provider-requests.md

Provider requests #

The daemon records provider attempts separately from the conversation transcript. requests.gleam owns the row schema, prefix identity, recording, and queries. These records support usage and cache analysis. They do not store request bodies.

What a row holds #

A row identifies the session, request kind, profile, provider, account when known, model, timing, outcome, and optional status and error. It can also contain reported usage, cost, stream observations, and response identifiers. Kinds include turn, summarizer, background, title, and side calls. outcome bounds HTTP and provider error details to 2,000 text scalars before adding a truncation marker. See Call, outcome, and record.

record returns a result, so a storage failure can prevent a row from being recorded. A row starts with a null transcript sequence. attach_in can attach it after the transcript row commits. Reported cost contributes to session spend in the same store operation as the insert. Missing cost adds nothing.

Prefix identity #

prefix hashes the instructions and tool definitions as the request head. It records the projected input count and, when projection replaces history, the count replaced and a hash of the replacement. direct_prefix describes calls outside session projection without a replacement identity. These hashes help compare requests without storing their bodies. They do not prove a provider cache hit.

Reading requests and usage #

page reads session rows with an ID cursor and time filter. The session HTTP handler exposes the request listing. The usage-hours migration defines an insert trigger that aggregates calls, errors, and token counts by hour, profile, provider, account, model, and kind. See quota for separately polled provider readings.

Usage totals #

usage_hours.summary reads hourly aggregates into day totals and per-profile, provider, account, and model summaries. It reports when its model or account lists are truncated. Day totals include all matching aggregate rows, including rows omitted from those lists. These are totals of recorded usage, not an independent measurement of provider billing.

Image generation #

The Codex image driver does not record its calls through requests.record. Image generation is therefore absent from these request listings, recorded spend, and usage totals. Missing image usage does not establish that a call consumed no quota or incurred no charge. See image generation for request identifiers and recovery rules.

Transport #

openai_api validates client header values before transport. stream_http handles streaming exchanges, and transport exposes both ordinary receive and deadline-based receive functions. Do not assume every stream wait has a timeout.

The connection coordinator tries IPv4 and IPv6 concurrently for hostnames. HTTPS selects the first connection that completes certificate verification, so a failed or stalled TLS handshake on one family does not discard a usable connection on the other. IP literals use only their own address family.

The streaming transport builds TLS options and loads trusted certificates only for HTTPS connections. Plain HTTP connections do not need that initialization.

One monotonic deadline covers fresh connection establishment, including DNS, TCP, TLS, and socket handoff. Cleanup confirms that losing attempts have stopped before returning. Cleanup can finish after that deadline while workers are being stopped. This budget does not replace the separate send, first-event, or response-body budgets.

Keep socket ownership and process cleanup in the native adapter, and connection selection policy in the coordinator. Attempts must not send HTTP requests. Only the selected connection reaches the existing request guard and HTTP writer. Preserve certificate and hostname verification, pool ownership, and the rule that guarded requests never replay implicitly when changing this path.

Mistral wire projection #

The Mistral wire module normalizes streamed thinking parts, projects replay for the current reasoning effort, and maps tool IDs before using the shared Chat Completions codec. It leaves stored replay unchanged. The sign-in module builds the browser sign-in's requests and PKCE pair, checks that returned URLs stay under the console, builds the stored key account, and runs the status poll. See sign-in ownership for deadlines, input wakes, and cancellation.

Claude image uploads #

claude/files owns Files API multipart requests, response IDs and expiration, and inline fallback. It uses SDK HTTP requests and four linked concurrent workers. A reader or upload failure leaves that image inline while successful uploads remain reusable. Stopping the caller stops its workers. A stopped batch does not publish partial cache state. The provider extension still supplies the account identity, credential header, and approved endpoint. Uploads do not choose another credential destination.

The persistent claude-files.json format remains an account object containing content keys and entries with id, bytes, and optional millisecond expires_at. Content keys hash the base64 payload. Fresh callers reuse saved handles. Expired handles and unreadable caches fall back inline. An unreadable cache is left unchanged. Newly uploaded handles become visible only after a successful cache write. A failed write leaves those images inline.

The shared file.with_lock protects short cache reads and merges. Image readers and HTTP uploads run outside that lock. A separate home-wide upload slot admits one batch with four workers; file.with_lock_timeout waits at most 50 milliseconds for this optional work. A busy slot leaves missing images inline. Empty and fully cached requests skip upload admission. Locks are daemon-local and independent of credential transactions; they do not coordinate separate OS processes.

A file-related 4xx rejection quarantines the caller and advances the account's in-memory generation under the cache lock before attempting a purge. Uploads capture that generation and discard results if it has changed before the merge. Fresh reference tokens also reject old results after generation storage is lost. A failed purge still fences earlier uploads, although existing saved handles may remain available to other callers. Other accounts survive the purge. Later callers may upload fresh handles; caller-local quarantine ends with its process.

Wire encoding loads one fresh account snapshot per request and projects all images from it without further disk reads. A later request observes sibling purges. This snapshot cannot revoke a request that has already been assembled. Keep this persistent cache with its feature owner; transient memo entries do not replace it.