WeKnora/internal/application/service/file
tayadwx a1450d382e
fix(knowledge): claim cloned and released document images in the resource catalog (#3752)
* fix(knowledge): claim cloned and released document images in the catalog

#3493 binds images at parse time (bindStoredImages), which covers ingestion
but not the two paths that move image ownership:

Clone. A copied image is written as a new object, yet nothing claimed it for
the destination knowledge, so the KB file proxy answered 403 and cloned
documents rendered without images. The copy now goes through SaveBytes into
the servable exports/ namespace (CopyFile wrote to the knowledge-scoped
upload layout the proxy rejects), is claimed by the destination knowledge,
and CloneChunk / FAQ clone bind the handles left in chunk content and
image_info.

Delete. Release only looked at multimodal ImageInfo, which stays empty for
documents whose images live in markdown alone, so those objects outlived the
knowledge that owned them. The release set is now the union of ImageInfo URLs
and the bindings recorded for the knowledge being removed, with source_file
excluded so reparse and cleanup keep the original document.

The parse-path claim from the earlier attempt is dropped: ProcessDocument
already gets it from bindStoredImages, and the removed test only string
matched that call in the source. Every claim path stays best-effort,
including the clone path, which used to fail the whole clone and delete the
fresh copy when a single Bind errored.

* fix(knowledge): keep markdown-only images out of the pre-reindex cleanup

cleanupKnowledgeResources runs before a knowledge is re-indexed -- a manual
update, a reparse, a move with reparse -- not before it is removed. Unioning
in the catalog bindings there released a solely owned markdown-only
attachment, deleteExtractedImages deleted the file, and the catalog file
service marked the resource deleted. The re-claim that runs after the cleanup
resolves through a state=active lookup, so it could never bind that handle
again: the republished body was left pointing at a deleted image.

Cleanup collects ImageInfo URLs alone again. The paths that do remove a
knowledge entry (executeKnowledgeDelete, ProcessKBDelete) keep the union, which
is what lets markdown-only images be released when the knowledge actually goes
away.

Reported by @lyingbug in review on #3752.

---------

Co-authored-by: tayadwx <tayadwx@users.noreply.github.com>
2026-10-09 13:01:26 +08:00
..
backend_scoped.go fix(files): accept canonical storage:// paths in bare provider services (#3166) 2026-09-25 18:48:04 +08:00
backend_scoped_test.go fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
canonical_path_parse_test.go style(files): wrap long test case to satisfy lll 2026-09-25 21:46:12 +08:00
cos.go fix(files): accept canonical storage:// paths in bare provider services (#3166) 2026-09-25 18:48:04 +08:00
cos_parse_test.go fix(security): close the low-severity shared-space findings (#3416) 2026-09-18 22:58:46 +08:00
dummy.go feat(resource): add stable resource registry with LLM-context alias compaction 2026-07-15 17:02:43 +08:00
endpoint_security_test.go fix(security): harden outbound URL SSRF protection (#2626) 2026-08-10 13:24:14 +08:00
errors.go fix: deep-copy stored files and images when cloning a knowledge base 2026-06-03 14:45:59 +08:00
factory.go fix(security): reject traversal in local prefixes, task IDs, and wiki sort 2026-09-07 11:23:45 +08:00
ks3.go fix(files): accept canonical storage:// paths in bare provider services (#3166) 2026-09-25 18:48:04 +08:00
ks3_path_test.go fix(security): close the low-severity shared-space findings (#3416) 2026-09-18 22:58:46 +08:00
ks3_redirect_test.go fix(storage): keep the SSRF redirect policy on the KS3 client (#3440) 2026-09-20 11:12:52 +08:00
local.go fix(storage): strip storage-backend scope in local provider path normalization (#2979) 2026-09-21 14:21:25 +08:00
local_copy_test.go fix: deep-copy stored files and images when cloning a knowledge base 2026-06-03 14:45:59 +08:00
local_test.go fix(storage): strip storage-backend scope in local provider path normalization (#2979) 2026-09-21 14:21:25 +08:00
minio.go fix(files): accept canonical storage:// paths in bare provider services (#3166) 2026-09-25 18:48:04 +08:00
object_storage_http.go fix(storage): let object storage transfers outlive 30 seconds (#3368) 2026-09-19 21:30:55 +08:00
object_storage_http_test.go fix(storage): let object storage transfers outlive 30 seconds (#3368) 2026-09-19 21:30:55 +08:00
obs.go fix(files): accept canonical storage:// paths in bare provider services (#3166) 2026-09-25 18:48:04 +08:00
obs_test.go fix(storage): use virtual-hosted addressing for OBS bucket requests (#3273) 2026-09-15 18:18:40 +08:00
oss.go fix(files): accept canonical storage:// paths in bare provider services (#3166) 2026-09-25 18:48:04 +08:00
oss_test.go fix(security): harden outbound URL SSRF protection (#2626) 2026-08-10 13:24:14 +08:00
resolve_tenant.go refactor(resource-access): unify scoped authorization and transfer recovery (#3097) 2026-09-08 15:36:33 +08:00
resource_catalog.go feat(agent): preview skill artifacts and verify installs without running them (#2823) 2026-08-27 10:30:32 +08:00
resource_catalog_test.go fix(knowledge): claim cloned and released document images in the resource catalog (#3752) 2026-10-09 13:01:26 +08:00
s3.go fix(storage): use virtual-hosted addressing for Tencent COS through the S3 driver (#3722) 2026-10-08 01:20:54 +08:00
s3_test.go fix(storage): use virtual-hosted addressing for Tencent COS through the S3 driver (#3722) 2026-10-08 01:20:54 +08:00
tos.go fix(files): accept canonical storage:// paths in bare provider services (#3166) 2026-09-25 18:48:04 +08:00