Skip to content

BatchScriptCancel and BatchScriptExecutionStatus return HTTP 200 for nonexistent batch IDs #43027

@getvictor

Description

@getvictor

Found by code inspection


💥 Actual behavior

When calling DELETE /api/v1/fleet/scripts/batch/{id} (cancel) or GET /api/v1/fleet/scripts/batch/{id}/summary (status) with a nonexistent batch execution ID, the server returns HTTP 200 with an empty response body instead of HTTP 404.

The root cause is in server/service/scripts.go. After ListBatchScriptExecutions returns successfully with an empty list, the code calls ctxerr.Wrap(ctx, err, "...") where err is nil (from the successful list call). Since ctxerr.Wrap returns nil when the cause is nil, the function returns nil (success) instead of a not-found error.

🛠️ To fix

Replace ctxerr.Wrap(ctx, err, "get batch script status") with a proper not-found error at both locations (server/service/scripts.go). For example:

return ctxerr.Wrap(ctx, notFoundError{}, "batch execution not found")

🧑‍💻 Steps to reproduce

These steps:

  • Have been confirmed to consistently lead to reproduction in multiple Fleet instances.
  • Describe the workflow that led to the error, but have not yet been reproduced in multiple Fleet instances.
  1. Authenticate as a global admin via POST /api/v1/fleet/login
  2. Call GET /api/v1/fleet/scripts/batch/99999999/summary (any nonexistent batch execution ID)
  3. Observe HTTP 200 with empty/nil response instead of HTTP 404
  4. Similarly, call DELETE /api/v1/fleet/scripts/batch/99999999 and observe HTTP 200

🕯️ More info (optional)

Metadata

Metadata

Assignees

Labels

#g-mdmMDM product group:productProduct Design department (shows up on 🦢 Drafting board)bugSomething isn't working as documented~assisting g-orchestrationThis is a #g-orchestration issue that another product group is assisting~released bugThis bug was found in a stable release.

Type

No type

Projects

Status

🦤 ‎In review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions