Repository navigation
fix(core): validate room_id + doc_slug exist in room_add_document - #700
Merged
Merged
Conversation
The room_documents junction table has an FK on room_id (→ rooms) but none on doc_slug, so POST /room/document/add accepted any doc_slug and created dangling room→document links. A bogus room_id also surfaced as a raw FK violation → 500. Validate both room_id and doc_slug existence in room_add_document, returning Error::Validation (→ 400) for unknown values. Update the PUT /room/document/add handler to map Validation → 400 accordingly. Closes #698
🔍 Cora AI Code Review🟡 Warning (1)
Review powered by cora-cli · BYOK · MIT |
ajianaz
added a commit
that referenced
this pull request
Aug 13, 2026
…tion fix(core): validate room_id + doc_slug exist in room_add_document
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
The
room_documentsjunction table enforces an FK onroom_id(→rooms) but has no FK ondoc_slug. As a resultPOST /room/document/addaccepted anydoc_slugstring — even one with no matching document — and created a dangling room→document link. A bogusroom_idalso surfaced as a raw FK violation returning500.This PR validates that both
room_idanddoc_slugreference existing rows before the insert, returningError::Validation(→400) for unknown values.Changes
crates/uteke-core/src/memory/rooms.rs—room_add_documentSELECT EXISTS(... FROM rooms WHERE id = ?)→Error::validation("Unknown room: …")if missing.SELECT EXISTS(... FROM documents WHERE slug = ?)→Error::validation("Unknown document slug: …")if missing.documents.slugisUNIQUEandCOLLATE NOCASE, so the lookup is consistent with how slugs are stored.)crates/uteke-server/src/handlers.rs—PUT /room/document/addError::Validation(_)→400instead of the previous blanket500(mirrorsPUT /memoryand the POST /memory/importance: fragile string-based error dispatch (400 silently degrades to 500) #697 fix).Behavior
Idempotent inserts (
INSERT OR IGNORE) and the existingroom_remove_documentare unchanged.Closes #698
Checklist
cargo fmtcleanroom_remove_documentleft as-is (noted in room_documents.doc_slug has no FK to documents — POST /room/document/add allows dangling links #698: returns Ok even when nothing deleted — separate concern)