Skip to content

Add anomaly summary to Activity results endpoint #129

Description

@siculo

Problem

The GET /api/jobs/{job_id}/results endpoint currently returns only per-photo
results. When a systemic failure occurs (e.g., Ollama is unreachable), every
photo has the same "failed" status with the same error message. There is no
way to distinguish "this individual photo failed" from "the entire activity
failed due to an infrastructure problem".

Current response (abbreviated)

{                                                                                                          
  "summary": { "total": 9, "completed": 0, "failed": 9 },
  "results": [
    { "status": "failed", "error": "Request to AI provider 'ollama' timed out after 120 seconds" },
    ...                                                                                                      
  ]
}                                                                                                            

The plugin interprets this as "9 photos processed" and shows no warning. When
the user tries to apply tags, Lightroom reports that no photos have tags —
with no actionable explanation.


Proposed solution

API — extend the response with an anomalies block

Add an optional anomalies field to the activity results response that
aggregates systemic error patterns:

{
  "job_id": "...",
  "summary": { "total": 9, "completed": 0, "failed": 9 },                                                    
  "anomalies": [
    {                                                                                                        
      "kind": "provider_unreachable",                                                                        
      "provider": "ollama",
      "affected_photos": 9,                                                                                  
      "sample_error": "Request to AI provider 'ollama' timed out after 120 seconds"                        
    }                                                                                                        
  ],
  "results": [ ... ]                                                                                         
}

Detection heuristics (to be refined):

  • All photos failed with the same error → surface as a systemic anomaly
  • Provider timeout / connection refused → kind: provider_unreachable
  • Partial failure with a common error → surface as a partial anomaly

The anomalies field is omitted (or empty array) when there are no systemic
issues.

Plugin — surface anomalies to the user

When the activity results contain anomalies:

  1. Display a dedicated warning dialog before showing the results panel, e.g.:
    "Activity completed with errors. Ollama was unreachable — no photos were
    tagged. Check that the Ollama service is running and try again."
  2. Do not present the standard "X photos processed" success message when
    completed == 0.

Acceptance criteria

  • API: anomalies field is present when all or most photos share the same
    failure reason
  • API: anomalies correctly identifies provider_unreachable for Ollama
    timeout/connection errors
  • Plugin: shows an actionable error message when anomalies is non-empty
  • Plugin: does not show "processed" count when no photos were actually tagged
  • Existing behavior is unchanged when there are no anomalies

Affected components

  • api/ — results endpoint, job/activity domain model
  • plugin/ — results polling and display logic

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions