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.
See the state of the workspaces
Section titled “See the state of the workspaces”-
Run
lo ls. The table shows the status of each workspace and how many services run, for example2/3 running. -
If
lo upfails, 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 upexits 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.
Read the logs
Section titled “Read the logs”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.
lo logs shop-a bookinglo logs shop-a booking customer-db -fEach line starts with the name of the unit and a bar. Use these options:
-for--followkeeps printing new lines.--jsonprints one JSON object for each line, with the fieldsunitandline.
The output has no color codes when it goes to a file, to a pipe, or when NO_COLOR is set.
Read the log of an earlier run
Section titled “Read the log of an earlier run”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.
- Run
lo runs <workspace> <unit>. The table shows each earlier run with its ID, its start time, its end time and its size. - Run
lo runs <workspace> <unit> <run>to print the log of one run. - Run
lo runs <workspace> <unit> --rmto 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:
logs: history: true keep: 20Set history: false to keep no earlier logs.
Check the environment of a service
Section titled “Check the environment of a service”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 a command in a service
Section titled “Run a command in a service”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.
lo exec shop-a booking -- npm testlo 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.
See the CPU and the memory
Section titled “See the CPU and the memory”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.
Check the code of a service
Section titled “Check the code of a service”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.
See the references
Section titled “See the references”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.
Open the code in an editor
Section titled “Open the code in an editor”- Run
lo editors <workspace> <service>. The list shows the editors, IDEs, file managers and terminals on your machine. The suggested IDE has a mark. - Run
lo edit <workspace> <service>. It opens the directory of the service in the suggested IDE. - To use a different app, add its ID:
lo edit <workspace> <service> --in <id>.
Run the checks of lo
Section titled “Run the checks of lo”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. |
Start when the machine is short of memory
Section titled “Start when the machine is short of memory”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 freeIn 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:
lo up shop-a --yesTo stop this check, set usage: {record: false} in the machine settings. localspace then records no usage and does not prompt.