small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
albedo robot-docs media.md
30 kB · 478 lines
Markdown
at main

Audio and video input #

A model can read audio and video clips beside text and images. A clip travels as a types.Image whose MIME type is one of types.clip_types, and types.media_kind tells a picture from an audio or video clip. A clip has no dimensions, so its width and height are 0. Everything that carries images carries clips: user uploads, tool results, the transcript, the image store, and history reads.

Formats and limits #

albedo_image/clip reads the MIME type from the clip's container and refuses a clip cut short where the container can tell:

Type Container Checked
audio/wav RIFF WAVE The RIFF size covers the file, with a fmt chunk.
audio/mpeg MP3 frames, optional ID3v2 The first frame header is MPEG layer III.
audio/aac ADTS frames, optional ID3v2 The frames run exactly to the end.
audio/flac fLaC STREAMINFO first, then metadata blocks and a frame.
audio/ogg Ogg pages The pages run to the end; the first opens an audio codec.
audio/mp4 ISO BMFF, brand M4A or M4B Top-level boxes cover the file, one of them moov.
video/mp4 ISO BMFF, any other brand As audio/mp4. QuickTime (qt ) is refused.
video/webm EBML with DocType webm The segment runs to the end, or its size is unknown.

Matroska other than WebM, QuickTime, and Ogg video are refused. Nothing decodes the audio or the pictures, so a clip that passes may still fail to play.

albedo_image.inspect_media reads pictures and clips and albedo_image.inspect reads pictures only. Use image.media_from_base64 where a clip may arrive, as the proxy's input_audio parts do (wav or mp3, checked against the format they name), and image.from_base64 where only a picture may, as image generation references and the proxy's image_url parts do. A stored clip read again is matched by albedo_image.matches against its first bytes only.

A clip holds at most types.max_clip_bytes (20 MiB) decoded, a picture types.max_image_bytes (5 MiB); types.max_bytes(mime) picks the bound, and validation, uploads and stored rows all read it. That is albedo's own ceiling, for kernel memory, base64 in json, and resends. A wire may declare a lower cap in types.ImageLimits.max_clip_bytes where its provider has one, and the openai wire does for Azure's 20 MB audio files. The raw upload route cannot know the model, so it keeps the ceiling, and the wire's cap holds where a message names the clip or a cell attaches it: types.media_refusal refuses a larger clip, the daemon sends the cap in each execute message as max_clip_bytes, and show_media raises past it. A request leaves out a clip in its history past the cap, after its copy is swapped in, with [N clip(s) omitted: this model takes clips of at most X MiB]. A cell attaches at most 4 pictures and clips together. Its pictures hold 5 MiB together, which keeps the result inside the kernel link's 8 MiB frame. Each clip may hold 20 MiB and a cell's clips 40 MiB together, because clips cross the link in raw parts beside the result (see Kernel). The kernel's clip_type ports the Gleam reader so the cell fails at the call. clip_header_parity_test holds the two to one answer over fixtures cut from real encoder output. Change both readers together.

Size estimates price a clip by how long it plays, at the rates the model's media facts give in types.Fidelity.tokens: the shipped Gemini entries bill 32 tokens a second of audio and 66 a video frame (258 before Gemini 3), at the clip's frame rate or the copy's, with its sound. clip.duration_ms reads the duration from a WAV's byte rate and data size, FLAC's STREAMINFO, an MP4's mvhd, an MP3's Xing or Info frame count or its first frame's bitrate, and an AAC stream's ADTS frames. Ogg and WebM keep theirs where only a full parse finds it. runtime/clip_cost reads a clip's payload once per daemon to learn it and gives the loop's size.Route the pricer, so an estimate does not change when a copy is made. A clip with no duration, or for a model with no token rates, counts a token per 400 decoded bytes in size.gleam. Provider usage corrects the estimate (compaction). The context summary reports the same prices by kind as media_tokens (context inspector).

Text that stands in for summarized media names each picture or clip with compaction.media_notes, such as [clip audio/wav, 48044 bytes; binary omitted]: a summarizer's input, rolling's recap of the user messages it summarized, and the source coding-lcm and persistent-agent keep verbatim when their summarizer answers nothing.

Which models read clips #

