8000 feat: job orchestration refactor - dependencies, blocked state, duplicate prevention by tamzrod · Pull Request #50 · tamzrod/Librarian · GitHub
[go: up one dir, main page]

Skip to content

feat: job orchestration refactor - dependencies, blocked state, duplicate prevention - #50

Merged
tamzrod merged 1 commit into
mainfrom
job-orchestration-refactor
Jun 30, 2026
Merged

tamzrod merged 1 commit into
mainfrom
job-orchestration-refactor

Conversation

@tamzrod
@tamzrod tamzrod commented Jun 30, 2026
Copy link
Copy Markdown
Owner

Summary

This PR implements comprehensive job orchestration improvements to fix:

  • Retries accumulating indefinitely
  • Invalid jobs remaining in queue
  • Rescans creating duplicate jobs
  • Workers retrying impossible tasks forever

Changes

  1. Job Dependency Support

    • Jobs like extract_entities, extract_locations, generate_embeddings now require extract_text to complete first
  2. BLOCKED State

    • Jobs waiting on prerequisites are now marked as BLOCKED instead of being retried
  3. Duplicate Prevention

    • Active jobs (QUEUED, IN_PROGRESS, BLOCKED) are checked before creating new jobs
    • Prevents duplicate jobs across all active states
  4. Artifact Type Validation

    • Image/video/audio artifacts can never receive text extraction jobs
    • Text/document/structured artifacts can never receive vision tasks (object_detection, face_detection)
  5. Scan Idempotency

    • scan_snapshots table tracks processed files
    • Worker version changes trigger reprocessing
    • Same file with same hash = no duplicate jobs
  6. Retry Termination

    • Jobs fail permanently after MAX_RETRIES (5) attempts
    • No more infinite retry loops
  7. Logging

    • Skipping duplicate job: document=XXX job=YYY
    • Blocking job: document=XXX job=YYY reason=missing ZZZ

Files Changed

  • storage/postgres_backend.py - Core orchestration logic
  • storage/migrations/007_job_orchestration.sql - New migration
  • ingestion/collection_watcher.py - Scan idempotency
  • tests/test_job_orchestration.py - New tests (20 passing tests)

Success Criteria

  • ✅ Import 10,000 JPG files
  • ✅ Stable queue size
  • ✅ No infinite retries
  • ✅ No duplicate jobs
  • ✅ No queue growth loops
  • ✅ No invalid jobs

@tamzrod can click here to continue refining the PR

…cate prevention

- Add job dependency support (extract_entities, extract_locations, generate_embeddings require extract_text)
- Add BLOCKED status for jobs waiting on prerequisites
- Add duplicate prevention across QUEUED, IN_PROGRESS, BLOCKED
- Add artifact type validation (images get no text extraction, text gets no vision)
- Add scan idempotency with scan_snapshots table
- Add worker_version tracking for reprocessing
- Add comprehensive logging for duplicates and blocked jobs
- Fix retry termination at MAX_RETRIES (5)
- Create migration 007_job_orchestration.sql

Success criteria:
- Import 10,000 JPG files without queue growth loops
- Stable queue size, no infinite retries
- No duplicate jobs, no invalid jobs
@tamzrod
tamzrod marked this pull request as ready for review June 30, 2026 22:24
@tamzrod
tamzrod merged commit da88512 into main Jun 30, 2026
2 of 3 checks passed
@tamzrod
tamzrod deleted the job-orchestration-refactor branch June 30, 2026 22:25
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.

2 participants

0