Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b60eab0
merge
carlos-irreverentlabs Jan 16, 2026
644927f
Merge remote-tracking branch 'upstream/main'
carlosgjs Jan 22, 2026
218f7aa
Merge remote-tracking branch 'upstream/main'
carlosgjs Feb 3, 2026
90da389
Merge remote-tracking branch 'upstream/main'
carlosgjs Feb 10, 2026
842e9b3
PSv2: Use connection pooling and retries for NATS
carlosgjs Feb 11, 2026
227a8db
Refactor and fix nats tests
carlosgjs Feb 11, 2026
2acf620
Tighten formatting
carlosgjs Feb 11, 2026
0632ce0
format
carlosgjs Feb 11, 2026
c5f8106
CR feedback
carlosgjs Feb 11, 2026
8805dbe
Apply suggestions from code review
carlosgjs Feb 11, 2026
8618d3c
Merge remote-tracking branch 'upstream/main'
carlosgjs Feb 13, 2026
c384199
refactor: simplify NATS connection handling — keep retry decorator, d…
mihow Feb 12, 2026
98a17f1
Merge branch 'main' into carlosg/natsconn
carlosgjs Feb 13, 2026
cf42506
revert: restore NATS connection pool — avoid per-operation connection…
mihow Feb 13, 2026
dc798ea
refactor: add switchable NATS connection strategies
mihow Feb 13, 2026
4d66c07
refactor: simplify NATS connection module — pool-only, archive original
mihow Feb 13, 2026
41bbeb3
docs: clarify where connection pool provides reuse vs. single-use
mihow Feb 13, 2026
ead53d1
fix: use `from None` to suppress noisy exception chain in _get_pool
mihow Feb 13, 2026
9737301
docs: update AGENTS.md test commands to use docker-compose.ci.yml
mihow Feb 13, 2026
fa0f84b
fix: correct mock setup in NATS task tests to match plain instantiation
mihow Feb 14, 2026
c7b2014
fix: address PR review feedback for NATS connection module
mihow Feb 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions .agents/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,34 @@ docker compose restart django celeryworker

### Backend (Django)

Run tests:
Run tests (use `docker-compose.ci.yml` to avoid conflicts with the local dev stack):
```bash
docker compose -f docker-compose.ci.yml run --rm django python manage.py test
```

Run a specific test module:
```bash
docker compose run --rm django python manage.py test
docker compose -f docker-compose.ci.yml run --rm django python manage.py test ami.ml.orchestration.tests.test_nats_connection
```

Run specific test pattern:
```bash
docker compose run --rm django python manage.py test -k pattern
docker compose -f docker-compose.ci.yml run --rm django python manage.py test -k pattern
```

Run tests with debugger on failure:
```bash
docker compose run --rm django python manage.py test -k pattern --failfast --pdb
docker compose -f docker-compose.ci.yml run --rm django python manage.py test -k pattern --failfast --pdb
```

Speed up test development (reuse database):
```bash
docker compose run --rm django python manage.py test --keepdb
docker compose -f docker-compose.ci.yml run --rm django python manage.py test --keepdb
```

Run pytest (alternative test runner):
```bash
docker compose run --rm django pytest --ds=config.settings.test --reuse-db
docker compose -f docker-compose.ci.yml run --rm django pytest --ds=config.settings.test --reuse-db
```

Django shell:
Expand Down Expand Up @@ -654,13 +659,13 @@ images = SourceImage.objects.annotate(det_count=Count('detections'))

```bash
# Run specific test class
docker compose run --rm django python manage.py test ami.main.tests.test_models.ProjectTestCase
docker compose -f docker-compose.ci.yml run --rm django python manage.py test ami.main.tests.test_models.ProjectTestCase

# Run specific test method
docker compose run --rm django python manage.py test ami.main.tests.test_models.ProjectTestCase.test_project_creation
docker compose -f docker-compose.ci.yml run --rm django python manage.py test ami.main.tests.test_models.ProjectTestCase.test_project_creation

# Run with pattern matching
docker compose run --rm django python manage.py test -k test_detection
docker compose -f docker-compose.ci.yml run --rm django python manage.py test -k test_detection
```

### Pre-commit Hooks
Expand Down
4 changes: 2 additions & 2 deletions ami/jobs/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def _ack_task_via_nats(reply_subject: str, job_logger: logging.Logger) -> None:
try:

async def ack_task():
async with TaskQueueManager() as manager:
return await manager.acknowledge_task(reply_subject)
manager = TaskQueueManager()
return await manager.acknowledge_task(reply_subject)

ack_success = async_to_sync(ack_task)()

Expand Down
4 changes: 1 addition & 3 deletions ami/jobs/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ def tearDown(self):

def _setup_mock_nats(self, mock_manager_class):
"""Helper to setup mock NATS manager."""
mock_manager = AsyncMock()
mock_manager = mock_manager_class.return_value
mock_manager.acknowledge_task = AsyncMock(return_value=True)
mock_manager_class.return_value.__aenter__.return_value = mock_manager
mock_manager_class.return_value.__aexit__.return_value = AsyncMock()
return mock_manager

def _create_error_result(self, image_id: str | None = None, error_msg: str = "Processing failed") -> dict:
Expand Down
10 changes: 5 additions & 5 deletions ami/jobs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ def tasks(self, request, pk=None):

async def get_tasks():
tasks = []
async with TaskQueueManager() as manager:
for _ in range(batch):
task = await manager.reserve_task(job.pk, timeout=0.1)
if task:
tasks.append(task.dict())
manager = TaskQueueManager()
for _ in range(batch):
task = await manager.reserve_task(job.pk, timeout=0.1)
if task:
tasks.append(task.dict())
return tasks

# Use async_to_sync to properly handle the async call
Expand Down
36 changes: 18 additions & 18 deletions ami/ml/orchestration/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def cleanup_async_job_resources(job: "Job") -> bool:

# Cleanup NATS resources
async def cleanup():
async with TaskQueueManager() as manager:
return await manager.cleanup_job_resources(job.pk)
manager = TaskQueueManager()
return await manager.cleanup_job_resources(job.pk)

try:
nats_success = async_to_sync(cleanup)()
Expand Down Expand Up @@ -96,22 +96,22 @@ async def queue_all_images():
successful_queues = 0
failed_queues = 0

async with TaskQueueManager() as manager:
for image_pk, task in tasks:
try:
logger.info(f"Queueing image {image_pk} to stream for job '{job.pk}': {task.image_url}")
success = await manager.publish_task(
job_id=job.pk,
data=task,
)
except Exception as e:
logger.error(f"Failed to queue image {image_pk} to stream for job '{job.pk}': {e}")
success = False

if success:
successful_queues += 1
else:
failed_queues += 1
manager = TaskQueueManager()
for image_pk, task in tasks:
try:
logger.info(f"Queueing image {image_pk} to stream for job '{job.pk}': {task.image_url}")
success = await manager.publish_task(
job_id=job.pk,
data=task,
)
except Exception as e:
logger.exception(f"Failed to queue image {image_pk} to stream for job '{job.pk}': {e}")
success = False

if success:
successful_queues += 1
else:
failed_queues += 1

return successful_queues, failed_queues

Expand Down
Loading