Skip to content

LM Studio + concurrent agents + unified KV cache = opencode runs past context limits, API errors, and gets stuck in a retry loop #50347

Closed as duplicate

Description

@machineonamission

Description

this is a very weird combination of settings.

i'm running opencode with an LLM via LM Studio on my somewhat modest RTX 5070 Ti

So: llama.cpp/lm studio has experimental concurrent agent settings.

opencode already makes full use of this, and autodiscovers lm studio and the agent is able to use concurrent and subagents amazinglky.

BUT: the unified kv cache causes an issue.

unified kv cache means the context window memory is shared among concurrently executing agents. this is useful because it makes it possible at all to have concurrent execution within memory limitations.

opencode isn't aware of this yet, and treats each subagent as if it has its own copy of the full context window.

so it runs the agents in parallel until the unified kv cache fills, but opencode has no idea that it has until lm studio sends back an API error, which opencode just entirely aborts and retries the subagent, but this doesn't actually fix the issue most of the time.

would it be possible for opencode to be aware of unified kv cache and manage subagents with that in mind?

Plugins

none i dont think

OpenCode version

2.0.12 desktop

Steps to reproduce

Launch 5 or more concurrent general subagents simultaneously, each requesting substantial context (file reads, glob searches, grep operations, git history — anything that produces long LLM responses). Use the same model for all agents

- M2

Screenshot and/or share link

Image

Operating System

windows 11 x64

Terminal

opencode desktop app lol

Activity

  1. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the detailed write-up. I think this is a duplicate of #27110, which asks for a setting to cap how many subagents run in parallel, for the same reason you describe: on a local server the parallel requests share limited context/KV memory. OpenCode can't see how LM Studio splits its unified KV cache across requests, so capping concurrent subagents is the practical way to keep them inside it. PR #55983 proposes exactly that (experimental.subagent_concurrency).

    Possible duplicates and related issues, ordered from most to least likely:

    The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different, for example if the retry loop also happens without concurrent subagents.

  2. opencodejr commented on Oct 29, 2026

    @opencodejr
    Contributor

    We haven't heard back, so I'm closing this as a duplicate of #27110. That issue asks for a cap on how many subagents run at once, which would stop parallel subagents from overflowing LM Studio's shared KV cache. Please follow #27110 and PR #55983, which proposes an experimental.subagent_concurrency setting.

    If you see the retry loop even without parallel subagents, please comment here with the details and we can reopen this. Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions