[BUG] Failed pickle saves erase previously saved training data

Abierto
#9,199 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@vatsalyd ya está trabajando en esto.

Desde el 6/11/2026.

  • #9201 de @vatsalyd — abierto
  • #9202 de @badrbel — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
python
Área
backend

Línea de trabajo

Start by reading PickleHandler.save() and CrewTrainingHandler in the training handler implementation, then inspect the related tests. Reproduce the failure with an unpicklable object and verify that a failed save preserves existing training data and does not leave an empty destination file. Two open pull requests are already linked to this issue.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Description

PickleHandler.save() opens its destination with wb before calling pickle.dump(). If serialization fails, the existing file has already been truncated. CrewTrainingHandler inherits this behavior, so one invalid save can erase training data for previously saved agents.

Steps to Reproduce
  1. Save valid agent training data.
  2. Attempt to save another agent's data containing an unpicklable object.
  3. Catch the serialization error and load the saved training data.
Expected behavior

The save raises its serialization error and preserves the earlier file and training data.

Screenshots/Code snippets
from pathlib import Path
from tempfile import TemporaryDirectory
from threading import Lock

from crewai.utilities.training_handler import CrewTrainingHandler

with TemporaryDirectory() as directory:
    path = Path(directory) / "training.pkl"
    handler = CrewTrainingHandler(str(path))
    handler.save_trained_data("saved-agent", {"score": 10})
    try:
        handler.save_trained_data("new-agent", {"lock": Lock()})
    except TypeError as error:
        print(error)
    print(handler.load())
    print(path.stat().st_size)
Operating System

Windows

Python Version

3.13.13

crewAI Version

1.15.36, main at 7abc196a176a5552c35c6e7a16817aa115f10655.

crewAI Tools Version

Not used.

Virtual Environment

Venv managed by uv with the repository lockfile.

Evidence

Before the failing save the file contains {'saved-agent': {'score': 10}} (42 bytes). Afterward:

cannot pickle '_thread.lock' object
{}
0

The failure also creates an empty file when the destination did not previously exist. Both regression cases reproduce locally without LLM calls.

Possible Solution

Serialize with pickle.dumps() before opening the destination, then write the resulting bytes under the existing lock.

Additional context

Prepared with AI assistance. This account cannot add labels; please apply the required llm-generated label.

Lenguaje dominante
Python
Estrellas
60.6k
Forks
9.1k
Merge medio
1 d 2 h
PR fusionados (30 d)
214

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de crewAIInc/crewAI

Todos los issues de crewAIInc/crewAI

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.