# Job files

> The format of workspace/jobs/*.toml: every field, the schedule syntax, the caps on files and agents, how changes are picked up and what removing a file does.

Source: https://docs.ventgris.com/agents/job-files

A job file declares one scheduled job in the workspace: `jobs/<name>.toml`, next to `agents/`, `skills/` and `rules/`. The scheduler reads the folder at start and then every minute, creates the job, changes it when the file changes, and pauses it when the file goes away. Use a job file when the job should live in the workspace like code: reviewed, copied between workspaces, versioned. Use the **Jobs** screen or `vg job create` when you want a one-off job without a file. Both create the same kind of [job](https://docs.ventgris.com/workspace/jobs.md).

## Where job files live

| Item | Value |
|---|---|
| Folder | `jobs/` at the root of the workspace (`$WORKSPACE_ROOT/jobs/`, `/home/agent/workspace/jobs/` on a workspace machine) |
| File name | `<name>.toml`. The base name is the job name |
| Skipped | sub-folders, files that do not end in `.toml`, names that start with `.` or `_` (use `_draft.toml` for a draft) |
| Files read per pass | 200 at most. The rest is reported and not read |
| Size | 64 KB at most per file |
| Pass | at start of `vgd`, then every minute |
| Runs as | the user of the AI sessions (`vg-ai`), never as the operator user |

The job name, and so the file name, must match `^[a-z0-9][a-z0-9._-]{0,63}$`: lowercase letters, digits, dots, dashes and underscores, starting with a letter or digit, 64 characters at most. Names that start with `sys.` are reserved for system jobs and refused.

## A complete example

`jobs/crm.weekly-report.toml`:

```toml
# What this job is for. Read by people, not by the scheduler.
description = "Monday report of the CRM pipeline, posted in #pulse"

kind = "agent"
agent = "ventgris"
prompt_path = "projects/crm/prompts/weekly-report.md"
schedule = "weekly mon 08:30"
timezone = "Europe/Paris"
timeout_s = 1800
overlap = "skip"
catchup = "once"
idem_key = "{job}:{week}"
deliver_to = "discord:pulse"
must_deliver = true
priority = 2
max_retries = 1
retry_backoff_s = 300
enabled = true
```

A command job:

```toml
description = "Nightly sync of the CRM database"
kind = "command"
argv = ["python3", "projects/crm/sync.py", "--since", "24h"]
schedule = "0 7 * * *"
timeout_s = 900
weight_mb = 300
idem_key = "{job}:{date}"
deliver_to = "discord:pulse"
secrets = ["CRM_API_KEY"]
```

## Fields

Every key is optional except where the table says otherwise. An unknown key refuses the whole file (`unknown key schedul`), so a typo never drops a setting silently.

| Key | Type | Default | Rules |
|---|---|---|---|
| `name` | string | the file name | If present, must equal the file name without `.toml`, or the file is refused |
| `description` | string | empty | Free text for the reader of the file. Not stored on the job |
| `kind` | `"agent"` or `"command"` | `"command"` when `argv` is set, `"agent"` otherwise | `agent`: a new AI session of a profile runs a prompt. `command`: a program runs |
| `agent` | string | none | Required for `kind = "agent"`: the slug of an existing [agent profile](https://docs.ventgris.com/agents/agent-profiles.md). Unknown slug: `unknown agent profile` |
| `prompt` | string | none | For `agent` jobs: the text of the task, 32 KB at most |
| `prompt_path` | string | none | For `agent` jobs, instead of `prompt`: a file of the workspace that holds the task (relative path, no `..`, 512 characters at most). Read at each run, 1 MiB at most. `prompt` wins when both are set |
| `argv` | array of strings | none | Required for `kind = "command"`: the program and its arguments, one per item. 64 items at most, 4096 bytes per item, no zero byte. No shell: write `["sh", "-c", "..."]` if you need one |
| `schedule` | string | empty | When it runs, see [Schedule syntax](#schedule-syntax). Empty: the job only runs when triggered (`vg enqueue`, **Run now**) |
| `timezone` | IANA zone name | the zone of the workspace (`Europe/Paris` unless changed) | Due times are computed in this zone |
| `timeout_s` | integer | `3600` | 1 to 86400. Counted from the real start, not from the due time. Time spent frozen under memory pressure does not count |
| `overlap` | `"skip"`, `"queue"`, `"replace"` | `"skip"` | What happens when a run is due while the previous one is still going: skip the new one, queue it behind, or stop the old one and start the new one |
| `catchup` | `"once"`, `"skip"` | `"once"` | Due times missed while the machine was stopped: one catch-up run at restart, or none |
| `idem_key` | string | empty | Uniqueness key template, 200 characters at most. Two runs with the same key: the second is `skipped`. See [Uniqueness key](#uniqueness-key) |
| `deliver_to` | string | none | The channel the result goes to, as `platform:name` (for example `discord:pulse`) or a channel id, 200 characters at most. **Required** in a job file |
| `must_deliver` | boolean | `true` | The run must deliver something. A run that ends with exit code 0 without delivering is `silent`, which raises an alert |
| `weight_mb` | integer | `0` | Memory weight for admission, 0 to 65536. `0` means the default of the kind |
| `priority` | integer | `2` | `2`, `3` or `4`. Higher numbers yield to other work. A job can never go above a person in the interface (0) or a channel session (1) |
| `max_retries` | integer | `0` | 0 to 5. Retries after a failure or a timeout, never after `ok`, `silent` or a manual stop |
| `retry_backoff_s` | integer | `60` | 10 to 3600. The wait before the first retry, doubled at each attempt, capped at 1 hour |
| `enabled` | boolean | `true` | Read when the job is created only. See [Who owns the on/off switch](#who-owns-the-onoff-switch) |
| `secrets` | array of strings | empty | The names of the secrets the job asks for. Grants nothing by itself. See [Secrets of a job](#secrets-of-a-job) |

## Schedule syntax

`schedule` accepts a 5-field cron expression or one of the short forms below. Case does not matter, and the word `at` is ignored in the short forms (`daily at 07:30` works). 200 characters at most.

| Form | Example | Meaning |
|---|---|---|
| Cron, 5 fields | `30 7 * * 1-5` | minute, hour, day of month, month, day of week. Lists (`1,4`), ranges (`1-5`), steps (`*/15`) and names (`mon`, `jan`) are accepted. Sunday is `0` |
| Macros | `@hourly`, `@daily`, `@midnight`, `@weekly`, `@monthly`, `@yearly`, `@annually` | the usual cron macros (`@weekly` is Sunday 00:00) |
| `daily HH:MM` | `daily 07:30` | every day at that time |
| `weekly DAYS HH:MM` | `weekly mon,thu 07:00` | the listed days of the week |
| `monthly DAYS HH:MM` | `monthly 28 20:00` | the listed days of the month |
| `hourly :MM` | `hourly :15` | every hour at that minute |
| `every N` | `every 30m`, `every 2h` | only steps that divide the hour or the day evenly |
| `once DATE TIME` | `once 2026-12-01 09:00` | a single run. A date in the past is refused |

A time can be written `07:30` or `7h30`. Everything except `once` is stored as a cron expression, so `vg job list` shows the canonical form (`daily 07:30` becomes `30 7 * * *`).

Daylight saving time: a wall-clock time that does not exist (02:30 on the last Sunday of March) runs at 03:00; a time that exists twice runs once, at the first occurrence.

> [!NOTE]
> A job file, and any job created by an agent, may not run more often than once every 5 minutes. `every 1m` or `* * * * *` is refused with `a job declared by a file runs at most every 5 minutes`.

## Uniqueness key

`idem_key` is a template. When a run is due, the scheduler fills it in; if a run with the same value already exists, the new run is recorded as `skipped`.

| Placeholder | Value |
|---|---|
| `{job}` | the job name |
| `{date}` | the day of the due time |
| `{hour}`, `{minute}` | the hour, the minute |
| `{week}`, `{month}` | the week, the month |
| `{event}` | the event id of a triggered run |
| `{arg.NAME}` | the argument `NAME` of a triggered run (`vg enqueue JOB --arg NAME=value`) |

Any other placeholder refuses the file: `idem_key: unknown placeholder {day}`.

## Caps on job files and on agent jobs

The workspace is writable by every AI session, so the scheduler treats a job file like a job an agent created on its own.

| Cap | Job file | Job created by an agent (`vg job create`, `job_create`) |
|---|---|---|
| `deliver_to` | required: `a job declared by a file needs deliver_to` | required: `a job managed by an agent needs deliver_to` |
| Shortest interval between two due times | 5 minutes | 5 minutes |
| Names under `sys.` | refused | refused |
| Number of jobs created by agents | not counted | 40 by default, or `max_jobs` of the session policy (`agents already manage 40 jobs, the cap`) |
| New jobs over 7 days | not counted | 10 by default, or `max_new_jobs_per_week` of the policy |
| Policy of the job | not checked: the job runs as `vg-ai` and never wider | an `agent` job must use a profile with the same policy as the session; a sandboxed (T2) session may not create a `command` job (`the policy of the job would be wider than the policy of the session`) |
| Owner | the first administrator of the workspace | the person the session works for |

A human can create jobs without these caps in the **Jobs** screen.

## How changes are picked up

Every minute the scheduler lists `jobs/`, and for each file:

1. Checks the name and the size.
2. Computes the SHA-256 of the content and compares it with the hash it kept from the last pass. Same hash: nothing happens.
3. Parses and validates the file. An error leaves the job as it was and reports `jobs/<name>.toml: <reason>`.
4. Creates the job, or updates the existing job with the new values.
5. Keeps the new hash.

Consequences:

- An edit takes effect within a minute. There is no reload command.
- A change made to a file job in the **Jobs** screen lasts until the file changes again. The next edit of the file overwrites it.
- Rewriting a file with the same bytes does nothing, even if someone changed the job in the interface in between.
- A job of the same name created in the interface, by an agent or by the system is never taken over: the file is reported with `a job of this name was created in the interface, by an agent or by the system: the file is ignored`.

The errors of the last pass are listed in the **Jobs** screen. They are also in the daemon answer the screen reads, so check the screen after writing a file.

## Who owns the on/off switch

`enabled` is read once, when the file creates the job. After that, enabling and pausing belong to people in the interface (and to `vg job enable` / `vg job disable`). A person who pauses a file job keeps it paused when the file changes. To pause a job from its file, remove the file or rename it with a leading `_`.

## Removing a file pauses the job

When a file disappears (deleted, renamed to `_name.toml`, moved), the next pass pauses its job. The job, its settings and its run history stay. Putting the file back with new content updates the job; it stays paused until someone enables it, because `enabled` is only read at creation.

An agent cannot delete a job: `an agent may pause a job, not delete it`. A person deletes it in the **Jobs** screen.

## What a run sees

| | `agent` job | `command` job |
|---|---|---|
| Runs as | a new AI session of the profile, origin `job`, titled with the job name | the program in `argv`, as `vg-ai` |
| Working directory | the profile's working directory | the workspace root |
| Environment | the session environment, with `VG_SESSION_ORIGIN=job` | `VG_JOB=<name>`, `VG_RUN=<run id>`, `VG_DRY_RUN=1` on a dry run, `VG_ARG_<NAME>=value` for each `--arg`, and the secrets granted to the job |
| `vg` commands | all those of its profile | only `vg notify`, `vg deliver` and `vg log` |
| Default `weight_mb` | the session weight | a light command weight |
| Questions | `vg ask` returns the default at once: nobody watches a job | no `vg ask` |

A run delivers by calling `vg deliver FILE` (posts the file in `deliver_to`) or `vg notify CHANNEL "text"`. Brokered actions never block a run: `vg action run` answers at once with `done`, `scheduled`, `pending_approval` or `blocked`, and the run reports that state in what it delivers. See [Brokered actions](https://docs.ventgris.com/agents/brokered-actions.md).

A dry run (the **Dry run** button) starts the job with `VG_DRY_RUN=1`: brokered actions are validated and answer without executing. A script should read `VG_DRY_RUN` and do nothing outward when it is `1`.

## States of a run

| State | Meaning |
|---|---|
| `queued` | waiting for memory, for its turn, or for a retry |
| `running` | in progress |
| `ok` | exit code 0, and something delivered if `must_deliver` is true |
| `failed` | non-zero exit code, or the run could not start |
| `timeout` | stopped at `timeout_s` |
| `skipped` | overlap, or uniqueness key already seen |
| `silent` | exit code 0 but nothing delivered while `must_deliver` is true |

`failed`, `timeout` and `silent` send an alert to the owner of the job.

## Secrets of a job

`secrets = ["CRM_API_KEY"]` is a request, not a grant. A person grants each secret to the subject `job:<name>` in the **Secrets** screen, with step-up. Until then the run starts without the variable. Once granted in `env` mode, the value is in the environment of each run of a `command` job, and each use is journaled. An `agent` job does not use this list: its session gets the secrets granted to its profile or policy. See [Secrets](https://docs.ventgris.com/workspace/secrets.md).

`vg job create` drops the `secrets` key and prints `note: secrets in a job file grants nothing: a human grants each one in the Secrets screen`.

> [!AGENT]
> To schedule recurring work, write `jobs/<name>.toml` with `deliver_to` set and an interval of 5 minutes or more, then check the **Jobs** screen or `vg job list` a minute later. Never put a secret value in a job file: name it in `secrets` and ask a person to grant it. To stop a job you created, remove its file or run `vg job disable NAME`; you cannot delete it.

## Errors and how to fix them

| Message | Fix |
|---|---|
| `unknown key K` | Remove or correct the key. Only the keys of the [Fields](#fields) table are accepted |
| `not valid TOML: ...` | Fix the syntax: strings in double quotes, arrays in `[ ]` |
| `name "x" does not match the file name "y"` | Rename the file or drop the `name` key |
| `the file name is not a job name: ...` | Use lowercase letters, digits, dots, dashes and underscores |
| `larger than 64 KB` | Move the prompt to a file and use `prompt_path` |
| `an agent job needs an agent profile` / `unknown agent profile` | Set `agent` to the slug of a profile in `agents/` |
| `an agent job needs a prompt or a job file` | Set `prompt` or `prompt_path` |
| `a command job needs a command` | Set `argv` |
| `invalid schedule: write it as: daily 07:30` | Use one of the forms of [Schedule syntax](#schedule-syntax) |
| `a job declared by a file needs deliver_to` | Add `deliver_to = "platform:name"` |
| `a job declared by a file runs at most every 5 minutes` | Space the schedule out |
| `timeout_s must be between 1 and 86400` (and the other range messages) | Bring the value into the range of the table |
| `this date is in the past` | Change the `once` date |
| `a job of this name was created in the interface, ...` | Rename the file, or delete the other job in the interface |

## Related

- [Jobs](https://docs.ventgris.com/workspace/jobs.md)
- [vg CLI reference](https://docs.ventgris.com/agents/vg-cli.md#jobs)
- [Agent profiles](https://docs.ventgris.com/agents/agent-profiles.md)
- [Brokered actions](https://docs.ventgris.com/agents/brokered-actions.md)
- [Workspace layout](https://docs.ventgris.com/agents/workspace-layout.md)
