#3371·CowAgent

[Bug] SchedulerToggleHandler reports success for a task id that does not exist

Author: aniruddhaadak80Created Sep 30, 2026Updated Sep 30, 2026

English is recommended so global developers can help. 推荐使用英文提交,谢谢 ❤️

  • I'm on the latest version and searched existing issues (incl. closed) — no duplicate.

Environment

Version: current master (commit 08f64f7) OS: any — platform-independent Python: 3.11 / 3.13 (CI matrix) Install: any Channel: Web console (scheduler page)

What happened?

Toggling a scheduled task that does not exist reports success, with a null task.

python
store.enable_task(task_id, enabled)      # no-op for an unknown id
task = store.get_task(task_id)           # None
return json.dumps({"status": "success", "task": task}, ensure_ascii=False)

SchedulerToggleHandler never checks that the task exists, so:

POST /api/scheduler/toggle {"task_id": "does-not-exist", "enabled": false}
-> {"status": "success", "task": null}

The inconsistency is the tell

SchedulerUpdateHandler, in the same file, handles the identical case correctly:

python
original_task = store.get_task(task_id)
if not original_task:
    return json.dumps({"status": "error", "message": f"Task '{task_id}' not found"})

So the console already has the right behaviour and the right message for "no such task" on update; toggle just never asked.

Steps to reproduce

  1. Open the console's scheduler page.
  2. Delete or rename a task, or hand-edit tasks.json and remove an id.
  3. Toggle the stale row (or call the endpoint with that id).

Expected: {"status": "error", "message": "Task 'does-not-exist' not found"}, matching POST /api/scheduler/update.

Actual: {"status": "success", "task": null}.

Impact

  • The UI shows a success toast for a change that changed nothing, so a task the user believes is enabled stays disabled (or vice versa) with no error surfaced.
  • Any client that reads task back gets null and dereferences it.
  • The failure is silent, which matters here because the toggle is how a user disables a task they no longer want running.

Suggested fix

Look the task up first and return the same not-found error SchedulerUpdateHandler uses. Reading it back after the update keeps the response carrying the task's new state.

Logs

Not applicable — reproducible with a direct POST to the endpoint.