Skip to content

Backend robustness fixes + module/component refactors (from a code review)#1307

Open
SandeepSubba wants to merge 3 commits into
CyberTimon:mainfrom
SandeepSubba:code-analysis-fixes
Open

Backend robustness fixes + module/component refactors (from a code review)#1307
SandeepSubba wants to merge 3 commits into
CyberTimon:mainfrom
SandeepSubba:code-analysis-fixes

Conversation

@SandeepSubba

Copy link
Copy Markdown

This branch came out of a code-analysis pass over RapidRAW. Three commits,
each scoped to one concern.

1. Backend correctness & robustness (fix:)

  • Stale-cache fix (the notable one): calculate_transform_hash hashed
    each AI patch by base64 string length instead of content, so two
    different patch results of identical dimensions could collide and leave
    the old patch composited. Now hashes the actual content.
  • AI model output validation: the SAM decoder, sky-seg, U-2-Netp,
    Depth-Anything, and LaMa paths indexed model output assuming an exact
    tensor shape and .unwrap()-ed. A model whose output resolution differs
    now returns a clean error instead of panicking.
  • Export guards: bounds-check the frontend mask_index; guard
    calculate_resize_target against zero-dimension images (was Inf/NaN).
  • lut_cache cap: it was keyed by path and never cleared by the
    session/image resets, so it grew unbounded — now capped at 32 entries.

2. Extract SettingsPanel widgets (refactor:)

Move 7 self-contained presentational components into
components/panel/settings/widgets.tsx. SettingsPanel.tsx 2415 → 2032 lines.

3. Split two oversized Rust files (refactor:)

Peel cohesive clusters into submodules (use super::* + pub use, so the
command paths in lib.rs are unchanged):

  • file_management/albums.rs, file_management/folder_tree.rs
  • image_processing/analysis.rs

file_management.rs 3661 → 3135, image_processing.rs 3262 → 2555.

Verification

  • cargo check — clean (no errors/warnings).
  • npm run typecheck — clean.

These are deliberately small, self-contained changes; happy to split into
separate PRs or adjust anything if it doesn't fit your direction.

SandeepSubba and others added 3 commits June 26, 2026 10:39
- cache_utils: hash full AI-patch base64 content instead of string length
  in calculate_transform_hash, so two distinct patch results of identical
  dimensions can no longer collide and leave a stale patch composited.
- ai_processing: validate AI model output tensor shapes before indexing
  (SAM decoder, sky-seg, U-2-Netp, Depth-Anything, LaMa). A model whose
  output resolution differs from the hardcoded assumption now returns a
  clean error instead of panicking on out-of-bounds access.
- export_processing: bounds-check the frontend-supplied mask_index and
  guard calculate_resize_target against zero-dimension images (was Inf/NaN).
- lib: cap lut_cache at 32 entries; it is keyed by path and never cleared
  by the session/image cache resets, so it previously grew unbounded.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Move the seven self-contained widget components (KeybindRow, SettingItem,
DataActionItem, AiProviderSwitch, CloudDashboard, CanvasInputModeSwitch,
PreviewModeSwitch) into src/components/panel/settings/widgets.tsx and prune
the now-dead imports. These widgets touch no parent state, so the cut is
mechanical. SettingsPanel.tsx drops from ~2415 to ~2032 lines.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Peel cohesive clusters out of two oversized Rust files into sibling
submodules, each using `use super::*` to inherit the parent's imports and
re-exported via `pub use` so the existing command paths in lib.rs are
unchanged:

- file_management/albums.rs    (AlbumItem + album commands, ~260 lines)
- file_management/folder_tree.rs (FolderNode + lazy dir scanning, ~270 lines)
- image_processing/analysis.rs  (histogram/waveform/auto-adjust, ~710 lines)

file_management.rs 3661 -> 3135, image_processing.rs 3262 -> 2555.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant