You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TaskContext::request_input leaves a request outstanding after its future is dropped #1579
A task operation that stops waiting for an answer, on its own timeout for example, can't take its question back. TaskContext::request_input (task_manager.rs, rmcp 3.12.1 and current main) inserts the request into the task's pending_inputs and awaits a oneshot. Nothing removes the entry when that future is dropped. So the task keeps reporting input_required, with a question nobody waits for, until the whole task ends, and the client keeps showing it to the user. An answer that arrives later goes to a dropped receiver.
let asked = ctx.request_input("ask-0",InputRequest::Elicitation(request));match tokio::time::timeout(Duration::from_secs(300), asked).await{Ok(answer) => {/* … */}// The task goes on without an answer, but `tasks/get` still lists `ask-0`// in `inputRequests`, and the status stays `input_required`.Err(_) => {/* … */}}
The spec leaves room for this. ext-tasks' tasks/update says each inputResponses key "MUST correspond to a currently-outstanding inputRequest key", so the set of outstanding requests is the server's current view, and the state machine has input_required → working.
Possible fix: remove the entry from pending_inputs when the request_input future is dropped before it resolves (a drop guard), and leave used_input_keys as it is so the key stays unique. The status then goes back to working once no other request is outstanding. An explicit TaskContext::withdraw_input(key) would do too, but the drop covers timeouts and select! without changes in callers.
Found in ssoxy-webtools, which asks the user through a task and gives up on the question after five minutes.
Confirmed on 37257723, and I agree with the diagnosis. Reading crates/rmcp/src/task_manager.rs:
TaskContext::request_input (:71-99) inserts into entry.pending_inputs and then only owns rx. The insert is never undone when the future is dropped: the only removals are update_task (:428), cancel_task (:467) and the terminal cleanup (:370, :525).
current_status() (:197-203) derives InputRequired purely from pending_inputs.is_empty(), and detailed() (:205-215) lists those keys, so timeout()/select! on the caller side leaves the task reporting input_required with a question nobody waits for.
The late-answer half is real too: update_task would remove the key and tx.send(value) into the dropped receiver (:428-430), and silently drops the error.
A drop guard is the right shape and is small. Notes from the rest of the module:
Late responses need no extra work.update_task already ignores unknown keys ("Unknown, already-answered, or superseded keys are ignored per spec", :414-415), so once the guard removes the key, a response that arrives afterwards is a no-op.
Removing by key is safe.used_input_keys makes a key belong to one request_input call for the life of the task, so the guard cannot remove somebody else's entry, and the lost race (answer delivered, then the future dropped) is a no-op because update_task removed the entry first.
Do not write task.status in the guard.get_task (:409) and update_task (:434) both recompute it from current_status(), so dropping the guard restores working on the next read without touching the status field.
Use lock()/lock().ok() in Drop, not expect(). Every other site panics on a poisoned lock, but panicking from a Drop during unwinding aborts the process.
Keep used_input_keys as you propose, and say so in the request_input doc (:63-70): today it only says keys must be unique over the task's lifetime, which reads as "no reuse ever" without saying why a retry after a timeout needs a new key.
created before rx.await, so it fires on the timeout, on select!, and on tasks/cancel (where it is a no-op because cancel_task already cleared the map).
On the option set:
A. Drop guard (yours): covers timeouts and select! without changing callers; ~15 lines plus two tests. Cannot withdraw while still awaiting something else.
B. TaskContext::withdraw_input(key): needed only if the operation wants to retract a question and keep running (e.g. replace it with a different one) while the original future is still alive. Can be added later on top of A; A is not a substitute for it, but nobody has asked for it yet.
C. Expiry marker in tasks/get: no such state in the spec; an input_required task with a request nobody waits for is exactly the state you are removing. I would not add it.
Two tests would pin it:
timeout(10ms, ctx.request_input("ask-0", …)) → get_task reports working and an empty input_requests, while used_input_keys still rejects re-using ask-0.
A late update_task(task_id, [("ask-0", value)]) after the timeout returns Ok and leaves the task working (this is the case that today silently feeds a dropped receiver).
Client-side note: withdrawing makes the key disappear from inputRequests, which is the only signal a polling client gets; a client that caches the question has to reconcile on the next tasks/get. That is consistent with the tasks/update rule you quoted (every inputResponses key must name a currently-outstanding request), so it is fine, but it is worth one line in the request_input doc.
Happy to review a PR that adds the guard and the two tests.
Activity
github-actions commentedon Dec 5, 2026
@connor4312 is on triage rotation this week and is the reviewer for this one.
Automated classification did not run for this one, so it needs a full manual pass.
Automated triage. Labels are a first pass and the assigned maintainer has the final say.
jokemanfire commentedon Dec 5, 2026
Confirmed on
37257723, and I agree with the diagnosis. Readingcrates/rmcp/src/task_manager.rs:TaskContext::request_input(:71-99) inserts intoentry.pending_inputsand then only ownsrx. The insert is never undone when the future is dropped: the only removals areupdate_task(:428),cancel_task(:467) and the terminal cleanup (:370,:525).current_status()(:197-203) derivesInputRequiredpurely frompending_inputs.is_empty(), anddetailed()(:205-215) lists those keys, sotimeout()/select!on the caller side leaves the task reportinginput_requiredwith a question nobody waits for.update_taskwouldremovethe key andtx.send(value)into the dropped receiver (:428-430), and silently drops the error.A drop guard is the right shape and is small. Notes from the rest of the module:
update_taskalready ignores unknown keys ("Unknown, already-answered, or superseded keys are ignored per spec",:414-415), so once the guard removes the key, a response that arrives afterwards is a no-op.used_input_keysmakes a key belong to onerequest_inputcall for the life of the task, so the guard cannot remove somebody else's entry, and the lost race (answer delivered, then the future dropped) is a no-op becauseupdate_taskremoved the entry first.task.statusin the guard.get_task(:409) andupdate_task(:434) both recompute it fromcurrent_status(), so dropping the guard restoresworkingon the next read without touching the status field.lock()/lock().ok()inDrop, notexpect(). Every other site panics on a poisoned lock, but panicking from aDropduring unwinding aborts the process.used_input_keysas you propose, and say so in therequest_inputdoc (:63-70): today it only says keys must be unique over the task's lifetime, which reads as "no reuse ever" without saying why a retry after a timeout needs a new key.Sketch:
created before
rx.await, so it fires on the timeout, onselect!, and ontasks/cancel(where it is a no-op becausecancel_taskalready cleared the map).On the option set:
select!without changing callers; ~15 lines plus two tests. Cannot withdraw while still awaiting something else.TaskContext::withdraw_input(key): needed only if the operation wants to retract a question and keep running (e.g. replace it with a different one) while the original future is still alive. Can be added later on top of A; A is not a substitute for it, but nobody has asked for it yet.tasks/get: no such state in the spec; aninput_requiredtask with a request nobody waits for is exactly the state you are removing. I would not add it.Two tests would pin it:
timeout(10ms, ctx.request_input("ask-0", …))→get_taskreportsworkingand an emptyinput_requests, whileused_input_keysstill rejects re-usingask-0.update_task(task_id, [("ask-0", value)])after the timeout returnsOkand leaves the taskworking(this is the case that today silently feeds a dropped receiver).Client-side note: withdrawing makes the key disappear from
inputRequests, which is the only signal a polling client gets; a client that caches the question has to reconcile on the nexttasks/get. That is consistent with thetasks/updaterule you quoted (everyinputResponseskey must name a currently-outstanding request), so it is fine, but it is worth one line in therequest_inputdoc.Happy to review a PR that adds the guard and the two tests.