Debug a run
Follow durable task logs and inspect the events, steps, and output ranges around a failure.
Start with a run ID from a trigger response or your operator run list. Run the CLI in the project that exports your configured runtime. Use the same environment and storage as the worker.
Add useful task logs
Task calls to console.log, console.info, console.warn, console.error, and console.debug appear in the run's stored logs by default and still print normally. Each message belongs to its task attempt, even when tasks run concurrently. Console arguments are formatted into one message.
Prefer context.logger when you need structured attributes. Log a short message and structured details at the point you need to explain:
import { task } from '@runlane/core'
import * as z from 'zod'
export const indexDocument = task({
id: 'documents.index',
schema: z.object({ documentId: z.string() }),
run({ documentId }, context) {
context.logger.info('Indexing document', { documentId, attempt: context.attempt })
return { indexed: true }
},
})debug, info, warn, and error return void. They validate and copy their inputs before returning. Runlane saves accepted logs before saving the attempt outcome. Keep credentials, personal data, and large documents out of messages and attributes.
Set logs: { captureConsole: false } in createRunlane() to disable automatic capture. Its default comes from contractDefaults.logs.captureConsole. Calls outside active task attempts are not captured. Console capture uses the same log limits and drain as context.logger, but synchronous admission errors do not throw into task code; the rejected record is not saved. See the logger contract for limits and failure behavior.
A callback in onSuccess, onFailure, onCancel, or onComplete can use the same context.logger. Hook logs include the stable delivery ID and callback attempt number. Task retries and hook retries can repeat application messages; each accepted call has its own log ID.
Follow the attempt
npm exec -- runlane runs logs <run-id> --followFollow polls until the run is terminal and its accepted attempt-log tail has drained. Terminal failure is output data, so inspect the saved failure before choosing a recovery action. Later hook callbacks can write more logs; read again to see that later tail. Interrupt the command to stop following without cancelling the task.
For scripts, use --json. Save the returned cursor and pass it as --after to the next logs call. --limit bounds one page.
Find the event around a message
npm exec -- runlane runs timeline <run-id> --limit 50 --json
npm exec -- runlane runs get <run-id>Events stay in sequence order. Between two events, the timeline shows what the attempt wrote after the first, ordered by the writer's clock. A message written after a metadata event cannot appear before that event, even if workers' clocks disagree.
Timeline entries summarize events, completed steps, log entries, and stream ranges. Step results, task payloads, and stream chunk bodies are omitted. A stream range shows its name, attempt, first and last positions, and record count. Read full chunks with runs.readStream() or the CLI's runs stream command. A range can continue on the next page.
The hooks entry is labelled current state and is captured when the first page is read. It is not an immutable history of hook invocations. A partially pruned run is labelled because some outgoing step history has already been removed.
Continue with --after <cursor> while hasMore is true, including empty pages. Logs and timeline use different cursors. Refresh from the beginning to include late commits behind an earlier page. These operator pages are not an export checkpoint.
Recover the cause
Check the stored failure code, attempt count, and current hook state. Fix the cause before retrying a failed run. A log_limit_exceeded failure means an individual message exceeds logs.maxEntryBytes. Shorten that message or its attributes. Run-wide entry and byte quotas save one truncation marker without failing the run. Other background persistence failures still fail an otherwise successful attempt.
See find and recover stuck runs for recovery actions and export telemetry for tracing and log export.