Validate select fields before model loading to prevent cryptic crashes - #168
Merged
Merged
Conversation
A production sam_fewshot_segmentation job received '"Model": null' in its saved tool config (a select field stores whatever was serialized when the tool was saved, defaults notwithstanding), built the checkpoint path '/None.pth' from it, and died with FileNotFoundError deep inside SAM's model loader — after "Loading model" was already reported and with no hint that the model selection was the problem. Add annotation_tools.get_required_select(value, field_name, allowed_values) which raises ValueError on null/empty/non-string select values and, when given the valid options, on stale names from configs saved against older worker images. Callers catch it and sendError so the user learns to re-select the field and save the tool. Missing values are rejected rather than silently replaced with the interface default, since substituting a model changes the output. Sweep every worker that builds a model/checkpoint from a select value: - sam_fewshot_segmentation: validate against the static model list and check the checkpoint file exists, before the heavy torch/SAM imports so the job fails fast instead of after GPU setup. - sam2_automatic_mask_generator, sam2_fewshot_segmentation, sam2_propagate, sam2_refine, sam2_video: hoist the copy-pasted model->config mapping to a MODEL_TO_CFG module constant, validate the selection against it (a null or stale name previously crashed with KeyError), and check checkpoint existence before build_sam2. - stardist: validate against the static pretrained-model list. - cellpose, cellposesam, piscis predict/train, cellpose_train, cellposesam_train: shape-validate only (custom models come from Girder, so there is no static option list), matching each worker's local sendError convention. sam_automatic_mask_generator reads Model but never uses it, so it is left alone. condensatenet already falls back safely via MODEL_PATHS.get(). Regression coverage: annotation_utilities/tests/test_required_select.py (runs in CI) plus compute-level tests in sam_fewshot_segmentation and sam2_fewshot_segmentation reproducing the production params. Document the pitfall in CLAUDE.md and the nimbus-worker-hardening catalog. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FFwLaqzmDWDnPuZvF6EL6m
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 325145ae90
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Address the Codex review on PR #168: the model-selection hardening changed observable behavior in thirteen workers without touching their hand-maintained docs. - Add a "Model selection validation" section to all twelve affected worker docs (the shared PISCIS.md covers both predict and train), describing why null/stale select values are rejected, the sendError the user sees, and the remediation (re-select the model and save the tool). The wording is tailored per family: SAM1/SAM2 workers also verify checkpoint existence, stardist validates against its static list, and the cellpose/piscis family shape-validates only since custom models come from Girder. - Add an explicit convention to CLAUDE.md and AGENTS.md: documentation updates ship with the change — any PR changing a worker's interface, behavior, outputs, or error handling must update the affected WORKERNAME.md in the same PR (the automated doc hooks are disabled, so this is a manual step). - Sync the select-pitfall section into AGENTS.md, which mirrors CLAUDE.md but had not received it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FFwLaqzmDWDnPuZvF6EL6m
Resolved the nimbus-worker-hardening SKILL.md conflict: both sides appended a new catalog entry numbered 7. Kept master's groupby-on-empty-DataFrame entry as #7 and renumbered the select-validation entry to #8. Mirrored #8 into the .agents copy, which this branch had not updated. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Browser-testing the model-selection validation against a real dataset turned up a regression in the seven sam*/stardist workers: sendError only prints a JSON line for the frontend to render, it does not fail the job. Returning after it left the job exit code 0, so Girder recorded a misconfigured run as SUCCESS. Verified end to end on sam2_refine with a saved config holding 'Model': null: old image job ERROR 'Job Failed, see the log' + KeyError: None new image, return job SUCCESS clear error banner, wrong status new image, raise job ERROR clear error banner, correct status A run that reports success but did nothing is worse than a crash, because nobody goes looking for it. The cellpose/piscis workers already re-raised; this brings the sam*/stardist workers in line. The checkpoint-missing guard raises FileNotFoundError for the same reason. Only the sites this branch added are changed; the pre-existing sendError+return paths (no training tag, no training annotations) are left alone. Tests updated to assert the raise, and docs/CLAUDE.md/AGENTS.md/skill catalog updated to record why return is wrong here. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
arjunrajlab
force-pushed
the
claude/docker-network-resolution-tnfkan
branch
from
August 7, 2026 14:37
5af23c4 to
820bb22
Compare
arjunrajlab
added a commit
that referenced
this pull request
Aug 7, 2026
Resolves three conflicts between this branch's dataset-aware `all` batch parsing and master's batch-coordinate validation (#165) / select-field validation (#168). worker_client.py: master added `_parse_batch_values`, which reported malformed Batch input with sendError before the clients were built. This branch needs the dataset's IndexRange to expand `all`, so parsing has to happen after datasetClient exists. Folded master's per-field error message into the shared `get_batch_ranges()` so it raises a ValueError naming the offending field, and WorkerClient catches it, sends the banner, and re-raises. `_parse_batch_values` is gone; the direct SAM batching loops now inherit the clear message too, which they never had. CELLPOSESAM.md / CROP.md: kept master's more precise wording (1-indexed, empty-selection error, size-one dimension note) and added this branch's `all` documentation alongside it rather than replacing either. Also mirrored the branch's skill updates into .claude/skills/, which it had only applied to .agents/, and fixed the duplicate "### 7" the textual auto-merge produced in the hardening catalog. Corrected the stale sweep counts there (claimed ~6 WorkerClient / ~26 direct; actually 43 / 10). Added two regression tests for the merged behavior: get_batch_ranges names the field that failed to parse, and returns re-iterable lists rather than one-shot generators. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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
Adds validation for
selectinterface fields (particularly model selections) before they are used in model loading or checkpoint path construction. This prevents cryptic crashes deep inside model loaders when a saved tool config holdsnullor a stale model name.Problem
A production
sam_fewshot_segmentationjob crashed withFileNotFoundError: [Errno 2] No such file or directory: '/None.pth'because the saved tool config held"Model": null. The null value was silently used to build the checkpoint path, and the job died deep inside SAM's model loader with no indication that the model selection was the problem.Additionally, configs saved against older worker images can name model checkpoints that no longer exist in the current image, leading to similar downstream failures.
Solution
New utility function
annotation_tools.get_required_select()validates that a select field value is:Noneor empty/whitespaceRaises
ValueErrorwith a clear message directing users to re-select the field.Early validation in compute() functions across all affected workers:
sendError()with a clear message on validation failureAffected workers:
sam_fewshot_segmentation: validates againstMODELSlistsam2_fewshot_segmentation,sam2_automatic_mask_generator,sam2_propagate,sam2_video,sam2_refine: validate againstMODEL_TO_CFGmappingstardist: validates againstMODELSlistcellpose,cellposesam,piscis(predict/train),cellpose_train,cellposesam_train: validate model selections (some without static allowed values for custom models)Key Changes
annotation_utilities/annotation_tools.py: Addedget_required_select()function with comprehensive validation and user-friendly error messagesannotation_utilities/tests/test_required_select.py: New test file with 14 regression tests covering valid values, missing values, wrong types, and stale valuesget_required_select()MODELSorMODEL_TO_CFGconstantsendError()on any validation failureCLAUDE.mdand.claude/skills/nimbus-worker-hardening/SKILL.md: Updated with guidance on the pitfall and the fix patternTestComputeModelValidationclasses tosam_fewshot_segmentationandsam2_fewshot_segmentationtest suitesImplementation Details
allowed_valueslist exists for thosehttps://claude.ai/code/session_01FFwLaqzmDWDnPuZvF6EL6m