Repository navigation
[obvious-fleet] Test scan correction learner + confidence router (ported onto alpha) - #38
obvious-autobuild[bot] wants to merge 7 commits into
Conversation
…tions Pins ConfidenceRouter behavior across 12 XCTests: per-source routing thresholds (vision, OCR exact, OCR fuzzy), inclusive boundary values via Float.nextDown plus hard literals, the nil ocrMatchKind -> .exact fallback (fuzzy vs nil divergence at 0.55), manual-source bypass, pinned Threshold constants, categorize order preservation and full partition coverage, character-for-character explanation strings with score rounding, bucket labels, and Detection convenience flags. Co-authored-by: Sam Gu <sgu07966@gmail.com>
… persistence, telemetry Co-authored-by: Sam Gu <sgu07966@gmail.com>
…cache ordering Co-authored-by: Sam Gu <sgu07966@gmail.com>
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Merges origin/alpha (0309dd1) into the PR branch so the change sits on the current integration branch. fix/scan-failure-report (3e6d321) is an ancestor of alpha; the branch's five commits are preserved as-is. Co-authored-by: obvious-autobuild[bot] <262744130+obvious-autobuild[bot]@users.noreply.github.com>
Swift-format strict lint (the repo's pre-commit gate, lineLength 100) flagged one line introduced by the port; wrapping only, no behavior change. Co-authored-by: obvious-autobuild[bot] <262744130+obvious-autobuild[bot]@users.noreply.github.com>
|
Independent review (Obvious, Autobuild + Max) Verdict: ready I did not author this PR (different thread); this review was performed autonomously per the task brief. Draft PR, base Findings (ranked by severity)1. LOW — record-time cache overwrite can drop the merged legacy count until restart. The record-time read-back ( 2. LOW — title undersells a production behavior change. The title says "Test scan correction learner + confidence router", but the PR also changes runtime behavior ( Housekeeping note: PR #53's base is this branch ( What I verified (commands and results, all on head fe6a8e6)
What I couldn't verify
|
fleet-packet: burst6-cont-fridgeluck-38
Test scan correction learner + confidence router — ported onto alpha
Covers the two recognition-logic services flagged in #4 with unit tests, and fixes one real bug found while writing them. The original base
fix/scan-failure-reportis stale against the repository's current integration branchalpha, so the branch is now ported onto alpha and this PR targets alpha. Still a draft.What changed and why
fix/scan-failure-report(3e6d321) is an ancestor ofalpha(0309dd1); the branch's five commits sat on that base while alpha moved 63 commits ahead, with zero overlap in touched files. The port is a merge oforigin/alphainto the branch as commit 4832043 — chosen over a rebase so the original commit hashes survive and no force-push is needed.git diff --name-only origin/alpha HEADis exactly the three PR files. PR base retargetedfix/scan-failure-report→alpha.apps/ios/Tests/LearningServiceTests.swift— 13 tests. Correction threshold (auto-correct at 2, suggestion at 1), split/mixed correction targets, case-insensitivity, whitespace normalization, cache reload agreement with the database (ORDER BYdeterminism incl. rowid tie-break), highest-count wins after reload, telemetry counts/hit-rate/persistence (UserDefaults reset in setUp).apps/ios/Tests/ConfidenceRouterTests.swift— 12 tests. Thresholds by source (Vision 0.82/0.45, OCR exact 0.90/0.60, OCR fuzzy 0.55 confirm-only), inclusive boundary values vianextDownon theThresholdsconstants,ocrMatchKind == nildefaulting to exact rules, manual-source always-auto,categorizeorder preservation, exact explanation strings + rounding, bucket labels.apps/ios/Capability/Core/Recognition/LearningService.swift— minimal fix (details below).fe6a8e6wraps one over-length line inLearningServiceTests.swiftso the repo'sswift format lint --strictpre-commit gate passes; formatting only.Fix: normalization in the correction learner
recordCorrection(visionLabel:)lowercased but did not trim, sorecordCorrection("tomato", 1)thenrecordCorrection("TOMATO ", 1)landed on two different cache keys and the label never reached the auto-correct threshold —correctedIngredientId(for: "tomato")stayednil. Failing-first repro:Fix: a single
normalizedLabelhelper (trim + lowercase) applied at every boundary — record, both lookups, cache load, and the storedvision_label. No schema migration; legacy untrimmed rows stay separate DB rows but the cache now merges them at read time (best-effort).Same patch makes both cache queries share one deterministic order —
ORDER BY correction_count DESC, last_used_at DESC, rowid DESC— so a freshLearningServiceinstance keeps the same winner per label as the record-time read-back instead of whichever row SQLite returns first on a count tie. (A second pre-fix failure —testMixedTargetCorrectionsDoNotAutoCorrectpicking the older row on a same-secondlast_used_attie — is the read-back sibling of this and is fixed by the same change.)Audit note: where corrections apply (unchanged by this PR)
VisionServicepassesLearningService.correctedIngredientId(for:)intoIngredientIdentityResolution.resolveLabel— corrections take precedence over curated/catalog matches.IngredientReviewViewis the write path:recordCorrection+suggestedCorrectionpre-selection + shown/accepted telemetry.ReverseScanService/RecommendationEngineuseConfidenceLearningService(confidence calibration — separate service, out of scope here).How I verified
Linux sandbox, Swift 6.4 (swift-6.4-RELEASE), GRDB 7.10.0 @ 36e30a6f — same pin as
apps/ios/Package.resolved. There is no Xcode here, so the Swift sources were exercised through a scratch SwiftPM check harness (same approach as the original PR run, like the repo's ownTools/*mirror packages): it mirrors the production sources unmodified (LearningService.swift,ConfidenceRouter.swift,ScanContracts.swift,Detection.swift,Migrations.swift, plusScanBenchmarkModels.swiftfor theScanRequestFailuretypealias) under a module namedFridgeLuck, with a two-type CoreGraphics shim (CGImage,CGFloat— Foundation on Linux already provides CGRect/CGPoint/CGSize) and the two new test files.swift format lint --strict --configuration .swift-formaton the three changed files → clean (afterfe6a8e6).swift test -j 4 -Xswiftc -DSQLITE_DISABLE_SNAPSHOTon the merged head, before and afterfe6a8e6→Executed 25 tests, with 0 failures (0 unexpected)(13 LearningServiceTests + 12 ConfidenceRouterTests).LearningService.swift(blobafa86dfcfrom 3e6d321) →Executed 25 tests, with 5 failures— 3× whitespace normalization (testCorrectionTrimsWhitespace,testWhitespaceAndCaseAcrossNewInstance) and 2× tie-ordering (testMixedTargetCorrectionsDoNotAutoCorrect,testNewInstanceKeepsMostRecentSuggestionOnCountTie), matching the original failing-first evidence; restored the fixed file → 25/25 again. The tests fail without the fix.git diff --name-only origin/alpha HEADafter the merge → exactly the three PR files, confirming the port introduces nothing else.What is not verified
FridgeLuckTestsXcode target. Hosted CI on this head fe6a8e6 (run 38757069606) is green: build-and-test pass (6m54s), dead-code-advisory pass (1m50s); CodeRabbit skipped (bot user not eligible).apps/iosSwiftPM package (AppModuleTests) does not compile on Linux (39 test files@testable import FridgeLuck, a module SwiftPM does not provide) — pre-existing and untouched by this PR.Assumptions
alpha; the original base branchfix/scan-failure-reportwas not touched, and the PR stays a draft.origin/alphainto the branch (preserving the five original commits, fast-forward push, no force-push) is an acceptable port; the zero-overlap check and the three-file diff against alpha are the evidence.🔗 Obvious Project · 🧵 Obvious Thread · 🔀 Obvious PR Artifact