TUI gets stuck on `working...` while `/task` reports `No tasks found`
Description
The TUI can enter a stale busy state where the footer keeps showing working..., new user input is moved into Pending inputs, but /task reports No tasks found.
Based on testing, this looks like a TUI state synchronization bug rather than a DeepSeek API/model failure. The frontend/composer state can believe a turn is still running even when the engine/task state has no active work.
There appears to be a mismatch between:
- frontend/composer state, especially
app.is_loading - engine/task state, shown by
/task
When app.is_loading remains true, later input is treated as queued/pending. But /task can still report No tasks found, which leaves the user in a dead-end state: the TUI looks busy, but there is nothing obvious to wait for or cancel.
Steps to reproduce
- On Windows
cmd, start the npm-installed TUI withdeepseek-tui. - Send a normal prompt, for example
你是什么模型. - Observe that the footer can remain stuck on
working.... - Send another normal prompt.
- Observe that the new prompt is moved into
Pending inputs. - Run
/task. - Observe that
/taskcan reportNo tasks foundeven though the footer still showsworking....
Notes:
- This does not reproduce every time.
- Starting a clean session with
deepseek-tui --freshcan avoid the issue, and the model can answer normally in a clean session. - This suggests the API key/model path is working, but the TUI can get stuck in an inconsistent frontend state.
Expected behavior
If the current turn is not actually active anymore, the TUI should not keep blocking future user input.
Expected behavior would be one of:
- The message is successfully dispatched to the engine and a normal turn starts.
- If dispatch fails before the turn starts, the TUI clears the busy state and shows a recoverable error.
- Future user input should not be silently queued forever when
/tasksays there are no active tasks.
Actual behavior
In the affected state:
- The footer remains on
working.... - Submitting another normal prompt does not start a new model turn.
- The prompt appears under
Pending inputs. /taskreportsNo tasks found.- The UI appears busy, but there is no visible active task.
Environment
- OS: Windows
- DeepSeek CLI version: npm-installed
deepseek/deepseek-tui - Model:
deepseek-v4-pro - Shell:
cmd
Logs or screenshots
Likely cause
In crates/tui/src/tui/ui.rs, dispatch_user_message() sets the UI loading state before sending the message to the engine:
app.is_loading = true;
app.last_send_at = Some(Instant::now());
Then it sends Op::SendMessage to the engine.
If that send fails before the engine accepts the message or before a turn-started event is emitted, the function can return early without clearing the frontend loading state.
As a result:
dispatch_user_message()
-> sets app.is_loading = true
-> engine send fails before turn starts
-> app.is_loading is not reset
-> later Enter submits are classified as queued
-> UI shows Pending inputs + working...
-> /task can still say No tasks found
Suggested minimal fix
Clear the frontend busy state if sending the message to the engine fails before the turn starts.
Suggested change in dispatch_user_message():
if let Err(err) = engine_handle
.send(Op::SendMessage {
content,
mode: app.mode,
model: effective_model,
goal_objective: app.goal.goal_objective.clone(),
reasoning_effort: app.reasoning_effort.api_value().map(str::to_string),
allow_shell: app.allow_shell,
trust_mode: app.trust_mode,
auto_approve: app.mode == AppMode::Yolo,
})
.await
{
app.is_loading = false;
app.last_send_at = None;
return Err(err);
}
This keeps the normal success path unchanged, but prevents the composer from staying permanently busy when dispatch fails before the engine starts a turn.
Suggested regression test
A deterministic unit-level reproduction can simulate a closed engine channel:
#[tokio::test]
async fn dispatch_failure_before_turn_started_clears_loading_state() {
let mut app = create_test_app();
let engine = crate::core::engine::mock_engine_handle();
let handle = engine.handle.clone();
// Simulate the engine no longer receiving ops.
drop(engine.rx_op);
let result = dispatch_user_message(
&mut app,
&handle,
crate::tui::app::QueuedMessage::new("hello".to_string(), None),
)
.await;
assert!(result.is_err());
assert!(
!app.is_loading,
"failed dispatch must not leave future composer submits queued as if a turn were live"
);
assert!(app.last_send_at.is_none());
}
Broader design suggestion
The minimal fix above addresses one concrete stale-loading path. Longer term, it may be worth making the TUI busy state more resilient by deriving or reconciling it from a single source of truth.
Possible improvements:
- If
is_loading == truebut there is no active turn/task/stream, show a recoverable error or reset the composer state. - Make
Pending inputsexplain why the input is pending. - Add a timeout or consistency check for states where the footer says
working...but the task manager reports no active work. - Ensure failed dispatch, engine shutdown, crash recovery, and resume/fresh-session paths all clean up frontend busy state consistently.
thank you! yes, i've tried a few different ways for this..... thought it was an api issue like you mentioned but I have a feeling it's from stale sessions or something of that nature. will work to fix for 0.8.13
Follow-up testing note:
I think the broader watchdog/reconciliation work is best treated as a follow-up to this issue rather than a separate bug.
After testing, I could not make the manual recovery/resume path fully deterministic. A clean --fresh prompt works normally, so this still looks like stale TUI/runtime state rather than a DeepSeek API/model failure.
The state-machine behavior is clear, though: when app.is_loading == true, normal Enter submits are routed into the queued/pending path even if no active task is visible. That matches the user-visible state reported here: working..., Pending inputs, and /task reporting No tasks found.
Would a narrow PR that only adds TUI-side liveness reconciliation be acceptable as a follow-up?
Scope would be limited to:
- tracking dispatch-start before
TurnStarted - clearing that marker on
TurnStarted,TurnComplete, engine error, cancel, and send failure - clearing stale busy state if dispatch waits too long without an active turn/agent
- clearing stale busy state if runtime status is terminal but the UI still shows loading
- focused unit tests only
This would not change engine behavior, task semantics, or session persistence.