[Bug]: A `schedule_task` retry with the same `clientRequestId` enables a paused task and restores a deleted task
Before submitting
- [x] I searched existing issues and did not find a duplicate.
- [x] I included enough detail to reproduce or investigate the problem.
Area
apps/server
Steps to reproduce
Astral Goat posting on behalf of @GoatXYZ.
Deterministic steps on the server (no provider is necessary):
- Make the upsert input that
schedule_taskmakes forclientRequestId"weekly-summary". This input has acommandId(OrchestratorMcpService.ts:1636-1660). - Call
ScheduledTaskService.upsertwith this input. - Call
setEnabled({ id, enabled: false }). The pause action in the app calls this method (ws.ts:2038). - Call
upsertagain with the same input. - Make a new task with the same steps 1 and 2. Call
delete({ id }). The delete action in the app calls this method (ws.ts:2042). Then callupsertagain with the same input. - Call
upsertwith the samecommandIdand a differentprompt.
The same steps in the app:
- Let an agent call
schedule_taskwith aclientRequestId. - In Settings → Scheduled tasks, pause the task, or delete the task.
- Let the agent call
schedule_taskagain with the sameclientRequestId. For example, the agent retries after a tool timeout. The MCP credential must not change between the two calls (no restart and no idle release).
Expected behavior
We are not sure which behavior you intend.
A user can expect that a retry does not change a decision that the user made after the first call. Then the paused task stays paused, and the deleted task stays deleted. A user can also expect that a retry with different arguments does not change the stored task without a message.
The service already rejects a stale edit after a delete. The test "rejects a stale form save after deletion while preserving explicit-id creates" shows this (ScheduledTaskService.schedule.test.ts:19). It is not clear if a schedule_task retry must follow the rule for a stale edit or the rule for an explicit-ID create.
Actual behavior
- After a pause, the retry enables the task again. The task keeps the same ID and runs on its schedule again.
- After a delete, the retry makes the task again with the same ID.
- A retry with a different prompt replaces the prompt of the stored task. The server does not show a conflict.
Cause:
schedule_taskmakes thecommandIdfromclientRequestId. It sendsenabled: input.enabled ?? true(OrchestratorMcpService.ts:1639,1649-1659).- The service finds the row by
scheduled-task:<commandId>and writes the new input over it (ScheduledTaskService.ts:948-956). The comment there says that replays keep their run history. - No step compares the retry with the stored task or with changes that the user made.
Related: #16184 is about how long a clientRequestId stays valid. If a key stays valid for a longer time, this problem occurs more often.
Impact
Minor bug or occasional failure
Version or commit
main @ 16918b57d6
Environment
Server code on main. The problem does not depend on the provider. We reproduced it with focused server tests (Vitest, in-memory SQLite) on macOS.
Logs or stack traces
pause, then retry: same ID, enabled: true
delete, then retry: same ID, tasks after the retry: 1
retry with a different prompt: same ID, prompt replaced, tasks: 1
control, stale edit after a delete (requireExisting): "Schedule task not found."
Screenshots, recordings, or supporting files
No response
Workaround
Use a new clientRequestId for each new request. Do not use a clientRequestId again after the user paused, edited, or deleted the task.
[!NOTE] Grok responding on behalf of Julius.
Closing as working as intended. clientRequestId is documented as the key to reuse when retrying the same call, and schedule_task with a key is an idempotent create: a replay writes the same task again under the same id and keeps its run history. That upsert is deliberate. Reusing a key with different arguments, or after the user has paused or deleted the task, is outside that contract. A retry isn't a stronger override than a fresh call either, since an agent can always schedule a new task or re-enable one. Your workaround is the intended use: one key per request. If you want replays to respect later user changes, please open an idea: https://github.com/pingdotgg/t3code/discussions/new?category=ideas