Repository navigation
fix(knowledge): delete the document directory even before it is indexed - #456
Merged
Merged
Conversation
`delete_document` located the directory through the SQLite row and returned `deleted_topics=0` when the row was missing. The row is written by the cascade a second or more after `POST /documents` returns, so a delete that follows a create closely (an undo, a client retry) found no row, touched nothing, and answered 204 — while the markdown stayed on disk and the cascade indexed the "deleted" document right back in. Reproduced against a live server: create → delete 3 ms later → the document listed and readable again a few seconds on. Markdown is the source of truth, so the disk is consulted when the index has no row: the directory name ends in the doc_id (`knowledge_writer`), and a `*/*_<doc_id>` glob under the scope's knowledge dir finds it. The response stays 204 in that case (no indexed topics were removed), as documented. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Member
Author
|
Live before/after on the same repro (create →
Script: |
8 of 12 tasks
gloryfromca
pushed a commit
that referenced
this pull request
Sep 24, 2026
PR #456 changes what a delete-before-index reports; the wording added here would be wrong once it lands, so keep the sentence as on main. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Member
Author
|
Adversarial review round (subagent, read-only) found two should-fix items; both addressed in the follow-up commit:
Test hardening: the fixture plants a sibling document and |
Adversarial review of the previous commit found two gaps. The doc_id went into a glob pattern unvalidated — `delete_document` is a public service function and only the HTTP route checks the id's shape, so `"*"` removed the first document of the first category. The directory name is now compared literally with `endswith`, every matching directory is removed, and the response reports the topic files that were on disk instead of a hard-coded 0, so a delete that beats the index answers 200 with the real count as the docs describe (204 stays for "nothing existed"). The test now plants a sibling document and the taxonomy file and asserts they survive — an `rmtree(knowledge_dir)` implementation passed the old test and fails this one — and a parametrised case checks that an absent id, `*` and `*/_original` remove nothing. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
gloryfromca
force-pushed
the
fix/knowledge-delete-before-index
branch
from
September 24, 2026 05:56
9a97816 to
825d83c
Compare
gloryfromca
pushed a commit
that referenced
this pull request
Sep 24, 2026
Adversarial review of the eventual-consistency paragraph against everalgo: the gate that actually decides under EverOS defaults is `min_tool_call_rounds=3` — no case below three tool-call rounds, which also makes the previously listed "assistant turn under ~200 tokens" gate unreachable — and the EverOS `agent_case_skipped_by_algo` event carries ids only; the reason is on everalgo's own log line. Also: `quiesce` is safe to call twice rather than "idempotent" (it reports `quiesced=True` both times), knowledge GET reads SQLite rather than "the index", the ~1 s figure is hedged like the others, the PATCH sentence names why it escapes the lag, and the delete status-code sentence is left as on main because PR #456 changes what a delete-before-index reports. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
0xKT
approved these changes
Sep 24, 2026
arelchan
self-requested a review
September 24, 2026 08:45
gloryfromca
enabled auto-merge (squash)
September 24, 2026 08:54
This was referenced Sep 24, 2026
Merged
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.
Summary
DELETE /api/v2/knowledge/documents/{doc_id}resolved the document directory through its SQLite row. The cascade writes that row a second or more afterPOST /documentshas returned, so a delete that followed a create closely (an undo, a client retry) found no row, removed nothing, answered204— and the markdown left on disk was indexed right back in: the "deleted" document reappeared inGET /documentsa few seconds later.Markdown is the source of truth, so when the index has no row the directory is located on disk instead: its name ends in the doc_id (
knowledge_writer.py: dir_name = f"{title_slug}_{root.doc_id}"), so a*/*_<doc_id>glob under the scope's knowledge dir finds it. Response semantics are unchanged (204when no indexed topics were removed, as documented).Area
Verification
POST /documents(201) →DELETE3 ms later (204) →GET /documentslists the document again,GET /documents/{id}→ 200, directory still on disk (.work_context/agent_sim/logs/trace.jsonl, local).test_delete_document_removes_dir_before_the_index_has_the_row(real tmp root, repo mocked to return no row) — red without the disk lookup (assert not doc_dir.exists()fails), green with it. The existing idempotent test now pinsEVEROS_ROOTto a tmp dir so it never touches~/.everos.tests/unit/test_service/test_knowledge_crud.py+test_knowledge_api.py: 57 passed.make lintgreen.Checklist
Notes for Reviewers
_find_doc_dirruns in a worker thread (anyio.to_thread.run_sync), same as the existingrmtree. The glob is bounded to<knowledge_dir>/<category>/— two levels, no recursion.🤖 Generated with Claude Code