google-gemini/gemini-cli · error

Loaded metadata for task ${taskId} is missing internal persi

Error message

Loaded metadata for task ${taskId} is missing internal persisted state.

What it means

During GCSTaskStore.load(), after downloading and JSON-parsing the metadata blob from GCS, getPersistedState() is called to extract __persistedState. If the key is absent or its contents fail the isPersistedStateMetadata() structural check, the loaded data cannot be reconstructed into a runnable task and this error is thrown.

Source

Thrown at packages/a2a-server/src/persistence/gcs.ts:255

    try {
      const metadataFile = this.storage
        .bucket(this.bucketName)
        .file(metadataObjectPath);
      const [metadataExists] = await metadataFile.exists();
      if (!metadataExists) {
        logger.info(`Task ${taskId} metadata not found in GCS.`);
        return undefined;
      }
      const [compressedMetadata] = await metadataFile.download();
      const jsonData = gunzipSync(compressedMetadata).toString();
      // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
      const loadedMetadata = JSON.parse(jsonData);
      logger.info(`Task ${taskId} metadata loaded from GCS.`);

      const persistedState = getPersistedState(loadedMetadata);
      if (!persistedState) {
        throw new Error(
          `Loaded metadata for task ${taskId} is missing internal persisted state.`,
        );
      }
      const agentSettings = persistedState._agentSettings;

      const workDir = await setTargetDir(agentSettings);
      await fse.ensureDir(workDir);
      const workspaceFile = this.storage
        .bucket(this.bucketName)
        .file(workspaceObjectPath);
      const [workspaceExists] = await workspaceFile.exists();
      if (workspaceExists) {
        const tmpArchiveFile = join(tmpdir(), getTmpArchiveFilename(taskId));
        try {
          await workspaceFile.download({ destination: tmpArchiveFile });
          await tar.x({ file: tmpArchiveFile, cwd: workDir });
          logger.info(
            `Task ${taskId} workspace restored from GCS to ${workDir}`,

View on GitHub (pinned to 5024443c72)

Solutions

  1. Re-save the task using the current code version to populate __persistedState.
  2. If the task is obsolete, delete the GCS objects (tasks/<id>/metadata.tar.gz) and recreate the task.
  3. Add a migration step that detects old-format metadata and upgrades it before load.
  4. Verify the task was originally saved by a compatible version of the a2a-server code.
Defensive patterns

Strategy: try-catch

Type guard

import { isPersistedStateMetadata, METADATA_KEY } from '../types.js';

function loadedMetadataHasPersistedState(loadedMetadata: unknown): boolean {
  return (
    typeof loadedMetadata === 'object' &&
    loadedMetadata !== null &&
    METADATA_KEY in loadedMetadata &&
    isPersistedStateMetadata(
      (loadedMetadata as Record<string, unknown>)[METADATA_KEY],
    )
  );
}

Try / catch

try {
  const task = await store.load(taskId);
} catch (e) {
  if (e instanceof Error && e.message.includes('missing internal persisted state')) {
    // The stored metadata is from an incompatible version or corrupted.
    // Options: delete the stale GCS objects, run a migration, or recreate the task.
    logger.warn(`Task ${taskId} has incompatible stored metadata. Recreating.`);
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Loading a task whose metadata was saved by an older code version (before __persistedState existed), manually edited in the GCS bucket, or corrupted during the gzip/JSON round-trip. Also fires if the metadata object is structurally valid JSON but missing the required _agentSettings or _taskState nested fields.

Common situations: Version mismatch between the code that saved the task and the code loading it; manual editing of GCS objects; schema migration gap; data corruption from interrupted writes.

Related errors


AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12). Data as JSON: /api/errors/d4ce315f88b1bcf1. Report an issue: GitHub.