Skip to content

feat(api): delete saved documents and owned retrieval chunks - #56

Merged
johnnyhuy merged 1 commit into
mainfrom
agent/issue-55-delete-saved-document
Nov 16, 2026
Merged

johnnyhuy merged 1 commit into
mainfrom
agent/issue-55-delete-saved-document

Conversation

@johnnyhuy

@johnnyhuy johnnyhuy commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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 install passed 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-backend passed, 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-frontend passed, 35 tests and 261 assertions.
  • MISE_YES=1 mise run test-runtime passed, 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 18055 reached Application startup complete, served the curl requests, then reached Application shutdown complete after SIGINT.
  • python3 .tmp/proof/document-delete-capture.py passed all curl status, saved-record, ownership and raw-distance assertions against that local server.
  • git diff --cached --check passed. 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.

  • Curl and retrieval transcript shows two identical documents with owned chunks at raw squared L2 distance 1.0. An injected Chroma deletion outage returns 503 and leaves the saved record readable. Retrying the same ID returns 200, subsequent detail/index/delete requests return 404, and retrieval retains only the second document's chunk at distance 1.0. Fixed vectors prove removal and identity, not production relevance.
  • Backend test names and output, frontend test output, runtime test output, installation output, and startup and shutdown output. Only trailing whitespace was normalised in the test and install logs.
  • Capture script and fixture process hook. Copy the hook to .tmp/offline-delete/sitecustomize.py and 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 the fail-delete marker 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.

Co-authored-by: OpenAI Codex <noreply@openai.com>
@johnnyhuy
johnnyhuy merged commit 1c0a558 into main Nov 16, 2026
10 checks passed
@johnnyhuy
johnnyhuy deleted the agent/issue-55-delete-saved-document branch November 16, 2026 10:17
@github-actions github-actions Bot mentioned this pull request Nov 16, 2026
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.

Delete a saved document and its owned retrieval chunks

1 participant