Skip to content

fix(ai): repair resource search, add AI tools and console commands - #330

Merged
roncodes merged 3 commits into
release/v0.6.69from
feature/ai-audit-hotfixes
Sep 21, 2026
Merged

roncodes merged 3 commits into
release/v0.6.69from
feature/ai-audit-hotfixes

Conversation

@roncodes

Copy link
Copy Markdown
Member

Why

Auditing the Fleetbase AI extension against a production log export turned up a hard failure on this side: fleet-ops.search_resources threw on every call because Sensor and the resource search still referenced sensor_type, a column an earlier migration had dropped. The full SQL error, company UUID included, was handed to the model provider, and the turns were still recorded as answered.

Fixes

  • sensor_typetype in Sensor (slug, activity log, filter params, scopeByType, alert context) and in the resource search.
  • Each resource type is searched in its own try/catch, so one broken type no longer kills the whole search; it is reported as an unavailable search instead.
  • Search terms are built from reference-like tokens only, with stopwords: no more LIKE against status, type or uuid, and the search is skipped when nothing useful is left. (The old behavior matched half the database on words like "the".)
  • Order amount thresholds are converted from dollars to minor units using the currency's exponent, and insights expose the currency.
  • applyDirectivesForPermissions is applied to the order insights, asset status and search queries, so AI answers stay inside what the user is allowed to see.

New surface for the AI extension

  • propose_create_order and fleetops_search tools (registered only when the AI extension's tool interface is present).
  • FleetOpsAiConsoleCommands: open, create, view and import commands for orders, drivers, vehicles, contacts, customers, places, fleets, issues, work orders and maintenances, plus the Fleet-Ops settings pages. They are built on the existing *-actions services. The model can only propose one; the user confirms and the server re-authorizes before anything runs.
  • CreateOrderPreviewCapability::buildDraft accepts a tool-supplied draft and an existing draft, instead of only parsing the prompt.

Testing

2882 tests, 0 failures, 8 errors. The 8 errors are the local SQLite build lacking CONCAT and fail the same way on main; they pass on MySQL in CI. Run one file per process, as this suite requires. php-cs-fixer is clean on the changed files.

Coverage for the new files has not been measured, and this repo's CI gate is 100%, so that may need a follow-up pass.

Related

The AI extension side is in fleetbase/ai; fleetbase/iam-engine#33 and fleetbase/dev-engine#46 add the resource-action services the console commands call into.

Hotfixes found while auditing the AI extension against production logs, where
`search_resources` failed on every call and leaked the SQL error to the provider:

- `Sensor` and the resource search referenced `sensor_type`, a column dropped by
  an earlier migration. Use `type`.
- Search each resource type in its own try/catch so one failure no longer takes
  down the whole search, and report it as an unavailable search instead.
- Build search terms from reference-like tokens only: never run LIKE against
  `status`, `type` or `uuid`, and skip the search when nothing useful remains.
- Convert order amount thresholds from dollars to minor units using the currency
  exponent, and expose the currency on insights.
- Scope the AI capability queries with `applyDirectivesForPermissions` so answers
  stay within what the user may see.

Adds the tool-calling surface the AI extension now drives:

- `propose_create_order` and `fleetops_search` tools, registered when the AI
  extension is installed.
- `FleetOpsAiConsoleCommands`: navigate, create, view and import commands for
  orders, drivers, vehicles, contacts, customers, places, fleets, issues, work
  orders, maintenances and the Fleet-Ops settings pages. The AI may only propose
  these; the user confirms and the server re-authorizes before anything runs.
@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.99%. Comparing base (7f581a3) to head (e997778).

Additional details and impacted files
@@            Coverage Diff             @@
##               main     #330    +/-   ##
==========================================
  Coverage     99.99%   99.99%            
- Complexity    11936    12001    +65     
==========================================
  Files           583      588     +5     
  Lines         44892    45189   +297     
==========================================
+ Hits          44891    45188   +297     
  Misses            1        1            
Flag Coverage Δ
backend 99.99% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Tool calling only reaches capabilities implementing `AIToolCapabilityInterface`,
so the seven Fleet-Ops capabilities without a tool definition were unreachable
once the AI extension defaulted to tools. Two of them had no replacement
anywhere: route optimization and order import guidance simply stopped working.

`OptimizeOrderRouteTool` wraps the existing preview capability so the model can
propose a resequenced route for one order. As before, the proposal is a card the
user confirms; nothing changes until they apply it.

`ImportOrdersTool` reports the accepted file formats and required spreadsheet
columns. It deliberately cannot read an uploaded file, and says so, so the model
does not claim rows were imported.

The remaining five are genuinely superseded by the core tools: `docs_help` by
`search_docs`, `console_navigation` by `find_console_commands`, and
`operational_query`, `order_insights` and `asset_status` by the generic record
counting and listing tools.
@roncodes
roncodes changed the base branch from main to release/v0.6.69 September 21, 2026 07:28
@roncodes
roncodes merged commit 427ae5a into release/v0.6.69 Sep 21, 2026
11 checks passed
@roncodes
roncodes deleted the feature/ai-audit-hotfixes branch September 21, 2026 07:36
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.

1 participant