types.ImageLimits.media names the clip types a session's provider reads. Each upstream declares what its wire carries:

  • Gemini inlineData takes every type (types.gemini_clips): Vertex, Antigravity's Gemini models, and OpenCode Go's Gemini route.
  • Chat Completions input_audio takes WAV and MP3 (types.chat_audio): the OpenAI-compatible extension on that protocol, and OpenCode Go's Chat route.
  • Every other wire, the Responses API and Anthropic Messages included, takes none.

runtime.upstream keeps only the types whose kind, audio or video, the model's catalog lists in input_modalities. Unlike images, a model no catalog describes reads no clips, unless this daemon saw a catalog answer for its endpoint and model in the last week: that answer stands, so a model dropping out of a catalog does not turn the clips in its sessions into notes and back. The memory ends with the daemon. Albedo reads only image support from Antigravity's discovery, so its catalog lists audio and video for its Gemini models.

The request gate #

types.readable_input turns every clip a provider does not read into a note in its message, such as [1 clip(s) omitted: this model does not read audio/wav]. It also stands for a text-only model's pictures. The model loop applies it when it builds a request, and runtime.upstream wraps every upstream's stream and count with it, so no request reaches a wire with a clip it would refuse, whoever built it. The transcript keeps the clip. A session that switches back to a model that reads it sends it again.

A new clip is refused where it arrives:

  • show_media raises in the cell, naming the types the model reads. The daemon checks a cell's clips again with types.media_refusal and reports the ones it drops in image_errors.
  • A message's image is refused with 409 image_rejected by the session's refused_image check, whether it came inline or as an upload, and whether the message is new or an edit of one still waiting.

Gemini nests only pictures in a function response. The Gemini and Antigravity encoders send a tool result's clips in the following user turn, labelled Tool result media:.

The clip budget #

A request carries at most types.ImageLimits.clip_budget of clips as base64. Each wire declares its budget beside max_edge, leaving the rest of its provider's request limit, which counts the whole body, to text and pictures. runtime.upstream holds it to types.request_clip_budget (64 MiB), albedo's own ceiling: every turn sends the whole history's clips again, even where a provider takes far more. Every reader below takes the budget from the session's limits. A wire that carries no clips leaves both bounds at albedo's ceilings.

Wire Budget Source
Vertex 400 MiB, held to 64 500 MiB a request, base64 included
Antigravity's Gemini models 64 MiB Measured: a 100 MB request with a 75 MiB WAV inline went through
OpenCode Go 12 MiB Nothing published. Its edge took 16 MB bodies and refused about 17 MB (#54784, #59067)
OpenAI-compatible Chat Completions 64 MiB Nothing published for input_audio

The clip_budget a /shake listing reports is the budget of the session's current model, or albedo's ceiling when the session has no provider.

The budget is kept where clips arrive, so a request never has to leave an older clip out to make room for a newer one. That would change an earlier message and miss the provider's prompt cache from there on. What a session holds is runtime.clips_held over the clips its next request carries, as its current model receives them, after readable_input, each counted as its copy when an image_copies row has one and as it is otherwise. It reads the sizes stored references carry and the copy rows, never a payload. A compaction leaves the clips of the messages it summarized out of the request, so admission counts an entry from before the last prepared request only for the clips that request carried (context_snapshot.retained_clips), and every clip after it. Without a request prepared on the current model, after a restart or a switch, every clip in the history counts until the next one. A clip that would take that past the budget is refused:

  • A message is refused with 409 media_budget, inline images and uploads alike, by the same refused_image check, so the upload waits for the next try. Its detail says how much the session holds, the limit, and that /shake frees room. A new clip counts as it is, since no copy of it exists yet.
  • A cell's clips are checked against the room left. The loop sums the step's prepared history, which leaves out what a compaction summarized, before its tool calls and passes the room to each call (extension.Context.clip_room), less what the calls before it attached. The daemon sends it in each execute message as clip_room, show_media raises when the call's clips do not fit, and the python tool keeps back the clips past it with an image_errors entry that names commands.shake.

Inputs already waiting in the queue are not counted, so two messages queued behind a running turn can together pass the budget.

A history can still hold more than the budget: after a switch to a wire with a smaller budget, or to a model that is sent larger copies or the originals, or once ffmpeg is gone. Then types.within_clip_budget keeps a request's clips newest first within it, and the older ones become [N clip(s) omitted: newer clips fill this request's media budget]. While the history is past the budget every new clip is refused, so each request trims it the same way and its prefix stays cached. runtime's wrapper applies readable_input to each message, swaps clips for copies, then applies the trim.

Pictures have no budget of their own, only their edge and per-image bounds. A body a provider refuses as too large is compacted and resent, as a prompt past the window is (compaction): Claude behind Vertex and Antigravity takes 30 MB a request, which a session of screenshots passes before its window.

Copies a model takes in #

A clip is sent with every request after it, and a model often takes in less of it than the file holds. How much is a fact about the model, not the wire, so it is the media section of the model facts, read by media_facts. A wire declares only what its protocol carries: the clip types in media, and in types.ImageLimits.frame_rate whether it can ask for a video's frame rate. runtime.upstream fills types.ImageLimits.fidelity from the first media entry that matches the profile's extension, the endpoint's host and the model, and drops its maxFps when the wire cannot send a rate. A model no entry matches is sent its clips whole and priced by their size. Everything after reads the fidelity from the limits.

A media section names each part, and leaves out what the model does not have:

{
  "audio": { "sources": ["audio/wav"], "rate": 16000, "kbps": 32 },
  "video": { "edge": 768, "fps": 1, "audio": { "rate": 16000, "kbps": 32 } },
  "maxFps": 24,
  "tokens": { "audioSecond": 32, "frame": 66 }
}
  • audio: the clip types copied, and the copy's sample rate in hertz and bitrate in kbps.
  • video: the copy's longest edge in pixels, its frame rate when the request asks for none, and its sound.
  • maxFps: the fastest rate a request may ask the model to sample a video at.
  • tokens: what a second of audio and a video frame cost.

The shipped entries:

Entry Matches Audio copy Video copy Tokens
gemini-2 gemini-2* models Any audio as mono 16 kHz MP3 at 32 kbps H.264 MP4 at the request's frame rate or 1, within 768 px, with 16 kHz sound 32 a second, 258 a frame
gemini gemini-* models As gemini-2 As gemini-2 32 a second, 66 a frame
audio-copies Every other model WAV as mono 24 kHz MP3 at 64 kbps None None, so priced by their size

Both Gemini entries take a maxFps of 24, the bound Google Cloud's reference gives videoMetadata.fps. Their sources are in the entries' provenance. The Gemini 3 figure is measured: with no mediaResolution set, Antigravity's gemini-3.8-flash-medium billed 66 tokens a frame on 2026-11-18, the figure Google's video page gives, not the 70 of its media resolution page. The Gemini 2 figure is documented only. Gemini reduces audio to 16 kbps and merges its channels, and samples video at 1 frame a second unless a request asks for another rate. Gemini 2 counts a 768 px picture tile as 258 tokens, so frames within that edge keep what even the high media resolution reads. OpenAI documents no sample rate for input_audio, so only a WAV, the lossless type it reads, is copied, at the 24 kHz its Realtime API takes. An MP3 may already be all the model hears.

Override an entry by its ID, or add one, in $ALBEDO_HOME/model-facts.json. A new ID goes first, so {"id": "mine", "match": {"model": "gemini-3*"}, "media": {...}} changes what Gemini 3 models get from the next request. A changed copy has a new profile, so its clips are encoded again once.

runtime/media_copies swaps each clip for its copy in runtime's request wrapper, after the type gate and before the budget, so every request to the upstream carries the same clips, and the budget counts what is sent. A route's count is not asked about a request that carries clips: each sizing would upload them again, so the usage earlier requests reported and the estimate size it instead. A clip of at least 256 KiB is copied when its model's facts name a copy for it and its wire reads the copy's type. The copy is used only when it is a valid clip of the planned type at most three quarters of the original's size. The message that carries it gains a note, such as [1 clip(s) sent re-encoded as 16 kHz mono MP3]. The transcript, history reads, the history image route and stored rows keep the original, so a session that switches to a model that takes more sends the original again.

Copies are kept in image_copies, keyed by the original payload's hash and a profile naming the encoder version and its bounds, such as 1:mp3:16000:32. The table is derived: a row references its source payload, goes with it when images.release deletes it, and is left out of transfers. A copy that finishes after its source was released is not kept. A failed encode, an unreadable copy, and one too large to use are recorded too, and a recorded row is kept, so a request on the same model sends the same bytes every turn and a clip ffmpeg cannot shrink is not encoded again. An encode cut short, by its deadline, a signal, or a scratch directory that could not be made, says nothing about the clip: its row carries a retry_at ten minutes on, the clip is sent as it is until then, and the next request after it encodes again and replaces the row. A copy's payload is read only while a request body is written. Without ffmpeg on the daemon's PATH nothing is recorded and the clip is sent as it is. A later request that finds ffmpeg copies it then, which changes that request's prefix once.

albedo_sdk/transcode runs ffmpeg with a deadline of two minutes, killing it there, in a scratch directory that goes with the call. Each copy is encoded in a process of its own under an albedo_process/lock held per copy: a second request that wants it waits for the first and reads its row, and a request cancelled meanwhile does not cancel the encode. At most two encodes run at once across the daemon, each copy taking the slot its key hashes to, since a model switch can ask for a copy of every clip in history. A request that waits past twice the deadline sends the original.

Shake #

/shake drops media from a session's history for good, and the model calls it as await commands.shake(...). Without a selector it lists each stored picture and clip once: an id of the first 8 hex digits of its payload hash, or more when two payloads share them, its kind, MIME type, size, and every row that shows it, a message or a tool result. clips_held and clip_budget say how full the requests are. Selectors are audio, video, image, all, or ids; one id names every row that shows the same bytes. An unknown or ambiguous id is refused and names the candidates. Clients reach it through GET /sessions/{session_id}/media and POST /sessions/{session_id}/media/shake; a refusal is 409 shake_refused.

storage/images.shake rewrites what shows the media in one transaction, the way compaction elides evicted tool images:

  • Each transcript row loses those images, and its text gains a marker for each, such as [audio/wav clip removed by shake]. A message left with no images is plain text.
  • Each Python cell result of the session loses them the same way.
  • A fit row scaled from a shaken picture, or from a copy such a row made, becomes its note, so nothing keeps the scaled copies.
  • images.release then deletes the payloads, their thumbnails and their copies, unless another row, pinned prompt or cell still names them. A fork keeps what it shows until it is shaken too.

session_shake runs in the session actor. It drops the loaded history, so the next read loads the rewritten rows, and tells clients to read the session and its context again. While a turn runs, the turn goes on with the rewritten history from its next request: RequestBoundary answers loop.Reloaded with the reloaded entries. Until then a retry resends the request the step already built, which reads the shaken payloads, so the shake holds their release back (State.shaken) until that boundary or the turn's end. A daemon that stops in between keeps those payloads. A compaction, summary or background call reads the history without such a boundary, so a shake is refused while one runs.

A shake changes earlier messages, so the next request misses the provider's prompt cache once; its answer says so. A saved compaction cut covers the user messages it summarized, uploads included. Shaking an upload a compaction already summarized changes that message, so the strategy finds the cut no longer matches and compacts again from the whole history. Tool results a compaction evicted have no images left to shake. The cut is a digest, never a payload reference, so it cannot keep a released payload alive or name one that is gone.

The kernel #

show_media(source, *sources) attaches images and clips as bytes or paths, telling them apart by their headers; show_image is the same function. Each call refuses a file cut short or a clip of a type the model does not read. A nested cells.run passes its attachments on to the outer cell. Plugins attach either with api.attach_media, and rem.show_media(path) (or rem.show_image) reads one from a remote host, up to the same 20 MiB. files.image(index) returns an uploaded clip's bytes too. The daemon sends the model's types to the kernel in each execute message as media, and the room the session's requests have left for clips as clip_room (the clip budget).

Frame rates #

show_media(..., fps=N), rem.show_media(path, fps=N) and api.attach_media(data, fps) ask the model to sample the call's videos at N frames a second. The bound is types.Fidelity.max_fps, the maxFps of the model's media facts, kept only on a wire whose types.ImageLimits.frame_rate says it can ask: the Gemini wires (Vertex, Antigravity's Gemini models and OpenCode Go's Gemini route). Every other wire has none. The daemon sends the bound in each execute message as max_fps. The call raises, attaching nothing, when the model takes no rate, when N is not above 0 or is past the bound, or when any item of the call is a picture or audio.

The rate travels with the clip: a base64 result entry is {"data": base64, "fps": N} and a raw part's is {"clip": digest, "fps": N}, which blobs keeps when it puts the bytes in. The daemon reads it with types.with_fps, which takes a rate above 0 for a video only, and types.media_refusal turns a rate the model does not take into an image_errors entry. The clip is stored with its rate, so every later request repeats it.

types.readable_input sends a stored rate as it is within the model's bound. Above it the clip goes at the bound, with [1 video sent at 10 fps, this model's most; asked for 20] in its message. To a model that takes no rate it goes without one, with [1 video sent without its 5 fps: this model samples at its own rate]. Only the call refuses. albedo_gemini/request inline_part, which Vertex, OpenCode Go and Antigravity's wire encode clips with, puts videoMetadata: {fps} on the clip's part. A video copy is encoded at the rate its request asks for, or 1 when it asks for none.

Storage #

A clip is stored as an image: its payload in the images table under its content hash, and the transcript row or cell result keeps the packed {image, Mime, {stored_data, Hash, Size}, 0, 0, Bytes}. The layout is the one in Persisted terms, so no migration runs. A loaded history reads stored clips lazily, like stored images.

A clip with a frame rate is types.Image's Clip constructor, packed as {clip, Mime, Data, 0, 0, Bytes, {clip_options, Fps}} by image_codec. Only such a clip takes the new layout: pictures and plain clips keep {image, ...} and the bytes earlier daemons wrote, in rows, cell results, inbox submissions and compaction fingerprints. The decoder reads both and refuses options on a picture or audio, or a rate that is not a float above 0. image_codec.hashes finds the payload hash in either, so deleting a session releases a clip's payload with it.

A build from before clips reads a stored clip of at most 5 MiB as an image of its type, which Gemini takes and other providers refuse. It cannot load a larger clip: the session's history answers 503 invalid saved transcript item, and a new message is accepted but never sent. Opening the session on a newer build again works for both.

A build from before frame rates cannot read a row or cell result that holds a clip with one. Opening the session fails with invalid saved transcript item, and reading the cell fails. A row that build finds unindexed at startup is healed: replaced with a note that it could not be read, its bytes moved to transcript_quarantine, and a newer build does not put it back. Rows without a frame rate read as before.

Clients #

The history image route serves a clip with its own Content-Type. It ignores edge for a clip, and answers one Range: bytes= range with a 206, which media players use to seek. The OpenAPI ImageUpload enum lists the clip types.

Raw uploads #

PUT /sessions/{session_id}/uploads/{upload_id} takes a picture or clip as its own bytes, its Content-Type naming the MIME type, so a 20 MiB clip does not travel as base64 inside a message. http_uploads admits the route with a body limit of types.max_clip_bytes, and media_uploads checks the bytes with image.media_from_base64 against the declared type, then keeps them in $ALBEDO_HOME/uploads/<session>/<upload_id>. A repeat with the same bytes answers the same upload; other bytes under that ID are id_conflict, even when both arrive at once: saves to one home take turns under an albedo_process/lock, which also keeps two uploads from both taking the last room under the bound. A message names it with {"upload": id} in images, beside inline {mime_type, data} entries, which ACP clients still send. The web and terminal clients upload every picture and clip; the terminal's daemon client keeps the upload IDs on the message's operation, so a resend repeats the same uploads. The message reads and checks the bytes again at admission, so the model's gate applies to the model the session has then.

An upload waits until a message the session accepts takes it, which deletes the file. A resend of that message, from a client that lost its answer and uploaded again, deletes it again. A message the session refuses, a clip its model cannot read among them, leaves the upload for the next try. One no message takes expires a day after it was written: reads past that treat it as gone, each new upload deletes expired ones first, and the maintenance sweep deletes the rest. Deleting a session deletes its uploads with it. Together, the uploads waiting across every session hold at most 256 MiB; past that a new one is refused with 429 uploads_full. A message naming an upload that is unknown, expired or already taken is refused with 409 upload_unknown.

The web client takes clips in the composer and plays them in messages and tool results with Clips.svelte. A clip's marker names its kind, [Audio #n] or [Video #n], numbered with the pictures' [Image #n], so the model reads which attachment each one is. The daemon does not parse markers; both clients write them, and the terminal client titles a clip's card with its kind and type. In the terminal, Ctrl+V attaches a picture, audio or video file copied in a file manager, read from the local disk, or else an image on the clipboard; over ssh the clipboard names files on another machine, so only images paste there.