Repository navigation
feat(api): delete saved documents and owned retrieval chunks - #56
Merged
Merged
Conversation
Co-authored-by: OpenAI Codex <noreply@openai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The management API can now delete a saved document with
DELETE /api/documents/{document_id}. It removes chunks carrying that document's numeric ID before deleting the saved row, preserves other owners, Slack chunks and unowned historical content, and returns a safe retryable 503 on storage failures.Part of #5. Closes #55.
Verification
Every command below ran with the inherited environment cleared using
env -i HOME="$HOME" PATH="$PATH". This worktree has no root or backend.env; no real token was read or changed.UV_PYTHON=3.13 MISE_YES=1 mise run installpassed for backend, frontend and runtime. The generated backend lock-file change was discarded; dependencies are unchanged.UV_PYTHON=3.13 UV_FROZEN=1 MISE_YES=1 SLACK_BOT_TOKEN=xoxb-fixture-only SLACK_SIGNING_SECRET=fixture-only DATABASE_URL=sqlite:///.tmp-tests.db mise run test-backendpassed, 221 tests with 1033 library and fixture warnings. The 12 new cases cover exact ownership, preserved metadata and embeddings, missing and malformed IDs, unindexed legacy records, vector initialisation and deletion failures, a lost vector acknowledgement, database rollback and retry, and a missing vector adapter. An initial test assertion used an incorrect fixture distance; it was corrected before this passing run.MISE_YES=1 mise run test-frontendpassed, 35 tests and 261 assertions.MISE_YES=1 mise run test-runtimepassed, 7 offline tests.UV_PYTHON=3.13 UV_FROZEN=1 MISE_YES=1 PYTHONPATH="$PWD/.tmp/offline-delete:$PWD/backend" SLACK_BOT_TOKEN=xoxb-fixture-only SLACK_SIGNING_SECRET=fixture-only DATABASE_URL="sqlite:///$PWD/.tmp/offline-delete/proof.db" mise run dev-backend -- --host 127.0.0.1 --port 18055reachedApplication startup complete, served the curl requests, then reachedApplication shutdown completeafter SIGINT.python3 .tmp/proof/document-delete-capture.pypassed all curl status, saved-record, ownership and raw-distance assertions against that local server.git diff --cached --checkpassed. No migration is needed.Proof
Capture methods (a) and (c) succeeded. The frontend test gate also passed; no UI changed, so a dashboard screenshot is not applicable. No capture path was blocked.
.tmp/offline-delete/sitecustomize.pyand use a fresh local proof directory/database to reproduce. The hook mocks Slack authentication, blocks Slack API calls and Socket Mode startup, uses local Chroma and fixed embeddings through the existing vector-store singleton, and injects a deletion failure while thefail-deletemarker exists.Review notes
This adds an API action; dashboard deletion remains a later slice. Existing management endpoints have no built-in authentication, so keep this destructive action behind trusted access controls.
Database and vector operations are separate. A vector failure keeps the saved record for retry. If database removal fails after chunks were removed, rollback retains the record but cannot restore the chunks; retry DELETE to finish. A lost database commit acknowledgement can instead leave the record already removed, in which case retry returns 404. Avoid overlapping indexing and deletion of the same ID: existing index requests can write chunks after deletion, and this slice does not coordinate concurrent workers or add tombstones.
Historical chunks without a numeric document owner remain searchable. Deletion does not erase Pi history or previously generated answers. Chroma and the shared vector-store configuration are required even for an unindexed record, but deletion does not invoke embedding or generation.
No Slack message, live workspace connection, real token, remote database, model request or paid embedding request was used. A live Slack workspace is not needed for this slice. Parent #5 stays open; child #55 closes only when this PR merges.