Youssef Jedidi
← All work

CFIA AI Lab · Software & AI Infrastructure Intern · since May 2026

Auth and ML infrastructure for Nachet, the CFIA’s seed-identification app

Nachet is the CFIA AI Lab’s public app for identifying seeds from photos. Everything below is merged and, apart from the taxonomy study, public.

Role
Software & AI Infrastructure Intern
Team
AI Lab, Data Analytics & Artificial Intelligence Solutions
Stack
React · FastAPI · Argo · Kubernetes
Code
nachet, howard-on-prem
Sections
Sign-in, Training, Data prep, WebGPU, Signing, Taxonomy
Public Nachet Mini interface shown as product context

Nachet Mini, from the project’s public documentation.

List all 85 pull requests

Authentication 9

Training and release 36

Data preparation 21

Browser app 5

Platform and CI 14

Authentication9Read this part
Training and release36Read this part
Data preparation21Read this part
Browser app5Read this part
Platform and CI14Read this part
Figure 1. Where the 85 public pull requests went. One dot per merged PR. Hover a dot to read it, click to open it on GitHub, or click a workstream to jump to it.

01 · June–July

Sign-in behind one interface

Sign-in was hard-wired to Microsoft in both the frontend and the backend. I moved it behind one interface, with Microsoft Entra still the default.

BEFOREevery call site imports MSAL directlyAFTERcall sites only know one auth layeruseDeviceDatauseFolderDatauseSpeciesDatauseWorkflowPollingWorkflowQueueManagerNavbarAuthPopupand moreNachet auth layerNachetAuthProvider+ API auth bridge#827 #836 #841 #846build timeOIDC adapterAnother OIDC providerKeycloak, tested locallyMSALMicrosoft’s browser SDKMSAL adapterMicrosoft Entra IDthe only optiondefault, unchanged

After: one auth layer

Call sites only talk to Nachet’s auth layer. It starts the MSAL or OIDC adapter chosen at build time, so a new provider means a new adapter, not edits across the app.

#827#836#841#846

Figure 2. How React stopped calling MSAL directly. The call-site migration (#846) took MSAL out of the hooks, components and services. A new provider is now one more adapter.
FRONTEND · REACTBACKEND · FASTAPIEXTERNALCall siteshooks · componentsAPI auth bridgeAxios interceptorNachet APItoken verifierKey cachediscovery + JWKSIdentity providerEntra or Keycloak1Sign in through the build-time adapter #827 #836access token, kept in the auth provider2Protected API call #846no token code in call sites3Request + bearer token #841only on protected Nachet routes4Key for the token’s kid #849Unknown kid: refetchrate-limited · HTTPS onlykey set, cached 24 hsigning key5Check signature, algorithm, issuer, #848audience, expiry, not-before, claimsONE OF THREE OUTCOMES401 · invalid or expiredrefresh, retry oncethen stop #841403 scope missing · 503 keys unreachable #851returned directly, not retried200 · mapped to the existing User model #851

Overview

Every protected request passes steps 1 to 5, then ends one of three ways. It follows one request through; pick a step or an outcome to stop on it.

  1. Sign in

    adapter chosen at build time

  2. Call the API

    no token code in call sites

  3. Attach the token

    protected routes only

  4. Find the signing key

    by kid, cached 24 h

  5. Verify before any route runs

    signature, issuer, audience, expiry, claims

  6. One of three outcomes

    401Token rejected

    refresh, retry once

  7. 403 · 503Refused, not retried

    missing scope, or keys unreachable

  8. 200Accepted

    existing User object

Figure 3. How the API checks a request, and what happens when it can’t. Steps 1 to 5 run on every protected request; each request then ends one of three ways. The figure plays through one; tags link the pull requests that added each part.

Fail closed. If the server can’t reach the provider’s keys, it answers 503. It never accepts a token it couldn’t check.

Tested with Entra and with a local Keycloak; production rollout isn’t covered here.

02 · August–November

Training and release as reviewed Argo workflows

I moved training and release into Argo workflows. Each run pauses for a person to pick checkpoints, choose a release and approve the upload to Hugging Face. A first GPU test run has finished on the cluster; full training runs are next.

TRAINING WORKFLOWnachet-detector-trainer · nachet-classifier-trainertrainer images signed with Cosign in CI#901 #913Train on a GPU nodeRT-DETR detector or Swin classifiereach attempt is an MLflow child runand resumes from the last checkpoint#899 #903 #914 #915full training runs · fresh-pod resumeReview checkpointsthe run pauses; a personpicks 1–3 checkpoints,and their files are checked#903 #908 #914External evaluationoptional, off by defaultreports for each pickedcheckpoint go to MLflow#918 #919 #920Choose a releaseone reviewed checkpoint,or none: the run endsand nothing is released#944writes each checkpointpicking an archivedcheckpoint restores it#1062reportschosencheckpointShared workspaceCephFS volume for trainingfiles, checkpoints, exportshoward #453 #933MLflowruns, archived checkpoints,evaluation and release results#915 #943 #1062 #1098To the release workflowexport, parity check, optionalINT8, upload approvalupload checkpointif the upload failsit is retried first, and thefile stays on the workspaceuntil it lands #1098a person decidesnot yet done on the cluster
  1. Train on a GPU node · resumes from the last checkpoint

    Upload fails: retried first; the checkpoint stays on the workspace until it lands.

  2. Review checkpoints · a person picks 1–3; archived ones are restored from MLflow
  3. External evaluation · optional, off by default
  4. Choose a release · one reviewed checkpoint, or none: nothing is released
Figure 4. A failed upload no longer costs the only checkpoint, and a person picks what moves on. Built and tested locally, then a first GPU test run on the cluster; dashed rings mark what is still to do there.

Export has to match. Before anything is published, the exported detector must find the same boxes as the original model.

RELEASE WORKFLOWnachet-model-release#943 #947starts from the checkpoint chosen in trainingExport on CPUPyTorch → ONNX FP32opset 16#926 #931 #933Detector paritysame pixels, boxes matched 1:1IoU ≥ 0.99confidence gap ≤ 1e-4#1063INT8 + browser filesoptional AVX512 INT8FP16 Swin for thebrowser heat map (CAM)#926Evaluate ONNXFP32 on CUDAINT8 on CPU#938 #939 #941 #942Approve, then uploadthe run pauses again;a reviewed model cardmust be in the inputs#943 #944checkpoint in,ONNX files outmismatch: failed parity report;the run stops before INT8logged to the training runHub tokenopens a Hubpull requestShared workspaceCephFS, as in trainingMLflowthe training runVaultMLflow S3 and Hub secrets;the Hub token reachesonly the upload podhoward #454 #943Hugging Face Hubcheckpoint + ONNX files;no training state#934first releasea person decidesnot yet done on the cluster
  1. Export on CPU · PyTorch → ONNX FP32
  2. Detector parity · IoU ≥ 0.99 against PyTorch

    Mismatch: the run stops before INT8.

  3. INT8 + browser files · optional
  4. Evaluate ONNX · results logged to MLflow
  5. Approve, then upload · needs a reviewed model card; opens a Hub pull request
Figure 5. A model reaches Hugging Face only if its export matches PyTorch and a person approves the upload. The parity check covers the detector. No model has been released to the Hub yet.

03 · November

Preparing seed images for review

One Argo workflow converts raw seed photos, pre-labels them with SAM 3 and loads them into FiftyOne, which I deployed on the cluster, for people to review.

IMAGE PIXELSeach PNG is written to S3 once; everything after reads that fileRaw originalsTIFF and JPEG incold Ceph S3,never changed#1056 howard #470ConvertCPUTIFF or JPEG → PNG,16-bit depth kept#964 #986 #994 #1059Prepared PNGsback in S3, own prefix,each named by its SHA-256no copyRead-only S3 mountthe same PNGs, readthrough an s3fs sidecar;the app is unprivilegedhoward #445 howard #461LABELSCOCO JSON, then database recordssaved afterall uploadsCOCO indexthe only files in theshared working folder;no image is staged on diskreads PNGs,checks hashesSAM 3 pre-labelGPUdraft COCO boxes + confidenceinvalid boxes flagged#966 #987 #1055registerMongoDBa new dataset: boxes,scores, file paths;no images#967FiftyOnereviewers check eachSAM 3 box and itsconfidence in thebrowserhoward #432howard #439One Argo workflow runs the three steps; credentials come from Secrets.#988 #989 howard #460

Pixels

Raw originals TIFF, JPEG in cold S3

Convert on CPU hash-named PNGs in S3

Read-only S3 mount the same PNGs, no copy

Labels

COCO index saved by Convert

SAM 3 on GPU draft boxes + confidence

MongoDB registered; no images

FiftyOne · reviewers check each SAM 3 box

Figure 6. Pixels and labels reach FiftyOne by separate paths, so the images are never copied. A local Docker rehearsal covered conversion, registration and the browser view (#1059); the pipeline has since run on the cluster.Rehearsed locally in Docker, then run on the cluster.

04 · May, November

Checking WebGPU before switching

In-browser detection was stuck on slow WASM because WebGPU returned wrong boxes. I traced it to an upstream bug, picked up the fix, checked that both backends agree, and switched.

BEFOREDetector always on WASMdetectorDevice = "wasm"code comment: “WebGPU has precision issues”ROOT CAUSE#1000ONNX Runtime ScatterND bugwrong WebGPU boxes, reproducedwith the dependencies pinned thenfixed upstream, picked up in #923MEDIAN DETECTOR INFERENCE PER IMAGE · LOCAL TESTWASM≈2.6 sWebGPU164 msdetections matchedon both backends, for four seed photosAFTER · FALLBACK RULE#1003Load on WebGPUif the model prefers it and the device has it;now the default for both RT-DETR modelsnot usable, or the load throwsthe error is loggedLoad once on WASMsame settings as beforeif that fails toothe error is returned, not retried

Median detector inference per image · local test

WASM≈2.6 sWebGPU164 ms

Detections matched on both backends, for four seed photos.

Fallback: if WebGPU is unusable or the load throws, load once on WASM; if that fails too, return the error.

Figure 7. Once both backends matched, WebGPU cut median detector time from about 2.6 s to 164 ms. A local test on four seed photos; WASM stays as the fallback.

05 · May–November

Why a signed image was still rejected

The cluster only runs signed images, so I added signing to CI. The signed image was still rejected: a hand-made trust policy didn’t match the signer, so I moved it into GitOps.

REJECTED AT ADMISSIONCAUSEFIX1“no signatures found”Argo CD couldn’t roll outthe backendImage never signedthe deployed 2.4.0 backendimage had no signatureSign every build in CI, then deploy signed tagsboth build workflows sign each image keylessly with Cosign v2.2.3 through GitHub OIDC,verify the signature, and push image and signature to GHCR;staging and production then point at a signed release#810 howard #435 howard #4362identity mismatchthe signed image wasrejected tooPolicy set up by handoutside GitOps; it didn’tmatch the new signing identityMove the policy into GitOpsa ClusterImagePolicy, checkedby the policy-controllerbefore a pod startshoward #437applies toglob: "**" (every image)authoritykeyless · Fulcio + RekorissuerGitHub Actions OIDCsubjectmatches the ai-cfia orgThese changes merged; I didn’t record the admission itself.
RejectedFix
“no signatures found” image never signedSign each build in CI with keyless Cosign; deploy signed tags
identity mismatch hand-made policy didn’t match the signerMove the policy into GitOps, trusting ai-cfia’s GitHub Actions

These changes merged; I didn’t record the admission itself.

Figure 8. Signing the image fixed the first rejection; the trust policy still had to match the signer. The policy admits only images signed with Cosign by the organization’s GitHub Actions.

06 · August

Separate family and genus models?

I compared training separate family and genus models with simply mapping the existing species prediction up the taxonomy.

LevelMethodAccuracyBalancedMacro F1
FamilySeparate probe0.98960.96770.9716
Map species → family0.99150.96970.9736
GenusSeparate probe0.98650.98550.9836
Map species → genus0.98670.98570.9840

Mapping did as well or slightly better, so I recommended against adding a second model.

Measured on the validation split; family-specific species heads weren’t tested. The study’s repository is private.

Links