#3594·WeKnora

maintenance: backfill extracted_image bindings for legacy documents

Author: tsumonCreated Sep 23, 2026Updated Oct 1, 2026

Context

PR #3493 fixed the forward path for newly ingested extracted images by creating the extracted_image resource binding and by preserving shared-KB parent lookups. Its scope note explicitly leaves historical documents parsed before that fix without bindings. Issue #3342 was closed after the new-document path was verified, but legacy documents still need a separate maintenance operation.

Problem

Legacy knowledge documents may have extracted image resources that exist in storage but have no live resource_bindings row. Shared-KB image authorization therefore continues to fail for those older documents even after the forward fix.

Proposed safe behavior

  • Make the operation explicitly opt-in and dry-run by default.
  • Process bounded, resumable batches rather than scanning or rewriting everything at once.
  • Discover only supported candidate document/image references.
  • Require resource.tenant_id == knowledge.tenant_id before creating a binding; skip and report cross-tenant candidates.
  • Use the existing idempotent binding operation with relation extracted_image.
  • Do not modify bytes, document content, sharing, ACLs, or resource ownership.
  • Report at least: scanned, already-bound, bound, skipped-cross-tenant, unresolved, and failed counts.

Acceptance criteria

  • A maintainer-selected entry point (one-shot admin command or maintenance task) supports dry-run and bounded execution.
  • Re-running the same batch is safe and does not create duplicate bindings.
  • Tests cover same-tenant repair, already-bound resources, missing resources, cross-tenant skips, and bind failures.
  • Logs/metrics make the result auditable before and after applying changes.

References

  • #3342 — original shared-KB extracted-image 403 report (now completed for newly ingested documents)
  • #3493 — merged forward fix; calls out historical backfill as a follow-up slice

I am happy to prepare the implementation once the maintainers confirm the preferred maintenance entry point.