allow manual onboarding when VIN decode is low-confidence#312
Open
allow manual onboarding when VIN decode is low-confidence#312
Conversation
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.
JamesReate
reviewed
Apr 17, 2026
Member
JamesReate
left a comment
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 asModel="4D"(body-style code), then got auto-registered on-chain astoyota_4d_2017. Client subsequently crashed trying to render the bad DD.japan_17vin_api.goextracted model from a column that sometimes holds body-style codes, anddecode_vin.gounconditionally created an on-chain DD on tableland miss regardless of how shaky the decode was.Changes
internal/infrastructure/gateways/japan_17vin_api.go— robust model extraction:Model Name,Model name,车型in priority order.^\d+[A-Za-z]{0,3}$(4D, 5D, 2D, 5HB).Additional Vehicle Infomation.internal/core/queries/decode_vin.go— gate auto-create for low-confidence sources:japan17vin,carvxvin,autoiso, orelevaand tableland returns no match → returnNotFoundErrorinstead of callingCreate().Out of scope
toyota_4d_2017).GJ5FW-550049(separate issue in sharedpkg/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.GWS214-6014148withcountryCode=JPNreturns error (not a new on-chain DD).