crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

Job updates partially mutate records with assignment validators

Open wangtaotaotao95 opened this issue 1 month ago • 4 comments

Description

The experimental job lifecycle added in #7864 validates the complete candidate record, but commit_job_update then assigns each field through Pydantic __setattr__. For application JobRecord subclasses using validate_assignment=True and cross-field validators, a valid stage completion can raise halfway through the commit and leave the accepted record inconsistent.

Reproduction

Define a ReportJob with notes: list[str], output_fields = frozenset({"notes"}), and an after-model validator requiring nonempty notes whenever "collect" is in committed_stages. Enable ConfigDict(validate_assignment=True) and set the initial stage to "collect".

  1. Add a queued record and accept its started update.
  2. Publish stage_completed, stage collect, outputs {"notes": ["Fact"]}.
  3. The full candidate passes validation, but assigning committed_stages before notes raises ValidationError. The original object now contains committed_stages=["collect"] with empty notes, while its update sequence and the state sequence have not advanced.

Expected: accept the fully valid record as one update, preserve its identity, and leave genuinely invalid proposals unchanged.

Reproduced on main 738c8e19e35c with Python 3.13 and Pydantic 2.12. Regression test fails on the unmodified implementation and passes when the validated fields are installed together.

AI disclosure

This issue and the associated fix were prepared with AI assistance. The repository requires llm-generated; this account cannot apply repository labels, so a maintainer will need to apply it.

wangtaotaotao95 avatar Oct 03 '26 13:10 wangtaotaotao95

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 03 '26 12:11 github-actions[bot]

This issue is still awaiting resolution through the open fix #7868; it should not be closed as inactive. The PR preserves atomic installation of validated job fields and includes regression coverage for assignment validators and unset-field tracking. Its existing CI blockers are documented in the PR: dependency advisories already present in the base lockfile and a telemetry test shard that needs a maintainer rerun (the rerun request was denied for this account). No new code or validation result is claimed by this status update. Please keep this issue open while the fix is reviewed.

wangtaotaotao95 avatar Nov 04 '26 02:11 wangtaotaotao95

This still reproduces on main (bf6fd3a). A valid stage_completed raises ValidationError from commit_job_update and leaves committed_stages advanced with empty notes.

#7868 was withdrawn, so I'd like to pick this up. My fix installs the validated candidate's fields in one step instead of per-field setattr, with a regression test in tests/test_flow_jobs.py. @wangtaotaotao95, if you plan to reopen your PR, tell me and I'll step back.

JohnnyWilson16 avatar Nov 15 '26 18:11 JohnnyWilson16

@JohnnyWilson16 Thanks for checking current main. I do not plan to reopen #7868 and am no longer claiming this issue, so please proceed through the project's contribution process. The withdrawn PR and its branch remain available as historical reference; the issue remains open. This reply was prepared with AI assistance.

wangtaotaotao95 avatar Nov 16 '26 07:11 wangtaotaotao95