Skip to content

Improve task status API response structure and consistency#96

Open
Darkshadow0409 wants to merge 1 commit intoindictechcom:masterfrom
Darkshadow0409:pr3-task-status
Open

Improve task status API response structure and consistency#96
Darkshadow0409 wants to merge 1 commit intoindictechcom:masterfrom
Darkshadow0409:pr3-task-status

Conversation

@Darkshadow0409
Copy link
Copy Markdown

Problem

The current task status API returns responses in a format that is inconsistent with other backend endpoints. It uses fields like "status" and "result" without clearly separating success, data, and error states.

Solution

This PR improves the response structure of the task status API to make it consistent with other endpoints.

Changes made:

  • Introduced "success", "data", and "errors" fields for consistency
  • Renamed "status" to "state" for better clarity
  • Improved error handling by returning structured error messages
  • Ensured uniform API response format across endpoints

Benefits

  • Improves API consistency
  • Simplifies frontend integration
  • Enhances readability and debugging
  • Provides a cleaner structure for future enhancements

Copilot AI review requested due to automatic review settings March 31, 2026 17:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the /api/task_status/<task_id> endpoint in app.py to return a more structured, backend-consistent response shape for Celery task polling.

Changes:

  • Introduces top-level success, data, and errors fields in the task status response.
  • Renames the task status field from status to state.
  • Returns task failure messages via a structured errors list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app.py
Comment on lines 327 to 333
response = {
"success": True,
"task_id": task_id,
"status": task.status,
"result": task.result if task.successful() else None,
"state": task.status, # PENDING, STARTED, SUCCESS, FAILURE
"data": {},
"errors": []
}
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

This endpoint’s response schema is a breaking change (renames statusstate, resultdata, and errorerrors). The current frontend polling code still destructures { status, result, error } from /api/task_status (see frontend/src/pages/Upload.js), so this change will break uploads unless the client is updated in the same PR or the API supports the legacy fields during a transition.

Copilot uses AI. Check for mistakes.
Comment thread app.py
Comment on lines +335 to +341
if task.successful():
response["data"] = task.result

# If task failed, include error information
if task.failed():
response["error"] = str(task.result)
elif task.failed():
response["success"] = False
response["errors"] = [str(task.result)]
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

task.successful() can be True even when the task result represents an application-level failure (e.g., tasks.py returns { "success": False, "errors": [...] } on KeyError without raising, so Celery marks the task as SUCCESS). In that case this endpoint will return top-level success: True and errors: [], which contradicts the “structured error handling” goal. Consider normalizing: if task.result is a dict with success == False / errors, propagate those to the top-level response (or make the Celery task raise on failure instead of returning a failure payload).

Copilot uses AI. Check for mistakes.
Comment thread app.py
"task_id": task_id,
"status": task.status,
"result": task.result if task.successful() else None,
"state": task.status, # PENDING, STARTED, SUCCESS, FAILURE
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

The inline state comment is incomplete: tasks.py explicitly sets state='PROGRESS' via update_state, so clients may see PROGRESS here as well. Update the comment (and any client expectations/docs) to reflect all states this API can return.

Suggested change
"state": task.status, # PENDING, STARTED, SUCCESS, FAILURE
"state": task.status, # Celery task state (e.g. PENDING, STARTED, PROGRESS, SUCCESS, FAILURE)

Copilot uses AI. Check for mistakes.
Comment thread app.py
Comment on lines +326 to 333
# Improve Task Status API
response = {
"success": True,
"task_id": task_id,
"status": task.status,
"result": task.result if task.successful() else None,
"state": task.status, # PENDING, STARTED, SUCCESS, FAILURE
"data": {},
"errors": []
}
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

PR description claims this change “ensured uniform API response format across endpoints”, but this file still has endpoints returning error (singular) instead of errors (plural) (e.g., /api/preference and /api/user_language GET responses). Either broaden this PR to update those responses too, or adjust the PR description to reflect that only /api/task_status is being changed.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants