Skip to content

allow manual onboarding when VIN decode is low-confidence#312

Open
zer0stars wants to merge 4 commits intomainfrom
allow-manual-onboarding
Open

allow manual onboarding when VIN decode is low-confidence#312
zer0stars wants to merge 4 commits intomainfrom
allow-manual-onboarding

Conversation

@zer0stars
Copy link
Copy Markdown
Member

Summary

Stops silent on-chain creation of garbage device definitions from low-confidence VIN decoders and hardens the Japan 17vin adapter.

Background

Japanese engineers onboarding vehicles hit two failures:

  • GWS214-6014148 (Toyota Crown chassis) decoded via japan17vin as Model="4D" (body-style code), then got auto-registered on-chain as toyota_4d_2017. Client subsequently crashed trying to render the bad DD.
  • Root cause: japan_17vin_api.go extracted model from a column that sometimes holds body-style codes, and decode_vin.go unconditionally created an on-chain DD on tableland miss regardless of how shaky the decode was.

Changes

  1. internal/infrastructure/gateways/japan_17vin_api.go — robust model extraction:

    • Tries Model Name, Model name, 车型 in priority order.
    • Rejects body-style codes matching ^\d+[A-Za-z]{0,3}$ (4D, 5D, 2D, 5HB).
    • Falls through to first non-body-style token in Additional Vehicle Infomation.
    • New unit tests.
  2. internal/core/queries/decode_vin.go — gate auto-create for low-confidence sources:

    • If source is japan17vin, carvxvin, autoiso, or eleva and tableland returns no match → return NotFoundError instead of calling Create().
    • Client (separate PR) catches this and opens the manual make/model/year picker.
    • High-confidence sources (Drivly, Vincario, DATGroup, Tesla) keep existing auto-create.

Out of scope

  • Cleaning up existing bad on-chain DDs (e.g., toyota_4d_2017).
  • JPN 11-char chassis 500 for GJ5FW-550049 (separate issue in shared pkg/vin.IsValidJapanChassis()).

Test plan

  • go test -race ./internal/infrastructure/gateways/... — green, includes new japan17vin extraction tests.
  • go build ./... — clean.
  • golangci-lint run — no new issues.
  • Local decode of GWS214-6014148 with countryCode=JPN returns error (not a new on-chain DD).
  • Local decode of a high-confidence VIN with tableland miss still auto-creates (regression check).
  • End-to-end with dimo-driver companion PR: app opens picker on decode failure.

Japanese chassis numbers were producing garbage on-chain device definitions
(e.g. Toyota Crown GWS214-6014148 landed as toyota_4d_2017 because the 17vin
adapter picked "4D" body-style from Model Name). Two fixes:

1. japan_17vin_api.go: robust model extraction. Try "Model Name", "Model name",
   "车型" in priority order; reject body-style codes matching ^\d+[A-Za-z]{0,3}$;
   fall through to first non-body-style token in "Additional Vehicle Infomation".

2. decode_vin.go: gate auto-create of on-chain DD for low-confidence sources
   (japan17vin, carvxvin, autoiso, eleva). On tableland miss from these providers,
   return NotFoundError so the client falls back to the manual picker instead
   of minting a bad DD. High-confidence providers (Drivly, Vincario, DATGroup,
   Tesla) retain existing auto-create behavior.
Locks in that CROWN/HYBRID resolves to CROWN (not 4D) against the
real 17vin response that caused the toyota_4d_2017 on-chain DD.
Platform-shared Toyota chassis (ZWR90, ZRR80) return
Model Name="NOAH/VOXY" or "NOAH/VOXY/ESQUIRE". Picking the first
slash token produced "NOAH" and broke indexing — prior production
DDs were all toyota_voxy_*. The Additional Vehicle Infomation column
names the actual built trim ("VOXY 07S ..."), so use it as a hint
to pick the right candidate. When the hint doesn't match any
candidate (e.g. "CROWN/HYBRID" + "4D HTWC") fall back to first,
which still rejects body-style tokens.

Adds a data-driven test suite covering 16 real payloads from prod.
Copy link
Copy Markdown
Member

@JamesReate JamesReate left a comment

Choose a reason for hiding this comment

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

overall makes sense to me, doesn't seem like it should impact anything other than japan really. tests seem to cover a lot

Two 17vin responses produced malformed model slugs:
- "LEXUS NX SERIES(TMMC" carried the factory code suffix into the
  slug (toyota_lexus-nx-series(tmmc_2022 — invalid, parens aren't
  legal slug chars).
- data.model_list[0].Model_en carries 17vin's standardized product
  name ("NX 350") which is cleaner than the raw EPC attribute;
  prefer it when populated.

Adds sanitizeModelName (truncate at first paren or comma, trim) and
two new test cases. Non-paren payloads unchanged.
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.

2 participants