Skip to content

bug(chat): file_access_log cannot record a dedup reference; it is logged as an upload with a metadata flag #21404

Closed

Description

@mrveiss

Problem

The file_access_log table cannot record a deduplication reference as its own access type. The dedup path logs it as upload and marks it only in the free-form metadata, so an audit query on access_type cannot tell a real upload from a reference to an existing file.

Evidence (origin/main)

  • autobot-backend/database/schemas/conversation_files_schema.sql:75 - CHECK (access_type IN ('upload', 'download', 'view', 'delete', 'restore')).
  • autobot-backend/conversation_file_manager.py:683-685 - "upload" with metadata {"deduplication": True, "reference": True}, with a comment that the CHECK has no reference.

Options

  1. Extend the CHECK with reference through a schema migration. Queries become exact; needs a SQLite table rebuild (CHECK cannot be altered in place) and existing rows stay as they are.
  2. Keep the metadata flag and document it as the design. No migration; audit consumers must read access_metadata to separate the cases.

Recommendation

Option 1: the access type is what audit consumers filter on, and the flag workaround hides a real event inside another type. It needs owner approval because it is a schema migration.

Acceptance criteria

  • Owner picks an option on this issue.
  • Option 1: a migration extends the CHECK, is idempotent, and preserves existing rows; the dedup path logs reference; a test asserts the logged type.
  • Option 2: the design is documented next to the schema and the code comment, and a test pins the flag.

Activity

  1. added
    bugSomething isn't working
    needs-decisionBlocked on an owner decision; options and a recommendation are on the issue
    phase:M3.9Chat, Agents, Analytics and Settings screens
    on Nov 12, 2026
  2. mrveiss commented on Nov 17, 2026

    @mrveiss
    OwnerAuthor

    Owner decision (2026-11-17): Option 1. A migration extends the access-type CHECK with reference; it is idempotent and preserves existing rows. The dedup path logs reference, and a test asserts the logged type. This goes into PR #21732.

  3. removed
    needs-decisionBlocked on an owner decision; options and a recommendation are on the issue
    on Nov 17, 2026
  4. mrveiss commented on Nov 17, 2026

    @mrveiss
    OwnerAuthor

    Option 1 implemented in PR #21732: conversation_file_access_type_schema.py (idempotent rebuild keeping rows), called from the manager schema init and migration 001; dedup logs reference.

  5. mrveiss commented on Nov 17, 2026

    @mrveiss
    OwnerAuthor

    Closure pass, checked against origin/main at df23644 (PR #21732), by reading code; tests were not run here, CI ran them on the PR.

    AC Evidence on main
    Owner picks an option on this issue. Owner decision 2026-11-17: Option 1.
    Option 1: a migration extends the CHECK, is idempotent, and preserves existing rows; the dedup path logs reference; a test asserts the logged type. CHECK now lists reference (database/schemas/conversation_files_schema.sql:75). Migration conversation_file_access_type_schema.py ensure_access_type_schema (:86): BEGIN IMMEDIATE rebuild, foreign keys off during the copy, orphans and the id counter kept; run from the manager schema init (conversation_file_manager.py:444 via apply_schema_upgrades) and from migration 001 (database/migrations/001_create_conversation_files.py:148). Dedup logs reference (conversation_file_manager.py:683). Tests in conversation_file_access_type_21404_test.py: test_a_duplicate_upload_is_logged_as_a_reference_not_an_upload, test_the_migration_keeps_every_row_and_column_and_is_idempotent, test_an_orphan_row_survives_and_the_foreign_key_setting_is_restored, test_log_ids_of_deleted_rows_are_never_reused, test_an_error_mid_migration_leaves_the_old_table_and_rows_intact, test_a_check_written_in_a_comment_does_not_hide_the_real_old_one.
    Option 2: the design is documented next to the schema and the code comment, and a test pins the flag. Not applicable: Option 1 was chosen; left unticked.

    Gate 2: check-issue-close-refs.sh 21404 clear. No frontend or API consumer filters on access_type, so no UI change. The issue stays closed.

  6. added
    needs-ac-evidenceClosed by a merge keyword; awaits an AC evidence table comment (#19520)
    on Nov 17, 2026
  7. github-actions commented on Nov 17, 2026

    @github-actions
    Contributor

    Landed in #21732, merge df23644add

  8. mrveiss commented on Nov 17, 2026

    @mrveiss
    OwnerAuthor

    Host evidence — local install on main @ df23644 (2026-11-17 22:32 Riga)

    Item Verdict Evidence
    Migration extends the CHECK on the host (Option 1) PASS The live file_access_log CREATE statement has CHECK (access_type IN ('upload', 'download', 'view', 'delete', 'restore', 'reference')), so the migration ran on the install.
    Existing rows preserved / normal logging still works PASS (partial) A new upload after the migration wrote a file_access_log row with access_type 'upload'. Pre-existing row counts were not compared.
    Dedup path logs reference on the host NOT OBSERVED Only one upload was made, so the dedup path was not triggered on the host. Test coverage is unchanged.

    No checkbox changes. The ticked Option 1 AC is code and test evidence, and this comment adds the host-side confirmation of the schema.

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 workingneeds-ac-evidenceClosed by a merge keyword; awaits an AC evidence table comment (#19520)phase:M3.9Chat, Agents, Analytics and Settings screenspriority: medium

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions