Skip to content

fix(sse): make MAX_TOOLS_LIMIT configurable via env var - #15193

Merged
diegosouzapw merged 3 commits into
diegosouzapw:release/v3.8.52from
70nyIT:fix/13190-max-tools-limit-env
Oct 8, 2026
Merged

diegosouzapw merged 3 commits into
diegosouzapw:release/v3.8.52from
70nyIT:fix/13190-max-tools-limit-env

Conversation

@70nyIT

@70nyIT 70nyIT commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ base-red inherited: #15100

Summary

  • MAX_TOOLS_LIMIT now reads OMNIROUTE_MAX_TOOLS_LIMIT through the existing envInt() helper: default 128, positive integers only. Unset or invalid values keep the current 128 behavior, so nothing changes by default.
  • truncateToolList() now evaluates bypassDefaultToolLimit before the known/detected provider limit. The getKnownToolLimit() branch used to return first, so once a provider limit was cached or detected the operator override was silently ignored.
  • The new var is documented in .env.example (§6 Tool & Routing Policies) and docs/reference/ENVIRONMENT.md (§6), matching the other envInt() knobs already listed there.
  • Request tool lists are still clipped to the same caps as before when no override and no bypass is requested.

Related Issues

Validation

  • Change type: routing
  • Focused tests and category gates from the golden path
  • npm run lint (pre-commit lint-staged on the changed files)
  • Reconciled with the current active release base; focused checks rerun afterward
  • Production-code changes include a new or updated automated test in this PR

Commands run:

  • node --import tsx/esm --test tests/unit/chatcore-upstream-body.test.ts tests/unit/max-tools-limit-env.test.ts → 45 pass / 0 fail
  • node --import tsx/esm --test tests/unit/cache-sweeps.test.ts → 26 pass / 0 fail
  • npm run typecheck:core → clean
  • npx eslint <changed files> → clean
  • npm run check:env-doc-sync → clean (864 vars in .env.example, 881 in ENVIRONMENT.md, all in sync)
  • npm run check:docs-sync and npm run check:fabricated-docs → clean
  • npm run check:docs-counts → fails only on the inherited base drift (README.md / llm.txt still say 3.8.51), which is 🔴 Release branch not green: release/v3.8.52 #15100 and is untouched by this branch.

TDD proof for the bypass fix: temporarily restoring the old ordering makes the new regression test fail with expected: 250, actual: 200; with the reorder it passes.

Tests Added Or Updated

  • tests/unit/chatcore-upstream-body.test.ts — regression: "operator bypass wins over a known provider limit"
  • tests/unit/max-tools-limit-env.test.ts (new) — unset ⇒ 128, OMNIROUTE_MAX_TOOLS_LIMIT=512 ⇒ 512, non-positive-integer values ⇒ 128

Coverage Notes

  • open-sse/config/constants.ts: the load-time parse is exercised by the new env override test.
  • open-sse/handlers/chatCore/upstreamBody.ts: the truncation/bypass path is exercised by tests/unit/chatcore-upstream-body.test.ts.

Reviewer Notes

  • Documentation updated: OMNIROUTE_MAX_TOOLS_LIMIT (default 128, positive integers only, invalid values fall back to 128) is listed in .env.example §6 and docs/reference/ENVIRONMENT.md §6. It only moves the default ceiling — a provider with a known/proactive limit (grok-cli 200, nvidia 1536) still applies its own cap.
  • Base release/v3.8.52 is currently red (🔴 Release branch not green: release/v3.8.52 #15100); any failures inherited from the base are not caused by this branch.

Make the request tool-list cap read OMNIROUTE_MAX_TOOLS_LIMIT (positive
integers only, default 128) through the existing envInt() helper, so an
operator can raise or lower the cap without a rebuild. Unset/invalid values
keep the previous 128 behavior, so nothing changes by default.

Also evaluate bypassDefaultToolLimit before the known/detected provider
limit in truncateToolList: the getKnownToolLimit() branch used to return
first, so once a provider limit was cached or detected the operator bypass
was silently ignored.

Regression tests cover the bypass precedence and the env override.

Refs diegosouzapw#13190
70nyIT and others added 2 commits September 30, 2026 12:42
Add the new tool-list cap override to .env.example (§6 Tool & Routing
Policies) and docs/reference/ENVIRONMENT.md, matching the existing envInt()
knobs already documented there.

Refs diegosouzapw#13190
bypassDefaultToolLimit is the OpenCode client signal, not an operator
override. Restore the original order in truncateToolList so it only lifts
the generic default cap and a known provider limit still truncates.
Replaces the test that pinned the opposite behavior.

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
@diegosouzapw
diegosouzapw merged commit c6a3540 into diegosouzapw:release/v3.8.52 Oct 8, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(backend): Make tool-list cap (MAX_TOOLS_LIMIT=128) configurable via env var

2 participants