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

Workspaces #

A session workspace identifies the directory where its work runs. The daemon represents it as a local path or an SSH location. Worktrees are separate checkouts that can supply a workspace.

Locations #

A location is the SDK's value (sdk/location), and every check that reads a disk or a host is core's (locations). location.parse accepts local strings beginning with / or ~, and remote locations of the form [user@]host:/absolute/path. Bracketed IPv6 addresses are supported. Remote paths are normalized lexically. This does not resolve filesystem links. User and host names must begin with a letter or digit.

locations.workspace validates an existing local directory when a session is created or moved. It resolves remote ~ through SSH, but accepts an absolute remote path without checking its existence at that point. A later operation can fail when the host or directory is unavailable.

locations.exists observes a local or remote folder without opening it. An unreachable host returns an error, not a missing-folder result. The remote probe and gather retain their separate time bounds.

ssh caches each host's probe answer: a ready host for a minute and a failure for five seconds, so repeated reads of an unreachable host do not each wait on ssh. ssh.ready answers that cached failure. A relay to another daemon, which a move, its finish, and letter forwarding open, connects through ssh.reach instead: a cached failure starts a new probe, so an action taken after the host came back is not refused on an answer from before. The daemon's cache probes through albedo_ssh.py; ssh.start_cache takes another prober, so a test drives the cache's rules without ssh.

A relays.Relay is the target daemon's home and two functions: send one HTTP call, and close. relays.connect builds one over ssh, and the move steps that reach a target take that connector as a parameter (moves.preflight_with, moves.finish_with), so a test can hand them a relay that calls a daemon in the same VM or fails as ssh does.

The relay starts in the host's login shell, so its first answer waits on the user's profile as well as on ssh. A relay that has not answered by its deadline reads as "can't reach the albedo daemon", so do not give the preflight's relay less time to start than its ssh probe (moves.preflight_relay_open_ms). With less, a reachable target that a move would reach is reported out of reach, and the user gets the wrong remedy. The move's own steps allow 30 seconds.

location.label and location.to_json show a remote host's alias, with user@ only when it differs from the user ssh config picks for it. The SDK formats without reading anything: the caller passes that lookup. locations.label and locations.to_json pass core's ssh -G reading, which the daemon caches for its life.

Extensions reach these checks through the hosts capability (sdk/hosts) on extension.Daemon and extension.Preparation: observe a host's cached probe, check whether a folder exists, and resolve a workspace. The links extension declares it to show members' presence. It is separate from Remote, which reaches sessions on other daemons.

Linked workspaces #

links stores workspace group membership. Linked workspaces retain their own data while group readers can include the other members. Linking and unlinking are separate from creating a worktree.

The links extension owns membership changes and session notifications. See its service and ledger. Group reads also include managed worktrees of each origin, as links.members shows. Which worktree a workspace is and what was made from an origin are core's records, so every group read takes the worktree.Origins its caller's context carries (origins on host.Context, Preparation, Daemon, and a sidebar's extension.Sidebar), which core's worktree.origins answers on the caller's connection. A failed read, as before the table exists, answers as if no worktree contained the workspace. The ledger declares workspace_links with its revision tables. The extension's initialiser calls the SDK's generated create_workspace_links, and its ledger writes the table.

The links API uses the recorded origin for a managed checkout, its workspace, and paths inside the checkout. An unrecorded checkout is its own workspace. The configuration response identifies the origin and lists explicit members. It shares its ETag and pagination tokens with requests made directly to the origin. For a merge, the query workspace and the peer path each resolve to their origin. For an unlink, both the query workspace and the member resolve to their origin. Unlinking a managed path detaches its origin from the group. The ledger resolves paths again in the write transaction before checking the observed validators.

At startup and when the daemon records or removes a managed worktree, the ledger checks legacy explicit memberships. It replaces a managed path with its origin when the replacement preserves the group's peer relationships. Multiple rows that resolve to the same workspace count once. When two groups would claim the same origin with different peer sets, the ledger keeps the stored rows and returns 409 link_migration_conflict for the affected groups. The error names a managed path and its origin. Runtime readers still follow the origin and ignore explicit managed paths in another group. Resolve a conflict by removing the managed worktree record through the worktrees extension, or by reconciling the conflicting membership rows offline with a backup before restarting the daemon. A session transfer carries no links, link revisions, or migration conflicts.

A change to a group posts a note to every session on this daemon in a member workspace or in a managed worktree of a member. The note for a join names the workspaces that joined, and the host adds what each recipient's own active extensions say about them through Daemon.linked_summaries (plugins). A session with memory active hears the memory its next snapshot will hold for them; a session without memory, or whose memory is quarantined, hears only the change. A session preparing when the link commits usually has that preparation refused, with "composition inputs changed during preparation", and its next preparation holds the new group in its snapshot. In a narrow window it can still publish the group it read; it then reads the new group at its next open or reload. The host collects every recipient's summaries under one deadline of a few seconds, so a slow or failing summary drops only itself. When the host cannot read a session's composition, its note goes without summaries, and a session already loaded then sees the joined memory only after it reloads. Links itself reads no memory.

Moving a session #

session_workspace records workspace changes and tracks their application to family members. A session configuration change and its application are distinct outcomes. The session configuration owner and session workspace owner govern the persisted state.

Moving a session between daemons is a separate transfer. transfers owns export and import, and http_transfers defines the HTTP routes. transfer/codec owns the segment format and streams rows through SQLite statements prepared on the caller's connection. Its module comment defines the cell encoding. A zero-byte chunk at a valid offset leaves the staged segment unchanged. transfer_files compares any overlapping bytes before appending the remainder. A mismatch leaves the staged segment unchanged. Keep segments byte-identical across changes. The golden case in transfer_codec_test pins the bytes and digest of a known export. Transfer adapters declare which extension data travels. See carry rows when a session moves for an adapter's tables, shifts, and activation. A transfer is not ongoing synchronization between the daemons. After a move, extensions reach the session's new daemon through host.Context.ask_moved, and refuse arrivals for it through extension.Daemon.tell_refused and hook_gone. These callbacks keep relay and refusal behavior with moves. While listing bindings or accounting for late occurrences, the source skips an adapter when all of its declared tables are absent. An adapter with a present table reports any storage error to the move.

Each owner keeps its stored states as a type with one codec for the stored and HTTP spelling. transfers owns TransferState and TransferRole, and moves owns MoveState and the binding status. A move reads the target's import state through transfers.parse_state. Bind states through the owning codec. Recovery queries name the admitted or excluded states, and guarded transitions bind the expected state separately from the next state. The guard keeps a stale caller from overwriting a newer transition.

Moves between versions #

Moves between daemons of different builds are supported in one direction only, from an older daemon to a newer one. Both must speak the same transfer.protocol. The source checks the target's protocol before it exports.

A move to an older daemon is unsupported when the carried schema differs. The export lists every carried table and every column in the manifest, including empty tables. An older target does not know a table or column added since its build. It refuses the manifest at staging, in transfers.known, when a segment:

  • names an extension the target lacks (transfer_unsupported), or one built in there that failed to load (transfer_extension_unavailable; older targets answer transfer_unsupported)
  • names a table that extension does not carry there (transfer_unsupported)
  • has a different table version (transfer_version)
  • has a column the target's table lacks (transfer_version, as owner/table here lacks column)

The source keeps the target's detail, which names the first thing it lacks, and reports transfer_version as transfer_target_older (relays.staged). It keeps transfer_unsupported, because a target from before transfer_extension_unavailable gives it both for an older build and for an extension that failed to load. The move then fails before anything goes live on the target, and before the target writes a receipt or staging directory. The source keeps the session, its bindings stay armed, and it still takes input.

The preflight asks the target before a move starts, through POST /transfers/check (transfers.check). The source sends transfers.shape: every table the export would list, with its version and this daemon's columns, without rows. It also sends one file entry for each owner that carries files and no tables, such as memory, when that owner has files to send. The target runs the same known checks and nothing else. It reads table columns, and writes no receipt or directory, runs no expiry, and checks no space. The check knows which extensions are quarantined, so the source reads a missing extension or table from it as transfer_target_older (relays.checked), and transfer_extension_unavailable stays as it is. Either makes the preflight unavailable with that code and the target's detail. A target from before the route answers 404 or 405. The preflight then offers the move, and staging refuses what that target lacks.

Clients read these codes for a person and keep the target's detail as secondary text. transfer_target_older asks to update albedo on the target. transfer_extension_unavailable says the extension failed to load there, with no update advice. transfer_unsupported names both causes. See the terminal client and the web client.

The daemon has no ordered version to compare. /server reports a build label and digest, which tell two builds apart but not which is older. The schema checks are what decide.

Keep older-to-newer moves working:

  • Keep adapter names stable. The target finds a segment's adapter by its owner name, so a renamed or removed adapter refuses segments from older daemons.
  • Keep the segment format byte-identical, as the codec requires.
  • Do not bump a carried table's version. The target accepts only its own version, so segments from older daemons would be refused.
  • Settle rows imported from an older daemon in the adapter's activate, as webhooks does.

move_versions_test.py moves a session from a pinned older build to this checkout, and checks that the reverse move is refused cleanly. move_test.py checks that the preflight refuses a target of this build that lacks a column, and writes and expires nothing there. transfer_check_test.gleam covers each refusal code, including a quarantined extension. See mixed-version moves.

Starting an older daemon on a whole home that a newer one upgraded is a different case. See downgrades.

Browsing #

Without a location, GET /workspaces lists workspace paths from session history. Its optional worktree filter uses the same managed checkout rule as the session list, before paging. With location, the endpoint browses directories instead.

folders.directory returns a directory listing for the folder picker. The same module owns file reads and existence checks. Remote locations use the location and SSH handling in that module, so an unavailable host is a distinct failure from a missing local directory.