mastra-ai/mastra · error · Error

Failed to time travel workflow: ${response.statusText}

Error message

Failed to time travel workflow: ${response.statusText}

What it means

Thrown by Run.timeTravelStream() when the time-travel streaming POST returns a non-OK HTTP status. Time travel rewinds a workflow to a prior step and streams execution; the server rejected the request so no stream is returned.

Source

Thrown at client-sdks/client-js/src/resources/run.ts:502

  async timeTravelStream({
    requestContext: paramsRequestContext,
    ...params
  }: TimeTravelParams): Promise<globalThis.ReadableStream<StreamVNextChunkType>> {
    const requestContext = parseClientRequestContext(paramsRequestContext);
    const response: Response = await this.request(
      `/workflows/${this.workflowId}/time-travel-stream?runId=${this.runId}`,
      {
        method: 'POST',
        body: {
          ...params,
          requestContext,
        },
        stream: true,
      },
    );

    if (!response.ok) {
      throw new Error(`Failed to time travel workflow: ${response.statusText}`);
    }

    if (!response.body) {
      throw new Error('Response body is null');
    }

    // Pipe the response body through the transform stream
    return response.body.pipeThrough(this.createChunkTransformStream());
  }
}

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Verify the target step/index exists in the run's execution history before time traveling.
  2. Confirm the time-travel payload matches the current workflow definition schema.
  3. Check server logs for the underlying 4xx/5xx reason.
  4. Retry transient 5xx with backoff.

Example fix

// before
await run.timeTravelStream({ step: 'processData', inputData });

// after
try {
  await run.timeTravelStream({ step: 'processData', inputData });
} catch (e) {
  console.error('Time travel rejected:', e.message); // check step exists in run history
}
Defensive patterns

Strategy: validation

Validate before calling

const runs = await client.getWorkflowRunById(workflowId, runId);
const history = runs.steps ?? {};
if (!(stepName in history)) throw new Error(`Step ${stepName} not in run history; cannot time travel`);

Type guard

function stepInHistory(steps: Record<string, unknown>, step: string): boolean {
  return Object.prototype.hasOwnProperty.call(steps, step);
}

Try / catch

try {
  await run.timeTravelStream({ step: stepName, inputData });
} catch (e) {
  if (/Failed to time travel/.test(e.message)) {
    console.error('Time travel rejected:', e.message);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling timeTravelStream() with an invalid runId, a step/run reference that does not exist, malformed time-travel payload, or server errors while rewinding (client-sdks/client-js/src/resources/run.ts:502).

Common situations: Time traveling to a step not in the run's history; payload schema mismatch after workflow definition changes; server rejecting rewind on completed/pruned runs.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/e1d6b91ca2256767. Report an issue: GitHub.