Scheduled Tasks API
A scheduled task runs a stored prompt on a timer — daily, weekly, or on an
interval — with no agent building and no workflow builder. Results are delivered
into a normal chat conversation owned by the task's creator (marked unread until
opened) and, optionally, by email. Tasks are user-owned (created_by); every
read and mutation is fenced to the creator within their tenant.
Managing scheduled tasks requires the SCHEDULED_TASKS_AUTHOR permission; for the
built-in roles that is member, KI-Manager, tenant admin, and admin (the read-only
viewer and demouser roles are rejected 403), and a tenant custom role granting
SCHEDULED_TASKS_AUTHOR is admitted regardless of its base role. Tasks remain fenced
to the creator within their tenant. The base URL is
https://ai-api-admin.myra.eu/admin/v1.
Internally a task reuses the platform's single scheduler (the same per-minute tick that drives agent schedules and workflow time-triggers) — the execution runs through the standard inference pipeline as the owner, so plan model clamps, the wallet / spend-cap enforcement, and PII protection all apply to unattended runs exactly as they do to interactive chat.
Endpoints
| Method | Path | Purpose |
|---|---|---|
GET |
/scheduled-tasks |
List the caller's own tasks. |
POST |
/scheduled-tasks |
Create a task. |
PATCH |
/scheduled-tasks/{id} |
Edit / pause / resume a task (owner only). A task deleted while the edit is in flight answers 404 (nothing is saved). |
DELETE |
/scheduled-tasks/{id} |
Delete a task (owner only). Answers 200 {"ok": true}. |
A task id that does not exist, belongs to another user, or belongs to another
tenant answers 404 { "error": "scheduled task not found" } (never 403, so ids cannot be probed).
Scheduled tasks are personal data of the caller: every route is refused
403 { "error": "impersonation_forbidden", "code": "impersonation_forbidden" }
while an administrator impersonates another user. This check runs
before the permission check.
All routes require the tenant's Scheduled tasks feature to be enabled (a platform administrator without a tenant has no flag to check; the check is skipped for them): when
scheduled_tasks_enabled is off, the endpoint returns 403 { "error": "feature_disabled",
"feature": "scheduled_tasks" } (a transient failure reading that flag returns 503
{ "error": "temporarily unavailable; retry later" }). On create, gateway_id must be a gateway of the caller's own workspace (the task runs as the
caller): absent / null → 400 gateway_id_required; not a string, "", longer than 36 bytes, invalid
UTF-8 or containing a control, line-break or invisible formatting character (see refused characters) → 400 gateway_id_invalid; unknown → 404; another workspace's gateway → 404 { "error": "not found" } for a tenant-scoped caller, the same answer as unknown
(why); a platform administrator: 403 gateway_outside_owner_tenant; a non-administrator account without a workspace has no
gateway (404). See
A token lives in its owner's own workspace.
Request body
| Field | Shape | Notes |
|---|---|---|
gateway_id |
string |
Create only. Must be a gateway of the caller's own workspace (see above). |
name |
string |
Required on create. 1–255 bytes. |
prompt |
string |
Required on create. 1–60000 bytes. The text sent to the model on every run. |
model |
string |
Required on create. 1–128 bytes. For self-serve plans the model must be inside the plan's entitlement (rejected 400 otherwise — fail closed; if the plan check cannot read the model catalogue — a retired model id is judged by its successor — or the tenant's plan, the create / model-changing update answers 503 { "error": "temporarily unavailable; retry later" } instead, nothing written; a caller whose organisation no longer exists — deleted while the session was still open — is refused 403 { "error": "forbidden" } on create, a model-changing update and a resume (enabled: true)); a PATCH that re-sends the stored model unchanged is not a model change and skips these checks; for enterprise plans the runtime pipeline allowlist is the boundary. The plan rejection is 400 { "error": "model not available on this plan", "code": "plan_model_not_allowed" }. The model must also be dispatch-able on the task's gateway: if the gateway enforces EU data-residency or a provider allowlist and the pinned model would resolve to a non-EU / non-allowed provider, the save is rejected 400 (data_residency_blocked / provider_not_allowed) instead of being accepted and then failing every scheduled run — the same save-time offer gate the project default and agent model pins use. If the gateway — or a read the verdict depends on (the model catalogue, the gateway's routing rules or provider opt-in set) — cannot be read at save time the save answers 503 { "error": "temporarily unavailable; retry later" } (nothing written — retry; never a 400 verdict built on the failed read); a gateway configuration stored corrupt answers the sanitised 500 { "error": "internal error", "request_id": "…" } (nothing written; permanent until the gateway is repaired). Validated only when the model field is present, so a task carrying an already-blocked model from before this gate stays editable for its other fields. A model that is later deprecated makes runs fail with a visible error; the task auto-pauses after 5 consecutive failed occurrences. |
schedule_kind |
"interval" \| "daily" \| "weekly" |
Required on create. An interval task becomes due immediately — its first run starts within about a minute — and the cadence applies from then on; the same holds when an interval task's cadence is edited or it is resumed. A daily/weekly task instead first runs at the next occurrence of the chosen time (daily_at, UTC): "daily at 10:00" created at 08:36 first runs at 10:00, never an immediate extra run on save. Editing only metadata (renaming, or an already-enabled task) keeps the armed run time; it is recomputed only when the cadence changes or a paused task is resumed. |
interval_sec |
integer |
interval kind: 60 … 31622400 (366 days). Accepts an integer value; a value that is not an integer in range is rejected 400. Sending it with a daily/weekly kind is rejected 400 (see Cadence fields belong to one kind below). |
daily_at |
"HH:MM" |
daily/weekly kinds. UTC. (The UI converts local time; a stored instant is UTC-anchored, so across a daylight-saving change the local run time shifts by one hour — a documented v1 limitation.) Sending it with an interval kind is rejected 400. |
daily_dow |
integer 0..6 |
weekly kind only (0 = Sunday … 6 = Saturday, UTC). Required for weekly; rejected outside 0..6. Sending it with an interval/daily kind is rejected 400. |
email_to |
string |
Optional. A plain ASCII email address (single @, dotted domain, no inner whitespace or control characters, max 254 bytes after surrounding whitespace is trimmed; stored trimmed) adds email delivery on top of the conversation. Empty or whitespace-only: no email delivery on create, removes it on PATCH. A non-string is 400 with a message naming the field; a malformed address is 400 { "error": "email_to must be a valid email address", "code": "invalid_email", "field": "email_to" } and nothing in the body is applied. An unchanged stored address is kept: a PATCH that re-sends the task's current address is accepted even when it would fail the check today, and the stored delivery setting is not rewritten (a PATCH whose only recognised field is that unchanged email_to answers 200 with the task as read, without a write). |
enabled |
boolean |
PATCH only. false pauses (the task keeps its config and its cap slot is freed); true resumes — the resume re-checks the cap. |
Every field is validated fail-closed; a malformed value (wrong type, out of
bounds, bad HH:MM, weekday out of range, oversized prompt) is rejected with
400 and a message naming the field (with a stable code: invalid_schedule for a cadence problem; see typed codes on refusals). Unknown body fields are ignored. The
integer cadence fields (interval_sec, daily_dow) are stored as canonical
integers, so a syntactically-integer value never reaches the database in a form
that would surface as a 500; anything the validator does not accept as an
in-range integer is a 400.
A create / update / delete whose write rolled back on a transient database conflict, or found no
database connection, changed nothing and answers 503 { "error": "temporarily unavailable; retry
later" } — send it again; any other database fault is 500 { "error": "internal error",
"request_id": "<id>" } (see Storage faults).
Cadence fields belong to exactly one kind
A task's cadence is described by the field(s) its schedule_kind uses —
interval uses interval_sec, daily uses daily_at, weekly uses daily_at
and daily_dow — and nothing else:
- A cadence field the kind does not use is rejected
400, on create and onPATCH, with a message naming the field (for exampleinterval_sectogether withschedule_kind: "daily"). It is never accepted and then quietly dropped. - Fields the new kind does not use are cleared when the kind changes. After a
switch from
intervaltodaily, the task'sinterval_secis cleared and the field is simply absent from the response body — a task never reports a cadence it does not run on. Re-saving an older task's cadence clears any leftover field the same way. - A
PATCHmay change the kind alone when the stored task already carries what the new kind needs.{"schedule_kind": "daily"}on a weekly task succeeds and keeps the storeddaily_at, becauseweeklyused that same field. It is rejected400when the new kind needs a field the task's previous kind never used — switching a daily task tointervalrequires an explicitinterval_sec, and is rejected rather than silently reusing a leftover value the request never named. - Sending
nullfor a cadence field the kind uses means "leave it as it is": the stored value is kept. APATCHwhose only field is such anullchanges nothing and is rejected400 no fields to update.
Changing the kind re-arms the next run time (an interval task becomes due
immediately, a daily/weekly task at the next occurrence of its time). Clearing
a leftover field on its own does not — a save that does not change the cadence the
task actually runs on keeps the armed run time.
Response shape. The response is wrapped: the list returns { "tasks": [ … ] },
while create (201) and patch (200) return { "task": { … } }. The fields below
belong to each inner task object: id, gateway_id, name, prompt, model,
schedule_kind, interval_sec, daily_at, daily_dow, enabled, email_to,
last_status, last_error, last_run_at, next_run_at, result_conversation_id,
created_at.
Account deactivated mid-request. Creating a task while the acting user is disabled or erased during the write answers 401 { "error": "unauthenticated" } — nothing is created.
Active-task cap
Each user has a cap on active (non-paused) tasks, resolved from the tenant plan: the paid Custom plan 10, the free trial 0 (DB-tunable per plan-config row); non-self-serve (enterprise/manual) tenants get a deployment-wide default cap (10, set by your operator). Creating — or re-enabling a paused task — beyond the cap answers:
Pausing or deleting a task frees its slot immediately.
Runs, retries, and failure handling
Handed-over agents. While an agent is paused after an owner hand-over, its schedules do not fire: the occurrence is recorded as skipped (no run, no failure strike, no failure e-mail, and it never counts towards the automatic pause after repeated failures). The schedules resume on their next slot once the new owner confirms the agent.
Agents paused by automatic protection. The same applies to an agent paused by automatic protection: its occurrences are skipped with no run, no failure strike and no failure e-mail.
A due task is claimed by the scheduler tick (at-most-once per cadence slot) and executed through the gateway as the owner:
- Transient provider failures (network error, HTTP 5xx, 429) are retried across ticks — up to 3 attempts per occurrence with a short backoff. The retry never postpones the task's real cadence slot.
- Permanent failures (any other 4xx — e.g. a deprecated model or a hard
budget block) are not retried; the occurrence is recorded as failed
(
last_status: "failed",last_errorset) and the task waits for its next cadence slot. - Interrupted answers (a turn cut off mid-answer: the typed error
(with
x-should-retry: falsewhen tools ran) after the model call failed mid-turn; a2xxcarryingX-AIG-Erroris read the same way as a defensive backstop — see Inference › Interrupted answers) are recorded as failed (the typed 5xx error records its own reason, e.g.http 502; only the2xxbackstop writeslast_error: "interrupted: the answer was cut off (<code>)"), are not retried whenx-should-retry: falseis present — the tools may already have run — and the partial is not delivered. - After 5 consecutive failed occurrences the task auto-pauses
(
last_status: "paused",enabled: 0) so an unattended broken task cannot burn budget nightly. Resume it after fixing the cause. - When the owner's wallet is empty or frozen (or a tenant/gateway/token spend cap
is reached), an unattended run is refused with
429 quota_exceeded, exactly like interactive chat — a hard stop, with no over-cap model downgrade.
Delivery is at-least-once: the conversation write is the commit point, and a rare crash between delivery and bookkeeping may re-run an occurrence on the next tick (a duplicate message in the owner's conversation, never a duplicate charge beyond the run itself).
Internal scheduler API: strict run completion
The scheduler process records the outcome of each run through the loopback-only
POST /internal/scheduler/finish-run (not a public endpoint). It parses the body strictly: a
field that is present with the wrong type or an out-of-range value is rejected with
400 {"error": "<code>"} and nothing is written (the run stays running; if no valid
completion follows, the reaper fails it with lease timeout once its lease expires); it is never silently floored, clamped to a default, or treated as absent.
run_id, ok and now are required: absent, JSON null or the wrong type is rejected like any
other bad value. For the optional fields (http_status, request_ref, error, agent_version,
guardrail_block, error_code) an absent field or JSON null counts as absent. Fields are checked in a fixed order and
the first failure wins: run_id, ok, now, http_status, request_ref, error, agent_version,
guardrail_block, error_code.
| Field | Accepted | Rejected as |
|---|---|---|
run_id |
non-empty string, at most 36 bytes | bad_run_id |
ok |
JSON boolean | bad_ok |
now |
integer, 0 up to (not including) 2^53 | bad_now |
http_status |
integer 0 to 999 (absent or null = 0) | bad_http_status |
request_ref |
valid UTF-8 string (clamped to 64 characters; "" is stored as NULL) |
bad_request_ref |
error |
valid UTF-8 string (clamped to 500 characters; "" is stored as NULL) |
bad_error |
agent_version |
integer, 0 to 2147483647 inclusive | bad_agent_version |
error_code |
the string agent_not_found (sent by the scheduler only for a failed run whose gateway response was a 404 with that code; absent or null = none) |
bad_error_code (any other value, including another string, a number or an empty string) |
guardrail_block |
JSON object with only the optional keys blocked_by and block_reason, each a UTF-8 string of at most 128 characters with no control character ({} is accepted); only together with ok: false |
bad_guardrail_block (also: a string, array, number or boolean, an unknown key, a bad name, or any block with ok: true) |
Residual 404 cause. The gateway answers an agent that is blocked by its review (Flagged or
Disabled) with the same public 404 AGENT_NOT_FOUND as an agent that does not exist; that response is
unchanged. When the scheduler reports a failed run with http_status 404 and error_code: agent_not_found,
/finish-run looks up the internal cause and prefixes the stored run error with it:
SCHEDULE_GATEWAY_MISMATCH (the schedule's gateway differs from the agent's gateway; the text names no gateway ids) or
AGENT_REVIEW_BLOCKED (the agent is flagged or disabled by its governance review). The original text follows
as (original: ...). When no cause is found, or the lookup fails, the error is stored as sent; the lookup never
fails the finish. The scheduler no longer claims a schedule of a review-blocked agent at all: its
next_run_at is left untouched, so the occurrence that fell due runs once after the agent is approved again.
Guardrail blocks. When the gateway refused a scheduled agent run with a guardrail block (see
Agents — guardrail-block marker), the scheduler sends guardrail_block
with ok: false: the run ends failed with error_class = guardrail_blocked and the guardrail name and reason
when the marker carried them ({} when the marker was missing or malformed). The object and its validator are
the same as on the workflow API's /internal/workflow/agent-run-finish.
POST /internal/scheduler/settle-delivery applies the same rule to its error field
(bad_error). JSON -0 is forwarded as the integer 0. The scheduler's own client only ever
sends valid UTF-8 and omits an out-of-range agent_version, so a legitimate run is not affected.
See also Workflows › Internal runner seam, which
uses the same validator module. Note that /internal/workflow/finish-run is a different route
of the workflow API (different fields), not this one. The workflow API's
/internal/workflow/agent-run-finish is stricter on two fields: http_status is required and a
request_ref over 64 characters is rejected (bad_request_ref). Here request_ref carries a
gateway trace/request id that the scheduler does not control, so it is clamped to 64 characters
(storage behaviour unchanged).
Internal scheduler API: strict integers on every route
The strict rule above applies to every POST /internal/scheduler/* route, not only finish-run.
Each integer field is parsed strictly: a field that is present but malformed is rejected with
400 {"error": "<code>"} before anything is read or written. Malformed means a numeric string
("100"), a fraction (1.5), a boolean, a non-finite number, or a value outside the range below.
Nothing is floored, coerced or silently defaulted. A required field that is absent or JSON null is
rejected the same way. fetched and dropped (record-email-poll) default to 0 only when the key is
absent; JSON null is a 400 (bad_fetched, bad_dropped). For agent_version, nbytes and
seal-audit-chain's now, JSON null counts as absent.
| Field | Routes | Accepted | Rejected as |
|---|---|---|---|
now |
all routes that take a clock | integer, 0 up to (not including) 2^53; negative is a 400, including on claim-webhook-run, insert-run, claim-run-resume and insert-audit |
bad_now |
limit |
the due-* and drain routes |
integer 1 to 1000 | bad_limit |
old_next_run_at, lease_until, new_next_run_at |
claim (all three); lease_until also on claim-webhook-run, claim-run-resume, insert-run |
integer, 0 up to (not including) 2^53 | bad_old_next_run_at, bad_lease_until, bad_new_next |
requested_at, expires_at |
insert-approval |
integer, 0 up to (not including) 2^53 | bad_requested_at, bad_expires_at |
action_summary |
insert-approval |
optional; absent, JSON null or "" is stored as empty. Otherwise a string of exactly the form <output_kind> / <N> chars with the same output_kind as the request and N a whole number of 1 to 12 digits (for example email / 1234 chars). The note never carries free text |
bad_action_summary (also for any non-string value) |
max_failures |
record-outcome, prompt-task-outcome |
integer 1 to 2147483647 | bad_max_failures |
mode |
prompt-task-outcome |
one of ok, retry, fail, tenant_suspended (the gateway refused a claimed fire, its invoke or its conversation write, because the tenant was suspended after the claim: resets the retry count, stores failed + the reason, no failure strike) |
bad_mode |
claimed_by |
prompt-task-outcome |
optional non-empty string (the claim token the write is fenced on); required for mode tenant_suspended, which always follows a claim |
bad_token (absent with tenant_suspended, or present but empty / not a string) |
error with mode tenant_suspended |
prompt-task-outcome |
required non-empty string (the stored reason); the general error rules below apply |
bad_error (absent, null or "") |
backoff_sec |
prompt-task-outcome (mode retry) |
integer 1 to 59 | bad_backoff |
delivery_lease |
reap (required) |
integer, 60 to 86400 | bad_delivery_lease |
lease_secs |
claim-approval-delivery (required) |
integer, 60 to 86400 | bad_lease_secs |
period |
mark-failure-notified, mark-delivery-notified |
integer 1 to 2592000 | bad_period |
agent_version |
insert-run |
optional integer, 0 to 2147483647 | bad_agent_version |
nbytes |
insert-audit |
optional integer, 0 up to (not including) 2^53 (absent = 0) | bad_nbytes |
error |
set-delivery (at most 500 characters), prompt-task-outcome (at most 255 characters) |
optional valid UTF-8 string, clamped by character; "" is stored as NULL |
bad_error |
fetched |
record-email-poll |
optional integer, 0 to 2147483647 (absent = 0; null is rejected) |
bad_fetched |
dropped |
record-email-poll |
optional integer, 0 to 10000 (absent = 0; null is rejected) |
bad_dropped |
fire_at |
enqueue-workflow-run |
integer, 1 up to (not including) 2^53 | bad_fire_at |
window_secs |
token-expiry-sweep |
integer, 1 to 7776000 (90 days) | bad_window |
run_days, trace_days |
prune |
integer, 1 to 100000 | bad_run_days, bad_trace_days |
Internal scheduler API: request body contract
Every POST /internal/scheduler/* route reads its JSON body through one shared checked reader, after the
secret check (a request without the secret is 401 whatever its body). The body is refused before any handler
logic runs, and nothing is written:
| Body | Answer |
|---|---|
| an object that repeats a key at any depth | 400 {"error": "duplicate_key"} (the message names the key) |
malformed JSON, or a non-finite number (NaN, Infinity, 1e400) |
400 {"error": "bad_json"} |
| more than 2,097,152 structural elements | 413 {"error": "body_too_complex"} |
| a body the gateway cannot read back from its temporary spool | 500 {"error": "body_unreadable"} (transient) |
claim additionally requires new_next_run_at to be greater than now (bad_new_next).
seal-audit-chain takes an optional now: absent or JSON null means no caller clock; a present
value must be an integer as above, otherwise bad_now. The scheduler's own client sends only
integers, valid UTF-8 and an in-range agent_version (an out-of-range one is omitted), so a
legitimate run is not affected.
insert-approval answers 409 {"error": "no_tenant"} when the organisation no longer exists and 409 {"error": "parent_gone"} when the run, the schedule or the gateway of the hold no longer exists. Nothing is written in either case; the scheduler treats it as "hold not created", not as a storage fault. Any other database fault stays 500 {"error": "db"}.
Result delivery
Each run appends the prompt and the answer as a normal user/assistant pair to the
task's result conversation (created on first delivery, reused afterwards) and
marks it unread (unread_at); opening the conversation clears the marker. If the
owner deletes the result conversation, the next run creates a fresh one. The
optional email delivery reuses the platform mailer with the stored recipient
only. When the run carried masked PII, email is suppressed fail-closed unless
the tenant has opted in (pii_internal_delivery_enabled) and the recipient is a
tenant-internal address — see Internal delivery of masked-PII output below.
When the email is suppressed, the task's owner (never the configured recipient) receives
a content-free notice that the result was not sent by email; if the owner cannot be
notified (deactivated, other tenant, no email) nothing is sent and a warning is logged.
The owner's own conversation is not an external egress and always receives the result.
Optional Mattermost delivery posts to the configured channel through the tenant's
Mattermost bot. The bot can only post where it is a member: for a private channel it
must be invited to the channel first, or delivery fails with the actionable reason "the
Mattermost bot is not a member of this channel — invite the tenant's bot to the channel"
(a 404/unknown-channel id reports "unknown Mattermost channel — check the channel id"). The
failure is recorded on the run and surfaced to the owner; it is not silent.
Delivery lookups and retryable database faults
The delivery routes (deliver-email, deliver-conversation, prompt-task) answer 503 service_unavailable with Retry-After: 1 when a load they depend on hits a retryable database fault; nothing is sent. The loads are, for deliver-email: the agent, the schedule, the release notice, the schedule creator and the agent owner; for prompt tasks: the task and the result conversation. The owner-mode blocked answer is unchanged, except that a retryable fault while reading the creator or owner now answers 503. A permanent fault keeps the 200 blocked answer.
deliver-conversation also answers 503 service_unavailable with Retry-After: 1 when creating the result conversation, or persisting the user and assistant pair, fails with a retryable database fault and nothing was written; sending the same delivery again is safe. The scheduler retries a 503 service_unavailable or service_starting from either deliver-email or deliver-conversation itself: up to twice within the same run, waiting the Retry-After (at most 5 seconds; a longer one is not retried), and records the delivery as failed if it still does not succeed. A write fault with an unknown outcome stays 500, and so does a failed pair write into a freshly created conversation whose pointer write also failed.
Internal delivery of masked-PII output
When a scheduled agent, prompt-task, or workflow run masks PII during execution, the
gateway refuses all external delivery of that run's (de-tokenized) output (Mattermost,
webhook, and any non-same-tenant email recipient) — the owner is instead sent a content-free
"delivery blocked" notice. A narrow, email-only relaxation delivers the unmasked output to
a same-tenant recipient, governed by the tenant flag pii_internal_delivery_enabled
(tenant-admin settable in Workspace settings, audited — see the
tenant PATCH field). Since migration 0358 this flag
defaults to 1 (ON) (it was 0/OFF before); a tenant admin can set it back to 0 to block
every masked run's output:
- Allowed: the run's unmasked output is emailed only when (1) the tenant flag is
1and (2) the recipient resolves to an active, registered user of the same tenant. The check runs server-side in the deliver-email handler with the trusted tenant context and the recipient re-read from the stored schedule/owner — never from the scheduler's request. - Still blocked (fail-closed), no unmasked output ever egresses: the tenant has not opted in; the recipient is not an active same-tenant user (external address, a disabled user, a user of another tenant, or a non-user shared inbox); Mattermost delivery (unlike email it has no tenant-internal recipient — it cannot deliver the unmasked body to the owner); webhook delivery (an arbitrary URL is not a tenant recipient); the run's PII signal is absent/garbage; or any lookup error/uncertainty.
In every blocked case the owner still receives the content-free "delivery blocked" notice, so
the outcome is never silent. The relaxation is a deliberate, per-tenant choice (now default-ON); a tenant that sets the flag back to 0 returns to blocking every masked run's output.
Note the boundary this does NOT move: external, cross-tenant, Mattermost, and webhook delivery of
masked-PII output stay fail-closed regardless of this flag.
The gateway also records the PII verdict of every unattended scheduled agent run itself, so
the verdict never depends on the scheduler reporting it. When an unattended service-token agent
invoke is bound to a run, the gateway stores a three-state value on the run: unset (never
recorded), 0 (observed clean) or 1 (masked PII; it never goes back to 0). The scheduler's
internal loopback route POST /internal/scheduler/deliver-clearance {run_id} answers from that
stored values alone and carries no content: 200 {"cleared": true, "disposition": "allow", "reasons": []} only when
the value is exactly 0 and the run's delivery disposition is allow or was never
recorded; 403 {"error": "blocked_pii", "cleared": false, "disposition": …, "reasons": […]} when it is 1, unset or
anything unexpected, or when the disposition is stricter than allow or unknown;
200 {"cleared": false, "held": "<release id>", "disposition": "approval_1" | "approval_2", "reasons": […]} when
the disposition is approval_1 / approval_2 and the run's stored schedule delivers to an external channel (the
result waits for a delivery release; the scheduler records waiting_release);
200 {"cleared": true, "disposition": …, "reasons": […], "internal_channel": "webhook" | "mattermost"} whatever the
disposition when the run's stored schedule delivers to a webhook / Mattermost channel the organisation classed
internal (delivery channel class; internal
delivery is never limited — a channel hint naming another kind is never cleared this way, an e-mail channel is
decided by the internal-recipient check of the deliver-email route instead; the scheduler accepts it only for the kind
it delivers to);
404 {"error": "not_found"} for an unknown run; 400 {"error": "bad_run_id"} for a missing,
non-string or over-36-byte run id; 400 {"error": "bad_channel"} for an optional channel hint that is not
mattermost, webhook, email or null; 500 {"error": "db"} when the store was unreachable — the
caller must then refuse delivery (never treat it as cleared) and may retry. The route accepts only the
internal scheduler secret.
For a suspended tenant the route answers 403 {"error": "tenant_suspended"} (503 tenant_state_unknown when the state cannot be read) before any other answer, and the owner failure mail is not sent: owner-failure-notify answers 200 {"notified": false, "reason": "tenant_suspended"}, and the scheduler then also skips the destination notice and the Mattermost owner-mail fallback. See Messages while suspended.
The agent scheduler calls this route before every agent-run delivery (email, webhook,
Mattermost) and delivers only when the run's X-AIG-PII-Active header was clean, its X-AIG-Delivery level (when
present) is allow, and the answer is 200 {"cleared": true} with no disposition other than allow.
When X-AIG-PII-Active is 1. Personal data masked anywhere in the run counts — the prompt, a page the agent
fetched, a web search result or the search query, a file it read, a knowledge passage, a connector result. A scheduled
web-reading agent (a press review, a news digest) whose page names a person is therefore not posted to Mattermost or a
webhook: the run records blocked_pii and the owner gets the content-free notice. The owner e-mail, and e-mail to
members of the tenant when the tenant enabled internal delivery, still arrive. X-AIG-Delivery names where the
personal data was found (internal_only; web_pages:fetched:heise.de), never the data. 403 blocked_pii records blocked_pii (plus the content-free owner
notice for webhook / Mattermost); any other answer — including 401 / 503 (the gateway
refusing or unavailable), a timeout or a malformed answer — records
delivery_status: failed (deliver clearance: http <status>) with no egress; it never halts the
scheduler tick. A transient failure is final for
that run — it is not retried; re-run the schedule. Prompt tasks and workflow deliveries are not
affected by this call.
The two internal run endpoints
(/v1/{tenant}/{gateway}/agents/scheduled-task/{id}/invoke and
…/deliver-conversation) accept only the gateway service token (a user-bound
token is refused with 404), and every execution parameter — prompt, model,
owner, recipient, conversation — is read from the stored task row, never from the
request body, so a leaked token cannot retarget a task. The invoke additionally
accepts the X-AIG-Unattended: 1 header (the scheduler always sends it) — the
same extended tool-loop budget contract as agent invokes; see
Agents API — Unattended runs.
Lifecycle
Tenant deletion (GDPR purge) removes tasks via the gateway cascade; per-user
erasure (Art. 17) deletes the user's tasks with their other self-created
schedules. Deactivating or restricting (Art. 18) the owner stops unattended runs
immediately — the run endpoints re-check the owner on every execution. A result e-mail
refused because the owner or the schedule creator is restricted is recorded as
delivery_status: owner_restricted (not a failure; re-run the schedule to deliver after the
restriction is lifted). While the owner
is restricted, no failure e-mail and no destination failure notice is sent for the
owner's schedules (including the Mattermost-to-owner-email fallback); the internal
POST /internal/scheduler/owner-failure-notify answers 200 with
{"notified": false, "reason": "owner_processing_restricted"} and the scheduler records
delivery.skipped (owner-restricted). Notices resume once the restriction is lifted.