# Background Job Reports

How reports from background commands and subagents reach the task that started them.

Since v1.3.0 a TUI run can also leave work in the background, since v1.3.2 through `background_command` and `background_subagents`; only requests whose origin is `cli-` and that have no deliver target qualify (this no longer depends on a decision model). `run_command_background` was renamed `background_command` (Removed in v1.3.2); `run_websocket` and the `subagents` `background` / `timeout_min` parameters were dropped (Removed in v1.3.2): use `background_command` and `background_subagents` instead. Each call starts one leg, with an id such as `cmd_` or `sub_` plus 8 hex characters. Since v1.3.8 the legs a task starts in the same turn form one job, stored as `~/.config/agenvoy/sessions/<session>/background/job_<8 hex>.json` instead of in the task's pending snapshot (Removed in v1.3.8), and both tools take `objective` (what the group is for, written to stand alone) and `next` (what to do with the reports); the first non-empty value in the group is kept. A session runs at most `MAX_BACKGROUND_TASKS` legs at once, shared by both tools (`DEFAULT_CONCURRENCY`: half the CPU count, at least 3). While a leg runs, its output is appended to `~/.config/agenvoy/sessions/<session>/background/<leg id>.log`, which is removed when it ends. A finished leg's result is kept up to 32 KiB; watch reports from a running `background_command` are kept up to 8 KiB each and 32 KiB in all, with the oldest marked `...[N reports elided]...`. Since v1.3.8 the starting task no longer stays pending for its legs: it ends normally and is written to task history, and the daemon no longer resumes it with a `[Resumed Task — background task finished]` message for every report (Removed in v1.3.8). Where a report goes depends on the starting task:

| Starting task | Report |
| --- | --- |
| Running | Added at the start of its next turn as a `[Background Report — background task finished]` (or `... update]`) message; a report that arrives just before it finishes adds one more turn |
| Paused or waiting on `ask_user` | Kept in the job and carried into the resume message when the task resumes |
| Ended | Held until every leg of the job has finished; the job then runs once as a new task whose hidden input starts with `[Resumed Task — background group finished]` and carries `objective`, `next`, every report and the starting task's id for `chat_history(mode=read)`. A job whose reports were all taken by the starting task does not run |

Background jobs, and the `background/` directories with them, are cleared when the daemon starts, so background work does not survive a restart.

`background_command` always watches its output: a new line containing an error keyword (`keywords`; by default `error`, `err!`, `fail`, `fatal`, `panic`, `exception`, `traceback`, `segmentation fault`, `core dumped`, `out of memory`, `permission denied`, `command not found`, `no such file`) reports the latest output (up to 8 KiB) while the command keeps running, once output settles (2 s of quiet, at most 10 s) and at most one report per 30 s. With a decision model set, a decision check first drops benign hits and repeats of the last report, and a failed check reports the output unchecked with the failure noted; without a decision model every hit is reported. The `interval` and `prompt` parameters of the old watch mode were dropped (Removed in v1.3.2). A `background_subagents` leg reports its saved report path; background legs never raise confirmations, they return what they gathered and say the call still needs approval.

While the TUI showed `Waiting for background tasks`, a message sent from that window joined the waiting task; that mode was Removed in v1.3.8, since the starting task now ends normally and a new message is an ordinary request. `POST /v1/send` still treats a `pending_task` that names a pending task with background jobs as a follow-up to it: it resumes that task, or becomes steer while the task is running. Resuming a task that is not the session's most recent task and has no background jobs moves it to a new task hash, so its replies are not inserted into the older task (v1.3.0).
