Skip to content

QVAC-22567 feat[bc]: remove dynamic tools (tools_compact) from llm-llamacpp addon - #3373

Merged
dev-nid merged 8 commits into
mainfrom
QVAC-22567-remove-dynamic-tools
Aug 14, 2026
Merged

dev-nid merged 8 commits into
mainfrom
QVAC-22567-remove-dynamic-tools

Conversation

@iancris

@iancris iancris commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

🎯 What problem does it solve?

The dynamic tools feature (tools_compact) lets a caller add tool definitions mid-conversation and have them trimmed from the KV cache once the tool-call chain resolves. It only works for Qwen3 — it depends on a custom Qwen3 dynamic template — and on sliding-context anchor bookkeeping that does not carry over to newer LLM models. This PR removes the feature from the llm-llamacpp addon.

Introduced in #706 and #1379 (QVAC-16769). The SDK-side removal (toolsMode) is split into companion PR #3380.

📝 How is it solved?

  • Deleted ToolsCompactController and Qwen3ToolsDynamicTemplate (normal Qwen3 templating keeps using getFixedQwen3Template)
  • The tools_compact config key is no longer parsed
  • Stripped the tools-anchor plumbing from ContextSlider, ContextShifter, ReasoningBlockCompactor, TextLlmContext/MtmdLlmContext, LlamaModel, and ContinuousBatchScheduler — general context sliding, M-RoPE sliding, and reasoning compaction are unchanged
  • Removed the two-pass (with/without tools) tokenization, the PromptLayout/validatePromptPolicy prompt-shape validation chain, and the nPastBeforeTools/toolsTrimmed debug stats
  • Deleted the feature's unit tests, tools-compact integration + mobile test suites, docs, and examples; adapted shared tests to the new signatures (kept general coverage — e.g. the tail-trim interaction tests were retained and renamed since the branches they pin still exist)
  • No version bump — releasing is deferred to the release flow

🧪 How is it tested?

  • Full local build (bare-make generate/build/install) and C++ unit tests — 704 ran, 698 passed, 0 failed, 6 pre-existing environmental skips (GPU-gated / fixture-gated); JS lint clean; mobile test manifest regenerated with group coverage validated
  • The identical addon content already passed the full labeled CI suite on the pre-split combined branch: cpp-tests on linux/darwin/windows, full prebuild matrix, iOS + Android mobile E2E, desktop integration on darwin-arm64/linux-arm64. The 3 red desktop platforms (test-linux-x64, test-darwin-x64, test-win32-x64) were verified byte-identical to same-day pre-PR baseline runs on other branches (pre-existing, non-gating)
  • Repo-wide grep for tools_compact|toolsCompact|tools_at_end|Qwen3ToolsDynamic|nPastBeforeTools|PromptLayout|validatePromptPolicy returns only historical changelog entries

⚠️ Any breaking changes?

Yes — the dynamic tools feature is removed. A lingering tools_compact config key is now accepted but ignored with a deprecation warning (a tombstone in commonParamsParse) for one release, so existing configs — including older SDK builds that still emit the key — keep loading rather than failing model load on an unknown argument. Plan to drop the tombstone (making the key an error) in a future release once no consumer emits it.

BEFORE:

// old — addon config key enabling dynamic tools (Qwen3-only)
const config = { tools: 'true', tools_compact: 'true' }

AFTER:

// new — tool definitions always stay in place; a leftover tools_compact
// key is ignored (deprecation warning) rather than toggling anything
const config = { tools: 'true' }

@iancris
iancris requested review from a team as code owners July 21, 2026 12:56
@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Status

Current Status: ✅ APPROVED
Approvals so far: Team Lead: 1, Member: 1

@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

License compliance — clean

No new dependency license findings in this PR.

Warn-only (shadow) mode — this check does not block merges yet.

Updated automatically by the canonical license compliance workflow.

NOTICE presence (advisory)

Missing NOTICE (advisory, does not block):

  • ./.github/actions/release-merge-guard
  • ./docs/website
  • ./packages/ggml-coload-smoke
  • ./packages/fabric/test/integration
  • ./packages/inference-addon-cpp/mobile
  • ./packages/sdk/e2e
  • ./packages/llm-llamacpp/benchmarks/performance
  • ./packages/llm-llamacpp/benchmarks/server
  • ./packages/vla-ggml/sim/server
  • ./packages/embed-llamacpp/benchmarks/performance
  • ./packages/embed-llamacpp/benchmarks/server
  • ./packages/asr-ggml/benchmarks/server

@iancris iancris added verified Retired - no longer authorizes CI. Fork PRs use fork-ci environment approval. verify labels Jul 21, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Mobile integration tests — @qvac/llm-llamacpp (iOS)

Result: passed

metric value
Devices passed 26
Devices failed 0
Test cases total 78
Test cases passed 78
Test cases failed 0
Test cases skipped 0

View workflow run

@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Mobile integration tests — @qvac/llm-llamacpp (Android)

Result: passed

metric value
Devices passed 21
Devices failed 0
Test cases total 63
Test cases passed 63
Test cases failed 0
Test cases skipped 0

View workflow run

@github-actions

github-actions Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

QVAC E2E — android — ✅ all tests passed (91/103, 2060s)

Config: suite=smoke · filter=(none) · exclude=(none)
Device pool: Google Pixel 9 Pro - Android 15 — ☀️ highly available
View run · Artifacts: reports · Device Farm logs

maxim-smotrov
maxim-smotrov previously approved these changes Jul 27, 2026
Comment thread packages/llm-llamacpp/test/unit/test_chat_template_utils.cpp
maxim-smotrov
maxim-smotrov previously approved these changes Jul 29, 2026
donriddo
donriddo previously approved these changes Jul 29, 2026

@donriddo donriddo 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.

isQwen3Architecture fix looks good. Exported from the header, six test cases pin the exact-match boundary including the qwen35 false case that was the original risk. Good to go.

iancris and others added 4 commits August 11, 2026 14:53
Remove the dynamic tools feature (tools added mid-conversation and
trimmed from the KV cache once the tool-call chain resolves). It only
worked for Qwen3 via a custom dynamic template and relied on
sliding-context anchor bookkeeping that does not carry over to newer
models.

- Delete ToolsCompactController and Qwen3ToolsDynamicTemplate
- Stop parsing the `tools_compact` config key (breaking)
- Strip the tools anchor plumbing from ContextSlider, ContextShifter,
  ReasoningBlockCompactor, Text/Mtmd contexts, LlamaModel, and the
  continuous-batch scheduler; general sliding/compaction is unchanged
- Remove the two-pass (with/without tools) tokenization
- Remove PromptLayout + validatePromptPolicy (existed only for
  tools_compact prompt-shape validation)
- Remove runtimeDebugStats (nPastBeforeTools/toolsTrimmed) and
  getNPastBeforeTools
- Delete feature unit/integration/mobile tests, docs, and examples;
  adapt shared tests to the new signatures

No version bump; releasing is deferred to the release flow. SDK-side
removal (toolsMode) is split into a companion PR.

Introduced in #706 and #1379 (QVAC-16769).
- Tolerate a lingering `tools_compact` config key: erase it with a
  deprecation warning instead of letting it fall through to the generic
  CLI-arg conversion, where the unknown `--tools-compact` argument would
  throw InvalidArgument and fail the entire model load. Restores the
  pre-removal graceful behavior (no-op / ignored) and decouples merge and
  release ordering from the SDK-side removal (PR #3380). Adds a regression
  test (CommonParamsParseToolsCompactIgnored).
- Remove the dead `hasKvCacheContext` block left in the continuous-batch
  admission path — a blocking file_size syscall performed under the
  scheduler lock whose only consumer (validatePromptPolicy) was deleted.
- Reword two stale comments that still referenced the removed
  onGenerationCompletePolicy / generationStarted_ (ContinuousBatchScheduler
  .hpp finalizeTerminalDriver doc + .cpp notifyDone re-run rationale).
- Fix the continuous-batching.md onCancel lifecycle row whose "Same policy
  as above" referred to the removed onGenerationCompletePolicy.
The tools_compact removal deleted `SupportsToolsCompactForModelMetadata
ByArchitecture`, which was the only test pinning the exact-match `qwen3`
arch predicate. That predicate survives (it still drives fixed-template
selection via isQwen3Model -> getChatTemplateForModel) but had lost all
direct coverage, so a regression that broadened it to match `qwen35`
would slip through silently.

Export `isQwen3Architecture` from ChatTemplateUtils (mirroring the
already-exported `isQwen3ReasoningFamilyArchitecture`) and add
`IsQwen3ArchitectureExactMatch` covering qwen3 (+case-insensitive) true
and qwen35/qwen3moe/llama/"" false. Addresses PR #3373 review comment.

@tobi-legan tobi-legan 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.

QA review summary: the existing isQwen3Architecture thread is addressed. The main remaining concern is release ordering: this addon PR intentionally removes tools_compact/dynamic tools, but current SDK and inference code still expose toolsMode dynamic and emit tools_compact=true. Before release, the companion SDK/inference PR should remove or loudly deprecate that public mode so users do not get silent behavior changes. The test ask is limited to proving the remaining static tool-calling path, or covering dynamic-mode rejection/deprecation in the companion PR. QIP triage: public addon/SDK contract removal trigger applies; proposal scope is removal and release ordering of dynamic tools.

Comment thread packages/llm-llamacpp/addon/src/model-interface/LlamaModel.cpp Outdated
Comment thread packages/llm-llamacpp/test/integration/tool-calling.test.js
tobi-legan
tobi-legan previously approved these changes Aug 12, 2026

@tobi-legan tobi-legan 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.

Re-reviewed the latest commits. Prior comments are addressed: tools_compact=true now rejects clearly, tools_compact=false remains an ignored tombstone, and the warm tool-calling follow-up now validates declared parseable tool calls. No further findings from my pass.

maxim-smotrov
maxim-smotrov previously approved these changes Aug 13, 2026

This branch was previously deployed

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

Labels

prebuilds CI: run only prebuild/cache stage (requires verified) run-cpp-addon-tests CI: run C++ addon tests (requires verified) run-desktop-addon-tests CI: run desktop integration tests (requires verified) run-mobile-addon-tests CI: run mobile integration tests (requires verified) verified Retired - no longer authorizes CI. Fork PRs use fork-ci environment approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants