Repository navigation
fix(chat-knowledge): contexts can be deleted, cascade with their chat, and orphans get cleaned (#16490) - #16503
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ SSOT Configuration Compliance: Passing🎉 No new hardcoded values of either class — Known backlog in |
AutoBot Phase Validation ResultsSystem Maturity: 96.5% Phase Status:PASS Phase 1: Core Infrastructure: 100.0% Recommendations:
|
|
Review of New All three ACs have dedicated tests: owner-delete-cascades ( |
AutoBot Phase Validation ResultsSystem Maturity: 96.5% Phase Status:PASS Phase 1: Core Infrastructure: 100.0% Recommendations:
|
…, and orphans get cleaned (#16490) Adds an owner-or-admin-scoped DELETE /api/chat-knowledge/context/{chat_id} (existence checked before authorization, so an unknown chat_id is a clean 404 rather than being silently claimed by validate_chat_ownership's legacy-migration path), removing the context together with its file associations (and any file the manager itself wrote to disk for them) and its pending-decisions entry. Deleting a chat session now cascades to its chat-knowledge context via _perform_all_session_cleanup. Admin-only GET/DELETE /api/chat-knowledge/context-orphans discover and clean contexts whose chat_id matches no chat, mirroring api/knowledge_maintenance.py's /session-orphans shape. api/chat_knowledge.py and api/chat_sessions.py were both within a few lines of scripts/check_python_file_size.py's ceiling (chat_sessions.py exactly at its grandfathered ceiling), so the new routes and the cascade helper live in two new sibling modules (api/chat_knowledge_delete.py, api/chat_sessions_delete_cleanup.py) instead, composed in the same way api/chat.py already composes api/chat_sessions.py. Extracting six pre-existing, unchanged helpers into the second module shrinks chat_sessions.py enough to lower its ceiling in both scripts/python_file_size_known_large.py and repo_tests/python_file_size_ratchet_baseline.py, rather than raising it.
Auto-regenerated (py3.14) to match the backend and/or SLM backend schema so the required verify-generated-types gate(s) pass. Triggered by auto-fix-generated-types.yml.
…he guard (#16490) py/path-injection raised two alerts on the transcript delete: validate_relative_path contains the path, but CodeQL only credits a guard in the sink's own scope, spelled realpath + startswith(root + os.sep), the form #16229 and #16236 settled on. The validator call stays; the sink now uses the realpath it checks.
4ed6dd5 to
f9f0b32
Compare
|
Delta
The CodeQL result on this head was not in yet when I posted, so whether CodeQL now credits the check is still unconfirmed. |
|
CodeQL at |
Closes #16490
Single-issue rationale: #16490 covers deleting chat-knowledge contexts: an authorized DELETE route, the cascade from chat and session delete, and orphan discovery and cleanup. No other open issue shares that scope. #16502, which reports the cascade result in the session-delete response, was split out because
schemas_chat.pysits exactly at its file-size ceiling and needs a module split first. #15160, the never-assignedchat_knowledge_managermodule global, is a different defect with its own fix.Thinking Path
A test probe on 2026-09-12 left an empty chat-knowledge context on an install, and there was no supported way to remove it. Contexts could be created and read but never deleted, and chat deletion didn't reach them. The fix needed an authorized delete, a cascade from the existing session-delete path, and a way to find contexts whose chat no longer exists.
All chat-knowledge state is in memory on
ChatKnowledgeManager(chat_contexts,file_associations,pending_decisions), so there are no DB or Redis rows to migrate. Persistent KB facts stay with_cleanup_knowledge_base_facts, as before.What Changed
api/chat_knowledge_delete.py(new, mounted fromchat_knowledge.py, the waychat.pymountschat_sessions.py):DELETE /api/chat-knowledge/context/{chat_id}removes the context, its temporary knowledge, its file associations, and files thatupload_file_to_chatitself wrote. Files that are only associated are left alone.peek_chat_knowledge_managerbefore authorization, so an unknown id is a 404 and is never claimed byvalidate_chat_ownership's legacy-migration path.validate_chat_ownership: owner, org admin, or feat(knowledge): Share KB facts when sharing conversations #689 shared access.GET/DELETE /api/chat-knowledge/context-orphans, dry-run by default, the same shape as/session-orphans. The path is hyphenated so/context/{chat_id}can never shadow it._perform_all_session_cleanupruns for bothDELETE /chats/{chat_id}andDELETE /chat/sessions/{session_id}, and now also calls_cleanup_chat_knowledge_context.api/chat_sessions_delete_cleanup.py(new): the six existing KB-fact and transcript cleanup helpers move here verbatim, which makes room for the cascade.chat_sessions.py's ceiling is lowered from 2090 to 1953; no ceiling was raised.SessionDeleteDatahas no field for the new result, so the response drops it.schemas_chat.pyis exactly at its ceiling. The cleanup itself happens and is tested at the backend-state level.Verification
chat_knowledge*.py,chat.pyorchat_sessions.py. Other PRs edit different ceiling entries in the shared size-baseline files.chat_knowledge_delete_test.py.chat_sessions_delete_cleanup_test.py.Model Used
Claude Opus 5 (coordinator session), with an implementation subagent.
🤖 Generated with Claude Code