Skip to content

test(api): pin 200 response for failed job status (#168) - #424

Merged
SahilKumar75 merged 4 commits into
SahilKumar75:mainfrom
Anshul1336:fix-168-job-status-code
Sep 19, 2026
Merged

SahilKumar75 merged 4 commits into
SahilKumar75:mainfrom
Anshul1336:fix-168-job-status-code

Conversation

@Anshul1336

@Anshul1336 Anshul1336 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Issue #168 asked for GET /jobs/{job_id} to return 4xx/5xx when a training job fails. After review we are keeping the 200: a failed job is a valid resource state, not a server error, and the dashboard depends on reading it from a 200 response. This PR pins that contract with a test so it cannot regress silently.

Scope

  • What changed: added test_get_job_status_reports_failed_job_in_body in tests/test_api.py, asserting a failed job returns 200 with status="failed" and the error text.
  • What did not change: app/api/jobs_routes.py. The first version of this PR raised a 500 there; that was reverted in 6c8b175.
  • Related issue: Closes API returns 200 on failed training job instead of 4xx/5xx #168

Product Impact

None for users. The dashboard keeps showing failed jobs as failed along with the error message.

Technical Notes

app/state/training_poller_state.py only handles 200 responses from this endpoint. _reconcile_status_via_rest is the fallback for when the Redis pub/sub event is lost. With a 500 it never saw failed, so the dashboard stayed on "running" forever, and the final fetch never filled in error_msg. A 500 would also have replaced the JobStatus body with {"detail": ...}.

A 404 for unknown job IDs was considered and rejected: the status key is only written to Redis once the worker picks the job up, so a queued job reads as not_found until then.

Validation

  • Unit tests added or updated (tests/test_api.py: 29 passed)
  • Integration path tested
  • Frontend manually verified (no frontend change)
  • Accessibility and responsive behavior reviewed (n/a)
  • Documentation updated (n/a)

Screenshots Or Recordings

n/a, no UI change.

Risk And Rollback

Test-only change, no risk. Roll back by reverting the commit.


Original fix by @Anshul1336; reworked during review.

was always returning 200 no matter what, even when the job actually
failed. added a check for that and it now returns 500 with the error
message instead. added a test for it too.

fixes SahilKumar75#168
@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: a88a1856-aa86-4ed9-80f9-f6045b7b1eb1


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@SahilKumar75

Copy link
Copy Markdown
Owner

Thank you for the contribution, @Anshul1336. This cannot be merged as is. The dashboard polling logic in training_poller_state.py only processes 200 responses, so a 500 would leave failed jobs shown as running and hide the error message.

A failed job is a valid state, not a server error, so we prefer to keep the 200 and close #168. Alternatively, please update the polling logic to handle the new status and add tests.

Please use the pull request template for future submissions.

@SahilKumar75 SahilKumar75 reopened this Sep 19, 2026
@SahilKumar75 SahilKumar75 changed the title fix job status endpoint returning 200 on failed jobs test(api): pin 200 response for failed job status (#168) Sep 19, 2026
A failed training job is a valid resource state, not a server error.
Returning 500 broke the dashboard poller in
app/state/training_poller_state.py, which only reads 200 responses:
failed jobs stayed "running" forever when the pub/sub event was missed,
and the error message was never shown.

Revert the 500 and replace the test with one that pins the contract:
GET /jobs/{id} returns 200 with status="failed" and the error text.
@SahilKumar75
SahilKumar75 force-pushed the fix-168-job-status-code branch from 956a7e6 to 6c8b175 Compare September 19, 2026 18:10
@SahilKumar75
SahilKumar75 merged commit e809ff3 into SahilKumar75:main Sep 19, 2026
12 checks passed
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.

API returns 200 on failed training job instead of 4xx/5xx

2 participants