Run Lifecycle
A run is a single execution attempt for a given task, agent profile, target Edge, workspace, and runtime adapter. The lifecycle matters because AgentHub delivers visible, reviewable, and auditable agent work — not a terminal transcript pasted into a webpage.
Current status
The run lifecycle vocabulary is contract-shaped. Local preview paths and adapter events can be exercised today; stable public SDK packages, full Hub/Web routing proof, and remote/cloud Edge lifecycle evidence are still in development.
Lifecycle Map
| Phase | Owner | What must happen |
|---|---|---|
| Created | Hub or Desktop | Task, actor, project/workspace context, requested Agent Profile |
| Planned | Hub/Edge | Target Edge, workspace policy, runtime profile, approval policy |
| Accepted | Edge | Edge confirms it can attempt the run |
| Preparing | Edge | Validate workspace allowlist, runtime availability, credentials boundary |
| Running | Runtime adapter | Stream normalized events, messages, tool calls, artifacts |
| Needs approval | Edge + reviewer | Pause write, shell, network, publish, or apply action |
| Applying | Edge | Apply approved action and keep audit evidence |
| Completed | Edge/Hub | Final response, artifacts, diff state, metrics, audit |
| Failed | Edge/Hub | Stable error code, safe details, recovery path |
| Cancelled | Actor/Edge | Explicit cancellation with terminal state |
The UI should never skip from "created" to "done" without event evidence. If the runtime cannot emit enough events, AgentHub should mark the run as degraded or failed and state a specific reason.
State Machine
stateDiagram-v2
[*] --> Created
Created --> Planned
Planned --> Accepted
Accepted --> Preparing
Preparing --> Running
Preparing --> Failed
Running --> NeedsApproval
NeedsApproval --> Running: approved
NeedsApproval --> Cancelled: rejected or cancelled
Running --> Applying
Applying --> Running
Running --> Completed
Running --> Failed
Running --> Cancelled
Completed --> [*]
Failed --> [*]
Cancelled --> [*]
Event Envelope
Every event should be safe to render in Desktop, Web, and future integrations. Raw runtime output may be attached for debugging only when it does not expose secrets.
{
"id": "evt_01",
"sequence": 12,
"type": "run.message.delta",
"runId": "run_01",
"sessionId": "session_01",
"agentId": "docs-agent",
"timestamp": "2026-06-09T00:00:00.000Z",
"payload": {
"text": "Reading the public docs route map."
}
}
| Field | Rule |
|---|---|
id | Unique event id for replay and audit |
sequence | Monotonic per run so clients can recover ordering |
type | Stable names such as run.started, run.message.delta, run.diff.ready |
runId | Required for all lifecycle, artifact, approval, and terminal events |
sessionId | Required when the event is visible in a shared session |
payload | Versionable, structured, secret-free data |
Core Event Groups
| Group | Examples | UI use |
|---|---|---|
| Lifecycle | run.created, run.started, run.completed, run.failed, run.cancelled | Status, timeline, audit |
| Message | run.message.delta, run.message.completed | Chat transcript |
| Tool | run.tool.call, run.tool.result | Inspect what the runtime did |
| File/diff | run.file.read, run.diff.ready, run.patch.proposed | Review files and candidate changes |
| Artifact | run.artifact.ready, run.preview.ready | Render docs, screenshots, previews |
| Approval | run.approval.requested, run.approval.resolved | Pause and resume high-risk actions |
| Runtime | runtime.unavailable, runtime.timeout, schema.validation_failed | Failure triage |
Approval Gates
AgentHub should default to conservative approval gates:
| Action | Default gate |
|---|---|
| Read inside allowlisted workspace | Allow and record |
| Read outside workspace | Deny |
| File write or patch apply | Ask |
| Shell command | Ask, with command preview and workspace context |
| Network access | Ask unless policy explicitly allows |
| Commit, push, publish, deploy | Ask and record actor |
| Secret access | Deny unless a product-specific server-side flow owns it |
Approvals should be explicit actions. Do not hide them behind a generic "continue" button when the risk is file write, shell, network, publish, or deploy.
Artifacts And Diff
Artifacts and diffs are review surfaces, not proof that a change has been accepted.
| Item | Required metadata |
|---|---|
| Diff | base, target, file path relative to workspace, change summary |
| Patch | affected files, apply status, approval id |
| File preview | path relative to allowlisted workspace, read timestamp |
| Screenshot | viewport, route, theme, language, privacy review |
| Generated docs | source route, language, build status |
Public examples should use synthetic paths such as docs/quickstart.md, not private absolute paths.
Failure Codes
Use specific, recoverable errors:
| Code | Meaning | First recovery |
|---|---|---|
runtime_unavailable | CLI missing, not logged in, or adapter not reachable | Check runtime CLI install and auth |
workspace_outside_allowlist | Requested path is not approved for Edge | Update allowlist or choose another workspace |
permission_denied | Policy rejected a read/write/shell/network action | Adjust approval policy or request explicit approval |
approval_rejected | Reviewer rejected the pending action | Stop or revise the run |
run_timeout | Runtime exceeded timeout | Retry with smaller scope or longer policy |
schema_validation_failed | Adapter emitted invalid event shape | Fix adapter mapping before trusting UI state |
target_offline | Edge target is not reachable | Reconnect target or use Desktop local mode |
Avoid generic "something went wrong" copy in product surfaces. A user should know whether to fix CLI auth, workspace policy, target availability, approval, or adapter schema — and the error should point to the right one.
Runtime Adapter Responsibilities
Runtime adapters should:
- Start and stop the underlying runtime process.
- Parse stdout, stderr, JSONL, NDJSON, or protocol events.
- Normalize messages, tool calls, file changes, approvals, and terminal state.
- Enforce timeout and cancellation hooks.
- Avoid logging provider keys, prompt secrets, local absolute paths, and raw private file content.
- Emit stable failure events when the runtime is missing, unauthenticated, or incompatible.
The adapter owns process details; the Agent Profile owns product-facing capability, label, policy, and selection behavior.
UI Requirements
Desktop and Web should render lifecycle state consistently:
- State label and last event time are visible.
- Running state does not resize the layout or jump after hydration.
- Approval state clearly separates read-only review from apply/write.
- Failed state shows code, safe message, and next action.
- Completed state links to artifacts, diff, transcript, and audit evidence.
- Theme and language changes do not reset the run timeline in a mock or preview.
Verification
For a run lifecycle claim to be real, verify:
- A run starts from a known actor and project or workspace.
- Edge validates workspace, runtime profile, and approval policy.
- Events arrive in order and can be replayed after refresh.
- Diff, artifact, and preview events render without private absolute paths.
- Approval blocks risky actions until explicit resolution.
- Completed, failed, and cancelled states are terminal and stable.
- Search, docs, and release notes describe the same lifecycle vocabulary.