WeKnora/internal/container
LuckVd c57766cc76
fix(tenant): stop wiki tasks of soft-deleted tenants from issuing model requests (#3602)
* fix(tenant): stop wiki tasks of soft-deleted tenants from issuing model requests

Tenant deletion only soft-deletes the tenant and its memberships; its
knowledge bases, model configs, and durable task_pending_ops rows survive.
Wiki ingest/finalize tasks restored from those ops only checked KB state,
so a deleted tenant kept accruing new LLM requests (observed as ~11h of
continued synthesis calls in #3593).

Gate every task entry point on tenant liveness:

- EnqueueIfKnowledgeBaseActive now also requires tenants.deleted_at IS NULL
  inside the same transaction (fail closed).
- Startup recovery purges pending rows whose tenant is soft-deleted (the
  predicate is wrapped in parentheses: NOT EXISTS(...) AND EXISTS(...) would
  parse as (NOT EXISTS(...)) AND EXISTS(...) and silently match nothing).
- Wiki ingest and finalize handlers check tenant liveness from the payload
  before any model call and drop the KB's queue when the tenant is gone.
  Liveness lookup errors fail open; the guarded enqueue and recovery paths
  enforce the same invariant on their own DB access.

Adds TaskPendingOpsTenantLiveness as an optional extension interface,
regression tests for the enqueue guard, startup recovery, and the task
entry guards.

Fixes #3593

* style(container): wrap long log line over 120 chars for golangci-lint (lll)

---------

Co-authored-by: LuckVd <LuckVd@users.noreply.github.com>
2026-09-23 12:13:32 +08:00
..
audit_sink.go feat(retriever): activate OpenSearch k-NN driver (PR 3 of 3) 2026-05-29 16:32:27 +08:00
audit_sink_test.go feat(retriever): activate OpenSearch k-NN driver (PR 3 of 3) 2026-05-29 16:32:27 +08:00
cleanup.go init commit 2025-08-05 15:08:07 +08:00
container.go feat(security): add a whitelist-only outbound mode that refuses before DNS (#3393) 2026-09-23 12:02:06 +08:00
datasource_registry_test.go feat(datasource): add DingTalk Docs integration with safe sync and localization (#2313) 2026-09-14 19:53:29 +08:00
engine_factory.go fix(security): harden outbound URL SSRF protection (#2626) 2026-08-10 13:24:14 +08:00
engine_factory_opensearch_test.go fix(retriever): rebuild a missing vector store engine on demand 2026-07-29 12:25:18 +08:00
engine_factory_test.go fix(security): harden outbound URL SSRF protection (#2626) 2026-08-10 13:24:14 +08:00
host_project_lookup.go feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549) 2026-09-22 19:35:03 +08:00
host_project_lookup_test.go feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549) 2026-09-22 19:35:03 +08:00
nolocalsandbox_test.go feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549) 2026-09-22 19:35:03 +08:00
recover_pending_wiki_tasks.go fix(tenant): stop wiki tasks of soft-deleted tenants from issuing model requests (#3602) 2026-09-23 12:13:32 +08:00
reset_pending_tasks.go fix(knowledge): recover tasks safely after server restart 2026-07-14 17:55:26 +08:00
reset_pending_tasks_test.go fix(tenant): stop wiki tasks of soft-deleted tenants from issuing model requests (#3602) 2026-09-23 12:13:32 +08:00
retrieve_registry_wiring_test.go fix(retriever): rebuild a missing vector store engine on demand 2026-07-29 12:25:18 +08:00
router_wiring_test.go fix(container): wire shared agent lookup for MCP handler 2026-09-21 14:38:54 +08:00
sandbox.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
sandbox_host.go feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549) 2026-09-22 19:35:03 +08:00
sandbox_host_shared.go feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549) 2026-09-22 19:35:03 +08:00
sandbox_host_stub.go feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549) 2026-09-22 19:35:03 +08:00
sandbox_host_test.go feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549) 2026-09-22 19:35:03 +08:00
sandbox_test.go feat(sandbox): 沙箱后端改为按空间配置,并补齐 E2B 模板与检测诊断 2026-08-11 15:42:02 +08:00
ssrf_test.go fix(security): harden outbound URL SSRF protection (#2626) 2026-08-10 13:24:14 +08:00
storagebackend_migration_test.go feat(knowledge): derive knowledge base descriptions from document profiles (#3370) 2026-09-17 22:21:55 +08:00
vector_store_whitelist_only_test.go feat(security): add a whitelist-only outbound mode that refuses before DNS (#3393) 2026-09-23 12:02:06 +08:00