Skip to content

Conversation

@LuoPengcheng12138
Copy link
Collaborator

Description

This PR fixes a runtime error caused by mutating a Pydantic frozen event model. In Workforce._handle_failed_task, we created a TaskFailedEvent and then attempted to set worker_id and failure_count afterward. CAMEL’s event models are ConfigDict(frozen=True, extra='forbid'), so post‑creation assignment raises ValidationError: Instance is frozen.

The fix passes worker_id directly in the constructor and moves failure_count into metadata, which is an allowed field. This keeps the event immutable and avoids the validation error during failure handling.

[error] BACKEND: 2026-02-02 22:09:29,434 - camel.camel.societies.workforce.workforce - ERROR - Error handling failed task 1770041310698-1927.1: 1 validation error for TaskFailedEvent
worker_id
  Instance is frozen [type=frozen_instance, input_value='3796b026-9380-46c9-bc42-86ad673fdee2', input_type=str]
    For further information visit https://errors.pydantic.dev/2.12/v/frozen_instance
Traceback (most recent call last):
  File "/Users/Luopc/.eigent/venvs/backend-0.0.82/lib/python3.10/site-packages/camel/societies/workforce/workforce.py", line 5473, in _listen_to_channel
    halt = await self._handle_failed_task(returned_task)
  File "/Users/Luopc/Documents/Development/MyLLMs/eigent/backend/app/utils/workforce.py", line 698, in _handle_failed_task
    event.worker_id = task.assigned_worker_id
  File "/Users/Luopc/.eigent/venvs/backend-0.0.82/lib/python3.10/site-packages/pydantic/main.py", line 1032, in __setattr__
    elif (setattr_handler := self._setattr_handler(name, value)) is not None:
  File "/Users/Luopc/.eigent/venvs/backend-0.0.82/lib/python3.10/site-packages/pydantic/main.py", line 1068, in _setattr_handler
    _check_frozen(cls, name, value)
  File "/Users/Luopc/.eigent/venvs/backend-0.0.82/lib/python3.10/site-packages/pydantic/main.py", line 89, in _check_frozen
    raise ValidationError.from_exception_data(
pydantic_core._pydantic_core.ValidationError: 1 validation error for TaskFailedEvent
worker_id
  Instance is frozen [type=frozen_instance, input_value='3796b026-9380-46c9-bc42-86ad673fdee2', input_type=str]
    For further information visit https://errors.pydantic.dev/2.12/v/frozen_instance

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant