Skip to main content

Task Lifecycle (Comet Browser Runs)

Every browser run managed by Comet-Bridge follows a strict lifecycle state machine. The lifecycle tracks run identity, status transitions, audit linkage, and execution metadata from creation through terminal completion. The authoritative lifecycle store lives in command-center-so. Comet-Bridge emits lifecycle events and run metadata to that authority during execution.

States

StateTerminalDescription
pendingNoRun created but not yet started (queued or deferred)
runningNoRun started; browser session is active
completedYesRun finished successfully
abortedYesRun intentionally stopped (user cancel, timeout, operator decision)
failedYesRun ended with error (script failure, CDP disconnect, ownership violation)
Terminal states (completed, aborted, failed) allow no further transitions.

Transitions

FromAllowed targets
pendingrunning (start), aborted (cancel before start), failed (error before start)
runningcompleted (success), aborted (cancel), failed (error)
completedNone
abortedNone
failedNone
Attempting an invalid transition (e.g. completed to running) throws a LifecycleTransitionError with the run ID, source state, and target state.

Lifecycle envelope

Each run produces a 13-field metadata envelope shared by both MCP and CLI execution paths:
FieldTypeRequiredDescription
taskThreadIdstringYesTask-thread identifier linking the run to an orchestration task
runIdstringYesUnique run identifier (auto-generated UUID if omitted)
statusenumYesCurrent lifecycle state (pending, running, completed, aborted, failed)
startedAtISO 8601YesTimestamp when the run was created
routemcp | cli | httpNoExecution channel that handled the run
fallbackUsedbooleanNotrue when the run degraded from MCP to CLI (default false)
agentIdstringNo (required for multi-agent)Agent identity for tab ownership (--agent-id or COMET_AGENT_ID env)
tabGroupIdstringNoChrome tab group ID when tab-group isolation is active
auditSessionIdstringNoLinks the run to a browser-audit session artifact
workflowIdstringNoWorkflow or playbook identifier
completedAtISO 8601NoSet automatically when the run transitions to a terminal state
failureReasonstringNoHuman-readable reason when status is aborted or failed
metadataRecord<string, unknown>NoArbitrary key-value data attached via updateRun
The shared lifecycle-metadata.mjs module in Comet-Bridge ensures both MCP and CLI paths emit identical envelopes. See Comet Browser — MCP/CLI parity for details.

Operations

The lifecycle adapter exposes six operations:
OperationDescriptionIdempotency
startRunCreate and register a new run. Transitions to running (or pending if deferred).Starting an already-running run returns the existing state.
updateRunUpdate metadata (auditSessionId, tabGroupId, workflowId, metadata) on a running run. Does not change state.Only allowed when status is running.
completeRunMark a run as successfully finished. Sets completedAt.Completing an already-completed run is a no-op.
abortRunMark a run as intentionally stopped. Sets completedAt and optional failureReason.No-op from any terminal state.
failRunMark a run as failed with a reason. Sets completedAt and failureReason.No-op from any terminal state.
getRunRetrieve a run by ID. Returns the full lifecycle record or null.Read-only.
Additional query: getRunsByTaskThread returns all runs linked to a given task-thread ID (cache + disk scan). isValidTransition checks whether a transition would succeed without performing it.

Error types

LifecycleTransitionError

Thrown when an invalid state transition is attempted.
FieldTypeDescription
name"LifecycleTransitionError"Error class name
runIdstringThe run that was targeted
fromCometRunStatusCurrent state of the run
toCometRunStatusAttempted target state
messagestring"Invalid lifecycle transition for run {runId}: {from} → {to}"

OwnershipError

Thrown when an agent attempts a sensitive action on a tab it does not own. See Multi-Agent Browser Isolation for the full ownership enforcement model and error fields.

Persistence

The lifecycle store uses an in-memory cache backed by atomic JSON file writes. Each run is stored as {runId}.json under src/data/comet-runs/. File writes use a tmp-rename pattern to prevent partial writes. In read-only environments (Railway, Vercel), persistence is disabled and the store operates in memory only.

Audit linkage

Lifecycle events are also recorded in browser-audit sessions. Each audit session can write lifecycle transitions to lifecycle.jsonl within the session directory, linking the runId and auditSessionId fields. See Comet Browser — Audit artifacts for the directory structure and event format.

See also