Skip to content

fix: resolve type hint mismatch in deduplicator and broaden embedder exceptions (#259)#279

Open
prasiddhi-105 wants to merge 2 commits into
ionfwsrijan:mainfrom
prasiddhi-105:fix/patchpilot-dedup-type-mismatch-259
Open

fix: resolve type hint mismatch in deduplicator and broaden embedder exceptions (#259)#279
prasiddhi-105 wants to merge 2 commits into
ionfwsrijan:mainfrom
prasiddhi-105:fix/patchpilot-dedup-type-mismatch-259

Conversation

@prasiddhi-105

Copy link
Copy Markdown

Linked issue

Closes #259

What this PR does

Resolves a type system mismatch between the main scan workflow engine and the machine learning deduplication / embedding logic. Previously, type hints on the deduplicator signature led to a silent failure where Pydantic Finding objects were being processed with dictionary-style getattr() defaults, resulting in zero-information empty text embeddings. This PR introduces a robust runtime instance-based type extractor, fixes the functional type hints, adds a type assertion guard inside the scanning controller loop, and broadens initialization exception wrappers for SentenceTransformer to protect the server boot process from third-party runtime failures (e.g., PyTorch out-of-memory or HuggingFace timeouts).

Type of change

  • Bug fix
  • New feature
  • ML model / training pipeline
  • Refactor (no behaviour change)
  • Documentation
  • Tests only

ML tier (if applicable)

  • Tier 1 — Triage
  • Tier 2 — Predictive
  • Tier 3 — Autonomous
  • Not ML-related

Stack affected

  • Backend
  • Frontend
  • Both

Changes

Backend

  • backend/app/ml/deduplicator.py: Upgraded data type signatures and annotations to explicitly accept structural collections of Union[Finding, Dict[str, Any]].
  • backend/app/ml/embedder.py: Introduced a localized polymorph conditional parser _extract_text to handle extraction paths natively using string parsing via .get() for raw dictionaries or getattr() for model properties.
  • backend/app/ml/embedder.py: Widen the initialization block check statement from except ImportError to except Exception to capture connection drops or memory faults gracefully.
  • backend/app/main.py: Deployed a clear static type check assertion boundary condition wrapper on the engine array loop directly before calculating cosine similarity.

Frontend

  • No frontend changes.

New dependencies

  • None.

Database / schema changes

  • None.

Testing

How did you test this?

  • Validated code layout alignment against python syntax trees locally.
  • Verified parsing function capabilities by running tests using standard dictionaries and live Pydantic models.
  • Mocked initialization dependency faults to check that the network loading layer correctly outputs a system warning instead of completely crashing the engine startup loop.

Checklist

  • Tested locally end-to-end (upload ZIP or GitHub URL → scan → findings returned correctly)
  • New ML model falls back gracefully when model file is absent
  • No new console.error or unhandled Python exceptions introduced
  • Added or updated tests where applicable
  • requirements.txt / package.json updated if new dependencies added
  • New model files (.pkl, .pt, etc.) are gitignored, not committed

Anything reviewers should focus on

Please check the structural implementation of the new private helper _extract_text within embedder.py to ensure it seamlessly toggles between dictionary-like and object-like item evaluations without degrading execution processing loops during full scan passes.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

🎉 Thank you @prasiddhi-105 for submitting a Pull Request!

We're excited to review your contribution.

Before Review

✅ Ensure all CI checks pass
✅ Complete the PR template
✅ Link the related issue

Want faster reviews and contributor support?

Join our Discord community:

🔗 https://discord.gg/FcXuyw2Rs

Maintainers and mentors are active there and can help resolve blockers quickly.

Happy Contributing! 🚀

@github-actions github-actions Bot added backend Backend issues bug Something isn't working frontend Frontend issues ml ML related issues SSoC26 labels Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

PR template check passed!

@arpit2006 this PR is ready for your review. 🚀

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

PR template check passed!

@arpit2006 this PR is ready for your review. 🚀

@arpit2006 arpit2006 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prasiddhi-105 , Resolve CI fails!

@arpit2006

Copy link
Copy Markdown
Collaborator

@prasiddhi-105 , Any Update.

@prasiddhi-105

Copy link
Copy Markdown
Author

@prasiddhi-105 , Any Update.

Yeah on it, I'll give u an update tomorrow morning, please do consider !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deduplication executes on empty embeddings due to Pydantic/dict type mismatch - all deduplication meaningless

2 participants