Skip to content

How it works

A workspace has a short life with four commands: lo new, lo up, lo down and lo rm. This page tells the actions of each command and their order. Use the page to understand the output of lo, and to find the reason for a failure.

lo newrecord the workspacecreatedlo upmake and startup / partiallo downstopdownlo rmremoveremoved

lo new records a workspace and starts nothing. It does not make a worktree, a container or a process. The command makes these records:

  1. The name of the workspace, a short random ID and a slug of the name. The slug is the name in a form that is safe for host names and for file names.
  2. The template, and the mode of the workspace: template for lo new, worktree for lo up in a git worktree.
  3. One source for each repository that a service uses. lo new fetches origin of each repository, then selects the ref. It uses the ref that you give, the branch that --match finds, or the default ref of the template.
  4. One unit for each service and for each resource server. Each unit keeps the engine that the machine settings select now. A resource keeps its isolation.
  5. The --env overrides and the shared instances that the workspace uses.

The workspace has the status created. Template errors, an unknown ref and a name that a different workspace uses stop the command before it records anything.

lo up makes the workspace run. It holds a lock on the workspace, so two commands cannot change the same workspace at the same time. The next sections follow the order of the actions.

loop[each service, in dependency order]lock the workspace, compare the state with the machinecheck the memory and the diskrecord new units, set the status to starting, allocate portsmake or reuse a worktree for each sourcestart shared instances, then the resourcesresolve the environment variablesrun setup and seed commands, then start the unitwait until the unit is readyapply the routes of the public URLsset the status to up, partial or downlo upStateGitEnginesProxylo upStateGitEnginesProxy
  1. lo up locks the workspace. It compares the records with the machine: an engine can say that a unit stopped, or a worktree can be gone. If a source directory is gone, the status is broken and lo up stops with the command to repair it.
  2. lo up compares the memory and the disk that the units use with the free memory and free disk of the machine. The units use the average of the earlier runs. If the machine is short, lo up shows a prompt. Use --yes to start without the prompt.
  3. lo up adds the units that the template got after lo new, and sets the status to starting.
  4. lo up allocates a host port for each unit that listens. A port comes from the range in the machine settings. It is free on the machine at that time, and no other workspace holds it. The workspace keeps the port until lo rm.

For each source, lo up makes a git worktree in the localspace home, in worktrees/<workspace>/<repository>. It reuses a worktree that it made before. The worktree is an owned worktree. localspace removes only an owned worktree.

  • If a worktree of the user has the branch, lo up does not make a copy. The service runs from that worktree, and localspace did not make it.
  • A source that uses the default ref is a snapshot with no branch. lo up moves the snapshot to the current commit of origin, only if the snapshot has no unsaved work.
  • In worktree mode, the service runs from the worktree where you ran lo up. localspace did not make it.

lo up starts the shared instances that the workspace uses, in reference order. With --service, it starts only the shared instances that the selected services must have: the items in their depends_on, or the services that a service without depends_on references. It then starts the resources in alphabetical order. Last, it starts the services. A service starts after the items in its depends_on. A service without depends_on starts after the services that it references.

A resource with instance isolation starts a server. A resource with database isolation makes a database on a server that workspaces use together. The server starts if it does not run. The provider then makes the database, or finds the one that carries the marker of the workspace.

For each service, lo up does these actions in order:

  1. Resolve the environment variables. The command replaces each reference with a value for this workspace. It reads the secrets from the secret store. A container and a host process get different addresses for the same reference.
  2. Do nothing more if the engine says that the unit runs.
  3. Run the setup command. A host process runs it in the directory of the service. A container runs it in a container that the engine removes afterward.
  4. Run the seed command of each resource that this service seeds, if the resource has no data from a seed.
  5. Start the unit with the engine that the workspace keeps. A container is built first.
  6. Record the public URL of the service, if the service is exposed.
  7. Wait until the unit is ready.

A unit is ready when its host port accepts connections. A ready setting can change this check to an HTTP path or to a command. The wait stops after 120 seconds, and the unit is failed.

A failed unit does not stop the other units. lo up keeps going, and the result lists the units that failed. Read their logs with lo logs. The one exception is depends_on: a service does not start if an item in its depends_on failed.

lo up gives the routes of the exposed services to the proxy. The proxy then serves the public URLs. Last, lo up sets the status of the workspace.

Status Meaning
up All services run and all resources are ready.
partial Some units run and some do not.
down No service runs.

localspace keeps its state in a database in the localspace home. The state has the workspaces, the sources, the units, the ports, the resources and an event for each change. The dashboard and lo read the same state.

The state is a record, and the machine is the truth. Before each read, the core compares the two. If an engine says that a unit stopped, the core records the unit as exited or missing. If a command was killed during lo up, the core records the units as the engine shows them. A workspace with a worktree that is gone gets the status broken.

Item Statuses
Workspace created, starting, up, partial, down, broken
Unit starting, running, stopping, stopped, restarting, failed, exited, missing

A unit is a service or a resource server that an engine runs. The state has a handle for each unit that started. The handle is a small map that the engine gives. The engine uses it to find the container or the process again in a different command. The core treats it as opaque data.

The workspace keeps the engine of each unit from lo new. If you change the engine in the machine settings, the change is only for new workspaces. A workspace uses the engine that it keeps until you remove it.

lo down stops the units and removes nothing. It keeps the worktrees, the data of the resources, the ports and the records. It stops the shared instances that no other running workspace uses. It then updates the routes of the proxy, and the status is down.

lo down --service <name> stops only the services that you name. The status is then partial.

lo rm removes a workspace and the things that localspace made for it.

  1. Refuse if an owned worktree has work that is not saved. See safety.
  2. Release the ports that lo checkout bound to the workspace.
  3. Stop and remove all units, and drop all resources. The provider of a resource removes the database, the bucket or the volume of the workspace.
  4. Remove the networks and the volumes that carry the owner label of the workspace.
  5. Remove the owned worktrees.
  6. Delete the records of the workspace. The events stay as a log.