{"record":{"id":"be8b083ea4f5392e","repo":"agalwood/Motrix","slug":"invalid-task-inspector-activity-snapshot","errorCode":null,"errorMessage":"Invalid Task Inspector Activity snapshot","messagePattern":"Invalid Task Inspector Activity snapshot","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/inspector-activity/task-inspector-activity-query.ts","lineNumber":67,"sourceCode":"        return invalid()\n      }\n      let taskId: string\n      try {\n        taskId = assertTaskId(descriptor.value as string)\n      } catch {\n        return invalid()\n      }\n      queryCount += 1\n      if (options.failAfterFirstQuery && queryCount > 1) {\n        throw new Error('deterministic Task Inspector Activity query failure')\n      }\n      const result = reader.snapshot(taskId)\n      if (result == null) {\n        throw new AppError(ErrorCode.TaskNotFound, `Task not found: ${taskId}`)\n      }\n      const snapshot = parseTaskInspectorActivitySnapshot(result, taskId)\n      if (!snapshot) {\n        throw new Error('Invalid Task Inspector Activity snapshot')\n      }\n      return snapshot\n    },\n  }\n}\n","sourceCodeStart":49,"sourceCodeEnd":73,"githubUrl":"https://github.com/agalwood/Motrix/blob/1a708ee57746c434e2c67a44bbf0906a976afea4/src/core/inspector-activity/task-inspector-activity-query.ts#L49-L73","documentation":"Thrown as a plain Error (not an AppError, no ErrorCode) when the reader returned a snapshot for the taskId but parseTaskInspectorActivitySnapshot(result, taskId) returned a falsy value — the stored data could not be parsed into a valid Task Inspector Activity snapshot. Indicates data-shape corruption rather than a missing task.","triggerScenarios":"parseTaskInspectorActivitySnapshot(result, taskId) returns null/undefined/false after reader.snapshot returned a non-null value. The raw record exists but does not conform to the expected snapshot schema.","commonSituations":"On-disk activity log written by an older/newer incompatible version; schema migration was skipped; partial/corrupted write of the activity record; a hand-edited or externally-modified store.","solutions":["Reset or rebuild the activity store for the affected task to clear the malformed record.","Ensure you are on a version whose snapshot schema matches the stored data (run migrations).","Log the raw result to identify which field failed parsing.","Restore the activity log from a backup if available."],"exampleFix":"// before\nconst snapshot = parseTaskInspectorActivitySnapshot(result, taskId)\nif (!snapshot) {\n  throw new Error('Invalid Task Inspector Activity snapshot')\n}\n\n// after — narrow and surface which field failed\nconst snapshot = parseTaskInspectorActivitySnapshot(result, taskId)\nif (!snapshot) {\n  log.warn('unparseable activity record for task %s: %j', taskId, result)\n  throw new Error(`Invalid Task Inspector Activity snapshot for task ${taskId}`)\n}","handlingStrategy":"try-catch","validationCode":"// Schema-check the raw record before parsing.\nfunction isRawActivityRecord(v: unknown): v is Record<string, unknown> {\n  return typeof v === 'object' && v !== null && 'events' in v && Array.isArray((v as any).events)\n}","typeGuard":"function isRawActivityRecord(v: unknown): v is { events: unknown[]; [k: string]: unknown } {\n  return typeof v === 'object' && v !== null && Array.isArray((v as { events?: unknown[] }).events)\n}","tryCatchPattern":"try {\n  return query.snapshot({ taskId })\n} catch (err) {\n  if (err instanceof Error && /Invalid Task Inspector Activity snapshot/.test(err.message)) {\n    // reset/rebuild the activity store for this task\n    await activityStore.rebuild(taskId)\n    return null\n  }\n  throw err\n}","preventionTips":["Run schema migrations on every version upgrade.","Treat the activity log as append-only to avoid corruption.","Validate records at write time, not just read time.","Back up the activity store before migrations."],"tags":["inspector","activity","parsing","schema","data-corruption"],"backgroundTag":null,"analyzedSha":"1a708ee57746c434e2c67a44bbf0906a976afea4","analyzedAt":"2026-08-12T16:18:09.346Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}