Skip to content

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

Open
roncodes wants to merge 1 commit into
mainfrom
feature/ai-audit-hotfixes
Open

roncodes wants to merge 1 commit into
mainfrom
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 (14601ca) to head (9b72307).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@              Coverage Diff              @@
##                main     #330      +/-   ##
=============================================
- Coverage     100.00%   99.99%   -0.01%     
- Complexity     11887    11990     +103     
=============================================
  Files            582      586       +4     
  Lines          44715    45132     +417     
=============================================
+ Hits           44715    45131     +416     
- Misses             0        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.

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