7.5 KiB
7.5 KiB
Session Knowledge — 2026-07-15
Goal
Debug why Celery batch API results are not displaying on the client UI and fix the full pipeline: server startup, worker task registration, Triton endpoint routing, polling storm, stale result re-submission.
Constraints & Preferences
- Client should not hammer backend with polls; need request coalescing and caching.
- Already-completed batch results should not be re-submitted or re-queried on every page view.
- Worker must target Modal Triton endpoint, not localhost.
Progress
Done
- Fixed
GroupResult.restore()returningNoneby addingresult.save()afterapply_async()insubmit_celery_batch(). - Fixed server startup
ModuleNotFoundError: No module named 'backend'by correctingCODEBASE_ROOTpath math inbackend/routers/run_cv_inference.sh(changedSCRIPT_DIR/..→SCRIPT_DIR/../..). - Added
celery_app.autodiscover_tasks(["backend.implementation.tasks"])tobackend/services/celery_app.pyso worker registersrun_cv_chunk. - Added
export TRITON_ENDPOINT=...modal.runtobackend/start_workers.shso worker targets Modal instead oflocalhost:8000. - Added server-side TTL poll cache (
_batch_poll_cache) inbackend/services/cv_celery_service.pywith default 2000ms TTL to coalesce rapid repeat polls. - Increased client poll interval from 1000ms → 2000ms and removed unused
pollIntervalMsparameter fromgetCvAnalyzeResultsForProfileCelery()infrontend/implementation/src/lib/cvAnalyzeApi.ts. - Fixed poll endpoint HTTP status semantics:
GET /api/test/analyze/batch/celery/{job_id}now returns202 Acceptedfor pending,404 Not Foundfor unknown,200 OKfor completed/failed. This removes the misleading-200 problem for in-flight jobs. - Added backend timing logs in
cv_celery_service.py: submission logs chunk/image counts; completion/failure logsduration_msfrom submission to terminal state. - Added frontend timing logs in
getCvAnalyzeResultsForProfileCelery()for completed/failed/unknown outcomes. - Migrated frontend config from
.env/.env.developmentto single YAML source of truth atconfig/frontend.config.yaml, loaded viajs-yamlinvite.config.tsusing Vitedefine. Removed old.envfiles. AddedVITE_MODAL_OLLAMA_TARGETto YAML so proxy target is config-driven. - Fixed TypeScript errors in
vite.config.tsby adding"types": ["node"]and includingvite.config.tsintsconfig.json. - Added client-side in-flight coalescing + completed-result cache in
getCvAnalyzeResultsForProfileCelery()so repeat page views don’t re-submit identical work.
In Progress
- Worker needs force-restart to pick up
autodiscover_tasks+TRITON_ENDPOINTchanges. - One submitted job reached
completed: 1/2but never finished — need worker restart + fresh batch test. - Client-side ETA estimation for pending batch jobs is planned but not yet implemented.
Blocked
- Worker process restart — old PID/log still active without the new fixes applied.
Key Decisions
- Used
result.save()because Celery does not auto-persistGroupResultmetadata to Redis. - Added
autodiscover_tasksinstead of manual imports because worker is launched via-A backend.services.celery_appand never importscv_tasks.pyotherwise. - Set worker
TRITON_ENDPOINTinstart_workers.shbecause worker is separate process that doesn’t runcv_inference_server.py’sos.environ.setdefault(). - Poll cache TTL set to 2000ms to match 2s client poll interval.
- Single YAML config replaces
.env+.env.developmentto eliminate precedence confusion. VITE_MODAL_OLLAMA_TARGETlives in YAML so proxy target is editable without touchingvite.config.tscode.
Next Steps
- Force-restart Celery worker (
kill -9stale PID, removecelery.pid, run./start_workers.sh start). - Verify worker log shows
backend.implementation.tasks.cv_tasks.run_cv_chunkunder[tasks]. - Submit fresh batch and confirm it transitions
pending→completedwith actual results. - Implement ETA estimation in backend poll response based on observed chunk throughput.
- Address client behavior that submits new jobs while previous jobs are still
pending(7+ concurrent jobs observed in logs).
Critical Context
- Latest server logs show 7+ concurrent jobs all stuck at
pendingwithcompleted: 0/2or1/2, plus new POST submissions every ~10s — indicating worker is not processing tasks. - Worker log still shows stale startup at
16:22:18with empty[tasks]; fixes incelery_app.pyandstart_workers.shhave not been loaded by running worker. - One job (
13fd014e) reachedcompleted: 1/2, progress: 0.5and stalled — second chunk likely failed or was never picked up. - Modal Triton endpoint:
https://dtj-tran--triton-s3-service-unified-triton-server.modal.run. - Redis broker/backend:
redis://localhost:6379/0. - Chunk size default: 4 frames per chunk (
CELERY_CHUNK_SIZE). cv_result_cache.pyalready exists with in-flight coalescing pattern; new batch poll cache follows same design.- Frontend not currently in Celery mode (
VITE_USE_CV_CELERY=falsein YAML). - Direct batch route still shows noisy fallback logs when Triton returns 502 on batched inference — fallback works, but should log at
infonotwarning.
Relevant Files
/Users/davestran/Downloads/vkist_internship/PILOT_PROJECT/workspace/sprint_1_2/CODEBASE/backend/services/cv_celery_service.py: Containssubmit_celery_batch()(fixed withresult.save()),get_celery_batch_result()(now with 2000ms TTL poll cache + timing logs), and poll cache constants./Users/davestran/Downloads/vkist_internship/PILOT_PROJECT/workspace/sprint_1_2/CODEBASE/backend/services/celery_app.py: Addedautodiscover_tasks(["backend.implementation.tasks"]); routescv_inference.run_chunktocv-inferencequeue./Users/davestran/Downloads/vkist_internship/PILOT_PROJECT/workspace/sprint_1_2/CODEBASE/backend/start_workers.sh: AddedTRITON_ENDPOINTexport so worker targets Modal./Users/davestran/Downloads/vkist_internship/PILOT_PROJECT/workspace/sprint_1_2/CODEBASE/backend/routers/run_cv_inference.sh: FixedCODEBASE_ROOTpath math (SCRIPT_DIR/../..) soPYTHONPATHresolvesbackendpackage./Users/davestran/Downloads/vkist_internship/PILOT_PROJECT/workspace/sprint_1_2/CODEBASE/backend/implementation/tasks/cv_tasks.py: Definesrun_cv_chunkCelery task./Users/davestran/Downloads/vkist_internship/PILOT_PROJECT/workspace/sprint_1_2/CODEBASE/backend/routers/cv_inference.py: Contains/api/test/analyze/batch/celeryendpoints. Poll endpoint now returns 202/404/200./Users/davestran/Downloads/vkist_internship/PILOT_PROJECT/workspace/sprint_1_2/CODEBASE/frontend/implementation/src/lib/cvAnalyzeApi.ts: Poll interval 2000ms; client-side cache + in-flight coalescing; timing logs./Users/davestran/Downloads/vkist_internship/PILOT_PROJECT/workspace/sprint_1_2/CODEBASE/frontend/implementation/src/hooks/useSegmentationOverlay.ts: CallsgetCvAnalyzeResultsForProfileCelery()./Users/davestran/Downloads/vkist_internship/PILOT_PROJECT/workspace/sprint_1_2/CODEBASE/frontend/implementation/config/frontend.config.yaml: Single source of truth for frontend feature flags and URLs./Users/davestran/Downloads/vkist_internship/PILOT_PROJECT/workspace/sprint_1_2/CODEBASE/frontend/implementation/vite.config.ts: Loads YAML config and injects asimport.meta.env.*./Users/davestran/Downloads/vkist_internship/PILOT_PROJECT/workspace/sprint_1_2/CODEBASE/frontend/implementation/tsconfig.json: Added"types": ["node"]and includedvite.config.ts.