Skip to content

feat(operator): KapeTool memory deletion-protection finalizer + Qdrant collection lifecycle (#38) - #147

Merged
dzungtr merged 1 commit into
mainfrom
feat/38-kapetool-deletion-qdrant
Jul 19, 2026
Merged

dzungtr merged 1 commit into
mainfrom
feat/38-kapetool-deletion-qdrant

Conversation

@dzungtr

@dzungtr dzungtr commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds kape.io/tool-protection finalizer to all memory-type KapeTool resources on reconcile (retroactive for existing resources)
  • Blocks deletion with Ready=False / ReferencedByHandlers condition and DeletionBlocked event while any KapeHandler carries kape.io/tool-ref-{name}=true; finalizer released once no referencing handlers remain
  • New operator/infra/qdrant package: EnsureCollection (idempotent on 200/409) called when StatefulSet reaches ReadyReplicas ≥ 1, DeleteCollection (idempotent on 404) called before finalizer removal
  • ports.ToolRepository and k8s.ToolRepository gain AddFinalizer/RemoveFinalizer (mirrors SchemaRepository pattern)

Test plan

  • TestToolReconciler_MemoryType_FinalizerAddedOnCreate — finalizer is added on first reconcile
  • TestToolReconciler_MemoryType_UpgradePath_FinalizerAddedRetroactively — existing tools without finalizer get it on next reconcile
  • TestToolReconciler_MemoryType_DeletionBlockedWhenHandlerReferences — finalizer stays, DeletionBlocked event emitted
  • TestToolReconciler_MemoryType_DeletionUnblocksWhenNoHandlers — finalizer removed, Qdrant DELETE called (200 response)
  • TestToolReconciler_MemoryType_DeleteCollection_Idempotent404 — 404 from Qdrant treated as success
  • TestEnsureCollection_Idempotent200 / TestEnsureCollection_Idempotent409 — collection create idempotency
  • TestDeleteCollection_Idempotent200 / TestDeleteCollection_Idempotent404 — collection delete idempotency
  • TestToolRepository_AddRemoveFinalizer — k8s adapter correctly patches finalizers
  • All operator tests pass (go test ./operator/...)

Closes #38

🤖 Generated with Claude Code

… Qdrant collection lifecycle

Adds kape.io/tool-protection finalizer to all memory-type KapeTools on
reconcile. Deletion is blocked with Ready=False/ReferencedByHandlers and
a DeletionBlocked event while any KapeHandler carries
kape.io/tool-ref-{name}=true. Once no referencing handlers remain, the
new qdrant package calls DELETE /collections/{name} (idempotent on 404)
before releasing the finalizer.

On StatefulSet ReadyReplicas >= 1, EnsureCollection calls PUT
/collections/{name} (idempotent on 200/409). Existing KapeTools without
the finalizer receive it retroactively on next reconcile.

Closes #38

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Phase 6 follow-up: KapeTool memory-type deletion protection + Qdrant collection cleanup (deferred from M2)

1 participant