> ## Documentation Index
> Fetch the complete documentation index at: https://axe-engine.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Output and replay

> How axed keeps process output, replays it from a byte offset, follows it with or without backpressure, and bounds the memory it uses.

## One log per process

Each process has one output log that holds stdout and stderr interleaved in the order the process wrote them. Every byte has an absolute offset, starting at 0. Each output event carries its `offset`, its `stream` (stdout or stderr) and its `data`. A process on a terminal reports everything as stdout.

`Process` describes the log with two fields:

| Field | Meaning |
| - | - |
| `output_start` | Offset of the oldest byte still retained. |
| `output_end` | Offset one past the newest byte. This is the total number of bytes the process has written. |

`axectl ps` shows `output_end` in its `OUTPUT` column.

## Replay from an offset

To continue after a disconnect, pass the offset one past the last byte you saw. You get exactly the rest of the output.

> [tab] axectl
>
> ```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> axectl ps                          # OUTPUT 1180
> axectl logs --from 1180 build      # only what came after byte 1180
> axectl logs build                  # everything still retained
> ```

> [tab] gRPC
>
> ```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> grpcurl -plaintext -d '{"process": {"name": "build"}, "from_offset": 1180, "no_follow": true}' \
>   localhost:9090 axe.v1.Processes/Attach
> ```
>
> Leave `from_offset` unset to replay from `output_start`. axed treats an offset past `output_end` as `output_end`.

`Attach` first sends a `started` event that describes the process, then the output. With `no_follow`, it stops after the retained output. It sends `exited` if the process has finished, and ends without it if the process is still running.

If you ask for bytes that were already evicted, you get a `gap` event with `from_offset` and `to_offset` naming the missing range, and the replay continues at the oldest retained byte. `axectl` prints this as `axectl: N bytes of output were dropped` on stderr.

## Follow a process

Without `no_follow`, `Attach` keeps streaming new output and ends with an `exited` event.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl logs -f build       # replay, then follow; Ctrl-C stops following, not the process
axectl attach build        # the same, but exits with the process's exit code
```

`axectl logs` always exits 0 once it has printed the output, like `docker logs`. `axectl attach` exits with the process's exit code.

## Lossless and lossy readers

Every reader is one of two kinds. You choose with `lossy` on `AttachRequest`.

| Reader | `AttachRequest.lossy` | When the reader falls behind |
| - | - | - |
| Lossless | `false` (default) | The log keeps every byte the reader has not read. Once retention is full, axed stops reading the process's pipe, the pipe fills, and the process blocks on `write`. This is the backpressure a terminal gives. |
| Lossy | `true` | The process never waits. Bytes evicted before the reader got to them arrive as a `gap` event. |

`Run` and `axectl exec` read losslessly from offset 0, so an attached run never drops output. `axectl attach` is lossless unless you pass `--lossy`. `axectl logs` is always lossy.

Each process allows at most 64 lossless readers at once. They include lossless `Attach` streams, `Run` streams (also those that repeat a `request_id`), and following `StreamProcessOutput` streams of the Agent Substrate API. One more fails with `RESOURCE_EXHAUSTED` until a lossless reader closes. Lossy readers are not limited.

With no lossless reader attached, the log is a ring. A detached process never blocks on output, and axed evicts the oldest bytes as new ones arrive.

> [!WARNING]
>
> A lossless reader that stops reading without closing its stream holds the process back. Use a lossy reader for dashboards and log tailing that must never slow the process.

## Retention

Retention is how many of the newest bytes each log keeps.

| Setting | Default | Meaning |
| - | - | - |
| `axed --retain` | `1MiB` | Retention when the start request does not choose one. |
| `axed --max-retain` | `64MiB` | Most a start request may ask for. |
| `StartRequest.retain_bytes`, `axectl run --retain` | `0` (daemon default) | Retention for this process. |

Retention is never below the largest single read from a process, `axed --stream-chunk-size` (default 64 KiB), so axed raises smaller values to it, including `--retain` and `--max-retain`. A `retain_bytes` above `--max-retain` fails with `INVALID_ARGUMENT`. Memory grows only with output the process writes. An idle process holds no output buffer. `axectl info` and `System.Info` report `default_retain_bytes` and `max_retain_bytes`.

## The global output budget

Every process reserves its full retention from a global budget, `axed --output-budget` (default `256MiB`), from the moment it starts until axed forgets it. Every process also takes one of `--max-processes` slots (default `1024`), running or finished.

When a new start does not fit, axed evicts the oldest finished process records until it does. If running processes alone hold the whole budget or every slot, the start fails with `RESOURCE_EXHAUSTED`:

```text theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl: resource exhausted (BUDGET_EXHAUSTED): running processes hold the whole budget (3 processes, 3145728 output bytes reserved)
```

To fit more concurrent processes, lower their retention or raise `--output-budget`. The budget is never smaller than `--max-retain`.

> [!NOTE]
>
> `Exec` and the Agent Sandbox `Execute` and `ExecuteWithLimits` buffer their whole output in the response, under two limits. Each stream keeps at most the limit the call asks for, and never more than 256 MiB. All calls running at once also share a second budget, `--capture-budget` (default `256MiB`), on top of `--output-budget`. When output does not fit either limit, `Exec` and `ExecuteWithLimits` keep a prefix of each stream and set `stdout_truncated` or `stderr_truncated` instead of waiting. The plain Agent Sandbox `Execute` has no truncation fields: it fails with `RESOURCE_EXHAUSTED` when its output is truncated or when its time limit kills the process.

## Finished process records

When a process started with `Start`, `Run`, `Exec` with a `request_id`, the Agent Substrate API or MCP's `run` exits, axed keeps its record, so you can still read its output and exit status and reattach by id or name. Records leave in three ways:

* When more than `--max-finished` (default `256`) records are finished, axed forgets the oldest.
* When a new start needs budget or a slot, axed forgets the oldest finished records first.
* You remove it with `Processes.Remove` (`axectl rm`). Removing a running process fails with `FAILED_PRECONDITION` unless you set `kill` (`axectl rm -f`).

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl rm build
axectl rm -f build     # kill it first if it is still running
```

Once a record is forgotten, its id returns `NOT_FOUND`, and its name resolves to an older kept process with that name, if there is one. A record axed evicted leaves its `request_id` behind, so a retry fails with `REQUEST_EXPIRED` instead of starting the command again. axed does not keep processes started with `Exec` without a `request_id`, or through the Agent Sandbox API. Their records vanish as soon as they exit.

## Agent Sandbox API

The Agent Sandbox `Start` stream sends `stdout` and `stderr` events with no offsets and no replay, and its process dies when the stream ends. There is no equivalent of `Attach`. The native API and the Agent Sandbox API share the same budget and process slots.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.