Skip to content

feat(core): make codemode agent and llm limits configurable - #67221

Open
kitlangton wants to merge 3 commits into
devfrom
codemode-agent-limits
Open

kitlangton wants to merge 3 commits into
devfrom
codemode-agent-limits

Conversation

@kitlangton

@kitlangton kitlangton commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Adds experimental.codemode_agent_limits so Code Mode agent() and llm() concurrency and total caps can be configured per user or workspace while keeping built-in defaults unchanged at 16/100 (agent) and 32/500 (llm).


Added by the opencode bot (AI-generated).

Related: #66691

Public API: adds config key experimental.codemode_agent_limits (agent_concurrency, agent_total, llm_concurrency, llm_total) to the schema, OpenAPI spec and client types; defaults unchanged (backwards compatible)

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as described. On the base branch, a Code Mode agent() child's completion lands in the parent's inbox; with this PR it finishes quietly, and a follow-up sent through a Job still reports back. I checked this by running the new subagent-report test on both branches. The three test files pass (32 tests) and tsc on packages/core is clean.

Public API: adds the config key experimental.codemode_agent_limits with optional positive-integer fields agent_concurrency, agent_total, llm_concurrency and llm_total. This is backwards compatible. Existing configs don't change, but the effective default limits go up from 16/100 to 64/500 for agent() and from 32/500 to 128/2000 for llm().

Blocking: packages/protocol/openapi.json wasn't regenerated. bun run check:generated in packages/protocol fails on this branch ("Generated OpenAPI document is stale") and passes on dev, and CI runs that check. Please run bun run generate there.

Worth trimming: the new limits tests are much larger than what they check (see inline).

This covers the reporting part of #66691 only. compaction-subagents.ts still has the automation-only filter, so finished agent() children still take up subagent slots in compaction checkpoints.

Related: #66691

subagent_depth: NonNegativeInt.pipe(optional).annotate({
description: "Maximum subagent nesting depth. Defaults to 1.",
}),
codemode_agent_limits: Schema.Struct({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new config key is part of the generated OpenAPI document, so packages/protocol/openapi.json needs regenerating. bun run check:generated in packages/protocol fails on this branch and CI runs it. Running bun run generate there should fix it.

if (!result.ok) expect(result.error.message).toContain("already started 3")
})

test("enforces agent() concurrency cap and shares run state across concurrent first calls", async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The limits block adds about 190 lines for a few small behaviours.

  • Three tests repeat the same ~20-line provideService setup. A small run(script, impl) helper would cut most of that.
  • The concurrency tests measure overlap with real Effect.sleep calls (20–25 ms), which depends on timing.
  • The schema-bounds test (line 291) mostly checks PositiveInt, and the "cache-stable" instructions test checks that a pure function returns the same string twice. Both can be dropped.

One total-cap test, one concurrency-cap test and the mergeLimits layering test would cover the change.

@kitlangton
kitlangton force-pushed the codemode-agent-limits branch from 7ea7d3e to 7264ebe Compare November 30, 2026 01:01
@kitlangton kitlangton changed the title feat(codemode): raise and configure agent()/llm() limits and stop child wake leaks feat(codemode): raise and configure agent() and llm() script limits Nov 30, 2026

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither of my earlier points is fixed in the pushed commit. The only change is that the SubagentReport part was dropped. packages/protocol/openapi.json still isn't regenerated, and bun run check:generated in packages/protocol still fails, which will fail CI. test/codemode/agents.test.ts is unchanged too: it still uses Effect.sleep and has no Deferred gates. The description says both were done, so those changes may not have been pushed.

The two test files pass (19 tests) and tsc on packages/core is clean.

Public API: adds the config key experimental.codemode_agent_limits with optional positive-integer fields agent_concurrency, agent_total, llm_concurrency and llm_total, and raises the default limits. This is backwards compatible.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both earlier points are addressed. The OpenAPI document and the client's generated types are regenerated, and the generated-file checks pass in packages/protocol and packages/client. The limits tests are down to three cases that share a run helper, and the concurrency test now uses Deferred gates instead of timed sleeps. I ran the two test files three times and all 15 tests passed each time; tsc on packages/core is clean. Nothing new to raise.

Public API: adds the config key experimental.codemode_agent_limits with optional positive-integer fields agent_concurrency, agent_total, llm_concurrency and llm_total. The OpenAPI spec and the generated client ConfigEntry type gain the same field. Default limits go from 16/100 to 64/500 for agent() and from 32/500 to 128/2000 for llm(). This is backwards compatible.

@kitlangton kitlangton changed the title feat(codemode): raise and configure agent() and llm() script limits feat(core): make codemode agent and llm limits configurable Nov 30, 2026

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest commit returns the defaults to 16/100 for agent() and 32/500 for llm(), and the code, schema descriptions, skill text and test all agree. The generated-file checks pass in packages/protocol and packages/client, the two test files pass (15 tests) and tsc on packages/core is clean. Both earlier points (regenerated OpenAPI, trimmed tests) are still addressed. Nothing new to raise.

Public API: adds the config key experimental.codemode_agent_limits with optional positive-integer fields agent_concurrency, agent_total, llm_concurrency and llm_total. The OpenAPI spec and the generated client ConfigEntry type gain the same field. Default behaviour is unchanged, so this is backwards compatible.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant