Skip to content

GetStatus blocks a tokio worker for the length of a generation #1779

Closed

Description

@malibio

Overview

LocalAgentService::get_status now reports the loaded model's id and granted context window (PR #1778, needed by the agent-eval preflight gate). Doing so calls model_spec(), which reaches LlamaChatEngine::model_info() — and that takes a std::sync::Mutex that generate_blocking holds for the entire duration of inference.

get_status (async)
  → service.read().await                       [held across the call below]
  → LocalAgentService::model_spec()
  → agent_loop.engine().model_info()
  → LlamaChatEngine::model_info()               packages/nlp-engine/src/chat/mod.rs:1120
  → self.state.lock()                           std::sync::Mutex

generate_blocking (packages/nlp-engine/src/chat/mod.rs:343) holds that same mutex while generating. So a previously-cheap status RPC can now block for 60–180s during a turn, and it blocks a tokio worker thread doing it (synchronous lock inside an async fn), while also holding the service read lock.

Why this isn't urgent today

  • GetStatus is currently called only by nodespace model status (the CLI path added for the eval preflight gate), which runs before a model is generating.
  • The frontend does not poll it.
  • service.read() is a read lock, so it does not block other readers.
  • Lock ordering is safe — every site touching service and active_model_id acquires service first and releases before active_model_id; there is no reverse-order site and no deadlock.

Why it should still be fixed

It is a latent trap. The moment a status poller is added to the UI — which is a natural thing to add — it will hang during streaming, and the cause will be several layers away from the symptom.

Suggested fix

Cache the spec at load time alongside active_model_id. It only changes on engine swap, and replace_engine is the single choke point, so a cached (model_id, granted_n_ctx) pair updated there would make get_status allocation-free and non-blocking.

Alternative: document the blocking behavior on model_spec() so the next caller is warned. That is strictly weaker — it relies on the next person reading it.

Source

Raised as 🟡 Important #4 in the code review of PR #1778 and deliberately deferred there: the fix is a daemon-internal refactor, and the PR's scope was the eval harness.

Activity

  1. malibio commented on Jul 28, 2026

    @malibio
    CollaboratorAuthor

    Baseline (issue-1779-cached-model-spec, from 461bab1): Frontend: 170 test files passed, 4104 tests passed.

  2. self-assigned this
    on Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions