Skip to content

Add durable background jobs for memory and scanner work#180

Open
massy-o wants to merge 2 commits into
XortexAI:mainfrom
massy-o:durable-memory-jobs
Open

Add durable background jobs for memory and scanner work#180
massy-o wants to merge 2 commits into
XortexAI:mainfrom
massy-o:durable-memory-jobs

Conversation

@massy-o
Copy link
Copy Markdown

@massy-o massy-o commented May 14, 2026

Refs #162

Summary

  • add a MongoDB-backed durable job queue with idempotency keys, retries, timeouts, stale lease recovery, and dead-letter records
  • enqueue /v1/memory/ingest and /v1/memory/batch-ingest work and expose /v1/jobs/{job_id} for job status/results
  • route scanner start/resume work through the durable queue while preserving the existing scanner job/status records and falling back to in-process tasks if the job store is unavailable
  • add job worker settings for polling, timeout, retry, backoff, and lease duration

This is a focused Phase 1 implementation for the task-queue/status foundation described in the issue discussion.

Validation

  • python3 -m py_compile src/jobs.py src/api/routes/jobs.py src/api/routes/memory.py src/api/routes/scanner.py src/api/app.py src/api/schemas.py
  • git diff --check
  • uv run --with pytest --with pytest-asyncio --with fastapi --with pydantic --with pydantic-settings --with python-jose --with pymongo --with httpx --with beautifulsoup4 pytest tests/api/test_dependencies_and_routes.py -q -> 4 passed

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a durable background job system using MongoDB to handle long-running tasks in the memory and scanner modules. It adds a new job status endpoint, a worker for asynchronous execution, and relevant configuration settings. The review feedback primarily highlights the need to offload synchronous database operations to worker threads using asyncio.to_thread to avoid blocking the FastAPI event loop. Additionally, improvements were suggested for the stability of idempotency keys, the completeness of dead-letter logs, and the refactoring of duplicated user identification logic.

Comment thread src/api/routes/jobs.py
Comment thread src/api/routes/jobs.py Outdated
Comment thread src/api/routes/memory.py Outdated
Comment thread src/api/routes/memory.py Outdated
Comment thread src/api/routes/scanner.py Outdated
Comment thread src/jobs.py
Comment thread src/jobs.py Outdated
Comment thread src/jobs.py Outdated
Comment thread src/api/routes/jobs.py Outdated
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.

1 participant