Skip to content

Debug a workspace

A workspace can fail in different ways. A service can crash, a reference can have an incorrect value, or the machine can be short of memory. This guide gives the commands that find the cause. Use the sections in the order that they have here.

Each command takes --json, which prints the result as JSON. A coding agent can use it. See coding agents.

  1. Run lo ls. The table shows the status of each workspace and how many services run, for example 2/3 running.

  2. If lo up fails, read its output. After the status, it prints one line for each unit that failed:

    failed: booking (lo logs shop-a booking)

    The line gives the command that shows the log of the unit. lo up exits with the code 1 when a unit fails.

The services and resources of a workspace are its units. The names of the units are the names in the template.

Run lo logs <workspace> to print the logs of all the units of the workspace. Name one or more units to print only their logs.

Terminal window
lo logs shop-a booking
lo logs shop-a booking customer-db -f

Each line starts with the name of the unit and a bar. Use these options:

  • -f or --follow keeps printing new lines.
  • --json prints one JSON object for each line, with the fields unit and line.

The output has no color codes when it goes to a file, to a pipe, or when NO_COLOR is set.

When a service starts again, localspace keeps the log of the run that ended. A service that crashed has its crash in that log. This is the best place to find the reason.

  1. Run lo runs <workspace> <unit>. The table shows each earlier run with its ID, its start time, its end time and its size.
  2. Run lo runs <workspace> <unit> <run> to print the log of one run.
  3. Run lo runs <workspace> <unit> --rm to delete all the runs of the unit. Add a run ID to delete only that run.

localspace keeps up to 20 runs for each unit. Change this in the machine settings:

~/.localspace/config.yaml
logs:
history: true
keep: 20

Set history: false to keep no earlier logs.

An incorrect value in the environment is a frequent cause of a crash. Run lo env <workspace> <service>. It prints each variable of the service with the values that the references gave. It masks the secrets. Add --reveal to print the secret values.

If a value comes from a .env file in the source, lo doctor can show the conflict. See the checks below.

Run lo exec <workspace> <service> -- <command> [args ...]. The command runs in the directory of the service with its environment. If the service runs as a container, the command runs in the container.

Terminal window
lo exec shop-a booking -- npm test

lo exec ends with the exit code of the command. Use it for tests or for a one-time check, such as a connection to the database.

Run lo stats. It shows the CPU and the memory of the machine and of each engine. Then it shows the units that run, with their workspace. Add a workspace name to see only its units.

Use lo stats to find a unit that uses too much memory.

If a service runs code that you do not know, find out where the code comes from.

  • lo commits <workspace> <service> prints the repository, the ref and the checkout of the service. It lists the changes that are not saved elsewhere, and the latest commits. Use -n <number> to change the number of commits. The default is 20.
  • lo commit <workspace> <service> <sha> prints one commit: its message, the files that it changed and its patch.

Run lo graph. It prints each workspace and shared instance with its services and resources. Below each item, it gives the items that it references. The first line shows the proxy and the services that it serves. Use it to find a reference that goes to the incorrect unit.

The flow page of the dashboard shows the same graph.

  1. Run lo editors <workspace> <service>. The list shows the editors, IDEs, file managers and terminals on your machine. The suggested IDE has a mark.
  2. Run lo edit <workspace> <service>. It opens the directory of the service in the suggested IDE.
  3. To use a different app, add its ID: lo edit <workspace> <service> --in <id>.

Run lo doctor. It runs the checks of all the modules and prints ok or FAIL for each. It exits with the code 1 if a check fails. The checks include these items:

Check It finds
git A missing git.
config A machine settings file that has errors.
templates A template with problems. Run lo template validate <template> to see them.
worktrees A source of which the checkout is not on the disk.
env files A key in a .env or .env.local file that the workspace also sets. The application can read the value of the file.
daemon A Docker daemon that does not answer.
shell A missing /bin/sh, which the native engine must have.

lo up compares the average memory and disk use of the workspace with the free memory and the free disk space of your machine. localspace takes the average from the earlier runs of the template. If your machine has less than the average, lo up stops before it starts a unit. The message gives the figures, for example:

shop uses 3.2GiB of memory on average and 3GiB is free

In a terminal, lo up prompts you to start anyway. Type y to start. In a script, the command fails with the code conflict. Add --yes to start without the question:

Terminal window
lo up shop-a --yes

To stop this check, set usage: {record: false} in the machine settings. localspace then records no usage and does not prompt.