Synced from Hive. This page is pulled from hivecommons/hive@v5 during the docs build. Edit the canonical source in the Hive repository.
Task workflows: regression pipeline
A TaskWorkflow is a DAG workflow: it describes agent kicks as a directed
acyclic graph (DAG) of steps, ordered by depends_on, that hive executes.
Unlike an
imported CI pipeline,
whose jobs hive observes but does not execute, a task workflow is run by hive
on its own agents. This guide follows the regression pipeline in the
design. The reference for the
spec, validation, execution and failure handling, with a fan-out and fan-in
example, is DAG workflows.
Task workflows are off by default (workflow.tasks.enabled). The spec, the
runner, the API, cron schedules and run-trigger tokens are in v5
(#20645); the dashboard view
is Settings → Workflows → Task workflows
(#20646). A GitHub Actions or
Tekton pipeline can be imported as a disabled task workflow draft
(GitHub Actions,
Tekton).
Prepare the pool
Configure three distinct hive agents named bob-1, bob-2 and bob-3 with
backend: bob; see agent configuration and the
backend setup. The names in spec.pools refer to
existing configured agents: a pool does not create agents or choose a backend.
Use dedicated agents without a governor cadence so ordinary work does not
compete for them, and ensure each agent can access the deployment, test tools
and a shared artifact location. A path local to one agent is not necessarily
accessible to another: use accessible URLs or shared storage for the test plan
and results.
Task workflows are off by default. An operator can enable the runner with:
workflow:
tasks:
enabled: true
max_concurrent_steps: 4
or with Enable task workflows under Settings → Workflows → Task workflows
(owner only). HIVE_WORKFLOW_TASKS_ENABLED overrides the enabled setting.
Turning the feature on or off takes a restart; the other workflow.tasks knobs
on that page apply on the runner’s next tick. Enablement does not create agents
or grant them extra permissions. In-pod completion reports require distinct
per-agent UIDs; without them the relay refuses reports. The runner is subject
to the governor’s budget gate and the existing agent permissions and sandbox
policy. Use a staging environment and review the deployment actions before
running the example.
Define the pipeline
Save the following as regression.yaml, replacing the prompts and artifact
instructions with commands and locations appropriate for your environment.
Results should be short references to shared artifacts, not secrets or full
logs. JSON with the same fields is also accepted.
apiVersion: workflow.hivecommons.dev/v1alpha1
kind: TaskWorkflow
metadata:
name: regression
description: Nightly regression on the Bob pool
spec:
params:
- { name: build, required: true }
- { name: env, default: staging }
pools:
bob: [bob-1, bob-2, bob-3]
concurrency: 3
timeout: 6h
schedule: { cron: "0 2 * * *", tz: UTC, params: { build: nightly } }
steps:
- id: deploy
pool: bob
prompt: |
Deploy build {{params.build}} to {{params.env}}.
Return the deployed URL as the result.
retry: { max_attempts: 3, backoff: 2m }
timeout: 30m
- id: gen-tests
pool: bob
depends_on: [deploy]
prompt: |
Generate test cases for {{steps.deploy.result}}.
Store the plan in shared storage and return its URL as the result.
- id: test-a
pool: bob
depends_on: [gen-tests]
prompt: |
Run suite A from {{steps.gen-tests.result}} against {{steps.deploy.result}}.
Store the results in shared storage and return their URL.
on_failure: continue
- id: test-b
pool: bob
depends_on: [gen-tests]
prompt: |
Run suite B from {{steps.gen-tests.result}} against {{steps.deploy.result}}.
Store the results in shared storage and return their URL.
on_failure: continue
- id: test-c
pool: bob
depends_on: [gen-tests]
prompt: |
Run suite C from {{steps.gen-tests.result}} against {{steps.deploy.result}}.
Store the results in shared storage and return their URL.
on_failure: continue
- id: report
pool: bob
depends_on: [test-a, test-b, test-c]
prompt: |
Write the regression report for build {{params.build}} using:
A: {{steps.test-a.result}}
B: {{steps.test-b.result}}
C: {{steps.test-c.result}}
Store the report in shared storage and return its URL.
build is required; env defaults to staging. Templates substitute params
and results of ancestor steps verbatim. Values supplied by an external caller
are untrusted input to agent prompts: restrict who can trigger a run, and do
not place secrets in params, prompts or results.
Deploy has at most three total attempts, with a two-minute wait before attempt
2 and a four-minute wait before attempt 3. Its 30-minute timeout is per
attempt; the six-hour timeout applies to the whole run. Test generation waits
for a successful deployment. Once it succeeds, the three independent test
steps can run in parallel, limited by available idle pool members, the run’s
concurrency: 3 and the hive-wide cap. Agents may run on different machines;
no particular pool member is guaranteed.
A test’s on_failure: continue lets independent test branches finish after
it exhausts its attempts. It does not make a failed dependency successful:
report runs only if all three tests succeed, and is skipped otherwise. The
run fails if any test fails. If a report is needed for failing tests, arrange a
separate reporting process that can inspect failed runs; do not rely on this
step to run after a failure.
Completion and troubleshooting
Hive frames each kick with the run ID, step ID and attempt number and tells
the agent to report exactly once using hive-step-done, for example:
hive-step-done --run <run-id> --step <step-id> --attempt <attempt> --status succeeded --result "<artifact URL>"
hive-step-done --run <run-id> --step <step-id> --attempt <attempt> --status failed --result "<reason>"
Use the IDs from the kick, not these placeholders. --result-file <path> can
replace --result; results are capped at 16 KiB. A failed report, timeout or
turn ending without a report can fail an attempt and trigger its retry policy.
A late or duplicate report, or one from a different agent, is refused. When a
run stalls, check that the agents are running and idle, the budget gate is
open, and reports are accepted; inspect each attempt’s status and failure reason on the run page or with
GET /api/task-workflows/regression/runs/<run-id>. If all deploy attempts fail, downstream steps
are skipped. A budget pause prevents new kicks until the gate reopens; the
whole-run timeout still runs.
Save and enable the workflow
These examples use the dashboard token ($HIVE_TOKEN), which carries the owner
role on a self-hosted hive. Saving is owner-only and audited. Validate first; the answer lists diagnostics
(unknown agents, cycles, bad templates, a schedule missing a required param):
yaml=$(cat regression.yaml)
curl --fail-with-body --request POST https://hive.example.com/api/task-workflows/validate \
--header "Authorization: Bearer $HIVE_TOKEN" --header 'Content-Type: application/json' \
--data "$(jq -n --arg y "$yaml" '{yaml: $y}')"
curl --fail-with-body --request PUT https://hive.example.com/api/task-workflows/regression \
--header "Authorization: Bearer $HIVE_TOKEN" --header 'Content-Type: application/json' \
--data "$(jq -n --arg y "$yaml" '{yaml: $y, enabled: true}')"
A workflow with validation errors can be saved only with "enabled": false; a
disabled workflow cannot run. metadata.name must match the path, and
hooks, import, settings and validate are reserved names. On a hosted hive these owner routes
sit behind the hub’s sign-in, so call them from a signed-in session.
Start, watch and cancel runs
From the dashboard: Settings → Workflows → Task workflows lists the
workflows, and owners can create, validate, save, enable and delete them in the
YAML editor there. Run now takes the params (a blank one takes its default)
and starts a run. The run page shows the steps by stage, each with its state,
and lists every attempt with its agent (linked to that agent’s past kicks), state,
duration and failure reason, and each step’s result. Cancel run and Re-run (same params,
current spec) are there too, and Approve on a step held by
approval: required. Run-trigger tokens are created and revoked on the same
page.
Cancelling and re-running a run need the merger or owner role. A merger can also start a run on the workflow’s defaults; only an owner can start one with params, because params land in prompts. Saving, deleting, approving and tokens need the owner. Step results and reasons are shown with secret-shaped text (tokens, keys, Bearer credentials) masked, and Kick log on an attempt loads the redacted record of that kick from the agent’s kick history. An active run refreshes itself every few seconds.
The same through the API:
curl --fail-with-body --request POST https://hive.example.com/api/task-workflows/regression/runs \
--header "Authorization: Bearer $HIVE_TOKEN" --header 'Content-Type: application/json' \
--data '{"params":{"build":"1.4.2-rc1"}}'
# => 202 {"ok":true,"run_id":"r-...","status":"running"}
curl https://hive.example.com/api/task-workflows/regression/runs/<run-id> --header "Authorization: Bearer $HIVE_TOKEN"
curl --request POST https://hive.example.com/api/task-workflows/regression/runs/<run-id>/cancel --header "Authorization: Bearer $HIVE_TOKEN"
A workflow never has two active runs: a start while one is active is refused
with 409, whatever started it, and workflow.tasks.max_active_runs (default
8) caps active runs across the hive (429 past it). Each param value is at
most 4 KiB and may not contain invalid UTF-8 or control or format characters other than
newline and tab; unknown params and a missing required param are refused.
Cancelling starts no new step and marks unfinished steps cancelled; an agent already working is not interrupted, and its late report is refused.
Schedule runs
The example’s five-field cron expression starts a run with build=nightly at
02:00 UTC every day, with the default env=staging. The timezone is required,
and a schedule must supply every required param that has no default. A fire
while a run of the workflow is still active, or while max_active_runs is
reached, is skipped and audited as
task_workflow_schedule_skipped. workflow.tasks.schedules_enabled: false
stops every schedule without editing definitions; fires missed while schedules
were off are not replayed when they are turned back on.
Trigger runs from an external scheduler
An external scheduler cannot hold a dashboard session, so an owner creates a run-trigger token for the workflow:
curl --fail-with-body --request POST https://hive.example.com/api/task-workflows/regression/tokens \
--header "Authorization: Bearer $HIVE_TOKEN" --header 'Content-Type: application/json' \
--data '{"name":"ci","ttl_days":90}'
# => {"ok":true,"token":"htw_...","info":{"id":"tok_...",...},"note":"This token is shown once..."}
The token is shown once: store it in the scheduler’s secret store. Hive keeps
only its SHA-256 hash, in a keystore-sealed file. It is scoped to this one
workflow and to two calls, start a run and read a run’s status; it cannot save,
cancel, approve or kick anything. ttl_days is 0 (no expiry) to 366. List
tokens with GET .../tokens and revoke one at once with
DELETE .../tokens/<id>; deleting the workflow revokes all of its tokens.
curl --fail-with-body --request POST \
https://hive.example.com/api/task-workflows/hooks/regression/runs \
--header "Authorization: Bearer $HIVE_RUN_TOKEN" \
--header 'Content-Type: application/json' \
--data '{"params":{"build":"1.4.2-rc1","env":"staging"}}'
# => 202 {"ok":true,"run_id":"r-...","status":"running"}
curl --fail-with-body https://hive.example.com/api/task-workflows/hooks/regression/runs/<run-id> \
--header "Authorization: Bearer $HIVE_RUN_TOKEN"
# => {"run_id":"r-...","status":"succeeded","steps":[{"id":"deploy","status":"succeeded","attempts":2,...}],...}
The status call returns the run’s status and each step’s status, attempt
count, result and reason, not the spec or params. Poll it until status is
succeeded, failed or cancelled; a 202 on start does not mean the tests
passed. Every token use and refusal is audited, and refused requests are rate
limited per client address. On a hosted hive these two hook routes, and only
these, pass the hub’s sign-in; the hive itself checks the token.
workflow.tasks.trigger_tokens_enabled: false refuses every token.
Replace the host and build with your own and never commit a token. Params from a token holder are untrusted input to agent prompts: decide in the spec where they appear.
Notify another system
A workflow can tell a CI system or chat bridge when a run or a step finishes:
hive sends a signed JSON POST to the workflow’s spec.notify.url. It is off
by default and needs the hive switch workflow.tasks.notify.enabled and a
per-workflow signing secret as well. See
Task workflow notifications for the
payload, how a receiver verifies the signature and which targets are allowed.
Settings
Every workflow.tasks knob is under Settings → Workflows → Task workflows, and in
hive.yaml:
| Key | Default | Meaning |
|---|---|---|
workflow.tasks.enabled | false | The feature; takes a restart. |
workflow.tasks.max_concurrent_steps | 4 | Steps running at once across the hive. |
workflow.tasks.max_active_runs | 8 | Runs active at once across the hive. |
workflow.tasks.default_step_timeout | 60m | Per-attempt timeout of a step that sets none. |
workflow.tasks.report_grace | 30s | Wait after a turn ends for its hive-step-done report. |
workflow.tasks.schedules_enabled | true | Cron schedules fire. |
workflow.tasks.trigger_tokens_enabled | true | Run-trigger tokens are accepted. |
workflow.tasks.retention_runs | 50 | Finished runs kept per workflow. |
workflow.tasks.retention_days | 30 | Finished runs older than this are pruned. |
workflow.tasks.notify.enabled | false | Signed run and step notifications may be sent. |
workflow.tasks.notify.allowed_private_hosts | empty | Notification hosts allowed on private addresses. |
Each has a HIVE_WORKFLOW_TASKS_* environment override; see
environment variables.