Repository navigation
fix(scheduled-tasks): reset an explicitly null assistant to lead_agent - #6185
Conversation
willem-bd
left a comment
There was a problem hiding this comment.
Reviewed against head 63958b5 — no issues found. The switch from "assistant_id" in updates to "assistant_id" in body.model_fields_set is correct Pydantic v2 usage for FastAPI-parsed bodies, and resolve_scheduled_task_assistant_id(None) returns lead_agent before any load_agent_config call, so both the explicit-null and omitted paths avoid loading the previous agent as claimed. The SQL repository's update setattr loop persists the injected updates["assistant_id"], and the new tests cover both the route-level behavior and real SQLite persistence for the explicit-null and omitted cases, each asserting the loader is never called. Docs match the implemented semantics, and the nginx-routing sentence removed from backend/app/gateway/AGENTS.md remains covered by backend/AGENTS.md (runtime exposition and the /api/langgraph/* rewrite note), so no information is lost.
) Co-authored-by: lakers-abing <[email protected]> HartMesh: code applies cleanly; doc conflicts keep HartMesh's text plus only this commit's lines; changelog hunks dropped. (cherry picked from upstream commit fafe904) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GujxPsQnaanjqeHp5fwAUn
Related: #5288.
Why
PATCHing a scheduled task pinned to a custom agent with
{"assistant_id": null}succeeds but silently retains the custom agent.model_dump(exclude_none=True)drops the explicit field before the shared resolver can map it tolead_agent, although creation already supports that default.What changed
An explicitly supplied null now resets the task to
lead_agent. Omittingassistant_idpreserves the current pin, even if its custom agent has been deleted. Other null update fields keep their existing ignored behavior. Both cases avoid loading the previous agent.The change uses Pydantic's
model_fields_setand the existing assistant resolver. Tests cover the route and actual SQLite persistence. README and Gateway guidance document the PATCH semantics; the guidance replaces a duplicate nginx-routing sentence to remain within its existing size budget.Surface area
Bug fix verification
backend/tests/test_scheduled_task_router_behavior.py.Validation
From
backend/:make lint: passed; Ruff formatting check covered 1,744 files.make test-blocking-io: 189 passed, both before and after.make testwith pytest-split'sleast_durationstrategy: 22,096 passed; optional integrations and live tests skipped. The first shard was rerun after adjusting the guidance note's location/size and passed.pytest tests/test_agent_guidance_check.py -q: 13 passed.python ../scripts/check_agent_guidance.py --base-ref origin/main --head-ref HEAD: 0 errors; existing soft-size warnings remain.git diff --check: passed.The initial full baseline additionally failed 22 web-fetch cases because this host lacked Node/Readability.js. After adding Node to the test PATH and installing ReadabiliPy's JavaScript dependencies in the local virtual environment, that unchanged test file passed all 48 cases. No dependency or lockfile changes are included in this PR.
AI assistance
Tool(s) used: Codex.
How you used it: Codex inspected the original agent-pinning issue/PR and current code, checked for duplicate contributions, wrote the handler fix, regression tests and documentation, and ran the validation above.