Skip to content

Fix per-task routing: local personas now upgrade to cloud for tool use (#371) - #401

Merged
joelteply merged 1 commit into
mainfrom
fix/task-routing-371
Mar 25, 2026
Merged

joelteply merged 1 commit into
mainfrom
fix/task-routing-371

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

  • Root cause: hasTools only checked nativeToolSpecs — always false for local models (candle) which get XML tools in system prompt. TaskAwareProviderRouter.routeForTask() never triggered the "tools require cloud" upgrade
  • Fix: Check toolCount from ToolDefinitionsSource metadata (set for both native AND XML paths). Now hasTools = hasNativeTools || hasXmlTools
  • Diagnostic: Added XML tool count log, clarified pre-routing log that was showing stale provider info

This was the core bug behind #371 and #366 — local 3B models can't use tools, but the routing that was supposed to upgrade them to cloud never fired.

Test plan

  • TypeScript compilation clean
  • Deployed, but local persona queue depth (~16 messages) prevents immediate QA
  • Verify routing log 🔄 Task routing — Tools require cloud model appears for local personas
  • Verify local personas actually use cloud provider for tool-requiring tasks

🤖 Generated with Claude Code

…enting cloud upgrade (#371)

Local personas (candle 3B) get XML tools in system prompt, not native tool specs.
The hasTools check only looked at nativeToolSpecs, so it was always false for local
models. TaskAwareProviderRouter never triggered "tools require cloud" upgrade.

Fix: check toolCount from ToolDefinitionsSource metadata (set for both native AND XML paths).
Now local personas with tool-requiring tasks get upgraded to best available cloud provider.

Also: clarified misleading pre-routing log, added XML tool count diagnostic log.
Copilot AI review requested due to automatic review settings March 25, 2026 05:05
@joelteply
joelteply merged commit 3bba9f7 into main Mar 25, 2026
4 of 6 checks passed
@joelteply
joelteply deleted the fix/task-routing-371 branch March 25, 2026 05:07

Copilot AI 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.

Pull request overview

Fixes per-task routing so local personas correctly upgrade to a cloud provider when tools are present, even when tools are injected via XML in the system prompt (rather than native tools[] specs).

Changes:

  • Update tool-presence detection to consider toolDefinitions.toolCount (covers both native and XML tool injection paths).
  • Improve diagnostics: clarify the Phase 3.3 log and add an explicit log for XML tool count.
  • Update planning doc status for issue #368.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/system/user/server/modules/PersonaResponseGenerator.ts Fixes hasTools detection for XML tool injection and adds clearer routing/tool logs.
docs/planning/ALPHA-GAP-ANALYSIS.md Marks #368 as completed (DONE) with PR reference.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +446 to +447
const hasXmlTools = !!(toolMeta?.toolCount && (toolMeta.toolCount as number) > 0);
const hasTools = hasNativeTools || hasXmlTools;

Copilot AI Mar 25, 2026

Copy link

Choose a reason for hiding this comment

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

hasXmlTools is derived solely from toolMeta.toolCount, which is populated for both native and XML tool paths. That makes the name misleading and can confuse future routing/logging changes. Consider deriving hasTools from toolCount and defining hasXmlTools as !hasNativeTools && toolCount > 0 (or renaming it to reflect it means “non-native tool injection”).

Suggested change
const hasXmlTools = !!(toolMeta?.toolCount && (toolMeta.toolCount as number) > 0);
const hasTools = hasNativeTools || hasXmlTools;
const hasTools = !!(toolMeta?.toolCount && (toolMeta.toolCount as number) > 0);
// XML tools here means "non-native tool injection" (tools present but no native specs)
const hasXmlTools = !hasNativeTools && hasTools;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants