Skip to content

Improved error handling for task endpoints#575

Open
chr-pok wants to merge 9 commits intomainfrom
task-err-handling
Open

Improved error handling for task endpoints#575
chr-pok wants to merge 9 commits intomainfrom
task-err-handling

Conversation

@chr-pok
Copy link
Copy Markdown
Collaborator

@chr-pok chr-pok commented Feb 9, 2026

  • Removed default URLs from settings
  • Improved error handling and logging for task endpoints

@chr-pok chr-pok marked this pull request as ready for review February 9, 2026 15:04
count=accounting_info.parameters.count,
project_id=user_context.project_id,
)
accounting_session = None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

accounting should be handling the null case with the null session. We shouldn't have a None default.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ok, reverted this

activity_id=activity_id,
task_definition=TASK_DEFINITIONS[task_type],
)
L.info(f"Task failure callback received: task_type={task_type}, activity_id={activity_id}")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When logging a service it would be better to only log warnings or unexpected code paths that would help with debugging, otherwise the server can be drown in trivial logs generated with each request.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I see! I removed all trivial info logging.

Comment on lines +163 to +178
try:
task_service.handle_task_failure_callback(
db_client=db_client,
activity_id=activity_id,
task_definition=TASK_DEFINITIONS[task_type],
)
except Exception as exc:
L.error(
f"Failed to process task failure callback for activity {activity_id}: {exc}",
exc_info=True,
)
raise ApiError(
message=f"Failed to process task failure callback: {exc}",
http_status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
error_code=ApiErrorCode.INTERNAL_ERROR,
) from exc
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this necessary? That part of the code has only entitysdk calls which map automatically to ApiError in app/application.py

async def entity_sdk_error_handler(request: Request, exc: EntitySDKError) -> None:
    """Handle database client errors globally.

    Allows using the sdk anywhere in the service without having to handle EntitySDKError that are
    emitted explicitly if not needed.
    """
    L.exception(
        "EntitySDKError in %s %s",
        request.method,
        request.url,
    )
    raise ApiError(
        message=str(exc),
        error_code=ApiErrorCode.DATABASE_CLIENT_ERROR,
        http_status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
    ) from exc


app = FastAPI(
    title=settings.APP_NAME,
    version=settings.APP_VERSION or "0.0.0",
    debug=settings.APP_DEBUG,
    lifespan=lifespan,
    exception_handlers={
        ApiError: api_error_handler,
        RequestValidationError: validation_exception_handler,
        EntitySDKError: entity_sdk_error_handler,
    },
    root_path=settings.ROOT_PATH,
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ok, reverted this part

project_id=user_context.project_id,
)
accounting_session = None
try:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of trying to capture everything, each service func should have its try/excepts, which is the case for make_task_reservation for example.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added separate try/except blocks for all service calls

Comment on lines +46 to +48
L.info(
f"Task launch request: task_type={json_model.task_type}, config_id={json_model.config_id}"
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as below. No need for trivial logging that add noise to the server logs.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I removed all trivial info logging.

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.

2 participants