Skip to content

bug(kb-ui): knowledge backups can't be deleted or restored — the UI reads backup.name, the API returns filename/filepath, so both send an empty body (422) #19721

Open

Description

@mrveiss

Problem

On /knowledge/health, deleting or restoring a knowledge backup does nothing useful. The backup list renders, but the UI holds no usable identifier for any backup.

Root cause: a frontend/backend contract mismatch

  • The list the backend returns (autobot-backend/knowledge/bulk.py:1892-1898, _scan_backup_files): each item has filename, filepath, size, created_at and compressed. There is no name field.
  • How the UI stores it (autobot-frontend/src/composables/knowledge/useKnowledgeBackup.ts:83): backups.value = data.backups, assigned raw with no mapping.
  • The buttons use the missing field (BackupManager.vue:99-101, delete, and :92, restore): both pass backup.name, which is undefined.
  • What gets sent (useKnowledgeBackup.ts:119-130): DELETE /api/knowledge-maintenance/backup with {backup_file: undefined}, which serialises to {}. DeleteBackupRequest requires backup_file, so the request fails with 422. Restore fails the same way.
  • A second gap behind the first: even a correct bare filename would be rejected. _resolve_backup_path (bulk.py:1467) applies realpath to the name relative to the process cwd, not to the backup directory.

Evidence: the RUM log has 18 HTTP_ERROR 422 entries on /api/knowledge-maintenance/backup from /knowledge/health, dated 2026-08-06 to 2026-10-16. RUM doesn't record the HTTP method, so some of these may be create-backup failures; that part is not verified. The backup directory itself is fine: it is owned by the service user and holds 239 backup files, so backups accumulate and can't be pruned from the UI.

Fix

One change:

  • the composable maps the list response to the UI model (filename as the id);
  • delete and restore send that identifier;
  • _resolve_backup_path resolves a bare filename inside the configured backup directory, rejecting anything that escapes it.

Acceptance criteria

  • A contract test pins the list_backups response shape against what useKnowledgeBackup.ts reads.
  • Delete and restore send the backup's filename. A test asserts the request body is non-empty.
  • _resolve_backup_path resolves a bare filename inside the backup directory and rejects ../ and absolute paths. A test pins both.
  • Host: after the builtin update, a user deletes one backup and restores one backup from /knowledge/health.

Activity

  1. mrveiss commented on Nov 2, 2026

    @mrveiss
    OwnerAuthor

    Landed in the merge train (PR #20594, 655489c4e6) via #20510.

    AC Evidence
    A contract test pins the list_backups response shape against what useKnowledgeBackup.ts reads repo_tests/knowledge_backup_list_contract_19721_test.py: test_the_list_returns_a_filename_and_no_name reads _scan_backup_files in autobot-backend/knowledge/bulk.py; test_the_composable_maps_filename_to_the_ui_s_name pins data.backups.map(({ filename, ...rest }) => ({ name: filename, ...rest })) in the composable.
    Delete and restore send the backup's filename; a test asserts the body is non-empty useKnowledgeBackup.ts sends backup_file: backupName in restore and delete; __tests__/useKnowledgeBackup.test.ts has "restores with that filename, so the request body is not empty" and the delete equivalent, asserting backup_file is kb_backup_1.jsongz.
    _resolve_backup_path resolves a bare filename inside the backup directory and rejects ../ and absolute paths; a test pins both bulk.py _resolve_backup_path calls resolve_backup_name(self._get_backup_dir(None), backup_file); autobot-backend/utils/path_validation_test.py has test_a_bare_filename_resolves_inside_the_backup_dir, test_an_absolute_path_is_refused_even_inside_the_backup_dir, test_a_nested_or_traversing_name_is_refused (../outside.json, ..), test_a_symlink_pointing_outside_is_refused.
    Host: after the builtin update, a user deletes one backup and restores one backup from /knowledge/health Not ticked. Needs a browser session on an updated host; a merge is not that evidence.

    3 of 4 met in code. The issue stays open for the host check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbugSomething isn't workingfrontendphase:M1.8Knowledge base: upload, web sources and chat retrieval work end to endpriority: high

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions