Skip to content

running_tasks DashMap.insert overwrites previous task — stop_agent_run can't kill the orphaned LLM call #3739

Description

@houko

Location

  • crates/librefang-kernel/src/kernel/mod.rs:6303-6309

Finding

if !is_fork {
    self.running_tasks.insert(
        (agent_id, effective_session_id),
        RunningTask { abort: handle.abort_handle(), ... });
}

DashMap::insert returns the old value and silently drops it. If two concurrent non-fork streaming invocations target the same (agent_id, session_id) key (which can happen with session_mode = Persistent when two callers both compute the same effective_session_id), the earlier entry's abort_handle is silently dropped.

stop_agent_run calls running_tasks.remove(&(agent_id, session_id)) and aborts whichever entry is currently stored — typically the second invocation's handle. The first invocation continues running, burning tokens, with no way to stop it externally.

When This Triggers

Impact

  • User clicks "stop"; UI says stopped; LLM call continues; budget drains; no log explains why
  • Impact severity depends on how often two concurrent streaming calls target the same session — uncommon in single-user single-session setups, more likely with channel bridges + dashboard open simultaneously

Fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/kernelCore kernel (scheduling, RBAC, workflows)area/runtimeAgent loop, LLM drivers, WASM sandboxbugSomething isn't workingneeds-triageAuto-applied when the issue title/body matched no area label — needs maintainer reviewseverity/mediumBug or limitation with workaround / partial impact

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions