Skip to content

fix(repository): replace peek_result panic with InfrastructureError#326

Open
SAY-5 wants to merge 1 commit intoaixigo:masterfrom
SAY-5:fix/issue-307-task-result-missing-no-panic
Open

fix(repository): replace peek_result panic with InfrastructureError#326
SAY-5 wants to merge 1 commit intoaixigo:masterfrom
SAY-5:fix/issue-307-task-result-missing-no-panic

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 30, 2026

Summary

Closes #307.

peek_result (api/src/apps/repository.rs) panics via unreachable!() when the database returns a row whose status = 'done' but whose result_success and result_error columns (and the merged-with task's columns) are all NULL. The incident in #307 shows this state does occur in production — the operator's database had ten such rows:

SELECT id, created_at FROM app_task a
WHERE result_success is null AND result_error is null AND a.status = 'done';
-- 10 rows

The unreachable!() therefore reduced PREvant to a panicking task fetcher whenever a corrupt row was peeked.

Fix

Replace the unreachable arm with Err(AppsError::InfrastructureError { error: ... }) so the caller can return a 500, the operator can inspect/repair the row, and the rest of the system keeps running:

_ => Err(AppsError::InfrastructureError {
    error: format!(
        "Task {status_id} is marked done but has neither a success nor an error result stored"
    ),
}),

The error variant is already exported and is the closest semantic match for "the task ran but its outcome wasn't persisted".

Test plan

  • cargo build -p prevant — passes
  • Maintainer verification on the live staging environment (or a manually-corrupted app_task row) that the API now returns 500 with the new error message instead of crashing the worker.

peek_result panicked via unreachable!() when the database returned a
row whose status is 'done' but whose result_success and result_error
columns (and the merged-with task's columns) are all NULL. The
incident in aixigo#307 shows this state does occur in production — the
operator's database had ten such rows after a deployment failure —
and the unreachable!() reduced PREvant to a panicking task fetcher.

Surface the corrupt row as an AppsError::InfrastructureError that
identifies the affected status_id so the caller can return a 500 and
recover, leaving the row in the database for an operator to inspect
or repair instead of taking the whole API down.

Closes aixigo#307.

Signed-off-by: SAY-5 <say.apm35@gmail.com>
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.

Panics for Task Results

1 participant