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
- Re-save the task using the current code version to populate __persistedState.
- If the task is obsolete, delete the GCS objects (tasks/<id>/metadata.tar.gz) and recreate the task.
- Add a migration step that detects old-format metadata and upgrades it before load.
- 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
- Keep save and load code versions in sync during deployments.
- Add a schema version field to persisted metadata to detect and migrate old formats.
- Never manually edit metadata objects in the GCS bucket.
- Run integration tests that round-trip save then load to catch schema drift.
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
- Task ${taskId} is missing persisted state in metadata.
- Cannot reconstruct task ${sdkTask.id}: missing persisted sta
- GCS bucket name is required.
- Failed to create GCS bucket ${this.bucketName}: ${createErro
- Failed to initialize GCS bucket ${this.bucketName}: ${error}
AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12).
Data as JSON: /api/errors/d4ce315f88b1bcf1.
Report an issue: GitHub.